tin  2.4.5
About: TIN is a threaded NNTP and spool based UseNet newsreader.
  Fossies Dox: tin-2.4.5.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

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