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 /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* 287c478bd9Sstevel@tonic-gate * Copyright 1989, 1994 by Mortice Kern Systems Inc. 297c478bd9Sstevel@tonic-gate * All rights reserved. 307c478bd9Sstevel@tonic-gate */ 31*4297a3b0SGarrett D'Amore /* 32*4297a3b0SGarrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved. 33*4297a3b0SGarrett D'Amore * Use is subject to license terms. 34*4297a3b0SGarrett D'Amore */ 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifndef _REGEX_H 377c478bd9Sstevel@tonic-gate #define _REGEX_H 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h> 407c478bd9Sstevel@tonic-gate #include <sys/types.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #ifdef __cplusplus 437c478bd9Sstevel@tonic-gate extern "C" { 447c478bd9Sstevel@tonic-gate #endif 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate * wchar_t is a built-in type in standard C++ and as such is not 497c478bd9Sstevel@tonic-gate * defined here when using standard C++. However, the GNU compiler 50159cf8a6Swesolows * fixincludes utility nonetheless creates its own version of this 517c478bd9Sstevel@tonic-gate * header for use by gcc and g++. In that version it adds a redundant 527c478bd9Sstevel@tonic-gate * guard for __cplusplus. To avoid the creation of a gcc/g++ specific 537c478bd9Sstevel@tonic-gate * header we need to include the following magic comment: 547c478bd9Sstevel@tonic-gate * 557c478bd9Sstevel@tonic-gate * we must use the C++ compiler's type 567c478bd9Sstevel@tonic-gate * 577c478bd9Sstevel@tonic-gate * The above comment should not be removed or changed until GNU 587c478bd9Sstevel@tonic-gate * gcc/fixinc/inclhack.def is updated to bypass this header. 597c478bd9Sstevel@tonic-gate */ 607c478bd9Sstevel@tonic-gate #if !defined(__cplusplus) || (__cplusplus < 199711L && !defined(__GNUG__)) 617c478bd9Sstevel@tonic-gate #ifndef _WCHAR_T 627c478bd9Sstevel@tonic-gate #define _WCHAR_T 637c478bd9Sstevel@tonic-gate #if defined(_LP64) 647c478bd9Sstevel@tonic-gate typedef int wchar_t; 657c478bd9Sstevel@tonic-gate #else 667c478bd9Sstevel@tonic-gate typedef long wchar_t; 677c478bd9Sstevel@tonic-gate #endif 687c478bd9Sstevel@tonic-gate #endif /* !_WCHAR_T */ 697c478bd9Sstevel@tonic-gate #endif /* !defined(__cplusplus) ... */ 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate typedef ssize_t regoff_t; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* regcomp flags */ 74*4297a3b0SGarrett D'Amore #define REG_BASIC 0x00 757c478bd9Sstevel@tonic-gate #define REG_EXTENDED 0x01 /* Use Extended Regular Expressions */ 767c478bd9Sstevel@tonic-gate #define REG_NEWLINE 0x08 /* Treat \n as regular character */ 777c478bd9Sstevel@tonic-gate #define REG_ICASE 0x04 /* Ignore case in match */ 787c478bd9Sstevel@tonic-gate #define REG_NOSUB 0x02 /* Don't set subexpression */ 797c478bd9Sstevel@tonic-gate #define REG_EGREP 0x1000 /* running as egrep(1) */ 807c478bd9Sstevel@tonic-gate 81*4297a3b0SGarrett D'Amore /* non-standard flags - note that most of these are not supported */ 827c478bd9Sstevel@tonic-gate #define REG_DELIM 0x10 /* string[0] is delimiter */ 837c478bd9Sstevel@tonic-gate #define REG_DEBUG 0x20 /* Debug recomp and regexec */ 847c478bd9Sstevel@tonic-gate #define REG_ANCHOR 0x40 /* Implicit ^ and $ */ 857c478bd9Sstevel@tonic-gate #define REG_WORDS 0x80 /* \< and \> match word boundries */ 867c478bd9Sstevel@tonic-gate 87*4297a3b0SGarrett D'Amore /* FreeBSD additions */ 88*4297a3b0SGarrett D'Amore #define REG_DUMP 0x2000 89*4297a3b0SGarrett D'Amore #define REG_PEND 0x4000 90*4297a3b0SGarrett D'Amore #define REG_NOSPEC 0x8000 91*4297a3b0SGarrett D'Amore 927c478bd9Sstevel@tonic-gate /* internal flags */ 937c478bd9Sstevel@tonic-gate #define REG_MUST 0x100 /* check for regmust substring */ 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* regexec flags */ 967c478bd9Sstevel@tonic-gate #define REG_NOTBOL 0x200 /* string is not BOL */ 977c478bd9Sstevel@tonic-gate #define REG_NOTEOL 0x400 /* string has no EOL */ 987c478bd9Sstevel@tonic-gate #define REG_NOOPT 0x800 /* don't do regmust optimization */ 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* regcomp and regexec return codes */ 1017c478bd9Sstevel@tonic-gate #define REG_OK 0 /* success (non-standard) */ 1027c478bd9Sstevel@tonic-gate #define REG_NOMATCH 1 /* regexec failed to match */ 1037c478bd9Sstevel@tonic-gate #define REG_ECOLLATE 2 /* invalid collation element ref. */ 1047c478bd9Sstevel@tonic-gate #define REG_EESCAPE 3 /* trailing \ in pattern */ 1057c478bd9Sstevel@tonic-gate #define REG_ENEWLINE 4 /* \n found before end of pattern */ 1067c478bd9Sstevel@tonic-gate #define REG_ENSUB 5 /* more than 9 \( \) pairs (OBS) */ 1077c478bd9Sstevel@tonic-gate #define REG_ESUBREG 6 /* number in \[0-9] invalid */ 1087c478bd9Sstevel@tonic-gate #define REG_EBRACK 7 /* [ ] imbalance */ 1097c478bd9Sstevel@tonic-gate #define REG_EPAREN 8 /* ( ) imbalance */ 1107c478bd9Sstevel@tonic-gate #define REG_EBRACE 9 /* \{ \} imbalance */ 1117c478bd9Sstevel@tonic-gate #define REG_ERANGE 10 /* invalid endpoint in range */ 1127c478bd9Sstevel@tonic-gate #define REG_ESPACE 11 /* no memory for compiled pattern */ 1137c478bd9Sstevel@tonic-gate #define REG_BADRPT 12 /* invalid repetition */ 1147c478bd9Sstevel@tonic-gate #define REG_ECTYPE 13 /* invalid char-class type */ 1157c478bd9Sstevel@tonic-gate #define REG_BADPAT 14 /* syntax error */ 1167c478bd9Sstevel@tonic-gate #define REG_BADBR 15 /* \{ \} contents bad */ 1177c478bd9Sstevel@tonic-gate #define REG_EFATAL 16 /* internal error, not POSIX.2 */ 1187c478bd9Sstevel@tonic-gate #define REG_ECHAR 17 /* invalid mulitbyte character */ 1197c478bd9Sstevel@tonic-gate #define REG_STACK 18 /* backtrack stack overflow */ 1207c478bd9Sstevel@tonic-gate #define REG_ENOSYS 19 /* function not supported (XPG4) */ 1217c478bd9Sstevel@tonic-gate #define REG__LAST 20 /* first unused code */ 1227c478bd9Sstevel@tonic-gate #define REG_EBOL 21 /* ^ anchor and not BOL */ 1237c478bd9Sstevel@tonic-gate #define REG_EEOL 22 /* $ anchor and not EOL */ 1247c478bd9Sstevel@tonic-gate #define _REG_BACKREF_MAX 9 /* Max # of subexp. backreference */ 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate typedef struct { /* regcomp() data saved for regexec() */ 1277c478bd9Sstevel@tonic-gate size_t re_nsub; /* # of subexpressions in RE pattern */ 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate /* 130*4297a3b0SGarrett D'Amore * Internal use only. Note that any changes to this structure 131*4297a3b0SGarrett D'Amore * have to preserve sizing, as it is baked into applications. 1327c478bd9Sstevel@tonic-gate */ 133*4297a3b0SGarrett D'Amore struct re_guts *re_g; 134*4297a3b0SGarrett D'Amore int re_magic; 135*4297a3b0SGarrett D'Amore const char *re_endp; 136*4297a3b0SGarrett D'Amore 137*4297a3b0SGarrett D'Amore /* here for compat */ 1387c478bd9Sstevel@tonic-gate size_t re_len; /* # wchar_t chars in compiled pattern */ 1397c478bd9Sstevel@tonic-gate struct _regex_ext_t *re_sc; /* for binary compatibility */ 1407c478bd9Sstevel@tonic-gate } regex_t; 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate /* subexpression positions */ 1437c478bd9Sstevel@tonic-gate typedef struct { 1447c478bd9Sstevel@tonic-gate #ifdef __STDC__ 1457c478bd9Sstevel@tonic-gate const char *rm_sp, *rm_ep; /* Start pointer, end pointer */ 1467c478bd9Sstevel@tonic-gate #else 1477c478bd9Sstevel@tonic-gate char *rm_sp, *rm_ep; /* Start pointer, end pointer */ 1487c478bd9Sstevel@tonic-gate #endif 1497c478bd9Sstevel@tonic-gate regoff_t rm_so, rm_eo; /* Start offset, end offset */ 1507c478bd9Sstevel@tonic-gate int rm_ss, rm_es; /* Used internally */ 1517c478bd9Sstevel@tonic-gate } regmatch_t; 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate /* 1557c478bd9Sstevel@tonic-gate * Additional API and structs to support regular expression manipulations 1567c478bd9Sstevel@tonic-gate * on wide characters. 1577c478bd9Sstevel@tonic-gate */ 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate #if defined(__STDC__) 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate extern int regcomp(regex_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, int); 1627c478bd9Sstevel@tonic-gate extern int regexec(const regex_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, 1637c478bd9Sstevel@tonic-gate size_t, regmatch_t *_RESTRICT_KYWD, int); 1647c478bd9Sstevel@tonic-gate extern size_t regerror(int, const regex_t *_RESTRICT_KYWD, 1657c478bd9Sstevel@tonic-gate char *_RESTRICT_KYWD, size_t); 1667c478bd9Sstevel@tonic-gate extern void regfree(regex_t *); 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate #else /* defined(__STDC__) */ 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate extern int regcomp(); 1717c478bd9Sstevel@tonic-gate extern int regexec(); 1727c478bd9Sstevel@tonic-gate extern size_t regerror(); 1737c478bd9Sstevel@tonic-gate extern void regfree(); 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate #endif /* defined(__STDC__) */ 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate #endif 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate #endif /* _REGEX_H */ 182