|
| 1 | +#if 0 |
| 2 | +# Stripped down, w64devkit, static, unity build of the PCRE2 POSIX regex |
| 3 | +# library. This script builds and installs regex.h and libregex.a inside |
| 4 | +# w64devkit. Link with -lregex. It is pretty bulky, nearly 300KiB. |
| 5 | +# |
| 6 | +# Copy and run this script in the root fo the PCRE source tree. Tested |
| 7 | +# with PCRE 10.43. |
| 8 | +# |
| 9 | +# $ sh libregex.c |
| 10 | +# |
| 11 | +# Ref: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/regex.h.html |
| 12 | +# This is free and unencumbered software released into the public domain. |
| 13 | +set -ex |
| 14 | + |
| 15 | +PREFIX="${PREFIX:-$(gcc -print-sysroot)}" |
| 16 | + |
| 17 | +cp src/pcre2.h.generic src/pcre2.h |
| 18 | +${CC:-cc} -c -fwhole-program ${CFLAGS:--Os} "$0" |
| 19 | +${STRIP:-strip} -x libregex.o |
| 20 | + |
| 21 | +mkdir -p "$PREFIX/lib" |
| 22 | +rm -f "$PREFIX/lib/libregex.a" |
| 23 | +${AR:-ar} -r "$PREFIX/lib/libregex.a" libregex.o |
| 24 | + |
| 25 | +mkdir -p "$PREFIX/include" |
| 26 | +tee >nul $PREFIX/include/regex.h <<EOF |
| 27 | +#pragma once |
| 28 | +#include <stddef.h> |
| 29 | + |
| 30 | +enum { |
| 31 | + REG_EXTENDED = 0x0000, |
| 32 | + REG_ICASE = 0x0001, |
| 33 | + REG_NEWLINE = 0x0002, |
| 34 | + REG_NOTBOL = 0x0004, |
| 35 | + REG_NOTEOL = 0x0008, |
| 36 | + REG_DOTALL = 0x0010, |
| 37 | + REG_NOSUB = 0x0020, |
| 38 | + REG_UTF = 0x0040, |
| 39 | + REG_STARTEND = 0x0080, |
| 40 | + REG_NOTEMPTY = 0x0100, |
| 41 | + REG_UNGREEDY = 0x0200, |
| 42 | + REG_UCP = 0x0400, |
| 43 | + REG_PEND = 0x0800, |
| 44 | + REG_NOSPEC = 0x1000, |
| 45 | +}; |
| 46 | + |
| 47 | +enum { |
| 48 | + REG_ASSERT = 1, |
| 49 | + REG_BADBR, |
| 50 | + REG_BADPAT, |
| 51 | + REG_BADRPT, |
| 52 | + REG_EBRACE, |
| 53 | + REG_EBRACK, |
| 54 | + REG_ECOLLATE, |
| 55 | + REG_ECTYPE, |
| 56 | + REG_EESCAPE, |
| 57 | + REG_EMPTY, |
| 58 | + REG_EPAREN, |
| 59 | + REG_ERANGE, |
| 60 | + REG_ESIZE, |
| 61 | + REG_ESPACE, |
| 62 | + REG_ESUBREG, |
| 63 | + REG_INVARG, |
| 64 | + REG_NOMATCH, |
| 65 | +}; |
| 66 | + |
| 67 | +typedef struct { |
| 68 | + void *re_pcre2_code; |
| 69 | + void *re_match_data; |
| 70 | + char *re_endp; |
| 71 | + size_t re_nsub; |
| 72 | + size_t re_erroffset; |
| 73 | + int re_cflags; |
| 74 | +} regex_t; |
| 75 | + |
| 76 | +typedef int regoff_t; |
| 77 | + |
| 78 | +typedef struct { |
| 79 | + regoff_t rm_so; |
| 80 | + regoff_t rm_eo; |
| 81 | +} regmatch_t; |
| 82 | + |
| 83 | +int regcomp(regex_t *, const char *, int); |
| 84 | +size_t regerror(int, const regex_t *, char *, size_t); |
| 85 | +int regexec(const regex_t *, const char *, size_t, regmatch_t *, int); |
| 86 | +void regfree(regex_t *); |
| 87 | +EOF |
| 88 | +exit 0 |
| 89 | +#endif |
| 90 | + |
| 91 | +#define PCRE2_EXP_DEFN static |
| 92 | +#define PCRE2_EXP_DECL static |
| 93 | +#define PCRE2POSIX_EXP_DECL |
| 94 | +#define PCRE2POSIX_EXP_DEFN __attribute((used)) |
| 95 | + |
| 96 | +#define HAVE_BUILTIN_MUL_OVERFLOW |
| 97 | +#define HAVE_MEMMOVE |
| 98 | +#define HEAP_LIMIT 20000000 |
| 99 | +#define LINK_SIZE 2 |
| 100 | +#define MATCH_LIMIT 10000000 |
| 101 | +#define MATCH_LIMIT_DEPTH MATCH_LIMIT |
| 102 | +#define MAX_NAME_COUNT 10000 |
| 103 | +#define MAX_NAME_SIZE 32 |
| 104 | +#define MAX_VARLOOKBEHIND 255 |
| 105 | +#define NEWLINE_DEFAULT 2 |
| 106 | +#define PARENS_NEST_LIMIT 250 |
| 107 | +#define PCRE2_CODE_UNIT_WIDTH 8 |
| 108 | +#define PCRE2_STATIC |
| 109 | +#define SUPPORT_UNICODE |
| 110 | + |
| 111 | +#include "src/pcre2posix.h" |
| 112 | +#undef regcomp |
| 113 | +#undef regexec |
| 114 | +#undef regerror |
| 115 | +#undef regfree |
| 116 | +#define pcre2_regcomp regcomp |
| 117 | +#define pcre2_regexec regexec |
| 118 | +#define pcre2_regerror regerror |
| 119 | +#define pcre2_regfree regfree |
| 120 | +#include "src/pcre2posix.c" |
| 121 | + |
| 122 | +#include "src/pcre2_auto_possess.c" |
| 123 | +#include "src/pcre2_chartables.c.dist" |
| 124 | +#include "src/pcre2_chkdint.c" |
| 125 | +#include "src/pcre2_compile.c" |
| 126 | +#include "src/pcre2_context.c" |
| 127 | +#include "src/pcre2_extuni.c" |
| 128 | +#include "src/pcre2_find_bracket.c" |
| 129 | +#include "src/pcre2_match.c" |
| 130 | +#include "src/pcre2_match_data.c" |
| 131 | +#include "src/pcre2_newline.c" |
| 132 | +#include "src/pcre2_ord2utf.c" |
| 133 | +#include "src/pcre2_pattern_info.c" |
| 134 | +#include "src/pcre2_script_run.c" |
| 135 | +#include "src/pcre2_string_utils.c" |
| 136 | +#include "src/pcre2_study.c" |
| 137 | +#include "src/pcre2_tables.c" |
| 138 | +#include "src/pcre2_ucd.c" |
| 139 | +#include "src/pcre2_valid_utf.c" |
| 140 | +#include "src/pcre2_xclass.c" |
0 commit comments