1 /* 2 * BEGIN illumos section 3 * This is an unstable interface; changes may be made 4 * without notice. 5 * END illumos section 6 */ 7 /*********************************************************************** 8 * * 9 * This software is part of the ast package * 10 * Copyright (c) 1985-2011 AT&T Intellectual Property * 11 * and is licensed under the * 12 * Eclipse Public License, Version 1.0 * 13 * by AT&T Intellectual Property * 14 * * 15 * A copy of the License is available at * 16 * http://www.eclipse.org/org/documents/epl-v10.html * 17 * (with md5 checksum b35adb5213ca9657e911e9befb180842) * 18 * * 19 * Information and Software Systems Research * 20 * AT&T Research * 21 * Florham Park NJ * 22 * * 23 * Glenn Fowler <gsf@research.att.com> * 24 * David Korn <dgk@research.att.com> * 25 * Phong Vo <kpv@research.att.com> * 26 * * 27 ***********************************************************************/ 28 #pragma prototyped 29 /* 30 * regexp interface and partial implementation 31 * what a novel approach 32 * don't do it again 33 * 34 * OBSOLETE: use <regex.h> 35 */ 36 37 #ifndef _REGEXP_H 38 #define _REGEXP_H 39 40 #define NBRA 9 41 42 typedef struct 43 { 44 char* re_braslist[NBRA]; 45 char* re_braelist[NBRA]; 46 char* re_loc1; 47 char* re_loc2; 48 char* re_locs; 49 int re_circf; 50 int re_nbra; 51 int re_nodelim; 52 int re_sed; 53 } regexp_t; 54 55 #define braslist _re_info.re_braslist 56 #define braelist _re_info.re_braelist 57 #define circf _re_info.re_circf 58 #define loc1 _re_info.re_loc1 59 #define loc2 _re_info.re_loc2 60 #define locs _re_info.re_locs 61 #define nbra _re_info.re_nbra 62 #define nodelim _re_info.re_nodelim 63 #define sed _re_info.re_sed 64 65 #define advance(a,b) _re_exec(&_re_info,a,b,1) 66 #define compile(a,b,c,d) _re_read(&_re_info,a,b,c,d) 67 #define step(a,b) _re_exec(&_re_info,a,b,0) 68 69 #if _BLD_ast && defined(__EXPORT__) 70 #define extern __EXPORT__ 71 #endif 72 73 extern int _re_comp(regexp_t*, const char*, char*, unsigned int); 74 extern int _re_exec(regexp_t*, const char*, const char*, int); 75 extern char* _re_putc(int); 76 extern char* _re_read(regexp_t*, const char*, char*, const char*, int); 77 78 #undef extern 79 80 #ifndef _REGEXP_DECLARE 81 82 regexp_t _re_info; 83 84 char* 85 _re_read(register regexp_t* re, const char* instring, char* ep, const char* endbuf, int seof) 86 { 87 register int c; 88 89 static const char* prev; 90 91 #ifdef INIT 92 INIT; 93 #endif 94 95 re->re_nodelim = 0; 96 if ((c = GETC()) == seof || c == '\n' || c == -1 || c == 0) 97 { 98 if (c != seof) 99 { 100 UNGETC(c); 101 re->re_nodelim = 1; 102 } 103 if (!re->re_sed && !prev) 104 { ERROR(41); } 105 RETURN((char*)endbuf); 106 } 107 UNGETC(c); 108 prev = 0; 109 for (;;) 110 { 111 if ((c = GETC()) == seof || c == '\n' || c == -1 || c == 0) 112 { 113 if (re->re_sed) 114 { ERROR(36); } 115 UNGETC(c); 116 re->re_nodelim = 1; 117 break; 118 } 119 if (c == '\\') 120 { 121 _re_putc(c); 122 if ((c = GETC()) == seof || c == '\n' || c == -1 || c == 0) 123 { ERROR(36); } 124 } 125 _re_putc(c); 126 } 127 if (c = _re_comp(re, _re_putc(0), ep, (char*)endbuf - ep)) 128 { ERROR(c); } 129 prev = endbuf; 130 RETURN((char*)prev); 131 } 132 133 #endif 134 135 #endif 136