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 */ 22*490fea6bSYuri Pankov 237c478bd9Sstevel@tonic-gate /* 24ba3594baSGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org> 25ba3594baSGarrett D'Amore * 267c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 277c478bd9Sstevel@tonic-gate * Use is subject to license terms. 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate /* 317c478bd9Sstevel@tonic-gate * Copyright 1989, 1994 by Mortice Kern Systems Inc. 327c478bd9Sstevel@tonic-gate * All rights reserved. 337c478bd9Sstevel@tonic-gate */ 34*490fea6bSYuri Pankov 354297a3b0SGarrett D'Amore /* 36*490fea6bSYuri Pankov * Copyright 2017 Nexenta Systems, Inc. 374297a3b0SGarrett D'Amore */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #ifndef _REGEX_H 407c478bd9Sstevel@tonic-gate #define _REGEX_H 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h> 437c478bd9Sstevel@tonic-gate #include <sys/types.h> 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #ifdef __cplusplus 467c478bd9Sstevel@tonic-gate extern "C" { 477c478bd9Sstevel@tonic-gate #endif 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * wchar_t is a built-in type in standard C++ and as such is not 527c478bd9Sstevel@tonic-gate * defined here when using standard C++. However, the GNU compiler 53159cf8a6Swesolows * fixincludes utility nonetheless creates its own version of this 547c478bd9Sstevel@tonic-gate * header for use by gcc and g++. In that version it adds a redundant 557c478bd9Sstevel@tonic-gate * guard for __cplusplus. To avoid the creation of a gcc/g++ specific 567c478bd9Sstevel@tonic-gate * header we need to include the following magic comment: 577c478bd9Sstevel@tonic-gate * 587c478bd9Sstevel@tonic-gate * we must use the C++ compiler's type 597c478bd9Sstevel@tonic-gate * 607c478bd9Sstevel@tonic-gate * The above comment should not be removed or changed until GNU 617c478bd9Sstevel@tonic-gate * gcc/fixinc/inclhack.def is updated to bypass this header. 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate #if !defined(__cplusplus) || (__cplusplus < 199711L && !defined(__GNUG__)) 647c478bd9Sstevel@tonic-gate #ifndef _WCHAR_T 657c478bd9Sstevel@tonic-gate #define _WCHAR_T 667c478bd9Sstevel@tonic-gate #if defined(_LP64) 677c478bd9Sstevel@tonic-gate typedef int wchar_t; 687c478bd9Sstevel@tonic-gate #else 697c478bd9Sstevel@tonic-gate typedef long wchar_t; 707c478bd9Sstevel@tonic-gate #endif 717c478bd9Sstevel@tonic-gate #endif /* !_WCHAR_T */ 727c478bd9Sstevel@tonic-gate #endif /* !defined(__cplusplus) ... */ 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate typedef ssize_t regoff_t; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate /* regcomp flags */ 77*490fea6bSYuri Pankov #define REG_BASIC 0x00000 78*490fea6bSYuri Pankov #define REG_EXTENDED 0x00001 /* Use Extended Regular Expressions */ 79*490fea6bSYuri Pankov #define REG_NOSUB 0x00002 /* Don't set subexpression */ 80*490fea6bSYuri Pankov #define REG_ICASE 0x00004 /* Ignore case in match */ 81*490fea6bSYuri Pankov #define REG_NEWLINE 0x00008 /* Treat \n as regular character */ 82*490fea6bSYuri Pankov #define REG_DELIM 0x00010 /* legacy, no effect */ 83*490fea6bSYuri Pankov #define REG_DEBUG 0x00020 /* legacy, no effect */ 84*490fea6bSYuri Pankov #define REG_ANCHOR 0x00040 /* legacy, no effect */ 85*490fea6bSYuri Pankov #define REG_WORDS 0x00080 /* legacy, no effect */ 86*490fea6bSYuri Pankov #define REG_EGREP 0x01000 /* legacy, no effect */ 87*490fea6bSYuri Pankov #define REG_DUMP 0x02000 /* internal */ 88*490fea6bSYuri Pankov #define REG_PEND 0x04000 /* NULs are ordinary characters */ 89*490fea6bSYuri Pankov #define REG_NOSPEC 0x08000 /* no special characters */ 904297a3b0SGarrett D'Amore 917c478bd9Sstevel@tonic-gate /* internal flags */ 92*490fea6bSYuri Pankov #define REG_MUST 0x00100 /* legacy, no effect */ 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate /* regexec flags */ 95*490fea6bSYuri Pankov #define REG_NOTBOL 0x00200 /* string is not BOL */ 96*490fea6bSYuri Pankov #define REG_NOTEOL 0x00400 /* string has no EOL */ 97*490fea6bSYuri Pankov #define REG_NOOPT 0x00800 /* legacy, no effect */ 98*490fea6bSYuri Pankov #define REG_STARTEND 0x10000 /* match whole pattern */ 99*490fea6bSYuri Pankov #define REG_TRACE 0x20000 /* tracing of execution */ 100*490fea6bSYuri Pankov #define REG_LARGE 0x40000 /* force large representation */ 101*490fea6bSYuri Pankov #define REG_BACKR 0x80000 /* force use of backref code */ 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 */ 121*490fea6bSYuri Pankov #define REG_ECHAR 17 /* invalid multibyte 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 */ 127*490fea6bSYuri Pankov #define REG_ATOI 255 /* convert name to number (!) */ 128*490fea6bSYuri Pankov #define REG_ITOA 256 /* convert number to name (!) */ 129*490fea6bSYuri Pankov 1307c478bd9Sstevel@tonic-gate #define _REG_BACKREF_MAX 9 /* Max # of subexp. backreference */ 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate typedef struct { /* regcomp() data saved for regexec() */ 1337c478bd9Sstevel@tonic-gate size_t re_nsub; /* # of subexpressions in RE pattern */ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate /* 1364297a3b0SGarrett D'Amore * Internal use only. Note that any changes to this structure 1374297a3b0SGarrett D'Amore * have to preserve sizing, as it is baked into applications. 1387c478bd9Sstevel@tonic-gate */ 1394297a3b0SGarrett D'Amore struct re_guts *re_g; 1404297a3b0SGarrett D'Amore int re_magic; 1414297a3b0SGarrett D'Amore const char *re_endp; 1424297a3b0SGarrett D'Amore 1434297a3b0SGarrett D'Amore /* here for compat */ 1447c478bd9Sstevel@tonic-gate size_t re_len; /* # wchar_t chars in compiled pattern */ 1457c478bd9Sstevel@tonic-gate struct _regex_ext_t *re_sc; /* for binary compatibility */ 1467c478bd9Sstevel@tonic-gate } regex_t; 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate /* subexpression positions */ 1497c478bd9Sstevel@tonic-gate typedef struct { 1507c478bd9Sstevel@tonic-gate const char *rm_sp, *rm_ep; /* Start pointer, end pointer */ 1517c478bd9Sstevel@tonic-gate regoff_t rm_so, rm_eo; /* Start offset, end offset */ 1527c478bd9Sstevel@tonic-gate int rm_ss, rm_es; /* Used internally */ 1537c478bd9Sstevel@tonic-gate } regmatch_t; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate /* 157*490fea6bSYuri Pankov * IEEE Std 1003.2 ("POSIX.2") regular expressions API. 1587c478bd9Sstevel@tonic-gate */ 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate extern int regcomp(regex_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, int); 1617c478bd9Sstevel@tonic-gate extern int regexec(const regex_t *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, 162*490fea6bSYuri Pankov size_t, regmatch_t *_RESTRICT_KYWD, int); 163*490fea6bSYuri Pankov extern size_t regerror(int, const regex_t *_RESTRICT_KYWD, char *_RESTRICT_KYWD, 164*490fea6bSYuri Pankov size_t); 1657c478bd9Sstevel@tonic-gate extern void regfree(regex_t *); 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate #endif 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate #endif /* _REGEX_H */ 172