pcre_fullinfo.c

Go to the documentation of this file.
00001 /*************************************************
00002 *      Perl-Compatible Regular Expressions       *
00003 *************************************************/
00004 
00005 /* PCRE is a library of functions to support regular expressions whose syntax
00006 and semantics are as close as possible to those of the Perl 5 language.
00007 
00008                        Written by Philip Hazel
00009            Copyright (c) 1997-2008 University of Cambridge
00010 
00011 -----------------------------------------------------------------------------
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014 
00015     * Redistributions of source code must retain the above copyright notice,
00016       this list of conditions and the following disclaimer.
00017 
00018     * Redistributions in binary form must reproduce the above copyright
00019       notice, this list of conditions and the following disclaimer in the
00020       documentation and/or other materials provided with the distribution.
00021 
00022     * Neither the name of the University of Cambridge nor the names of its
00023       contributors may be used to endorse or promote products derived from
00024       this software without specific prior written permission.
00025 
00026 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036 POSSIBILITY OF SUCH DAMAGE.
00037 -----------------------------------------------------------------------------
00038 */
00039 
00040 
00041 /* This module contains the external function pcre_fullinfo(), which returns
00042 information about a compiled pattern. */
00043 
00044 
00045 #ifdef HAVE_CONFIG_H
00046 #include "config.h"
00047 #endif
00048 
00049 #include "pcre_internal.h"
00050 
00051 
00052 /*************************************************
00053 *        Return info about compiled pattern      *
00054 *************************************************/
00055 
00056 /* This is a newer "info" function which has an extensible interface so
00057 that additional items can be added compatibly.
00058 
00059 Arguments:
00060   argument_re      points to compiled code
00061   extra_data       points extra data, or NULL
00062   what             what information is required
00063   where            where to put the information
00064 
00065 Returns:           0 if data returned, negative on error
00066 */
00067 
00068 PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
00069 pcre_fullinfo(const pcre *argument_re, const pcre_extra *extra_data, int what,
00070   void *where)
00071 {
00072 real_pcre internal_re;
00073 pcre_study_data internal_study;
00074 const real_pcre *re = (const real_pcre *)argument_re;
00075 const pcre_study_data *study = NULL;
00076 
00077 if (re == NULL || where == NULL) return PCRE_ERROR_NULL;
00078 
00079 if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_STUDY_DATA) != 0)
00080   study = (const pcre_study_data *)extra_data->study_data;
00081 
00082 if (re->magic_number != MAGIC_NUMBER)
00083   {
00084   re = _pcre_try_flipped(re, &internal_re, study, &internal_study);
00085   if (re == NULL) return PCRE_ERROR_BADMAGIC;
00086   if (study != NULL) study = &internal_study;
00087   }
00088 
00089 switch (what)
00090   {
00091   case PCRE_INFO_OPTIONS:
00092   *((unsigned long int *)where) = re->options & PUBLIC_OPTIONS;
00093   break;
00094 
00095   case PCRE_INFO_SIZE:
00096   *((size_t *)where) = re->size;
00097   break;
00098 
00099   case PCRE_INFO_STUDYSIZE:
00100   *((size_t *)where) = (study == NULL)? 0 : study->size;
00101   break;
00102 
00103   case PCRE_INFO_CAPTURECOUNT:
00104   *((int *)where) = re->top_bracket;
00105   break;
00106 
00107   case PCRE_INFO_BACKREFMAX:
00108   *((int *)where) = re->top_backref;
00109   break;
00110 
00111   case PCRE_INFO_FIRSTBYTE:
00112   *((int *)where) =
00113     ((re->flags & PCRE_FIRSTSET) != 0)? re->first_byte :
00114     ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2;
00115   break;
00116 
00117   /* Make sure we pass back the pointer to the bit vector in the external
00118   block, not the internal copy (with flipped integer fields). */
00119 
00120   case PCRE_INFO_FIRSTTABLE:
00121   *((const uschar **)where) =
00122     (study != NULL && (study->options & PCRE_STUDY_MAPPED) != 0)?
00123       ((const pcre_study_data *)extra_data->study_data)->start_bits : NULL;
00124   break;
00125 
00126   case PCRE_INFO_LASTLITERAL:
00127   *((int *)where) =
00128     ((re->flags & PCRE_REQCHSET) != 0)? re->req_byte : -1;
00129   break;
00130 
00131   case PCRE_INFO_NAMEENTRYSIZE:
00132   *((int *)where) = re->name_entry_size;
00133   break;
00134 
00135   case PCRE_INFO_NAMECOUNT:
00136   *((int *)where) = re->name_count;
00137   break;
00138 
00139   case PCRE_INFO_NAMETABLE:
00140   *((const uschar **)where) = (const uschar *)re + re->name_table_offset;
00141   break;
00142 
00143   case PCRE_INFO_DEFAULT_TABLES:
00144   *((const uschar **)where) = (const uschar *)(_pcre_default_tables);
00145   break;
00146 
00147   case PCRE_INFO_OKPARTIAL:
00148   *((int *)where) = (re->flags & PCRE_NOPARTIAL) == 0;
00149   break;
00150 
00151   case PCRE_INFO_JCHANGED:
00152   *((int *)where) = (re->flags & PCRE_JCHANGED) != 0;
00153   break;
00154 
00155   case PCRE_INFO_HASCRORLF:
00156   *((int *)where) = (re->flags & PCRE_HASCRORLF) != 0;
00157   break;
00158 
00159   default: return PCRE_ERROR_BADOPTION;
00160   }
00161 
00162 return 0;
00163 }
00164 
00165 /* End of pcre_fullinfo.c */

Generated on Tue Jul 5 14:11:57 2011 for ROOT_528-00b_version by  doxygen 1.5.1