src/usr.bin/wc

Alexander 'alxl' Lobachov alxl at alxl.info
Sun Jan 9 12:53:06 PST 2005


Apply some style(9):
- Remove (void) casts
- Add some braces around somewhat complex blocks
- Don't treat *argv as boolean, compare it against NULL
- Add $DragonFly$ to Makefile
- Add WARNS 6 to Makefile

-- 
Alexander 'alxl' Lobachov	mailto:alxl at xxxxxxxxx
Index: src/usr.bin/wc/Makefile
===================================================================
RCS file: /home/cvs/DragonFly/src/usr.bin/wc/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- src/usr.bin/wc/Makefile	17 Jun 2003 02:56:34 -0000	1.1
+++ src/usr.bin/wc/Makefile	9 Jan 2005 20:44:39 -0000	1.2
@@ -1,5 +1,7 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
+# $DragonFly$
 
 PROG=	wc
+WARNS?=	6
 
 .include <bsd.prog.mk>
Index: src/usr.bin/wc/wc.c
===================================================================
RCS file: /home/cvs/DragonFly/src/usr.bin/wc/wc.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- src/usr.bin/wc/wc.c	4 Oct 2003 20:36:55 -0000	1.3
+++ src/usr.bin/wc/wc.c	9 Jan 2005 20:44:39 -0000	1.4
@@ -60,10 +60,10 @@
 {
 	int ch, errors, total;
 
-	(void) setlocale(LC_CTYPE, "");
+	setlocale(LC_CTYPE, "");
 
-	while ((ch = getopt(argc, argv, "clmw")) != -1)
-		switch((char)ch) {
+	while ((ch = getopt(argc, argv, "clmw")) != -1) {
+		switch ((char)ch) {
 		case 'l':
 			doline = 1;
 			break;
@@ -82,6 +82,7 @@
 		default:
 			usage();
 		}
+	}
 	argv += optind;
 	argc -= optind;
 
@@ -91,28 +92,28 @@
 
 	errors = 0;
 	total = 0;
-	if (!*argv) {
+	if (*argv == NULL) {
 		if (cnt((char *)NULL) != 0)
 			++errors;
 		else
-			(void)printf("\n");
+			printf("\n");
 	}
 	else do {
 		if (cnt(*argv) != 0)
 			++errors;
 		else
-			(void)printf(" %s\n", *argv);
+			printf(" %s\n", *argv);
 		++total;
 	} while(*++argv);
 
 	if (total > 1) {
 		if (doline)
-			(void)printf(" %7qu", tlinect);
+			printf(" %7qu", tlinect);
 		if (doword)
-			(void)printf(" %7qu", twordct);
+			printf(" %7qu", twordct);
 		if (dochar || domulti)
-			(void)printf(" %7qu", tcharct);
-		(void)printf(" total\n");
+			printf(" %7qu", tcharct);
+		printf(" total\n");
 	}
 	exit(errors == 0 ? 0 : 1);
 }
@@ -149,21 +150,22 @@
 			while ((len = read(fd, buf, MAXBSIZE))) {
 				if (len == -1) {
 					warn("%s: read", file);
-					(void)close(fd);
+					close(fd);
 					return (1);
 				}
 				charct += len;
-				for (p = buf; len--; ++p)
+				for (p = buf; len--; ++p) {
 					if (*p == '\n')
 						++linect;
+				}
 			}
 			tlinect += linect;
-			(void)printf(" %7qu", linect);
+			printf(" %7qu", linect);
 			if (dochar) {
 				tcharct += charct;
-				(void)printf(" %7qu", charct);
+				printf(" %7qu", charct);
 			}
-			(void)close(fd);
+			close(fd);
 			return (0);
 		}
 		/*
@@ -173,13 +175,13 @@
 		if (dochar || domulti) {
 			if (fstat(fd, &sb)) {
 				warn("%s: fstat", file);
-				(void)close(fd);
+				close(fd);
 				return (1);
 			}
 			if (S_ISREG(sb.st_mode)) {
-				(void)printf(" %7lld", (long long)sb.st_size);
+				printf(" %7lld", (long long)sb.st_size);
 				tcharct += sb.st_size;
-				(void)close(fd);
+				close(fd);
 				return (0);
 			}
 		}
@@ -192,7 +194,7 @@
 	while ((nread = read(fd, buf + len, MAXBSIZE - len)) != 0) {
 		if (nread == -1) {
 			warn("%s: read", file);
-			(void)close(fd);
+			close(fd);
 			return (1);
 		}
 		len += nread;
@@ -230,23 +232,23 @@
 	}
 	if (doline) {
 		tlinect += linect;
-		(void)printf(" %7qu", linect);
+		printf(" %7qu", linect);
 	}
 	if (doword) {
 		twordct += wordct;
-		(void)printf(" %7qu", wordct);
+		printf(" %7qu", wordct);
 	}
 	if (dochar || domulti) {
 		tcharct += charct;
-		(void)printf(" %7qu", charct);
+		printf(" %7qu", charct);
 	}
-	(void)close(fd);
+	close(fd);
 	return (0);
 }
 
 static void
 usage(void)
 {
-	(void)fprintf(stderr, "usage: wc [-clmw] [file ...]\n");
+	fprintf(stderr, "usage: wc [-clmw] [file ...]\n");
 	exit(1);
 }




More information about the Submit mailing list