/[pcre]/code/branches/pcre16/pcre_fullinfo.c
ViewVC logotype

Contents of /code/branches/pcre16/pcre_fullinfo.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 795 - (show annotations)
Sat Dec 10 02:20:06 2011 UTC (7 years, 8 months ago) by zherczeg
File MIME type: text/plain
File size: 6022 byte(s)
extending the 16 bit API, mode check, and fixes
1 /*************************************************
2 * Perl-Compatible Regular Expressions *
3 *************************************************/
4
5 /* PCRE is a library of functions to support regular expressions whose syntax
6 and semantics are as close as possible to those of the Perl 5 language.
7
8 Written by Philip Hazel
9 Copyright (c) 1997-2011 University of Cambridge
10
11 -----------------------------------------------------------------------------
12 Redistribution and use in source and binary forms, with or without
13 modification, 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
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 POSSIBILITY OF SUCH DAMAGE.
37 -----------------------------------------------------------------------------
38 */
39
40
41 /* This module contains the external function pcre_fullinfo(), which returns
42 information about a compiled pattern. */
43
44
45 #ifdef HAVE_CONFIG_H
46 #include "config.h"
47 #endif
48
49 #include "pcre_internal.h"
50
51
52 /*************************************************
53 * Return info about compiled pattern *
54 *************************************************/
55
56 /* This is a newer "info" function which has an extensible interface so
57 that additional items can be added compatibly.
58
59 Arguments:
60 argument_re points to compiled code
61 extra_data points extra data, or NULL
62 what what information is required
63 where where to put the information
64
65 Returns: 0 if data returned, negative on error
66 */
67
68 #ifdef COMPILE_PCRE8
69 PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
70 pcre_fullinfo(const pcre *argument_re, const pcre_extra *extra_data, int what,
71 void *where)
72 #else
73 PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
74 pcre16_fullinfo(const pcre *argument_re, const pcre_extra *extra_data, int what,
75 void *where)
76 #endif
77 {
78 real_pcre internal_re;
79 pcre_study_data internal_study;
80 const real_pcre *re = (const real_pcre *)argument_re;
81 const pcre_study_data *study = NULL;
82
83 if (re == NULL || where == NULL) return PCRE_ERROR_NULL;
84
85 if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_STUDY_DATA) != 0)
86 study = (const pcre_study_data *)extra_data->study_data;
87
88 if (re->magic_number != MAGIC_NUMBER)
89 {
90 re = PRIV(try_flipped)(re, &internal_re, study, &internal_study);
91 if (re == NULL) return PCRE_ERROR_BADMAGIC;
92 if (study != NULL) study = &internal_study;
93 }
94 if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;
95
96 switch (what)
97 {
98 case PCRE_INFO_OPTIONS:
99 *((unsigned long int *)where) = re->options & PUBLIC_COMPILE_OPTIONS;
100 break;
101
102 case PCRE_INFO_SIZE:
103 *((size_t *)where) = re->size;
104 break;
105
106 case PCRE_INFO_STUDYSIZE:
107 *((size_t *)where) = (study == NULL)? 0 : study->size;
108 break;
109
110 case PCRE_INFO_CAPTURECOUNT:
111 *((int *)where) = re->top_bracket;
112 break;
113
114 case PCRE_INFO_BACKREFMAX:
115 *((int *)where) = re->top_backref;
116 break;
117
118 case PCRE_INFO_FIRSTBYTE:
119 *((int *)where) =
120 ((re->flags & PCRE_FIRSTSET) != 0)? re->first_char :
121 ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2;
122 break;
123
124 /* Make sure we pass back the pointer to the bit vector in the external
125 block, not the internal copy (with flipped integer fields). */
126
127 case PCRE_INFO_FIRSTTABLE:
128 *((const pcre_uint8 **)where) =
129 (study != NULL && (study->flags & PCRE_STUDY_MAPPED) != 0)?
130 ((const pcre_study_data *)extra_data->study_data)->start_bits : NULL;
131 break;
132
133 case PCRE_INFO_MINLENGTH:
134 *((int *)where) =
135 (study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0)?
136 study->minlength : -1;
137 break;
138
139 case PCRE_INFO_JIT:
140 *((int *)where) = extra_data != NULL &&
141 (extra_data->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 &&
142 extra_data->executable_jit != NULL;
143 break;
144
145 case PCRE_INFO_LASTLITERAL:
146 *((int *)where) =
147 ((re->flags & PCRE_REQCHSET) != 0)? re->req_char : -1;
148 break;
149
150 case PCRE_INFO_NAMEENTRYSIZE:
151 *((int *)where) = re->name_entry_size;
152 break;
153
154 case PCRE_INFO_NAMECOUNT:
155 *((int *)where) = re->name_count;
156 break;
157
158 case PCRE_INFO_NAMETABLE:
159 *((const pcre_uchar **)where) = (const pcre_uchar *)re + re->name_table_offset;
160 break;
161
162 case PCRE_INFO_DEFAULT_TABLES:
163 *((const pcre_uint8 **)where) = (const pcre_uint8 *)(PRIV(default_tables));
164 break;
165
166 /* From release 8.00 this will always return TRUE because NOPARTIAL is
167 no longer ever set (the restrictions have been removed). */
168
169 case PCRE_INFO_OKPARTIAL:
170 *((int *)where) = (re->flags & PCRE_NOPARTIAL) == 0;
171 break;
172
173 case PCRE_INFO_JCHANGED:
174 *((int *)where) = (re->flags & PCRE_JCHANGED) != 0;
175 break;
176
177 case PCRE_INFO_HASCRORLF:
178 *((int *)where) = (re->flags & PCRE_HASCRORLF) != 0;
179 break;
180
181 default: return PCRE_ERROR_BADOPTION;
182 }
183
184 return 0;
185 }
186
187 /* End of pcre_fullinfo.c */

Properties

Name Value
svn:eol-style native
svn:keywords "Author Date Id Revision Url"

  ViewVC Help
Powered by ViewVC 1.1.5