home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / NGAWK1.ZIP / REGEX.H < prev   
C/C++ Source or Header  |  1988-07-17  |  10KB  |  217 lines

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