home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / dfa.h < prev    next >
C/C++ Source or Header  |  1992-01-19  |  23KB  |  564 lines

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