1 /*
2 
3 regexpr.h
4 
5 Author: Tatu Ylonen <ylo@ngs.fi>
6 
7 Copyright (c) 1991 Tatu Ylonen, Espoo, Finland
8 
9 Permission to use, copy, modify, distribute, and sell this software
10 and its documentation is hereby granted without fee, provided that the
11 above copyright notice appears in all source code copies, the name of
12 Tatu Ylonen is not used to advertise products containing this software
13 or a derivation thereof, and all modified versions are clearly marked
14 as such.
15 
16 This software is provided "as is" without express or implied warranty.
17 
18 Created: Thu Sep 26 17:15:36 1991 ylo
19 Last modified: Fri Jan  3 12:05:45 1992 ylo
20 
21 Small changes made by Christopher J. Kane 94/01/19 marked with "(cjk)",
22 for the NeXT system.  Changes also made to regexpr.c.
23  - hide re_comp(), re_exec()
24  - renamed re_match.* to re_match_pattern.* and re_search.* to
25    re_search_pattern.* to avoid tiresome library conflicts on NeXT
26    (re_match conflicted)
27  - eliminated all compiler warnings
28 */
29 
30 #ifndef REGEXPR_H
31 #define REGEXPR_H
32 
33 #define RE_NREGS	10  /* number of registers available */
34 
35 typedef struct re_pattern_buffer
36 {
37   char *buffer; 	 /* compiled pattern */
38   int allocated;	 /* allocated size of compiled pattern */
39   int used;		 /* actual length of compiled pattern */
40   char *fastmap;	 /* fastmap[ch] is true if ch can start pattern */
41   char *translate;	 /* translation to apply during compilation/matching */
42   char fastmap_accurate; /* true if fastmap is valid */
43   char can_be_null;	 /* true if can match empty string */
44   char uses_registers;	 /* registers are used and need to be initialized */
45   char anchor;		 /* anchor: 0=none 1=begline 2=begbuf */
46 } *regexp_t;
47 
48 typedef struct re_registers
49 {
50   int start[RE_NREGS];  /* start offset of region */
51   int end[RE_NREGS];    /* end offset of region */
52 } *regexp_registers_t;
53 
54 /* bit definitions for syntax */
55 #define RE_NO_BK_PARENS		1    /* no quoting for parentheses */
56 #define RE_NO_BK_VBAR		2    /* no quoting for vertical bar */
57 #define RE_BK_PLUS_QM		4    /* quoting needed for + and ? */
58 #define RE_TIGHT_VBAR		8    /* | binds tighter than ^ and $ */
59 #define RE_NEWLINE_OR		16   /* treat newline as or */
60 #define RE_CONTEXT_INDEP_OPS	32   /* ^$?*+ are special in all contexts */
61 #define RE_ANSI_HEX		64   /* ansi sequences (\n etc) and \xhh */
62 #define RE_NO_GNU_EXTENSIONS   128   /* no gnu extensions */
63 
64 /* definitions for some common regexp styles */
65 #define RE_SYNTAX_AWK	(RE_NO_BK_PARENS|RE_NO_BK_VBAR|RE_CONTEXT_INDEP_OPS)
66 #define RE_SYNTAX_EGREP	(RE_SYNTAX_AWK|RE_NEWLINE_OR)
67 #define RE_SYNTAX_GREP	(RE_BK_PLUS_QM|RE_NEWLINE_OR)
68 #define RE_SYNTAX_EMACS	0
69 
70 #ifdef __STDC__
71 
72 int re_set_syntax(int syntax);
73 /* This sets the syntax to use and returns the previous syntax.  The
74    syntax is specified by a bit mask of the above defined bits. */
75 
76 char *re_compile_pattern(char *regex, int regex_size, regexp_t compiled);
77 /* This compiles the regexp (given in regex and length in regex_size).
78    This returns NULL if the regexp compiled successfully, and an error
79    message if an error was encountered.  The buffer field must be
80    initialized to a memory area allocated by malloc (or to NULL) before
81    use, and the allocated field must be set to its length (or 0 if buffer is
82    NULL).  Also, the translate field must be set to point to a valid
83    translation table, or NULL if it is not used. */
84 
85 int re_match_pattern(regexp_t compiled, char *string, int size, int pos,
86 	     regexp_registers_t regs);
87 /* This tries to match the regexp against the string.  This returns the
88    length of the matched portion, or -1 if the pattern could not be
89    matched and -2 if an error (such as failure stack overflow) is
90    encountered. */
91 
92 int re_match_pattern_2(regexp_t compiled, char *string1, int size1,
93 	      char *string2, int size2, int pos, regexp_registers_t regs,
94 	       int mstop);
95 /* This tries to match the regexp to the concatenation of string1 and
96    string2.  This returns the length of the matched portion, or -1 if the
97    pattern could not be matched and -2 if an error (such as failure stack
98    overflow) is encountered. */
99 
100 int re_search_pattern(regexp_t compiled, char *string, int size, int startpos,
101 	      int range, regexp_registers_t regs);
102 /* This rearches for a substring matching the regexp.  This returns the first
103    index at which a match is found.  range specifies at how many positions to
104    try matching; positive values indicate searching forwards, and negative
105    values indicate searching backwards.  mstop specifies the offset beyond
106    which a match must not go.  This returns -1 if no match is found, and
107    -2 if an error (such as failure stack overflow) is encountered. */
108 
109 int re_search_pattern_2(regexp_t compiled, char *string1, int size1,
110 		char *string2, int size2, int startpos, int range,
111 		regexp_registers_t regs, int mstop);
112 /* This is like re_search, but search from the concatenation of string1 and
113    string2.  */
114 
115 void re_compile_fastmap(regexp_t compiled);
116 /* This computes the fastmap for the regexp.  For this to have any effect,
117    the calling program must have initialized the fastmap field to point
118    to an array of 256 characters. */
119 
120 /* 94/01/19 (cjk) hide these on NeXT */
121 #if !defined(NeXT)
122 char *re_comp(char *s);
123 /* BSD 4.2 regex library routine re_comp.  This compiles the regexp into
124    an internal buffer.  This returns NULL if the regexp was compiled
125    successfully, and an error message if there was an error. */
126 
127 int re_exec(char *s);
128 /* BSD 4.2 regexp library routine re_exec.  This returns true if the string
129    matches the regular expression (that is, a matching part is found
130    anywhere in the string). */
131 #endif /* !defined(NeXT) */
132 
133 #else /* __STDC__ */
134 
135 int re_set_syntax();
136 char *re_compile_pattern();
137 int re_match_pattern();
138 int re_match_pattern_2();
139 int re_search_pattern();
140 int re_search_pattern_2();
141 void re_compile_fastmap();
142 
143 /* 94/01/19 (cjk) hide these on NeXT */
144 #if !defined(NeXT)
145 char *re_comp();
146 int re_exec();
147 #endif /* !defined(NeXT) */
148 
149 #endif /* __STDC__ */
150 
151 #endif /* REGEXPR_H */
152 
153 
154