]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/engine/regexp.cpp
2 * regcomp and regexec -- regsub and regerror are elsewhere
4 * Copyright (c) 1986 by University of Toronto.
5 * Written by Henry Spencer. Not derived from licensed software.
7 * Permission is granted to anyone to use this software for any
8 * purpose on any computer system, and to redistribute it freely,
9 * subject to the following restrictions:
11 * 1. The author is not responsible for the consequences of use of
12 * this software, no matter how awful, even if they arise
15 * 2. The origin of this software must not be misrepresented, either
16 * by explicit claim or by omission.
18 * 3. Altered versions must be plainly marked as such, and must not
19 * be misrepresented as being the original software.
20 *** THIS IS AN ALTERED VERSION. It was altered by John Gilmore,
21 *** hoptoad!gnu, on 27 Dec 1986, to add \n as an alternative to |
22 *** to assist in implementing egrep.
23 *** THIS IS AN ALTERED VERSION. It was altered by John Gilmore,
24 *** hoptoad!gnu, on 27 Dec 1986, to add \< and \> for word-matching
25 *** as in BSD grep and ex.
26 *** THIS IS AN ALTERED VERSION. It was altered by John Gilmore,
27 *** hoptoad!gnu, on 28 Dec 1986, to optimize characters quoted with \.
28 *** THIS IS AN ALTERED VERSION. It was altered by James A. Woods,
29 *** ames!jaw, on 19 June 1987, to quash a regcomp() redundancy.
30 *** THIS IS AN ALTERED VERSION. It was altered by Christopher Seiwald
31 *** seiwald@vix.com, on 28 August 1993, for use in jam. Regmagic.h
32 *** was moved into regexp.h, and the include of regexp.h now uses "'s
33 *** to avoid conflicting with the system regexp.h. Const, bless its
34 *** soul, was removed so it can compile everywhere. The declaration
35 *** of strchr() was in conflict on AIX, so it was removed (as it is
36 *** happily defined in string.h).
37 *** THIS IS AN ALTERED VERSION. It was altered by Christopher Seiwald
38 *** seiwald@perforce.com, on 20 January 2000, to use function prototypes.
40 * Beware that some of this code is subtly aware of the way operator precedence
41 * is structured in regular expressions. Serious changes in regular-expression
42 * syntax might require a total rethink.
59 * The "internal use only" fields in regexp.h are present to pass info from
60 * compile to execute that permits the execute phase to run lots faster on
61 * simple cases. They are:
63 * regstart char that must begin a match; '\0' if none obvious.
64 * reganch is the match anchored (at beginning-of-line only)?
65 * regmust string (pointer into program) that match must include, or NULL.
66 * regmlen length of regmust string.
68 * Regstart and reganch permit very fast decisions on suitable starting points
69 * for a match, cutting down the work a lot. Regmust permits fast rejection of
70 * lines that cannot possibly match. The regmust tests are costly enough that
71 * regcomp() supplies a regmust only if the r.e. contains something potentially
72 * expensive (at present, the only such thing detected is * or + at the start of
73 * the r.e., which can involve a lot of backup). Regmlen is supplied because the
74 * test in regexec() needs it and regcomp() is computing it anyway.
78 * Structure for regexp "program". This is essentially a linear encoding of a
79 * nondeterministic finite-state machine (aka syntax charts or "railroad normal
80 * form" in parsing technology). Each node is an opcode plus a "next" pointer,
81 * possibly plus an operand. "Next" pointers of all nodes except BRANCH
82 * implement concatenation; a "next" pointer with a BRANCH on both ends of it is
83 * connecting two alternatives. [Here we have one of the subtle syntax
84 * dependencies: an individual BRANCH, as opposed to a collection of them, is
85 * never concatenated with anything because of operator precedence.] The operand
86 * of some types of node is a literal string; for others, it is a node leading
87 * into a sub-FSM. In particular, the operand of a BRANCH node is the first node
88 * of the branch. [NB this is *not* a tree structure: the tail of the branch
89 * connects to the thing following the set of BRANCHes.] The opcodes are:
92 /* definition number opnd? meaning */
93 #define END 0 /* no End of program. */
94 #define BOL 1 /* no Match "" at beginning of line. */
95 #define EOL 2 /* no Match "" at end of line. */
96 #define ANY 3 /* no Match any one character. */
97 #define ANYOF 4 /* str Match any character in this string. */
98 #define ANYBUT 5 /* str Match any character not in this string. */
99 #define BRANCH 6 /* node Match this alternative, or the next... */
100 #define BACK 7 /* no Match "", "next" ptr points backward. */
101 #define EXACTLY 8 /* str Match this string. */
102 #define NOTHING 9 /* no Match empty string. */
103 #define STAR 10 /* node Match this (simple) thing 0 or more times. */
104 #define PLUS 11 /* node Match this (simple) thing 1 or more times. */
105 #define WORDA 12 /* no Match "" at wordchar, where prev is nonword */
106 #define WORDZ 13 /* no Match "" at nonwordchar, where prev is word */
107 #define OPEN 20 /* no Mark this point in input as start of #n. */
108 /* OPEN+1 is number 1, etc. */
109 #define CLOSE 30 /* no Analogous to OPEN. */
115 * BRANCH The set of branches constituting a single choice are hooked
116 * together with their "next" pointers, since precedence prevents
117 * anything being concatenated to any individual branch. The
118 * "next" pointer of the last BRANCH in a choice points to the
119 * thing following the whole choice. This is also where the
120 * final "next" pointer of each individual branch points; each
121 * branch starts with the operand node of a BRANCH node.
123 * BACK Normal "next" pointers all implicitly point forward; BACK
124 * exists to make loop structures possible.
126 * STAR,PLUS '?', and complex '*' and '+', are implemented as circular
127 * BRANCH structures using BACK. Simple cases (one character
128 * per match) are implemented with STAR and PLUS for speed
129 * and to minimize recursive plunges.
131 * OPEN,CLOSE ...are numbered at compile time.
135 * A node is one char of opcode followed by two chars of "next" pointer.
136 * "Next" pointers are stored as two 8-bit pieces, high order first. The
137 * value is a positive offset from the opcode of the node containing it.
138 * An operand, if any, simply follows the node. (Note that much of the
139 * code generation knows about this implicit relationship.)
141 * Using two bytes for the "next" pointer is vast overkill for most things,
142 * but allows patterns to get big without disasters.
145 #define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))
146 #define OPERAND(p) ((p) + 3)
149 * See regmagic.h for one further detail of program structure.
154 * Utility definitions.
157 #define UCHARAT(p) ((int)*(const unsigned char *)(p))
159 #define UCHARAT(p) ((int)*(p)&CHARBITS)
162 #define FAIL(m) { regerror(m); return(NULL); }
163 #define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?')
166 * Flags to be passed up and down.
168 #define HASWIDTH 01 /* Known never to match null string. */
169 #define SIMPLE 02 /* Simple enough to be STAR/PLUS operand. */
170 #define SPSTART 04 /* Starts with * or +. */
171 #define WORST 0 /* Worst case. */
174 * Global work variables for regcomp().
176 static char *regparse
; /* Input-scan pointer. */
177 static int regnpar
; /* () count. */
178 static char regdummy
;
179 static char *regcode
; /* Code-emit pointer; ®dummy = don't. */
180 static long regsize
; /* Code size. */
183 * Forward declarations for regcomp()'s friends.
186 #define STATIC static
188 STATIC
char *reg( int paren
, int *flagp
);
189 STATIC
char *regbranch( int *flagp
);
190 STATIC
char *regpiece( int *flagp
);
191 STATIC
char *regatom( int *flagp
);
192 STATIC
char *regnode( int op
);
193 STATIC
char *regnext( char *p
);
194 STATIC
void regc( int b
);
195 STATIC
void reginsert( char op
, char *opnd
);
196 STATIC
void regtail( char *p
, char *val
);
197 STATIC
void regoptail( char *p
, char *val
);
199 STATIC
int strcspn();
203 - regcomp - compile a regular expression into internal code
205 * We can't allocate space until we know how big the compiled form will be,
206 * but we can't compile it (and thus know how big it is) until we've got a
207 * place to put the code. So we cheat: we compile it twice, once with code
208 * generation turned off and size counting turned on, and once "for real".
209 * This also means that we don't allocate space until we are sure that the
210 * thing really will compile successfully, and we never have to move the
211 * code and thus invalidate pointers into it. (Note that it has to be in
212 * one piece because free() must be able to free it all.)
214 * Beware that the optimization-preparation code in here knows about some
215 * of the structure of the compiled regexp.
218 regcomp( const char *exp
)
227 FAIL("NULL argument");
229 /* First pass: determine size, legality. */
231 if (exp
[0] == '.' && exp
[1] == '*') exp
+= 2; /* aid grep */
233 regparse
= (char *)exp
;
238 if (reg(0, &flags
) == NULL
)
241 /* Small enough for pointer-storage convention? */
242 if (regsize
>= 32767L) /* Probably could be 65535L. */
243 FAIL("regexp too big");
245 /* Allocate space. */
246 r
= (regexp
*)BJAM_MALLOC(sizeof(regexp
) + (unsigned)regsize
);
248 FAIL("out of space");
250 /* Second pass: emit code. */
251 regparse
= (char *)exp
;
253 regcode
= r
->program
;
255 if (reg(0, &flags
) == NULL
)
258 /* Dig out information for optimizations. */
259 r
->regstart
= '\0'; /* Worst-case defaults. */
263 scan
= r
->program
+1; /* First BRANCH. */
264 if (OP(regnext(scan
)) == END
) { /* Only one top-level choice. */
265 scan
= OPERAND(scan
);
267 /* Starting-point info. */
268 if (OP(scan
) == EXACTLY
)
269 r
->regstart
= *OPERAND(scan
);
270 else if (OP(scan
) == BOL
)
274 * If there's something expensive in the r.e., find the
275 * longest literal string that must appear and make it the
276 * regmust. Resolve ties in favor of later strings, since
277 * the regstart check works with the beginning of the r.e.
278 * and avoiding duplication strengthens checking. Not a
279 * strong reason, but sufficient in the absence of others.
284 for (; scan
!= NULL
; scan
= regnext(scan
))
285 if (OP(scan
) == EXACTLY
&& strlen(OPERAND(scan
)) >= len
) {
286 longest
= OPERAND(scan
);
287 len
= strlen(OPERAND(scan
));
289 r
->regmust
= longest
;
298 - reg - regular expression, i.e. main body or parenthesized thing
300 * Caller must absorb opening parenthesis.
302 * Combining parenthesis handling with the base level of regular expression
303 * is a trifle forced, but the need to tie the tails of the branches to what
304 * follows makes it hard to avoid.
308 int paren
, /* Parenthesized? */
317 *flagp
= HASWIDTH
; /* Tentatively. */
319 /* Make an OPEN node, if parenthesized. */
321 if (regnpar
>= NSUBEXP
)
325 ret
= regnode(OPEN
+parno
);
329 /* Pick up the branches, linking them together. */
330 br
= regbranch(&flags
);
334 regtail(ret
, br
); /* OPEN -> first. */
337 if (!(flags
&HASWIDTH
))
339 *flagp
|= flags
&SPSTART
;
340 while (*regparse
== '|' || *regparse
== '\n') {
342 br
= regbranch(&flags
);
345 regtail(ret
, br
); /* BRANCH -> BRANCH. */
346 if (!(flags
&HASWIDTH
))
348 *flagp
|= flags
&SPSTART
;
351 /* Make a closing node, and hook it on the end. */
352 ender
= regnode((paren
) ? CLOSE
+parno
: END
);
355 /* Hook the tails of the branches to the closing node. */
356 for (br
= ret
; br
!= NULL
; br
= regnext(br
))
357 regoptail(br
, ender
);
359 /* Check for proper termination. */
360 if (paren
&& *regparse
++ != ')') {
361 FAIL("unmatched ()");
362 } else if (!paren
&& *regparse
!= '\0') {
363 if (*regparse
== ')') {
364 FAIL("unmatched ()");
366 FAIL("junk on end"); /* "Can't happen". */
374 - regbranch - one alternative of an | operator
376 * Implements the concatenation operator.
379 regbranch( int *flagp
)
386 *flagp
= WORST
; /* Tentatively. */
388 ret
= regnode(BRANCH
);
390 while (*regparse
!= '\0' && *regparse
!= ')' &&
391 *regparse
!= '\n' && *regparse
!= '|') {
392 latest
= regpiece(&flags
);
395 *flagp
|= flags
&HASWIDTH
;
396 if (chain
== NULL
) /* First piece. */
397 *flagp
|= flags
&SPSTART
;
399 regtail(chain
, latest
);
402 if (chain
== NULL
) /* Loop ran zero times. */
403 (void) regnode(NOTHING
);
409 - regpiece - something followed by possible [*+?]
411 * Note that the branching code sequences used for ? and the general cases
412 * of * and + are somewhat optimized: they use the same NOTHING node as
413 * both the endmarker for their branch list and the body of the last branch.
414 * It might seem that this node could be dispensed with entirely, but the
415 * endmarker role is not redundant.
418 regpiece( int *flagp
)
425 ret
= regatom(&flags
);
435 if (!(flags
&HASWIDTH
) && op
!= '?')
436 FAIL("*+ operand could be empty");
437 *flagp
= (op
!= '+') ? (WORST
|SPSTART
) : (WORST
|HASWIDTH
);
439 if (op
== '*' && (flags
&SIMPLE
))
440 reginsert(STAR
, ret
);
441 else if (op
== '*') {
442 /* Emit x* as (x&|), where & means "self". */
443 reginsert(BRANCH
, ret
); /* Either x */
444 regoptail(ret
, regnode(BACK
)); /* and loop */
445 regoptail(ret
, ret
); /* back */
446 regtail(ret
, regnode(BRANCH
)); /* or */
447 regtail(ret
, regnode(NOTHING
)); /* null. */
448 } else if (op
== '+' && (flags
&SIMPLE
))
449 reginsert(PLUS
, ret
);
450 else if (op
== '+') {
451 /* Emit x+ as x(&|), where & means "self". */
452 next
= regnode(BRANCH
); /* Either */
454 regtail(regnode(BACK
), ret
); /* loop back */
455 regtail(next
, regnode(BRANCH
)); /* or */
456 regtail(ret
, regnode(NOTHING
)); /* null. */
457 } else if (op
== '?') {
458 /* Emit x? as (x|) */
459 reginsert(BRANCH
, ret
); /* Either x */
460 regtail(ret
, regnode(BRANCH
)); /* or */
461 next
= regnode(NOTHING
); /* null. */
463 regoptail(ret
, next
);
466 if (ISMULT(*regparse
))
473 - regatom - the lowest level
475 * Optimization: gobbles an entire sequence of ordinary characters so that
476 * it can turn them into a single node, which is smaller to store and
477 * faster to run. Backslashed characters are exceptions, each becoming a
478 * separate node; the code is simpler that way and it's not worth fixing.
481 regatom( int *flagp
)
486 *flagp
= WORST
; /* Tentatively. */
488 switch (*regparse
++) {
489 /* FIXME: these chars only have meaning at beg/end of pat? */
498 *flagp
|= HASWIDTH
|SIMPLE
;
504 if (*regparse
== '^') { /* Complement of range. */
505 ret
= regnode(ANYBUT
);
508 ret
= regnode(ANYOF
);
509 if (*regparse
== ']' || *regparse
== '-')
511 while (*regparse
!= '\0' && *regparse
!= ']') {
512 if (*regparse
== '-') {
514 if (*regparse
== ']' || *regparse
== '\0')
517 classr
= UCHARAT(regparse
-2)+1;
518 classend
= UCHARAT(regparse
);
519 if (classr
> classend
+1)
520 FAIL("invalid [] range");
521 for (; classr
<= classend
; classr
++)
529 if (*regparse
!= ']')
530 FAIL("unmatched []");
532 *flagp
|= HASWIDTH
|SIMPLE
;
536 ret
= reg(1, &flags
);
539 *flagp
|= flags
&(HASWIDTH
|SPSTART
);
545 FAIL("internal urp"); /* Supposed to be caught earlier. */
550 FAIL("?+* follows nothing");
553 switch (*regparse
++) {
558 ret
= regnode(WORDA
);
561 ret
= regnode(WORDZ
);
563 /* FIXME: Someday handle \1, \2, ... */
565 /* Handle general quoted chars in exact-match routine */
572 * Encode a string of characters to be matched exactly.
574 * This is a bit tricky due to quoted chars and due to
575 * '*', '+', and '?' taking the SINGLE char previous
578 * On entry, the char at regparse[-1] is going to go
579 * into the string, no matter what it is. (It could be
580 * following a \ if we are entered from the '\' case.)
582 * Basic idea is to pick up a good char in ch and
583 * examine the next char. If it's *+? then we twiddle.
584 * If it's \ then we frozzle. If it's other magic char
585 * we push ch and terminate the string. If none of the
586 * above, we push ch on the string and go around again.
588 * regprev is used to remember where "the current char"
589 * starts in the string, if due to a *+? we need to back
590 * up and put the current char in a separate, 1-char, string.
591 * When regprev is NULL, ch is the only char in the
592 * string; this is used in *+? handling, and in setting
593 * flags |= SIMPLE at the end.
599 regparse
--; /* Look at cur char */
600 ret
= regnode(EXACTLY
);
601 for ( regprev
= 0 ; ; ) {
602 ch
= *regparse
++; /* Get current char */
603 switch (*regparse
) { /* look at next one */
606 regc(ch
); /* Add cur to string */
609 case '.': case '[': case '(':
610 case ')': case '|': case '\n':
613 /* FIXME, $ and ^ should not always be magic */
615 regc(ch
); /* dump cur char */
616 goto done
; /* and we are done */
618 case '?': case '+': case '*':
619 if (!regprev
) /* If just ch in str, */
620 goto magic
; /* use it */
621 /* End mult-char string one early */
622 regparse
= regprev
; /* Back up parse */
626 regc(ch
); /* Cur char OK */
627 switch (regparse
[1]){ /* Look after \ */
631 /* FIXME: Someday handle \1, \2, ... */
632 goto done
; /* Not quoted */
634 /* Backup point is \, scan * point is after it. */
637 continue; /* NOT break; */
640 regprev
= regparse
; /* Set backup point */
645 if (!regprev
) /* One char? */
655 - regnode - emit a node
657 static char * /* Location. */
664 if (ret
== ®dummy
) {
671 *ptr
++ = '\0'; /* Null "next" pointer. */
679 - regc - emit (if appropriate) a byte of code
684 if (regcode
!= ®dummy
)
691 - reginsert - insert an operator in front of already-emitted operand
693 * Means relocating the operand.
704 if (regcode
== ®dummy
) {
715 place
= opnd
; /* Op node, where operand used to be. */
722 - regtail - set the next-pointer at the end of a node chain
736 /* Find last node. */
739 temp
= regnext(scan
);
745 if (OP(scan
) == BACK
)
749 *(scan
+1) = (offset
>>8)&0377;
750 *(scan
+2) = offset
&0377;
754 - regoptail - regtail on operand of first argument; nop if operandless
762 /* "Operandless" and "op != BRANCH" are synonymous in practice. */
763 if (p
== NULL
|| p
== ®dummy
|| OP(p
) != BRANCH
)
765 regtail(OPERAND(p
), val
);
769 * regexec and friends
773 * Global work variables for regexec().
775 static const char *reginput
; /* String-input pointer. */
776 static const char *regbol
; /* Beginning of input, for ^ check. */
777 static const char **regstartp
; /* Pointer to startp array. */
778 static const char **regendp
; /* Ditto for endp. */
783 STATIC
int regtry( regexp
*prog
, const char *string
);
784 STATIC
int regmatch( char *prog
);
785 STATIC
int regrepeat( char *p
);
790 STATIC
char *regprop();
794 - regexec - match a regexp against a string
804 if (prog
== NULL
|| string
== NULL
) {
805 regerror("NULL parameter");
809 /* Check validity of program. */
810 if (UCHARAT(prog
->program
) != MAGIC
) {
811 regerror("corrupted program");
815 /* If there is a "must appear" string, look for it. */
816 if ( prog
->regmust
!= NULL
)
819 while ( ( s
= strchr( s
, prog
->regmust
[ 0 ] ) ) != NULL
)
821 if ( !strncmp( s
, prog
->regmust
, prog
->regmlen
) )
822 break; /* Found it. */
825 if ( s
== NULL
) /* Not present. */
829 /* Mark beginning of line for ^ . */
830 regbol
= (char *)string
;
832 /* Simplest case: anchored match need be tried only once. */
834 return regtry( prog
, string
);
836 /* Messy cases: unanchored match. */
838 if (prog
->regstart
!= '\0')
839 /* We know what char it must start with. */
840 while ((s
= strchr(s
, prog
->regstart
)) != NULL
) {
846 /* We do not -- general case. */
848 if ( regtry( prog
, s
) )
850 } while ( *s
++ != '\0' );
858 * regtry() - try match at specific point.
861 static int /* 0 failure, 1 success */
871 regstartp
= prog
->startp
;
872 regendp
= prog
->endp
;
876 for ( i
= NSUBEXP
; i
> 0; --i
)
881 if ( regmatch( prog
->program
+ 1 ) )
883 prog
->startp
[ 0 ] = string
;
884 prog
->endp
[ 0 ] = reginput
;
893 * regmatch() - main matching routine.
895 * Conceptually the strategy is simple: check to see whether the current node
896 * matches, call self recursively to see whether the rest matches, and then act
897 * accordingly. In practice we make some effort to avoid recursion, in
898 * particular by going through "ordinary" nodes (that do not need to know
899 * whether the rest of the match failed) by a loop instead of by recursion.
902 static int /* 0 failure, 1 success */
903 regmatch( char * prog
)
905 char * scan
; /* Current node. */
906 char * next
; /* Next node. */
910 if (scan
!= NULL
&& regnarrate
)
911 err_printf("%s(\n", regprop(scan
));
913 while (scan
!= NULL
) {
916 err_printf("%s...\n", regprop(scan
));
918 next
= regnext(scan
);
922 if (reginput
!= regbol
)
926 if (*reginput
!= '\0')
930 /* Must be looking at a letter, digit, or _ */
931 if ((!isalnum(*reginput
)) && *reginput
!= '_')
933 /* Prev must be BOL or nonword */
934 if (reginput
> regbol
&&
935 (isalnum(reginput
[-1]) || reginput
[-1] == '_'))
939 /* Must be looking at non letter, digit, or _ */
940 if (isalnum(*reginput
) || *reginput
== '_')
942 /* We don't care what the previous char was */
945 if (*reginput
== '\0')
953 opnd
= OPERAND(scan
);
954 /* Inline the first character, for speed. */
955 if (*opnd
!= *reginput
)
958 if (len
> 1 && strncmp(opnd
, reginput
, len
) != 0)
964 if (*reginput
== '\0' || strchr(OPERAND(scan
), *reginput
) == NULL
)
969 if (*reginput
== '\0' || strchr(OPERAND(scan
), *reginput
) != NULL
)
989 no
= OP(scan
) - OPEN
;
992 if (regmatch(next
)) {
994 * Don't set startp if some later
995 * invocation of the same parentheses
998 if (regstartp
[no
] == NULL
)
999 regstartp
[no
] = save
;
1017 no
= OP(scan
) - CLOSE
;
1020 if (regmatch(next
)) {
1022 * Don't set endp if some later
1023 * invocation of the same parentheses
1026 if (regendp
[no
] == NULL
)
1036 if (OP(next
) != BRANCH
) /* No choice. */
1037 next
= OPERAND(scan
); /* Avoid recursion. */
1041 if (regmatch(OPERAND(scan
)))
1044 scan
= regnext(scan
);
1045 } while (scan
!= NULL
&& OP(scan
) == BRANCH
);
1059 * Lookahead to avoid useless match attempts
1060 * when we know what character comes next.
1063 if (OP(next
) == EXACTLY
)
1064 nextch
= *OPERAND(next
);
1065 min
= (OP(scan
) == STAR
) ? 0 : 1;
1067 no
= regrepeat(OPERAND(scan
));
1069 /* If it could work, try it. */
1070 if (nextch
== '\0' || *reginput
== nextch
)
1073 /* Couldn't or didn't -- back up. */
1075 reginput
= save
+ no
;
1081 return(1); /* Success! */
1084 regerror("memory corruption");
1093 * We get here only if there's trouble -- normally "case END" is
1094 * the terminating point.
1096 regerror("corrupted pointers");
1101 - regrepeat - repeatedly match something simple, report how many
1104 regrepeat( char *p
)
1114 count
= strlen(scan
);
1118 while (*opnd
== *scan
) {
1124 while (*scan
!= '\0' && strchr(opnd
, *scan
) != NULL
) {
1130 while (*scan
!= '\0' && strchr(opnd
, *scan
) == NULL
) {
1135 default: /* Oh dear. Called inappropriately. */
1136 regerror("internal foulup");
1137 count
= 0; /* Best compromise. */
1146 - regnext - dig the "next" pointer out of a node
1168 STATIC
char *regprop();
1171 - regdump - dump a regexp onto stdout in vaguely comprehensible form
1174 regdump( regexp
*r
)
1177 char op
= EXACTLY
; /* Arbitrary non-END op. */
1182 while (op
!= END
) { /* While that wasn't END last time... */
1184 out_printf("%2d%s", s
-r
->program
, regprop(s
)); /* Where, what. */
1186 if (next
== NULL
) /* Next ptr. */
1189 out_printf("(%d)", (s
-r
->program
)+(next
-s
));
1191 if (op
== ANYOF
|| op
== ANYBUT
|| op
== EXACTLY
) {
1192 /* Literal string, where present. */
1193 while (*s
!= '\0') {
1202 /* Header fields of interest. */
1203 if (r
->regstart
!= '\0')
1204 out_printf("start `%c' ", r
->regstart
);
1206 out_printf("anchored ");
1207 if (r
->regmust
!= NULL
)
1208 out_printf("must have \"%s\"", r
->regmust
);
1213 - regprop - printable representation of opcode
1219 static char buf
[50];
1221 (void) strcpy(buf
, ":");
1263 sprintf(buf
+strlen(buf
), "OPEN%d", OP(op
)-OPEN
);
1275 sprintf(buf
+strlen(buf
), "CLOSE%d", OP(op
)-CLOSE
);
1291 regerror("corrupted opcode");
1295 (void) strcat(buf
, p
);
1301 * The following is provided for those people who do not have strcspn() in
1302 * their C libraries. They should get off their butts and do something
1303 * about it; at least one public-domain implementation of those (highly
1304 * useful) string routines has been published on Usenet.
1308 * strcspn - find length of initial segment of s1 consisting entirely
1309 * of characters not from s2
1322 for (scan1
= s1
; *scan1
!= '\0'; scan1
++) {
1323 for (scan2
= s2
; *scan2
!= '\0';) /* ++ moved down. */
1324 if (*scan1
== *scan2
++)