ViewVC logotype

Contents of /code/tags/pcre-5.0/doc/pcrecallout.3

Parent Directory Parent Directory | Revision Log Revision Log

Revision 71 - (show annotations)
Sat Feb 24 21:40:24 2007 UTC (13 years, 7 months ago) by nigel
Original Path: code/trunk/doc/pcrecallout.3
File size: 3922 byte(s)
Load pcre-4.4 into code/trunk.
1 .TH PCRE 3
3 PCRE - Perl-compatible regular expressions
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.
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:
20 (?C1)\dabc(?C2)def
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:
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;
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.
42 The \fIcallout_number\fR field contains the number of the callout, as compiled
43 into the pattern (that is, the number after ?C).
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.
50 The \fIsubject\fR and \fIsubject_length\fR fields contain copies the values
51 that were passed to \fBpcre_exec()\fR.
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.
57 The \fIcurrent_position\fR field contains the offset within the subject of the
58 current match pointer.
60 The \fIcapture_top\fR field contains one more than the number of the highest
61 numbered captured substring so far. If no substrings have been captured,
62 the value of \fIcapture_top\fR is one.
64 The \fIcapture_last\fR field contains the number of the most recently captured
65 substring.
67 The \fIcallout_data\fR field contains a value that is passed to
68 \fBpcre_exec()\fR by the caller specifically so that it can be passed back in
69 callouts. It is passed in the \fIpcre_callout\fR field of the \fBpcre_extra\fR
70 data structure. If no such data was passed, the value of \fIcallout_data\fR in
71 a \fBpcre_callout\fR block is NULL. There is a description of the
72 \fBpcre_extra\fR structure in the \fBpcreapi\fR documentation.
76 .rs
77 .sp
78 The callout function returns an integer. If the value is zero, matching
79 proceeds as normal. If the value is greater than zero, matching fails at the
80 current point, but backtracking to test other possibilities goes ahead, just as
81 if a lookahead assertion had failed. If the value is less than zero, the match
82 is abandoned, and \fBpcre_exec()\fR returns the value.
84 Negative values should normally be chosen from the set of PCRE_ERROR_xxx
85 values. In particular, PCRE_ERROR_NOMATCH forces a standard "no match" failure.
86 The error number PCRE_ERROR_CALLOUT is reserved for use by callout functions;
87 it will never be used by PCRE itself.
89 .in 0
90 Last updated: 21 January 2003
91 .br
92 Copyright (c) 1997-2003 University of Cambridge.

  ViewVC Help
Powered by ViewVC 1.1.5