/[pcre]/code/trunk/doc/html/pcrecallout.html
ViewVC logotype

Diff of /code/trunk/doc/html/pcrecallout.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 63 by nigel, Sat Feb 24 21:40:03 2007 UTC revision 111 by ph10, Thu Mar 8 16:53:09 2007 UTC
# Line 3  Line 3 
3  <title>pcrecallout specification</title>  <title>pcrecallout specification</title>
4  </head>  </head>
5  <body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">  <body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
6  This HTML document has been generated automatically from the original man page.  <h1>pcrecallout man page</h1>
7  If there is any nonsense in it, please consult the man page, in case the  <p>
8  conversion went wrong.<br>  Return to the <a href="index.html">PCRE index page</a>.
9    </p>
10    <p>
11    This page is part of the PCRE HTML documentation. It was generated automatically
12    from the original man page. If there is any nonsense in it, please consult the
13    man page, in case the conversion went wrong.
14    <br>
15  <ul>  <ul>
16  <li><a name="TOC1" href="#SEC1">PCRE CALLOUTS</a>  <li><a name="TOC1" href="#SEC1">PCRE CALLOUTS</a>
17  <li><a name="TOC2" href="#SEC2">RETURN VALUES</a>  <li><a name="TOC2" href="#SEC2">MISSING CALLOUTS</a>
18    <li><a name="TOC3" href="#SEC3">THE CALLOUT INTERFACE</a>
19    <li><a name="TOC4" href="#SEC4">RETURN VALUES</a>
20    <li><a name="TOC5" href="#SEC5">AUTHOR</a>
21    <li><a name="TOC6" href="#SEC6">REVISION</a>
22  </ul>  </ul>
23  <br><a name="SEC1" href="#TOC1">PCRE CALLOUTS</a><br>  <br><a name="SEC1" href="#TOC1">PCRE CALLOUTS</a><br>
24  <P>  <P>
# Line 26  Within a regular expression, (?C) indica Line 36  Within a regular expression, (?C) indica
36  function is to be called. Different callout points can be identified by putting  function is to be called. Different callout points can be identified by putting
37  a number less than 256 after the letter C. The default value is zero.  a number less than 256 after the letter C. The default value is zero.
38  For example, this pattern has two callout points:  For example, this pattern has two callout points:
 </P>  
 <P>  
39  <pre>  <pre>
40    (?C1)\dabc(?C2)def    (?C1)\deabc(?C2)def
41  </PRE>  </pre>
42  </P>  If the PCRE_AUTO_CALLOUT option bit is set when <b>pcre_compile()</b> is called,
43  <P>  PCRE automatically inserts callouts, all with number 255, before each item in
44  During matching, when PCRE reaches a callout point (and <i>pcre_callout</i> is  the pattern. For example, if PCRE_AUTO_CALLOUT is used with the pattern
45  set), the external function is called. Its only argument is a pointer to a  <pre>
46  <b>pcre_callout</b> block. This contains the following variables:    A(\d{2}|--)
47    </pre>
48    it is processed as if it were
49    <br>
50    <br>
51    (?C255)A(?C255)((?C255)\d{2}(?C255)|(?C255)-(?C255)-(?C255))(?C255)
52    <br>
53    <br>
54    Notice that there is a callout before and after each parenthesis and
55    alternation bar. Automatic callouts can be used for tracking the progress of
56    pattern matching. The
57    <a href="pcretest.html"><b>pcretest</b></a>
58    command has an option that sets automatic callouts; when it is used, the output
59    indicates how the pattern is matched. This is useful information when you are
60    trying to optimize the performance of a particular pattern.
61  </P>  </P>
62    <br><a name="SEC2" href="#TOC1">MISSING CALLOUTS</a><br>
63  <P>  <P>
64    You should be aware that, because of optimizations in the way PCRE matches
65    patterns, callouts sometimes do not happen. For example, if the pattern is
66    <pre>
67      ab(?C4)cd
68    </pre>
69    PCRE knows that any matching string must contain the letter "d". If the subject
70    string is "abyz", the lack of "d" means that matching doesn't ever start, and
71    the callout is never reached. However, with "abyd", though the result is still
72    no match, the callout is obeyed.
73    </P>
74    <br><a name="SEC3" href="#TOC1">THE CALLOUT INTERFACE</a><br>
75    <P>
76    During matching, when PCRE reaches a callout point, the external function
77    defined by <i>pcre_callout</i> is called (if it is set). This applies to both
78    the <b>pcre_exec()</b> and the <b>pcre_dfa_exec()</b> matching functions. The
79    only argument to the callout function is a pointer to a <b>pcre_callout</b>
80    block. This structure contains the following fields:
81  <pre>  <pre>
82    int          <i>version</i>;    int          <i>version</i>;
83    int          <i>callout_number</i>;    int          <i>callout_number</i>;
# Line 49  set), the external function is called. I Line 89  set), the external function is called. I
89    int          <i>capture_top</i>;    int          <i>capture_top</i>;
90    int          <i>capture_last</i>;    int          <i>capture_last</i>;
91    void        *<i>callout_data</i>;    void        *<i>callout_data</i>;
92  </PRE>    int          <i>pattern_position</i>;
93  </P>    int          <i>next_item_length</i>;
94  <P>  </pre>
95  The <i>version</i> field is an integer containing the version number of the  The <i>version</i> field is an integer containing the version number of the
96  block format. The current version is zero. The version number may change in  block format. The initial version was 0; the current version is 1. The version
97  future if additional fields are added, but the intention is never to remove any  number will change again in future if additional fields are added, but the
98  of the existing fields.  intention is never to remove any of the existing fields.
99  </P>  </P>
100  <P>  <P>
101  The <i>callout_number</i> field contains the number of the callout, as compiled  The <i>callout_number</i> field contains the number of the callout, as compiled
102  into the pattern (that is, the number after ?C).  into the pattern (that is, the number after ?C for manual callouts, and 255 for
103    automatically generated callouts).
104  </P>  </P>
105  <P>  <P>
106  The <i>offset_vector</i> field is a pointer to the vector of offsets that was  The <i>offset_vector</i> field is a pointer to the vector of offsets that was
107  passed by the caller to <b>pcre_exec()</b>. The contents can be inspected in  passed by the caller to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>. When
108  order to extract substrings that have been matched so far, in the same way as  <b>pcre_exec()</b> is used, the contents can be inspected in order to extract
109  for extracting substrings after a match has completed.  substrings that have been matched so far, in the same way as for extracting
110    substrings after a match has completed. For <b>pcre_dfa_exec()</b> this field is
111    not useful.
112  </P>  </P>
113  <P>  <P>
114  The <i>subject</i> and <i>subject_length</i> fields contain copies the values  The <i>subject</i> and <i>subject_length</i> fields contain copies of the values
115  that were passed to <b>pcre_exec()</b>.  that were passed to <b>pcre_exec()</b>.
116  </P>  </P>
117  <P>  <P>
118  The <i>start_match</i> field contains the offset within the subject at which the  The <i>start_match</i> field contains the offset within the subject at which the
119  current match attempt started. If the pattern is not anchored, the callout  current match attempt started. If the pattern is not anchored, the callout
120  function may be called several times for different starting points.  function may be called several times from the same point in the pattern for
121    different starting points in the subject.
122  </P>  </P>
123  <P>  <P>
124  The <i>current_position</i> field contains the offset within the subject of the  The <i>current_position</i> field contains the offset within the subject of the
125  current match pointer.  current match pointer.
126  </P>  </P>
127  <P>  <P>
128  The <i>capture_top</i> field contains the number of the highest captured  When the <b>pcre_exec()</b> function is used, the <i>capture_top</i> field
129  substring so far.  contains one more than the number of the highest numbered captured substring so
130    far. If no substrings have been captured, the value of <i>capture_top</i> is
131    one. This is always the case when <b>pcre_dfa_exec()</b> is used, because it
132    does not support captured substrings.
133  </P>  </P>
134  <P>  <P>
135  The <i>capture_last</i> field contains the number of the most recently captured  The <i>capture_last</i> field contains the number of the most recently captured
136  substring.  substring. If no substrings have been captured, its value is -1. This is always
137    the case when <b>pcre_dfa_exec()</b> is used.
138  </P>  </P>
139  <P>  <P>
140  The <i>callout_data</i> field contains a value that is passed to  The <i>callout_data</i> field contains a value that is passed to
141  <b>pcre_exec()</b> by the caller specifically so that it can be passed back in  <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b> specifically so that it can be
142  callouts. It is passed in the <i>pcre_callout</i> field of the <b>pcre_extra</b>  passed back in callouts. It is passed in the <i>pcre_callout</i> field of the
143  data structure. If no such data was passed, the value of <i>callout_data</i> in  <b>pcre_extra</b> data structure. If no such data was passed, the value of
144  a <b>pcre_callout</b> block is NULL. There is a description of the  <i>callout_data</i> in a <b>pcre_callout</b> block is NULL. There is a
145  <b>pcre_extra</b> structure in the <b>pcreapi</b> documentation.  description of the <b>pcre_extra</b> structure in the
146  </P>  <a href="pcreapi.html"><b>pcreapi</b></a>
147  <br><a name="SEC2" href="#TOC1">RETURN VALUES</a><br>  documentation.
148  <P>  </P>
149  The callout function returns an integer. If the value is zero, matching  <P>
150  proceeds as normal. If the value is greater than zero, matching fails at the  The <i>pattern_position</i> field is present from version 1 of the
151  current point, but backtracking to test other possibilities goes ahead, just as  <i>pcre_callout</i> structure. It contains the offset to the next item to be
152  if a lookahead assertion had failed. If the value is less than zero, the match  matched in the pattern string.
153  is abandoned, and <b>pcre_exec()</b> returns the value.  </P>
154    <P>
155    The <i>next_item_length</i> field is present from version 1 of the
156    <i>pcre_callout</i> structure. It contains the length of the next item to be
157    matched in the pattern string. When the callout immediately precedes an
158    alternation bar, a closing parenthesis, or the end of the pattern, the length
159    is zero. When the callout precedes an opening parenthesis, the length is that
160    of the entire subpattern.
161    </P>
162    <P>
163    The <i>pattern_position</i> and <i>next_item_length</i> fields are intended to
164    help in distinguishing between different automatic callouts, which all have the
165    same callout number. However, they are set for all callouts.
166    </P>
167    <br><a name="SEC4" href="#TOC1">RETURN VALUES</a><br>
168    <P>
169    The external callout function returns an integer to PCRE. If the value is zero,
170    matching proceeds as normal. If the value is greater than zero, matching fails
171    at the current point, but the testing of other matching possibilities goes
172    ahead, just as if a lookahead assertion had failed. If the value is less than
173    zero, the match is abandoned, and <b>pcre_exec()</b> (or <b>pcre_dfa_exec()</b>)
174    returns the negative value.
175  </P>  </P>
176  <P>  <P>
177  Negative values should normally be chosen from the set of PCRE_ERROR_xxx  Negative values should normally be chosen from the set of PCRE_ERROR_xxx
# Line 110  values. In particular, PCRE_ERROR_NOMATC Line 179  values. In particular, PCRE_ERROR_NOMATC
179  The error number PCRE_ERROR_CALLOUT is reserved for use by callout functions;  The error number PCRE_ERROR_CALLOUT is reserved for use by callout functions;
180  it will never be used by PCRE itself.  it will never be used by PCRE itself.
181  </P>  </P>
182    <br><a name="SEC5" href="#TOC1">AUTHOR</a><br>
183  <P>  <P>
184  Last updated: 21 January 2003  Philip Hazel
185    <br>
186    University Computing Service
187    <br>
188    Cambridge CB2 3QH, England.
189    <br>
190    </P>
191    <br><a name="SEC6" href="#TOC1">REVISION</a><br>
192    <P>
193    Last updated: 06 March 2007
194    <br>
195    Copyright &copy; 1997-2007 University of Cambridge.
196  <br>  <br>
197  Copyright &copy; 1997-2003 University of Cambridge.  <p>
198    Return to the <a href="index.html">PCRE index page</a>.
199    </p>

Legend:
Removed from v.63  
changed lines
  Added in v.111

  ViewVC Help
Powered by ViewVC 1.1.5