Blame


1 b2cfc4e2 2003-09-30 devnull .TH REGEXP9 3
2 b2cfc4e2 2003-09-30 devnull .de EX
3 b2cfc4e2 2003-09-30 devnull .nf
4 b2cfc4e2 2003-09-30 devnull .ft B
5 b2cfc4e2 2003-09-30 devnull ..
6 b2cfc4e2 2003-09-30 devnull .de EE
7 b2cfc4e2 2003-09-30 devnull .fi
8 b2cfc4e2 2003-09-30 devnull .ft R
9 b2cfc4e2 2003-09-30 devnull ..
10 b2cfc4e2 2003-09-30 devnull .de LR
11 b2cfc4e2 2003-09-30 devnull .if t .BR \\$1 \\$2
12 b2cfc4e2 2003-09-30 devnull .if n .RB ` \\$1 '\\$2
13 b2cfc4e2 2003-09-30 devnull ..
14 b2cfc4e2 2003-09-30 devnull .de L
15 b2cfc4e2 2003-09-30 devnull .nh
16 b2cfc4e2 2003-09-30 devnull .if t .B \\$1
17 b2cfc4e2 2003-09-30 devnull .if n .RB ` \\$1 '
18 b2cfc4e2 2003-09-30 devnull ..
19 b2cfc4e2 2003-09-30 devnull .SH NAME
20 b2cfc4e2 2003-09-30 devnull regcomp, regcomplit, regcompnl, regexec, regsub, regerror \- Plan 9 regular expression library
21 b2cfc4e2 2003-09-30 devnull .SH SYNOPSIS
22 b2cfc4e2 2003-09-30 devnull .B #include <regexp9.h>
23 b2cfc4e2 2003-09-30 devnull .PP
24 b2cfc4e2 2003-09-30 devnull .ta \w'\fLRegprog 'u
25 b2cfc4e2 2003-09-30 devnull .B
26 b2cfc4e2 2003-09-30 devnull Reprog *regcomp(char *exp)
27 b2cfc4e2 2003-09-30 devnull .PP
28 b2cfc4e2 2003-09-30 devnull .B
29 b2cfc4e2 2003-09-30 devnull Reprog *regcomplit(char *exp)
30 b2cfc4e2 2003-09-30 devnull .PP
31 b2cfc4e2 2003-09-30 devnull .B
32 b2cfc4e2 2003-09-30 devnull Reprog *regcompnl(char *exp)
33 b2cfc4e2 2003-09-30 devnull .PP
34 b2cfc4e2 2003-09-30 devnull .nf
35 b2cfc4e2 2003-09-30 devnull .B
36 b2cfc4e2 2003-09-30 devnull int regexec(Reprog *prog, char *string, Resub *match, int msize)
37 b2cfc4e2 2003-09-30 devnull .PP
38 b2cfc4e2 2003-09-30 devnull .nf
39 b2cfc4e2 2003-09-30 devnull .B
40 b2cfc4e2 2003-09-30 devnull void regsub(char *source, char *dest, int dlen, Resub *match, int msize)
41 b2cfc4e2 2003-09-30 devnull .PP
42 b2cfc4e2 2003-09-30 devnull .nf
43 b2cfc4e2 2003-09-30 devnull .B
44 b2cfc4e2 2003-09-30 devnull int rregexec(Reprog *prog, Rune *string, Resub *match, int msize)
45 b2cfc4e2 2003-09-30 devnull .PP
46 b2cfc4e2 2003-09-30 devnull .nf
47 b2cfc4e2 2003-09-30 devnull .B
48 b2cfc4e2 2003-09-30 devnull void rregsub(Rune *source, Rune *dest, int dlen, Resub *match, int msize)
49 b2cfc4e2 2003-09-30 devnull .PP
50 b2cfc4e2 2003-09-30 devnull .B
51 b2cfc4e2 2003-09-30 devnull void regerror(char *msg)
52 b2cfc4e2 2003-09-30 devnull .SH DESCRIPTION
53 b2cfc4e2 2003-09-30 devnull .I Regcomp
54 b2cfc4e2 2003-09-30 devnull compiles a
55 b2cfc4e2 2003-09-30 devnull regular expression and returns
56 b2cfc4e2 2003-09-30 devnull a pointer to the generated description.
57 b2cfc4e2 2003-09-30 devnull The space is allocated by
58 b2cfc4e2 2003-09-30 devnull .IR malloc (3)
59 b2cfc4e2 2003-09-30 devnull and may be released by
60 b2cfc4e2 2003-09-30 devnull .IR free .
61 b2cfc4e2 2003-09-30 devnull Regular expressions are exactly as in
62 b2cfc4e2 2003-09-30 devnull .IR regexp9 (7).
63 b2cfc4e2 2003-09-30 devnull .PP
64 b2cfc4e2 2003-09-30 devnull .I Regcomplit
65 b2cfc4e2 2003-09-30 devnull is like
66 b2cfc4e2 2003-09-30 devnull .I regcomp
67 b2cfc4e2 2003-09-30 devnull except that all characters are treated literally.
68 b2cfc4e2 2003-09-30 devnull .I Regcompnl
69 b2cfc4e2 2003-09-30 devnull is like
70 b2cfc4e2 2003-09-30 devnull .I regcomp
71 b2cfc4e2 2003-09-30 devnull except that the
72 b2cfc4e2 2003-09-30 devnull .B .
73 b2cfc4e2 2003-09-30 devnull metacharacter matches all characters, including newlines.
74 b2cfc4e2 2003-09-30 devnull .PP
75 b2cfc4e2 2003-09-30 devnull .I Regexec
76 b2cfc4e2 2003-09-30 devnull matches a null-terminated
77 b2cfc4e2 2003-09-30 devnull .I string
78 b2cfc4e2 2003-09-30 devnull against the compiled regular expression in
79 b2cfc4e2 2003-09-30 devnull .IR prog .
80 b2cfc4e2 2003-09-30 devnull If it matches,
81 b2cfc4e2 2003-09-30 devnull .I regexec
82 b2cfc4e2 2003-09-30 devnull returns
83 b2cfc4e2 2003-09-30 devnull .B 1
84 b2cfc4e2 2003-09-30 devnull and fills in the array
85 b2cfc4e2 2003-09-30 devnull .I match
86 b2cfc4e2 2003-09-30 devnull with character pointers to the substrings of
87 b2cfc4e2 2003-09-30 devnull .I string
88 b2cfc4e2 2003-09-30 devnull that correspond to the
89 b2cfc4e2 2003-09-30 devnull parenthesized subexpressions of
90 b2cfc4e2 2003-09-30 devnull .IR exp :
91 b2cfc4e2 2003-09-30 devnull .BI match[ i ].sp
92 b2cfc4e2 2003-09-30 devnull points to the beginning and
93 b2cfc4e2 2003-09-30 devnull .BI match[ i ].ep
94 b2cfc4e2 2003-09-30 devnull points just beyond
95 b2cfc4e2 2003-09-30 devnull the end of the
96 b2cfc4e2 2003-09-30 devnull .IR i th
97 b2cfc4e2 2003-09-30 devnull substring.
98 b2cfc4e2 2003-09-30 devnull (Subexpression
99 b2cfc4e2 2003-09-30 devnull .I i
100 b2cfc4e2 2003-09-30 devnull begins at the
101 b2cfc4e2 2003-09-30 devnull .IR i th
102 b2cfc4e2 2003-09-30 devnull left parenthesis, counting from 1.)
103 b2cfc4e2 2003-09-30 devnull Pointers in
104 b2cfc4e2 2003-09-30 devnull .B match[0]
105 b2cfc4e2 2003-09-30 devnull pick out the substring that corresponds to
106 b2cfc4e2 2003-09-30 devnull the whole regular expression.
107 b2cfc4e2 2003-09-30 devnull Unused elements of
108 b2cfc4e2 2003-09-30 devnull .I match
109 b2cfc4e2 2003-09-30 devnull are filled with zeros.
110 b2cfc4e2 2003-09-30 devnull Matches involving
111 b2cfc4e2 2003-09-30 devnull .LR * ,
112 b2cfc4e2 2003-09-30 devnull .LR + ,
113 b2cfc4e2 2003-09-30 devnull and
114 b2cfc4e2 2003-09-30 devnull .L ?
115 b2cfc4e2 2003-09-30 devnull are extended as far as possible.
116 b2cfc4e2 2003-09-30 devnull The number of array elements in
117 b2cfc4e2 2003-09-30 devnull .I match
118 b2cfc4e2 2003-09-30 devnull is given by
119 b2cfc4e2 2003-09-30 devnull .IR msize .
120 b2cfc4e2 2003-09-30 devnull The structure of elements of
121 b2cfc4e2 2003-09-30 devnull .I match
122 b2cfc4e2 2003-09-30 devnull is:
123 b2cfc4e2 2003-09-30 devnull .IP
124 b2cfc4e2 2003-09-30 devnull .EX
125 b2cfc4e2 2003-09-30 devnull typedef struct {
126 b2cfc4e2 2003-09-30 devnull union {
127 b2cfc4e2 2003-09-30 devnull char *sp;
128 b2cfc4e2 2003-09-30 devnull Rune *rsp;
129 b2cfc4e2 2003-09-30 devnull } s;
130 b2cfc4e2 2003-09-30 devnull union {
131 b2cfc4e2 2003-09-30 devnull char *ep;
132 b2cfc4e2 2003-09-30 devnull Rune *rep;
133 b2cfc4e2 2003-09-30 devnull } e;
134 b2cfc4e2 2003-09-30 devnull } Resub;
135 b2cfc4e2 2003-09-30 devnull .EE
136 b2cfc4e2 2003-09-30 devnull .LP
137 b2cfc4e2 2003-09-30 devnull If
138 b2cfc4e2 2003-09-30 devnull .B match[0].s.sp
139 b2cfc4e2 2003-09-30 devnull is nonzero on entry,
140 b2cfc4e2 2003-09-30 devnull .I regexec
141 b2cfc4e2 2003-09-30 devnull starts matching at that point within
142 b2cfc4e2 2003-09-30 devnull .IR string .
143 b2cfc4e2 2003-09-30 devnull If
144 b2cfc4e2 2003-09-30 devnull .B match[0].e.ep
145 b2cfc4e2 2003-09-30 devnull is nonzero on entry,
146 b2cfc4e2 2003-09-30 devnull the last character matched is the one
147 b2cfc4e2 2003-09-30 devnull preceding that point.
148 b2cfc4e2 2003-09-30 devnull .PP
149 b2cfc4e2 2003-09-30 devnull .I Regsub
150 b2cfc4e2 2003-09-30 devnull places in
151 b2cfc4e2 2003-09-30 devnull .I dest
152 b2cfc4e2 2003-09-30 devnull a substitution instance of
153 b2cfc4e2 2003-09-30 devnull .I source
154 b2cfc4e2 2003-09-30 devnull in the context of the last
155 b2cfc4e2 2003-09-30 devnull .I regexec
156 b2cfc4e2 2003-09-30 devnull performed using
157 b2cfc4e2 2003-09-30 devnull .IR match .
158 b2cfc4e2 2003-09-30 devnull Each instance of
159 b2cfc4e2 2003-09-30 devnull .BI \e n\f1,
160 b2cfc4e2 2003-09-30 devnull where
161 b2cfc4e2 2003-09-30 devnull .I n
162 b2cfc4e2 2003-09-30 devnull is a digit, is replaced by the
163 b2cfc4e2 2003-09-30 devnull string delimited by
164 b2cfc4e2 2003-09-30 devnull .BI match[ n ].s.sp
165 b2cfc4e2 2003-09-30 devnull and
166 b2cfc4e2 2003-09-30 devnull .BI match[ n ].e.ep\f1.
167 b2cfc4e2 2003-09-30 devnull Each instance of
168 b2cfc4e2 2003-09-30 devnull .L &
169 b2cfc4e2 2003-09-30 devnull is replaced by the string delimited by
170 b2cfc4e2 2003-09-30 devnull .B match[0].s.sp
171 b2cfc4e2 2003-09-30 devnull and
172 b2cfc4e2 2003-09-30 devnull .BR match[0].e.ep .
173 b2cfc4e2 2003-09-30 devnull The substitution will always be null terminated and
174 b2cfc4e2 2003-09-30 devnull trimmed to fit into dlen bytes.
175 b2cfc4e2 2003-09-30 devnull .PP
176 b2cfc4e2 2003-09-30 devnull .IR Regerror ,
177 b2cfc4e2 2003-09-30 devnull called whenever an error is detected in
178 b2cfc4e2 2003-09-30 devnull .IR regcomp ,
179 b2cfc4e2 2003-09-30 devnull writes the string
180 b2cfc4e2 2003-09-30 devnull .I msg
181 b2cfc4e2 2003-09-30 devnull on the standard error file and exits.
182 b2cfc4e2 2003-09-30 devnull .I Regerror
183 b2cfc4e2 2003-09-30 devnull can be replaced to perform
184 b2cfc4e2 2003-09-30 devnull special error processing.
185 b2cfc4e2 2003-09-30 devnull If the user supplied
186 b2cfc4e2 2003-09-30 devnull .I regerror
187 b2cfc4e2 2003-09-30 devnull returns rather than exits,
188 b2cfc4e2 2003-09-30 devnull .I regcomp
189 b2cfc4e2 2003-09-30 devnull will return 0.
190 b2cfc4e2 2003-09-30 devnull .PP
191 b2cfc4e2 2003-09-30 devnull .I Rregexec
192 b2cfc4e2 2003-09-30 devnull and
193 b2cfc4e2 2003-09-30 devnull .I rregsub
194 b2cfc4e2 2003-09-30 devnull are variants of
195 b2cfc4e2 2003-09-30 devnull .I regexec
196 b2cfc4e2 2003-09-30 devnull and
197 b2cfc4e2 2003-09-30 devnull .I regsub
198 b2cfc4e2 2003-09-30 devnull that use strings of
199 b2cfc4e2 2003-09-30 devnull .B Runes
200 b2cfc4e2 2003-09-30 devnull instead of strings of
201 b2cfc4e2 2003-09-30 devnull .BR chars .
202 b2cfc4e2 2003-09-30 devnull With these routines, the
203 b2cfc4e2 2003-09-30 devnull .I rsp
204 b2cfc4e2 2003-09-30 devnull and
205 b2cfc4e2 2003-09-30 devnull .I rep
206 b2cfc4e2 2003-09-30 devnull fields of the
207 b2cfc4e2 2003-09-30 devnull .I match
208 b2cfc4e2 2003-09-30 devnull array elements should be used.
209 b2cfc4e2 2003-09-30 devnull .SH "SEE ALSO"
210 b2cfc4e2 2003-09-30 devnull .IR grep (1),
211 b2cfc4e2 2003-09-30 devnull .IR regexp9 (7)
212 b2cfc4e2 2003-09-30 devnull .SH DIAGNOSTICS
213 b2cfc4e2 2003-09-30 devnull .I Regcomp
214 b2cfc4e2 2003-09-30 devnull returns
215 b2cfc4e2 2003-09-30 devnull .B 0
216 b2cfc4e2 2003-09-30 devnull for an illegal expression
217 b2cfc4e2 2003-09-30 devnull or other failure.
218 b2cfc4e2 2003-09-30 devnull .I Regexec
219 b2cfc4e2 2003-09-30 devnull returns 0
220 b2cfc4e2 2003-09-30 devnull if
221 b2cfc4e2 2003-09-30 devnull .I string
222 b2cfc4e2 2003-09-30 devnull is not matched.
223 b2cfc4e2 2003-09-30 devnull .SH HISTORY
224 b2cfc4e2 2003-09-30 devnull This particular regular expression was first written by Rob Pike for Plan 9.
225 b2cfc4e2 2003-09-30 devnull It has also appeared as part of the Inferno operating system.
226 b2cfc4e2 2003-09-30 devnull .SH BUGS
227 b2cfc4e2 2003-09-30 devnull There is no way to specify or match a NUL character; NULs terminate patterns and strings.