| 1 |
nigel |
77 |
/************************************************* |
| 2 |
|
|
* Perl-Compatible Regular Expressions * |
| 3 |
|
|
*************************************************/ |
| 4 |
|
|
|
| 5 |
ph10 |
305 |
/* PCRE is a library of functions to support regular expressions whose syntax |
| 6 |
nigel |
77 |
and semantics are as close as possible to those of the Perl 5 language. |
| 7 |
|
|
|
| 8 |
|
|
Written by Philip Hazel |
| 9 |
ph10 |
666 |
Copyright (c) 1997-2011 University of Cambridge |
| 10 |
nigel |
77 |
|
| 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 |
ph10 |
200 |
#ifdef HAVE_CONFIG_H |
| 46 |
ph10 |
236 |
#include "config.h" |
| 47 |
ph10 |
200 |
#endif |
| 48 |
ph10 |
199 |
|
| 49 |
nigel |
77 |
#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 |
ph10 |
359 |
PCRE_EXP_DEFN int PCRE_CALL_CONVENTION |
| 69 |
nigel |
77 |
pcre_fullinfo(const pcre *argument_re, const pcre_extra *extra_data, int what, |
| 70 |
|
|
void *where) |
| 71 |
|
|
{ |
| 72 |
|
|
real_pcre internal_re; |
| 73 |
|
|
pcre_study_data internal_study; |
| 74 |
|
|
const real_pcre *re = (const real_pcre *)argument_re; |
| 75 |
|
|
const pcre_study_data *study = NULL; |
| 76 |
|
|
|
| 77 |
|
|
if (re == NULL || where == NULL) return PCRE_ERROR_NULL; |
| 78 |
|
|
|
| 79 |
|
|
if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_STUDY_DATA) != 0) |
| 80 |
|
|
study = (const pcre_study_data *)extra_data->study_data; |
| 81 |
|
|
|
| 82 |
|
|
if (re->magic_number != MAGIC_NUMBER) |
| 83 |
|
|
{ |
| 84 |
zherczeg |
764 |
re = PRIV(try_flipped)(re, &internal_re, study, &internal_study); |
| 85 |
nigel |
77 |
if (re == NULL) return PCRE_ERROR_BADMAGIC; |
| 86 |
|
|
if (study != NULL) study = &internal_study; |
| 87 |
|
|
} |
| 88 |
|
|
|
| 89 |
|
|
switch (what) |
| 90 |
|
|
{ |
| 91 |
|
|
case PCRE_INFO_OPTIONS: |
| 92 |
ph10 |
389 |
*((unsigned long int *)where) = re->options & PUBLIC_COMPILE_OPTIONS; |
| 93 |
nigel |
77 |
break; |
| 94 |
|
|
|
| 95 |
|
|
case PCRE_INFO_SIZE: |
| 96 |
|
|
*((size_t *)where) = re->size; |
| 97 |
|
|
break; |
| 98 |
|
|
|
| 99 |
|
|
case PCRE_INFO_STUDYSIZE: |
| 100 |
|
|
*((size_t *)where) = (study == NULL)? 0 : study->size; |
| 101 |
|
|
break; |
| 102 |
|
|
|
| 103 |
|
|
case PCRE_INFO_CAPTURECOUNT: |
| 104 |
|
|
*((int *)where) = re->top_bracket; |
| 105 |
|
|
break; |
| 106 |
|
|
|
| 107 |
|
|
case PCRE_INFO_BACKREFMAX: |
| 108 |
|
|
*((int *)where) = re->top_backref; |
| 109 |
|
|
break; |
| 110 |
|
|
|
| 111 |
|
|
case PCRE_INFO_FIRSTBYTE: |
| 112 |
|
|
*((int *)where) = |
| 113 |
zherczeg |
774 |
((re->flags & PCRE_FIRSTSET) != 0)? re->first_char : |
| 114 |
ph10 |
230 |
((re->flags & PCRE_STARTLINE) != 0)? -1 : -2; |
| 115 |
nigel |
77 |
break; |
| 116 |
|
|
|
| 117 |
|
|
/* Make sure we pass back the pointer to the bit vector in the external |
| 118 |
|
|
block, not the internal copy (with flipped integer fields). */ |
| 119 |
|
|
|
| 120 |
|
|
case PCRE_INFO_FIRSTTABLE: |
| 121 |
ph10 |
756 |
*((const pcre_uint8 **)where) = |
| 122 |
ph10 |
455 |
(study != NULL && (study->flags & PCRE_STUDY_MAPPED) != 0)? |
| 123 |
nigel |
77 |
((const pcre_study_data *)extra_data->study_data)->start_bits : NULL; |
| 124 |
|
|
break; |
| 125 |
ph10 |
461 |
|
| 126 |
ph10 |
455 |
case PCRE_INFO_MINLENGTH: |
| 127 |
|
|
*((int *)where) = |
| 128 |
|
|
(study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0)? |
| 129 |
|
|
study->minlength : -1; |
| 130 |
ph10 |
461 |
break; |
| 131 |
nigel |
77 |
|
| 132 |
ph10 |
666 |
case PCRE_INFO_JIT: |
| 133 |
ph10 |
691 |
*((int *)where) = extra_data != NULL && |
| 134 |
ph10 |
666 |
(extra_data->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 && |
| 135 |
|
|
extra_data->executable_jit != NULL; |
| 136 |
|
|
break; |
| 137 |
|
|
|
| 138 |
nigel |
77 |
case PCRE_INFO_LASTLITERAL: |
| 139 |
|
|
*((int *)where) = |
| 140 |
zherczeg |
774 |
((re->flags & PCRE_REQCHSET) != 0)? re->req_char : -1; |
| 141 |
nigel |
77 |
break; |
| 142 |
|
|
|
| 143 |
|
|
case PCRE_INFO_NAMEENTRYSIZE: |
| 144 |
|
|
*((int *)where) = re->name_entry_size; |
| 145 |
|
|
break; |
| 146 |
|
|
|
| 147 |
|
|
case PCRE_INFO_NAMECOUNT: |
| 148 |
|
|
*((int *)where) = re->name_count; |
| 149 |
|
|
break; |
| 150 |
|
|
|
| 151 |
|
|
case PCRE_INFO_NAMETABLE: |
| 152 |
ph10 |
756 |
*((const pcre_uchar **)where) = (const pcre_uchar *)re + re->name_table_offset; |
| 153 |
nigel |
77 |
break; |
| 154 |
|
|
|
| 155 |
|
|
case PCRE_INFO_DEFAULT_TABLES: |
| 156 |
zherczeg |
764 |
*((const pcre_uint8 **)where) = (const pcre_uint8 *)(PRIV(default_tables)); |
| 157 |
nigel |
77 |
break; |
| 158 |
ph10 |
172 |
|
| 159 |
ph10 |
426 |
/* From release 8.00 this will always return TRUE because NOPARTIAL is |
| 160 |
|
|
no longer ever set (the restrictions have been removed). */ |
| 161 |
ph10 |
461 |
|
| 162 |
ph10 |
169 |
case PCRE_INFO_OKPARTIAL: |
| 163 |
ph10 |
230 |
*((int *)where) = (re->flags & PCRE_NOPARTIAL) == 0; |
| 164 |
ph10 |
169 |
break; |
| 165 |
ph10 |
172 |
|
| 166 |
ph10 |
169 |
case PCRE_INFO_JCHANGED: |
| 167 |
ph10 |
230 |
*((int *)where) = (re->flags & PCRE_JCHANGED) != 0; |
| 168 |
ph10 |
172 |
break; |
| 169 |
nigel |
77 |
|
| 170 |
ph10 |
226 |
case PCRE_INFO_HASCRORLF: |
| 171 |
ph10 |
230 |
*((int *)where) = (re->flags & PCRE_HASCRORLF) != 0; |
| 172 |
ph10 |
226 |
break; |
| 173 |
|
|
|
| 174 |
nigel |
77 |
default: return PCRE_ERROR_BADOPTION; |
| 175 |
|
|
} |
| 176 |
|
|
|
| 177 |
|
|
return 0; |
| 178 |
|
|
} |
| 179 |
|
|
|
| 180 |
|
|
/* End of pcre_fullinfo.c */ |