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

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

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

revision 75 by nigel, Sat Feb 24 21:40:37 2007 UTC revision 645 by ph10, Sun Jul 31 17:02:18 2011 UTC
# Line 1  Line 1 
1  .TH PCRE 3  .TH PCRECALLOUT 3
2  .SH NAME  .SH NAME
3  PCRE - Perl-compatible regular expressions  PCRE - Perl-compatible regular expressions
4  .SH "PCRE CALLOUTS"  .SH "PCRE CALLOUTS"
# Line 17  function is to be called. Different call Line 17  function is to be called. Different call
17  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.
18  For example, this pattern has two callout points:  For example, this pattern has two callout points:
19  .sp  .sp
20    (?C1)\deabc(?C2)def    (?C1)abc(?C2)def
21  .sp  .sp
22  If the PCRE_AUTO_CALLOUT option bit is set when \fBpcre_compile()\fP is called,  If the PCRE_AUTO_CALLOUT option bit is set when \fBpcre_compile()\fP or
23  PCRE automatically inserts callouts, all with number 255, before each item in  \fBpcre_compile2()\fP is called, PCRE automatically inserts callouts, all with
24  the pattern. For example, if PCRE_AUTO_CALLOUT is used with the pattern  number 255, before each item in the pattern. For example, if PCRE_AUTO_CALLOUT
25    is used with the pattern
26  .sp  .sp
27    A(\ed{2}|--)    A(\ed{2}|--)
28  .sp  .sp
# Line 44  trying to optimize the performance of a Line 45  trying to optimize the performance of a
45  .rs  .rs
46  .sp  .sp
47  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
48  patterns, callouts sometimes do not happen. For example, if the pattern is  patterns by default, callouts sometimes do not happen. For example, if the
49    pattern is
50  .sp  .sp
51    ab(?C4)cd    ab(?C4)cd
52  .sp  .sp
# Line 52  PCRE knows that any matching string must Line 54  PCRE knows that any matching string must
54  string is "abyz", the lack of "d" means that matching doesn't ever start, and  string is "abyz", the lack of "d" means that matching doesn't ever start, and
55  the callout is never reached. However, with "abyd", though the result is still  the callout is never reached. However, with "abyd", though the result is still
56  no match, the callout is obeyed.  no match, the callout is obeyed.
57    .P
58    If the pattern is studied, PCRE knows the minimum length of a matching string,
59    and will immediately give a "no match" return without actually running a match
60    if the subject is not long enough, or, for unanchored patterns, if it has
61    been scanned far enough.
62    .P
63    You can disable these optimizations by passing the PCRE_NO_START_OPTIMIZE
64    option to \fBpcre_compile()\fP, \fBpcre_exec()\fP, or \fBpcre_dfa_exec()\fP,
65    or by starting the pattern with (*NO_START_OPT). This slows down the matching
66    process, but does ensure that callouts such as the example above are obeyed.
67  .  .
68  .  .
69  .SH "THE CALLOUT INTERFACE"  .SH "THE CALLOUT INTERFACE"
70  .rs  .rs
71  .sp  .sp
72  During matching, when PCRE reaches a callout point, the external function  During matching, when PCRE reaches a callout point, the external function
73  defined by \fIpcre_callout\fP is called (if it is set). The only argument is a  defined by \fIpcre_callout\fP is called (if it is set). This applies to both
74  pointer to a \fBpcre_callout\fP block. This structure contains the following  the \fBpcre_exec()\fP and the \fBpcre_dfa_exec()\fP matching functions. The
75  fields:  only argument to the callout function is a pointer to a \fBpcre_callout\fP
76  .sp  block. This structure contains the following fields:
77    int          \fIversion\fP;  .sp
78    int          \fIcallout_number\fP;    int         \fIversion\fP;
79    int         *\fIoffset_vector\fP;    int         \fIcallout_number\fP;
80    const char  *\fIsubject\fP;    int        *\fIoffset_vector\fP;
81    int          \fIsubject_length\fP;    const char *\fIsubject\fP;
82    int          \fIstart_match\fP;    int         \fIsubject_length\fP;
83    int          \fIcurrent_position\fP;    int         \fIstart_match\fP;
84    int          \fIcapture_top\fP;    int         \fIcurrent_position\fP;
85    int          \fIcapture_last\fP;    int         \fIcapture_top\fP;
86    void        *\fIcallout_data\fP;    int         \fIcapture_last\fP;
87    int          \fIpattern_position\fP;    void       *\fIcallout_data\fP;
88    int          \fInext_item_length\fP;    int         \fIpattern_position\fP;
89      int         \fInext_item_length\fP;
90      const unsigned char *\fImark\fP;
91  .sp  .sp
92  The \fIversion\fP field is an integer containing the version number of the  The \fIversion\fP field is an integer containing the version number of the
93  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
94  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
95  intention is never to remove any of the existing fields.  intention is never to remove any of the existing fields.
96  .P  .P
# Line 85  into the pattern (that is, the number af Line 99  into the pattern (that is, the number af
99  automatically generated callouts).  automatically generated callouts).
100  .P  .P
101  The \fIoffset_vector\fP field is a pointer to the vector of offsets that was  The \fIoffset_vector\fP field is a pointer to the vector of offsets that was
102  passed by the caller to \fBpcre_exec()\fP. The contents can be inspected in  passed by the caller to \fBpcre_exec()\fP or \fBpcre_dfa_exec()\fP. When
103  order to extract substrings that have been matched so far, in the same way as  \fBpcre_exec()\fP is used, the contents can be inspected in order to extract
104  for extracting substrings after a match has completed.  substrings that have been matched so far, in the same way as for extracting
105    substrings after a match has completed. For \fBpcre_dfa_exec()\fP this field is
106    not useful.
107  .P  .P
108  The \fIsubject\fP and \fIsubject_length\fP fields contain copies of the values  The \fIsubject\fP and \fIsubject_length\fP fields contain copies of the values
109  that were passed to \fBpcre_exec()\fP.  that were passed to \fBpcre_exec()\fP.
110  .P  .P
111  The \fIstart_match\fP field contains the offset within the subject at which the  The \fIstart_match\fP field normally contains the offset within the subject at
112  current match attempt started. If the pattern is not anchored, the callout  which the current match attempt started. However, if the escape sequence \eK
113  function may be called several times from the same point in the pattern for  has been encountered, this value is changed to reflect the modified starting
114  different starting points in the subject.  point. If the pattern is not anchored, the callout function may be called
115    several times from the same point in the pattern for different starting points
116    in the subject.
117  .P  .P
118  The \fIcurrent_position\fP field contains the offset within the subject of the  The \fIcurrent_position\fP field contains the offset within the subject of the
119  current match pointer.  current match pointer.
120  .P  .P
121  The \fIcapture_top\fP field contains one more than the number of the highest  When the \fBpcre_exec()\fP function is used, the \fIcapture_top\fP field
122  numbered captured substring so far. If no substrings have been captured,  contains one more than the number of the highest numbered captured substring so
123  the value of \fIcapture_top\fP is one.  far. If no substrings have been captured, the value of \fIcapture_top\fP is
124    one. This is always the case when \fBpcre_dfa_exec()\fP is used, because it
125    does not support captured substrings.
126  .P  .P
127  The \fIcapture_last\fP field contains the number of the most recently captured  The \fIcapture_last\fP field contains the number of the most recently captured
128  substring. If no substrings have been captured, its value is -1.  substring. If no substrings have been captured, its value is -1. This is always
129    the case when \fBpcre_dfa_exec()\fP is used.
130  .P  .P
131  The \fIcallout_data\fP field contains a value that is passed to  The \fIcallout_data\fP field contains a value that is passed to
132  \fBpcre_exec()\fP by the caller specifically so that it can be passed back in  \fBpcre_exec()\fP or \fBpcre_dfa_exec()\fP specifically so that it can be
133  callouts. It is passed in the \fIpcre_callout\fP field of the \fBpcre_extra\fP  passed back in callouts. It is passed in the \fIpcre_callout\fP field of the
134  data structure. If no such data was passed, the value of \fIcallout_data\fP in  \fBpcre_extra\fP data structure. If no such data was passed, the value of
135  a \fBpcre_callout\fP block is NULL. There is a description of the  \fIcallout_data\fP in a \fBpcre_callout\fP block is NULL. There is a
136  \fBpcre_extra\fP structure in the  description of the \fBpcre_extra\fP structure in the
137  .\" HREF  .\" HREF
138  \fBpcreapi\fP  \fBpcreapi\fP
139  .\"  .\"
# Line 132  of the entire subpattern. Line 153  of the entire subpattern.
153  The \fIpattern_position\fP and \fInext_item_length\fP fields are intended to  The \fIpattern_position\fP and \fInext_item_length\fP fields are intended to
154  help in distinguishing between different automatic callouts, which all have the  help in distinguishing between different automatic callouts, which all have the
155  same callout number. However, they are set for all callouts.  same callout number. However, they are set for all callouts.
156    .P
157    The \fImark\fP field is present from version 2 of the \fIpcre_callout\fP
158    structure. In callouts from \fBpcre_exec()\fP it contains a pointer to the
159    zero-terminated name of the most recently passed (*MARK) item in the match, or
160    NULL if there are no (*MARK)s in the current matching path. In callouts from
161    \fBpcre_dfa_exec()\fP this field always contains NULL.
162  .  .
163  .  .
164  .SH "RETURN VALUES"  .SH "RETURN VALUES"
# Line 139  same callout number. However, they are s Line 166  same callout number. However, they are s
166  .sp  .sp
167  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,
168  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
169  at the current point, but backtracking to test other matching possibilities  at the current point, but the testing of other matching possibilities goes
170  goes ahead, just as if a lookahead assertion had failed. If the value is less  ahead, just as if a lookahead assertion had failed. If the value is less than
171  than zero, the match is abandoned, and \fBpcre_exec()\fP returns the negative  zero, the match is abandoned, and \fBpcre_exec()\fP or \fBpcre_dfa_exec()\fP
172  value.  returns the negative value.
173  .P  .P
174  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
175  values. In particular, PCRE_ERROR_NOMATCH forces a standard "no match" failure.  values. In particular, PCRE_ERROR_NOMATCH forces a standard "no match" failure.
176  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;
177  it will never be used by PCRE itself.  it will never be used by PCRE itself.
178  .P  .
179  .in 0  .
180  Last updated: 09 September 2004  .SH AUTHOR
181  .br  .rs
182  Copyright (c) 1997-2004 University of Cambridge.  .sp
183    .nf
184    Philip Hazel
185    University Computing Service
186    Cambridge CB2 3QH, England.
187    .fi
188    .
189    .
190    .SH REVISION
191    .rs
192    .sp
193    .nf
194    Last updated: 31 July 2011
195    Copyright (c) 1997-2011 University of Cambridge.
196    .fi

Legend:
Removed from v.75  
changed lines
  Added in v.645

  ViewVC Help
Powered by ViewVC 1.1.5