2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: reexec.c /main/3 1995/11/01 18:22:33 rswiston $ */
24 /***************************************************************
26 * AT&T - PROPRIETARY *
28 * THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
31 * Copyright (c) 1995 AT&T Corp. *
32 * All Rights Reserved *
34 * This software is licensed by AT&T Corp. *
35 * under the terms and conditions of the license in *
36 * http://www.research.att.com/orgs/ssr/book/reuse *
38 * This software was created by the *
39 * Software Engineering Research Department *
40 * AT&T Bell Laboratories *
42 * For further information contact *
43 * gsf@research.att.com *
45 ***************************************************************/
47 /* : : generated by proto : : */
49 #if !defined(__PROTO__)
50 #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus)
51 #if defined(__cplusplus)
52 #define __MANGLE__ "C"
57 #define __PROTO__(x) x
59 #define __PARAM__(n,o) n
60 #if !defined(__STDC__) && !defined(__cplusplus)
61 #if !defined(c_plusplus)
72 #define __PROTO__(x) ()
73 #define __OTORP__(x) x
74 #define __PARAM__(n,o) o
82 #if defined(__cplusplus) || defined(c_plusplus)
83 #define __VARARG__ ...
87 #if defined(__STDARG__)
88 #define __VA_START__(p,a) va_start(p,a)
90 #define __VA_START__(p,a) va_start(p)
97 #define LISTINCREMENT 8
101 Inst_t* inst; /* instruction of the thread */
102 Subexp_t se; /* matched sub-expressions this thread */
106 * note optimization in addinst:
107 * *p must be pending when addinst called; if *l has been looked
108 * at already, the optimization is a bug.
112 newthread __PARAM__((register List_t* p, register Inst_t* ip, register Subexp_t* sep), (p, ip, sep)) __OTORP__(register List_t* p; register Inst_t* ip; register Subexp_t* sep;){
116 if (sep->m[0].sp < p->se.m[0].sp) p->se = *sep;
126 newmatch __PARAM__((register Subexp_t* mp, register Subexp_t* np), (mp, np)) __OTORP__(register Subexp_t* mp; register Subexp_t* np;){
127 if (!mp->m[0].sp || np->m[0].sp < mp->m[0].sp || np->m[0].sp == mp->m[0].sp && np->m[0].ep > mp->m[0].ep)
132 reexec __PARAM__((Re_program_t* aprogp, const char* starts), (aprogp, starts)) __OTORP__(Re_program_t* aprogp; const char* starts;){
133 Re_program_t* progp = (Re_program_t*)aprogp;
134 register int flag = 0;
135 register Inst_t* inst;
136 register List_t* tlp;
137 register const char* s;
142 List_t* tl; /* this list, next list */
143 List_t* nl; /* this list, next list */
144 List_t* tle; /* ends of this and next list */
145 List_t* nle; /* ends of this and next list */
150 static int listsize = LISTINCREMENT;
151 static Subexp_t sempty; /* empty set of matches */
154 startchar = progp->startinst->type < TOKEN ? progp->startinst->type : 0;
155 mp = (progp->flags & RE_MATCH) ? &progp->subexp : 0;
159 checkstart = startchar;
161 if (mp) mp->m[0].sp = mp->m[0].ep = 0;
164 if (!(list[0] = newof(0, List_t, 2 * listsize, 0)))
165 reerror("list overflow");
166 list[1] = list[0] + listsize;
167 liste[0] = list[0] + listsize - 1;
168 liste[1] = list[1] + listsize - 1;
170 list[0][0].inst = list[1][0].inst = 0;
173 * execute machine once for each character, including terminal '\0'
180 * fast check for first char
183 if (checkstart && *s != startchar) continue;
186 nl = list[flag ^= 1];
191 * add first instruction to this list
194 sempty.m[0].sp = (char*)s;
195 newthread(tl, progp->startinst, &sempty);
198 * execute machine until this list is empty
201 for (tlp = tl; inst = tlp->inst; tlp++)
210 tlp->se.m[inst->subid].sp = (char*)s;
214 tlp->se.m[inst->subid].ep = (char*)s;
234 if (s == starts || !isalnum(*(s - 1)) && *(s - 1) != '_')
241 if (!*s || !isalnum(*s) && *s != '_')
248 if (tstbit(inst->cclass, *s)) goto Addinst;
252 * evaluate right choice later
255 if (newthread(tlp, inst->right, &tlp->se) == tle)
259 * efficiency: advance and re-evaluate
267 const char* ms = (char*)tlp->se.m[inst->subid].sp;
268 const char* me = (char*)tlp->se.m[inst->subid].ep;
276 error(-1, "subexpression %d ref=\"%s\"", inst->subid, ms);
278 error(-1, "subexpression %d src=\"%s\"", inst->subid, s);
286 for (ss = s; ms < me && *ss++ == *ms; ms++);
300 tlp->se.m[0].ep = (char*)s;
301 if (mp) newmatch(mp, &tlp->se);
308 if (inst->type == *s)
311 if (newthread(nl, inst->next, &tlp->se) == nle)
317 checkstart = startchar && !nl->inst;
319 if (list[0]) free(list[0]);
324 listsize += LISTINCREMENT;