Path: blob/master/thirdparty/pcre2/src/pcre2_config.c
9898 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*/3940#ifdef HAVE_CONFIG_H41#include "config.h"42#endif4344/* Save the configured link size, which is in bytes. In 16-bit and 32-bit modes45its value gets changed by pcre2_intmodedep.h (included by pcre2_internal.h) to46be in code units. */4748static int configured_link_size = LINK_SIZE;4950#include "pcre2_internal.h"5152/* These macros are the standard way of turning unquoted text into C strings.53They allow macros like PCRE2_MAJOR to be defined without quotes, which is54convenient for user programs that want to test their values. */5556#define STRING(a) # a57#define XSTRING(s) STRING(s)585960/*************************************************61* Return info about what features are configured *62*************************************************/6364/* If where is NULL, the length of memory required is returned.6566Arguments:67what what information is required68where where to put the information6970Returns: 0 if a numerical value is returned71>= 0 if a string value72PCRE2_ERROR_BADOPTION if "where" not recognized73or JIT target requested when JIT not enabled74*/7576PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION77pcre2_config(uint32_t what, void *where)78{79if (where == NULL) /* Requests a length */80{81switch(what)82{83default:84return PCRE2_ERROR_BADOPTION;8586case PCRE2_CONFIG_BSR:87case PCRE2_CONFIG_COMPILED_WIDTHS:88case PCRE2_CONFIG_DEPTHLIMIT:89case PCRE2_CONFIG_HEAPLIMIT:90case PCRE2_CONFIG_JIT:91case PCRE2_CONFIG_LINKSIZE:92case PCRE2_CONFIG_MATCHLIMIT:93case PCRE2_CONFIG_NEVER_BACKSLASH_C:94case PCRE2_CONFIG_NEWLINE:95case PCRE2_CONFIG_PARENSLIMIT:96case PCRE2_CONFIG_STACKRECURSE: /* Obsolete */97case PCRE2_CONFIG_TABLES_LENGTH:98case PCRE2_CONFIG_UNICODE:99return sizeof(uint32_t);100101/* These are handled below */102103case PCRE2_CONFIG_JITTARGET:104case PCRE2_CONFIG_UNICODE_VERSION:105case PCRE2_CONFIG_VERSION:106break;107}108}109110switch (what)111{112default:113return PCRE2_ERROR_BADOPTION;114115case PCRE2_CONFIG_BSR:116#ifdef BSR_ANYCRLF117*((uint32_t *)where) = PCRE2_BSR_ANYCRLF;118#else119*((uint32_t *)where) = PCRE2_BSR_UNICODE;120#endif121break;122123case PCRE2_CONFIG_COMPILED_WIDTHS:124*((uint32_t *)where) = 0125#ifdef SUPPORT_PCRE2_8126+ 1127#endif128#ifdef SUPPORT_PCRE2_16129+ 2130#endif131#ifdef SUPPORT_PCRE2_32132+ 4133#endif134;135break;136137case PCRE2_CONFIG_DEPTHLIMIT:138*((uint32_t *)where) = MATCH_LIMIT_DEPTH;139break;140141case PCRE2_CONFIG_HEAPLIMIT:142*((uint32_t *)where) = HEAP_LIMIT;143break;144145case PCRE2_CONFIG_JIT:146#ifdef SUPPORT_JIT147*((uint32_t *)where) = 1;148#else149*((uint32_t *)where) = 0;150#endif151break;152153case PCRE2_CONFIG_JITTARGET:154#ifdef SUPPORT_JIT155{156const char *v = PRIV(jit_get_target)();157return (int)(1 + ((where == NULL)?158strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));159}160#else161return PCRE2_ERROR_BADOPTION;162#endif163164case PCRE2_CONFIG_LINKSIZE:165*((uint32_t *)where) = (uint32_t)configured_link_size;166break;167168case PCRE2_CONFIG_MATCHLIMIT:169*((uint32_t *)where) = MATCH_LIMIT;170break;171172case PCRE2_CONFIG_NEWLINE:173*((uint32_t *)where) = NEWLINE_DEFAULT;174break;175176case PCRE2_CONFIG_NEVER_BACKSLASH_C:177#ifdef NEVER_BACKSLASH_C178*((uint32_t *)where) = 1;179#else180*((uint32_t *)where) = 0;181#endif182break;183184case PCRE2_CONFIG_PARENSLIMIT:185*((uint32_t *)where) = PARENS_NEST_LIMIT;186break;187188/* This is now obsolete. The stack is no longer used via recursion for189handling backtracking in pcre2_match(). */190191case PCRE2_CONFIG_STACKRECURSE:192*((uint32_t *)where) = 0;193break;194195case PCRE2_CONFIG_TABLES_LENGTH:196*((uint32_t *)where) = TABLES_LENGTH;197break;198199case PCRE2_CONFIG_UNICODE_VERSION:200{201#if defined SUPPORT_UNICODE202const char *v = PRIV(unicode_version);203#else204const char *v = "Unicode not supported";205#endif206return (int)(1 + ((where == NULL)?207strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));208}209break;210211case PCRE2_CONFIG_UNICODE:212#if defined SUPPORT_UNICODE213*((uint32_t *)where) = 1;214#else215*((uint32_t *)where) = 0;216#endif217break;218219/* The hackery in setting "v" below is to cope with the case when220PCRE2_PRERELEASE is set to an empty string (which it is for real releases).221If the second alternative is used in this case, it does not leave a space222before the date. On the other hand, if all four macros are put into a single223XSTRING when PCRE2_PRERELEASE is not empty, an unwanted space is inserted.224There are problems using an "obvious" approach like this:225226XSTRING(PCRE2_MAJOR) "." XSTRING(PCRE2_MINOR)227XSTRING(PCRE2_PRERELEASE) " " XSTRING(PCRE2_DATE)228229because, when PCRE2_PRERELEASE is empty, this leads to an attempted expansion230of STRING(). The C standard states: "If (before argument substitution) any231argument consists of no preprocessing tokens, the behavior is undefined." It232turns out the gcc treats this case as a single empty string - which is what233we really want - but Visual C grumbles about the lack of an argument for the234macro. Unfortunately, both are within their rights. As there seems to be no235way to test for a macro's value being empty at compile time, we have to236resort to a runtime test. */237238case PCRE2_CONFIG_VERSION:239{240const char *v = (XSTRING(Z PCRE2_PRERELEASE)[1] == 0)?241XSTRING(PCRE2_MAJOR.PCRE2_MINOR PCRE2_DATE) :242XSTRING(PCRE2_MAJOR.PCRE2_MINOR) XSTRING(PCRE2_PRERELEASE PCRE2_DATE);243return (int)(1 + ((where == NULL)?244strlen(v) : PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v)));245}246}247248return 0;249}250251/* End of pcre2_config.c */252253254