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-2008 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 "pcre_config.h" |
---|
46 | #include "pcre_internal.h" |
---|
47 | |
---|
48 | |
---|
49 | /************************************************* |
---|
50 | * Return info about compiled pattern * |
---|
51 | *************************************************/ |
---|
52 | |
---|
53 | /* This is a newer "info" function which has an extensible interface so |
---|
54 | that additional items can be added compatibly. |
---|
55 | |
---|
56 | Arguments: |
---|
57 | argument_re points to compiled code |
---|
58 | extra_data points extra data, or NULL |
---|
59 | what what information is required |
---|
60 | where where to put the information |
---|
61 | |
---|
62 | Returns: 0 if data returned, negative on error |
---|
63 | */ |
---|
64 | |
---|
65 | PCRE_EXP_DEFN int PCRE_CALL_CONVENTION |
---|
66 | pcre_fullinfo(const pcre *argument_re, const pcre_extra *extra_data, int what, |
---|
67 | void *where) |
---|
68 | { |
---|
69 | real_pcre internal_re; |
---|
70 | pcre_study_data internal_study; |
---|
71 | const real_pcre *re = (const real_pcre *)argument_re; |
---|
72 | const pcre_study_data *study = NULL; |
---|
73 | |
---|
74 | if (re == NULL || where == NULL) return PCRE_ERROR_NULL; |
---|
75 | |
---|
76 | if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_STUDY_DATA) != 0) |
---|
77 | study = (const pcre_study_data *)extra_data->study_data; |
---|
78 | |
---|
79 | if (re->magic_number != MAGIC_NUMBER) |
---|
80 | { |
---|
81 | re = _pcre_try_flipped(re, &internal_re, study, &internal_study); |
---|
82 | if (re == NULL) return PCRE_ERROR_BADMAGIC; |
---|
83 | if (study != NULL) study = &internal_study; |
---|
84 | } |
---|
85 | |
---|
86 | switch (what) |
---|
87 | { |
---|
88 | case PCRE_INFO_OPTIONS: |
---|
89 | *((unsigned long int *)where) = re->options & PUBLIC_OPTIONS; |
---|
90 | break; |
---|
91 | |
---|
92 | case PCRE_INFO_SIZE: |
---|
93 | *((size_t *)where) = re->size; |
---|
94 | break; |
---|
95 | |
---|
96 | case PCRE_INFO_STUDYSIZE: |
---|
97 | *((size_t *)where) = (study == NULL)? 0 : study->size; |
---|
98 | break; |
---|
99 | |
---|
100 | case PCRE_INFO_CAPTURECOUNT: |
---|
101 | *((int *)where) = re->top_bracket; |
---|
102 | break; |
---|
103 | |
---|
104 | case PCRE_INFO_BACKREFMAX: |
---|
105 | *((int *)where) = re->top_backref; |
---|
106 | break; |
---|
107 | |
---|
108 | case PCRE_INFO_FIRSTBYTE: |
---|
109 | *((int *)where) = |
---|
110 | ((re->flags & PCRE_FIRSTSET) != 0)? re->first_byte : |
---|
111 | ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2; |
---|
112 | break; |
---|
113 | |
---|
114 | /* Make sure we pass back the pointer to the bit vector in the external |
---|
115 | block, not the internal copy (with flipped integer fields). */ |
---|
116 | |
---|
117 | case PCRE_INFO_FIRSTTABLE: |
---|
118 | *((const uschar **)where) = |
---|
119 | (study != NULL && (study->options & PCRE_STUDY_MAPPED) != 0)? |
---|
120 | ((const pcre_study_data *)extra_data->study_data)->start_bits : NULL; |
---|
121 | break; |
---|
122 | |
---|
123 | case PCRE_INFO_LASTLITERAL: |
---|
124 | *((int *)where) = |
---|
125 | ((re->flags & PCRE_REQCHSET) != 0)? re->req_byte : -1; |
---|
126 | break; |
---|
127 | |
---|
128 | case PCRE_INFO_NAMEENTRYSIZE: |
---|
129 | *((int *)where) = re->name_entry_size; |
---|
130 | break; |
---|
131 | |
---|
132 | case PCRE_INFO_NAMECOUNT: |
---|
133 | *((int *)where) = re->name_count; |
---|
134 | break; |
---|
135 | |
---|
136 | case PCRE_INFO_NAMETABLE: |
---|
137 | *((const uschar **)where) = (const uschar *)re + re->name_table_offset; |
---|
138 | break; |
---|
139 | |
---|
140 | case PCRE_INFO_DEFAULT_TABLES: |
---|
141 | *((const uschar **)where) = (const uschar *)(_pcre_default_tables); |
---|
142 | break; |
---|
143 | |
---|
144 | case PCRE_INFO_OKPARTIAL: |
---|
145 | *((int *)where) = (re->flags & PCRE_NOPARTIAL) == 0; |
---|
146 | break; |
---|
147 | |
---|
148 | case PCRE_INFO_JCHANGED: |
---|
149 | *((int *)where) = (re->flags & PCRE_JCHANGED) != 0; |
---|
150 | break; |
---|
151 | |
---|
152 | case PCRE_INFO_HASCRORLF: |
---|
153 | *((int *)where) = (re->flags & PCRE_HASCRORLF) != 0; |
---|
154 | break; |
---|
155 | |
---|
156 | default: return PCRE_ERROR_BADOPTION; |
---|
157 | } |
---|
158 | |
---|
159 | return 0; |
---|
160 | } |
---|
161 | |
---|
162 | /* End of pcre_fullinfo.c */ |
---|