[PATCH]sbin/comcontrol WARNS=6, style

Sepherosa Ziehau sepherosa at softhome.net
Fri Mar 18 18:11:12 PST 2005


WARNS=6, style clean
a brief at the beginning of the patch futher states what the patch does
please review it.1) dump up warn level to 6
2) reorder "include" according to style
3) white space adjustment in local variable definition
4) add missing "{}" after certain "if-else", according to style
5) !strcmp() -> strcmp == 0

Index: Makefile
===================================================================
RCS file: /opt/df_cvs/src/sbin/comcontrol/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- Makefile	17 Jun 2003 04:27:32 -0000	1.2
+++ Makefile	19 Mar 2005 02:09:12 -0000
@@ -2,6 +2,7 @@
 # $FreeBSD: src/sbin/comcontrol/Makefile,v 1.2.12.1 2001/04/25 10:58:13 ru Exp $
 # $DragonFly: src/sbin/comcontrol/Makefile,v 1.2 2003/06/17 04:27:32 dillon Exp $
 
+WARNS?=	6
 PROG=	comcontrol
 MAN=	comcontrol.8
 
Index: comcontrol.c
===================================================================
RCS file: /opt/df_cvs/src/sbin/comcontrol/comcontrol.c,v
retrieving revision 1.2
diff -u -r1.2 comcontrol.c
--- comcontrol.c	17 Jun 2003 04:27:32 -0000	1.2
+++ comcontrol.c	19 Mar 2005 02:09:12 -0000
@@ -29,6 +29,9 @@
  * $DragonFly: src/sbin/comcontrol/comcontrol.c,v 1.2 2003/06/17 04:27:32 dillon Exp $
  */
 
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
 #include <ctype.h>
 #include <err.h>
 #include <errno.h>
@@ -37,11 +40,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
 
 static void
-usage()
+usage(void)
 {
 	fprintf(stderr,
 	"usage: comcontrol <filename> [dtrwait <n>] [drainwait <n>]\n");
@@ -51,18 +52,18 @@
 int
 main(int argc, char *argv[])
 {
-	int	fd;
-	int     res = 0;
-	int     print_dtrwait = 1, print_drainwait = 1;
-	int     dtrwait = -1, drainwait = -1;
+	int fd;
+	int res = 0;
+	int print_dtrwait = 1, print_drainwait = 1;
+	int dtrwait = -1, drainwait = -1;
 
 	if (argc < 2)
 		usage();
 
-	if (strcmp(argv[1], "-") == 0)
+	if (strcmp(argv[1], "-") == 0) {
 		fd = STDIN_FILENO;
-	else {
-		fd = open(argv[1], O_RDONLY|O_NONBLOCK, 0);
+	} else {
+		fd = open(argv[1], O_RDONLY | O_NONBLOCK, 0);
 		if (fd < 0) {
 			warn("couldn't open file %s", argv[1]);
 			return 1;
@@ -90,22 +91,23 @@
 		printf("\n");
 	} else {
 		while (argv[2] != NULL) {
-			if (!strcmp(argv[2],"dtrwait")) {
+			if (strcmp(argv[2],"dtrwait") == 0) {
 				if (dtrwait >= 0)
 					usage();
 				if (argv[3] == NULL || !isdigit(argv[3][0]))
 					usage();
 				dtrwait = atoi(argv[3]);
 				argv += 2;
-			} else if (!strcmp(argv[2],"drainwait")) {
+			} else if (strcmp(argv[2],"drainwait") == 0) {
 				if (drainwait >= 0)
 					usage();
 				if (argv[3] == NULL || !isdigit(argv[3][0]))
 					usage();
 				drainwait = atoi(argv[3]);
 				argv += 2;
-			} else
+			} else {
 				usage();
+			}
 		}
 		if (dtrwait >= 0) {
 			if (ioctl(fd, TIOCMSDTRWAIT, &dtrwait) < 0) {




More information about the Submit mailing list