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