home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnurx.zip / rx / rxgnucomp.h < prev    next >
C/C++ Source or Header  |  1995-12-31  |  10KB  |  255 lines

  1. /* classes: h_files */
  2.  
  3. #ifndef RXGNUCOMPH
  4. #define RXGNUCOMPH
  5. /*    Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
  6.  * 
  7.  * This program is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU Library General Public License as published by
  9.  * the Free Software Foundation; either version 2, or (at your option)
  10.  * any later version.
  11.  * 
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU Library General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this software; see the file COPYING.  If not, write to
  19.  * the Free Software Foundation, 59 Temple Place - Suite 330, 
  20.  * Boston, MA 02111-1307, USA. 
  21.  */
  22.  
  23.  
  24.  
  25. #include "rxcset.h"
  26. #include "rxnode.h"
  27.  
  28.  
  29.  
  30.  
  31. /* This is an array of error messages corresponding to the error codes.
  32.  */
  33. extern const char *rx_error_msg[];
  34.  
  35.  
  36.  
  37. /* If any error codes are removed, changed, or added, update the
  38.  * `rx_error_msg' table.
  39.  */
  40. typedef enum
  41. {
  42.   REG_NOERROR = 0,    /* Success.  */
  43.   REG_NOMATCH,        /* Didn't find a match (for regexec).  */
  44.  
  45.   /* POSIX regcomp return error codes.  (In the order listed in the
  46.      standard.)  */
  47.   REG_BADPAT,        /* Invalid pattern.  */
  48.   REG_ECOLLATE,        /* Not implemented.  */
  49.   REG_ECTYPE,        /* Invalid character class name.  */
  50.   REG_EESCAPE,        /* Trailing backslash.  */
  51.   REG_ESUBREG,        /* Invalid back reference.  */
  52.   REG_EBRACK,        /* Unmatched left bracket.  */
  53.   REG_EPAREN,        /* Parenthesis imbalance.  */ 
  54.   REG_EBRACE,        /* Unmatched \{.  */
  55.   REG_BADBR,        /* Invalid contents of \{\}.  */
  56.   REG_ERANGE,        /* Invalid range end.  */
  57.   REG_ESPACE,        /* Ran out of memory.  */
  58.   REG_BADRPT,        /* No preceding re for repetition op.  */
  59.  
  60.   /* Error codes we've added.  */
  61.   REG_EEND,        /* Premature end.  */
  62.   REG_ESIZE,        /* Compiled pattern bigger than 2^16 bytes.  */
  63.   REG_ERPAREN        /* Unmatched ) or \); not returned from regcomp.  */
  64. } reg_errcode_t;
  65.  
  66.  
  67. /* {Syntax Bits}
  68.  */
  69.  
  70. /* The following bits are used to determine the regexp syntax we
  71.    recognize.  The set/not-set meanings are chosen so that Emacs syntax
  72.    remains the value 0.  The bits are given in alphabetical order, and
  73.    the definitions shifted by one from the previous bit; thus, when we
  74.    add or remove a bit, only one other definition need change.  */
  75.  
  76. /* If this bit is not set, then \ inside a bracket expression is literal.
  77.    If set, then such a \ quotes the following character.  */
  78. #define RE_BACKSLASH_ESCAPE_IN_LISTS (1)
  79.  
  80. /* If this bit is not set, then + and ? are operators, and \+ and \? are
  81.      literals. 
  82.    If set, then \+ and \? are operators and + and ? are literals.  */
  83. #define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
  84.  
  85. /* If this bit is set, then character classes are supported.  They are:
  86.      [:alpha:], [:upper:], [:lower:],  [:digit:], [:alnum:], [:xdigit:],
  87.      [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
  88.    If not set, then character classes are not supported.  */
  89. #define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
  90.  
  91. /* If this bit is set, then ^ and $ are always anchors (outside bracket
  92.      expressions, of course).
  93.    If this bit is not set, then it depends:
  94.         ^  is an anchor if it is at the beginning of a regular
  95.            expression or after an open-group or an alternation operator;
  96.         $  is an anchor if it is at the end of a regular expression, or
  97.            before a close-group or an alternation operator.  
  98.  
  99.    This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
  100.    POSIX draft 11.2 says that * etc. in leading positions is undefined.
  101.    We already implemented a previous draft which made those constructs
  102.    invalid, though, so we haven't changed the code back.  */
  103. #define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
  104.  
  105. /* If this bit is set, then special characters are always special
  106.      regardless of where they are in the pattern.
  107.    If this bit is not set, then special characters are special only in
  108.      some contexts; otherwise they are ordinary.  Specifically, 
  109.      * + ? and intervals are only special when not after the beginning,
  110.      open-group, or alternation operator.  */
  111. #define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
  112.  
  113. /* If this bit is set, then *, +, ?, and { cannot be first in an re or
  114.      immediately after an alternation or begin-group operator.  */
  115. #define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
  116.  
  117. /* If this bit is set, then . matches newline.
  118.    If not set, then it doesn't.  */
  119. #define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
  120.  
  121. /* If this bit is set, then . doesn't match NUL.
  122.    If not set, then it does.  */
  123. #define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
  124.  
  125. /* If this bit is set, nonmatching lists [^...] do not match newline.
  126.    If not set, they do.  */
  127. #define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
  128.  
  129. /* If this bit is set, either \{...\} or {...} defines an
  130.      interval, depending on RE_NO_BK_BRACES. 
  131.    If not set, \{, \}, {, and } are literals.  */
  132. #define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
  133.  
  134. /* If this bit is set, +, ? and | aren't recognized as operators.
  135.    If not set, they are.  */
  136. #define RE_LIMITED_OPS (RE_INTERVALS << 1)
  137.  
  138. /* If this bit is set, newline is an alternation operator.
  139.    If not set, newline is literal.  */
  140. #define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
  141.  
  142. /* If this bit is set, then `{...}' defines an interval, and \{ and \}
  143.      are literals.
  144.   If not set, then `\{...\}' defines an interval.  */
  145. #define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
  146.  
  147. /* If this bit is set, (...) defines a group, and \( and \) are literals.
  148.    If not set, \(...\) defines a group, and ( and ) are literals.  */
  149. #define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
  150.  
  151. /* If this bit is set, then \<digit> matches <digit>.
  152.    If not set, then \<digit> is a back-reference.  */
  153. #define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
  154.  
  155. /* If this bit is set, then | is an alternation operator, and \| is literal. 
  156.    If not set, then \| is an alternation operator, and | is literal.  */
  157. #define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
  158.  
  159. /* If this bit is set, then an ending range point collating higher
  160.      than the starting range point, as in [z-a], is invalid.
  161.    If not set, then when ending range point collates higher than the
  162.      starting range point, the range is ignored.  */
  163. #define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
  164.  
  165. /* If this bit is set, then an unmatched ) is ordinary.
  166.    If not set, then an unmatched ) is invalid.  */
  167. #define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
  168.  
  169. /* Define combinations of the above bits for the standard possibilities.
  170.    (The [[[ comments delimit what gets put into the Texinfo file, so
  171.    don't delete them!)  */ 
  172. /* [[[begin syntaxes]]] */
  173. #define RE_SYNTAX_EMACS 0
  174.  
  175. #define RE_SYNTAX_AWK                            \
  176.   (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL            \
  177.    | RE_NO_BK_PARENS            | RE_NO_BK_REFS                \
  178.    | RE_NO_BK_VBAR               | RE_NO_EMPTY_RANGES            \
  179.    | RE_UNMATCHED_RIGHT_PAREN_ORD)
  180.  
  181. #define RE_SYNTAX_POSIX_AWK                         \
  182.   (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)
  183.  
  184. #define RE_SYNTAX_GREP                            \
  185.   (RE_BK_PLUS_QM              | RE_CHAR_CLASSES                \
  186.    | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS                \
  187.    | RE_NEWLINE_ALT)
  188.  
  189. #define RE_SYNTAX_EGREP                            \
  190.   (RE_CHAR_CLASSES        | RE_CONTEXT_INDEP_ANCHORS            \
  191.    | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE            \
  192.    | RE_NEWLINE_ALT       | RE_NO_BK_PARENS                \
  193.    | RE_NO_BK_VBAR)
  194.  
  195. #define RE_SYNTAX_POSIX_EGREP                        \
  196.   (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
  197.  
  198. #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
  199.  
  200. /* Syntax bits common to both basic and extended POSIX regex syntax.  */
  201. #define _RE_SYNTAX_POSIX_COMMON                        \
  202.   (RE_CHAR_CLASSES | RE_DOT_NEWLINE      | RE_DOT_NOT_NULL        \
  203.    | RE_INTERVALS  | RE_NO_EMPTY_RANGES)
  204.  
  205. #define RE_SYNTAX_POSIX_BASIC                        \
  206.   (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
  207.  
  208. /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
  209.    RE_LIMITED_OPS, i.e., \? \+ \| are not recognized.  Actually, this
  210.    isn't minimal, since other operators, such as \`, aren't disabled.  */
  211. #define RE_SYNTAX_POSIX_MINIMAL_BASIC                    \
  212.   (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
  213.  
  214. #define RE_SYNTAX_POSIX_EXTENDED                    \
  215.   (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS            \
  216.    | RE_CONTEXT_INDEP_OPS  | RE_NO_BK_BRACES                \
  217.    | RE_NO_BK_PARENS       | RE_NO_BK_VBAR                \
  218.    | RE_UNMATCHED_RIGHT_PAREN_ORD)
  219.  
  220. /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
  221.    replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added.  */
  222. #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED                \
  223.   (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS            \
  224.    | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES                \
  225.    | RE_NO_BK_PARENS        | RE_NO_BK_REFS                \
  226.    | RE_NO_BK_VBAR        | RE_UNMATCHED_RIGHT_PAREN_ORD)
  227. /* [[[end syntaxes]]] */
  228.  
  229.  
  230.  
  231. /* Maximum number of duplicates an interval can allow.  Some systems
  232.    (erroneously) define this in other header files, but we want our
  233.    value, so remove any previous define.  */
  234. #ifdef RE_DUP_MAX
  235. #undef RE_DUP_MAX
  236. #endif
  237. #define RE_DUP_MAX ((1 << 15) - 1) 
  238.  
  239.  
  240.  
  241. #ifdef __STDC__
  242. extern reg_errcode_t rx_parse (struct rexp_node ** rexp_p,
  243.                    const char *pattern,
  244.                    int size,
  245.                    unsigned long syntax,
  246.                    int cset_size,
  247.                    unsigned char *translate);
  248.  
  249. #else /* STDC */
  250. extern reg_errcode_t rx_parse ();
  251.  
  252. #endif /* STDC */
  253.  
  254. #endif  /* RXGNUCOMPH */
  255.