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.
31 * Beware that some of this code is subtly aware of the way operator
32 * precedence is structured in regular expressions. Serious changes in
33 * regular-expression syntax might require a total rethink.
45 * The "internal use only" fields in regexp.h are present to pass info from
46 * compile to execute that permits the execute phase to run lots faster on
47 * simple cases. They are:
49 * regstart char that must begin a match; '\0' if none obvious
50 * reganch is the match anchored (at beginning-of-line only)?
51 * regmust string (pointer into program) that match must include, or NULL
52 * regmlen length of regmust string
54 * Regstart and reganch permit very fast decisions on suitable starting points
55 * for a match, cutting down the work a lot. Regmust permits fast rejection
56 * of lines that cannot possibly match. The regmust tests are costly enough
57 * that regcomp() supplies a regmust only if the r.e. contains something
58 * potentially expensive (at present, the only such thing detected is * or +
59 * at the start of the r.e., which can involve a lot of backup). Regmlen is
60 * supplied because the test in regexec() needs it and regcomp() is computing
65 * Structure for regexp "program". This is essentially a linear encoding
66 * of a nondeterministic finite-state machine (aka syntax charts or
67 * "railroad normal form" in parsing technology). Each node is an opcode
68 * plus a "next" pointer, possibly plus an operand. "Next" pointers of
69 * all nodes except BRANCH implement concatenation; a "next" pointer with
70 * a BRANCH on both ends of it is connecting two alternatives. (Here we
71 * have one of the subtle syntax dependencies: an individual BRANCH (as
72 * opposed to a collection of them) is never concatenated with anything
73 * because of operator precedence.) The operand of some types of node is
74 * a literal string; for others, it is a node leading into a sub-FSM. In
75 * particular, the operand of a BRANCH node is the first node of the branch.
76 * (NB this is *not* a tree structure: the tail of the branch connects
77 * to the thing following the set of BRANCHes.) The opcodes are:
80 /* definition number opnd? meaning */
81 #define END 0 /* no End of program. */
82 #define BOL 1 /* no Match "" at beginning of line. */
83 #define EOL 2 /* no Match "" at end of line. */
84 #define ANY 3 /* no Match any one character. */
85 #define ANYOF 4 /* str Match any character in this string. */
86 #define ANYBUT 5 /* str Match any character not in this string. */
87 #define BRANCH 6 /* node Match this alternative, or the next... */
88 #define BACK 7 /* no Match "", "next" ptr points backward. */
89 #define EXACTLY 8 /* str Match this string. */
90 #define NOTHING 9 /* no Match empty string. */
91 #define STAR 10 /* node Match this (simple) thing 0 or more times. */
92 #define PLUS 11 /* node Match this (simple) thing 1 or more times. */
93 #define WORDA 12 /* no Match "" at wordchar, where prev is nonword */
94 #define WORDZ 13 /* no Match "" at nonwordchar, where prev is word */
95 #define OPEN 20 /* no Mark this point in input as start of #n. */
96 /* OPEN+1 is number 1, etc. */
97 #define CLOSE 30 /* no Analogous to OPEN. */
102 * BRANCH The set of branches constituting a single choice are hooked
103 * together with their "next" pointers, since precedence prevents
104 * anything being concatenated to any individual branch. The
105 * "next" pointer of the last BRANCH in a choice points to the
106 * thing following the whole choice. This is also where the
107 * final "next" pointer of each individual branch points; each
108 * branch starts with the operand node of a BRANCH node.
110 * BACK Normal "next" pointers all implicitly point forward; BACK
111 * exists to make loop structures possible.
113 * STAR,PLUS '?', and complex '*' and '+', are implemented as circular
114 * BRANCH structures using BACK. Simple cases (one character
115 * per match) are implemented with STAR and PLUS for speed
116 * and to minimize recursive plunges.
118 * OPEN,CLOSE ...are numbered at compile time.
122 * A node is one char of opcode followed by two chars of "next" pointer.
123 * "Next" pointers are stored as two 8-bit pieces, high order first. The
124 * value is a positive offset from the opcode of the node containing it.
125 * An operand, if any, simply follows the node. (Note that much of the
126 * code generation knows about this implicit relationship.)
128 * Using two bytes for the "next" pointer is vast overkill for most things,
129 * but allows patterns to get big without disasters.
132 #define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))
133 #define OPERAND(p) ((p) + 3)
136 * See regmagic.h for one further detail of program structure.
141 * Utility definitions.
144 #define UCHARAT(p) ((int)*(unsigned char *)(p))
146 #define UCHARAT(p) ((int)*(p)&CHARBITS)
149 #define FAIL(m) { regerror(m); return(NULL); }
150 #define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?')
153 * Flags to be passed up and down.
155 #define HASWIDTH 01 /* Known never to match null string. */
156 #define SIMPLE 02 /* Simple enough to be STAR/PLUS operand. */
157 #define SPSTART 04 /* Starts with * or +. */
158 #define WORST 0 /* Worst case. */
161 * Global work variables for regcomp().
163 static char *regparse; /* Input-scan pointer. */
164 static int regnpar; /* () count. */
165 static char regdummy;
166 static char *regcode; /* Code-emit pointer; ®dummy = don't. */
167 static long regsize; /* Code size. */
170 * Forward declarations for regcomp()'s friends.
173 #define STATIC static
176 STATIC char *regbranch();
177 STATIC char *regpiece();
178 STATIC char *regatom();
179 STATIC char *regnode();
180 STATIC char *regnext();
182 STATIC void reginsert();
183 STATIC void regtail();
184 STATIC void regoptail();
186 STATIC int strcspn();
190 - regcomp - compile a regular expression into internal code
192 * We can't allocate space until we know how big the compiled form will be,
193 * but we can't compile it (and thus know how big it is) until we've got a
194 * place to put the code. So we cheat: we compile it twice, once with code
195 * generation turned off and size counting turned on, and once "for real".
196 * This also means that we don't allocate space until we are sure that the
197 * thing really will compile successfully, and we never have to move the
198 * code and thus invalidate pointers into it. (Note that it has to be in
199 * one piece because free() must be able to free it all.)
201 * Beware that the optimization-preparation code in here knows about some
202 * of the structure of the compiled regexp.
210 register char *longest;
215 FAIL("NULL argument");
217 /* First pass: determine size, legality. */
219 if (exp[0] == '.' && exp[1] == '*') exp += 2; /* aid grep */
221 regparse = (char *)exp;
226 if (reg(0, &flags) == NULL)
229 /* Small enough for pointer-storage convention? */
230 if (regsize >= 32767L) /* Probably could be 65535L. */
231 FAIL("regexp too big");
233 /* Allocate space. */
234 r = (regexp *)malloc(sizeof(regexp) + (unsigned)regsize);
236 FAIL("out of space");
238 /* Second pass: emit code. */
239 regparse = (char *)exp;
241 regcode = r->program;
243 if (reg(0, &flags) == NULL)
246 /* Dig out information for optimizations. */
247 r->regstart = '\0'; /* Worst-case defaults. */
251 scan = r->program+1; /* First BRANCH. */
252 if (OP(regnext(scan)) == END) { /* Only one top-level choice. */
253 scan = OPERAND(scan);
255 /* Starting-point info. */
256 if (OP(scan) == EXACTLY)
257 r->regstart = *OPERAND(scan);
258 else if (OP(scan) == BOL)
262 * If there's something expensive in the r.e., find the
263 * longest literal string that must appear and make it the
264 * regmust. Resolve ties in favor of later strings, since
265 * the regstart check works with the beginning of the r.e.
266 * and avoiding duplication strengthens checking. Not a
267 * strong reason, but sufficient in the absence of others.
272 for (; scan != NULL; scan = regnext(scan))
273 if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) {
274 longest = OPERAND(scan);
275 len = strlen(OPERAND(scan));
277 r->regmust = longest;
286 - reg - regular expression, i.e. main body or parenthesized thing
288 * Caller must absorb opening parenthesis.
290 * Combining parenthesis handling with the base level of regular expression
291 * is a trifle forced, but the need to tie the tails of the branches to what
292 * follows makes it hard to avoid.
296 int paren; /* Parenthesized? */
301 register char *ender;
305 *flagp = HASWIDTH; /* Tentatively. */
307 /* Make an OPEN node, if parenthesized. */
309 if (regnpar >= NSUBEXP)
313 ret = regnode(OPEN+parno);
317 /* Pick up the branches, linking them together. */
318 br = regbranch(&flags);
322 regtail(ret, br); /* OPEN -> first. */
325 if (!(flags&HASWIDTH))
327 *flagp |= flags&SPSTART;
328 while (*regparse == '|' || *regparse == '\n') {
330 br = regbranch(&flags);
333 regtail(ret, br); /* BRANCH -> BRANCH. */
334 if (!(flags&HASWIDTH))
336 *flagp |= flags&SPSTART;
339 /* Make a closing node, and hook it on the end. */
340 ender = regnode((paren) ? CLOSE+parno : END);
343 /* Hook the tails of the branches to the closing node. */
344 for (br = ret; br != NULL; br = regnext(br))
345 regoptail(br, ender);
347 /* Check for proper termination. */
348 if (paren && *regparse++ != ')') {
349 FAIL("unmatched ()");
350 } else if (!paren && *regparse != '\0') {
351 if (*regparse == ')') {
352 FAIL("unmatched ()");
354 FAIL("junk on end"); /* "Can't happen". */
362 - regbranch - one alternative of an | operator
364 * Implements the concatenation operator.
371 register char *chain;
372 register char *latest;
375 *flagp = WORST; /* Tentatively. */
377 ret = regnode(BRANCH);
379 while (*regparse != '\0' && *regparse != ')' &&
380 *regparse != '\n' && *regparse != '|') {
381 latest = regpiece(&flags);
384 *flagp |= flags&HASWIDTH;
385 if (chain == NULL) /* First piece. */
386 *flagp |= flags&SPSTART;
388 regtail(chain, latest);
391 if (chain == NULL) /* Loop ran zero times. */
392 (void) regnode(NOTHING);
398 - regpiece - something followed by possible [*+?]
400 * Note that the branching code sequences used for ? and the general cases
401 * of * and + are somewhat optimized: they use the same NOTHING node as
402 * both the endmarker for their branch list and the body of the last branch.
403 * It might seem that this node could be dispensed with entirely, but the
404 * endmarker role is not redundant.
415 ret = regatom(&flags);
425 if (!(flags&HASWIDTH) && op != '?')
426 FAIL("*+ operand could be empty");
427 *flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH);
429 if (op == '*' && (flags&SIMPLE))
430 reginsert(STAR, ret);
431 else if (op == '*') {
432 /* Emit x* as (x&|), where & means "self". */
433 reginsert(BRANCH, ret); /* Either x */
434 regoptail(ret, regnode(BACK)); /* and loop */
435 regoptail(ret, ret); /* back */
436 regtail(ret, regnode(BRANCH)); /* or */
437 regtail(ret, regnode(NOTHING)); /* null. */
438 } else if (op == '+' && (flags&SIMPLE))
439 reginsert(PLUS, ret);
440 else if (op == '+') {
441 /* Emit x+ as x(&|), where & means "self". */
442 next = regnode(BRANCH); /* Either */
444 regtail(regnode(BACK), ret); /* loop back */
445 regtail(next, regnode(BRANCH)); /* or */
446 regtail(ret, regnode(NOTHING)); /* null. */
447 } else if (op == '?') {
448 /* Emit x? as (x|) */
449 reginsert(BRANCH, ret); /* Either x */
450 regtail(ret, regnode(BRANCH)); /* or */
451 next = regnode(NOTHING); /* null. */
453 regoptail(ret, next);
456 if (ISMULT(*regparse))
463 - regatom - the lowest level
465 * Optimization: gobbles an entire sequence of ordinary characters so that
466 * it can turn them into a single node, which is smaller to store and
467 * faster to run. Backslashed characters are exceptions, each becoming a
468 * separate node; the code is simpler that way and it's not worth fixing.
477 *flagp = WORST; /* Tentatively. */
479 switch (*regparse++) {
480 /* FIXME: these chars only have meaning at beg/end of pat? */
489 *flagp |= HASWIDTH|SIMPLE;
493 register int classend;
496 if (*regparse == '^') { /* Complement of range. */
497 ret = regnode(ANYBUT);
500 ret = regnode(ANYOF);
501 if (*regparse == ']' || *regparse == '-')
503 while (*regparse != '\0' && *regparse != ']') {
504 if (*regparse == '-') {
506 if (*regparse == ']' || *regparse == '\0')
509 class = UCHARAT(regparse-2);
510 classend = UCHARAT(regparse);
511 if (__collate_load_error) {
512 if (class > classend)
513 FAIL("invalid [] range");
514 for (class++; class <= classend; class++)
517 if (__collate_range_cmp(class, classend) > 0)
518 FAIL("invalid [] range");
519 for (i = 0; i <= UCHAR_MAX; i++)
521 && __collate_range_cmp(class, i) <= 0
522 && __collate_range_cmp(i, classend) <= 0
532 if (*regparse != ']')
533 FAIL("unmatched []");
535 *flagp |= HASWIDTH|SIMPLE;
539 ret = reg(1, &flags);
542 *flagp |= flags&(HASWIDTH|SPSTART);
548 FAIL("internal urp"); /* Supposed to be caught earlier. */
553 FAIL("?+* follows nothing");
556 switch (*regparse++) {
561 ret = regnode(WORDA);
564 ret = regnode(WORDZ);
566 /* FIXME: Someday handle \1, \2, ... */
568 /* Handle general quoted chars in exact-match routine */
575 * Encode a string of characters to be matched exactly.
577 * This is a bit tricky due to quoted chars and due to
578 * '*', '+', and '?' taking the SINGLE char previous
581 * On entry, the char at regparse[-1] is going to go
582 * into the string, no matter what it is. (It could be
583 * following a \ if we are entered from the '\' case.)
585 * Basic idea is to pick up a good char in ch and
586 * examine the next char. If it's *+? then we twiddle.
587 * If it's \ then we frozzle. If it's other magic char
588 * we push ch and terminate the string. If none of the
589 * above, we push ch on the string and go around again.
591 * regprev is used to remember where "the current char"
592 * starts in the string, if due to a *+? we need to back
593 * up and put the current char in a separate, 1-char, string.
594 * When regprev is NULL, ch is the only char in the
595 * string; this is used in *+? handling, and in setting
596 * flags |= SIMPLE at the end.
602 regparse--; /* Look at cur char */
603 ret = regnode(EXACTLY);
604 for ( regprev = 0 ; ; ) {
605 ch = *regparse++; /* Get current char */
606 switch (*regparse) { /* look at next one */
609 regc(ch); /* Add cur to string */
612 case '.': case '[': case '(':
613 case ')': case '|': case '\n':
616 /* FIXME, $ and ^ should not always be magic */
618 regc(ch); /* dump cur char */
619 goto done; /* and we are done */
621 case '?': case '+': case '*':
622 if (!regprev) /* If just ch in str, */
623 goto magic; /* use it */
624 /* End mult-char string one early */
625 regparse = regprev; /* Back up parse */
629 regc(ch); /* Cur char OK */
630 switch (regparse[1]){ /* Look after \ */
634 /* FIXME: Someday handle \1, \2, ... */
635 goto done; /* Not quoted */
637 /* Backup point is \, scan * point is after it. */
640 continue; /* NOT break; */
643 regprev = regparse; /* Set backup point */
648 if (!regprev) /* One char? */
658 - regnode - emit a node
660 static char * /* Location. */
668 if (ret == ®dummy) {
675 *ptr++ = '\0'; /* Null "next" pointer. */
683 - regc - emit (if appropriate) a byte of code
689 if (regcode != ®dummy)
696 - reginsert - insert an operator in front of already-emitted operand
698 * Means relocating the operand.
707 register char *place;
709 if (regcode == ®dummy) {
720 place = opnd; /* Op node, where operand used to be. */
727 - regtail - set the next-pointer at the end of a node chain
741 /* Find last node. */
744 temp = regnext(scan);
750 if (OP(scan) == BACK)
754 *(scan+1) = (offset>>8)&0377;
755 *(scan+2) = offset&0377;
759 - regoptail - regtail on operand of first argument; nop if operandless
766 /* "Operandless" and "op != BRANCH" are synonymous in practice. */
767 if (p == NULL || p == ®dummy || OP(p) != BRANCH)
769 regtail(OPERAND(p), val);
773 * regexec and friends
777 * Global work variables for regexec().
779 static char *reginput; /* String-input pointer. */
780 static char *regbol; /* Beginning of input, for ^ check. */
781 static char **regstartp; /* Pointer to startp array. */
782 static char **regendp; /* Ditto for endp. */
788 STATIC int regmatch();
789 STATIC int regrepeat();
794 STATIC char *regprop();
798 - regexec - match a regexp against a string
801 regexec(prog, string)
802 register const regexp *prog;
803 register const char *string;
806 extern char *strchr();
809 if (prog == NULL || string == NULL) {
810 regerror("NULL parameter");
814 /* Check validity of program. */
815 if (UCHARAT(prog->program) != MAGIC) {
816 regerror("corrupted program");
820 /* If there is a "must appear" string, look for it. */
821 if (prog->regmust != NULL) {
823 while ((s = strchr(s, prog->regmust[0])) != NULL) {
824 if (strncmp(s, prog->regmust, prog->regmlen) == 0)
825 break; /* Found it. */
828 if (s == NULL) /* Not present. */
832 /* Mark beginning of line for ^ . */
833 regbol = (char *)string;
835 /* Simplest case: anchored match need be tried only once. */
837 return(regtry(prog, string));
839 /* Messy cases: unanchored match. */
841 if (prog->regstart != '\0')
842 /* We know what char it must start with. */
843 while ((s = strchr(s, prog->regstart)) != NULL) {
849 /* We don't -- general case. */
853 } while (*s++ != '\0');
860 - regtry - try match at specific point
862 static int /* 0 failure, 1 success */
872 regstartp = prog->startp;
873 regendp = prog->endp;
877 for (i = NSUBEXP; i > 0; i--) {
881 if (regmatch(prog->program + 1)) {
882 prog->startp[0] = string;
883 prog->endp[0] = reginput;
890 - regmatch - main matching routine
892 * Conceptually the strategy is simple: check to see whether the current
893 * node matches, call self recursively to see whether the rest matches,
894 * and then act accordingly. In practice we make some effort to avoid
895 * recursion, in particular by going through "ordinary" nodes (that don't
896 * need to know whether the rest of the match failed) by a loop instead of
899 static int /* 0 failure, 1 success */
903 register char *scan; /* Current node. */
904 char *next; /* Next node. */
908 if (scan != NULL && regnarrate)
909 fprintf(stderr, "%s(\n", regprop(scan));
911 while (scan != NULL) {
914 fprintf(stderr, "%s...\n", regprop(scan));
916 next = regnext(scan);
920 if (reginput != regbol)
924 if (*reginput != '\0')
928 /* Must be looking at a letter, digit, or _ */
929 if ((!isalnum((unsigned char)*reginput)) && *reginput != '_')
931 /* Prev must be BOL or nonword */
932 if (reginput > regbol &&
933 (isalnum((unsigned char)reginput[-1]) || reginput[-1] == '_'))
937 /* Must be looking at non letter, digit, or _ */
938 if (isalnum((unsigned char)*reginput) || *reginput == '_')
940 /* We don't care what the previous char was */
943 if (*reginput == '\0')
951 opnd = OPERAND(scan);
952 /* Inline the first character, for speed. */
953 if (*opnd != *reginput)
956 if (len > 1 && strncmp(opnd, reginput, len) != 0)
962 if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) == NULL)
967 if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) != NULL)
987 no = OP(scan) - OPEN;
990 if (regmatch(next)) {
992 * Don't set startp if some later
993 * invocation of the same parentheses
996 if (regstartp[no] == NULL)
997 regstartp[no] = save;
1013 register char *save;
1015 no = OP(scan) - CLOSE;
1018 if (regmatch(next)) {
1020 * Don't set endp if some later
1021 * invocation of the same parentheses
1024 if (regendp[no] == NULL)
1032 register char *save;
1034 if (OP(next) != BRANCH) /* No choice. */
1035 next = OPERAND(scan); /* Avoid recursion. */
1039 if (regmatch(OPERAND(scan)))
1042 scan = regnext(scan);
1043 } while (scan != NULL && OP(scan) == BRANCH);
1051 register char nextch;
1053 register char *save;
1057 * Lookahead to avoid useless match attempts
1058 * when we know what character comes next.
1061 if (OP(next) == EXACTLY)
1062 nextch = *OPERAND(next);
1063 min = (OP(scan) == STAR) ? 0 : 1;
1065 no = regrepeat(OPERAND(scan));
1067 /* If it could work, try it. */
1068 if (nextch == '\0' || *reginput == nextch)
1071 /* Couldn't or didn't -- back up. */
1073 reginput = save + no;
1079 return(1); /* Success! */
1082 regerror("memory corruption");
1091 * We get here only if there's trouble -- normally "case END" is
1092 * the terminating point.
1094 regerror("corrupted pointers");
1099 - regrepeat - repeatedly match something simple, report how many
1105 register int count = 0;
1106 register char *scan;
1107 register char *opnd;
1113 count = strlen(scan);
1117 while (*opnd == *scan) {
1123 while (*scan != '\0' && strchr(opnd, *scan) != NULL) {
1129 while (*scan != '\0' && strchr(opnd, *scan) == NULL) {
1134 default: /* Oh dear. Called inappropriately. */
1135 regerror("internal foulup");
1136 count = 0; /* Best compromise. */
1145 - regnext - dig the "next" pointer out of a node
1151 register int offset;
1168 STATIC char *regprop();
1171 - regdump - dump a regexp onto stdout in vaguely comprehensible form
1178 register char op = EXACTLY; /* Arbitrary non-END op. */
1179 register char *next;
1180 extern char *strchr();
1184 while (op != END) { /* While that wasn't END last time... */
1186 printf("%2d%s", s-r->program, regprop(s)); /* Where, what. */
1188 if (next == NULL) /* Next ptr. */
1191 printf("(%d)", (s-r->program)+(next-s));
1193 if (op == ANYOF || op == ANYBUT || op == EXACTLY) {
1194 /* Literal string, where present. */
1195 while (*s != '\0') {
1204 /* Header fields of interest. */
1205 if (r->regstart != '\0')
1206 printf("start `%c' ", r->regstart);
1208 printf("anchored ");
1209 if (r->regmust != NULL)
1210 printf("must have \"%s\"", r->regmust);
1215 - regprop - printable representation of opcode
1222 static char buf[50];
1224 (void) strcpy(buf, ":");
1266 sprintf(buf+strlen(buf), "OPEN%d", OP(op)-OPEN);
1278 sprintf(buf+strlen(buf), "CLOSE%d", OP(op)-CLOSE);
1294 regerror("corrupted opcode");
1298 (void) strcat(buf, p);
1304 * The following is provided for those people who do not have strcspn() in
1305 * their C libraries. They should get off their butts and do something
1306 * about it; at least one public-domain implementation of those (highly
1307 * useful) string routines has been published on Usenet.
1311 * strcspn - find length of initial segment of s1 consisting entirely
1312 * of characters not from s2
1320 register char *scan1;
1321 register char *scan2;
1325 for (scan1 = s1; *scan1 != '\0'; scan1++) {
1326 for (scan2 = s2; *scan2 != '\0';) /* ++ moved down. */
1327 if (*scan1 == *scan2++)