• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/pcre/pcre_fullinfo.c

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