1 /* $NetBSD: debug.c,v 1.4 2005/02/06 06:05:19 perry Exp $ */
4 * Copyright (c) 1993 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
42 - regprint - print a regexp for debugging
43 == void regprint(regex_t *r, FILE *d);
50 struct re_guts
*g
= r
->re_g
;
56 fprintf(d
, "%ld states, %d categories", (long)g
->nstates
,
58 fprintf(d
, ", first %ld last %ld", (long)g
->firststate
,
61 fprintf(d
, ", USEBOL");
63 fprintf(d
, ", USEEOL");
67 fprintf(d
, ", nsub=%ld", (long)g
->nsub
);
69 fprintf(d
, ", must(%ld) `%*s'", (long)g
->mlen
, (int)g
->mlen
,
72 fprintf(d
, ", backrefs");
74 fprintf(d
, ", nplus %ld", (long)g
->nplus
);
77 for (i
= 0; i
< g
->ncategories
; i
++) {
79 for (c
= CHAR_MIN
; c
<= CHAR_MAX
; c
++)
80 if (g
->categories
[c
] == i
)
83 fprintf(d
, "cc0#%d", nincat
[0]);
84 for (i
= 1; i
< g
->ncategories
; i
++)
86 for (c
= CHAR_MIN
; c
<= CHAR_MAX
; c
++)
87 if (g
->categories
[c
] == i
)
89 fprintf(d
, ", %d=%s", i
, regchar(c
));
92 for (i
= 1; i
< g
->ncategories
; i
++)
94 fprintf(d
, "cc%d\t", i
);
96 for (c
= CHAR_MIN
; c
<= CHAR_MAX
+1; c
++) /* +1 does flush */
97 if (c
<= CHAR_MAX
&& g
->categories
[c
] == i
) {
99 fprintf(d
, "%s", regchar(c
));
115 - s_print - print the strip for debugging
116 == static void s_print(struct re_guts *g, FILE *d);
131 # define GAP() { if (offset % 5 == 0) { \
133 fprintf(d, "\n\t"); \
144 if (OP(g
->strip
[0]) != OEND
)
145 fprintf(d
, "missing initial OEND!\n");
146 for (s
= &g
->strip
[1]; !done
; s
++) {
154 if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd
) != NULL
)
155 fprintf(d
, "\\%c", (char)opnd
);
157 fprintf(d
, "%s", regchar((char)opnd
));
175 fprintf(d
, "[(%ld)", (long)opnd
);
178 for (i
= 0; i
< g
->csetsize
+1; i
++) /* +1 flushes */
179 if (CHIN(cs
, i
) && i
< g
->csetsize
) {
181 fprintf(d
, "%s", regchar(i
));
195 fprintf(d
, "(\\<%ld>", (long)opnd
);
198 fprintf(d
, "<%ld>\\)", (long)opnd
);
202 if (OP(*(s
+opnd
)) != O_PLUS
)
203 fprintf(d
, "<%ld>", (long)opnd
);
206 if (OP(*(s
-opnd
)) != OPLUS_
)
207 fprintf(d
, "<%ld>", (long)opnd
);
212 if (OP(*(s
+opnd
)) != O_QUEST
)
213 fprintf(d
, "<%ld>", (long)opnd
);
216 if (OP(*(s
-opnd
)) != OQUEST_
)
217 fprintf(d
, "<%ld>", (long)opnd
);
221 fprintf(d
, "((<%ld>", (long)opnd
);
224 fprintf(d
, "<%ld>))", (long)opnd
);
228 if (OP(*(s
+opnd
)) != OOR2
)
229 fprintf(d
, "<%ld>", (long)opnd
);
232 if (OP(*(s
-opnd
)) != OOR1
&& OP(*(s
-opnd
)) != OCH_
)
233 fprintf(d
, "<%ld>", (long)opnd
);
238 if (OP(*(s
+opnd
)) != OOR2
&& OP(*(s
+opnd
)) != O_CH
)
239 fprintf(d
, "<%ld>", (long)opnd
);
242 if (OP(*(s
-opnd
)) != OOR1
)
243 fprintf(d
, "<%ld>", (long)opnd
);
247 fprintf(d
, "!%d(%d)!", OP(*s
), opnd
);
256 - regchar - make a character printable
257 == static char *regchar(int ch);
259 static char * /* -> representation */
265 if (isprint(ch
) || ch
== ' ')
266 sprintf(buf
, "%c", ch
);
268 sprintf(buf
, "\\%o", ch
);