pcre2posix.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*************************************************
  2. * Perl-Compatible Regular Expressions *
  3. *************************************************/
  4. /* PCRE2 is a library of functions to support regular expressions whose syntax
  5. and semantics are as close as possible to those of the Perl 5 language. This is
  6. the public header file to be #included by applications that call PCRE2 via the
  7. POSIX wrapper interface.
  8. Written by Philip Hazel
  9. Original API code Copyright (c) 1997-2012 University of Cambridge
  10. New API code Copyright (c) 2016-2019 University of Cambridge
  11. -----------------------------------------------------------------------------
  12. Redistribution and use in source and binary forms, with or without
  13. modification, are permitted provided that the following conditions are met:
  14. * Redistributions of source code must retain the above copyright notice,
  15. this list of conditions and the following disclaimer.
  16. * Redistributions in binary form must reproduce the above copyright
  17. notice, this list of conditions and the following disclaimer in the
  18. documentation and/or other materials provided with the distribution.
  19. * Neither the name of the University of Cambridge nor the names of its
  20. contributors may be used to endorse or promote products derived from
  21. this software without specific prior written permission.
  22. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. POSSIBILITY OF SUCH DAMAGE.
  33. -----------------------------------------------------------------------------
  34. */
  35. /* Have to include stdlib.h in order to ensure that size_t is defined. */
  36. #include <stdlib.h>
  37. /* Allow for C++ users */
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Options, mostly defined by POSIX, but with some extras. */
  42. #define REG_ICASE 0x0001 /* Maps to PCRE2_CASELESS */
  43. #define REG_NEWLINE 0x0002 /* Maps to PCRE2_MULTILINE */
  44. #define REG_NOTBOL 0x0004 /* Maps to PCRE2_NOTBOL */
  45. #define REG_NOTEOL 0x0008 /* Maps to PCRE2_NOTEOL */
  46. #define REG_DOTALL 0x0010 /* NOT defined by POSIX; maps to PCRE2_DOTALL */
  47. #define REG_NOSUB 0x0020 /* Do not report what was matched */
  48. #define REG_UTF 0x0040 /* NOT defined by POSIX; maps to PCRE2_UTF */
  49. #define REG_STARTEND 0x0080 /* BSD feature: pass subject string by so,eo */
  50. #define REG_NOTEMPTY 0x0100 /* NOT defined by POSIX; maps to PCRE2_NOTEMPTY */
  51. #define REG_UNGREEDY 0x0200 /* NOT defined by POSIX; maps to PCRE2_UNGREEDY */
  52. #define REG_UCP 0x0400 /* NOT defined by POSIX; maps to PCRE2_UCP */
  53. #define REG_PEND 0x0800 /* GNU feature: pass end pattern by re_endp */
  54. #define REG_NOSPEC 0x1000 /* Maps to PCRE2_LITERAL */
  55. /* This is not used by PCRE2, but by defining it we make it easier
  56. to slot PCRE2 into existing programs that make POSIX calls. */
  57. #define REG_EXTENDED 0
  58. /* Error values. Not all these are relevant or used by the wrapper. */
  59. enum {
  60. REG_ASSERT = 1, /* internal error ? */
  61. REG_BADBR, /* invalid repeat counts in {} */
  62. REG_BADPAT, /* pattern error */
  63. REG_BADRPT, /* ? * + invalid */
  64. REG_EBRACE, /* unbalanced {} */
  65. REG_EBRACK, /* unbalanced [] */
  66. REG_ECOLLATE, /* collation error - not relevant */
  67. REG_ECTYPE, /* bad class */
  68. REG_EESCAPE, /* bad escape sequence */
  69. REG_EMPTY, /* empty expression */
  70. REG_EPAREN, /* unbalanced () */
  71. REG_ERANGE, /* bad range inside [] */
  72. REG_ESIZE, /* expression too big */
  73. REG_ESPACE, /* failed to get memory */
  74. REG_ESUBREG, /* bad back reference */
  75. REG_INVARG, /* bad argument */
  76. REG_NOMATCH /* match failed */
  77. };
  78. /* The structure representing a compiled regular expression. It is also used
  79. for passing the pattern end pointer when REG_PEND is set. */
  80. typedef struct {
  81. void *re_pcre2_code;
  82. void *re_match_data;
  83. const char *re_endp;
  84. size_t re_nsub;
  85. size_t re_erroffset;
  86. int re_cflags;
  87. } regex_t;
  88. /* The structure in which a captured offset is returned. */
  89. typedef int regoff_t;
  90. typedef struct {
  91. regoff_t rm_so;
  92. regoff_t rm_eo;
  93. } regmatch_t;
  94. /* When an application links to a PCRE2 DLL in Windows, the symbols that are
  95. imported have to be identified as such. When building PCRE2, the appropriate
  96. export settings are needed, and are set in pcre2posix.c before including this
  97. file. */
  98. #if defined(_WIN32) && !defined(PCRE2_STATIC) && !defined(PCRE2POSIX_EXP_DECL)
  99. # define PCRE2POSIX_EXP_DECL extern __declspec(dllimport)
  100. # define PCRE2POSIX_EXP_DEFN __declspec(dllimport)
  101. #endif
  102. /* By default, we use the standard "extern" declarations. */
  103. #ifndef PCRE2POSIX_EXP_DECL
  104. # ifdef __cplusplus
  105. # define PCRE2POSIX_EXP_DECL extern "C"
  106. # define PCRE2POSIX_EXP_DEFN extern "C"
  107. # else
  108. # define PCRE2POSIX_EXP_DECL extern
  109. # define PCRE2POSIX_EXP_DEFN extern
  110. # endif
  111. #endif
  112. /* The functions. The actual code is in functions with pcre2_xxx names for
  113. uniqueness. POSIX names are provided as macros for API compatibility with POSIX
  114. regex functions. It's done this way to ensure to they are always linked from
  115. the PCRE2 library and not by accident from elsewhere (regex_t differs in size
  116. elsewhere). */
  117. PCRE2POSIX_EXP_DECL int pcre2_regcomp(regex_t *, const char *, int);
  118. PCRE2POSIX_EXP_DECL int pcre2_regexec(const regex_t *, const char *, size_t,
  119. regmatch_t *, int);
  120. PCRE2POSIX_EXP_DECL size_t pcre2_regerror(int, const regex_t *, char *, size_t);
  121. PCRE2POSIX_EXP_DECL void pcre2_regfree(regex_t *);
  122. #define regcomp pcre2_regcomp
  123. #define regexec pcre2_regexec
  124. #define regerror pcre2_regerror
  125. #define regfree pcre2_regfree
  126. /* Debian had a patch that used different names. These are now here to save
  127. them having to maintain their own patch, but are not documented by PCRE2. */
  128. #define PCRE2regcomp pcre2_regcomp
  129. #define PCRE2regexec pcre2_regexec
  130. #define PCRE2regerror pcre2_regerror
  131. #define PCRE2regfree pcre2_regfree
  132. #ifdef __cplusplus
  133. } /* extern "C" */
  134. #endif
  135. /* End of pcre2posix.h */