home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / AWK.ZIP / REGEX.H < prev   
Encoding:
Text File  |  1988-09-09  |  11.6 KB  |  208 lines

  1. /**
  2.  * $Revision:   1.1  $
  3.  * $Log:   C:/AWK/REGEX.H_V  $
  4.  * 
  5.  *    Rev 1.1   09 Sep 1988 18:34:10   vince
  6.  * MC 5.1 version
  7.  * 
  8.  *    Rev 1.0   09 Sep 1988 18:03:58   vince
  9.  * Original source
  10.  *
  11.  * Definitions for data structures callers pass the regex library. 
  12.  *    Copyright (C) 1985 Free Software Foundation, Inc. 
  13.  *
  14.  * NO WARRANTY 
  15.  *
  16.  * BECAUSE THIS PROGRAM IS LICENSED FREE OF CHARGE, WE PROVIDE ABSOLUTELY NO
  17.  * WARRANTY, TO THE EXTENT PERMITTED BY APPLICABLE STATE LAW.  EXCEPT WHEN
  18.  * OTHERWISE STATED IN WRITING, FREE SOFTWARE FOUNDATION, INC, RICHARD M. STALLMAN
  19.  * AND/OR OTHER PARTIES PROVIDE THIS PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
  20.  * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE
  22.  * ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
  23.  * SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
  24.  * SERVICING, REPAIR OR CORRECTION. 
  25.  *
  26.  * IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL RICHARD M. STALLMAN,
  27.  * THE FREE SOFTWARE FOUNDATION, INC., AND/OR ANY OTHER PARTY WHO MAY MODIFY
  28.  * AND REDISTRIBUTE THIS PROGRAM AS PERMITTED BELOW, BE LIABLE TO YOU FOR
  29.  * DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL,
  30.  * INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO
  31.  * USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
  32.  * INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES OR A FAILURE OF THE PROGRAM TO
  33.  * OPERATE WITH ANY OTHER PROGRAMS) THIS PROGRAM, EVEN IF YOU HAVE BEEN ADVISED
  34.  * OF THE POSSIBILITY OF SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. 
  35.  *
  36.  * GENERAL PUBLIC LICENSE TO COPY 
  37.  *
  38.  * 1. You may copy and distribute verbatim copies of this source file as you
  39.  *    receive it, in any medium, provided that you conspicuously and appropriately
  40.  *    publish on each copy a valid copyright notice "Copyright (C) 1986 Free
  41.  *    Software Foundation, Inc."; and include following the copyright notice
  42.  *    a verbatim copy of the above disclaimer of warranty and of this License. 
  43.  *
  44.  * 2. You may modify your copy or copies of this source file or any portion of
  45.  *    it, and copy and distribute such modifications under the terms of Paragraph 1
  46.  *    above, provided that you also do the following: 
  47.  *
  48.  *    a) cause the modified files to carry prominent notices stating that you changed
  49.  *       the files and the date of any change; and 
  50.  *
  51.  *    b) cause the whole of any work that you distribute or publish, that in whole or
  52.  *       in part contains or is a derivative of this program or any part thereof,
  53.  *       to be freely distributed and licensed to all third parties on terms identical
  54.  *       to those contained in this License Agreement (except that you may choose
  55.  *       to grant more extensive warranty protection to third parties, at your option). 
  56.  *
  57.  * 3. You may copy and distribute this program or any portion of it in compiled,
  58.  *    executable or object code form under the terms of Paragraphs 1 and 2 above
  59.  *    provided that you do the following: 
  60.  *
  61.  *    a) cause each such copy to be accompanied by the corresponding machine-
  62.  *       readable source code, which must be distributed under the terms of
  63.  *       Paragraphs 1 and 2 above; or, 
  64.  *
  65.  *    b) cause each such copy to be accompanied by a written offer, with no
  66.  *       time limit, to give any third party free (except for a nominal shipping
  67.  *       charge) a machine readable copy of the corresponding source code, to be
  68.  *       distributed under the terms of Paragraphs 1 and 2 above; or, 
  69.  *
  70.  *    c) in the case of a recipient of this program in compiled, executable or
  71.  *       object code form (without the corresponding source code) you shall
  72.  *       cause copies you distribute to be accompanied by a copy of the written
  73.  *       offer of source code which you received along with the copy you received. 
  74.  *
  75.  * 4. You may not copy, sublicense, distribute or transfer this program except as
  76.  *    expressly provided under this License Agreement.  Any attempt otherwise
  77.  *    to copy, sublicense, distribute or transfer this program is void and your
  78.  *    rights to use the program under this License agreement shall be
  79.  *    automatically terminated.  However, parties who have received computer
  80.  *    software programs from you with this License Agreement will not have their
  81.  *    licenses terminated so long as such parties remain in full compliance. 
  82.  *
  83.  *
  84.  * In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and
  85.  * improve what you give them.   Help stamp out software-hoarding!
  86.  *
  87.  * Modifications by Andrew D. Estes, July 1988 
  88.  */
  89.  
  90. #ifndef RE_NREGS
  91. #define RE_NREGS 10
  92. #endif
  93.  
  94.  
  95. /* JF for syntax stuff */
  96. /*
  97.  * To add more variable-syntax features, just use more bits.  If we go over 16, we probably should make obscure_syntax a long. 
  98.  * (JF: Yes, virgina, there really are 16 bit machines out there) 
  99.  */
  100. #define RE_NO_BK_PARENS (1<<0)
  101. #define RE_NO_BK_VBAR   (1<<1)
  102.  
  103. /* This data structure is used to represent a compiled pattern. */
  104.  
  105. struct re_pattern_buffer
  106. {
  107.    char *buffer;                       /* Space holding the compiled pattern commands. */
  108.    int allocated;                      /* Size of space that  buffer  points to */
  109.    int used;                           /* Length of portion of buffer actually occupied */
  110.    char *fastmap;                      /* Pointer to fastmap, if any, or zero if none. */
  111.    /*
  112.     * re_search uses the fastmap, if there is one, to skip quickly over totally implausible characters 
  113.     */
  114.    char *translate;                    /* Translate table to apply to all characters before comparing. Or zero for no translation.
  115.                                         * The translation is applied to a pattern when it is compiled and to data when it is
  116.                                         * matched. */
  117.    char fastmap_accurate;
  118.    /*
  119.     * Set to zero when a new pattern is stored, set to one when the fastmap is updated from it. 
  120.     */
  121.    char can_be_null;                   /* Set to one by compiling fastmap if this pattern might match the null string. It does not
  122.                                         * necessarily match the null string in that case, but if this is zero, it cannot. 2 as
  123.                                         * value means can match null string but at end of range or before a character listed in the
  124.                                         * fastmap.  */
  125. };
  126.  
  127. /*
  128.  * Structure to store "register" contents data in. 
  129.  *
  130.  * Pass the address of such a structure as an argument to re_match, etc., if you want this information back. 
  131.  *
  132.  * start[i] and end[i] record the string matched by \( ... \) grouping i, for i from 1 to RE_NREGS - 1. start[0] and end[0] record the
  133.  * entire string matched. 
  134.  */
  135.  
  136. struct re_registers
  137. {
  138.    int start[RE_NREGS];
  139.    int end[RE_NREGS];
  140. };
  141.  
  142. /*
  143.  * These are the command codes that appear in compiled regular expressions, one per byte. Some command codes are followed by
  144.  * argument bytes. A command code can specify any interpretation whatever for its arguments. Zero-bytes may appear in the compiled
  145.  * regular expression. 
  146.  */
  147.  
  148. enum regexpcode
  149. {
  150.    unused,
  151.    exactn,                             /* followed by one byte giving n, and then by n literal bytes */
  152.    begline,                            /* fails unless at beginning of line */
  153.    endline,                            /* fails unless at end of line */
  154.    jump,                               /* followed by two bytes giving relative address to jump to */
  155.    on_failure_jump,                    /* followed by two bytes giving relative address of place to resume at in case of failure. */
  156.    finalize_jump,                      /* Throw away latest failure point and then jump to address. */
  157.    maybe_finalize_jump,                /* Like jump but finalize if safe to do so. This is used to jump back to the beginning of a
  158.                                         * repeat.  If the command that follows this jump is clearly incompatible with the one at
  159.                                         * the beginning of the repeat, such that we can be sure that there is no use backtracking
  160.                                         * out of repetitions already completed, then we finalize. */
  161.    dummy_failure_jump,                 /* jump, and push a dummy failure point. This failure point will be thrown away if an
  162.                                         * attempt is made to use it for a failure. A + construct makes this before the first
  163.                                         * repeat.  */
  164.    anychar,                            /* matches any one character */
  165.    charset,                            /* matches any one char belonging to specified set. First following byte is # bitmap bytes.
  166.                                         * Then come bytes for a bit-map saying which chars are in. Bits in each byte are ordered
  167.                                         * low-bit-first. A character is in the set if its bit is 1. A character too large to have a
  168.                                         * bit in the map is automatically not in the set */
  169.    charset_not,                        /* similar but match any character that is NOT one of those specified */
  170.    start_memory,                       /* starts remembering the text that is matched and stores it in a memory register. followed
  171.                                         * by one byte containing the register number. Register numbers must be in the range 0
  172.                                         * through NREGS. */
  173.    stop_memory,                        /* stops remembering the text that is matched and stores it in a memory register. followed
  174.                                         * by one byte containing the register number. Register numbers must be in the range 0
  175.                                         * through NREGS. */
  176.    duplicate,                          /* match a duplicate of something remembered. Followed by one byte containing the index of
  177.                                         * the memory register. */
  178.    before_dot,                         /* Succeeds if before dot */
  179.    at_dot,                             /* Succeeds if at dot */
  180.    after_dot,                          /* Succeeds if after dot */
  181.    begbuf,                             /* Succeeds if at beginning of buffer */
  182.    endbuf,                             /* Succeeds if at end of buffer */
  183.    wordchar,                           /* Matches any word-constituent character */
  184.    notwordchar,                        /* Matches any char that is not a word-constituent */
  185.    wordbeg,                            /* Succeeds if at word beginning */
  186.    wordend,                            /* Succeeds if at word end */
  187.    wordbound,                          /* Succeeds if at a word boundary */
  188.    notwordbound,                       /* Succeeds if not at a word boundary */
  189.    syntaxspec,                         /* Matches any character whose syntax is specified. followed by a byte which contains a
  190.                                         * syntax code, Sword or such like */
  191.    notsyntaxspec                       /* Matches any character whose syntax differs from the specified. */
  192. };
  193.  
  194.  
  195. extern char *re_compile_pattern();
  196. /* Is this really advertised? */
  197. extern void re_compile_fastmap();
  198. extern int re_search(), re_search_2();
  199. extern int re_match(), re_match_2();
  200.  
  201. /* 4.2 bsd compatibility (yuck) */
  202. extern char *re_comp();
  203. extern int re_exec();
  204.  
  205. #ifdef SYNTAX_TABLE
  206. extern char *re_syntax_table;
  207. #endif
  208.