1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
27 #ifndef D_FILE_OFFSET_BITS
28 #define _FILE_OFFSET_BITS 64
30 #ifndef _LARGEFILE64_SOURCE
31 #define _LARGEFILE64_SOURCE 1
39 #include <sys/types.h>
47 - regprint - print a regexp for debugging
48 == void regprint(regex_t *r, FILE *d);
55 register struct re_guts *g = r->re_g;
61 fprintf(d, "%ld states, %d categories", (long)g->nstates,
63 fprintf(d, ", first %ld last %ld", (long)g->firststate,
65 if (g->iflags & USEBOL)
66 fprintf(d, ", USEBOL");
67 if (g->iflags & USEEOL)
68 fprintf(d, ", USEEOL");
72 fprintf(d, ", nsub=%ld", (long)g->nsub);
74 fprintf(d, ", must(%ld) `%*s'", (long)g->mlen, (int)g->mlen,
77 fprintf(d, ", backrefs");
79 fprintf(d, ", nplus %ld", (long)g->nplus);
82 for (i = 0; i < g->ncategories; i++)
85 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
86 if (g->categories[c] == i)
89 fprintf(d, "cc0#%d", nincat[0]);
90 for (i = 1; i < g->ncategories; i++)
93 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
94 if (g->categories[c] == i)
96 fprintf(d, ", %d=%s", i, vogl_regchar(c));
99 for (i = 1; i < g->ncategories; i++)
102 fprintf(d, "cc%d\t", i);
104 for (c = CHAR_MIN; c <= CHAR_MAX + 1; c++) /* +1 does flush */
105 if (c <= CHAR_MAX && g->categories[c] == i)
109 fprintf(d, "%s", vogl_regchar(c));
119 vogl_regchar(c - 1));
128 - vogl_s_print - print the strip for debugging
129 == static void s_print(register struct re_guts *g, FILE *d);
132 vogl_s_print(g, d) register struct re_guts *g;
138 register int done = 0;
140 register int col = 0;
142 register sopno offset = 2;
145 if (offset % 5 == 0) \
149 fprintf(d, "\n\t"); \
163 if (OP(g->strip[0]) != OEND)
164 fprintf(d, "missing initial OEND!\n");
165 for (s = &g->strip[1]; !done; s++)
175 if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL)
176 fprintf(d, "\\%c", (char)opnd);
178 fprintf(d, "%s", vogl_regchar((char)opnd));
196 fprintf(d, "[(%ld)", (long)opnd);
199 for (i = 0; i < g->csetsize + 1; i++) /* +1 flushes */
200 if (CHIN(cs, i) && i < g->csetsize)
204 fprintf(d, "%s", vogl_regchar(i));
214 vogl_regchar(i - 1));
221 fprintf(d, "(\\<%ld>", (long)opnd);
224 fprintf(d, "<%ld>\\)", (long)opnd);
228 if (OP(*(s + opnd)) != O_PLUS)
229 fprintf(d, "<%ld>", (long)opnd);
232 if (OP(*(s - opnd)) != OPLUS_)
233 fprintf(d, "<%ld>", (long)opnd);
238 if (OP(*(s + opnd)) != O_QUEST)
239 fprintf(d, "<%ld>", (long)opnd);
242 if (OP(*(s - opnd)) != OQUEST_)
243 fprintf(d, "<%ld>", (long)opnd);
247 fprintf(d, "((<%ld>", (long)opnd);
250 fprintf(d, "<%ld>))", (long)opnd);
254 if (OP(*(s + opnd)) != OOR2)
255 fprintf(d, "<%ld>", (long)opnd);
258 if (OP(*(s - opnd)) != OOR1 && OP(*(s - opnd)) != OCH_)
259 fprintf(d, "<%ld>", (long)opnd);
264 if (OP(*(s + opnd)) != OOR2 && OP(*(s + opnd)) != O_CH)
265 fprintf(d, "<%ld>", (long)opnd);
268 if (OP(*(s - opnd)) != OOR1)
269 fprintf(d, "<%ld>", (long)opnd);
273 fprintf(d, "!%d(%d)!", (int)OP(*s), (int)opnd);
282 - vogl_regchar - make a character printable
283 == static char *vogl_regchar(int ch);
285 static char * /* -> representation */
286 vogl_regchar(ch) int ch;
290 if (isprint(ch) || ch == ' ')
291 sprintf(buf, "%c", ch);
293 sprintf(buf, "\\%o", ch);