regex.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 <strings.h>
  34. #include <stdlib.h>
  35. #ifdef __UCLIBC_HAS_WCHAR__
  36. #define RE_ENABLE_I18N
  37. #include <wchar.h>
  38. #include <wctype.h>
  39. #define __iswctype iswctype
  40. #define __wcrtomb wcrtomb
  41. #define __btowc btowc
  42. #define __wctype wctype
  43. libc_hidden_proto(wcscoll)
  44. libc_hidden_proto(wcrtomb)
  45. libc_hidden_proto(mbrtowc)
  46. libc_hidden_proto(iswctype)
  47. libc_hidden_proto(iswlower)
  48. libc_hidden_proto(iswalnum)
  49. libc_hidden_proto(towlower)
  50. libc_hidden_proto(towupper)
  51. libc_hidden_proto(mbsinit)
  52. libc_hidden_proto(btowc)
  53. libc_hidden_proto(wctype)
  54. #endif
  55. #include <ctype.h>
  56. #ifdef __UCLIBC_HAS_CTYPE_TABLES__
  57. #define __toupper toupper
  58. #define __tolower tolower
  59. #endif
  60. #define __mempcpy mempcpy
  61. #ifdef __UCLIBC_HAS_XLOCALE__
  62. libc_hidden_proto(__ctype_b_loc)
  63. libc_hidden_proto(__ctype_toupper_loc)
  64. #elif __UCLIBC_HAS_CTYPE_TABLES__
  65. libc_hidden_proto(__ctype_b)
  66. libc_hidden_proto(__ctype_toupper)
  67. #else
  68. libc_hidden_proto(isascii)
  69. #endif
  70. libc_hidden_proto(toupper)
  71. libc_hidden_proto(tolower)
  72. libc_hidden_proto(memcmp)
  73. libc_hidden_proto(memcpy)
  74. libc_hidden_proto(memmove)
  75. libc_hidden_proto(memset)
  76. libc_hidden_proto(strchr)
  77. libc_hidden_proto(strcmp)
  78. libc_hidden_proto(strlen)
  79. libc_hidden_proto(strncpy)
  80. libc_hidden_proto(getenv)
  81. libc_hidden_proto(strcasecmp)
  82. libc_hidden_proto(abort)
  83. #ifdef __USE_GNU
  84. libc_hidden_proto(mempcpy)
  85. #endif
  86. #endif
  87. /* Make sure noone compiles this code with a C++ compiler. */
  88. #ifdef __cplusplus
  89. # error "This is C code, use a C compiler"
  90. #endif
  91. #if defined _LIBC || defined __UCLIBC__
  92. /* We have to keep the namespace clean. */
  93. # define regfree(preg) __regfree (preg)
  94. # define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef)
  95. # define regcomp(preg, pattern, cflags) __regcomp (preg, pattern, cflags)
  96. # define regerror(errcode, preg, errbuf, errbuf_size) \
  97. __regerror(errcode, preg, errbuf, errbuf_size)
  98. # define re_set_registers(bu, re, nu, st, en) \
  99. __re_set_registers (bu, re, nu, st, en)
  100. # define re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) \
  101. __re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
  102. # define re_match(bufp, string, size, pos, regs) \
  103. __re_match (bufp, string, size, pos, regs)
  104. # define re_search(bufp, string, size, startpos, range, regs) \
  105. __re_search (bufp, string, size, startpos, range, regs)
  106. # define re_compile_pattern(pattern, length, bufp) \
  107. __re_compile_pattern (pattern, length, bufp)
  108. # define re_set_syntax(syntax) __re_set_syntax (syntax)
  109. # define re_search_2(bufp, st1, s1, st2, s2, startpos, range, regs, stop) \
  110. __re_search_2 (bufp, st1, s1, st2, s2, startpos, range, regs, stop)
  111. # define re_compile_fastmap(bufp) __re_compile_fastmap (bufp)
  112. #ifndef __UCLIBC__
  113. # include "../locale/localeinfo.h"
  114. #endif
  115. #endif
  116. /* On some systems, limits.h sets RE_DUP_MAX to a lower value than
  117. GNU regex allows. Include it before <regex.h>, which correctly
  118. #undefs RE_DUP_MAX and sets it to the right value. */
  119. #include <limits.h>
  120. #ifdef __UCLIBC__
  121. #include "_regex.h"
  122. #else
  123. #include <regex.h>
  124. #endif
  125. #include "regex_internal.h"
  126. #include "regex_internal.c"
  127. #include "regcomp.c"
  128. #include "regexec.c"
  129. /* Binary backward compatibility. */
  130. #if _LIBC
  131. # include <shlib-compat.h>
  132. # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3)
  133. link_warning (re_max_failures, "the 're_max_failures' variable is obsolete and will go away.")
  134. int re_max_failures = 2000;
  135. # endif
  136. #endif