]>
git.ipfire.org Git - people/arne_f/kernel.git/blob - net/netfilter/regexp/regexp.c
2 * regcomp and regexec -- regsub and regerror are elsewhere
3 * @(#)regexp.c 1.3 of 18 April 87
5 * Copyright (c) 1986 by University of Toronto.
6 * Written by Henry Spencer. Not derived from licensed software.
8 * Permission is granted to anyone to use this software for any
9 * purpose on any computer system, and to redistribute it freely,
10 * subject to the following restrictions:
12 * 1. The author is not responsible for the consequences of use of
13 * this software, no matter how awful, even if they arise
16 * 2. The origin of this software must not be misrepresented, either
17 * by explicit claim or by omission.
19 * 3. Altered versions must be plainly marked as such, and must not
20 * be misrepresented as being the original software.
22 * Beware that some of this code is subtly aware of the way operator
23 * precedence is structured in regular expressions. Serious changes in
24 * regular-expression syntax might require a total rethink.
26 * This code was modified by Ethan Sommer to work within the kernel
27 * (it now uses kmalloc etc..)
29 * Modified slightly by Matthew Strait to use more modern C.
35 /* added by ethan and matt. Lets it work in both kernel and user space.
36 (So iptables can use it, for instance.) Yea, it goes both ways... */
38 #define malloc(foo) kmalloc(foo,GFP_ATOMIC)
40 #define printk(format,args...) printf(format,##args)
43 void regerror(char * s
)
45 printk("<3>Regexp: %s\n", s
);
50 * The "internal use only" fields in regexp.h are present to pass info from
51 * compile to execute that permits the execute phase to run lots faster on
52 * simple cases. They are:
54 * regstart char that must begin a match; '\0' if none obvious
55 * reganch is the match anchored (at beginning-of-line only)?
56 * regmust string (pointer into program) that match must include, or NULL
57 * regmlen length of regmust string
59 * Regstart and reganch permit very fast decisions on suitable starting points
60 * for a match, cutting down the work a lot. Regmust permits fast rejection
61 * of lines that cannot possibly match. The regmust tests are costly enough
62 * that regcomp() supplies a regmust only if the r.e. contains something
63 * potentially expensive (at present, the only such thing detected is * or +
64 * at the start of the r.e., which can involve a lot of backup). Regmlen is
65 * supplied because the test in regexec() needs it and regcomp() is computing
70 * Structure for regexp "program". This is essentially a linear encoding
71 * of a nondeterministic finite-state machine (aka syntax charts or
72 * "railroad normal form" in parsing technology). Each node is an opcode
73 * plus a "next" pointer, possibly plus an operand. "Next" pointers of
74 * all nodes except BRANCH implement concatenation; a "next" pointer with
75 * a BRANCH on both ends of it is connecting two alternatives. (Here we
76 * have one of the subtle syntax dependencies: an individual BRANCH (as
77 * opposed to a collection of them) is never concatenated with anything
78 * because of operator precedence.) The operand of some types of node is
79 * a literal string; for others, it is a node leading into a sub-FSM. In
80 * particular, the operand of a BRANCH node is the first node of the branch.
81 * (NB this is *not* a tree structure: the tail of the branch connects
82 * to the thing following the set of BRANCHes.) The opcodes are:
85 /* definition number opnd? meaning */
86 #define END 0 /* no End of program. */
87 #define BOL 1 /* no Match "" at beginning of line. */
88 #define EOL 2 /* no Match "" at end of line. */
89 #define ANY 3 /* no Match any one character. */
90 #define ANYOF 4 /* str Match any character in this string. */
91 #define ANYBUT 5 /* str Match any character not in this string. */
92 #define BRANCH 6 /* node Match this alternative, or the next... */
93 #define BACK 7 /* no Match "", "next" ptr points backward. */
94 #define EXACTLY 8 /* str Match this string. */
95 #define NOTHING 9 /* no Match empty string. */
96 #define STAR 10 /* node Match this (simple) thing 0 or more times. */
97 #define PLUS 11 /* node Match this (simple) thing 1 or more times. */
98 #define OPEN 20 /* no Mark this point in input as start of #n. */
99 /* OPEN+1 is number 1, etc. */
100 #define CLOSE 30 /* no Analogous to OPEN. */
105 * BRANCH The set of branches constituting a single choice are hooked
106 * together with their "next" pointers, since precedence prevents
107 * anything being concatenated to any individual branch. The
108 * "next" pointer of the last BRANCH in a choice points to the
109 * thing following the whole choice. This is also where the
110 * final "next" pointer of each individual branch points; each
111 * branch starts with the operand node of a BRANCH node.
113 * BACK Normal "next" pointers all implicitly point forward; BACK
114 * exists to make loop structures possible.
116 * STAR,PLUS '?', and complex '*' and '+', are implemented as circular
117 * BRANCH structures using BACK. Simple cases (one character
118 * per match) are implemented with STAR and PLUS for speed
119 * and to minimize recursive plunges.
121 * OPEN,CLOSE ...are numbered at compile time.
125 * A node is one char of opcode followed by two chars of "next" pointer.
126 * "Next" pointers are stored as two 8-bit pieces, high order first. The
127 * value is a positive offset from the opcode of the node containing it.
128 * An operand, if any, simply follows the node. (Note that much of the
129 * code generation knows about this implicit relationship.)
131 * Using two bytes for the "next" pointer is vast overkill for most things,
132 * but allows patterns to get big without disasters.
135 #define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))
136 #define OPERAND(p) ((p) + 3)
139 * See regmagic.h for one further detail of program structure.
144 * Utility definitions.
147 #define UCHARAT(p) ((int)*(unsigned char *)(p))
149 #define UCHARAT(p) ((int)*(p)&CHARBITS)
152 #define FAIL(m) { regerror(m); return(NULL); }
153 #define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?')
154 #define META "^$.[()|?+*\\"
157 * Flags to be passed up and down.
159 #define HASWIDTH 01 /* Known never to match null string. */
160 #define SIMPLE 02 /* Simple enough to be STAR/PLUS operand. */
161 #define SPSTART 04 /* Starts with * or +. */
162 #define WORST 0 /* Worst case. */
165 * Global work variables for regcomp().
167 struct match_globals
{
168 char *reginput
; /* String-input pointer. */
169 char *regbol
; /* Beginning of input, for ^ check. */
170 char **regstartp
; /* Pointer to startp array. */
171 char **regendp
; /* Ditto for endp. */
172 char *regparse
; /* Input-scan pointer. */
173 int regnpar
; /* () count. */
175 char *regcode
; /* Code-emit pointer; ®dummy = don't. */
176 long regsize
; /* Code size. */
180 * Forward declarations for regcomp()'s friends.
183 #define STATIC static
185 STATIC
char *reg(struct match_globals
*g
, int paren
,int *flagp
);
186 STATIC
char *regbranch(struct match_globals
*g
, int *flagp
);
187 STATIC
char *regpiece(struct match_globals
*g
, int *flagp
);
188 STATIC
char *regatom(struct match_globals
*g
, int *flagp
);
189 STATIC
char *regnode(struct match_globals
*g
, char op
);
190 STATIC
char *regnext(struct match_globals
*g
, char *p
);
191 STATIC
void regc(struct match_globals
*g
, char b
);
192 STATIC
void reginsert(struct match_globals
*g
, char op
, char *opnd
);
193 STATIC
void regtail(struct match_globals
*g
, char *p
, char *val
);
194 STATIC
void regoptail(struct match_globals
*g
, char *p
, char *val
);
197 __kernel_size_t
my_strcspn(const char *s1
,const char *s2
)
204 for (scan1
= (char *)s1
; *scan1
!= '\0'; scan1
++) {
205 for (scan2
= (char *)s2
; *scan2
!= '\0';) /* ++ moved down. */
206 if (*scan1
== *scan2
++)
214 - regcomp - compile a regular expression into internal code
216 * We can't allocate space until we know how big the compiled form will be,
217 * but we can't compile it (and thus know how big it is) until we've got a
218 * place to put the code. So we cheat: we compile it twice, once with code
219 * generation turned off and size counting turned on, and once "for real".
220 * This also means that we don't allocate space until we are sure that the
221 * thing really will compile successfully, and we never have to move the
222 * code and thus invalidate pointers into it. (Note that it has to be in
223 * one piece because free() must be able to free it all.)
225 * Beware that the optimization-preparation code in here knows about some
226 * of the structure of the compiled regexp.
229 regcomp(char *exp
,int *patternsize
)
233 register char *longest
;
236 struct match_globals g
;
238 /* commented out by ethan
239 extern char *malloc();
243 FAIL("NULL argument");
245 /* First pass: determine size, legality. */
249 g
.regcode
= &g
.regdummy
;
251 if (reg(&g
, 0, &flags
) == NULL
)
254 /* Small enough for pointer-storage convention? */
255 if (g
.regsize
>= 32767L) /* Probably could be 65535L. */
256 FAIL("regexp too big");
258 /* Allocate space. */
259 *patternsize
=sizeof(regexp
) + (unsigned)g
.regsize
;
260 r
= (regexp
*)malloc(sizeof(regexp
) + (unsigned)g
.regsize
);
262 FAIL("out of space");
264 /* Second pass: emit code. */
267 g
.regcode
= r
->program
;
269 if (reg(&g
, 0, &flags
) == NULL
)
272 /* Dig out information for optimizations. */
273 r
->regstart
= '\0'; /* Worst-case defaults. */
277 scan
= r
->program
+1; /* First BRANCH. */
278 if (OP(regnext(&g
, scan
)) == END
) { /* Only one top-level choice. */
279 scan
= OPERAND(scan
);
281 /* Starting-point info. */
282 if (OP(scan
) == EXACTLY
)
283 r
->regstart
= *OPERAND(scan
);
284 else if (OP(scan
) == BOL
)
288 * If there's something expensive in the r.e., find the
289 * longest literal string that must appear and make it the
290 * regmust. Resolve ties in favor of later strings, since
291 * the regstart check works with the beginning of the r.e.
292 * and avoiding duplication strengthens checking. Not a
293 * strong reason, but sufficient in the absence of others.
298 for (; scan
!= NULL
; scan
= regnext(&g
, scan
))
299 if (OP(scan
) == EXACTLY
&& strlen(OPERAND(scan
)) >= len
) {
300 longest
= OPERAND(scan
);
301 len
= strlen(OPERAND(scan
));
303 r
->regmust
= longest
;
312 - reg - regular expression, i.e. main body or parenthesized thing
314 * Caller must absorb opening parenthesis.
316 * Combining parenthesis handling with the base level of regular expression
317 * is a trifle forced, but the need to tie the tails of the branches to what
318 * follows makes it hard to avoid.
321 reg(struct match_globals
*g
, int paren
, int *flagp
/* Parenthesized? */ )
325 register char *ender
;
326 register int parno
= 0; /* 0 makes gcc happy */
329 *flagp
= HASWIDTH
; /* Tentatively. */
331 /* Make an OPEN node, if parenthesized. */
333 if (g
->regnpar
>= NSUBEXP
)
337 ret
= regnode(g
, OPEN
+parno
);
341 /* Pick up the branches, linking them together. */
342 br
= regbranch(g
, &flags
);
346 regtail(g
, ret
, br
); /* OPEN -> first. */
349 if (!(flags
&HASWIDTH
))
351 *flagp
|= flags
&SPSTART
;
352 while (*g
->regparse
== '|') {
354 br
= regbranch(g
, &flags
);
357 regtail(g
, ret
, br
); /* BRANCH -> BRANCH. */
358 if (!(flags
&HASWIDTH
))
360 *flagp
|= flags
&SPSTART
;
363 /* Make a closing node, and hook it on the end. */
364 ender
= regnode(g
, (paren
) ? CLOSE
+parno
: END
);
365 regtail(g
, ret
, ender
);
367 /* Hook the tails of the branches to the closing node. */
368 for (br
= ret
; br
!= NULL
; br
= regnext(g
, br
))
369 regoptail(g
, br
, ender
);
371 /* Check for proper termination. */
372 if (paren
&& *g
->regparse
++ != ')') {
373 FAIL("unmatched ()");
374 } else if (!paren
&& *g
->regparse
!= '\0') {
375 if (*g
->regparse
== ')') {
376 FAIL("unmatched ()");
378 FAIL("junk on end"); /* "Can't happen". */
386 - regbranch - one alternative of an | operator
388 * Implements the concatenation operator.
391 regbranch(struct match_globals
*g
, int *flagp
)
394 register char *chain
;
395 register char *latest
;
398 *flagp
= WORST
; /* Tentatively. */
400 ret
= regnode(g
, BRANCH
);
402 while (*g
->regparse
!= '\0' && *g
->regparse
!= '|' && *g
->regparse
!= ')') {
403 latest
= regpiece(g
, &flags
);
406 *flagp
|= flags
&HASWIDTH
;
407 if (chain
== NULL
) /* First piece. */
408 *flagp
|= flags
&SPSTART
;
410 regtail(g
, chain
, latest
);
413 if (chain
== NULL
) /* Loop ran zero times. */
414 (void) regnode(g
, NOTHING
);
420 - regpiece - something followed by possible [*+?]
422 * Note that the branching code sequences used for ? and the general cases
423 * of * and + are somewhat optimized: they use the same NOTHING node as
424 * both the endmarker for their branch list and the body of the last branch.
425 * It might seem that this node could be dispensed with entirely, but the
426 * endmarker role is not redundant.
429 regpiece(struct match_globals
*g
, int *flagp
)
436 ret
= regatom(g
, &flags
);
446 if (!(flags
&HASWIDTH
) && op
!= '?')
447 FAIL("*+ operand could be empty");
448 *flagp
= (op
!= '+') ? (WORST
|SPSTART
) : (WORST
|HASWIDTH
);
450 if (op
== '*' && (flags
&SIMPLE
))
451 reginsert(g
, STAR
, ret
);
452 else if (op
== '*') {
453 /* Emit x* as (x&|), where & means "self". */
454 reginsert(g
, BRANCH
, ret
); /* Either x */
455 regoptail(g
, ret
, regnode(g
, BACK
)); /* and loop */
456 regoptail(g
, ret
, ret
); /* back */
457 regtail(g
, ret
, regnode(g
, BRANCH
)); /* or */
458 regtail(g
, ret
, regnode(g
, NOTHING
)); /* null. */
459 } else if (op
== '+' && (flags
&SIMPLE
))
460 reginsert(g
, PLUS
, ret
);
461 else if (op
== '+') {
462 /* Emit x+ as x(&|), where & means "self". */
463 next
= regnode(g
, BRANCH
); /* Either */
464 regtail(g
, ret
, next
);
465 regtail(g
, regnode(g
, BACK
), ret
); /* loop back */
466 regtail(g
, next
, regnode(g
, BRANCH
)); /* or */
467 regtail(g
, ret
, regnode(g
, NOTHING
)); /* null. */
468 } else if (op
== '?') {
469 /* Emit x? as (x|) */
470 reginsert(g
, BRANCH
, ret
); /* Either x */
471 regtail(g
, ret
, regnode(g
, BRANCH
)); /* or */
472 next
= regnode(g
, NOTHING
); /* null. */
473 regtail(g
, ret
, next
);
474 regoptail(g
, ret
, next
);
477 if (ISMULT(*g
->regparse
))
484 - regatom - the lowest level
486 * Optimization: gobbles an entire sequence of ordinary characters so that
487 * it can turn them into a single node, which is smaller to store and
488 * faster to run. Backslashed characters are exceptions, each becoming a
489 * separate node; the code is simpler that way and it's not worth fixing.
492 regatom(struct match_globals
*g
, int *flagp
)
497 *flagp
= WORST
; /* Tentatively. */
499 switch (*g
->regparse
++) {
501 ret
= regnode(g
, BOL
);
504 ret
= regnode(g
, EOL
);
507 ret
= regnode(g
, ANY
);
508 *flagp
|= HASWIDTH
|SIMPLE
;
512 register int classend
;
514 if (*g
->regparse
== '^') { /* Complement of range. */
515 ret
= regnode(g
, ANYBUT
);
518 ret
= regnode(g
, ANYOF
);
519 if (*g
->regparse
== ']' || *g
->regparse
== '-')
520 regc(g
, *g
->regparse
++);
521 while (*g
->regparse
!= '\0' && *g
->regparse
!= ']') {
522 if (*g
->regparse
== '-') {
524 if (*g
->regparse
== ']' || *g
->regparse
== '\0')
527 class = UCHARAT(g
->regparse
-2)+1;
528 classend
= UCHARAT(g
->regparse
);
529 if (class > classend
+1)
530 FAIL("invalid [] range");
531 for (; class <= classend
; class++)
536 regc(g
, *g
->regparse
++);
539 if (*g
->regparse
!= ']')
540 FAIL("unmatched []");
542 *flagp
|= HASWIDTH
|SIMPLE
;
546 ret
= reg(g
, 1, &flags
);
549 *flagp
|= flags
&(HASWIDTH
|SPSTART
);
554 FAIL("internal urp"); /* Supposed to be caught earlier. */
559 FAIL("?+* follows nothing");
562 if (*g
->regparse
== '\0')
564 ret
= regnode(g
, EXACTLY
);
565 regc(g
, *g
->regparse
++);
567 *flagp
|= HASWIDTH
|SIMPLE
;
574 len
= my_strcspn((const char *)g
->regparse
, (const char *)META
);
576 FAIL("internal disaster");
577 ender
= *(g
->regparse
+len
);
578 if (len
> 1 && ISMULT(ender
))
579 len
--; /* Back off clear of ?+* operand. */
583 ret
= regnode(g
, EXACTLY
);
585 regc(g
, *g
->regparse
++);
597 - regnode - emit a node
599 static char * /* Location. */
600 regnode(struct match_globals
*g
, char op
)
606 if (ret
== &g
->regdummy
) {
613 *ptr
++ = '\0'; /* Null "next" pointer. */
621 - regc - emit (if appropriate) a byte of code
624 regc(struct match_globals
*g
, char b
)
626 if (g
->regcode
!= &g
->regdummy
)
633 - reginsert - insert an operator in front of already-emitted operand
635 * Means relocating the operand.
638 reginsert(struct match_globals
*g
, char op
, char* opnd
)
642 register char *place
;
644 if (g
->regcode
== &g
->regdummy
) {
655 place
= opnd
; /* Op node, where operand used to be. */
662 - regtail - set the next-pointer at the end of a node chain
665 regtail(struct match_globals
*g
, char *p
, char *val
)
671 if (p
== &g
->regdummy
)
674 /* Find last node. */
677 temp
= regnext(g
, scan
);
683 if (OP(scan
) == BACK
)
687 *(scan
+1) = (offset
>>8)&0377;
688 *(scan
+2) = offset
&0377;
692 - regoptail - regtail on operand of first argument; nop if operandless
695 regoptail(struct match_globals
*g
, char *p
, char *val
)
697 /* "Operandless" and "op != BRANCH" are synonymous in practice. */
698 if (p
== NULL
|| p
== &g
->regdummy
|| OP(p
) != BRANCH
)
700 regtail(g
, OPERAND(p
), val
);
704 * regexec and friends
711 STATIC
int regtry(struct match_globals
*g
, regexp
*prog
, char *string
);
712 STATIC
int regmatch(struct match_globals
*g
, char *prog
);
713 STATIC
int regrepeat(struct match_globals
*g
, char *p
);
718 STATIC
char *regprop(char *op
);
722 - regexec - match a regexp against a string
725 regexec(regexp
*prog
, char *string
)
728 struct match_globals g
;
731 if (prog
== NULL
|| string
== NULL
) {
732 printk("<3>Regexp: NULL parameter\n");
736 /* Check validity of program. */
737 if (UCHARAT(prog
->program
) != MAGIC
) {
738 printk("<3>Regexp: corrupted program\n");
742 /* If there is a "must appear" string, look for it. */
743 if (prog
->regmust
!= NULL
) {
745 while ((s
= strchr(s
, prog
->regmust
[0])) != NULL
) {
746 if (strncmp(s
, prog
->regmust
, prog
->regmlen
) == 0)
747 break; /* Found it. */
750 if (s
== NULL
) /* Not present. */
754 /* Mark beginning of line for ^ . */
757 /* Simplest case: anchored match need be tried only once. */
759 return(regtry(&g
, prog
, string
));
761 /* Messy cases: unanchored match. */
763 if (prog
->regstart
!= '\0')
764 /* We know what char it must start with. */
765 while ((s
= strchr(s
, prog
->regstart
)) != NULL
) {
766 if (regtry(&g
, prog
, s
))
771 /* We don't -- general case. */
773 if (regtry(&g
, prog
, s
))
775 } while (*s
++ != '\0');
782 - regtry - try match at specific point
784 static int /* 0 failure, 1 success */
785 regtry(struct match_globals
*g
, regexp
*prog
, char *string
)
791 g
->reginput
= string
;
792 g
->regstartp
= prog
->startp
;
793 g
->regendp
= prog
->endp
;
797 for (i
= NSUBEXP
; i
> 0; i
--) {
801 if (regmatch(g
, prog
->program
+ 1)) {
802 prog
->startp
[0] = string
;
803 prog
->endp
[0] = g
->reginput
;
810 - regmatch - main matching routine
812 * Conceptually the strategy is simple: check to see whether the current
813 * node matches, call self recursively to see whether the rest matches,
814 * and then act accordingly. In practice we make some effort to avoid
815 * recursion, in particular by going through "ordinary" nodes (that don't
816 * need to know whether the rest of the match failed) by a loop instead of
819 static int /* 0 failure, 1 success */
820 regmatch(struct match_globals
*g
, char *prog
)
822 register char *scan
= prog
; /* Current node. */
823 char *next
; /* Next node. */
826 if (scan
!= NULL
&& regnarrate
)
827 fprintf(stderr
, "%s(\n", regprop(scan
));
829 while (scan
!= NULL
) {
832 fprintf(stderr
, "%s...\n", regprop(scan
));
834 next
= regnext(g
, scan
);
838 if (g
->reginput
!= g
->regbol
)
842 if (*g
->reginput
!= '\0')
846 if (*g
->reginput
== '\0')
854 opnd
= OPERAND(scan
);
855 /* Inline the first character, for speed. */
856 if (*opnd
!= *g
->reginput
)
859 if (len
> 1 && strncmp(opnd
, g
->reginput
, len
) != 0)
865 if (*g
->reginput
== '\0' || strchr(OPERAND(scan
), *g
->reginput
) == NULL
)
870 if (*g
->reginput
== '\0' || strchr(OPERAND(scan
), *g
->reginput
) != NULL
)
889 no
= OP(scan
) - OPEN
;
892 if (regmatch(g
, next
)) {
894 * Don't set startp if some later
895 * invocation of the same parentheses
898 if (g
->regstartp
[no
] == NULL
)
899 g
->regstartp
[no
] = save
;
918 no
= OP(scan
) - CLOSE
;
921 if (regmatch(g
, next
)) {
923 * Don't set endp if some later
924 * invocation of the same parentheses
927 if (g
->regendp
[no
] == NULL
)
928 g
->regendp
[no
] = save
;
937 if (OP(next
) != BRANCH
) /* No choice. */
938 next
= OPERAND(scan
); /* Avoid recursion. */
942 if (regmatch(g
, OPERAND(scan
)))
945 scan
= regnext(g
, scan
);
946 } while (scan
!= NULL
&& OP(scan
) == BRANCH
);
954 register char nextch
;
960 * Lookahead to avoid useless match attempts
961 * when we know what character comes next.
964 if (OP(next
) == EXACTLY
)
965 nextch
= *OPERAND(next
);
966 min
= (OP(scan
) == STAR
) ? 0 : 1;
968 no
= regrepeat(g
, OPERAND(scan
));
970 /* If it could work, try it. */
971 if (nextch
== '\0' || *g
->reginput
== nextch
)
972 if (regmatch(g
, next
))
974 /* Couldn't or didn't -- back up. */
976 g
->reginput
= save
+ no
;
982 return(1); /* Success! */
985 printk("<3>Regexp: memory corruption\n");
994 * We get here only if there's trouble -- normally "case END" is
995 * the terminating point.
997 printk("<3>Regexp: corrupted pointers\n");
1002 - regrepeat - repeatedly match something simple, report how many
1005 regrepeat(struct match_globals
*g
, char *p
)
1007 register int count
= 0;
1008 register char *scan
;
1009 register char *opnd
;
1015 count
= strlen(scan
);
1019 while (*opnd
== *scan
) {
1025 while (*scan
!= '\0' && strchr(opnd
, *scan
) != NULL
) {
1031 while (*scan
!= '\0' && strchr(opnd
, *scan
) == NULL
) {
1036 default: /* Oh dear. Called inappropriately. */
1037 printk("<3>Regexp: internal foulup\n");
1038 count
= 0; /* Best compromise. */
1047 - regnext - dig the "next" pointer out of a node
1050 regnext(struct match_globals
*g
, char *p
)
1052 register int offset
;
1054 if (p
== &g
->regdummy
)
1069 STATIC
char *regprop();
1072 - regdump - dump a regexp onto stdout in vaguely comprehensible form
1078 register char op
= EXACTLY
; /* Arbitrary non-END op. */
1079 register char *next
;
1080 /* extern char *strchr(); */
1084 while (op
!= END
) { /* While that wasn't END last time... */
1086 printf("%2d%s", s
-r
->program
, regprop(s
)); /* Where, what. */
1088 if (next
== NULL
) /* Next ptr. */
1091 printf("(%d)", (s
-r
->program
)+(next
-s
));
1093 if (op
== ANYOF
|| op
== ANYBUT
|| op
== EXACTLY
) {
1094 /* Literal string, where present. */
1095 while (*s
!= '\0') {
1104 /* Header fields of interest. */
1105 if (r
->regstart
!= '\0')
1106 printf("start `%c' ", r
->regstart
);
1108 printf("anchored ");
1109 if (r
->regmust
!= NULL
)
1110 printf("must have \"%s\"", r
->regmust
);
1115 - regprop - printable representation of opcode
1122 static char buf
[BUFLEN
];
1166 snprintf(buf
+strlen(buf
),BUFLEN
-strlen(buf
), "OPEN%d", OP(op
)-OPEN
);
1178 snprintf(buf
+strlen(buf
),BUFLEN
-strlen(buf
), "CLOSE%d", OP(op
)-CLOSE
);
1188 printk("<3>Regexp: corrupted opcode\n");
1192 strncat(buf
, p
, BUFLEN
-strlen(buf
));