home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / cutils / Regex / H / Regex
Encoding:
Text File  |  1991-05-12  |  5.2 KB  |  162 lines

  1. /* Definitions for data structures callers pass the regex library.
  2.  
  3.    Copyright (C) 1985, 1989-90 Free Software Foundation, Inc.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 1, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19.  
  20. #ifndef __REGEX_H
  21. #define __REGEX_H
  22.  
  23. /* We need size_t. There are three possibilities:
  24.    1. Require <stddef.h> to be included before "regex.h" - obnoxious.
  25.    2. Include <stddef.h> here - nested includes are a nuisance.
  26.    3. Copy the definition from <stddef.h> - this is the approach Acorn
  27.       uses, and it seems the lesser evil. Requires keeping in line...
  28.  */
  29.  
  30. #ifndef __size_t
  31. #define __size_t 1
  32. typedef unsigned int size_t;        /* others (e.g. <stddef.h>) define */
  33.    /* the unsigned integral type of the result of the sizeof operator. */
  34. #endif
  35.  
  36. /* Define number of parens for which we record the beginnings and ends.
  37.    This affects how much space the `struct re_registers' type takes up.  */
  38. #define RE_NREGS 10
  39.  
  40. /* Maximum number of duplicates an interval can allow.  */
  41. #define RE_DUP_MAX  ((1 << 15) - 1)
  42.  
  43. /* The following section contains GNU regex compatibility functions.
  44.  * These allow (in the GNU version) for run-time tailoring of the regex
  45.  * syntax allowed. In this version, the syntax is fixed and these functions
  46.  * do nothing.
  47.  */
  48. #define RE_NO_BK_PARENS            0
  49. #define RE_NO_BK_VBAR            0
  50. #define RE_BK_PLUS_QM            0
  51. #define RE_TIGHT_VBAR            0
  52. #define RE_NEWLINE_OR            0
  53. #define RE_CONTEXT_INDEP_OPS        0
  54. #define RE_AWK_CLASS_HACK        0
  55. #define RE_INTERVALS            0
  56. #define RE_NO_BK_CURLY_BRACES        0
  57. #define RE_CHAR_CLASSES            0
  58. #define RE_DOT_NOT_NULL            0
  59. #define RE_HAT_NOT_NEWLINE        0
  60. #define RE_NO_BK_REFS            0
  61. #define RE_NO_EMPTY_BK_REF        0
  62. #define RE_NO_EMPTY_BRACKETS        0
  63. #define RE_CONTEXTUAL_INVALID_OPS    0
  64. #define RE_LIMITED_OPS            0
  65. #define RE_NO_EMPTY_RANGES        0
  66. #define RE_NO_HYPHEN_RANGE_END        0
  67. #define RE_SYNTAX_POSIX_AWK        0
  68. #define RE_SYNTAX_AWK            0
  69. #define RE_SYNTAX_EGREP            0
  70. #define RE_SYNTAX_GREP            0
  71. #define RE_SYNTAX_EMACS            0
  72. #define RE_SYNTAX_POSIX_BASIC        0
  73. #define RE_SYNTAX_POSIX_EXTENDED    0
  74. #define RE_EXACTN_VALUE            1 /* Used in GNU emacs... */
  75. #define re_set_syntax(n)        0
  76.  
  77. /* This data structure is used to represent a compiled pattern.
  78.  *
  79.  * The fields are:
  80.  *
  81.  * buffer        - Space holding the compiled pattern commands.
  82.  * allocated        - Size of the space that buffer points to.
  83.  * used            - Length of the portion of buffer which is actually
  84.  *              occupied.
  85.  * fastmap        - Pointer to the fastmap (if any). This is set up by
  86.  *              re_search to skip over characters which can't start
  87.  *              a match.
  88.  * translate        - Translation table to apply to all characters before
  89.  *              comparing (NULL if no translation is to occur).
  90.  * fastmap_accurate    - Set to 1 when the fastmap is correct.
  91.  * can_be_null        - Set when the fastmap is compiled. Zero means the
  92.  *              pattern cannot match the null string, 1 means it
  93.  *              may, and 2 means it may match a null at the end of
  94.  *              a line, or before a character in the fastmap.
  95.  */
  96.  
  97. typedef struct re_pattern_buffer
  98. {
  99.     char *buffer;
  100.     size_t allocated;
  101.     size_t used;
  102.     char *fastmap;
  103.     const char *translate;
  104.     char fastmap_accurate;
  105.     char can_be_null;
  106. }
  107. REGEX;
  108.  
  109. /* This data structure is used to store register contents data in.
  110.  *
  111.  * Pass the address of such a structure as an argument to re_match, etc.,
  112.  * if you want this information back.
  113.  *
  114.  * For i from 1 to RE_NREGS - 1, start[i] records the starting index in
  115.  * the string of where the ith subexpression matched, and end[i] records
  116.  * one after the ending index.  start[0] and end[0] are analogous, for
  117.  * the entire pattern.
  118.  */
  119.  
  120. typedef struct re_registers
  121. {
  122.     int start[RE_NREGS];
  123.     int end[RE_NREGS];
  124. }
  125. REREGS;
  126.  
  127. /* Return values from re_match */
  128. #define RE_FAIL        (-1)
  129. #define RE_ERROR    (-2)
  130.  
  131. /* The following is the external interface */
  132.  
  133. /* GNU compatible interface */
  134. extern char *re_compile_pattern (char *, int, REGEX *);
  135. extern void re_compile_fastmap (REGEX *);
  136. extern int re_search_2 (REGEX *, char *, int, char *, int, int, int,
  137.             REREGS *, int);
  138. extern int re_match_2 (REGEX *, char *, int, char *, int, int, REREGS *, int);
  139.  
  140. /* BSD compatible interface */
  141. extern char *re_comp (char *);
  142. extern int re_exec (char *);
  143.  
  144. /* Simpler matching functions for one string only - prototypes would be
  145.  *
  146.  *    int re_match (REGEX *, char *, int, int, REREGS *)
  147.  *    int re_search (REGEX *, char*, int, int, int, REREGS *)
  148.  *
  149.  * Provided as functions in the GNU package, but macros here.
  150.  */
  151.  
  152. #define re_search(re,str,size,start,range,regs)    \
  153.     re_search_2 (re, 0, 0, str, size, start, range, regs, size)
  154. #define re_match(re,str,size,pos,regs)        \
  155.     re_match_2 (re, 0, 0, str, size, pos, regs, size)
  156.  
  157. /* Creation and deletion of regex buffers */
  158. extern REGEX *re_create (const char *);
  159. extern void re_free (REGEX *);
  160.  
  161. #endif /* !__REGEX_H */
  162.