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