home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / utils / hwgrcs / hwgdiff / rcs.rcsfiles / regex.h,v < prev    next >
Encoding:
Text File  |  1993-02-20  |  9.6 KB  |  284 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     HWGDIFF_Fish:1.1
  5.     HWGDIFF:1.1;
  6. locks; strict;
  7. comment    @ * @;
  8.  
  9.  
  10. 1.1
  11. date    93.01.19.14.04.33;    author heinz;    state Exp;
  12. branches;
  13. next    ;
  14.  
  15.  
  16. desc
  17. @RCS for the first time ...
  18. @
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/* Definitions for data structures callers pass the regex library.
  27.  
  28.    Copyright (C) 1985, 1989-90 Free Software Foundation, Inc.
  29.  
  30.    This program is free software; you can redistribute it and/or modify
  31.    it under the terms of the GNU General Public License as published by
  32.    the Free Software Foundation; either version 1, or (at your option)
  33.    any later version.
  34.  
  35.    This program is distributed in the hope that it will be useful,
  36.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  37.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  38.    GNU General Public License for more details.
  39.  
  40.    You should have received a copy of the GNU General Public License
  41.    along with this program; if not, write to the Free Software
  42.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  43.  
  44.  
  45. #ifdef __GNUC__
  46.   #pragma once
  47. #endif
  48.  
  49. #ifndef __REGEXP_LIBRARY
  50. #define __REGEXP_LIBRARY
  51.  
  52. /* Define number of parens for which we record the beginnings and ends.
  53.    This affects how much space the `struct re_registers' type takes up.  */
  54. #ifndef RE_NREGS
  55. #define RE_NREGS 10
  56. #endif
  57.  
  58. #define BYTEWIDTH 8
  59.  
  60.  
  61. /* Maximum number of duplicates an interval can allow.  */
  62. #define RE_DUP_MAX  ((1 << 15) - 1) 
  63.  
  64.  
  65. /* This defines the various regexp syntaxes.  */
  66. extern int obscure_syntax;
  67.  
  68.  
  69. /* The following bits are used in the obscure_syntax variable to choose among
  70.    alternative regexp syntaxes.  */
  71.  
  72. /* If this bit is set, plain parentheses serve as grouping, and backslash
  73.      parentheses are needed for literal searching.
  74.    If not set, backslash-parentheses are grouping, and plain parentheses
  75.      are for literal searching.  */
  76. #define RE_NO_BK_PARENS    1
  77.  
  78. /* If this bit is set, plain | serves as the `or'-operator, and \| is a 
  79.      literal.
  80.    If not set, \| serves as the `or'-operator, and | is a literal.  */
  81. #define RE_NO_BK_VBAR (1 << 1)
  82.  
  83. /* If this bit is not set, plain + or ? serves as an operator, and \+, \? are 
  84.      literals.
  85.    If set, \+, \? are operators and plain +, ? are literals.  */
  86. #define RE_BK_PLUS_QM (1 << 2)
  87.  
  88. /* If this bit is set, | binds tighter than ^ or $.
  89.    If not set, the contrary.  */
  90. #define RE_TIGHT_VBAR (1 << 3)
  91.  
  92. /* If this bit is set, then treat newline as an OR operator.
  93.    If not set, treat it as a normal character.  */
  94. #define RE_NEWLINE_OR (1 << 4)
  95.  
  96. /* If this bit is set, then special characters may act as normal
  97.    characters in some contexts. Specifically, this applies to:
  98.     ^ -- only special at the beginning, or after ( or |;
  99.     $ -- only special at the end, or before ) or |;
  100.     *, +, ? -- only special when not after the beginning, (, or |.
  101.    If this bit is not set, special characters (such as *, ^, and $)
  102.    always have their special meaning regardless of the surrounding
  103.    context.  */
  104. #define RE_CONTEXT_INDEP_OPS (1 << 5)
  105.  
  106. /* If this bit is not set, then \ before anything inside [ and ] is taken as 
  107.      a real \.
  108.    If set, then such a \ escapes the following character.  This is a
  109.      special case for awk.  */
  110. #define RE_AWK_CLASS_HACK (1 << 6)
  111.  
  112. /* If this bit is set, then \{ and \} or { and } serve as interval operators.
  113.    If not set, then \{ and \} and { and } are treated as literals.  */
  114. #define RE_INTERVALS (1 << 7)
  115.  
  116. /* If this bit is not set, then \{ and \} serve as interval operators and 
  117.      { and } are literals.
  118.    If set, then { and } serve as interval operators and \{ and \} are 
  119.      literals.  */
  120. #define RE_NO_BK_CURLY_BRACES (1 << 8)
  121.  
  122. /* If this bit is set, then character classes are supported; they are:
  123.      [:alpha:],    [:upper:], [:lower:],  [:digit:], [:alnum:], [:xdigit:],
  124.      [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
  125.    If not set, then character classes are not supported.  */
  126. #define RE_CHAR_CLASSES (1 << 9)
  127.  
  128. /* If this bit is set, then the dot re doesn't match a null byte.
  129.    If not set, it does.  */
  130. #define RE_DOT_NOT_NULL (1 << 10)
  131.  
  132. /* If this bit is set, then [^...] doesn't match a newline.
  133.    If not set, it does.  */
  134. #define RE_HAT_NOT_NEWLINE (1 << 11)
  135.  
  136. /* If this bit is set, back references are recognized.
  137.    If not set, they aren't.  */
  138. #define RE_NO_BK_REFS (1 << 12)
  139.  
  140. /* If this bit is set, back references must refer to a preceding
  141.    subexpression.  If not set, a back reference to a nonexistent
  142.    subexpression is treated as literal characters.  */
  143. #define RE_NO_EMPTY_BK_REF (1 << 13)
  144.  
  145. /* If this bit is set, bracket expressions can't be empty.  
  146.    If it is set, they can be empty.  */
  147. #define RE_NO_EMPTY_BRACKETS (1 << 14)
  148.  
  149. /* If this bit is set, then *, +, ? and { cannot be first in an re or
  150.    immediately after a |, or a (.  Furthermore, a | cannot be first or
  151.    last in an re, or immediately follow another | or a (.  Also, a ^
  152.    cannot appear in a nonleading position and a $ cannot appear in a
  153.    nontrailing position (outside of bracket expressions, that is).  */
  154. #define RE_CONTEXTUAL_INVALID_OPS (1 << 15)
  155.  
  156. /* If this bit is set, then +, ? and | aren't recognized as operators.
  157.    If it's not, they are.  */
  158. #define RE_LIMITED_OPS (1 << 16)
  159.  
  160. /* If this bit is set, then an ending range point has to collate higher
  161.      or equal to the starting range point.
  162.    If it's not set, then when the ending range point collates higher
  163.      than the starting range point, the range is just considered empty.  */
  164. #define RE_NO_EMPTY_RANGES (1 << 17)
  165.  
  166. /* If this bit is set, then a hyphen (-) can't be an ending range point.
  167.    If it isn't, then it can.  */
  168. #define RE_NO_HYPHEN_RANGE_END (1 << 18)
  169.  
  170.  
  171. /* Define combinations of bits for the standard possibilities.  */
  172. #define RE_SYNTAX_POSIX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR \
  173.             | RE_CONTEXT_INDEP_OPS)
  174. #define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR \
  175.             | RE_CONTEXT_INDEP_OPS | RE_AWK_CLASS_HACK)
  176. #define RE_SYNTAX_EGREP (RE_NO_BK_PARENS | RE_NO_BK_VBAR \
  177.             | RE_CONTEXT_INDEP_OPS | RE_NEWLINE_OR)
  178. #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR)
  179. #define RE_SYNTAX_EMACS 0
  180. #define RE_SYNTAX_POSIX_BASIC (RE_INTERVALS | RE_BK_PLUS_QM         \
  181.             | RE_CHAR_CLASSES | RE_DOT_NOT_NULL         \
  182.                         | RE_HAT_NOT_NEWLINE | RE_NO_EMPTY_BK_REF     \
  183.                         | RE_NO_EMPTY_BRACKETS | RE_LIMITED_OPS        \
  184.                         | RE_NO_EMPTY_RANGES | RE_NO_HYPHEN_RANGE_END)    
  185.                         
  186. #define RE_SYNTAX_POSIX_EXTENDED (RE_INTERVALS | RE_NO_BK_CURLY_BRACES       \
  187.             | RE_NO_BK_VBAR | RE_NO_BK_PARENS            \
  188.                         | RE_HAT_NOT_NEWLINE | RE_CHAR_CLASSES            \
  189.                         | RE_NO_EMPTY_BRACKETS | RE_CONTEXTUAL_INVALID_OPS \
  190.                         | RE_NO_BK_REFS | RE_NO_EMPTY_RANGES            \
  191.                         | RE_NO_HYPHEN_RANGE_END)
  192.  
  193.  
  194. /* This data structure is used to represent a compiled pattern.  */
  195.  
  196. struct re_pattern_buffer
  197.   {
  198.     char *buffer;    /* Space holding the compiled pattern commands.  */
  199.     long allocated;    /* Size of space that `buffer' points to. */
  200.     long used;        /* Length of portion of buffer actually occupied  */
  201.     char *fastmap;    /* Pointer to fastmap, if any, or zero if none.  */
  202.             /* re_search uses the fastmap, if there is one,
  203.                to skip over totally implausible characters.  */
  204.     char *translate;    /* Translate table to apply to all characters before 
  205.                    comparing, or zero for no translation.
  206.                The translation is applied to a pattern when it is 
  207.                            compiled and to data when it is matched.  */
  208.     char fastmap_accurate;
  209.             /* Set to zero when a new pattern is stored,
  210.                set to one when the fastmap is updated from it.  */
  211.     char can_be_null;   /* Set to one by compiling fastmap
  212.                if this pattern might match the null string.
  213.                It does not necessarily match the null string
  214.                in that case, but if this is zero, it cannot.
  215.                2 as value means can match null string
  216.                but at end of range or before a character
  217.                listed in the fastmap.  */
  218.   };
  219.  
  220.  
  221. /* search.c (search_buffer) needs this one value.  It is defined both in
  222.    regex.c and here.  */
  223. #define RE_EXACTN_VALUE 1
  224.  
  225.  
  226. /* Structure to store register contents data in.
  227.  
  228.    Pass the address of such a structure as an argument to re_match, etc.,
  229.    if you want this information back.
  230.  
  231.    For i from 1 to RE_NREGS - 1, start[i] records the starting index in
  232.    the string of where the ith subexpression matched, and end[i] records
  233.    one after the ending index.  start[0] and end[0] are analogous, for
  234.    the entire pattern.  */
  235.  
  236. struct re_registers
  237.   {
  238.     int start[RE_NREGS];
  239.     int end[RE_NREGS];
  240.   };
  241.  
  242.  
  243.  
  244. #ifdef __STDC__
  245.  
  246. extern char *re_compile_pattern (char *, int, struct re_pattern_buffer *);
  247. /* Is this really advertised?  */
  248. extern void re_compile_fastmap (struct re_pattern_buffer *);
  249. extern int re_search (struct re_pattern_buffer *, char*, int, int, int,
  250.               struct re_registers *);
  251. extern int re_search_2 (struct re_pattern_buffer *, char *, int,
  252.             char *, int, int, int,
  253.             struct re_registers *, int);
  254. extern int re_match (struct re_pattern_buffer *, char *, int, int,
  255.              struct re_registers *);
  256. extern int re_match_2 (struct re_pattern_buffer *, char *, int,
  257.                char *, int, int, struct re_registers *, int);
  258.  
  259. /* 4.2 bsd compatibility.  */
  260. extern char *re_comp (char *);
  261. extern int re_exec (char *);
  262.  
  263. #else /* !__STDC__ */
  264.  
  265. extern char *re_compile_pattern ();
  266. /* Is this really advertised? */
  267. extern void re_compile_fastmap ();
  268. extern int re_search (), re_search_2 ();
  269. extern int re_match (), re_match_2 ();
  270.  
  271. /* 4.2 bsd compatibility.  */
  272. extern char *re_comp ();
  273. extern int re_exec ();
  274.  
  275. #endif /* __STDC__ */
  276.  
  277.  
  278. #ifdef SYNTAX_TABLE
  279. extern char *re_syntax_table;
  280. #endif
  281.  
  282. #endif /* !__REGEXP_LIBRARY */
  283. @
  284.