Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/dsslib/ip_t/ireexec.h
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2000-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* Phong Vo <[email protected]> *
19
* *
20
***********************************************************************/
21
#pragma prototyped
22
/*
23
* include this file to instantiate a private ire exec
24
* parameterized on these macros
25
*
26
* IREINIT the re element integral type
27
* IRENEXT the re advance function
28
* IREEXEC the re exec function
29
*
30
* macros must be defined before include
31
* macros undefined after include
32
*
33
* Glenn Fowler
34
* AT&T Research
35
*/
36
37
/*
38
* advance IREINT re until success:1 or failure:0
39
*/
40
41
static int
42
IRENEXT(Ire_t* ire, register Re_t* re, int must, IREINT* lp, IREINT* rp)
43
{
44
register int i;
45
register int j;
46
register int n;
47
IREINT* bp;
48
IREINT* cp;
49
IREINT* ep;
50
51
if (!re)
52
return !ire->right || lp >= rp;
53
if ((rp - lp) < must)
54
return 0;
55
if (re->lo)
56
{
57
must -= re->lo;
58
bp = lp + re->lo - 1;
59
}
60
else if (IRENEXT(ire, re->next, must, lp, rp))
61
return 1;
62
else
63
bp = lp;
64
if ((rp - bp) < must)
65
return 0;
66
if (!re->hi || re->hi > (rp - lp))
67
ep = rp;
68
else
69
ep = lp + re->hi;
70
if ((rp - ep) < must)
71
ep = rp - must;
72
for (cp = lp; cp < ep; cp++)
73
{
74
if (*cp == ire->group && ire->group)
75
{
76
j = *++cp;
77
if (cp < bp)
78
{
79
bp += j + 1;
80
ep += j + 1;
81
}
82
cp += j;
83
j = 1 - j;
84
}
85
else
86
j = 0;
87
if (re->n)
88
{
89
while (j < 1)
90
{
91
n = cp[j++];
92
for (i = 0; i < re->n; i++)
93
if (n == re->id[i])
94
{
95
if (re->invert)
96
return 0;
97
goto hit;
98
}
99
}
100
if (!re->invert)
101
return 0;
102
}
103
hit:
104
if (cp >= bp && IRENEXT(ire, re->next, must, cp + 1, rp))
105
return 1;
106
}
107
return 0;
108
}
109
110
/*
111
* IREINT ire exec
112
*/
113
114
static int
115
IREEXEC(Ire_t* ire, void* data, size_t size)
116
{
117
register Re_t* re = ire->re;
118
IREINT* lp = (IREINT*)data;
119
IREINT* rp = lp + size / sizeof(IREINT);
120
int left = ire->left;
121
int must = ire->must;
122
123
do
124
{
125
if (IRENEXT(ire, re, must, lp, rp))
126
return 1;
127
if (*lp++ == ire->group && ire->group)
128
lp += *lp + 1;
129
} while (!left && lp < rp);
130
return 0;
131
}
132
133
#undef IREINT
134
#undef IRENEXT
135
#undef IREEXEC
136
137