home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / textprocess / grep_2 / release / h / dfa next >
Text File  |  1998-09-23  |  26KB  |  577 lines

  1. /*->h.dfa */
  2. /* dfa.h - declarations for GNU deterministic regexp compiler
  3.    Copyright (C) 1988 Free Software Foundation, Inc.
  4.                       Written June, 1988 by Mike Haertel
  5.  
  6.                        NO WARRANTY
  7.  
  8.   BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY
  9. NO WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT
  10. WHEN OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC,
  11. RICHARD M. STALLMAN AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS"
  12. WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
  13. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  14. FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY
  15. AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE
  16. DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  17. CORRECTION.
  18.  
  19.  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M.
  20. STALLMAN, THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY
  21. WHO MAY MODIFY AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE
  22. LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  23. OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  24. USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  25. DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR
  26. A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS) THIS
  27. PROGRAM, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH
  28. DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  29.  
  30.                 GENERAL PUBLIC LICENSE TO COPY
  31.  
  32.   1. You may copy and distribute verbatim copies of this source file
  33. as you receive it, in any medium, provided that you conspicuously and
  34. appropriately publish on each copy a valid copyright notice "Copyright
  35.  (C) 1988 Free Software Foundation, Inc."; and include following the
  36. copyright notice a verbatim copy of the above disclaimer of warranty
  37. and of this License.  You may charge a distribution fee for the
  38. physical act of transferring a copy.
  39.  
  40.   2. You may modify your copy or copies of this source file or
  41. any portion of it, and copy and distribute such modifications under
  42. the terms of Paragraph 1 above, provided that you also do the following:
  43.  
  44.     a) cause the modified files to carry prominent notices stating
  45.     that you changed the files and the date of any change; and
  46.  
  47.     b) cause the whole of any work that you distribute or publish,
  48.     that in whole or in part contains or is a derivative of this
  49.     program or any part thereof, to be licensed at no charge to all
  50.     third parties on terms identical to those contained in this
  51.     License Agreement (except that you may choose to grant more extensive
  52.     warranty protection to some or all third parties, at your option).
  53.  
  54.     c) You may charge a distribution fee for the physical act of
  55.     transferring a copy, and you may at your option offer warranty
  56.     protection in exchange for a fee.
  57.  
  58. Mere aggregation of another unrelated program with this program (or its
  59. derivative) on a volume of a storage or distribution medium does not bring
  60. the other program under the scope of these terms.
  61.  
  62.   3. You may copy and distribute this program or any portion of it in
  63. compiled, executable or object code form under the terms of Paragraphs
  64. 1 and 2 above provided that you do the following:
  65.  
  66.     a) accompany it with the complete corresponding machine-readable
  67.     source code, which must be distributed under the terms of
  68.     Paragraphs 1 and 2 above; or,
  69.  
  70.     b) accompany it with a written offer, valid for at least three
  71.     years, to give any third party free (except for a nominal
  72.     shipping charge) a complete machine-readable copy of the
  73.     corresponding source code, to be distributed under the terms of
  74.     Paragraphs 1 and 2 above; or,
  75.  
  76.     c) accompany it with the information you received as to where the
  77.     corresponding source code may be obtained.  (This alternative is
  78.     allowed only for noncommercial distribution and only if you
  79.     received the program in object code or executable form alone.)
  80.  
  81. For an executable file, complete source code means all the source code for
  82. all modules it contains; but, as a special exception, it need not include
  83. source code for modules which are standard libraries that accompany the
  84. operating system on which the executable file runs.
  85.  
  86.   4. You may not copy, sublicense, distribute or transfer this program
  87. except as expressly provided under this License Agreement.  Any attempt
  88. otherwise to copy, sublicense, distribute or transfer this program is void and
  89. your rights to use the program under this License agreement shall be
  90. automatically terminated.  However, parties who have received computer
  91. software programs from you with this License Agreement will not have
  92. their licenses terminated so long as such parties remain in full compliance.
  93.  
  94.   5. If you wish to incorporate parts of this program into other free
  95. programs whose distribution conditions are different, write to the Free
  96. Software Foundation at 675 Mass Ave, Cambridge, MA 02139.  We have not yet
  97. worked out a simple rule that can be stated here, but we will often permit
  98. this.  We will be guided by the two goals of preserving the free status of
  99. all derivatives our free software and of promoting the sharing and reuse of
  100. software.
  101.  
  102.  
  103. In other words, you are welcome to use, share and improve this program.
  104. You are forbidden to forbid anyone else to use, share and improve
  105. what you give them.   Help stamp out software-hoarding!  */
  106.  
  107.  
  108. #ifdef USG
  109. #include <string.h>
  110. extern char *index();
  111. #else
  112. #include <string.h>
  113. /* extern char *strchr(), *strrchr();void * memcpy(); */
  114. #endif
  115.  
  116. #ifdef __STDC__
  117.  
  118. /* Missing include files for GNU C. */
  119.  
  120. #ifdef ACORN
  121. #include <stdlib.h>
  122. #endif
  123.  
  124. /*
  125.  
  126. #include <stdlib.h>
  127. typedef int size_t;
  128. extern void *calloc(int, size_t);
  129. extern void *malloc(size_t);
  130. extern void *realloc(void *, size_t);
  131. extern void free(void *);
  132.  
  133. */
  134.  
  135.  
  136. extern char *bcopy(), *bzero();
  137.  
  138. /* #ifdef SOMEDAY */
  139.  
  140. #define ISALNUM(c) isalnum(c)
  141. #define ISALPHA(c) isalpha(c)
  142.  
  143. /*
  144. #else
  145. #define ISALNUM(c) (isascii(c) && isalnum(c))
  146. #define ISALPHA(c) (isascii(c) && isalpha(c))
  147. #endif
  148.  */
  149.  
  150. #else /* ! __STDC__ */
  151.  
  152. #define const
  153. #ifndef ACORN
  154. typedef int size_t;
  155. extern char *calloc(), *malloc(), *realloc();
  156. #else
  157. #include <stdlib.h>
  158. /* extern void *calloc(size_t,size_t), *malloc(size_t), *realloc(void *,size_t); */
  159. #endif
  160. extern void free();
  161.  
  162. extern char *bcopy(), *bzero();
  163.  
  164. #ifdef ACORN
  165. #define ISALNUM(c) (isprint(c) && isalnum(c))
  166. #define ISALPHA(c) (isprint(c) && isalpha(c))
  167. #else
  168. #define ISALNUM(c) (isascii(c) && isalnum(c))
  169. #define ISALPHA(c) (isascii(c) && isalpha(c))
  170. #endif
  171.  
  172. #endif /* ! __STDC__ */
  173.  
  174. /* 1 means plain parentheses serve as grouping, and backslash
  175.      parentheses are needed for literal searching.
  176.    0 means backslash-parentheses are grouping, and plain parentheses
  177.      are for literal searching.  */
  178. #define RE_NO_BK_PARENS 1
  179.  
  180. /* 1 means plain | serves as the "or"-operator, and \| is a literal.
  181.    0 means \| serves as the "or"-operator, and | is a literal.  */
  182. #define RE_NO_BK_VBAR 2
  183.  
  184. /* 0 means plain + or ? serves as an operator, and \+, \? are literals.
  185.    1 means \+, \? are operators and plain +, ? are literals.  */
  186. #define RE_BK_PLUS_QM 4
  187.  
  188. /* 1 means | binds tighter than ^ or $.
  189.    0 means the contrary.  */
  190. #define RE_TIGHT_VBAR 8
  191.  
  192. /* 1 means treat \n as an _OR operator
  193.    0 means treat it as a normal character */
  194. #define RE_NEWLINE_OR 16
  195.  
  196. /* 0 means that a special characters (such as *, ^, and $) always have
  197.      their special meaning regardless of the surrounding context.
  198.    1 means that special characters may act as normal characters in some
  199.      contexts.  Specifically, this applies to:
  200.         ^ - only special at the beginning, or after ( or |
  201.         $ - only special at the end, or before ) or |
  202.         *, +, ? - only special when not after the beginning, (, or | */
  203. #define RE_CONTEXT_INDEP_OPS 32
  204.  
  205. /* Now define combinations of bits for the standard possibilities.  */
  206. #define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_CONTEXT_INDEP_OPS)
  207. #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK | RE_NEWLINE_OR)
  208. #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR)
  209. #define RE_SYNTAX_EMACS 0
  210.  
  211. /* The NULL pointer.
  212. #define NULL 0 */
  213.  
  214. /* Number of bits in an unsigned char. */
  215. #define CHARBITS 8
  216.  
  217. /* First integer value that is greater than any character code. */
  218. #define _NOTCHAR (1 << CHARBITS)
  219.  
  220. /* INTBITS need not be exact, just a lower bound. */
  221. #define INTBITS (CHARBITS * sizeof (int))
  222.  
  223. /* Number of ints required to hold a bit for every character. */
  224. #define _CHARSET_INTS ((_NOTCHAR + INTBITS - 1) / INTBITS)
  225.  
  226. /* Sets of unsigned characters are stored as bit vectors in arrays of ints. */
  227. typedef int _charset[_CHARSET_INTS];
  228.  
  229. /* The regexp is parsed into an array of tokens in postfix form.  Some tokens
  230.    are operators and others are terminal symbols.  Most (but not all) of these
  231.    codes are returned by the lexical analyzer. */
  232. #ifdef __STDC__
  233.  
  234. typedef enum
  235. {
  236.   _END = -1,                    /* _END is a terminal symbol that matches the
  237.                                    end of input; any value of _END or less in
  238.                                    the parse tree is such a symbol.  Accepting
  239.                                    states of the DFA are those that would have
  240.                                    a transition on _END. */
  241.  
  242.   /* Ordinary character values are terminal symbols that match themselves. */
  243.  
  244.   _EMPTY = _NOTCHAR,            /* _EMPTY is a terminal symbol that matches
  245.                                    the empty string. */
  246.  
  247.   _BACKREF,                     /* _BACKREF is generated by \<digit>; it
  248.                                    it not completely handled.  If the scanner
  249.                                    detects a transition on backref, it returns
  250.                                    a kind of "semi-success" indicating that
  251.                                    the match will have to be verified with
  252.                                    a backtracking matcher. */
  253.  
  254.   _BEGLINE,                     /* _BEGLINE is a terminal symbol that matches
  255.                                    the empty string if it is at the beginning
  256.                                    of a line. */
  257.  
  258.   _ALLBEGLINE,                  /* _ALLBEGLINE is a terminal symbol that
  259.                                    matches the empty string if it is at the
  260.                                    beginning of a line; _ALLBEGLINE applies
  261.                                    to the entire regexp and can only occur
  262.                                    as the first token thereof.  _ALLBEGLINE
  263.                                    never appears in the parse tree; a _BEGLINE
  264.                                    is prepended with _CAT to the entire
  265.                                    regexp instead. */
  266.  
  267.   _ENDLINE,                     /* _ENDLINE is a terminal symbol that matches
  268.                                    the empty string if it is at the end of
  269.                                    a line. */
  270.  
  271.   _ALLENDLINE,                  /* _ALLENDLINE is to _ENDLINE as _ALLBEGLINE
  272.                                    is to _BEGLINE. */
  273.  
  274.   _BEGWORD,                     /* _BEGWORD is a terminal symbol that matches
  275.                                    the empty string if it is at the beginning
  276.                                    of a word. */
  277.  
  278.   _ENDWORD,                     /* _ENDWORD is a terminal symbol that matches
  279.                                    the empty string if it is at the end of
  280.                                    a word. */
  281.  
  282.   _LIMWORD,                     /* _LIMWORD is a terminal symbol that matches
  283.                                    the empty string if it is at the beginning
  284.                                    or the end of a word. */
  285.  
  286.   _NOTLIMWORD,                  /* _NOTLIMWORD is a terminal symbol that
  287.                                    matches the empty string if it is not at
  288.                                    the beginning or end of a word. */
  289.  
  290.   _QMARK,                       /* _QMARK is an operator of one argument that
  291.                                    matches zero or one occurences of its
  292.                                    argument. */
  293.  
  294.   _STAR,                        /* _STAR is an operator of one argument that
  295.                                    matches the Kleene closure (zero or more
  296.                                    occurrences) of its argument. */
  297.  
  298.   _PLUS,                        /* _PLUS is an operator of one argument that
  299.                                    matches the positive closure (one or more
  300.                                    occurrences) of its argument. */
  301.  
  302.   _CAT,                         /* _CAT is an operator of two arguments that
  303.                                    matches the concatenation of its
  304.                                    arguments.  _CAT is never returned by the
  305.                                    lexical analyzer. */
  306.  
  307.   _OR,                          /* _OR is an operator of two arguments that
  308.                                    matches either of its arguments. */
  309.  
  310.   _LPAREN,                      /* _LPAREN never appears in the parse tree,
  311.                                    it is only a lexeme. */
  312.  
  313.   _RPAREN,                      /* _RPAREN never appears in the parse tree. */
  314.  
  315.   _SET                          /* _SET and (and any value greater) is a
  316.                                    terminal symbol that matches any of a
  317.                                    class of characters. */
  318. } _token;
  319.  
  320. #else /* ! __STDC__ */
  321.  
  322. typedef short _token;
  323.  
  324. #define _END -1
  325. #define _EMPTY _NOTCHAR
  326. #define _BACKREF (_EMPTY + 1)
  327. #define _BEGLINE (_EMPTY + 2)
  328. #define _ALLBEGLINE (_EMPTY + 3)
  329. #define _ENDLINE (_EMPTY + 4)
  330. #define _ALLENDLINE (_EMPTY + 5)
  331. #define _BEGWORD (_EMPTY + 6)
  332. #define _ENDWORD (_EMPTY + 7)
  333. #define _LIMWORD (_EMPTY + 8)
  334. #define _NOTLIMWORD (_EMPTY + 9)
  335. #define _QMARK (_EMPTY + 10)
  336. #define _STAR (_EMPTY + 11)
  337. #define _PLUS (_EMPTY + 12)
  338. #define _CAT (_EMPTY + 13)
  339. #define _OR (_EMPTY + 14)
  340. #define _LPAREN (_EMPTY + 15)
  341. #define _RPAREN (_EMPTY + 16)
  342. #define _SET (_EMPTY + 17)
  343.  
  344. #endif /* ! __STDC__ */
  345.  
  346. /* Sets are stored in an array in the compiled regexp; the index of the
  347.    array corresponding to a given set token is given by _SET_INDEX(t). */
  348. #define _SET_INDEX(t) ((t) - _SET)
  349.  
  350. /* Sometimes characters can only be matched depending on the surrounding
  351.    context.  Such context decisions depend on what the previous character
  352.    was, and the value of the current (lookahead) character.  Context
  353.    dependent constraints are encoded as 8 bit integers.  Each bit that
  354.    is set indicates that the constraint succeeds in the corresponding
  355.    context.
  356.  
  357.    bit 7 - previous and current are newlines
  358.    bit 6 - previous was newline, current isn't
  359.    bit 5 - previous wasn't newline, current is
  360.    bit 4 - neither previous nor current is a newline
  361.    bit 3 - previous and current are word-constituents
  362.    bit 2 - previous was word-constituent, current isn't
  363.    bit 1 - previous wasn't word-constituent, current is
  364.    bit 0 - neither previous nor current is word-constituent
  365.  
  366.    Word-constituent characters are those that satisfy isalnum().
  367.  
  368.    The macro _SUCCEEDS_IN_CONTEXT determines whether a a given constraint
  369.    succeeds in a particular context.  Prevn is true if the previous character
  370.    was a newline, currn is true if the lookahead character is a newline.
  371.    Prevl and currl similarly depend upon whether the previous and current
  372.    characters are word-constituent letters. */
  373. #define _MATCHES_NEWLINE_CONTEXT(constraint, prevn, currn) \
  374.   ((constraint) & 1 << ((prevn) ? 2 : 0) + ((currn) ? 1 : 0) + 4)
  375. #define _MATCHES_LETTER_CONTEXT(constraint, prevl, currl) \
  376.   ((constraint) & 1 << ((prevl) ? 2 : 0) + ((currl) ? 1 : 0))
  377. #define _SUCCEEDS_IN_CONTEXT(constraint, prevn, currn, prevl, currl) \
  378.   (_MATCHES_NEWLINE_CONTEXT(constraint, prevn, currn)                \
  379.    && _MATCHES_LETTER_CONTEXT(constraint, prevl, currl))
  380.  
  381. /* The following macros give information about what a constraint depends on. */
  382. #define _PREV_NEWLINE_DEPENDENT(constraint) \
  383.   (((constraint) & 0xc0) >> 2 != ((constraint) & 0x30))
  384. #define _PREV_LETTER_DEPENDENT(constraint) \
  385.   (((constraint) & 0x0c) >> 2 != ((constraint) & 0x03))
  386.  
  387. /* Tokens that match the empty string subject to some constraint actually
  388.    work by applying that constraint to determine what may follow them,
  389.    taking into account what has gone before.  The following values are
  390.    the constraints corresponding to the special tokens previously defined. */
  391. #define _NO_CONSTRAINT 0xff
  392. #define _BEGLINE_CONSTRAINT 0xcf
  393. #define _ENDLINE_CONSTRAINT 0xaf
  394. #define _BEGWORD_CONSTRAINT 0xf2
  395. #define _ENDWORD_CONSTRAINT 0xf4
  396. #define _LIMWORD_CONSTRAINT 0xf6
  397. #define _NOTLIMWORD_CONSTRAINT 0xf9
  398.  
  399. /* States of the recognizer correspond to sets of positions in the parse
  400.    tree, together with the constraints under which they may be matched.
  401.    So a position is encoded as an index into the parse tree together with
  402.    a constraint. */
  403. typedef struct
  404. {
  405.   unsigned index;               /* Index into the parse array. */
  406.   unsigned constraint;          /* Constraint for matching this position. */
  407. } _position;
  408.  
  409. /* Sets of positions are stored as arrays. */
  410. typedef struct
  411. {
  412.   _position *elems;             /* Elements of this position set. */
  413.   int nelem;                    /* Number of elements in this set. */
  414. } _position_set;
  415.  
  416. /* A state of the regexp consists of a set of positions, some flags,
  417.    and the token value of the lowest-numbered position of the state that
  418.    contains an _END token. */
  419. typedef struct
  420. {
  421.   int hash;                     /* Hash of the positions of this state. */
  422.   _position_set elems;          /* Positions this state could match. */
  423.   char newline;                 /* True if previous state matched newline. */
  424.   char letter;                  /* True if previous state matched a letter. */
  425.   char backref;                 /* True if this state matches a \<digit>. */
  426.   unsigned char constraint;     /* Constraint for this state to accept. */
  427.   int first_end;                /* Token value of the first _END in elems. */
  428. } _dfa_state;
  429.  
  430. /* If an r.e. is at most MUST_MAX characters long, we look for a string which
  431.    must appear in it; whatever's found is dropped into the struct reg. */
  432.  
  433. #define MUST_MAX        50
  434.  
  435. /* A compiled regular expression. */
  436. struct regexp
  437. {
  438.   /* Stuff built by the scanner. */
  439.   _charset *charsets;           /* Array of character sets for _SET tokens. */
  440.   int cindex;                   /* Index for adding new charsets. */
  441.   int calloc;                   /* Number of charsets currently allocated. */
  442.  
  443.   /* Stuff built by the parser. */
  444.   _token *tokens;               /* Postfix parse array. */
  445.   int tindex;                   /* Index for adding new tokens. */
  446.   int talloc;                   /* Number of tokens currently allocated. */
  447.   int depth;                    /* Depth required of an evaluation stack
  448.                                    used for depth-first traversal of the
  449.                                    parse tree. */
  450.   int nleaves;                  /* Number of leaves on the parse tree. */
  451.   int nregexps;                 /* Count of parallel regexps being built
  452.                                    with regparse(). */
  453.  
  454.   /* Stuff owned by the state builder. */
  455.   _dfa_state *states;           /* States of the regexp. */
  456.   int sindex;                   /* Index for adding new states. */
  457.   int salloc;                   /* Number of states currently allocated. */
  458.  
  459.   /* Stuff built by the structure analyzer. */
  460.   _position_set *follows;       /* Array of follow sets, indexed by position
  461.                                    index.  The follow of a position is the set
  462.                                    of positions containing characters that
  463.                                    could conceivably follow a character
  464.                                    matching the given position in a string
  465.                                    matching the regexp.  Allocated to the
  466.                                    maximum possible position index. */
  467.   int searchflag;               /* True if we are supposed to build a searching
  468.                                    as opposed to an exact matcher.  A searching
  469.                                    matcher finds the first and shortest string
  470.                                    matching a regexp anywhere in the buffer,
  471.                                    whereas an exact matcher finds the longest
  472.                                    string matching, but anchored to the
  473.                                    beginning of the buffer. */
  474.  
  475.   /* Stuff owned by the executor. */
  476.   int tralloc;                  /* Number of transition tables that have
  477.                                    slots so far. */
  478.   int trcount;                  /* Number of transition tables that have
  479.                                    actually been built. */
  480.   int **trans;                  /* Transition tables for states that can
  481.                                    never accept.  If the transitions for a
  482.                                    state have not yet been computed, or the
  483.                                    state could possibly accept, its entry in
  484.                                    this table is NULL. */
  485.   int **realtrans;              /* Trans always points to realtrans + 1; this
  486.                                    is so trans[-1] can contain NULL. */
  487.   int **fails;                  /* Transition tables after failing to accept
  488.                                    on a state that potentially could do so. */
  489.   int *success;                 /* Table of acceptance conditions used in
  490.                                    regexecute and computed in build_state. */
  491.   int *newlines;                /* Transitions on newlines.  The entry for a
  492.                                    newline in any transition table is always
  493.                                    -1 so we can count lines without wasting
  494.                                    too many cycles.  The transition for a
  495.                                    newline is stored separately and handled
  496.                                    as a special case.  Newline is also used
  497.                                    as a sentinel at the end of the buffer. */
  498.   char must[MUST_MAX];
  499.   int mustn;
  500. };
  501.  
  502. /* Some macros for user access to regexp internals. */
  503.  
  504. /* ACCEPTING returns true if s could possibly be an accepting state of r. */
  505. #define ACCEPTING(s, r) ((r).states[s].constraint)
  506.  
  507. /* ACCEPTS_IN_CONTEXT returns true if the given state accepts in the
  508.    specified context. */
  509. #define ACCEPTS_IN_CONTEXT(prevn, currn, prevl, currl, state, reg) \
  510.   _SUCCEEDS_IN_CONTEXT((reg).states[state].constraint,             \
  511.                        prevn, currn, prevl, currl)
  512.  
  513. /* FIRST_MATCHING_REGEXP returns the index number of the first of parallel
  514.    regexps that a given state could accept.  Parallel regexps are numbered
  515.    starting at 1. */
  516. #define FIRST_MATCHING_REGEXP(state, reg) (-(reg).states[state].first_end)
  517.  
  518. /* Entry points. */
  519.  
  520. #ifdef __STDC__
  521.  
  522. /* Regsyntax() takes two arguments; the first sets the syntax bits described
  523.    earlier in this file, and the second sets the case-folding flag. */
  524. extern void regsyntax(int, int);
  525.  
  526. /* Compile the given string of the given length into the given struct regexp.
  527.    Final argument is a flag specifying whether to build a searching or an
  528.    exact matcher. */
  529. extern void regcompile(const char *, size_t, struct regexp *, int);
  530.  
  531. /* Execute the given struct regexp on the buffer of characters.  The
  532.    first char * points to the beginning, and the second points to the
  533.    first character after the end of the buffer, which must be a writable
  534.    place so a sentinel end-of-buffer marker can be stored there.  The
  535.    second-to-last argument is a flag telling whether to allow newlines to
  536.    be part of a string matching the regexp.  The next-to-last argument,
  537.    if non-NULL, points to a place to increment every time we see a
  538.    newline.  The final argument, if non-NULL, points to a flag that will
  539.    be set if further examination by a backtracking matcher is needed in
  540.    order to verify backreferencing; otherwise the flag will be cleared.
  541.    Returns NULL if no match is found, or a pointer to the first
  542.    character after the first & shortest matching string in the buffer. */
  543. extern char *regexecute(struct regexp *, char *, char *, int, int *, int *);
  544.  
  545. /* Free the storage held by the components of a struct regexp. */
  546. extern void regfree(struct regexp *);
  547.  
  548. /* Entry points for people who know what they're doing. */
  549.  
  550. /* Initialize the components of a struct regexp. */
  551. extern void reginit(struct regexp *);
  552.  
  553. /* Incrementally parse a string of given length into a struct regexp. */
  554. extern void regparse(const char *, size_t, struct regexp *);
  555.  
  556. /* Analyze a parsed regexp; second argument tells whether to build a searching
  557.    or an exact matcher. */
  558. extern void reganalyze(struct regexp *, int);
  559.  
  560. /* Compute, for each possible character, the transitions out of a given
  561.    state, storing them in an array of integers. */
  562. extern void regstate(int, struct regexp *, int []);
  563.  
  564. /* Error handling. */
  565.  
  566. /* Regerror() is called by the regexp routines whenever an error occurs.  It
  567.    takes a single argument, a NUL-terminated string describing the error.
  568.    The default regerror() prints the error message to stderr and exits.
  569.    The user can provide a different regfree() if so desired. */
  570. extern void regerror(const char *);
  571.  
  572. #else /* ! __STDC__ */
  573. extern void regsyntax(), regcompile(), regfree(), reginit(), regparse();
  574. extern void reganalyze(), regstate(), regerror();
  575. extern char *regexecute();
  576. #endif
  577.