PageRenderTime 43ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/casa/Utilities/cregex.h

http://casacore.googlecode.com/
C Header | 307 lines | 94 code | 58 blank | 155 comment | 1 complexity | f70e56d3798fe485023de351e6bfff25 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. cregex.h: Extended regular expression matching and search library
  3. Copyright (C) 1993,1994,1995,1997,1999,2001
  4. Associated Universities, Inc. Washington DC, USA.
  5. This library is free software; you can redistribute it and/or modify it
  6. under the terms of the GNU Library General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or (at your
  8. option) any later version.
  9. This library is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
  12. License for more details.
  13. You should have received a copy of the GNU Library General Public License
  14. along with this library; if not, write to the Free Software Foundation,
  15. Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
  16. Correspondence concerning AIPS++ should be addressed as follows:
  17. Internet email: aips2-request@nrao.edu.
  18. Postal address: AIPS++ Project Office
  19. National Radio Astronomy Observatory
  20. 520 Edgemont Road
  21. Charlottesville, VA 22903-2475 USA
  22. $Id: cregex.h 20901 2010-06-09 07:23:37Z gervandiepen $
  23. */
  24. #ifndef CASA_CREGEX_H
  25. #define CASA_CREGEX_H
  26. /* Definitions for data structures callers pass the regex library. */
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Define number of parens for which we record the beginnings and ends.
  31. This affects how much space the `struct re_registers' type takes up. */
  32. #ifndef RE_NREGS
  33. #define RE_NREGS 32
  34. #endif
  35. #define BYTEWIDTH 8
  36. #include <casa/aips.h>
  37. namespace casa { //# NAMESPACE CASA - BEGIN
  38. /* Maximum number of duplicates an interval can allow. */
  39. /* Has been changed to copy from the limits.h file
  40. #if defined(_AIX) || defined(__sgi)
  41. # undef RE_DUP_MAX
  42. #endif
  43. #define RE_DUP_MAX ((1 << 15) - 1)
  44. */
  45. /* This defines the various regexp syntaxes.
  46. It can be set using the function a2_re_set_syntax. */
  47. ///extern int obscure_syntax;
  48. /* The following bits are used in the obscure_syntax variable to choose among
  49. alternative regexp syntaxes. */
  50. /* If this bit is set, plain parentheses serve as grouping, and backslash
  51. parentheses are needed for literal searching.
  52. If not set, backslash-parentheses are grouping, and plain parentheses
  53. are for literal searching. */
  54. #define RE_NO_BK_PARENS 1
  55. /* If this bit is set, plain | serves as the `or'-operator, and \| is a
  56. literal.
  57. If not set, \| serves as the `or'-operator, and | is a literal. */
  58. #define RE_NO_BK_VBAR (1 << 1)
  59. /* If this bit is not set, plain + or ? serves as an operator, and \+, \? are
  60. literals.
  61. If set, \+, \? are operators and plain +, ? are literals. */
  62. #define RE_BK_PLUS_QM (1 << 2)
  63. /* If this bit is set, | binds tighter than ^ or $.
  64. If not set, the contrary. */
  65. #define RE_TIGHT_VBAR (1 << 3)
  66. /* If this bit is set, then treat newline as an OR operator.
  67. If not set, treat it as a normal character. */
  68. #define RE_NEWLINE_OR (1 << 4)
  69. /* If this bit is set, then special characters may act as normal
  70. characters in some contexts. Specifically, this applies to:
  71. ^ -- only special at the beginning, or after ( or |;
  72. $ -- only special at the end, or before ) or |;
  73. *, +, ? -- only special when not after the beginning, (, or |.
  74. If this bit is not set, special characters (such as *, ^, and $)
  75. always have their special meaning regardless of the surrounding
  76. context. */
  77. #define RE_CONTEXT_INDEP_OPS (1 << 5)
  78. /* If this bit is not set, then \ before anything inside [ and ] is taken as
  79. a real \.
  80. If set, then such a \ escapes the following character. This is a
  81. special case for awk. */
  82. #define RE_AWK_CLASS_HACK (1 << 6)
  83. /* If this bit is set, then \{ and \} or { and } serve as interval operators.
  84. If not set, then \{ and \} and { and } are treated as literals. */
  85. #define RE_INTERVALS (1 << 7)
  86. /* If this bit is not set, then \{ and \} serve as interval operators and
  87. { and } are literals.
  88. If set, then { and } serve as interval operators and \{ and \} are
  89. literals. */
  90. #define RE_NO_BK_CURLY_BRACES (1 << 8)
  91. /* If this bit is set, then character classes are supported; they are:
  92. [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
  93. [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
  94. If not set, then character classes are not supported. */
  95. #define RE_CHAR_CLASSES (1 << 9)
  96. /* If this bit is set, then the dot re doesn't match a null byte.
  97. If not set, it does. */
  98. #define RE_DOT_NOT_NULL (1 << 10)
  99. /* If this bit is set, then [^...] doesn't match a newline.
  100. If not set, it does. */
  101. #define RE_HAT_NOT_NEWLINE (1 << 11)
  102. /* If this bit is not set, back references are recognized.
  103. If set, they aren't. */
  104. #define RE_NO_BK_REFS (1 << 12)
  105. /* If this bit is set, back references must refer to a preceding
  106. subexpression. If not set, a back reference to a nonexistent
  107. subexpression is treated as literal characters. */
  108. #define RE_NO_EMPTY_BK_REF (1 << 13)
  109. /* If this bit is set, bracket expressions can't be empty.
  110. If it is set, they can be empty. */
  111. #define RE_NO_EMPTY_BRACKETS (1 << 14)
  112. /* If this bit is set, then *, +, ? and { cannot be first in an re or
  113. immediately after a |, or a (. Furthermore, a | cannot be first or
  114. last in an re, or immediately follow another | or a (. Also, a ^
  115. cannot appear in a nonleading position and a $ cannot appear in a
  116. nontrailing position (outside of bracket expressions, that is). */
  117. #define RE_CONTEXTUAL_INVALID_OPS (1 << 15)
  118. /* If this bit is set, then +, ? and | aren't recognized as operators.
  119. If it's not, they are. */
  120. #define RE_LIMITED_OPS (1 << 16)
  121. /* If this bit is set, then an ending range point has to collate higher
  122. or equal to the starting range point.
  123. If it's not set, then when the ending range point collates higher
  124. than the starting range point, the range is just considered empty. */
  125. #define RE_NO_EMPTY_RANGES (1 << 17)
  126. /* If this bit is set, then a hyphen (-) can't be an ending range point.
  127. If it isn't, then it can. */
  128. #define RE_NO_HYPHEN_RANGE_END (1 << 18)
  129. /* Define combinations of bits for the standard possibilities. */
  130. #define RE_SYNTAX_POSIX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR \
  131. | RE_CONTEXT_INDEP_OPS)
  132. #define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR \
  133. | RE_CONTEXT_INDEP_OPS | RE_AWK_CLASS_HACK)
  134. #define RE_SYNTAX_EGREP (RE_NO_BK_PARENS | RE_NO_BK_VBAR \
  135. | RE_CONTEXT_INDEP_OPS | RE_NEWLINE_OR)
  136. #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR)
  137. #define RE_SYNTAX_EMACS 0
  138. #define RE_SYNTAX_POSIX_BASIC (RE_INTERVALS | RE_BK_PLUS_QM \
  139. | RE_CHAR_CLASSES | RE_DOT_NOT_NULL \
  140. | RE_HAT_NOT_NEWLINE | RE_NO_EMPTY_BK_REF \
  141. | RE_NO_EMPTY_BRACKETS | RE_LIMITED_OPS \
  142. | RE_NO_EMPTY_RANGES | RE_NO_HYPHEN_RANGE_END)
  143. #define RE_SYNTAX_POSIX_EXTENDED (RE_INTERVALS | RE_NO_BK_CURLY_BRACES \
  144. | RE_NO_BK_VBAR | RE_NO_BK_PARENS \
  145. | RE_HAT_NOT_NEWLINE | RE_CHAR_CLASSES \
  146. | RE_NO_EMPTY_BRACKETS | RE_CONTEXTUAL_INVALID_OPS \
  147. | RE_NO_BK_REFS | RE_NO_EMPTY_RANGES \
  148. | RE_NO_HYPHEN_RANGE_END)
  149. /* This data structure is used to represent a compiled pattern. */
  150. // <summary>
  151. // This data structure is used to represent a compiled pattern.
  152. // </summary>
  153. // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
  154. // </reviewed>
  155. // <synopsis>
  156. // This data structure is used to represent a compiled pattern.
  157. // It is used by the regular expression functions in cregex.cc.
  158. // </synopsis>
  159. struct re_pattern_buffer
  160. {
  161. char *buffer; /* Space holding the compiled pattern commands. */
  162. long allocated; /* Size of space that `buffer' points to. */
  163. long used; /* Length of portion of buffer actually occupied */
  164. char *fastmap; /* Pointer to fastmap, if any, or zero if none. */
  165. /* a2_re_search uses the fastmap, if there is one,
  166. to skip over totally implausible characters. */
  167. char *translate; /* Translate table to apply to all characters before
  168. comparing, or zero for no translation.
  169. The translation is applied to a pattern when it is
  170. compiled and to data when it is matched. */
  171. char fastmap_accurate;
  172. /* Set to zero when a new pattern is stored,
  173. set to one when the fastmap is updated from it. */
  174. char can_be_null; /* Set to one by compiling fastmap
  175. if this pattern might match the null string.
  176. It does not necessarily match the null string
  177. in that case, but if this is zero, it cannot.
  178. 2 as value means can match null string
  179. but at end of range or before a character
  180. listed in the fastmap. */
  181. };
  182. /* search.c (search_buffer) needs this one value. It is defined both in
  183. regex.c and here. */
  184. #define RE_EXACTN_VALUE 1
  185. /* Structure to store register contents data in.
  186. Pass the address of such a structure as an argument to a2_re_match, etc.,
  187. if you want this information back.
  188. For i from 1 to RE_NREGS - 1, start[i] records the starting index in
  189. the string of where the ith subexpression matched, and end[i] records
  190. one after the ending index. start[0] and end[0] are analogous, for
  191. the entire pattern. */
  192. // <summary>
  193. // Data structure to store register contents data in.
  194. // </summary>
  195. // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
  196. // </reviewed>
  197. // <synopsis>
  198. // This data structure is used to store register contents data in.
  199. // It is used by the regular expression functions in cregex.cc.
  200. // </synopsis>
  201. struct re_registers
  202. {
  203. int start[RE_NREGS];
  204. int end[RE_NREGS];
  205. };
  206. #if defined(__STDC__) || defined(__cplusplus)
  207. extern const char *a2_re_compile_pattern (char *, int, struct re_pattern_buffer *);
  208. extern int a2_re_set_syntax (int syntax);
  209. /* Is this really advertised? */
  210. extern void a2_re_compile_fastmap (struct re_pattern_buffer *);
  211. extern int a2_re_search (struct re_pattern_buffer *, char*, int, int, int,
  212. struct re_registers *);
  213. extern int a2_re_search_2 (struct re_pattern_buffer *, char *, int,
  214. char *, int, int, int,
  215. struct re_registers *, int);
  216. extern int a2_re_match (struct re_pattern_buffer *, char *, int, int,
  217. struct re_registers *);
  218. extern int a2_re_match_2 (struct re_pattern_buffer *, char *, int,
  219. char *, int, int, struct re_registers *, int);
  220. /* 4.2 bsd compatibility. */
  221. // extern const char *re_comp (char *);
  222. // extern int re_exec (char *);
  223. #else /* !__STDC__ */
  224. extern const char *a2_re_compile_pattern ();
  225. /* Is this really advertised? */
  226. extern void a2_re_compile_fastmap ();
  227. extern int a2_re_search (), a2_re_search_2 ();
  228. extern int a2_re_match (), a2_re_match_2 ();
  229. /* 4.2 bsd compatibility. */
  230. extern const char *re_comp ();
  231. extern int re_exec ();
  232. #endif /* __STDC__ */
  233. #ifdef SYNTAX_TABLE
  234. ///extern char *re_syntax_table;
  235. #endif
  236. #ifdef __cplusplus
  237. ///extern int re_max_failures;
  238. }
  239. #endif
  240. } //# NAMESPACE CASA - END
  241. #endif /* !__REGEXP_LIBRARY */