NCBI C++ ToolKit
pcre_fullinfo.c
Go to the documentation of this file.

Go to the SVN repository for this file.

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-2013 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 #if defined COMPILE_PCRE8
70 pcre_fullinfo(const pcre *argument_re, const pcre_extra *extra_data,
71  int what, void *where)
72 #elif defined COMPILE_PCRE16
74 pcre16_fullinfo(const pcre16 *argument_re, const pcre16_extra *extra_data,
75  int what, void *where)
76 #elif defined COMPILE_PCRE32
78 pcre32_fullinfo(const pcre32 *argument_re, const pcre32_extra *extra_data,
79  int what, void *where)
80 #endif
81 {
82 const REAL_PCRE *re = (const REAL_PCRE *)argument_re;
83 const pcre_study_data *study = NULL;
84 
85 if (re == NULL || where == NULL) return PCRE_ERROR_NULL;
86 
87 if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_STUDY_DATA) != 0)
88  study = (const pcre_study_data *)extra_data->study_data;
89 
90 /* Check that the first field in the block is the magic number. If it is not,
91 return with PCRE_ERROR_BADMAGIC. However, if the magic number is equal to
92 REVERSED_MAGIC_NUMBER we return with PCRE_ERROR_BADENDIANNESS, which
93 means that the pattern is likely compiled with different endianness. */
94 
95 if (re->magic_number != MAGIC_NUMBER)
96  return re->magic_number == REVERSED_MAGIC_NUMBER?
98 
99 /* Check that this pattern was compiled in the correct bit mode */
100 
101 if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;
102 
103 switch (what)
104  {
105  case PCRE_INFO_OPTIONS:
106  *((unsigned long int *)where) = re->options & PUBLIC_COMPILE_OPTIONS;
107  break;
108 
109  case PCRE_INFO_SIZE:
110  *((size_t *)where) = re->size;
111  break;
112 
113  case PCRE_INFO_STUDYSIZE:
114  *((size_t *)where) = (study == NULL)? 0 : study->size;
115  break;
116 
117  case PCRE_INFO_JITSIZE:
118 #ifdef SUPPORT_JIT
119  *((size_t *)where) =
120  (extra_data != NULL &&
121  (extra_data->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 &&
122  extra_data->executable_jit != NULL)?
123  PRIV(jit_get_size)(extra_data->executable_jit) : 0;
124 #else
125  *((size_t *)where) = 0;
126 #endif
127  break;
128 
130  *((int *)where) = re->top_bracket;
131  break;
132 
134  *((int *)where) = re->top_backref;
135  break;
136 
137  case PCRE_INFO_FIRSTBYTE:
138  *((int *)where) =
139  ((re->flags & PCRE_FIRSTSET) != 0)? (int)re->first_char :
140  ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2;
141  break;
142 
144  *((pcre_uint32 *)where) =
145  (re->flags & PCRE_FIRSTSET) != 0 ? re->first_char : 0;
146  break;
147 
149  *((int *)where) =
150  ((re->flags & PCRE_FIRSTSET) != 0) ? 1 :
151  ((re->flags & PCRE_STARTLINE) != 0) ? 2 : 0;
152  break;
153 
154  /* Make sure we pass back the pointer to the bit vector in the external
155  block, not the internal copy (with flipped integer fields). */
156 
158  *((const pcre_uint8 **)where) =
159  (study != NULL && (study->flags & PCRE_STUDY_MAPPED) != 0)?
160  ((const pcre_study_data *)extra_data->study_data)->start_bits : NULL;
161  break;
162 
163  case PCRE_INFO_MINLENGTH:
164  *((int *)where) =
165  (study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0)?
166  (int)(study->minlength) : -1;
167  break;
168 
169  case PCRE_INFO_JIT:
170  *((int *)where) = extra_data != NULL &&
171  (extra_data->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 &&
172  extra_data->executable_jit != NULL;
173  break;
174 
176  *((int *)where) =
177  ((re->flags & PCRE_REQCHSET) != 0)? (int)re->req_char : -1;
178  break;
179 
181  *((pcre_uint32 *)where) =
182  ((re->flags & PCRE_REQCHSET) != 0) ? re->req_char : 0;
183  break;
184 
186  *((int *)where) =
187  ((re->flags & PCRE_REQCHSET) != 0);
188  break;
189 
191  *((int *)where) = re->name_entry_size;
192  break;
193 
194  case PCRE_INFO_NAMECOUNT:
195  *((int *)where) = re->name_count;
196  break;
197 
198  case PCRE_INFO_NAMETABLE:
199  *((const pcre_uchar **)where) = (const pcre_uchar *)re + re->name_table_offset;
200  break;
201 
203  *((const pcre_uint8 **)where) = (const pcre_uint8 *)(PRIV(default_tables));
204  break;
205 
206  /* From release 8.00 this will always return TRUE because NOPARTIAL is
207  no longer ever set (the restrictions have been removed). */
208 
209  case PCRE_INFO_OKPARTIAL:
210  *((int *)where) = (re->flags & PCRE_NOPARTIAL) == 0;
211  break;
212 
213  case PCRE_INFO_JCHANGED:
214  *((int *)where) = (re->flags & PCRE_JCHANGED) != 0;
215  break;
216 
217  case PCRE_INFO_HASCRORLF:
218  *((int *)where) = (re->flags & PCRE_HASCRORLF) != 0;
219  break;
220 
222  *((int *)where) = re->max_lookbehind;
223  break;
224 
226  if ((re->flags & PCRE_MLSET) == 0) return PCRE_ERROR_UNSET;
227  *((pcre_uint32 *)where) = re->limit_match;
228  break;
229 
231  if ((re->flags & PCRE_RLSET) == 0) return PCRE_ERROR_UNSET;
232  *((pcre_uint32 *)where) = re->limit_recursion;
233  break;
234 
236  *((int *)where) = (re->flags & PCRE_MATCH_EMPTY) != 0;
237  break;
238 
239  default: return PCRE_ERROR_BADOPTION;
240  }
241 
242 return 0;
243 }
244 
245 /* End of pcre_fullinfo.c */
#define NULL
Definition: ncbistd.hpp:225
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
#define PCRE_INFO_NAMETABLE
Definition: pcre.h:273
#define PCRE_INFO_MAXLOOKBEHIND
Definition: pcre.h:282
#define PCRE_INFO_NAMEENTRYSIZE
Definition: pcre.h:271
#define PCRE_INFO_FIRSTCHARACTERFLAGS
Definition: pcre.h:284
#define PCRE_INFO_OPTIONS
Definition: pcre.h:263
int pcre16_fullinfo(const pcre16 *, const pcre16_extra *, int, void *)
#define PCRE_INFO_SIZE
Definition: pcre.h:264
#define PCRE_INFO_LASTLITERAL
Definition: pcre.h:270
#define PCRE_ERROR_BADMODE
Definition: pcre.h:213
#define PCRE_INFO_CAPTURECOUNT
Definition: pcre.h:265
#define PCRE_EXTRA_STUDY_DATA
Definition: pcre.h:320
#define PCRE_ERROR_BADOPTION
Definition: pcre.h:183
#define PCRE_INFO_JITSIZE
Definition: pcre.h:281
#define PCRE_INFO_BACKREFMAX
Definition: pcre.h:266
#define PCRE_INFO_HASCRORLF
Definition: pcre.h:278
#define PCRE_ERROR_BADMAGIC
Definition: pcre.h:184
#define PCRE_ERROR_BADENDIANNESS
Definition: pcre.h:214
#define PCRE_INFO_FIRSTBYTE
Definition: pcre.h:267
#define PCRE_INFO_NAMECOUNT
Definition: pcre.h:272
#define PCRE_INFO_FIRSTTABLE
Definition: pcre.h:269
#define PCRE_INFO_REQUIREDCHAR
Definition: pcre.h:285
#define PCRE_INFO_FIRSTCHARACTER
Definition: pcre.h:283
#define PCRE_INFO_REQUIREDCHARFLAGS
Definition: pcre.h:286
#define PCRE_INFO_MINLENGTH
Definition: pcre.h:279
#define PCRE_INFO_MATCHLIMIT
Definition: pcre.h:287
#define PCRE_INFO_JIT
Definition: pcre.h:280
#define PCRE_ERROR_NULL
Definition: pcre.h:182
#define PCRE_INFO_MATCH_EMPTY
Definition: pcre.h:289
#define PCRE_INFO_STUDYSIZE
Definition: pcre.h:274
#define PCRE_EXTRA_EXECUTABLE_JIT
Definition: pcre.h:326
#define PCRE_ERROR_UNSET
Definition: pcre.h:218
#define PCRE_INFO_JCHANGED
Definition: pcre.h:277
#define PCRE_INFO_OKPARTIAL
Definition: pcre.h:276
int pcre32_fullinfo(const pcre32 *, const pcre32_extra *, int, void *)
#define PCRE_INFO_DEFAULT_TABLES
Definition: pcre.h:275
#define PCRE_INFO_RECURSIONLIMIT
Definition: pcre.h:288
int pcre_fullinfo(const pcre *argument_re, const pcre_extra *extra_data, int what, void *where)
Definition: pcre_fullinfo.c:70
#define PCRE_MODE
#define REAL_PCRE
#define PCRE_EXP_DEFN
#define PCRE_STUDY_MAPPED
#define MAGIC_NUMBER
#define PUBLIC_COMPILE_OPTIONS
#define REVERSED_MAGIC_NUMBER
#define PCRE_REQCHSET
unsigned char pcre_uint8
#define PCRE_NOPARTIAL
#define PCRE_HASCRORLF
#define PCRE_MLSET
#define PCRE_CALL_CONVENTION
#define PCRE_STUDY_MINLEN
unsigned char pcre_uchar
#define PCRE_FIRSTSET
#define PCRE_RLSET
#define PCRE_JCHANGED
#define PRIV(name)
#define PCRE_MATCH_EMPTY
#define PCRE_STARTLINE
unsigned long int flags
Definition: pcre.h:409
void * executable_jit
Definition: pcre.h:416
void * study_data
Definition: pcre.h:410
pcre_uint32 minlength
pcre_uint32 flags
pcre_uint32 size
Modified on Thu May 23 12:28:57 2024 by modify_doxy.py rev. 669887