Back to index

php5  5.3.10
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-2009 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 #include "config.h"
00046 
00047 #include "pcre_internal.h"
00048 
00049 
00050 /*************************************************
00051 *        Return info about compiled pattern      *
00052 *************************************************/
00053 
00054 /* This is a newer "info" function which has an extensible interface so
00055 that additional items can be added compatibly.
00056 
00057 Arguments:
00058   argument_re      points to compiled code
00059   extra_data       points extra data, or NULL
00060   what             what information is required
00061   where            where to put the information
00062 
00063 Returns:           0 if data returned, negative on error
00064 */
00065 
00066 PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
00067 pcre_fullinfo(const pcre *argument_re, const pcre_extra *extra_data, int what,
00068   void *where)
00069 {
00070 real_pcre internal_re;
00071 pcre_study_data internal_study;
00072 const real_pcre *re = (const real_pcre *)argument_re;
00073 const pcre_study_data *study = NULL;
00074 
00075 if (re == NULL || where == NULL) return PCRE_ERROR_NULL;
00076 
00077 if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_STUDY_DATA) != 0)
00078   study = (const pcre_study_data *)extra_data->study_data;
00079 
00080 if (re->magic_number != MAGIC_NUMBER)
00081   {
00082   re = _pcre_try_flipped(re, &internal_re, study, &internal_study);
00083   if (re == NULL) return PCRE_ERROR_BADMAGIC;
00084   if (study != NULL) study = &internal_study;
00085   }
00086 
00087 switch (what)
00088   {
00089   case PCRE_INFO_OPTIONS:
00090   *((unsigned long int *)where) = re->options & PUBLIC_COMPILE_OPTIONS;
00091   break;
00092 
00093   case PCRE_INFO_SIZE:
00094   *((size_t *)where) = re->size;
00095   break;
00096 
00097   case PCRE_INFO_STUDYSIZE:
00098   *((size_t *)where) = (study == NULL)? 0 : study->size;
00099   break;
00100 
00101   case PCRE_INFO_CAPTURECOUNT:
00102   *((int *)where) = re->top_bracket;
00103   break;
00104 
00105   case PCRE_INFO_BACKREFMAX:
00106   *((int *)where) = re->top_backref;
00107   break;
00108 
00109   case PCRE_INFO_FIRSTBYTE:
00110   *((int *)where) =
00111     ((re->flags & PCRE_FIRSTSET) != 0)? re->first_byte :
00112     ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2;
00113   break;
00114 
00115   /* Make sure we pass back the pointer to the bit vector in the external
00116   block, not the internal copy (with flipped integer fields). */
00117 
00118   case PCRE_INFO_FIRSTTABLE:
00119   *((const uschar **)where) =
00120     (study != NULL && (study->flags & PCRE_STUDY_MAPPED) != 0)?
00121       ((const pcre_study_data *)extra_data->study_data)->start_bits : NULL;
00122   break;
00123 
00124   case PCRE_INFO_MINLENGTH:
00125   *((int *)where) =
00126     (study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0)?
00127       study->minlength : -1;
00128   break;
00129 
00130   case PCRE_INFO_LASTLITERAL:
00131   *((int *)where) =
00132     ((re->flags & PCRE_REQCHSET) != 0)? re->req_byte : -1;
00133   break;
00134 
00135   case PCRE_INFO_NAMEENTRYSIZE:
00136   *((int *)where) = re->name_entry_size;
00137   break;
00138 
00139   case PCRE_INFO_NAMECOUNT:
00140   *((int *)where) = re->name_count;
00141   break;
00142 
00143   case PCRE_INFO_NAMETABLE:
00144   *((const uschar **)where) = (const uschar *)re + re->name_table_offset;
00145   break;
00146 
00147   case PCRE_INFO_DEFAULT_TABLES:
00148   *((const uschar **)where) = (const uschar *)(_pcre_default_tables);
00149   break;
00150 
00151   /* From release 8.00 this will always return TRUE because NOPARTIAL is
00152   no longer ever set (the restrictions have been removed). */
00153 
00154   case PCRE_INFO_OKPARTIAL:
00155   *((int *)where) = (re->flags & PCRE_NOPARTIAL) == 0;
00156   break;
00157 
00158   case PCRE_INFO_JCHANGED:
00159   *((int *)where) = (re->flags & PCRE_JCHANGED) != 0;
00160   break;
00161 
00162   case PCRE_INFO_HASCRORLF:
00163   *((int *)where) = (re->flags & PCRE_HASCRORLF) != 0;
00164   break;
00165 
00166   default: return PCRE_ERROR_BADOPTION;
00167   }
00168 
00169 return 0;
00170 }
00171 
00172 /* End of pcre_fullinfo.c */