home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / microcode / regex.h < prev    next >
C/C++ Source or Header  |  1999-01-02  |  8KB  |  212 lines

  1. /* -*-C-*-
  2.  
  3. $Id: regex.h,v 1.7 1999/01/02 06:11:34 cph Exp $
  4.  
  5. Copyright (c) 1987-1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. /* NOTE: This program was created by translation from the regular
  23. expression code of GNU Emacs; it was translated from the original C to
  24. 68000 assembly language (in 1986), and then translated back from 68000
  25. assembly language to C (in 1987).  Users should be aware that the GNU
  26. GENERAL PUBLIC LICENSE may apply to this code.  A copy of that license
  27. should have been included along with this file. */
  28.  
  29. /* Structure to represent a buffer of text to match against.
  30.    This contains the information that an editor buffer would have
  31.    to supply for the matching process to be executed.
  32.  
  33.    `translation' is an array of MAX_ASCII characters which is used to
  34.    map each character before matching.  Both the pattern and the match
  35.    text are mapped.  This is normally used to implement case
  36.    insensitive searches.
  37.  
  38.    `syntax_table' describes the syntax of the match text.  See the
  39.    syntax table primitives for more information.
  40.  
  41.    `text' points to the beginning of the match text.  It is used only
  42.    for translating match text pointers into indices.
  43.  
  44.    `text_start' and `text_end' delimit the match text.  They define
  45.    the buffer-start and buffer-end for those matching commands that
  46.    refer to them.  Also, all matching must take place within these
  47.    limits.
  48.  
  49.    `gap_start' and `gap_end' delimit a gap in the match text.  Editor
  50.    buffers normally have such a gap.  For applications without a gap,
  51.    it is recommended that these be set to the same value as
  52.    `text_end'.
  53.  
  54.    Both `text_start' and `gap_start' are inclusive indices, while
  55.    `text_end' and `gap_end' are exclusive.
  56.  
  57.    The following conditions must be true:
  58.  
  59.    (text <= text_start)
  60.    (text_start <= text_end)
  61.    (gap_start <= gap_end)
  62.    (! ((text_start < text_end) &&
  63.        (gap_start < gap_end) &&
  64.        ((text_start == gap_start) || (text_end == gap_end))))
  65.  
  66.    */
  67.  
  68. struct re_buffer
  69.   {
  70.     unsigned char *translation;
  71.     SYNTAX_TABLE_TYPE syntax_table;
  72.     unsigned char *text;
  73.     unsigned char *text_start;
  74.     unsigned char *text_end;
  75.     unsigned char *gap_start;
  76.     unsigned char *gap_end;
  77.   };
  78.  
  79. /* Structure to store "register" contents data in.
  80.  
  81.    Pass the address of such a structure as an argument to re_match,
  82.    etc., if you want this information back.
  83.  
  84.    start[i] and end[i] record the string matched by \( ... \) grouping
  85.    i, for i from 1 to RE_NREGS - 1.
  86.  
  87.    start[0] and end[0] record the entire string matched. */
  88.  
  89. #define RE_NREGS 10
  90.  
  91. struct re_registers
  92.   {
  93.     long start[RE_NREGS];
  94.     long end[RE_NREGS];
  95.   };
  96.  
  97. /* These are the command codes that appear in compiled regular
  98.    expressions, one per byte.  Some command codes are followed by
  99.    argument bytes.  A command code can specify any interpretation
  100.    whatever for its arguments.  Zero-bytes may appear in the compiled
  101.    regular expression. */
  102.  
  103. enum regexpcode
  104.   {
  105.     regexpcode_unused,
  106.     regexpcode_exact_1,        /* Followed by 1 literal byte */
  107.  
  108.     /* Followed by one byte giving n, and then by n literal bytes. */
  109.     regexpcode_exact_n,
  110.  
  111.     regexpcode_line_start,    /* Fails unless at beginning of line */
  112.     regexpcode_line_end,    /* Fails unless at end of line */
  113.  
  114.     /* Followed by two bytes giving relative address to jump to. */
  115.     regexpcode_jump,
  116.  
  117.     /* Followed by two bytes giving relative address of place to
  118.        resume at in case of failure. */
  119.     regexpcode_on_failure_jump,
  120.  
  121.     /* Throw away latest failure point and then jump to address. */
  122.     regexpcode_finalize_jump,
  123.  
  124.     /* Like jump but finalize if safe to do so.  This is used to jump
  125.        back to the beginning of a repeat.  If the command that follows
  126.        this jump is clearly incompatible with the one at the beginning
  127.        of the repeat, such that we can be sure that there is no use
  128.        backtracking out of repetitions already completed, then we
  129.        finalize. */
  130.     regexpcode_maybe_finalize_jump,
  131.  
  132.     /* jump, and push a dummy failure point.  This failure point will
  133.        be thrown away if an attempt is made to use it for a failure.
  134.        A + construct makes this before the first repeat. */
  135.     regexpcode_dummy_failure_jump,
  136.  
  137.     regexpcode_any_char,    /* Matches any one character */
  138.  
  139.     /* Matches any one char belonging to specified set.  First
  140.        following byte is # bitmap bytes.  Then come bytes for a
  141.        bit-map saying which chars are in.  Bits in each byte are
  142.        ordered low-bit-first.  A character is in the set if its bit is
  143.        1.  A character too large to have a bit in the map is
  144.        automatically not in the set. */
  145.     regexpcode_char_set,
  146.  
  147.     /* Similar but match any character that is NOT one of those
  148.        specified. */
  149.     regexpcode_not_char_set,
  150.  
  151.     /* Starts remembering the text that is matched and stores it in a
  152.        memory register.  Followed by one byte containing the register
  153.        number.  Register numbers must be in the range 0 through
  154.        (RE_NREGS - 1) inclusive.  */
  155.     regexpcode_start_memory,
  156.  
  157.     /* Stops remembering the text that is matched and stores it in a
  158.        memory register.  Followed by one byte containing the register
  159.        number.  Register numbers must be in the range 0 through
  160.        (RE_NREGS - 1) inclusive.  */
  161.     regexpcode_stop_memory,
  162.  
  163.     /* Match a duplicate of something remembered.  Followed by one
  164.        byte containing the index of the memory register. */
  165.     regexpcode_duplicate,
  166.  
  167.     regexpcode_buffer_start,    /* Succeeds if at beginning of buffer */
  168.     regexpcode_buffer_end,    /* Succeeds if at end of buffer */
  169.     regexpcode_word_char,    /* Matches any word-constituent character */
  170.  
  171.     /* Matches any char that is not a word-constituent. */
  172.     regexpcode_not_word_char,
  173.  
  174.     regexpcode_word_start,    /* Succeeds if at word beginning */
  175.     regexpcode_word_end,    /* Succeeds if at word end */
  176.     regexpcode_word_bound,    /* Succeeds if at a word boundary */
  177.     regexpcode_not_word_bound,    /* Succeeds if not at a word boundary */
  178.  
  179.     /* Matches any character whose syntax is specified.  Followed by a
  180.        byte which contains a syntax code, Sword or such like. */
  181.     regexpcode_syntax_spec,
  182.  
  183.     /* Matches any character whose syntax differs from the specified. */
  184.     regexpcode_not_syntax_spec
  185.   };
  186.  
  187. extern void
  188.   EXFUN (re_buffer_initialize,
  189.      (struct re_buffer *, unsigned char *, SYNTAX_TABLE_TYPE,
  190.       unsigned char *, unsigned long, unsigned long,
  191.       unsigned long, unsigned long));
  192.  
  193. extern int
  194.   EXFUN (re_compile_fastmap,
  195.      (unsigned char *, unsigned char *, unsigned char *,
  196.       SYNTAX_TABLE_TYPE, unsigned char *));
  197.  
  198. extern int
  199.   EXFUN (re_match,
  200.      (unsigned char *, unsigned char *, struct re_buffer *,
  201.       struct re_registers *, unsigned char *, unsigned char *));
  202.  
  203. extern int
  204.   EXFUN (re_search_forward,
  205.      (unsigned char *, unsigned char *, struct re_buffer *,
  206.       struct re_registers *, unsigned char *, unsigned char *));
  207.  
  208. extern int
  209.   EXFUN (re_search_backward,
  210.      (unsigned char *, unsigned char *, struct re_buffer *,
  211.       struct re_registers *, unsigned char *, unsigned char *));
  212.