regex.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* Extended regular expression matching and search library.
  2. Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #ifdef HAVE_CONFIG_H
  18. #include "config.h"
  19. #endif
  20. /* uClibc addons */
  21. #include <features.h>
  22. #ifdef __UCLIBC__
  23. #undef _LIBC
  24. #define _REGEX_RE_COMP
  25. #ifdef __USE_GNU
  26. # define HAVE_MEMPCPY
  27. #endif
  28. #define HAVE_LANGINFO
  29. #define HAVE_LANGINFO_CODESET
  30. #include <stdbool.h>
  31. #include <stdint.h>
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #ifdef __UCLIBC_HAS_WCHAR__
  35. #define RE_ENABLE_I18N
  36. #include <wchar.h>
  37. #include <wctype.h>
  38. #define __iswctype iswctype
  39. #define __wcrtomb wcrtomb
  40. #define __btowc btowc
  41. #define __wctype wctype
  42. /* libc_hidden_proto(wcscoll) */
  43. /* libc_hidden_proto(wcrtomb) */
  44. /* libc_hidden_proto(mbrtowc) */
  45. /* libc_hidden_proto(iswctype) */
  46. /* libc_hidden_proto(iswlower) */
  47. /* libc_hidden_proto(iswalnum) */
  48. /* libc_hidden_proto(towlower) */
  49. /* libc_hidden_proto(towupper) */
  50. /* libc_hidden_proto(mbsinit) */
  51. /* libc_hidden_proto(btowc) */
  52. /* libc_hidden_proto(wctype) */
  53. #endif
  54. #include <ctype.h>
  55. #ifdef __UCLIBC_HAS_CTYPE_TABLES__
  56. #define __toupper toupper
  57. #define __tolower tolower
  58. #endif
  59. #define __mempcpy mempcpy
  60. #ifdef __UCLIBC_HAS_XLOCALE__
  61. /* libc_hidden_proto(__ctype_b_loc) */
  62. /* libc_hidden_proto(__ctype_toupper_loc) */
  63. #elif defined __UCLIBC_HAS_CTYPE_TABLES__
  64. /* libc_hidden_proto(__ctype_b) */
  65. /* libc_hidden_proto(__ctype_toupper) */
  66. #else
  67. /* libc_hidden_proto(isascii) */
  68. #endif
  69. /* libc_hidden_proto(toupper) */
  70. /* libc_hidden_proto(tolower) */
  71. /* Experimentally off - libc_hidden_proto(memcmp) */
  72. /* Experimentally off - libc_hidden_proto(memcpy) */
  73. /* Experimentally off - libc_hidden_proto(memmove) */
  74. /* Experimentally off - libc_hidden_proto(memset) */
  75. /* Experimentally off - libc_hidden_proto(strchr) */
  76. /* Experimentally off - libc_hidden_proto(strcmp) */
  77. /* Experimentally off - libc_hidden_proto(strlen) */
  78. /* Experimentally off - libc_hidden_proto(strncpy) */
  79. /* libc_hidden_proto(getenv) */
  80. /* Experimentally off - libc_hidden_proto(strcasecmp) */
  81. /* libc_hidden_proto(abort) */
  82. #ifdef __USE_GNU
  83. /* Experimentally off - libc_hidden_proto(mempcpy) */
  84. #endif
  85. #endif
  86. /* Make sure noone compiles this code with a C++ compiler. */
  87. #ifdef __cplusplus
  88. # error "This is C code, use a C compiler"
  89. #endif
  90. #if defined _LIBC || defined __UCLIBC__
  91. /* We have to keep the namespace clean. */
  92. # define regfree(preg) __regfree (preg)
  93. # define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef)
  94. # define regcomp(preg, pattern, cflags) __regcomp (preg, pattern, cflags)
  95. # define regerror(errcode, preg, errbuf, errbuf_size) \
  96. __regerror(errcode, preg, errbuf, errbuf_size)
  97. # define re_set_registers(bu, re, nu, st, en) \
  98. __re_set_registers (bu, re, nu, st, en)
  99. # define re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) \
  100. __re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
  101. # define re_match(bufp, string, size, pos, regs) \
  102. __re_match (bufp, string, size, pos, regs)
  103. # define re_search(bufp, string, size, startpos, range, regs) \
  104. __re_search (bufp, string, size, startpos, range, regs)
  105. # define re_compile_pattern(pattern, length, bufp) \
  106. __re_compile_pattern (pattern, length, bufp)
  107. # define re_set_syntax(syntax) __re_set_syntax (syntax)
  108. # define re_search_2(bufp, st1, s1, st2, s2, startpos, range, regs, stop) \
  109. __re_search_2 (bufp, st1, s1, st2, s2, startpos, range, regs, stop)
  110. # define re_compile_fastmap(bufp) __re_compile_fastmap (bufp)
  111. #ifndef __UCLIBC__
  112. # include "../locale/localeinfo.h"
  113. #endif
  114. #endif
  115. /* On some systems, limits.h sets RE_DUP_MAX to a lower value than
  116. GNU regex allows. Include it before <regex.h>, which correctly
  117. #undefs RE_DUP_MAX and sets it to the right value. */
  118. #include <limits.h>
  119. #ifdef __UCLIBC__
  120. #include "_regex.h"
  121. #else
  122. #include <regex.h>
  123. #endif
  124. #include "regex_internal.h"
  125. #include "regex_internal.c"
  126. #include "regcomp.c"
  127. #include "regexec.c"
  128. /* Binary backward compatibility. */
  129. #if _LIBC
  130. # include <shlib-compat.h>
  131. # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3)
  132. link_warning (re_max_failures, "the 're_max_failures' variable is obsolete and will go away.")
  133. int re_max_failures = 2000;
  134. # endif
  135. #endif