at the ends of files. Discard waste.
SCCS-vsn: usr.bin/sort/sort.c 4.11
-static char *sccsid = "@(#)sort.c 4.10 (Berkeley) %G%";
+static char *sccsid = "@(#)sort.c 4.11 (Berkeley) %G%";
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
}
*lp++ = cp;
len = strlen(cp) + 1; /* null terminate */
}
*lp++ = cp;
len = strlen(cp) + 1; /* null terminate */
- if(cp[len - 2] != '\n') {
- diag("line too long (skipped): ", cp);
- while((c = getc(is)) != EOF && c != '\n')
- /* throw it away */;
- --lp;
- continue;
- }
+ if(cp[len - 2] != '\n')
+ if (len == L) {
+ diag("line too long (skipped): ", cp);
+ while((c=getc(is)) != EOF && c != '\n')
+ /* throw it away */;
+ --lp;
+ continue;
+ } else {
+ diag("missing newline before EOF in ",
+ f ? f : "standard input");
+ /* be friendly, append a newline */
+ ++len;
+ cp[len - 2] = '\n';
+ cp[len - 1] = '\0';
+ }
cp += len;
--lines;
text -= len;
cp += len;
--lines;
text -= len;
-#ifndef blank
-blank(c)
-{
- if(c==' ' || c=='\t')
- return(1);
- return(0);
-}
-#endif
-
#define qsexc(p,q) t= *p;*p= *q;*q=t
#define qstexc(p,q,r) t= *p;*p= *r;*r= *q;*q=t
#define qsexc(p,q) t= *p;*p= *q;*q=t
#define qstexc(p,q,r) t= *p;*p= *r;*r= *q;*q=t