Module Name:    src
Committed By:   dholland
Date:           Thu Aug 13 06:59:38 UTC 2009

Modified Files:
        src/usr.bin/error: Makefile error.h input.c main.c pi.c subr.c touch.c

Log Message:
Pass WARNS=4, not without some gross preprocessor hackery.
XXX: does this program actually do anything useful these days?


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/error/Makefile
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/error/error.h
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/error/input.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/error/main.c src/usr.bin/error/pi.c
cvs rdiff -u -r1.18 -r1.19 src/usr.bin/error/subr.c
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/error/touch.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/error/Makefile
diff -u src/usr.bin/error/Makefile:1.8 src/usr.bin/error/Makefile:1.9
--- src/usr.bin/error/Makefile:1.8	Thu Aug 13 04:09:53 2009
+++ src/usr.bin/error/Makefile	Thu Aug 13 06:59:37 2009
@@ -1,7 +1,5 @@
 #	@(#)Makefile	8.1 (Berkeley) 6/6/93
-#	$NetBSD: Makefile,v 1.8 2009/08/13 04:09:53 dholland Exp $
-
-WARNS?=	2	# fails -Wcast-qual -Wshadow (etc)
+#	$NetBSD: Makefile,v 1.9 2009/08/13 06:59:37 dholland Exp $
 
 PROG=	error
 SRCS=	main.c input.c pi.c subr.c filter.c touch.c

Index: src/usr.bin/error/error.h
diff -u src/usr.bin/error/error.h:1.14 src/usr.bin/error/error.h:1.15
--- src/usr.bin/error/error.h:1.14	Thu Aug 13 05:53:58 2009
+++ src/usr.bin/error/error.h	Thu Aug 13 06:59:37 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: error.h,v 1.14 2009/08/13 05:53:58 dholland Exp $	*/
+/*	$NetBSD: error.h,v 1.15 2009/08/13 06:59:37 dholland Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -85,7 +85,7 @@
 /*
  * Resources to count and print out the error categories
  */
-extern char *class_table[];
+extern const char *class_table[];
 extern int class_count[];
 
 #define nunknown	class_count[C_UNKNOWN]
@@ -109,7 +109,7 @@
 extern char *processname;
 extern char *scriptname;
 
-extern char *suffixlist;
+extern const char *suffixlist;
 
 extern boolean query;
 extern boolean terse;
@@ -128,7 +128,7 @@
  * Describes attributes about a language
  */
 struct lang_desc {
-	char *lang_name;
+	const char *lang_name;
 	const char *lang_incomment;	/* one of the following defines */
 	const char *lang_outcomment;	/* one of the following defines */
 };
@@ -204,6 +204,58 @@
 extern char *currentfilename;
 
 /*
+ * Macros for initializing arrays of string constants.
+ * This is a fairly gross set of preprocessor hacks; the idea is
+ * that instead of
+ *     static char *foo[4] = { "alpha", "beta", "gamma", "delta" };
+ * you do
+ *     DECL_STRINGS_4(static, foo, "alpha", "beta", "gamma", "delta");
+ *
+ * and it comes out as
+ *     static char foo_0[] = "delta";
+ *     static char foo_1[] = "gamma";
+ *     static char foo_2[] = "beta";
+ *     static char foo_3[] = "alpha";
+ *     static char *foo[4] = { foo_3, foo_2, foo_1, foo_0 };
+ *
+ * none of which is const.
+ *
+ * Unfortunately, the string arrays this program slings around freely
+ * can't be all const (because it munges some of them) and can't be
+ * all non-const without something like this to initialize the ones
+ * that need to contain string constants. Unfortunately you can't
+ * mix (const char *const *) and (char **) in C, only in C++.
+ */
+
+#define DECL_STR(sym, num, str) static char sym##_##num[] = str
+
+#define DECL_S1(sym, s, ...) __VA_ARGS__ DECL_STR(sym, 0, s)
+#define DECL_S2(sym, s, ...) DECL_STR(sym, 1, s); DECL_S1(sym, __VA_ARGS__)
+#define DECL_S3(sym, s, ...) DECL_STR(sym, 2, s); DECL_S2(sym, __VA_ARGS__)
+#define DECL_S4(sym, s, ...) DECL_STR(sym, 3, s); DECL_S3(sym, __VA_ARGS__)
+#define DECL_S5(sym, s, ...) DECL_STR(sym, 4, s); DECL_S4(sym, __VA_ARGS__)
+#define DECL_S6(sym, s, ...) DECL_STR(sym, 5, s); DECL_S5(sym, __VA_ARGS__)
+
+#define USE_S1(sym) sym##_0
+#define USE_S2(sym) sym##_1, USE_S1(sym)
+#define USE_S3(sym) sym##_2, USE_S2(sym)
+#define USE_S4(sym) sym##_3, USE_S3(sym)
+#define USE_S5(sym) sym##_4, USE_S4(sym)
+#define USE_S6(sym) sym##_5, USE_S5(sym)
+
+#define DECL_STRS(num, class, sym, ...) \
+	DECL_S##num(sym, __VA_ARGS__); \
+	class char *sym[num] = { USE_S##num(sym) }
+
+#define DECL_STRINGS_1(class, sym, ...) DECL_STRS(1, class, sym, __VA_ARGS__)
+#define DECL_STRINGS_2(class, sym, ...) DECL_STRS(2, class, sym, __VA_ARGS__)
+#define DECL_STRINGS_3(class, sym, ...) DECL_STRS(3, class, sym, __VA_ARGS__)
+#define DECL_STRINGS_4(class, sym, ...) DECL_STRS(4, class, sym, __VA_ARGS__)
+#define DECL_STRINGS_5(class, sym, ...) DECL_STRS(5, class, sym, __VA_ARGS__)
+#define DECL_STRINGS_6(class, sym, ...) DECL_STRS(6, class, sym, __VA_ARGS__)
+	
+
+/*
  *	Functional forwards
  */
 void arrayify(int *, Eptr **, Eptr);
@@ -224,6 +276,7 @@
 int position(const char *, char);
 void printerrors(bool, int, Eptr []);
 const char *plural(int);
+char *Strdup(const char *);
 char *substitute(char *, char, char);
 bool touchfiles(int, Eptr **, int *, char ***);
 const char *verbform(int);

Index: src/usr.bin/error/input.c
diff -u src/usr.bin/error/input.c:1.15 src/usr.bin/error/input.c:1.16
--- src/usr.bin/error/input.c:1.15	Thu Aug 13 05:53:58 2009
+++ src/usr.bin/error/input.c	Thu Aug 13 06:59:37 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: input.c,v 1.15 2009/08/13 05:53:58 dholland Exp $	*/
+/*	$NetBSD: input.c,v 1.16 2009/08/13 06:59:37 dholland Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)input.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: input.c,v 1.15 2009/08/13 05:53:58 dholland Exp $");
+__RCSID("$NetBSD: input.c,v 1.16 2009/08/13 06:59:37 dholland Exp $");
 #endif /* not lint */
 
 #include <stdio.h>
@@ -197,10 +197,10 @@
 	} else
 	if (cur_wordc == 1 && language == INLD) {
 		nwordv = Calloc(4, sizeof(char *));
-		nwordv[0] = "ld:";
+		nwordv[0] = Strdup("ld:");	/* XXX leaked */
 		nwordv[1] = cur_wordv[1];
-		nwordv[2] = "is";
-		nwordv[3] = "undefined.";
+		nwordv[2] = Strdup("is");	/* XXX leaked */
+		nwordv[3] = Strdup("undefined.");/* XXX leaked */
 		cur_wordc = 4;
 		cur_wordv = nwordv - 1;
 		return (C_NONSPEC);
@@ -423,8 +423,15 @@
 	return (C_UNKNOWN);
 } /* end of lint 2*/
 
+#if 0 /* not const-correct */
 static char *Lint31[4] = {"returns", "value", "which", "is"};
 static char *Lint32[6] = {"value", "is", "used,", "but", "none", "returned"};
+#else
+DECL_STRINGS_4(static, Lint31,
+	       "returns", "value", "which", "is");
+DECL_STRINGS_6(static, Lint32,
+	       "value", "is", "used,", "but", "none", "returned");
+#endif
 
 static Errorclass
 lint3(void)
@@ -442,10 +449,17 @@
 /*
  * Special word vectors for use by F77 recognition
  */
+#if 0 /* not const-correct */
 static char *F77_fatal[3] = {"Compiler", "error", "line"};
 static char *F77_error[3] = {"Error", "on", "line"};
 static char *F77_warning[3] = {"Warning", "on", "line"};
 static char *F77_no_ass[3] = {"Error.","No","assembly."};
+#else
+DECL_STRINGS_3(static, F77_fatal, "Compiler", "error", "line");
+DECL_STRINGS_3(static, F77_error, "Error", "on", "line");
+DECL_STRINGS_3(static, F77_warning, "Warning", "on", "line");
+DECL_STRINGS_3(static, F77_no_ass, "Error.", "No", "assembly.");
+#endif
 
 static Errorclass
 f77(void)
@@ -487,8 +501,14 @@
 	return (C_UNKNOWN);
 } /* end of f77 */
 
+#if 0 /* not const-correct */
 static char *Make_Croak[3] = {"***", "Error", "code"};
 static char *Make_NotRemade[5] = {"not", "remade", "because", "of", "errors"};
+#else
+DECL_STRINGS_3(static, Make_Croak, "***", "Error", "code");
+DECL_STRINGS_5(static, Make_NotRemade,
+	       "not", "remade", "because", "of", "errors");
+#endif
 
 static Errorclass
 make(void)

Index: src/usr.bin/error/main.c
diff -u src/usr.bin/error/main.c:1.16 src/usr.bin/error/main.c:1.17
--- src/usr.bin/error/main.c:1.16	Thu Aug 13 05:53:58 2009
+++ src/usr.bin/error/main.c	Thu Aug 13 06:59:37 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.16 2009/08/13 05:53:58 dholland Exp $	*/
+/*	$NetBSD: main.c,v 1.17 2009/08/13 06:59:37 dholland Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: main.c,v 1.16 2009/08/13 05:53:58 dholland Exp $");
+__RCSID("$NetBSD: main.c,v 1.17 2009/08/13 06:59:37 dholland Exp $");
 #endif /* not lint */
 
 #include <signal.h>
@@ -66,7 +66,8 @@
 boolean *touchedfiles;  /* which files we touched */
 int language = INCC;
 
-char *currentfilename = "????";
+static char default_currentfilename[] = "????";
+char *currentfilename = default_currentfilename;
 char *processname;
 
 boolean query = false;	/* query the operator if touch files */
@@ -75,7 +76,7 @@
 static char im_on[] = _PATH_TTY;	/* my tty name */
 static boolean notouch = false;		/* don't touch ANY files */
 
-char *suffixlist = ".*";	/* initially, can touch any file */
+const char *suffixlist = ".*";	/* initially, can touch any file */
 
 static int errorsort(const void *, const void *);
 static void forkvi(int, char **);
Index: src/usr.bin/error/pi.c
diff -u src/usr.bin/error/pi.c:1.16 src/usr.bin/error/pi.c:1.17
--- src/usr.bin/error/pi.c:1.16	Thu Aug 13 05:53:58 2009
+++ src/usr.bin/error/pi.c	Thu Aug 13 06:59:37 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: pi.c,v 1.16 2009/08/13 05:53:58 dholland Exp $	*/
+/*	$NetBSD: pi.c,v 1.17 2009/08/13 06:59:37 dholland Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)pi.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: pi.c,v 1.16 2009/08/13 05:53:58 dholland Exp $");
+__RCSID("$NetBSD: pi.c,v 1.17 2009/08/13 06:59:37 dholland Exp $");
 #endif /* not lint */
 
 #include <stdio.h>
@@ -43,13 +43,18 @@
 #include <stdlib.h>
 #include "error.h"
 
-static char *c_linenumber;
+#if 0 /* not const-correct */
 static char *unk_hdr[] = {"In", "program", "???"};
+#else
+DECL_STRINGS_3(static, unk_hdr, "In", "program", "???");
+#endif
+
+static char *c_linenumber;
 static char **c_header = &unk_hdr[0];
 
 static boolean alldigits(const char *);
 static boolean isdateformat(int, char **);
-static boolean instringset(const char *, char **);
+static boolean instringset(const char *, const char **);
 static boolean piptr(const char *);
 
 
@@ -136,21 +141,22 @@
  *	  w - function bletch is never used
  *	  E - z undefined on lines 9 13
  */
-static char *Months[] = {
+static const char *Months[] = {
 	"Jan", "Feb", "Mar", "Apr", "May", "Jun",
 	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
 	0
 };
-static char *Days[] = {
+static const char *Days[] = {
 	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", 0
 };
-static char *Piroutines[] = {
+static const char *Piroutines[] = {
 	"program", "function", "procedure", 0
 };
 
 
 static boolean structured, multiple;
 
+#if 0 /* not const-correct */
 static char *pi_Endmatched[] = {"End", "matched"};
 static char *pi_Inserted[] = {"Inserted", "keyword", "end", "matching"};
 
@@ -162,6 +168,22 @@
 static char *pi_imp1[] = {"improperly", "used", "on", "line"};
 static char *pi_imp2[] = {"improperly", "used", "on", "lines"};
 
+#else
+DECL_STRINGS_2(static, pi_Endmatched, "End", "matched");
+DECL_STRINGS_4(static, pi_Inserted, "Inserted", "keyword", "end", "matching");
+
+DECL_STRINGS_6(static, pi_multiple,
+	       "Mutiply", "defined", "label", "in", "case,", "line");
+DECL_STRINGS_5(static, pi_structured,
+	       "is", "into", "a", "structured", "statement");
+
+DECL_STRINGS_3(static, pi_und1, "undefined", "on", "line");
+DECL_STRINGS_3(static, pi_und2, "undefined", "on", "lines");
+DECL_STRINGS_4(static, pi_imp1, "improperly", "used", "on", "line");
+DECL_STRINGS_4(static, pi_imp2, "improperly", "used", "on", "lines");
+
+#endif
+
 static boolean
 alldigits(const char *string)
 {
@@ -171,7 +193,7 @@
 }
 
 static boolean
-instringset(const char *member, char **set)
+instringset(const char *member, const char **set)
 {
 	for (; *set; set++) {
 		if (strcmp(*set, member) == 0)
@@ -249,7 +271,7 @@
 		nwordv[0] = strdup(currentfilename);
 		nwordv[1] = strdup(c_linenumber);
 		if (!longpiptr) {
-			nwordv[2] = "pascal errortype";
+			nwordv[2] = Strdup("pascal errortype"); /* XXX leaked */
 			nwordv[3] = cur_wordv[1];
 			nwordv[4] = strdup("%%%\n");
 			if (strlen(nwordv[5]) > (8-2))	/* this is the pointer */

Index: src/usr.bin/error/subr.c
diff -u src/usr.bin/error/subr.c:1.18 src/usr.bin/error/subr.c:1.19
--- src/usr.bin/error/subr.c:1.18	Thu Aug 13 05:53:58 2009
+++ src/usr.bin/error/subr.c	Thu Aug 13 06:59:37 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr.c,v 1.18 2009/08/13 05:53:58 dholland Exp $	*/
+/*	$NetBSD: subr.c,v 1.19 2009/08/13 06:59:37 dholland Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)subr.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: subr.c,v 1.18 2009/08/13 05:53:58 dholland Exp $");
+__RCSID("$NetBSD: subr.c,v 1.19 2009/08/13 06:59:37 dholland Exp $");
 #endif /* not lint */
 
 #include <ctype.h>
@@ -81,6 +81,18 @@
 	return (back);
 }
 
+char *
+Strdup(const char *s)
+{
+	char *ret;
+
+	ret = strdup(s);
+	if (ret == NULL) {
+		errx(1, "Ran out of memory.");
+	}
+	return ret;
+}
+
 /*
  * find the position of a given character in a string
  * (one based)

Index: src/usr.bin/error/touch.c
diff -u src/usr.bin/error/touch.c:1.21 src/usr.bin/error/touch.c:1.22
--- src/usr.bin/error/touch.c:1.21	Thu Aug 13 05:53:58 2009
+++ src/usr.bin/error/touch.c	Thu Aug 13 06:59:37 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: touch.c,v 1.21 2009/08/13 05:53:58 dholland Exp $	*/
+/*	$NetBSD: touch.c,v 1.22 2009/08/13 06:59:37 dholland Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)touch.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: touch.c,v 1.21 2009/08/13 05:53:58 dholland Exp $");
+__RCSID("$NetBSD: touch.c,v 1.22 2009/08/13 06:59:37 dholland Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -83,7 +83,7 @@
 static void text(Eptr, boolean);
 static boolean writetouched(int);
 static int mustoverwrite(FILE *, FILE *);
-static int mustwrite(const char *, int, FILE *);
+static int mustwrite(const char *, unsigned, FILE *);
 static void errorprint(FILE *, Eptr, boolean);
 static int probethisfile(const char *);
 
@@ -158,7 +158,7 @@
 	return (my_nfiles);
 }
 
-char *class_table[] = {
+const char *class_table[] = {
 	/*C_UNKNOWN	0	*/	"Unknown",
 	/*C_IGNORE	1	*/	"ignore",
 	/*C_SYNC	2	*/	"synchronization",
@@ -449,7 +449,7 @@
 oktotouch(const char *filename)
 {
 	const char *src;
-	char *pat;
+	const char *pat;
 	const char *osrc;
 
 	pat = suffixlist;
@@ -507,7 +507,7 @@
 	sep = NULL;
 	(*r_argv) = Calloc(n_pissed_on + 3, sizeof(char *));
 	(*r_argc) =  n_pissed_on + 2;
-	(*r_argv)[1] = "+1;/###/";
+	(*r_argv)[1] = Strdup("+1;/###/"); /* XXX leaked */
 	n_pissed_on = 2;
 	if (!terse) {
 		fprintf(stdout, "You touched file(s):");
@@ -607,7 +607,7 @@
 static boolean
 writetouched(int overwrite)
 {
-	int nread;
+	unsigned nread;
 	FILE *localfile;
 	FILE *temp;
 	int botch;
@@ -674,7 +674,7 @@
 static int
 mustoverwrite(FILE *preciousfile, FILE *temp)
 {
-	int nread;
+	unsigned nread;
 
 	while ((nread = fread(edbuf, 1, sizeof(edbuf), temp)) != 0) {
 		if (mustwrite(edbuf, nread, preciousfile) == 0)
@@ -687,9 +687,9 @@
  * return 0 on catastrophe
  */
 static int
-mustwrite(const char *base, int n, FILE *preciousfile)
+mustwrite(const char *base, unsigned n, FILE *preciousfile)
 {
-	int nwrote;
+	unsigned nwrote;
 
 	if (n <= 0)
 		return (1);

Reply via email to