CVS commit: src/usr.bin/comm
Module Name:src Committed By: simonb Date: Wed Sep 5 04:01:23 UTC 2012 Modified Files: src/usr.bin/comm: comm.c Log Message: Use getc instead of fgetc. This is approximately five times faster for "comm -23 a b" where a and b are identical 100MB files. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/usr.bin/comm/comm.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/comm/comm.c diff -u src/usr.bin/comm/comm.c:1.19 src/usr.bin/comm/comm.c:1.20 --- src/usr.bin/comm/comm.c:1.19 Tue Aug 30 21:36:38 2011 +++ src/usr.bin/comm/comm.c Wed Sep 5 04:01:23 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: comm.c,v 1.19 2011/08/30 21:36:38 joerg Exp $ */ +/* $NetBSD: comm.c,v 1.20 2012/09/05 04:01:23 simonb Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 #if 0 static char sccsid[] = "@(#)comm.c 8.4 (Berkeley) 5/4/95"; #endif -__RCSID("$NetBSD: comm.c,v 1.19 2011/08/30 21:36:38 joerg Exp $"); +__RCSID("$NetBSD: comm.c,v 1.20 2012/09/05 04:01:23 simonb Exp $"); #endif /* not lint */ #include @@ -197,7 +197,7 @@ getnextln(char *buf, FILE *fp) size_t i = 0; int c; - while ((c = fgetc(fp)) != '\n' && c != EOF) { + while ((c = getc(fp)) != '\n' && c != EOF) { buf[i++] = c; if (i >= MAXLINELEN)
CVS commit: src/usr.bin/comm
Module Name:src Committed By: joerg Date: Tue Aug 30 21:36:38 UTC 2011 Modified Files: src/usr.bin/comm: comm.c Log Message: static + __dead To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/usr.bin/comm/comm.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/comm/comm.c diff -u src/usr.bin/comm/comm.c:1.18 src/usr.bin/comm/comm.c:1.19 --- src/usr.bin/comm/comm.c:1.18 Sat Nov 28 03:56:38 2009 +++ src/usr.bin/comm/comm.c Tue Aug 30 21:36:38 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: comm.c,v 1.18 2009/11/28 03:56:38 darcy Exp $ */ +/* $NetBSD: comm.c,v 1.19 2011/08/30 21:36:38 joerg Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)comm.c 8.4 (Berkeley) 5/4/95"; #endif -__RCSID("$NetBSD: comm.c,v 1.18 2009/11/28 03:56:38 darcy Exp $"); +__RCSID("$NetBSD: comm.c,v 1.19 2011/08/30 21:36:38 joerg Exp $"); #endif /* not lint */ #include @@ -55,12 +55,12 @@ #define MAXLINELEN (LINE_MAX + 1) -const char *tabs[] = { "", "\t", "\t\t" }; +static const char *tabs[] = { "", "\t", "\t\t" }; -FILE *file(const char *); -void show(FILE *, const char *, char *); -void usage(void); -char *getnextln(char *buf, FILE *); +static FILE *file(const char *); +static void show(FILE *, const char *, char *); +__dead static void usage(void); +static char *getnextln(char *buf, FILE *); int main(int argc, char **argv) @@ -164,14 +164,14 @@ exit(0); } -void +static void show(FILE *fp, const char *offset, char *buf) { while (printf("%s%s\n", offset, buf) >= 0 && getnextln(buf, fp)) ; } -FILE * +static FILE * file(const char *name) { FILE *fp; @@ -183,7 +183,7 @@ return (fp); } -void +static void usage(void) { @@ -191,7 +191,7 @@ exit(1); } -char * +static char * getnextln(char *buf, FILE *fp) { size_t i = 0;
CVS commit: src/usr.bin/comm
Module Name:src Committed By: darcy Date: Sat Nov 28 03:56:38 UTC 2009 Modified Files: src/usr.bin/comm: comm.c Log Message: Don't include newlines when comparing to prevent errors when lines have characters that sort lower such as tabs. This is a temporary fix to allow pullups to existing, supported versions of NetBSD. I will follow up with a version for current using the new getline function. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/comm/comm.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/comm/comm.c diff -u src/usr.bin/comm/comm.c:1.17 src/usr.bin/comm/comm.c:1.18 --- src/usr.bin/comm/comm.c:1.17 Sat Apr 11 12:18:45 2009 +++ src/usr.bin/comm/comm.c Sat Nov 28 03:56:38 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: comm.c,v 1.17 2009/04/11 12:18:45 lukem Exp $ */ +/* $NetBSD: comm.c,v 1.18 2009/11/28 03:56:38 darcy Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)comm.c 8.4 (Berkeley) 5/4/95"; #endif -__RCSID("$NetBSD: comm.c,v 1.17 2009/04/11 12:18:45 lukem Exp $"); +__RCSID("$NetBSD: comm.c,v 1.18 2009/11/28 03:56:38 darcy Exp $"); #endif /* not lint */ #include @@ -60,6 +60,7 @@ FILE *file(const char *); void show(FILE *, const char *, char *); void usage(void); +char *getnextln(char *buf, FILE *); int main(int argc, char **argv) @@ -116,9 +117,9 @@ for (read1 = read2 = 1;;) { /* read next line, check for EOF */ if (read1) - file1done = !fgets(line1, MAXLINELEN, fp1); + file1done = !getnextln(line1, fp1); if (read2) - file2done = !fgets(line2, MAXLINELEN, fp2); + file2done = !getnextln(line2, fp2); /* if one file done, display the rest of the other file */ if (file1done) { @@ -136,7 +137,7 @@ if (!(comp = compare(line1, line2))) { read1 = read2 = 1; if (col3) -if (printf("%s%s", col3, line1) < 0) +if (printf("%s%s\n", col3, line1) < 0) break; continue; } @@ -146,13 +147,13 @@ read1 = 1; read2 = 0; if (col1) -if (printf("%s%s", col1, line1) < 0) +if (printf("%s%s\n", col1, line1) < 0) break; } else { read1 = 0; read2 = 1; if (col2) -if (printf("%s%s", col2, line2) < 0) +if (printf("%s%s\n", col2, line2) < 0) break; } } @@ -166,7 +167,7 @@ void show(FILE *fp, const char *offset, char *buf) { - while (printf("%s%s", offset, buf) >= 0 && fgets(buf, MAXLINELEN, fp)) + while (printf("%s%s\n", offset, buf) >= 0 && getnextln(buf, fp)) ; } @@ -189,3 +190,24 @@ (void)fprintf(stderr, "usage: comm [-123f] file1 file2\n"); exit(1); } + +char * +getnextln(char *buf, FILE *fp) +{ + size_t i = 0; + int c; + + while ((c = fgetc(fp)) != '\n' && c != EOF) { + buf[i++] = c; + + if (i >= MAXLINELEN) + i--; /* consumes extra characters till newline */ + } + + if (c == EOF && !i) + return NULL; + + buf[i] = 0; + return buf; +} +
CVS commit: src/usr.bin/comm
Module Name:src Committed By: lukem Date: Sat Apr 11 12:18:45 UTC 2009 Modified Files: src/usr.bin/comm: comm.c Log Message: fix -Wcast-qual issues for WARNS=4 To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/usr.bin/comm/comm.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/comm/comm.c diff -u src/usr.bin/comm/comm.c:1.16 src/usr.bin/comm/comm.c:1.17 --- src/usr.bin/comm/comm.c:1.16 Mon Jul 21 14:19:22 2008 +++ src/usr.bin/comm/comm.c Sat Apr 11 12:18:45 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: comm.c,v 1.16 2008/07/21 14:19:22 lukem Exp $ */ +/* $NetBSD: comm.c,v 1.17 2009/04/11 12:18:45 lukem Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)comm.c 8.4 (Berkeley) 5/4/95"; #endif -__RCSID("$NetBSD: comm.c,v 1.16 2008/07/21 14:19:22 lukem Exp $"); +__RCSID("$NetBSD: comm.c,v 1.17 2009/04/11 12:18:45 lukem Exp $"); #endif /* not lint */ #include @@ -55,10 +55,10 @@ #define MAXLINELEN (LINE_MAX + 1) -char *tabs[] = { "", "\t", "\t\t" }; +const char *tabs[] = { "", "\t", "\t\t" }; FILE *file(const char *); -void show(FILE *, char *, char *); +void show(FILE *, const char *, char *); void usage(void); int @@ -67,8 +67,8 @@ int comp, file1done, file2done, read1, read2; int ch, flag1, flag2, flag3; FILE *fp1, *fp2; - char *col1, *col2, *col3; - char **p, line1[MAXLINELEN], line2[MAXLINELEN]; + const char *col1, *col2, *col3, **p; + char line1[MAXLINELEN], line2[MAXLINELEN]; int (*compare)(const char*,const char*); (void)setlocale(LC_ALL, ""); @@ -164,7 +164,7 @@ } void -show(FILE *fp, char *offset, char *buf) +show(FILE *fp, const char *offset, char *buf) { while (printf("%s%s", offset, buf) >= 0 && fgets(buf, MAXLINELEN, fp)) ;