CVS commit: src/usr.bin/comm

2012-09-04 Thread Simon Burge
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 err.h
@@ -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

2011-08-30 Thread Joerg Sonnenberger
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 err.h
@@ -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

2009-11-27 Thread D'Arcy J.M. Cain
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 err.h
@@ -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;
+}
+