1 |
.TH PCRE 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\fR. By default, this variable contains NULL,
|
13 |
which disables all calling out.
|
14 |
|
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 |
|
20 |
(?C1)\dabc(?C2)def
|
21 |
|
22 |
During matching, when PCRE reaches a callout point (and \fIpcre_callout\fR is
|
23 |
set), the external function is called. Its only argument is a pointer to a
|
24 |
\fBpcre_callout\fR block. This contains the following variables:
|
25 |
|
26 |
int \fIversion\fR;
|
27 |
int \fIcallout_number\fR;
|
28 |
int *\fIoffset_vector\fR;
|
29 |
const char *\fIsubject\fR;
|
30 |
int \fIsubject_length\fR;
|
31 |
int \fIstart_match\fR;
|
32 |
int \fIcurrent_position\fR;
|
33 |
int \fIcapture_top\fR;
|
34 |
int \fIcapture_last\fR;
|
35 |
void *\fIcallout_data\fR;
|
36 |
|
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
|
39 |
future if additional fields are added, but the intention is never to remove any
|
40 |
of the existing fields.
|
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).
|
44 |
|
45 |
The \fIoffset_vector\fR field is a pointer to the vector of offsets that was
|
46 |
passed by the caller to \fBpcre_exec()\fR. The contents can be inspected in
|
47 |
order to extract substrings that have been matched so far, in the same way as
|
48 |
for extracting substrings after a match has completed.
|
49 |
|
50 |
The \fIsubject\fR and \fIsubject_length\fR fields contain copies the values
|
51 |
that were passed to \fBpcre_exec()\fR.
|
52 |
|
53 |
The \fIstart_match\fR field contains the offset within the subject at which the
|
54 |
current match attempt started. If the pattern is not anchored, the callout
|
55 |
function may be called several times for different starting points.
|
56 |
|
57 |
The \fIcurrent_position\fR field contains the offset within the subject of the
|
58 |
current match pointer.
|
59 |
|
60 |
The \fIcapture_top\fR field contains the number of the highest captured
|
61 |
substring so far.
|
62 |
|
63 |
The \fIcapture_last\fR field contains the number of the most recently captured
|
64 |
substring.
|
65 |
|
66 |
The \fIcallout_data\fR field contains a value that is passed to
|
67 |
\fBpcre_exec()\fR by the caller specifically so that it can be passed back in
|
68 |
callouts. It is passed in the \fIpcre_callout\fR field of the \fBpcre_extra\fR
|
69 |
data structure. If no such data was passed, the value of \fIcallout_data\fR in
|
70 |
a \fBpcre_callout\fR block is NULL. There is a description of the
|
71 |
\fBpcre_extra\fR structure in the \fBpcreapi\fR documentation.
|
72 |
|
73 |
|
74 |
.SH RETURN VALUES
|
75 |
.rs
|
76 |
.sp
|
77 |
The callout function returns an integer. If the value is zero, matching
|
78 |
proceeds as normal. If the value is greater than zero, matching fails at the
|
79 |
current point, but backtracking to test other possibilities goes ahead, just as
|
80 |
if a lookahead assertion had failed. If the value is less than zero, the match
|
81 |
is abandoned, and \fBpcre_exec()\fR returns the value.
|
82 |
|
83 |
Negative values should normally be chosen from the set of PCRE_ERROR_xxx
|
84 |
values. In particular, PCRE_ERROR_NOMATCH forces a standard "no match" failure.
|
85 |
The error number PCRE_ERROR_CALLOUT is reserved for use by callout functions;
|
86 |
it will never be used by PCRE itself.
|
87 |
|
88 |
.in 0
|
89 |
Last updated: 21 January 2003
|
90 |
.br
|
91 |
Copyright (c) 1997-2003 University of Cambridge.
|