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 |
</ul> |
</ul> |
21 |
<br><a name="SEC1" href="#TOC1">PCRE CALLOUTS</a><br> |
<br><a name="SEC1" href="#TOC1">PCRE CALLOUTS</a><br> |
22 |
<P> |
<P> |
34 |
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 |
35 |
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. |
36 |
For example, this pattern has two callout points: |
For example, this pattern has two callout points: |
|
</P> |
|
|
<P> |
|
37 |
<pre> |
<pre> |
38 |
(?C1)\dabc(?C2)def |
(?C1)\deabc(?C2)def |
39 |
</PRE> |
</pre> |
40 |
</P> |
If the PCRE_AUTO_CALLOUT option bit is set when <b>pcre_compile()</b> is called, |
41 |
<P> |
PCRE automatically inserts callouts, all with number 255, before each item in |
42 |
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 |
43 |
set), the external function is called. Its only argument is a pointer to a |
<pre> |
44 |
<b>pcre_callout</b> block. This contains the following variables: |
A(\d{2}|--) |
45 |
|
</pre> |
46 |
|
it is processed as if it were |
47 |
|
<br> |
48 |
|
<br> |
49 |
|
(?C255)A(?C255)((?C255)\d{2}(?C255)|(?C255)-(?C255)-(?C255))(?C255) |
50 |
|
<br> |
51 |
|
<br> |
52 |
|
Notice that there is a callout before and after each parenthesis and |
53 |
|
alternation bar. Automatic callouts can be used for tracking the progress of |
54 |
|
pattern matching. The |
55 |
|
<a href="pcretest.html"><b>pcretest</b></a> |
56 |
|
command has an option that sets automatic callouts; when it is used, the output |
57 |
|
indicates how the pattern is matched. This is useful information when you are |
58 |
|
trying to optimize the performance of a particular pattern. |
59 |
</P> |
</P> |
60 |
|
<br><a name="SEC2" href="#TOC1">MISSING CALLOUTS</a><br> |
61 |
<P> |
<P> |
62 |
|
You should be aware that, because of optimizations in the way PCRE matches |
63 |
|
patterns, callouts sometimes do not happen. For example, if the pattern is |
64 |
|
<pre> |
65 |
|
ab(?C4)cd |
66 |
|
</pre> |
67 |
|
PCRE knows that any matching string must contain the letter "d". If the subject |
68 |
|
string is "abyz", the lack of "d" means that matching doesn't ever start, and |
69 |
|
the callout is never reached. However, with "abyd", though the result is still |
70 |
|
no match, the callout is obeyed. |
71 |
|
</P> |
72 |
|
<br><a name="SEC3" href="#TOC1">THE CALLOUT INTERFACE</a><br> |
73 |
|
<P> |
74 |
|
During matching, when PCRE reaches a callout point, the external function |
75 |
|
defined by <i>pcre_callout</i> is called (if it is set). The only argument is a |
76 |
|
pointer to a <b>pcre_callout</b> block. This structure contains the following |
77 |
|
fields: |
78 |
<pre> |
<pre> |
79 |
int <i>version</i>; |
int <i>version</i>; |
80 |
int <i>callout_number</i>; |
int <i>callout_number</i>; |
86 |
int <i>capture_top</i>; |
int <i>capture_top</i>; |
87 |
int <i>capture_last</i>; |
int <i>capture_last</i>; |
88 |
void *<i>callout_data</i>; |
void *<i>callout_data</i>; |
89 |
</PRE> |
int <i>pattern_position</i>; |
90 |
</P> |
int <i>next_item_length</i>; |
91 |
<P> |
</pre> |
92 |
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 |
93 |
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 |
94 |
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 |
95 |
of the existing fields. |
intention is never to remove any of the existing fields. |
96 |
</P> |
</P> |
97 |
<P> |
<P> |
98 |
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 |
99 |
into the pattern (that is, the number after ?C). |
into the pattern (that is, the number after ?C for manual callouts, and 255 for |
100 |
|
automatically generated callouts). |
101 |
</P> |
</P> |
102 |
<P> |
<P> |
103 |
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 |
106 |
for extracting substrings after a match has completed. |
for extracting substrings after a match has completed. |
107 |
</P> |
</P> |
108 |
<P> |
<P> |
109 |
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 |
110 |
that were passed to <b>pcre_exec()</b>. |
that were passed to <b>pcre_exec()</b>. |
111 |
</P> |
</P> |
112 |
<P> |
<P> |
113 |
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 |
114 |
current match attempt started. If the pattern is not anchored, the callout |
current match attempt started. If the pattern is not anchored, the callout |
115 |
function may be called several times for different starting points. |
function may be called several times from the same point in the pattern for |
116 |
|
different starting points in the subject. |
117 |
</P> |
</P> |
118 |
<P> |
<P> |
119 |
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 |
126 |
</P> |
</P> |
127 |
<P> |
<P> |
128 |
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 |
129 |
substring. |
substring. If no substrings have been captured, its value is -1. |
130 |
</P> |
</P> |
131 |
<P> |
<P> |
132 |
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 |
134 |
callouts. It is passed in the <i>pcre_callout</i> field of the <b>pcre_extra</b> |
callouts. It is passed in the <i>pcre_callout</i> field of the <b>pcre_extra</b> |
135 |
data structure. If no such data was passed, the value of <i>callout_data</i> in |
data structure. If no such data was passed, the value of <i>callout_data</i> in |
136 |
a <b>pcre_callout</b> block is NULL. There is a description of the |
a <b>pcre_callout</b> block is NULL. There is a description of the |
137 |
<b>pcre_extra</b> structure in the <b>pcreapi</b> documentation. |
<b>pcre_extra</b> structure in the |
138 |
|
<a href="pcreapi.html"><b>pcreapi</b></a> |
139 |
|
documentation. |
140 |
|
</P> |
141 |
|
<P> |
142 |
|
The <i>pattern_position</i> field is present from version 1 of the |
143 |
|
<i>pcre_callout</i> structure. It contains the offset to the next item to be |
144 |
|
matched in the pattern string. |
145 |
|
</P> |
146 |
|
<P> |
147 |
|
The <i>next_item_length</i> field is present from version 1 of the |
148 |
|
<i>pcre_callout</i> structure. It contains the length of the next item to be |
149 |
|
matched in the pattern string. When the callout immediately precedes an |
150 |
|
alternation bar, a closing parenthesis, or the end of the pattern, the length |
151 |
|
is zero. When the callout precedes an opening parenthesis, the length is that |
152 |
|
of the entire subpattern. |
153 |
|
</P> |
154 |
|
<P> |
155 |
|
The <i>pattern_position</i> and <i>next_item_length</i> fields are intended to |
156 |
|
help in distinguishing between different automatic callouts, which all have the |
157 |
|
same callout number. However, they are set for all callouts. |
158 |
</P> |
</P> |
159 |
<br><a name="SEC2" href="#TOC1">RETURN VALUES</a><br> |
<br><a name="SEC4" href="#TOC1">RETURN VALUES</a><br> |
160 |
<P> |
<P> |
161 |
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, |
162 |
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 |
163 |
current point, but backtracking to test other possibilities goes ahead, just as |
at the current point, but backtracking to test other matching possibilities |
164 |
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 |
165 |
is abandoned, and <b>pcre_exec()</b> returns the value. |
than zero, the match is abandoned, and <b>pcre_exec()</b> returns the negative |
166 |
|
value. |
167 |
</P> |
</P> |
168 |
<P> |
<P> |
169 |
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 |
172 |
it will never be used by PCRE itself. |
it will never be used by PCRE itself. |
173 |
</P> |
</P> |
174 |
<P> |
<P> |
175 |
Last updated: 21 January 2003 |
Last updated: 09 September 2004 |
176 |
<br> |
<br> |
177 |
Copyright © 1997-2003 University of Cambridge. |
Copyright © 1997-2004 University of Cambridge. |
178 |
|
<p> |
179 |
|
Return to the <a href="index.html">PCRE index page</a>. |
180 |
|
</p> |