Added 'linty' target for make
authorBob Little <Bob.Little@aeronix.com>
Sun, 18 Jun 2017 00:43:19 +0000 (20:43 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 18 Jun 2017 02:28:40 +0000 (22:28 -0400)
"make linty" does lots of error checking while compiling.
Simplified the standard make's CFLAGS.
Cleaned up code to eliminate resulting warnings generated by "make linty".

Makefile
advent.h
dungeon.c
main.c
misc.c
newdungeon.py

index b0b06b95c7f24896df0d99cafd81848fcbc9c88b..62a4ee4fc91dd1bb775f6af2cebaa49b6f8ed2d4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -25,9 +25,7 @@
 VERS=1.0
 
 CC?=gcc
-CCFLAGS+=-std=c99 -D _DEFAULT_SOURCE -Wall -Wpedantic -Wextra -g
-CCFLAGS+=-Wstrict-prototypes
-CCFLAGS+=-Wmissing-prototypes
+CCFLAGS+=-std=c99 -D _DEFAULT_SOURCE -Wpedantic 
 LIBS=
 UNAME_S := $(shell uname -s)
 ifeq ($(UNAME_S),Linux)
@@ -118,5 +116,8 @@ refresh: advent.html
 
 dist: advent-$(VERS).tar.gz
 
+linty: CCFLAGS += -W -Wall -Wextra -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wfloat-equal -Wcast-align -Wwrite-strings -Waggregate-return -Wcast-qual -Wswitch-enum -Wwrite-strings -Wunreachable-code -Winit-self -Wpointer-arith -O2 
+linty: advent
+
 debug: CCFLAGS += -O0 --coverage -g
 debug: advent
index 1cc87842240974bfe9ad4d0c7db339d84712c1d9..c5abaa6661cc917ec9fb1ad25687ba624ae512e0 100644 (file)
--- a/advent.h
+++ b/advent.h
@@ -84,7 +84,7 @@ extern bool oldstyle, editline, prompt;
 #define WRITE_MODE "wb"
 extern char* xstrdup(const char*);
 extern void packed_to_token(long, char token[]);
-extern void newspeak(char*);
+extern void newspeak(const char*);
 extern void PSPEAK(vocab_t,int);
 extern void RSPEAK(vocab_t);
 extern void SETPRM(long,long,long);
index dfc5b1c9db799c4dfe5cec7bef7b0ca89585625d..5b94d9508e1a584f33d0be84e40782f8fa1c7b90 100644 (file)
--- a/dungeon.c
+++ b/dungeon.c
@@ -487,12 +487,12 @@ static int read_database(FILE* database) {
  *  whether the abbreviated description is printed.  Counts modulo 5
  *  unless "LOOK" is used. */
 
-static void write_0d(FILE* header_file, long single, char* varname)
+static void write_0d(FILE* header_file, long single, const char* varname)
 {
    fprintf(header_file, "LOCATION long %s INITIALIZE(= %ld);\n", varname, single);
 }
 
-static void write_1d(FILE* header_file, long array[], long dim, char* varname)
+static void write_1d(FILE* header_file, long array[], long dim, const char* varname)
 {
    fprintf(header_file, "LOCATION long %s[] INITIALIZE(= {\n", varname);
    for (int i = 0; i < dim; ++i)
@@ -508,7 +508,7 @@ static void write_1d(FILE* header_file, long array[], long dim, char* varname)
    fprintf(header_file, "\n});\n");
 }
 
-static void write_hints(FILE* header_file, long matrix[][HINTLEN], long dim1, long dim2, char* varname)
+static void write_hints(FILE* header_file, long matrix[][HINTLEN], long dim1, long dim2, const char* varname)
 {
    fprintf(header_file, "LOCATION long %s[][%ld] INITIALIZE(= {\n", varname, dim2);
    for (int i = 0; i < dim1; ++i)
diff --git a/main.c b/main.c
index 3d23c968f7b8fe531c5c7decbc9d1a1699b57284..526eda171513899093f5a381e7a218d621d4fc86 100644 (file)
--- a/main.c
+++ b/main.c
@@ -913,7 +913,7 @@ static void listobjects(void)
 static bool do_command(FILE *cmdin)
 /* Get and execute a command */ 
 {
-    long verb, V1, V2;
+    long verb=0, V1, V2;
     long kmod, defn;
     static long igo = 0;
     static long obj = 0;
@@ -950,7 +950,7 @@ static bool do_command(FILE *cmdin)
     for (;;) {
        if (game.loc == 0)
            croak(cmdin);
-       char* msg = locations[game.loc].description.small;
+       const char* msg = locations[game.loc].description.small;
        if (MOD(game.abbrev[game.loc],game.abbnum) == 0 || msg == 0)
            msg=locations[game.loc].description.big;
        if (!FORCED(game.loc) && DARK(game.loc)) {
diff --git a/misc.c b/misc.c
index cf75e6442c42452ec02ca6db6ab75bb4a4e23c02..978e4b61aefb51cfee18d33d7d4a08638f6a8d2f 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -45,7 +45,7 @@ void packed_to_token(long packed, char token[6])
 
 /*  I/O routines (SPEAK, PSPEAK, RSPEAK, SETPRM, GETIN, YES) */
 
-void newspeak(char* msg)
+void newspeak(const char* msg)
 {
   // Do nothing if we got a null pointer.
   if (msg == NULL)
index a4b046e9ed5b124f454f28011f13afd00de032e7..2bd2a5a6f8b191cd4efb943b7e6a2cc98cc4c2a5 100755 (executable)
@@ -28,7 +28,7 @@ def write_regular_messages(name, h, c):
         h += "  {},\n".format(key)
     h += "};\n\n"
     
-    c += "char* {}[] = {{\n".format(name)   
+    c += "const char* {}[] = {{\n".format(name)   
     index = 0
     for key, text in dungeon[name]:
         if text == None:
@@ -47,13 +47,13 @@ with open(yaml_name, "r") as f:
 h = """#include <stdio.h>
 
 typedef struct {
-  char* inventory;
-  char** longs;
+  const char* inventory;
+  const char** longs;
 } object_description_t;
 
 typedef struct {
-  char* small;
-  char* big;
+  const char* small;
+  const char* big;
 } descriptions_t;
 
 typedef struct {
@@ -62,9 +62,9 @@ typedef struct {
 
 extern location_t locations[];
 extern object_description_t object_descriptions[];
-extern char* arbitrary_messages[];
-extern char* class_messages[];
-extern char* turn_threshold_messages[];
+extern const char* arbitrary_messages[];
+extern const char* class_messages[];
+extern const char* turn_threshold_messages[];
 
 extern size_t CLSSES;
 
@@ -118,7 +118,7 @@ for key, data in dungeon["object_descriptions"]:
     c += "    .inventory = {},\n".format(data["inventory"])
     try:
         data["longs"][0]
-        c += "    .longs = (char* []) {\n"
+        c += "    .longs = (const char* []) {\n"
         for l in data["longs"]:
             l = c_escape(l)
             c += "      \"{}\",\n".format(l)