Date: Tue, 12 Nov 1996 19:25:36 +0100 From: Wolfram Schneider <wosch@cs.tu-berlin.de> To: mark@linus.demon.co.uk (Mark Valentine), hackers@freebsd.org, Keith Bostic <bostic@cs.berkeley.edu> Subject: Re: cvs commit: src/share/doc/handbook porting.sgml ports.sgml Message-ID: <199611121825.TAA00674@campa.panke.de> In-Reply-To: <199611121304.OAA00453@campa.panke.de> References: <199611120404.EAA23202@janai.thuvia.org> <199611121304.OAA00453@campa.panke.de>
next in thread | previous in thread | raw e-mail | index | archive | help
Wolfram Schneider writes:
>>> Jordan K. Hubbard writes:
>>> >> I'm guessing sed, I thought Jordan had a disdain dislike for perl. :-)
>>> >
>>> >sed, definitely. I mean, who needs perl when you've already got
>>> >sed, sh and awk? :-)
>>>
>>> Perl is 8 bit clean and can edit binary data.
>>>
>>> $ wc /kernel
>>> 2379 24484 808608 /kernel
>>> $ perl -npe 's,/sbin/,/SBIN/,g' /kernel | wc
>>> 2379 24484 808608 /kernel
>>> $ sed 's,/sbin/,/SBIN/,g' /kernel | wc
>>> 67 753 29419
>>
>>$ wc /kernel
>> 3672 44913 1282638 /kernel
>>$ /usr/gnu/bin/sed 's,/sbin/,/SBIN/,g' /kernel | wc
>> 3672 44913 1282638
Ok, here is the patch. The problem occurs if a line *start*
with character '\377'. C beginners bug, getc() return
an int and not a char or unsigned char.
Index: main.c
===================================================================
RCS file: /usr/cvs/src/usr.bin/sed/main.c,v
retrieving revision 1.3
diff -u -r1.3 main.c
--- 1.3 1996/08/11 17:46:34
+++ main.c 1996/11/12 18:11:37
@@ -274,8 +274,7 @@
err(FATAL, "%s: %s",
fname, strerror(errno));
}
- if ((c = getc(f)) != EOF) {
- (void)ungetc(c, f);
+ if (!feof(f)) {
break;
}
(void)fclose(f);
@@ -299,7 +298,7 @@
linenum++;
/* Advance to next non-empty file */
- while ((c = getc(f)) == EOF) {
+ while (feof(f)) {
(void)fclose(f);
files = files->next;
if (files == NULL) {
@@ -315,7 +314,6 @@
err(FATAL, "%s: %s", fname, strerror(errno));
}
}
- (void)ungetc(c, f);
return (1);
}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199611121825.TAA00674>
