Small formatting cleanups in b.c.

This commit is contained in:
Arnold D. Robbins 2020-01-01 22:42:50 +02:00
parent 3358f3f36b
commit 140802c128
2 changed files with 9 additions and 7 deletions

View File

@ -2,6 +2,7 @@
* tran.c (syminit, arginit, envinit): Free sval member before * tran.c (syminit, arginit, envinit): Free sval member before
setting it. Thanks to valgrind. setting it. Thanks to valgrind.
* b.c: Small formatting cleanups in several routines.
2019-12-27 Arnold D. Robbins <arnold@skeeve.com> 2019-12-27 Arnold D. Robbins <arnold@skeeve.com>

15
b.c
View File

@ -180,7 +180,7 @@ fa *makedfa(const char *s, bool anchor) /* returns dfa for reg expr s */
} }
fa *mkdfa(const char *s, bool anchor) /* does the real work of making a dfa */ fa *mkdfa(const char *s, bool anchor) /* does the real work of making a dfa */
/* anchor = 1 for anchored matches, else 0 */ /* anchor = true for anchored matches, else false */
{ {
Node *p, *p1; Node *p, *p1;
fa *f; fa *f;
@ -223,17 +223,17 @@ int makeinit(fa *f, bool anchor)
k = *(f->re[0].lfollow); k = *(f->re[0].lfollow);
xfree(f->posns[2]); xfree(f->posns[2]);
f->posns[2] = intalloc(k + 1, __func__); f->posns[2] = intalloc(k + 1, __func__);
for (i=0; i <= k; i++) { for (i = 0; i <= k; i++) {
(f->posns[2])[i] = (f->re[0].lfollow)[i]; (f->posns[2])[i] = (f->re[0].lfollow)[i];
} }
if ((f->posns[2])[1] == f->accept) if ((f->posns[2])[1] == f->accept)
f->out[2] = 1; f->out[2] = 1;
for (i=0; i < NCHARS; i++) for (i = 0; i < NCHARS; i++)
f->gototab[2][i] = 0; f->gototab[2][i] = 0;
f->curstat = cgoto(f, 2, HAT); f->curstat = cgoto(f, 2, HAT);
if (anchor) { if (anchor) {
*f->posns[2] = k-1; /* leave out position 0 */ *f->posns[2] = k-1; /* leave out position 0 */
for (i=0; i < k; i++) { for (i = 0; i < k; i++) {
(f->posns[0])[i] = (f->posns[2])[i]; (f->posns[0])[i] = (f->posns[2])[i];
} }
@ -463,9 +463,10 @@ int first(Node *p) /* collects initially active leaves of p into setvec */
} }
if (type(p) == CCL && (*(char *) right(p)) == '\0') if (type(p) == CCL && (*(char *) right(p)) == '\0')
return(0); /* empty CCL */ return(0); /* empty CCL */
else return(1); return(1);
case PLUS: case PLUS:
if (first(left(p)) == 0) return(0); if (first(left(p)) == 0)
return(0);
return(1); return(1);
case STAR: case STAR:
case QUEST: case QUEST:
@ -714,7 +715,7 @@ bool fnematch(fa *pfa, FILE *f, char **pbuf, int *pbufsize, int quantum)
if (buf[--k] && ungetc(buf[k], f) == EOF) if (buf[--k] && ungetc(buf[k], f) == EOF)
FATAL("unable to ungetc '%c'", buf[k]); FATAL("unable to ungetc '%c'", buf[k]);
while (k > i + patlen); while (k > i + patlen);
buf[k] = 0; buf[k] = '\0';
return true; return true;
} }
else else