| 1 |
<html>
|
| 2 |
<head>
|
| 3 |
<title>pcrecallout specification</title>
|
| 4 |
</head>
|
| 5 |
<body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
|
| 6 |
This HTML document has been generated automatically from the original man page.
|
| 7 |
If there is any nonsense in it, please consult the man page, in case the
|
| 8 |
conversion went wrong.<br>
|
| 9 |
<ul>
|
| 10 |
<li><a name="TOC1" href="#SEC1">PCRE CALLOUTS</a>
|
| 11 |
<li><a name="TOC2" href="#SEC2">RETURN VALUES</a>
|
| 12 |
</ul>
|
| 13 |
<br><a name="SEC1" href="#TOC1">PCRE CALLOUTS</a><br>
|
| 14 |
<P>
|
| 15 |
<b>int (*pcre_callout)(pcre_callout_block *);</b>
|
| 16 |
</P>
|
| 17 |
<P>
|
| 18 |
PCRE provides a feature called "callout", which is a means of temporarily
|
| 19 |
passing control to the caller of PCRE in the middle of pattern matching. The
|
| 20 |
caller of PCRE provides an external function by putting its entry point in the
|
| 21 |
global variable <i>pcre_callout</i>. By default, this variable contains NULL,
|
| 22 |
which disables all calling out.
|
| 23 |
</P>
|
| 24 |
<P>
|
| 25 |
Within a regular expression, (?C) indicates the points at which the external
|
| 26 |
function is to be called. Different callout points can be identified by putting
|
| 27 |
a number less than 256 after the letter C. The default value is zero.
|
| 28 |
For example, this pattern has two callout points:
|
| 29 |
</P>
|
| 30 |
<P>
|
| 31 |
<pre>
|
| 32 |
(?C1)\dabc(?C2)def
|
| 33 |
</PRE>
|
| 34 |
</P>
|
| 35 |
<P>
|
| 36 |
During matching, when PCRE reaches a callout point (and <i>pcre_callout</i> is
|
| 37 |
set), the external function is called. Its only argument is a pointer to a
|
| 38 |
<b>pcre_callout</b> block. This contains the following variables:
|
| 39 |
</P>
|
| 40 |
<P>
|
| 41 |
<pre>
|
| 42 |
int <i>version</i>;
|
| 43 |
int <i>callout_number</i>;
|
| 44 |
int *<i>offset_vector</i>;
|
| 45 |
const char *<i>subject</i>;
|
| 46 |
int <i>subject_length</i>;
|
| 47 |
int <i>start_match</i>;
|
| 48 |
int <i>current_position</i>;
|
| 49 |
int <i>capture_top</i>;
|
| 50 |
int <i>capture_last</i>;
|
| 51 |
void *<i>callout_data</i>;
|
| 52 |
</PRE>
|
| 53 |
</P>
|
| 54 |
<P>
|
| 55 |
The <i>version</i> field is an integer containing the version number of the
|
| 56 |
block format. The current version is zero. The version number may change in
|
| 57 |
future if additional fields are added, but the intention is never to remove any
|
| 58 |
of the existing fields.
|
| 59 |
</P>
|
| 60 |
<P>
|
| 61 |
The <i>callout_number</i> field contains the number of the callout, as compiled
|
| 62 |
into the pattern (that is, the number after ?C).
|
| 63 |
</P>
|
| 64 |
<P>
|
| 65 |
The <i>offset_vector</i> field is a pointer to the vector of offsets that was
|
| 66 |
passed by the caller to <b>pcre_exec()</b>. The contents can be inspected in
|
| 67 |
order to extract substrings that have been matched so far, in the same way as
|
| 68 |
for extracting substrings after a match has completed.
|
| 69 |
</P>
|
| 70 |
<P>
|
| 71 |
The <i>subject</i> and <i>subject_length</i> fields contain copies the values
|
| 72 |
that were passed to <b>pcre_exec()</b>.
|
| 73 |
</P>
|
| 74 |
<P>
|
| 75 |
The <i>start_match</i> field contains the offset within the subject at which the
|
| 76 |
current match attempt started. If the pattern is not anchored, the callout
|
| 77 |
function may be called several times for different starting points.
|
| 78 |
</P>
|
| 79 |
<P>
|
| 80 |
The <i>current_position</i> field contains the offset within the subject of the
|
| 81 |
current match pointer.
|
| 82 |
</P>
|
| 83 |
<P>
|
| 84 |
The <i>capture_top</i> field contains the number of the highest captured
|
| 85 |
substring so far.
|
| 86 |
</P>
|
| 87 |
<P>
|
| 88 |
The <i>capture_last</i> field contains the number of the most recently captured
|
| 89 |
substring.
|
| 90 |
</P>
|
| 91 |
<P>
|
| 92 |
The <i>callout_data</i> field contains a value that is passed to
|
| 93 |
<b>pcre_exec()</b> by the caller specifically so that it can be passed back in
|
| 94 |
callouts. It is passed in the <i>pcre_callout</i> field of the <b>pcre_extra</b>
|
| 95 |
data structure. If no such data was passed, the value of <i>callout_data</i> in
|
| 96 |
a <b>pcre_callout</b> block is NULL. There is a description of the
|
| 97 |
<b>pcre_extra</b> structure in the <b>pcreapi</b> documentation.
|
| 98 |
</P>
|
| 99 |
<br><a name="SEC2" href="#TOC1">RETURN VALUES</a><br>
|
| 100 |
<P>
|
| 101 |
The callout function returns an integer. If the value is zero, matching
|
| 102 |
proceeds as normal. If the value is greater than zero, matching fails at the
|
| 103 |
current point, but backtracking to test other possibilities goes ahead, just as
|
| 104 |
if a lookahead assertion had failed. If the value is less than zero, the match
|
| 105 |
is abandoned, and <b>pcre_exec()</b> returns the value.
|
| 106 |
</P>
|
| 107 |
<P>
|
| 108 |
Negative values should normally be chosen from the set of PCRE_ERROR_xxx
|
| 109 |
values. In particular, PCRE_ERROR_NOMATCH forces a standard "no match" failure.
|
| 110 |
The error number PCRE_ERROR_CALLOUT is reserved for use by callout functions;
|
| 111 |
it will never be used by PCRE itself.
|
| 112 |
</P>
|
| 113 |
<P>
|
| 114 |
Last updated: 21 January 2003
|
| 115 |
<br>
|
| 116 |
Copyright © 1997-2003 University of Cambridge.
|