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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 392 - (show annotations)
Tue Mar 17 21:30:30 2009 UTC (10 years, 7 months ago) by ph10
File size: 7370 byte(s)
Update after detrailing for a test release.
1 .TH PCRECALLOUT 3
2 .SH NAME
3 PCRE - Perl-compatible regular expressions
4 .SH "PCRE CALLOUTS"
5 .rs
6 .sp
7 .B int (*pcre_callout)(pcre_callout_block *);
8 .PP
9 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
11 caller of PCRE provides an external function by putting its entry point in the
12 global variable \fIpcre_callout\fP. By default, this variable contains NULL,
13 which disables all calling out.
14 .P
15 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
17 a number less than 256 after the letter C. The default value is zero.
18 For example, this pattern has two callout points:
19 .sp
20 (?C1)abc(?C2)def
21 .sp
22 If the PCRE_AUTO_CALLOUT option bit is set when \fBpcre_compile()\fP is called,
23 PCRE automatically inserts callouts, all with number 255, before each item in
24 the pattern. For example, if PCRE_AUTO_CALLOUT is used with the pattern
25 .sp
26 A(\ed{2}|--)
27 .sp
28 it is processed as if it were
29 .sp
30 (?C255)A(?C255)((?C255)\ed{2}(?C255)|(?C255)-(?C255)-(?C255))(?C255)
31 .sp
32 Notice that there is a callout before and after each parenthesis and
33 alternation bar. Automatic callouts can be used for tracking the progress of
34 pattern matching. The
35 .\" HREF
36 \fBpcretest\fP
37 .\"
38 command has an option that sets automatic callouts; when it is used, the output
39 indicates how the pattern is matched. This is useful information when you are
40 trying to optimize the performance of a particular pattern.
41 .
42 .
43 .SH "MISSING CALLOUTS"
44 .rs
45 .sp
46 You should be aware that, because of optimizations in the way PCRE matches
47 patterns by default, callouts sometimes do not happen. For example, if the
48 pattern is
49 .sp
50 ab(?C4)cd
51 .sp
52 PCRE knows that any matching string must contain the letter "d". If the subject
53 string is "abyz", the lack of "d" means that matching doesn't ever start, and
54 the callout is never reached. However, with "abyd", though the result is still
55 no match, the callout is obeyed.
56 .P
57 You can disable these optimizations by passing the PCRE_NO_START_OPTIMIZE
58 option to \fBpcre_exec()\fP or \fBpcre_dfa_exec()\fP. This slows down the
59 matching process, but does ensure that callouts such as the example above are
60 obeyed.
61 .
62 .
63 .SH "THE CALLOUT INTERFACE"
64 .rs
65 .sp
66 During matching, when PCRE reaches a callout point, the external function
67 defined by \fIpcre_callout\fP is called (if it is set). This applies to both
68 the \fBpcre_exec()\fP and the \fBpcre_dfa_exec()\fP matching functions. The
69 only argument to the callout function is a pointer to a \fBpcre_callout\fP
70 block. This structure contains the following fields:
71 .sp
72 int \fIversion\fP;
73 int \fIcallout_number\fP;
74 int *\fIoffset_vector\fP;
75 const char *\fIsubject\fP;
76 int \fIsubject_length\fP;
77 int \fIstart_match\fP;
78 int \fIcurrent_position\fP;
79 int \fIcapture_top\fP;
80 int \fIcapture_last\fP;
81 void *\fIcallout_data\fP;
82 int \fIpattern_position\fP;
83 int \fInext_item_length\fP;
84 .sp
85 The \fIversion\fP field is an integer containing the version number of the
86 block format. The initial version was 0; the current version is 1. The version
87 number will change again in future if additional fields are added, but the
88 intention is never to remove any of the existing fields.
89 .P
90 The \fIcallout_number\fP field contains the number of the callout, as compiled
91 into the pattern (that is, the number after ?C for manual callouts, and 255 for
92 automatically generated callouts).
93 .P
94 The \fIoffset_vector\fP field is a pointer to the vector of offsets that was
95 passed by the caller to \fBpcre_exec()\fP or \fBpcre_dfa_exec()\fP. When
96 \fBpcre_exec()\fP is used, the contents can be inspected in order to extract
97 substrings that have been matched so far, in the same way as for extracting
98 substrings after a match has completed. For \fBpcre_dfa_exec()\fP this field is
99 not useful.
100 .P
101 The \fIsubject\fP and \fIsubject_length\fP fields contain copies of the values
102 that were passed to \fBpcre_exec()\fP.
103 .P
104 The \fIstart_match\fP field normally contains the offset within the subject at
105 which the current match attempt started. However, if the escape sequence \eK
106 has been encountered, this value is changed to reflect the modified starting
107 point. If the pattern is not anchored, the callout function may be called
108 several times from the same point in the pattern for different starting points
109 in the subject.
110 .P
111 The \fIcurrent_position\fP field contains the offset within the subject of the
112 current match pointer.
113 .P
114 When the \fBpcre_exec()\fP function is used, the \fIcapture_top\fP field
115 contains one more than the number of the highest numbered captured substring so
116 far. If no substrings have been captured, the value of \fIcapture_top\fP is
117 one. This is always the case when \fBpcre_dfa_exec()\fP is used, because it
118 does not support captured substrings.
119 .P
120 The \fIcapture_last\fP field contains the number of the most recently captured
121 substring. If no substrings have been captured, its value is -1. This is always
122 the case when \fBpcre_dfa_exec()\fP is used.
123 .P
124 The \fIcallout_data\fP field contains a value that is passed to
125 \fBpcre_exec()\fP or \fBpcre_dfa_exec()\fP specifically so that it can be
126 passed back in callouts. It is passed in the \fIpcre_callout\fP field of the
127 \fBpcre_extra\fP data structure. If no such data was passed, the value of
128 \fIcallout_data\fP in a \fBpcre_callout\fP block is NULL. There is a
129 description of the \fBpcre_extra\fP structure in the
130 .\" HREF
131 \fBpcreapi\fP
132 .\"
133 documentation.
134 .P
135 The \fIpattern_position\fP field is present from version 1 of the
136 \fIpcre_callout\fP structure. It contains the offset to the next item to be
137 matched in the pattern string.
138 .P
139 The \fInext_item_length\fP field is present from version 1 of the
140 \fIpcre_callout\fP structure. It contains the length of the next item to be
141 matched in the pattern string. When the callout immediately precedes an
142 alternation bar, a closing parenthesis, or the end of the pattern, the length
143 is zero. When the callout precedes an opening parenthesis, the length is that
144 of the entire subpattern.
145 .P
146 The \fIpattern_position\fP and \fInext_item_length\fP fields are intended to
147 help in distinguishing between different automatic callouts, which all have the
148 same callout number. However, they are set for all callouts.
149 .
150 .
151 .SH "RETURN VALUES"
152 .rs
153 .sp
154 The external callout function returns an integer to PCRE. If the value is zero,
155 matching proceeds as normal. If the value is greater than zero, matching fails
156 at the current point, but the testing of other matching possibilities goes
157 ahead, just as if a lookahead assertion had failed. If the value is less than
158 zero, the match is abandoned, and \fBpcre_exec()\fP (or \fBpcre_dfa_exec()\fP)
159 returns the negative value.
160 .P
161 Negative values should normally be chosen from the set of PCRE_ERROR_xxx
162 values. In particular, PCRE_ERROR_NOMATCH forces a standard "no match" failure.
163 The error number PCRE_ERROR_CALLOUT is reserved for use by callout functions;
164 it will never be used by PCRE itself.
165 .
166 .
167 .SH AUTHOR
168 .rs
169 .sp
170 .nf
171 Philip Hazel
172 University Computing Service
173 Cambridge CB2 3QH, England.
174 .fi
175 .
176 .
177 .SH REVISION
178 .rs
179 .sp
180 .nf
181 Last updated: 15 March 2009
182 Copyright (c) 1997-2009 University of Cambridge.
183 .fi

Properties

Name Value
svn:eol-style native
svn:keywords "Author Date Id Revision Url"

  ViewVC Help
Powered by ViewVC 1.1.5