"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".
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)
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
#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);
* 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)
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)
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;
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)) {
/* 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)
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:
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 {
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;
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)