/[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 579 by ph10, Wed Nov 24 17:39:25 2010 UTC revision 903 by ph10, Sat Jan 21 16:37:17 2012 UTC
# Line 25  man page, in case the conversion went wr Line 25  man page, in case the conversion went wr
25  <b>int (*pcre_callout)(pcre_callout_block *);</b>  <b>int (*pcre_callout)(pcre_callout_block *);</b>
26  </P>  </P>
27  <P>  <P>
28    <b>int (*pcre16_callout)(pcre16_callout_block *);</b>
29    </P>
30    <P>
31  PCRE provides a feature called "callout", which is a means of temporarily  PCRE provides a feature called "callout", which is a means of temporarily
32  passing control to the caller of PCRE in the middle of pattern matching. The  passing control to the caller of PCRE in the middle of pattern matching. The
33  caller of PCRE provides an external function by putting its entry point in the  caller of PCRE provides an external function by putting its entry point in the
34  global variable <i>pcre_callout</i>. By default, this variable contains NULL,  global variable <i>pcre_callout</i> (<i>pcre16_callout</i> for the 16-bit
35  which disables all calling out.  library). By default, this variable contains NULL, which disables all calling
36    out.
37  </P>  </P>
38  <P>  <P>
39  Within a regular expression, (?C) indicates the points at which the external  Within a regular expression, (?C) indicates the points at which the external
# Line 39  For example, this pattern has two callou Line 43  For example, this pattern has two callou
43  <pre>  <pre>
44    (?C1)abc(?C2)def    (?C1)abc(?C2)def
45  </pre>  </pre>
46  If the PCRE_AUTO_CALLOUT option bit is set when <b>pcre_compile()</b> or  If the PCRE_AUTO_CALLOUT option bit is set when a pattern is compiled, PCRE
47  <b>pcre_compile2()</b> is called, PCRE automatically inserts callouts, all with  automatically inserts callouts, all with number 255, before each item in the
48  number 255, before each item in the pattern. For example, if PCRE_AUTO_CALLOUT  pattern. For example, if PCRE_AUTO_CALLOUT is used with the pattern
 is used with the pattern  
49  <pre>  <pre>
50    A(\d{2}|--)    A(\d{2}|--)
51  </pre>  </pre>
# Line 60  command has an option that sets automati Line 63  command has an option that sets automati
63  indicates how the pattern is matched. This is useful information when you are  indicates how the pattern is matched. This is useful information when you are
64  trying to optimize the performance of a particular pattern.  trying to optimize the performance of a particular pattern.
65  </P>  </P>
66    <P>
67    The use of callouts in a pattern makes it ineligible for optimization by the
68    just-in-time compiler. Studying such a pattern with the PCRE_STUDY_JIT_COMPILE
69    option always fails.
70    </P>
71  <br><a name="SEC2" href="#TOC1">MISSING CALLOUTS</a><br>  <br><a name="SEC2" href="#TOC1">MISSING CALLOUTS</a><br>
72  <P>  <P>
73  You should be aware that, because of optimizations in the way PCRE matches  You should be aware that, because of optimizations in the way PCRE matches
# Line 81  been scanned far enough. Line 89  been scanned far enough.
89  </P>  </P>
90  <P>  <P>
91  You can disable these optimizations by passing the PCRE_NO_START_OPTIMIZE  You can disable these optimizations by passing the PCRE_NO_START_OPTIMIZE
92  option to <b>pcre_compile()</b>, <b>pcre_exec()</b>, or <b>pcre_dfa_exec()</b>,  option to the matching function, or by starting the pattern with
93  or by starting the pattern with (*NO_START_OPT). This slows down the matching  (*NO_START_OPT). This slows down the matching process, but does ensure that
94  process, but does ensure that callouts such as the example above are obeyed.  callouts such as the example above are obeyed.
95  </P>  </P>
96  <br><a name="SEC3" href="#TOC1">THE CALLOUT INTERFACE</a><br>  <br><a name="SEC3" href="#TOC1">THE CALLOUT INTERFACE</a><br>
97  <P>  <P>
98  During matching, when PCRE reaches a callout point, the external function  During matching, when PCRE reaches a callout point, the external function
99  defined by <i>pcre_callout</i> is called (if it is set). This applies to both  defined by <i>pcre_callout</i> or <i>pcre16_callout</i> is called (if it is set).
100  the <b>pcre_exec()</b> and the <b>pcre_dfa_exec()</b> matching functions. The  This applies to both normal and DFA matching. The only argument to the callout
101  only argument to the callout function is a pointer to a <b>pcre_callout</b>  function is a pointer to a <b>pcre_callout</b> or <b>pcre16_callout</b> block.
102  block. This structure contains the following fields:  These structures contains the following fields:
103  <pre>  <pre>
104    int          <i>version</i>;    int           <i>version</i>;
105    int          <i>callout_number</i>;    int           <i>callout_number</i>;
106    int         *<i>offset_vector</i>;    int          *<i>offset_vector</i>;
107    const char  *<i>subject</i>;    const char   *<i>subject</i>;           (8-bit version)
108    int          <i>subject_length</i>;    PCRE_SPTR16   <i>subject</i>;           (16-bit version)
109    int          <i>start_match</i>;    int           <i>subject_length</i>;
110    int          <i>current_position</i>;    int           <i>start_match</i>;
111    int          <i>capture_top</i>;    int           <i>current_position</i>;
112    int          <i>capture_last</i>;    int           <i>capture_top</i>;
113    void        *<i>callout_data</i>;    int           <i>capture_last</i>;
114    int          <i>pattern_position</i>;    void         *<i>callout_data</i>;
115    int          <i>next_item_length</i>;    int           <i>pattern_position</i>;
116      int           <i>next_item_length</i>;
117      const unsigned char *<i>mark</i>;       (8-bit version)
118      const PCRE_UCHAR16  *<i>mark</i>;       (16-bit version)
119  </pre>  </pre>
120  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
121  block format. The initial version was 0; the current version is 1. The version  block format. The initial version was 0; the current version is 2. The version
122  number will change again in future if additional fields are added, but the  number will change again in future if additional fields are added, but the
123  intention is never to remove any of the existing fields.  intention is never to remove any of the existing fields.
124  </P>  </P>
# Line 118  automatically generated callouts). Line 129  automatically generated callouts).
129  </P>  </P>
130  <P>  <P>
131  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
132  passed by the caller to <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>. When  passed by the caller to the matching function. When <b>pcre_exec()</b> or
133  <b>pcre_exec()</b> is used, the contents can be inspected in order to extract  <b>pcre16_exec()</b> is used, the contents can be inspected, in order to extract
134  substrings that have been matched so far, in the same way as for extracting  substrings that have been matched so far, in the same way as for extracting
135  substrings after a match has completed. For <b>pcre_dfa_exec()</b> this field is  substrings after a match has completed. For the DFA matching functions, this
136  not useful.  field is not useful.
137  </P>  </P>
138  <P>  <P>
139  The <i>subject</i> and <i>subject_length</i> fields contain copies of the values  The <i>subject</i> and <i>subject_length</i> fields contain copies of the values
140  that were passed to <b>pcre_exec()</b>.  that were passed to the matching function.
141  </P>  </P>
142  <P>  <P>
143  The <i>start_match</i> field normally contains the offset within the subject at  The <i>start_match</i> field normally contains the offset within the subject at
# Line 141  The <i>current_position</i> field contai Line 152  The <i>current_position</i> field contai
152  current match pointer.  current match pointer.
153  </P>  </P>
154  <P>  <P>
155  When the <b>pcre_exec()</b> function is used, the <i>capture_top</i> field  When the <b>pcre_exec()</b> or <b>pcre16_exec()</b> is used, the
156  contains one more than the number of the highest numbered captured substring so  <i>capture_top</i> field contains one more than the number of the highest
157  far. If no substrings have been captured, the value of <i>capture_top</i> is  numbered captured substring so far. If no substrings have been captured, the
158  one. This is always the case when <b>pcre_dfa_exec()</b> is used, because it  value of <i>capture_top</i> is one. This is always the case when the DFA
159  does not support captured substrings.  functions are used, because they do not support captured substrings.
160  </P>  </P>
161  <P>  <P>
162  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
163  substring. If no substrings have been captured, its value is -1. This is always  substring. If no substrings have been captured, its value is -1. This is always
164  the case when <b>pcre_dfa_exec()</b> is used.  the case for the DFA matching functions.
165  </P>  </P>
166  <P>  <P>
167  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 a matching
168  <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b> specifically so that it can be  function specifically so that it can be passed back in callouts. It is passed
169  passed back in callouts. It is passed in the <i>pcre_callout</i> field of the  in the <i>callout_data</i> field of a <b>pcre_extra</b> or <b>pcre16_extra</b>
170  <b>pcre_extra</b> data structure. If no such data was passed, the value of  data structure. If no such data was passed, the value of <i>callout_data</i> in
171  <i>callout_data</i> in a <b>pcre_callout</b> block is NULL. There is a  a callout block is NULL. There is a description of the <b>pcre_extra</b>
172  description of the <b>pcre_extra</b> structure in the  structure in the
173  <a href="pcreapi.html"><b>pcreapi</b></a>  <a href="pcreapi.html"><b>pcreapi</b></a>
174  documentation.  documentation.
175  </P>  </P>
176  <P>  <P>
177  The <i>pattern_position</i> field is present from version 1 of the  The <i>pattern_position</i> field is present from version 1 of the callout
178  <i>pcre_callout</i> structure. It contains the offset to the next item to be  structure. It contains the offset to the next item to be matched in the pattern
179  matched in the pattern string.  string.
180  </P>  </P>
181  <P>  <P>
182  The <i>next_item_length</i> field is present from version 1 of the  The <i>next_item_length</i> field is present from version 1 of the callout
183  <i>pcre_callout</i> structure. It contains the length of the next item to be  structure. It contains the length of the next item to be matched in the pattern
184  matched in the pattern string. When the callout immediately precedes an  string. When the callout immediately precedes an alternation bar, a closing
185  alternation bar, a closing parenthesis, or the end of the pattern, the length  parenthesis, or the end of the pattern, the length is zero. When the callout
186  is zero. When the callout precedes an opening parenthesis, the length is that  precedes an opening parenthesis, the length is that of the entire subpattern.
 of the entire subpattern.  
187  </P>  </P>
188  <P>  <P>
189  The <i>pattern_position</i> and <i>next_item_length</i> fields are intended to  The <i>pattern_position</i> and <i>next_item_length</i> fields are intended to
190  help in distinguishing between different automatic callouts, which all have the  help in distinguishing between different automatic callouts, which all have the
191  same callout number. However, they are set for all callouts.  same callout number. However, they are set for all callouts.
192  </P>  </P>
193    <P>
194    The <i>mark</i> field is present from version 2 of the callout structure. In
195    callouts from <b>pcre_exec()</b> or <b>pcre16_exec()</b> it contains a pointer to
196    the zero-terminated name of the most recently passed (*MARK), (*PRUNE), or
197    (*THEN) item in the match, or NULL if no such items have been passed. Instances
198    of (*PRUNE) or (*THEN) without a name do not obliterate a previous (*MARK). In
199    callouts from the DFA matching functions this field always contains NULL.
200    </P>
201  <br><a name="SEC4" href="#TOC1">RETURN VALUES</a><br>  <br><a name="SEC4" href="#TOC1">RETURN VALUES</a><br>
202  <P>  <P>
203  The external callout function returns an integer to PCRE. If the value is zero,  The external callout function returns an integer to PCRE. If the value is zero,
204  matching proceeds as normal. If the value is greater than zero, matching fails  matching proceeds as normal. If the value is greater than zero, matching fails
205  at the current point, but the testing of other matching possibilities goes  at the current point, but the testing of other matching possibilities goes
206  ahead, just as if a lookahead assertion had failed. If the value is less than  ahead, just as if a lookahead assertion had failed. If the value is less than
207  zero, the match is abandoned, and <b>pcre_exec()</b> or <b>pcre_dfa_exec()</b>  zero, the match is abandoned, the matching function returns the negative value.
 returns the negative value.  
208  </P>  </P>
209  <P>  <P>
210  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 206  Cambridge CB2 3QH, England. Line 223  Cambridge CB2 3QH, England.
223  </P>  </P>
224  <br><a name="SEC6" href="#TOC1">REVISION</a><br>  <br><a name="SEC6" href="#TOC1">REVISION</a><br>
225  <P>  <P>
226  Last updated: 21 November 2010  Last updated: 08 Janurary 2012
227  <br>  <br>
228  Copyright &copy; 1997-2010 University of Cambridge.  Copyright &copy; 1997-2012 University of Cambridge.
229  <br>  <br>
230  <p>  <p>
231  Return to the <a href="index.html">PCRE index page</a>.  Return to the <a href="index.html">PCRE index page</a>.

Legend:
Removed from v.579  
changed lines
  Added in v.903

  ViewVC Help
Powered by ViewVC 1.1.5