xref: /titanic_41/usr/src/head/regex.h (revision b59b3655028aeb11832ad679eb5c2577c2b75235)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*b59b3655SGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24*b59b3655SGarrett D'Amore  *
257c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
267c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Copyright 1989, 1994 by Mortice Kern Systems Inc.
317c478bd9Sstevel@tonic-gate  * All rights reserved.
327c478bd9Sstevel@tonic-gate  */
334297a3b0SGarrett D'Amore /*
344297a3b0SGarrett D'Amore  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
354297a3b0SGarrett D'Amore  * Use is subject to license terms.
364297a3b0SGarrett D'Amore  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifndef	_REGEX_H
397c478bd9Sstevel@tonic-gate #define	_REGEX_H
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
427c478bd9Sstevel@tonic-gate #include <sys/types.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
457c478bd9Sstevel@tonic-gate extern "C" {
467c478bd9Sstevel@tonic-gate #endif
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * wchar_t is a built-in type in standard C++ and as such is not
517c478bd9Sstevel@tonic-gate  * defined here when using standard C++. However, the GNU compiler
52159cf8a6Swesolows  * fixincludes utility nonetheless creates its own version of this
537c478bd9Sstevel@tonic-gate  * header for use by gcc and g++. In that version it adds a redundant
547c478bd9Sstevel@tonic-gate  * guard for __cplusplus. To avoid the creation of a gcc/g++ specific
557c478bd9Sstevel@tonic-gate  * header we need to include the following magic comment:
567c478bd9Sstevel@tonic-gate  *
577c478bd9Sstevel@tonic-gate  * we must use the C++ compiler's type
587c478bd9Sstevel@tonic-gate  *
597c478bd9Sstevel@tonic-gate  * The above comment should not be removed or changed until GNU
607c478bd9Sstevel@tonic-gate  * gcc/fixinc/inclhack.def is updated to bypass this header.
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate #if !defined(__cplusplus) || (__cplusplus < 199711L && !defined(__GNUG__))
637c478bd9Sstevel@tonic-gate #ifndef _WCHAR_T
647c478bd9Sstevel@tonic-gate #define	_WCHAR_T
657c478bd9Sstevel@tonic-gate #if defined(_LP64)
667c478bd9Sstevel@tonic-gate typedef int	wchar_t;
677c478bd9Sstevel@tonic-gate #else
687c478bd9Sstevel@tonic-gate typedef long    wchar_t;
697c478bd9Sstevel@tonic-gate #endif
707c478bd9Sstevel@tonic-gate #endif	/* !_WCHAR_T */
717c478bd9Sstevel@tonic-gate #endif	/* !defined(__cplusplus) ... */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate typedef ssize_t regoff_t;
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /* regcomp flags */
764297a3b0SGarrett D'Amore #define	REG_BASIC	0x00
777c478bd9Sstevel@tonic-gate #define	REG_EXTENDED	0x01		/* Use Extended Regular Expressions */
787c478bd9Sstevel@tonic-gate #define	REG_NEWLINE	0x08		/* Treat \n as regular character */
797c478bd9Sstevel@tonic-gate #define	REG_ICASE	0x04		/* Ignore case in match */
807c478bd9Sstevel@tonic-gate #define	REG_NOSUB	0x02		/* Don't set subexpression */
817c478bd9Sstevel@tonic-gate #define	REG_EGREP	0x1000		/* running as egrep(1) */
827c478bd9Sstevel@tonic-gate 
834297a3b0SGarrett D'Amore /* non-standard flags - note that most of these are not supported */
847c478bd9Sstevel@tonic-gate #define	REG_DELIM	0x10		/* string[0] is delimiter */
857c478bd9Sstevel@tonic-gate #define	REG_DEBUG	0x20		/* Debug recomp and regexec */
867c478bd9Sstevel@tonic-gate #define	REG_ANCHOR	0x40		/* Implicit ^ and $ */
877c478bd9Sstevel@tonic-gate #define	REG_WORDS	0x80		/* \< and \> match word boundries */
887c478bd9Sstevel@tonic-gate 
894297a3b0SGarrett D'Amore /* FreeBSD additions */
904297a3b0SGarrett D'Amore #define	REG_DUMP	0x2000
914297a3b0SGarrett D'Amore #define	REG_PEND	0x4000
924297a3b0SGarrett D'Amore #define	REG_NOSPEC	0x8000
9384441f85SGarrett D'Amore #define	REG_STARTEND	0x10000
944297a3b0SGarrett D'Amore 
957c478bd9Sstevel@tonic-gate /* internal flags */
967c478bd9Sstevel@tonic-gate #define	REG_MUST	0x100		/* check for regmust substring */
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /* regexec flags */
997c478bd9Sstevel@tonic-gate #define	REG_NOTBOL	0x200		/* string is not BOL */
1007c478bd9Sstevel@tonic-gate #define	REG_NOTEOL	0x400		/* string has no EOL */
1017c478bd9Sstevel@tonic-gate #define	REG_NOOPT	0x800		/* don't do regmust optimization */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate /* regcomp and regexec return codes */
1047c478bd9Sstevel@tonic-gate #define	REG_OK		0		/* success (non-standard) */
1057c478bd9Sstevel@tonic-gate #define	REG_NOMATCH	1		/* regexec failed to match */
1067c478bd9Sstevel@tonic-gate #define	REG_ECOLLATE	2		/* invalid collation element ref. */
1077c478bd9Sstevel@tonic-gate #define	REG_EESCAPE	3		/* trailing \ in pattern */
1087c478bd9Sstevel@tonic-gate #define	REG_ENEWLINE	4		/* \n found before end of pattern */
1097c478bd9Sstevel@tonic-gate #define	REG_ENSUB	5		/* more than 9 \( \) pairs (OBS) */
1107c478bd9Sstevel@tonic-gate #define	REG_ESUBREG	6		/* number in \[0-9] invalid */
1117c478bd9Sstevel@tonic-gate #define	REG_EBRACK	7		/* [ ] imbalance */
1127c478bd9Sstevel@tonic-gate #define	REG_EPAREN	8		/* ( ) imbalance */
1137c478bd9Sstevel@tonic-gate #define	REG_EBRACE	9		/* \{ \} imbalance */
1147c478bd9Sstevel@tonic-gate #define	REG_ERANGE	10		/* invalid endpoint in range */
1157c478bd9Sstevel@tonic-gate #define	REG_ESPACE	11		/* no memory for compiled pattern */
1167c478bd9Sstevel@tonic-gate #define	REG_BADRPT	12		/* invalid repetition */
1177c478bd9Sstevel@tonic-gate #define	REG_ECTYPE	13		/* invalid char-class type */
1187c478bd9Sstevel@tonic-gate #define	REG_BADPAT	14		/* syntax error */
1197c478bd9Sstevel@tonic-gate #define	REG_BADBR	15		/* \{ \} contents bad */
1207c478bd9Sstevel@tonic-gate #define	REG_EFATAL	16		/* internal error, not POSIX.2 */
1217c478bd9Sstevel@tonic-gate #define	REG_ECHAR	17		/* invalid mulitbyte character */
1227c478bd9Sstevel@tonic-gate #define	REG_STACK	18		/* backtrack stack overflow */
1237c478bd9Sstevel@tonic-gate #define	REG_ENOSYS	19		/* function not supported (XPG4) */
1247c478bd9Sstevel@tonic-gate #define	REG__LAST	20		/* first unused code */
1257c478bd9Sstevel@tonic-gate #define	REG_EBOL	21		/* ^ anchor and not BOL */
1267c478bd9Sstevel@tonic-gate #define	REG_EEOL	22		/* $ anchor and not EOL */
1277c478bd9Sstevel@tonic-gate #define	_REG_BACKREF_MAX 9		/* Max # of subexp. backreference */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate typedef struct {		/* regcomp() data saved for regexec() */
1307c478bd9Sstevel@tonic-gate 	size_t  re_nsub;	/* # of subexpressions in RE pattern */
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	/*
1334297a3b0SGarrett D'Amore 	 * Internal use only.  Note that any changes to this structure
1344297a3b0SGarrett D'Amore 	 * have to preserve sizing, as it is baked into applications.
1357c478bd9Sstevel@tonic-gate 	 */
1364297a3b0SGarrett D'Amore 	struct re_guts *re_g;
1374297a3b0SGarrett D'Amore 	int re_magic;
1384297a3b0SGarrett D'Amore 	const char *re_endp;
1394297a3b0SGarrett D'Amore 
1404297a3b0SGarrett D'Amore 	/* here for compat */
1417c478bd9Sstevel@tonic-gate 	size_t	re_len;		/* # wchar_t chars in compiled pattern */
1427c478bd9Sstevel@tonic-gate 	struct _regex_ext_t *re_sc;	/* for binary compatibility */
1437c478bd9Sstevel@tonic-gate } regex_t;
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate /* subexpression positions */
1467c478bd9Sstevel@tonic-gate typedef struct {
1477c478bd9Sstevel@tonic-gate 	const char	*rm_sp, *rm_ep;	/* Start pointer, end pointer */
1487c478bd9Sstevel@tonic-gate 	regoff_t	rm_so, rm_eo;	/* Start offset, end offset */
1497c478bd9Sstevel@tonic-gate 	int		rm_ss, rm_es;	/* Used internally */
1507c478bd9Sstevel@tonic-gate } regmatch_t;
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate  * Additional API and structs to support regular expression manipulations
1557c478bd9Sstevel@tonic-gate  * on wide characters.
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate extern int regcomp(regex_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, int);
1597c478bd9Sstevel@tonic-gate extern int regexec(const regex_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
1607c478bd9Sstevel@tonic-gate 	size_t, regmatch_t *_RESTRICT_KYWD, int);
1617c478bd9Sstevel@tonic-gate extern size_t regerror(int, const regex_t *_RESTRICT_KYWD,
1627c478bd9Sstevel@tonic-gate 	char *_RESTRICT_KYWD, size_t);
1637c478bd9Sstevel@tonic-gate extern void regfree(regex_t *);
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate #endif
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate #endif	/* _REGEX_H */
170