From 6f0a860fc1e58338349173799291c963808faee9 Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Tue, 11 Mar 1997 13:45:59 +0000 Subject: [PATCH] Merge from Lite2 (note: needs checking by somebody who understands join) --- usr.bin/join/join.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/usr.bin/join/join.c b/usr.bin/join/join.c index a3efd7e2a2c..bc1f0743066 100644 --- a/usr.bin/join/join.c +++ b/usr.bin/join/join.c @@ -42,7 +42,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)join.c 8.3 (Berkeley) 4/16/94"; +static char sccsid[] = "@(#)join.c 8.6 (Berkeley) 5/4/95"; #endif /* not lint */ #include @@ -53,6 +53,7 @@ static char sccsid[] = "@(#)join.c 8.3 (Berkeley) 4/16/94"; #include #include #include +#include /* * There's a structure per input file which encapsulates the state of the @@ -288,6 +289,10 @@ slurp(F) F->setalloc * sizeof(LINE))) == NULL) err(1, NULL); memset(F->set + cnt, 0, 50 * sizeof(LINE)); + + /* re-set lastlp in case it moved */ + if (lastlp != NULL) + lastlp = &F->set[F->setcnt - 1]; } /* @@ -310,7 +315,7 @@ slurp(F) if ((bp = fgetln(F->fp, &len)) == NULL) return; if (lp->linealloc <= len + 1) { - lp->linealloc += MAX(100, len + 1); + lp->linealloc += MAX(100, len + 1 - lp->linealloc); if ((lp->line = realloc(lp->line, lp->linealloc)) == NULL) err(1, NULL); @@ -353,7 +358,7 @@ cmp(lp1, fieldno1, lp2, fieldno2) u_long fieldno1, fieldno2; { if (lp1->fieldcnt <= fieldno1) - return (lp2->fieldcnt < fieldno2 ? 0 : 1); + return (lp2->fieldcnt <= fieldno2 ? 0 : 1); if (lp2->fieldcnt <= fieldno2) return (-1); return (strcmp(lp1->fields[fieldno1], lp2->fields[fieldno2])); @@ -473,7 +478,7 @@ fieldarg(option) u_long fieldno; char *end, *token; - while ((token = strsep(&option, " \t")) != NULL) { + while ((token = strsep(&option, ", \t")) != NULL) { if (*token == '\0') continue; if (token[0] != '1' && token[0] != '2' || token[1] != '.')