monotone

monotone Mtn Source Tree

Root/pcre/pcre_fullinfo.c

1/*************************************************
2* Perl-Compatible Regular Expressions *
3*************************************************/
4
5/* PCRE is a library of functions to support regular expressions whose syntax
6and semantics are as close as possible to those of the Perl 5 language.
7
8 Written by Philip Hazel
9 Copyright (c) 1997-2008 University of Cambridge
10
11-----------------------------------------------------------------------------
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14
15 * Redistributions of source code must retain the above copyright notice,
16 this list of conditions and the following disclaimer.
17
18 * Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
21
22 * Neither the name of the University of Cambridge nor the names of its
23 contributors may be used to endorse or promote products derived from
24 this software without specific prior written permission.
25
26THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36POSSIBILITY OF SUCH DAMAGE.
37-----------------------------------------------------------------------------
38*/
39
40
41/* This module contains the external function pcre_fullinfo(), which returns
42information about a compiled pattern. */
43
44
45#include "pcre_config.h"
46
47#include "pcre_internal.h"
48
49
50/*************************************************
51* Return info about compiled pattern *
52*************************************************/
53
54/* This is a newer "info" function which has an extensible interface so
55that additional items can be added compatibly.
56
57Arguments:
58 argument_re points to compiled code
59 extra_data points extra data, or NULL
60 what what information is required
61 where where to put the information
62
63Returns: 0 if data returned, negative on error
64*/
65
66PCRE_EXP_DEFN int
67pcre_fullinfo(const pcre *argument_re, const pcre_extra *extra_data, int what,
68 void *where)
69{
70real_pcre internal_re;
71pcre_study_data internal_study;
72const real_pcre *re = (const real_pcre *)argument_re;
73const pcre_study_data *study = NULL;
74
75if (re == NULL || where == NULL) return PCRE_ERROR_NULL;
76
77if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_STUDY_DATA) != 0)
78 study = (const pcre_study_data *)extra_data->study_data;
79
80if (re->magic_number != MAGIC_NUMBER)
81 {
82 re = _pcre_try_flipped(re, &internal_re, study, &internal_study);
83 if (re == NULL) return PCRE_ERROR_BADMAGIC;
84 if (study != NULL) study = &internal_study;
85 }
86
87switch (what)
88 {
89 case PCRE_INFO_OPTIONS:
90 *((unsigned long int *)where) = re->options & PUBLIC_OPTIONS;
91 break;
92
93 case PCRE_INFO_SIZE:
94 *((size_t *)where) = re->size;
95 break;
96
97 case PCRE_INFO_STUDYSIZE:
98 *((size_t *)where) = (study == NULL)? 0 : study->size;
99 break;
100
101 case PCRE_INFO_CAPTURECOUNT:
102 *((int *)where) = re->top_bracket;
103 break;
104
105 case PCRE_INFO_BACKREFMAX:
106 *((int *)where) = re->top_backref;
107 break;
108
109 case PCRE_INFO_FIRSTBYTE:
110 *((int *)where) =
111 ((re->flags & PCRE_FIRSTSET) != 0)? re->first_byte :
112 ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2;
113 break;
114
115 /* Make sure we pass back the pointer to the bit vector in the external
116 block, not the internal copy (with flipped integer fields). */
117
118 case PCRE_INFO_FIRSTTABLE:
119 *((const uschar **)where) =
120 (study != NULL && (study->options & PCRE_STUDY_MAPPED) != 0)?
121 ((const pcre_study_data *)extra_data->study_data)->start_bits : NULL;
122 break;
123
124 case PCRE_INFO_LASTLITERAL:
125 *((int *)where) =
126 ((re->flags & PCRE_REQCHSET) != 0)? re->req_byte : -1;
127 break;
128
129 case PCRE_INFO_NAMEENTRYSIZE:
130 *((int *)where) = re->name_entry_size;
131 break;
132
133 case PCRE_INFO_NAMECOUNT:
134 *((int *)where) = re->name_count;
135 break;
136
137 case PCRE_INFO_NAMETABLE:
138 *((const uschar **)where) = (const uschar *)re + re->name_table_offset;
139 break;
140
141 case PCRE_INFO_DEFAULT_TABLES:
142 *((const uschar **)where) = (const uschar *)(_pcre_default_tables);
143 break;
144
145 case PCRE_INFO_OKPARTIAL:
146 *((int *)where) = (re->flags & PCRE_NOPARTIAL) == 0;
147 break;
148
149 case PCRE_INFO_JCHANGED:
150 *((int *)where) = (re->flags & PCRE_JCHANGED) != 0;
151 break;
152
153 case PCRE_INFO_HASCRORLF:
154 *((int *)where) = (re->flags & PCRE_HASCRORLF) != 0;
155 break;
156
157 default: return PCRE_ERROR_BADOPTION;
158 }
159
160return 0;
161}
162
163/* End of pcre_fullinfo.c */

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status