regex.h revision 1.17 1 /* $NetBSD: regex.h,v 1.17 2024/10/30 15:56:10 riastradh Exp $ */
2
3 /*-
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Henry Spencer of the University of Toronto.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)regex.h 8.2 (Berkeley) 1/3/94
35 */
36
37 /*-
38 * Copyright (c) 1992 Henry Spencer.
39 *
40 * This code is derived from software contributed to Berkeley by
41 * Henry Spencer of the University of Toronto.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed by the University of
54 * California, Berkeley and its contributors.
55 * 4. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
58 *
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
70 *
71 * @(#)regex.h 8.2 (Berkeley) 1/3/94
72 */
73
74 #ifndef _REGEX_H_
75 #define _REGEX_H_
76
77 #include <sys/cdefs.h>
78 #include <sys/featuretest.h>
79 #include <sys/types.h>
80
81 /* types */
82 typedef off_t regoff_t;
83
84 typedef struct {
85 int re_magic;
86 size_t re_nsub; /* number of parenthesized subexpressions */
87 const char *re_endp; /* end pointer for REG_PEND */
88 struct re_guts *re_g; /* none of your business :-) */
89 } regex_t;
90
91 typedef struct {
92 regoff_t rm_so; /* start of match */
93 regoff_t rm_eo; /* end of match */
94 } regmatch_t;
95
96 /* regcomp() flags */
97 #define REG_BASIC 0000
98 #define REG_EXTENDED 0001
99 #define REG_ICASE 0002
100 #define REG_NOSUB 0004
101 #define REG_NEWLINE 0010
102 #define REG_NOSPEC 0020
103 #define REG_PEND 0040
104 #define REG_DUMP 0200
105 #define REG_GNU 0400
106
107 /* regerror() flags */
108 #define REG_NOMATCH 1
109 #define REG_BADPAT 2
110 #define REG_ECOLLATE 3
111 #define REG_ECTYPE 4
112 #define REG_EESCAPE 5
113 #define REG_ESUBREG 6
114 #define REG_EBRACK 7
115 #define REG_EPAREN 8
116 #define REG_EBRACE 9
117 #define REG_BADBR 10
118 #define REG_ERANGE 11
119 #define REG_ESPACE 12
120 #define REG_BADRPT 13
121 #define REG_EMPTY 14
122 #define REG_ASSERT 15
123 #define REG_INVARG 16
124 #define REG_ILLSEQ 17
125 #define REG_ATOI 255 /* convert name to number (!) */
126 #define REG_ITOA 0400 /* convert number to name (!) */
127
128 /* regexec() flags */
129 #define REG_NOTBOL 00001
130 #define REG_NOTEOL 00002
131 #define REG_STARTEND 00004
132 #define REG_TRACE 00400 /* tracing of execution */
133 #define REG_LARGE 01000 /* force large representation */
134 #define REG_BACKR 02000 /* force use of backref code */
135
136 __BEGIN_DECLS
137 int regcomp(regex_t * __restrict, const char * __restrict, int);
138 size_t regerror(int, const regex_t * __restrict, char * __restrict, size_t);
139 int regexec(const regex_t * __restrict,
140 const char * __restrict, size_t, regmatch_t [], int);
141 void regfree(regex_t *);
142 #ifdef _NETBSD_SOURCE
143 ssize_t regnsub(char *, size_t, const char *, const regmatch_t *, const char *);
144 ssize_t regasub(char **buf, const char *, const regmatch_t *, const char *);
145 #endif
146 __END_DECLS
147
148 #endif /* !_REGEX_H_ */
149