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