Path: blob/master/thirdparty/pcre2/src/pcre2_config.c
21928 views
/*************************************************1* Perl-Compatible Regular Expressions *2*************************************************/34/* PCRE is a library of functions to support regular expressions whose syntax5and semantics are as close as possible to those of the Perl 5 language.67Written by Philip Hazel8Original API code Copyright (c) 1997-2012 University of Cambridge9New API code Copyright (c) 2016-2020 University of Cambridge1011-----------------------------------------------------------------------------12Redistribution and use in source and binary forms, with or without13modification, are permitted provided that the following conditions are met:1415* Redistributions of source code must retain the above copyright notice,16this list of conditions and the following disclaimer.1718* Redistributions in binary form must reproduce the above copyright19notice, this list of conditions and the following disclaimer in the20documentation and/or other materials provided with the distribution.2122* Neither the name of the University of Cambridge nor the names of its23contributors may be used to endorse or promote products derived from24this software without specific prior written permission.2526THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"27AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE28IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE29ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE30LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR31CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF32SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS33INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN34CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)35ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE36POSSIBILITY OF SUCH DAMAGE.37-----------------------------------------------------------------------------38*/394041#include "pcre2_internal.h"42434445/* These macros are the standard way of turning unquoted text into C strings.46They allow macros like PCRE2_MAJOR to be defined without quotes, which is47convenient for user programs that want to test their values. */4849#define STRING(a) # a50#define XSTRING(s) STRING(s)515253/*************************************************54* Return info about what features are configured *55*************************************************/5657/* If where is NULL, the length of memory required is returned.5859Arguments:60what what information is required61where where to put the information6263Returns: 0 if a numerical value is returned64>= 0 if a string value65PCRE2_ERROR_BADOPTION if "where" not recognized66or JIT target requested when JIT not enabled67*/6869PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION70pcre2_config(uint32_t what, void *where)71{72if (where == NULL) /* Requests a length */73{74switch (what)75{76default:77return PCRE2_ERROR_BADOPTION;7879case PCRE2_CONFIG_BSR:80case PCRE2_CONFIG_COMPILED_WIDTHS:81case PCRE2_CONFIG_DEPTHLIMIT:82case PCRE2_CONFIG_EFFECTIVE_LINKSIZE:83case PCRE2_CONFIG_HEAPLIMIT:84case PCRE2_CONFIG_JIT:85case PCRE2_CONFIG_LINKSIZE:86case PCRE2_CONFIG_MATCHLIMIT:87case PCRE2_CONFIG_NEVER_BACKSLASH_C:88case PCRE2_CONFIG_NEWLINE:89case PCRE2_CONFIG_PARENSLIMIT:90case PCRE2_CONFIG_STACKRECURSE: /* Obsolete */91case PCRE2_CONFIG_TABLES_LENGTH:92case PCRE2_CONFIG_UNICODE:93return sizeof(uint32_t);9495/* These are handled below */9697case PCRE2_CONFIG_JITTARGET:98case PCRE2_CONFIG_UNICODE_VERSION:99case PCRE2_CONFIG_VERSION:100break;101}102}103104switch (what)105{106default:107return PCRE2_ERROR_BADOPTION;108109case PCRE2_CONFIG_BSR:110#ifdef BSR_ANYCRLF111*((uint32_t *)where) = PCRE2_BSR_ANYCRLF;112#else113*((uint32_t *)where) = PCRE2_BSR_UNICODE;114#endif115break;116117case PCRE2_CONFIG_COMPILED_WIDTHS:118*((uint32_t *)where) = 0119#ifdef SUPPORT_PCRE2_8120+ (1 << 0)121#endif122#ifdef SUPPORT_PCRE2_16123+ (1 << 1)124#endif125#ifdef SUPPORT_PCRE2_32126+ (1 << 2)127#endif128;129break;130131case PCRE2_CONFIG_DEPTHLIMIT:132*((uint32_t *)where) = MATCH_LIMIT_DEPTH;133break;134135case PCRE2_CONFIG_EFFECTIVE_LINKSIZE:136*((uint32_t *)where) = LINK_SIZE * sizeof(PCRE2_UCHAR);137break;138139case PCRE2_CONFIG_HEAPLIMIT:140*((uint32_t *)where) = HEAP_LIMIT;141break;142143case PCRE2_CONFIG_JIT:144#ifdef SUPPORT_JIT145*((uint32_t *)where) = 1;146#else147*((uint32_t *)where) = 0;148#endif149break;150151case PCRE2_CONFIG_JITTARGET:152#ifdef SUPPORT_JIT153{154const char *v = PRIV(jit_get_target)();155return (int)(1 + ((where == NULL)?156strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));157}158#else159return PCRE2_ERROR_BADOPTION;160#endif161162case PCRE2_CONFIG_LINKSIZE:163*((uint32_t *)where) = (uint32_t)CONFIGURED_LINK_SIZE;164break;165166case PCRE2_CONFIG_MATCHLIMIT:167*((uint32_t *)where) = MATCH_LIMIT;168break;169170case PCRE2_CONFIG_NEWLINE:171*((uint32_t *)where) = NEWLINE_DEFAULT;172break;173174case PCRE2_CONFIG_NEVER_BACKSLASH_C:175#ifdef NEVER_BACKSLASH_C176*((uint32_t *)where) = 1;177#else178*((uint32_t *)where) = 0;179#endif180break;181182case PCRE2_CONFIG_PARENSLIMIT:183*((uint32_t *)where) = PARENS_NEST_LIMIT;184break;185186/* This is now obsolete. The stack is no longer used via recursion for187handling backtracking in pcre2_match(). */188189case PCRE2_CONFIG_STACKRECURSE:190*((uint32_t *)where) = 0;191break;192193case PCRE2_CONFIG_TABLES_LENGTH:194*((uint32_t *)where) = TABLES_LENGTH;195break;196197case PCRE2_CONFIG_UNICODE_VERSION:198{199#if defined SUPPORT_UNICODE200const char *v = PRIV(unicode_version);201#else202const char *v = "Unicode not supported";203#endif204return (int)(1 + ((where == NULL)?205strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));206}207208case PCRE2_CONFIG_UNICODE:209#if defined SUPPORT_UNICODE210*((uint32_t *)where) = 1;211#else212*((uint32_t *)where) = 0;213#endif214break;215216/* The hackery in setting "v" below is to cope with the case when217PCRE2_PRERELEASE is set to an empty string (which it is for real releases).218If the second alternative is used in this case, it does not leave a space219before the date. On the other hand, if all four macros are put into a single220XSTRING when PCRE2_PRERELEASE is not empty, an unwanted space is inserted.221There are problems using an "obvious" approach like this:222223XSTRING(PCRE2_MAJOR) "." XSTRING(PCRE2_MINOR)224XSTRING(PCRE2_PRERELEASE) " " XSTRING(PCRE2_DATE)225226because, when PCRE2_PRERELEASE is empty, this leads to an attempted expansion227of STRING(). The C standard states: "If (before argument substitution) any228argument consists of no preprocessing tokens, the behavior is undefined." It229turns out the gcc treats this case as a single empty string - which is what230we really want - but Visual C grumbles about the lack of an argument for the231macro. Unfortunately, both are within their rights. As there seems to be no232way to test for a macro's value being empty at compile time, we have to233resort to a runtime test. */234235case PCRE2_CONFIG_VERSION:236{237const char *v = (XSTRING(Z PCRE2_PRERELEASE)[1] == 0)?238XSTRING(PCRE2_MAJOR.PCRE2_MINOR PCRE2_DATE) :239XSTRING(PCRE2_MAJOR.PCRE2_MINOR) XSTRING(PCRE2_PRERELEASE PCRE2_DATE);240return (int)(1 + ((where == NULL)?241strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));242}243244}245246return 0;247}248249/* End of pcre2_config.c */250251252