Mercurial > cpython-lru_cache-weakref
annotate Modules/regexpr.h @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 18a639db048c |
| children | 0965d9fd1862 |
| rev | line source |
|---|---|
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
1 /* |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
2 * -*- mode: c-mode; c-file-style: python -*- |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
3 */ |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
4 |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1273
diff
changeset
|
5 #ifndef Py_REGEXPR_H |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1273
diff
changeset
|
6 #define Py_REGEXPR_H |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1273
diff
changeset
|
7 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1273
diff
changeset
|
8 extern "C" { |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1273
diff
changeset
|
9 #endif |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1273
diff
changeset
|
10 |
| 616 | 11 /* |
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
12 * regexpr.h |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
13 * |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
14 * Author: Tatu Ylonen <ylo@ngs.fi> |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
15 * |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
16 * Copyright (c) 1991 Tatu Ylonen, Espoo, Finland |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
17 * |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
18 * Permission to use, copy, modify, distribute, and sell this software |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
19 * and its documentation for any purpose is hereby granted without fee, |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
20 * provided that the above copyright notice appear in all copies. This |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
21 * software is provided "as is" without express or implied warranty. |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
22 * |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
23 * Created: Thu Sep 26 17:15:36 1991 ylo |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
24 * Last modified: Mon Nov 4 15:49:46 1991 ylo |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
25 */ |
| 616 | 26 |
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
27 /* $Id$ */ |
| 616 | 28 |
| 29 #ifndef REGEXPR_H | |
| 30 #define REGEXPR_H | |
| 31 | |
|
1273
69a066b6b1ff
(I suggest a recompile after getting this, the ceval.c bugfix may be crucial!)
Guido van Rossum <guido@python.org>
parents:
640
diff
changeset
|
32 #define RE_NREGS 100 /* number of registers available */ |
| 616 | 33 |
| 34 typedef struct re_pattern_buffer | |
| 35 { | |
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
36 char *buffer; /* compiled pattern */ |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
37 int allocated; /* allocated size of compiled pattern */ |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
38 int used; /* actual length of compiled pattern */ |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
39 char *fastmap; /* fastmap[ch] is true if ch can start pattern */ |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
40 char *translate; /* translation to apply during compilation/matching */ |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
41 char fastmap_accurate; /* true if fastmap is valid */ |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
42 char can_be_null; /* true if can match empty string */ |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
43 char uses_registers; /* registers are used and need to be initialized */ |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
44 int num_registers; /* number of registers used */ |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
45 char anchor; /* anchor: 0=none 1=begline 2=begbuf */ |
| 616 | 46 } *regexp_t; |
| 47 | |
| 48 typedef struct re_registers | |
| 49 { | |
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
50 int start[RE_NREGS]; /* start offset of region */ |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
51 int end[RE_NREGS]; /* end offset of region */ |
| 616 | 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 | |
|
3612
4866a0fc2bbd
rename exported symbols with _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
70 /* Rename all exported symbols to avoid conflicts with similarly named |
|
4866a0fc2bbd
rename exported symbols with _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
71 symbols in some systems' standard C libraries... */ |
|
4866a0fc2bbd
rename exported symbols with _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
72 |
|
4866a0fc2bbd
rename exported symbols with _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
73 #define re_syntax _Py_re_syntax |
|
4866a0fc2bbd
rename exported symbols with _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
74 #define re_set_syntax _Py_re_set_syntax |
|
4866a0fc2bbd
rename exported symbols with _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
75 #define re_compile_pattern _Py_re_compile_pattern |
|
4866a0fc2bbd
rename exported symbols with _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
76 #define re_match _Py_re_match |
|
4866a0fc2bbd
rename exported symbols with _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
77 #define re_search _Py_re_search |
|
4866a0fc2bbd
rename exported symbols with _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
78 #define re_compile_fastmap _Py_re_compile_fastmap |
|
4866a0fc2bbd
rename exported symbols with _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
79 #define re_comp _Py_re_comp |
|
4866a0fc2bbd
rename exported symbols with _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
80 #define re_exec _Py_re_exec |
|
4866a0fc2bbd
rename exported symbols with _Py_ prefix
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
81 |
|
640
0b38000fc823
Change prototypes decision.
Guido van Rossum <guido@python.org>
parents:
616
diff
changeset
|
82 #ifdef HAVE_PROTOTYPES |
| 616 | 83 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1329
diff
changeset
|
84 extern int re_syntax; |
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
85 /* This is the actual syntax mask. It was added so that Python could do |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
86 * syntax-dependent munging of patterns before compilation. */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1329
diff
changeset
|
87 |
| 616 | 88 int re_set_syntax(int syntax); |
| 89 /* This sets the syntax to use and returns the previous syntax. The | |
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
90 * syntax is specified by a bit mask of the above defined bits. */ |
| 616 | 91 |
| 92 char *re_compile_pattern(char *regex, int regex_size, regexp_t compiled); | |
| 93 /* This compiles the regexp (given in regex and length in regex_size). | |
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
94 * This returns NULL if the regexp compiled successfully, and an error |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
95 * message if an error was encountered. The buffer field must be |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
96 * initialized to a memory area allocated by malloc (or to NULL) before |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
97 * use, and the allocated field must be set to its length (or 0 if |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
98 * buffer is NULL). Also, the translate field must be set to point to a |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
99 * valid translation table, or NULL if it is not used. */ |
| 616 | 100 |
| 101 int re_match(regexp_t compiled, char *string, int size, int pos, | |
|
5465
09e6b4e34523
Latest from Jeffrey Ollie.
Guido van Rossum <guido@python.org>
parents:
3612
diff
changeset
|
102 regexp_registers_t old_regs); |
| 616 | 103 /* This tries to match the regexp against the string. This returns the |
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
104 * length of the matched portion, or -1 if the pattern could not be |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
105 * matched and -2 if an error (such as failure stack overflow) is |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
106 * encountered. */ |
| 616 | 107 |
| 108 int re_search(regexp_t compiled, char *string, int size, int startpos, | |
| 109 int range, regexp_registers_t regs); | |
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
110 /* This rearches for a substring matching the regexp. This returns the |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
111 * first index at which a match is found. range specifies at how many |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
112 * positions to try matching; positive values indicate searching |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
113 * forwards, and negative values indicate searching backwards. mstop |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
114 * specifies the offset beyond which a match must not go. This returns |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
115 * -1 if no match is found, and -2 if an error (such as failure stack |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
116 * overflow) is encountered. */ |
| 616 | 117 |
| 118 void re_compile_fastmap(regexp_t compiled); | |
| 119 /* This computes the fastmap for the regexp. For this to have any effect, | |
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
120 * the calling program must have initialized the fastmap field to point |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
121 * to an array of 256 characters. */ |
| 616 | 122 |
| 123 char *re_comp(char *s); | |
| 124 /* BSD 4.2 regex library routine re_comp. This compiles the regexp into | |
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
125 * an internal buffer. This returns NULL if the regexp was compiled |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
126 * successfully, and an error message if there was an error. */ |
| 616 | 127 |
| 128 int re_exec(char *s); | |
|
5755
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
129 /* BSD 4.2 regexp library routine re_exec. This returns true if the |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
130 * string matches the regular expression (that is, a matching part is |
|
18a639db048c
New versions straight from Jeffrey Ollie's web site
Guido van Rossum <guido@python.org>
parents:
5465
diff
changeset
|
131 * found anywhere in the string). */ |
| 616 | 132 |
|
640
0b38000fc823
Change prototypes decision.
Guido van Rossum <guido@python.org>
parents:
616
diff
changeset
|
133 #else /* HAVE_PROTOTYPES */ |
| 616 | 134 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1329
diff
changeset
|
135 extern int re_syntax; |
| 616 | 136 int re_set_syntax(); |
| 137 char *re_compile_pattern(); | |
| 138 int re_match(); | |
| 139 int re_search(); | |
| 140 void re_compile_fastmap(); | |
| 141 char *re_comp(); | |
| 142 int re_exec(); | |
| 143 | |
|
640
0b38000fc823
Change prototypes decision.
Guido van Rossum <guido@python.org>
parents:
616
diff
changeset
|
144 #endif /* HAVE_PROTOTYPES */ |
| 616 | 145 |
| 146 #endif /* REGEXPR_H */ | |
| 147 | |
| 148 | |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1273
diff
changeset
|
149 |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1273
diff
changeset
|
150 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1273
diff
changeset
|
151 } |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1273
diff
changeset
|
152 #endif |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1273
diff
changeset
|
153 #endif /* !Py_REGEXPR_H */ |
