/[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 74 by nigel, Sat Feb 24 21:40:24 2007 UTC revision 75 by nigel, Sat Feb 24 21:40:37 2007 UTC
# Line 1  Line 1 
1  .TH PCRE 3  .TH PCRE 3
2  .SH NAME  .SH NAME
3  PCRE - Perl-compatible regular expressions  PCRE - Perl-compatible regular expressions
4  .SH PCRE CALLOUTS  .SH "PCRE CALLOUTS"
5  .rs  .rs
6  .sp  .sp
7  .B int (*pcre_callout)(pcre_callout_block *);  .B int (*pcre_callout)(pcre_callout_block *);
# Line 9  PCRE - Perl-compatible regular expressio Line 9  PCRE - Perl-compatible regular expressio
9  PCRE provides a feature called "callout", which is a means of temporarily  PCRE provides a feature called "callout", which is a means of temporarily
10  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
11  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
12  global variable \fIpcre_callout\fR. By default, this variable contains NULL,  global variable \fIpcre_callout\fP. By default, this variable contains NULL,
13  which disables all calling out.  which disables all calling out.
14    .P
15  Within a regular expression, (?C) indicates the points at which the external  Within a regular expression, (?C) indicates the points at which the external
16  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
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
20    (?C1)\dabc(?C2)def    (?C1)\deabc(?C2)def
21    .sp
22  During matching, when PCRE reaches a callout point (and \fIpcre_callout\fR is  If the PCRE_AUTO_CALLOUT option bit is set when \fBpcre_compile()\fP is called,
23  set), the external function is called. Its only argument is a pointer to a  PCRE automatically inserts callouts, all with number 255, before each item in
24  \fBpcre_callout\fR block. This contains the following variables:  the pattern. For example, if PCRE_AUTO_CALLOUT is used with the pattern
25    .sp
26    int          \fIversion\fR;    A(\ed{2}|--)
27    int          \fIcallout_number\fR;  .sp
28    int         *\fIoffset_vector\fR;  it is processed as if it were
29    const char  *\fIsubject\fR;  .sp
30    int          \fIsubject_length\fR;  (?C255)A(?C255)((?C255)\ed{2}(?C255)|(?C255)-(?C255)-(?C255))(?C255)
31    int          \fIstart_match\fR;  .sp
32    int          \fIcurrent_position\fR;  Notice that there is a callout before and after each parenthesis and
33    int          \fIcapture_top\fR;  alternation bar. Automatic callouts can be used for tracking the progress of
34    int          \fIcapture_last\fR;  pattern matching. The
35    void        *\fIcallout_data\fR;  .\" HREF
36    \fBpcretest\fP
37  The \fIversion\fR field is an integer containing the version number of the  .\"
38  block format. The current version is zero. The version number may change in  command has an option that sets automatic callouts; when it is used, the output
39  future if additional fields are added, but the intention is never to remove any  indicates how the pattern is matched. This is useful information when you are
40  of the existing fields.  trying to optimize the performance of a particular pattern.
41    .
42  The \fIcallout_number\fR field contains the number of the callout, as compiled  .
43  into the pattern (that is, the number after ?C).  .SH "MISSING CALLOUTS"
44    .rs
45  The \fIoffset_vector\fR field is a pointer to the vector of offsets that was  .sp
46  passed by the caller to \fBpcre_exec()\fR. The contents can be inspected in  You should be aware that, because of optimizations in the way PCRE matches
47    patterns, callouts sometimes do not happen. For example, if the pattern is
48    .sp
49      ab(?C4)cd
50    .sp
51    PCRE knows that any matching string must contain the letter "d". If the subject
52    string is "abyz", the lack of "d" means that matching doesn't ever start, and
53    the callout is never reached. However, with "abyd", though the result is still
54    no match, the callout is obeyed.
55    .
56    .
57    .SH "THE CALLOUT INTERFACE"
58    .rs
59    .sp
60    During matching, when PCRE reaches a callout point, the external function
61    defined by \fIpcre_callout\fP is called (if it is set). The only argument is a
62    pointer to a \fBpcre_callout\fP block. This structure contains the following
63    fields:
64    .sp
65      int          \fIversion\fP;
66      int          \fIcallout_number\fP;
67      int         *\fIoffset_vector\fP;
68      const char  *\fIsubject\fP;
69      int          \fIsubject_length\fP;
70      int          \fIstart_match\fP;
71      int          \fIcurrent_position\fP;
72      int          \fIcapture_top\fP;
73      int          \fIcapture_last\fP;
74      void        *\fIcallout_data\fP;
75      int          \fIpattern_position\fP;
76      int          \fInext_item_length\fP;
77    .sp
78    The \fIversion\fP field is an integer containing the version number of the
79    block format. The initial version was 0; the current version is 1. The version
80    number will change again in future if additional fields are added, but the
81    intention is never to remove any of the existing fields.
82    .P
83    The \fIcallout_number\fP field contains the number of the callout, as compiled
84    into the pattern (that is, the number after ?C for manual callouts, and 255 for
85    automatically generated callouts).
86    .P
87    The \fIoffset_vector\fP field is a pointer to the vector of offsets that was
88    passed by the caller to \fBpcre_exec()\fP. The contents can be inspected in
89  order to extract substrings that have been matched so far, in the same way as  order to extract substrings that have been matched so far, in the same way as
90  for extracting substrings after a match has completed.  for extracting substrings after a match has completed.
91    .P
92  The \fIsubject\fR and \fIsubject_length\fR fields contain copies the values  The \fIsubject\fP and \fIsubject_length\fP fields contain copies of the values
93  that were passed to \fBpcre_exec()\fR.  that were passed to \fBpcre_exec()\fP.
94    .P
95  The \fIstart_match\fR field contains the offset within the subject at which the  The \fIstart_match\fP field contains the offset within the subject at which the
96  current match attempt started. If the pattern is not anchored, the callout  current match attempt started. If the pattern is not anchored, the callout
97  function may be called several times for different starting points.  function may be called several times from the same point in the pattern for
98    different starting points in the subject.
99  The \fIcurrent_position\fR field contains the offset within the subject of the  .P
100    The \fIcurrent_position\fP field contains the offset within the subject of the
101  current match pointer.  current match pointer.
102    .P
103  The \fIcapture_top\fR field contains one more than the number of the highest  The \fIcapture_top\fP field contains one more than the number of the highest
104  numbered captured substring so far. If no substrings have been captured,  numbered captured substring so far. If no substrings have been captured,
105  the value of \fIcapture_top\fR is one.  the value of \fIcapture_top\fP is one.
106    .P
107  The \fIcapture_last\fR field contains the number of the most recently captured  The \fIcapture_last\fP field contains the number of the most recently captured
108  substring.  substring. If no substrings have been captured, its value is -1.
109    .P
110  The \fIcallout_data\fR field contains a value that is passed to  The \fIcallout_data\fP field contains a value that is passed to
111  \fBpcre_exec()\fR by the caller specifically so that it can be passed back in  \fBpcre_exec()\fP by the caller specifically so that it can be passed back in
112  callouts. It is passed in the \fIpcre_callout\fR field of the \fBpcre_extra\fR  callouts. It is passed in the \fIpcre_callout\fP field of the \fBpcre_extra\fP
113  data structure. If no such data was passed, the value of \fIcallout_data\fR in  data structure. If no such data was passed, the value of \fIcallout_data\fP in
114  a \fBpcre_callout\fR block is NULL. There is a description of the  a \fBpcre_callout\fP block is NULL. There is a description of the
115  \fBpcre_extra\fR structure in the \fBpcreapi\fR documentation.  \fBpcre_extra\fP structure in the
116    .\" HREF
117    \fBpcreapi\fP
118  .SH RETURN VALUES  .\"
119    documentation.
120    .P
121    The \fIpattern_position\fP field is present from version 1 of the
122    \fIpcre_callout\fP structure. It contains the offset to the next item to be
123    matched in the pattern string.
124    .P
125    The \fInext_item_length\fP field is present from version 1 of the
126    \fIpcre_callout\fP structure. It contains the length of the next item to be
127    matched in the pattern string. When the callout immediately precedes an
128    alternation bar, a closing parenthesis, or the end of the pattern, the length
129    is zero. When the callout precedes an opening parenthesis, the length is that
130    of the entire subpattern.
131    .P
132    The \fIpattern_position\fP and \fInext_item_length\fP fields are intended to
133    help in distinguishing between different automatic callouts, which all have the
134    same callout number. However, they are set for all callouts.
135    .
136    .
137    .SH "RETURN VALUES"
138  .rs  .rs
139  .sp  .sp
140  The callout function returns an integer. If the value is zero, matching  The external callout function returns an integer to PCRE. If the value is zero,
141  proceeds as normal. If the value is greater than zero, matching fails at the  matching proceeds as normal. If the value is greater than zero, matching fails
142  current point, but backtracking to test other possibilities goes ahead, just as  at the current point, but backtracking to test other matching possibilities
143  if a lookahead assertion had failed. If the value is less than zero, the match  goes ahead, just as if a lookahead assertion had failed. If the value is less
144  is abandoned, and \fBpcre_exec()\fR returns the value.  than zero, the match is abandoned, and \fBpcre_exec()\fP returns the negative
145    value.
146    .P
147  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
148  values. In particular, PCRE_ERROR_NOMATCH forces a standard "no match" failure.  values. In particular, PCRE_ERROR_NOMATCH forces a standard "no match" failure.
149  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;
150  it will never be used by PCRE itself.  it will never be used by PCRE itself.
151    .P
152  .in 0  .in 0
153  Last updated: 21 January 2003  Last updated: 09 September 2004
154  .br  .br
155  Copyright (c) 1997-2003 University of Cambridge.  Copyright (c) 1997-2004 University of Cambridge.

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

  ViewVC Help
Powered by ViewVC 1.1.5