1PCRECALLOUT(3)             Library Functions Manual             PCRECALLOUT(3)
2
3
4

NAME

6       PCRE - Perl-compatible regular expressions
7

SYNOPSIS

9
10       #include <pcre.h>
11
12       int (*pcre_callout)(pcre_callout_block *);
13
14       int (*pcre16_callout)(pcre16_callout_block *);
15
16       int (*pcre32_callout)(pcre32_callout_block *);
17

DESCRIPTION

19
20       PCRE provides a feature called "callout", which is a means of temporar‐
21       ily passing control to the caller of PCRE  in  the  middle  of  pattern
22       matching.  The  caller of PCRE provides an external function by putting
23       its entry point in the global variable pcre_callout (pcre16_callout for
24       the 16-bit library, pcre32_callout for the 32-bit library). By default,
25       this variable contains NULL, which disables all calling out.
26
27       Within a regular expression, (?C) indicates the  points  at  which  the
28       external  function  is  to  be  called. Different callout points can be
29       identified by putting a number less than 256 after the  letter  C.  The
30       default  value  is  zero.   For  example,  this pattern has two callout
31       points:
32
33         (?C1)abc(?C2)def
34
35       If the PCRE_AUTO_CALLOUT option bit is set when a pattern is  compiled,
36       PCRE  automatically  inserts callouts, all with number 255, before each
37       item in the pattern. For example, if PCRE_AUTO_CALLOUT is used with the
38       pattern
39
40         A(\d{2}|--)
41
42       it is processed as if it were
43
44       (?C255)A(?C255)((?C255)\d{2}(?C255)|(?C255)-(?C255)-(?C255))(?C255)
45
46       Notice  that  there  is a callout before and after each parenthesis and
47       alternation bar. Automatic  callouts  can  be  used  for  tracking  the
48       progress  of  pattern matching. The pcretest command has an option that
49       sets automatic callouts; when it is used, the output indicates how  the
50       pattern  is  matched. This is useful information when you are trying to
51       optimize the performance of a particular pattern.
52
53       The use of callouts in a pattern makes it ineligible  for  optimization
54       by  the  just-in-time  compiler.  Studying  such  a  pattern  with  the
55       PCRE_STUDY_JIT_COMPILE option always fails.
56

MISSING CALLOUTS

58
59       You should be aware that, because of  optimizations  in  the  way  PCRE
60       matches  patterns  by  default,  callouts  sometimes do not happen. For
61       example, if the pattern is
62
63         ab(?C4)cd
64
65       PCRE knows that any matching string must contain the letter "d". If the
66       subject  string  is "abyz", the lack of "d" means that matching doesn't
67       ever start, and the callout is never  reached.  However,  with  "abyd",
68       though the result is still no match, the callout is obeyed.
69
70       If  the pattern is studied, PCRE knows the minimum length of a matching
71       string, and will immediately give a "no match" return without  actually
72       running  a  match if the subject is not long enough, or, for unanchored
73       patterns, if it has been scanned far enough.
74
75       You can disable these optimizations by passing the  PCRE_NO_START_OPTI‐
76       MIZE  option  to the matching function, or by starting the pattern with
77       (*NO_START_OPT). This slows down the matching process, but does  ensure
78       that callouts such as the example above are obeyed.
79

THE CALLOUT INTERFACE

81
82       During  matching, when PCRE reaches a callout point, the external func‐
83       tion defined by pcre_callout or pcre[16|32]_callout is called (if it is
84       set).  This  applies to both normal and DFA matching. The only argument
85       to  the  callout  function  is  a  pointer   to   a   pcre_callout   or
86       pcre[16|32]_callout  block.   These  structures  contains the following
87       fields:
88
89         int           version;
90         int           callout_number;
91         int          *offset_vector;
92         const char   *subject;           (8-bit version)
93         PCRE_SPTR16   subject;           (16-bit version)
94         PCRE_SPTR32   subject;           (32-bit version)
95         int           subject_length;
96         int           start_match;
97         int           current_position;
98         int           capture_top;
99         int           capture_last;
100         void         *callout_data;
101         int           pattern_position;
102         int           next_item_length;
103         const unsigned char *mark;       (8-bit version)
104         const PCRE_UCHAR16  *mark;       (16-bit version)
105         const PCRE_UCHAR32  *mark;       (32-bit version)
106
107       The version field is an integer containing the version  number  of  the
108       block  format. The initial version was 0; the current version is 2. The
109       version number will change again in future  if  additional  fields  are
110       added, but the intention is never to remove any of the existing fields.
111
112       The  callout_number  field  contains the number of the callout, as com‐
113       piled into the pattern (that is, the number after ?C for  manual  call‐
114       outs, and 255 for automatically generated callouts).
115
116       The  offset_vector field is a pointer to the vector of offsets that was
117       passed by the caller to the  matching  function.  When  pcre_exec()  or
118       pcre[16|32]_exec()  is used, the contents can be inspected, in order to
119       extract substrings that have been matched so far, in the  same  way  as
120       for  extracting  substrings  after  a  match has completed. For the DFA
121       matching functions, this field is not useful.
122
123       The subject and subject_length fields contain copies of the values that
124       were passed to the matching function.
125
126       The  start_match  field normally contains the offset within the subject
127       at which the current match attempt  started.  However,  if  the  escape
128       sequence  \K has been encountered, this value is changed to reflect the
129       modified starting point. If the pattern is not  anchored,  the  callout
130       function may be called several times from the same point in the pattern
131       for different starting points in the subject.
132
133       The current_position field contains the offset within  the  subject  of
134       the current match pointer.
135
136       When  the  pcre_exec()  or  pcre[16|32]_exec() is used, the capture_top
137       field contains one more than the number of the  highest  numbered  cap‐
138       tured  substring so far. If no substrings have been captured, the value
139       of capture_top is one. This is always the case when the  DFA  functions
140       are used, because they do not support captured substrings.
141
142       The  capture_last  field  contains the number of the most recently cap‐
143       tured substring. If no substrings have been captured, its value is  -1.
144       This is always the case for the DFA matching functions.
145
146       The  callout_data  field  contains a value that is passed to a matching
147       function specifically so that it can be passed back in callouts. It  is
148       passed  in  the callout_data field of a pcre_extra or pcre[16|32]_extra
149       data structure. If no such data was passed, the value  of  callout_data
150       in  a  callout  block is NULL. There is a description of the pcre_extra
151       structure in the pcreapi documentation.
152
153       The pattern_position field is present from version  1  of  the  callout
154       structure. It contains the offset to the next item to be matched in the
155       pattern string.
156
157       The next_item_length field is present from version  1  of  the  callout
158       structure. It contains the length of the next item to be matched in the
159       pattern string. When the callout immediately  precedes  an  alternation
160       bar,  a  closing  parenthesis, or the end of the pattern, the length is
161       zero. When the callout precedes an opening parenthesis, the  length  is
162       that of the entire subpattern.
163
164       The  pattern_position  and next_item_length fields are intended to help
165       in distinguishing between different automatic callouts, which all  have
166       the same callout number. However, they are set for all callouts.
167
168       The  mark  field is present from version 2 of the callout structure. In
169       callouts from pcre_exec() or pcre[16|32]_exec() it contains  a  pointer
170       to  the  zero-terminated  name  of  the  most  recently passed (*MARK),
171       (*PRUNE), or (*THEN) item in the match, or NULL if no such  items  have
172       been  passed.  Instances  of  (*PRUNE) or (*THEN) without a name do not
173       obliterate a previous (*MARK). In callouts from the DFA matching  func‐
174       tions this field always contains NULL.
175

RETURN VALUES

177
178       The  external callout function returns an integer to PCRE. If the value
179       is zero, matching proceeds as normal. If  the  value  is  greater  than
180       zero,  matching  fails  at  the current point, but the testing of other
181       matching possibilities goes ahead, just as if a lookahead assertion had
182       failed.  If  the  value  is less than zero, the match is abandoned, the
183       matching function returns the negative value.
184
185       Negative  values  should  normally  be   chosen   from   the   set   of
186       PCRE_ERROR_xxx values. In particular, PCRE_ERROR_NOMATCH forces a stan‐
187       dard "no  match"  failure.   The  error  number  PCRE_ERROR_CALLOUT  is
188       reserved  for  use  by callout functions; it will never be used by PCRE
189       itself.
190

AUTHOR

192
193       Philip Hazel
194       University Computing Service
195       Cambridge CB2 3QH, England.
196

REVISION

198
199       Last updated: 24 June 2012
200       Copyright (c) 1997-2012 University of Cambridge.
201
202
203
204PCRE 8.30                        24 June 2012                   PCRECALLOUT(3)
Impressum