xref: /titanic_50/usr/src/head/regex.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate  * Copyright 1989, 1994 by Mortice Kern Systems Inc.
29*7c478bd9Sstevel@tonic-gate  * All rights reserved.
30*7c478bd9Sstevel@tonic-gate  */
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #ifndef	_REGEX_H
33*7c478bd9Sstevel@tonic-gate #define	_REGEX_H
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
41*7c478bd9Sstevel@tonic-gate extern "C" {
42*7c478bd9Sstevel@tonic-gate #endif
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  * wchar_t is a built-in type in standard C++ and as such is not
47*7c478bd9Sstevel@tonic-gate  * defined here when using standard C++. However, the GNU compiler
48*7c478bd9Sstevel@tonic-gate  * fixincludes utility nonetheless creates it's own version of this
49*7c478bd9Sstevel@tonic-gate  * header for use by gcc and g++. In that version it adds a redundant
50*7c478bd9Sstevel@tonic-gate  * guard for __cplusplus. To avoid the creation of a gcc/g++ specific
51*7c478bd9Sstevel@tonic-gate  * header we need to include the following magic comment:
52*7c478bd9Sstevel@tonic-gate  *
53*7c478bd9Sstevel@tonic-gate  * we must use the C++ compiler's type
54*7c478bd9Sstevel@tonic-gate  *
55*7c478bd9Sstevel@tonic-gate  * The above comment should not be removed or changed until GNU
56*7c478bd9Sstevel@tonic-gate  * gcc/fixinc/inclhack.def is updated to bypass this header.
57*7c478bd9Sstevel@tonic-gate  */
58*7c478bd9Sstevel@tonic-gate #if !defined(__cplusplus) || (__cplusplus < 199711L && !defined(__GNUG__))
59*7c478bd9Sstevel@tonic-gate #ifndef _WCHAR_T
60*7c478bd9Sstevel@tonic-gate #define	_WCHAR_T
61*7c478bd9Sstevel@tonic-gate #if defined(_LP64)
62*7c478bd9Sstevel@tonic-gate typedef int	wchar_t;
63*7c478bd9Sstevel@tonic-gate #else
64*7c478bd9Sstevel@tonic-gate typedef long    wchar_t;
65*7c478bd9Sstevel@tonic-gate #endif
66*7c478bd9Sstevel@tonic-gate #endif	/* !_WCHAR_T */
67*7c478bd9Sstevel@tonic-gate #endif	/* !defined(__cplusplus) ... */
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate typedef ssize_t regoff_t;
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate /* regcomp flags */
72*7c478bd9Sstevel@tonic-gate #define	REG_EXTENDED	0x01		/* Use Extended Regular Expressions */
73*7c478bd9Sstevel@tonic-gate #define	REG_NEWLINE	0x08		/* Treat \n as regular character */
74*7c478bd9Sstevel@tonic-gate #define	REG_ICASE	0x04		/* Ignore case in match */
75*7c478bd9Sstevel@tonic-gate #define	REG_NOSUB	0x02		/* Don't set subexpression */
76*7c478bd9Sstevel@tonic-gate #define	REG_EGREP	0x1000		/* running as egrep(1) */
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate /* non-standard flags */
79*7c478bd9Sstevel@tonic-gate #define	REG_DELIM	0x10		/* string[0] is delimiter */
80*7c478bd9Sstevel@tonic-gate #define	REG_DEBUG	0x20		/* Debug recomp and regexec */
81*7c478bd9Sstevel@tonic-gate #define	REG_ANCHOR	0x40		/* Implicit ^ and $ */
82*7c478bd9Sstevel@tonic-gate #define	REG_WORDS	0x80		/* \< and \> match word boundries */
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate /* internal flags */
85*7c478bd9Sstevel@tonic-gate #define	REG_MUST	0x100		/* check for regmust substring */
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate /* regexec flags */
88*7c478bd9Sstevel@tonic-gate #define	REG_NOTBOL	0x200		/* string is not BOL */
89*7c478bd9Sstevel@tonic-gate #define	REG_NOTEOL	0x400		/* string has no EOL */
90*7c478bd9Sstevel@tonic-gate #define	REG_NOOPT	0x800		/* don't do regmust optimization */
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate /* regcomp and regexec return codes */
93*7c478bd9Sstevel@tonic-gate #define	REG_OK		0		/* success (non-standard) */
94*7c478bd9Sstevel@tonic-gate #define	REG_NOMATCH	1		/* regexec failed to match */
95*7c478bd9Sstevel@tonic-gate #define	REG_ECOLLATE	2		/* invalid collation element ref. */
96*7c478bd9Sstevel@tonic-gate #define	REG_EESCAPE	3		/* trailing \ in pattern */
97*7c478bd9Sstevel@tonic-gate #define	REG_ENEWLINE	4		/* \n found before end of pattern */
98*7c478bd9Sstevel@tonic-gate #define	REG_ENSUB	5		/* more than 9 \( \) pairs (OBS) */
99*7c478bd9Sstevel@tonic-gate #define	REG_ESUBREG	6		/* number in \[0-9] invalid */
100*7c478bd9Sstevel@tonic-gate #define	REG_EBRACK	7		/* [ ] imbalance */
101*7c478bd9Sstevel@tonic-gate #define	REG_EPAREN	8		/* ( ) imbalance */
102*7c478bd9Sstevel@tonic-gate #define	REG_EBRACE	9		/* \{ \} imbalance */
103*7c478bd9Sstevel@tonic-gate #define	REG_ERANGE	10		/* invalid endpoint in range */
104*7c478bd9Sstevel@tonic-gate #define	REG_ESPACE	11		/* no memory for compiled pattern */
105*7c478bd9Sstevel@tonic-gate #define	REG_BADRPT	12		/* invalid repetition */
106*7c478bd9Sstevel@tonic-gate #define	REG_ECTYPE	13		/* invalid char-class type */
107*7c478bd9Sstevel@tonic-gate #define	REG_BADPAT	14		/* syntax error */
108*7c478bd9Sstevel@tonic-gate #define	REG_BADBR	15		/* \{ \} contents bad */
109*7c478bd9Sstevel@tonic-gate #define	REG_EFATAL	16		/* internal error, not POSIX.2 */
110*7c478bd9Sstevel@tonic-gate #define	REG_ECHAR	17		/* invalid mulitbyte character */
111*7c478bd9Sstevel@tonic-gate #define	REG_STACK	18		/* backtrack stack overflow */
112*7c478bd9Sstevel@tonic-gate #define	REG_ENOSYS	19		/* function not supported (XPG4) */
113*7c478bd9Sstevel@tonic-gate #define	REG__LAST	20		/* first unused code */
114*7c478bd9Sstevel@tonic-gate #define	REG_EBOL	21		/* ^ anchor and not BOL */
115*7c478bd9Sstevel@tonic-gate #define	REG_EEOL	22		/* $ anchor and not EOL */
116*7c478bd9Sstevel@tonic-gate #define	_REG_BACKREF_MAX 9		/* Max # of subexp. backreference */
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate typedef struct {		/* regcomp() data saved for regexec() */
119*7c478bd9Sstevel@tonic-gate 	size_t  re_nsub;	/* # of subexpressions in RE pattern */
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 	/*
122*7c478bd9Sstevel@tonic-gate 	 * Internal use only
123*7c478bd9Sstevel@tonic-gate 	 */
124*7c478bd9Sstevel@tonic-gate 	void	*re_comp;	/* compiled RE; freed by regfree() */
125*7c478bd9Sstevel@tonic-gate 	int	re_cflags;	/* saved cflags for regexec() */
126*7c478bd9Sstevel@tonic-gate 	size_t	re_erroff;	/* RE pattern error offset */
127*7c478bd9Sstevel@tonic-gate 	size_t	re_len;		/* # wchar_t chars in compiled pattern */
128*7c478bd9Sstevel@tonic-gate 	struct _regex_ext_t *re_sc;	/* for binary compatibility */
129*7c478bd9Sstevel@tonic-gate } regex_t;
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate /* subexpression positions */
132*7c478bd9Sstevel@tonic-gate typedef struct {
133*7c478bd9Sstevel@tonic-gate #ifdef __STDC__
134*7c478bd9Sstevel@tonic-gate 	const char	*rm_sp, *rm_ep;	/* Start pointer, end pointer */
135*7c478bd9Sstevel@tonic-gate #else
136*7c478bd9Sstevel@tonic-gate 	char		*rm_sp, *rm_ep;	/* Start pointer, end pointer */
137*7c478bd9Sstevel@tonic-gate #endif
138*7c478bd9Sstevel@tonic-gate 	regoff_t	rm_so, rm_eo;	/* Start offset, end offset */
139*7c478bd9Sstevel@tonic-gate 	int		rm_ss, rm_es;	/* Used internally */
140*7c478bd9Sstevel@tonic-gate } regmatch_t;
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate /*
144*7c478bd9Sstevel@tonic-gate  * Additional API and structs to support regular expression manipulations
145*7c478bd9Sstevel@tonic-gate  * on wide characters.
146*7c478bd9Sstevel@tonic-gate  */
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate #if defined(__STDC__)
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate extern int regcomp(regex_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, int);
151*7c478bd9Sstevel@tonic-gate extern int regexec(const regex_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
152*7c478bd9Sstevel@tonic-gate 	size_t, regmatch_t *_RESTRICT_KYWD, int);
153*7c478bd9Sstevel@tonic-gate extern size_t regerror(int, const regex_t *_RESTRICT_KYWD,
154*7c478bd9Sstevel@tonic-gate 	char *_RESTRICT_KYWD, size_t);
155*7c478bd9Sstevel@tonic-gate extern void regfree(regex_t *);
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate #else  /* defined(__STDC__) */
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate extern int regcomp();
160*7c478bd9Sstevel@tonic-gate extern int regexec();
161*7c478bd9Sstevel@tonic-gate extern size_t regerror();
162*7c478bd9Sstevel@tonic-gate extern void regfree();
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate #endif  /* defined(__STDC__) */
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
167*7c478bd9Sstevel@tonic-gate }
168*7c478bd9Sstevel@tonic-gate #endif
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate #endif	/* _REGEX_H */
171