/src/glib/glib/pcre/pcre_fullinfo.c
Line | Count | Source (jump to first uncovered line) |
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-2012 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 | | #include "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 |
55 | | that additional items can be added compatibly. |
56 | | |
57 | | Arguments: |
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 | | |
63 | | Returns: 0 if data returned, negative on error |
64 | | */ |
65 | | |
66 | | #ifdef COMPILE_PCRE8 |
67 | | PCRE_EXP_DEFN int PCRE_CALL_CONVENTION |
68 | | pcre_fullinfo(const pcre *argument_re, const pcre_extra *extra_data, |
69 | | int what, void *where) |
70 | | #else |
71 | | PCRE_EXP_DEFN int PCRE_CALL_CONVENTION |
72 | | pcre16_fullinfo(const pcre16 *argument_re, const pcre16_extra *extra_data, |
73 | | int what, void *where) |
74 | | #endif |
75 | 0 | { |
76 | 0 | const REAL_PCRE *re = (const REAL_PCRE *)argument_re; |
77 | 0 | const pcre_study_data *study = NULL; |
78 | |
|
79 | 0 | if (re == NULL || where == NULL) return PCRE_ERROR_NULL; |
80 | | |
81 | 0 | if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_STUDY_DATA) != 0) |
82 | 0 | study = (const pcre_study_data *)extra_data->study_data; |
83 | | |
84 | | /* Check that the first field in the block is the magic number. If it is not, |
85 | | return with PCRE_ERROR_BADMAGIC. However, if the magic number is equal to |
86 | | REVERSED_MAGIC_NUMBER we return with PCRE_ERROR_BADENDIANNESS, which |
87 | | means that the pattern is likely compiled with different endianness. */ |
88 | |
|
89 | 0 | if (re->magic_number != MAGIC_NUMBER) |
90 | 0 | return re->magic_number == REVERSED_MAGIC_NUMBER? |
91 | 0 | PCRE_ERROR_BADENDIANNESS:PCRE_ERROR_BADMAGIC; |
92 | | |
93 | | /* Check that this pattern was compiled in the correct bit mode */ |
94 | | |
95 | 0 | if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE; |
96 | | |
97 | 0 | switch (what) |
98 | 0 | { |
99 | 0 | case PCRE_INFO_OPTIONS: |
100 | 0 | *((unsigned long int *)where) = re->options & PUBLIC_COMPILE_OPTIONS; |
101 | 0 | break; |
102 | | |
103 | 0 | case PCRE_INFO_SIZE: |
104 | 0 | *((size_t *)where) = re->size; |
105 | 0 | break; |
106 | | |
107 | 0 | case PCRE_INFO_STUDYSIZE: |
108 | 0 | *((size_t *)where) = (study == NULL)? 0 : study->size; |
109 | 0 | break; |
110 | | |
111 | 0 | case PCRE_INFO_JITSIZE: |
112 | | #ifdef SUPPORT_JIT |
113 | | *((size_t *)where) = |
114 | | (extra_data != NULL && |
115 | | (extra_data->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 && |
116 | | extra_data->executable_jit != NULL)? |
117 | | PRIV(jit_get_size)(extra_data->executable_jit) : 0; |
118 | | #else |
119 | 0 | *((size_t *)where) = 0; |
120 | 0 | #endif |
121 | 0 | break; |
122 | | |
123 | 0 | case PCRE_INFO_CAPTURECOUNT: |
124 | 0 | *((int *)where) = re->top_bracket; |
125 | 0 | break; |
126 | | |
127 | 0 | case PCRE_INFO_BACKREFMAX: |
128 | 0 | *((int *)where) = re->top_backref; |
129 | 0 | break; |
130 | | |
131 | 0 | case PCRE_INFO_FIRSTBYTE: |
132 | 0 | *((int *)where) = |
133 | 0 | ((re->flags & PCRE_FIRSTSET) != 0)? re->first_char : |
134 | 0 | ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2; |
135 | 0 | break; |
136 | | |
137 | | /* Make sure we pass back the pointer to the bit vector in the external |
138 | | block, not the internal copy (with flipped integer fields). */ |
139 | | |
140 | 0 | case PCRE_INFO_FIRSTTABLE: |
141 | 0 | *((const pcre_uint8 **)where) = |
142 | 0 | (study != NULL && (study->flags & PCRE_STUDY_MAPPED) != 0)? |
143 | 0 | ((const pcre_study_data *)extra_data->study_data)->start_bits : NULL; |
144 | 0 | break; |
145 | | |
146 | 0 | case PCRE_INFO_MINLENGTH: |
147 | 0 | *((int *)where) = |
148 | 0 | (study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0)? |
149 | 0 | (int)(study->minlength) : -1; |
150 | 0 | break; |
151 | | |
152 | 0 | case PCRE_INFO_JIT: |
153 | 0 | *((int *)where) = extra_data != NULL && |
154 | 0 | (extra_data->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 && |
155 | 0 | extra_data->executable_jit != NULL; |
156 | 0 | break; |
157 | | |
158 | 0 | case PCRE_INFO_LASTLITERAL: |
159 | 0 | *((int *)where) = |
160 | 0 | ((re->flags & PCRE_REQCHSET) != 0)? re->req_char : -1; |
161 | 0 | break; |
162 | | |
163 | 0 | case PCRE_INFO_NAMEENTRYSIZE: |
164 | 0 | *((int *)where) = re->name_entry_size; |
165 | 0 | break; |
166 | | |
167 | 0 | case PCRE_INFO_NAMECOUNT: |
168 | 0 | *((int *)where) = re->name_count; |
169 | 0 | break; |
170 | | |
171 | 0 | case PCRE_INFO_NAMETABLE: |
172 | 0 | *((const pcre_uchar **)where) = (const pcre_uchar *)re + re->name_table_offset; |
173 | 0 | break; |
174 | | |
175 | 0 | case PCRE_INFO_DEFAULT_TABLES: |
176 | 0 | *((const pcre_uint8 **)where) = (const pcre_uint8 *)(PRIV(default_tables)); |
177 | 0 | break; |
178 | | |
179 | | /* From release 8.00 this will always return TRUE because NOPARTIAL is |
180 | | no longer ever set (the restrictions have been removed). */ |
181 | | |
182 | 0 | case PCRE_INFO_OKPARTIAL: |
183 | 0 | *((int *)where) = (re->flags & PCRE_NOPARTIAL) == 0; |
184 | 0 | break; |
185 | | |
186 | 0 | case PCRE_INFO_JCHANGED: |
187 | 0 | *((int *)where) = (re->flags & PCRE_JCHANGED) != 0; |
188 | 0 | break; |
189 | | |
190 | 0 | case PCRE_INFO_HASCRORLF: |
191 | 0 | *((int *)where) = (re->flags & PCRE_HASCRORLF) != 0; |
192 | 0 | break; |
193 | | |
194 | 0 | case PCRE_INFO_MAXLOOKBEHIND: |
195 | 0 | *((int *)where) = re->max_lookbehind; |
196 | 0 | break; |
197 | | |
198 | 0 | default: return PCRE_ERROR_BADOPTION; |
199 | 0 | } |
200 | | |
201 | 0 | return 0; |
202 | 0 | } |
203 | | |
204 | | /* End of pcre_fullinfo.c */ |