From 90dcfc8357bd22f7a29e8aee6cf6959cc425b3b6 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 23 Mar 2026 05:29:20 +0100 Subject: [PATCH] port: fixed all remaining c89 warnings Enabled -wextra --- makefile | 8 ++-- src/ulas.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++------ src/ulas.h | 37 ++++++++++-------- src/uldas.c | 3 ++ 4 files changed, 128 insertions(+), 31 deletions(-) diff --git a/makefile b/makefile index 9c2c872..c41b6f2 100644 --- a/makefile +++ b/makefile @@ -2,7 +2,7 @@ NAME=ulas TEST_NAME=test$(NAME) DBGCFLAGS=-g -fsanitize=address DBGLDFLAGS=-fsanitize=address -CFLAGS=-Wall -pedantic $(DBGCFLAGS) -std=gnu89 +CFLAGS=-Wall -Wextra -pedantic $(DBGCFLAGS) -std=gnu89 LIBS= LDFLAGS=$(DBGLDFLAGS) $(LIBS) @@ -16,10 +16,12 @@ all: bin btest release: make DBGCFLAGS="" DBGLDFLAGS="" +PHONY: FORCE +FORCE: -main.o: src/main.c +main.o: src/main.c FORCE $(CCOBJ) -test.o: src/test.c +test.o: src/test.c FORCE $(CCOBJ) diff --git a/src/ulas.c b/src/ulas.c index 8f91af7..b6c133a 100644 --- a/src/ulas.c +++ b/src/ulas.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "uldas.h" FILE *ulasin = NULL; @@ -107,6 +108,63 @@ void ulas_free(void) { ulas_preprocfree(&ulas.pp); } + +int ulas_dbg(const char *fmt, ...) { + int res = 0; + va_list args; + + if (!ulascfg.verbose) { + return 0; + } + + ULASINFO(); + va_start(args, fmt); + res = vfprintf(ulaserr, fmt, args); + va_end(args); + + return res; +} + +int ulas_err(const char *fmt, ...) { + int res = 0; + va_list args; + + ULASINFO(); + + va_start(args, fmt); + res = vfprintf(ulaserr, fmt, args); + va_end(args); + + return res; +} + +int ulas_warn(const char *fmt, ...) { + int res = 0; + va_list args; + + ULASINFO(); + va_start(args, fmt); + res = vfprintf(ulaserr, fmt, args); + va_end(args); + + return res; +} + +int ulas_panic(const char *fmt, ...) { + int res = 0; + va_list args; + + ULASINFO(); + + va_start(args, fmt); + res = vfprintf(ulaserr, fmt, args); + va_end(args); + + exit(-1); + + return res; +} + char *ulas_strdup(const char *s) { int len = strlen(s); return ulas_strndup(s, len); @@ -2553,7 +2611,11 @@ int ulas_asmdirdefenum(const char **line, unsigned long n) { tok.val.intv = ulas.enumv; rc = 0; - ULAS_EVALEXPRS(ulas.enumv += ulas_intexpr(line, n, &rc)); + + ULAS_EVALEXPRS_BEGIN + ulas.enumv += ulas_intexpr(line, n, &rc); + ULAS_EVALEXPRS_END + if (rc == -1) { goto fail; } @@ -2586,7 +2648,10 @@ int ulas_asmdirfill(FILE *dst, const char **line, unsigned long n, int *rc) { } count = 0; - ULAS_EVALEXPRS(count = ulas_intexpr(line, n, rc)); + ULAS_EVALEXPRS_BEGIN + count = ulas_intexpr(line, n, rc); + ULAS_EVALEXPRS_END + if (count < 0) { ULASERR("Count must be positive\n"); return 0; @@ -2663,12 +2728,18 @@ int ulas_asmdirincbin(FILE *dst, const char **line, unsigned long n, int *rc) { } int ulas_asmdiradv(FILE *dst, const char **line, unsigned long n, int *rc) { - ULAS_EVALEXPRS(ulas.address += ulas_intexpr(line, ulas_strnlen(*line, n), rc)); + ULAS_EVALEXPRS_BEGIN + ulas.address += ulas_intexpr(line, ulas_strnlen(*line, n), rc); + ULAS_EVALEXPRS_END + return 0; } int ulas_asmdirsetenum(FILE *dst, const char **line, unsigned long n, int *rc) { - ULAS_EVALEXPRS(ulas.enumv = ulas_intexpr(line, ulas_strnlen(*line, n), rc)); + ULAS_EVALEXPRS_BEGIN + ulas.enumv = ulas_intexpr(line, ulas_strnlen(*line, n), rc); + ULAS_EVALEXPRS_END + return 0; } @@ -2677,7 +2748,10 @@ int ulas_asmdirsetcharcode(const char **line, unsigned long n) { int charcode = 0; int setto = 0; struct ulas_tok t; - ULAS_EVALEXPRS(charcode = ulas_intexpr(line, n, &rc)); + ULAS_EVALEXPRS_BEGIN + charcode = ulas_intexpr(line, n, &rc); + ULAS_EVALEXPRS_END + charcode = charcode & 0xFF; ulas_tok(&ulas.tok, line, n); @@ -2689,7 +2763,10 @@ int ulas_asmdirsetcharcode(const char **line, unsigned long n) { return 0; } - ULAS_EVALEXPRS(setto = ulas_intexpr(line, n, &rc)); + ULAS_EVALEXPRS_BEGIN + setto = ulas_intexpr(line, n, &rc); + ULAS_EVALEXPRS_END + setto = setto & 0xFF; ulas.charcodemap[charcode] = (char)setto; @@ -2774,7 +2851,10 @@ int ulas_asmdirrep(FILE *dst, FILE *src, const char **line, unsigned long n) { repval = 0; rc = 0; - ULAS_EVALEXPRS(repval = ulas_intexpr(line, n, &rc)); + ULAS_EVALEXPRS_BEGIN + repval = ulas_intexpr(line, n, &rc); + ULAS_EVALEXPRS_END + ulas_tok(&ulas.tok, line, n); t = ulas_totok(ulas.tok.buf, ulas_strnlen(ulas.tok.buf, ulas.tok.maxlen), &rc); @@ -2784,7 +2864,10 @@ int ulas_asmdirrep(FILE *dst, FILE *src, const char **line, unsigned long n) { } step = 0; - ULAS_EVALEXPRS(step = ulas_intexpr(line, n, &rc)); + ULAS_EVALEXPRS_BEGIN + step = ulas_intexpr(line, n, &rc); + ULAS_EVALEXPRS_END + ulas_tok(&ulas.tok, line, n); t = ulas_totok(ulas.tok.buf, ulas_strnlen(ulas.tok.buf, ulas.tok.maxlen), &rc); if (rc == -1 || t.type != ',') { @@ -2821,7 +2904,10 @@ int ulas_asmdirsection(FILE *dst, FILE *src, const char **line, int ulas_asmdirbank(FILE *dst, FILE *src, const char **line, unsigned long n, int *rc) { - ULAS_EVALEXPRS(ulas.bank = ulas_intexpr(line, ulas_strnlen(*line, n), rc)); + ULAS_EVALEXPRS_BEGIN + ulas.bank = ulas_intexpr(line, ulas_strnlen(*line, n), rc); + ULAS_EVALEXPRS_END + return *rc; } @@ -2905,8 +2991,11 @@ int ulas_asmline(FILE *dst, FILE *src, const char *line, unsigned long n) { switch (dir) { case ULAS_ASMDIR_ORG: { - ULAS_EVALEXPRS(ulas.address = - ulas_intexpr(&line, ulas_strnlen(start, n), &rc)); + ULAS_EVALEXPRS_BEGIN + ulas.address = + ulas_intexpr(&line, ulas_strnlen(start, n), &rc); + ULAS_EVALEXPRS_END + break; } case ULAS_ASMDIR_DEF: diff --git a/src/ulas.h b/src/ulas.h index 1460e9b..3d81b28 100644 --- a/src/ulas.h +++ b/src/ulas.h @@ -91,19 +91,16 @@ extern unsigned long defslen; #define ULAS_TOK_SCOPED_SYMBOL_BEGIN '@' #define ULAS_TOK_CURRENT_ADDR '$' +#define ULAS_UNUSED(x) (void)(x) + #define ULASINFO() fprintf(ulaserr, "%s:%ld ", ulas.filename, ulas.line); -#define ULASDBG(...) \ - if (ulascfg.verbose) { \ - fprintf(ulaserr, __VA_ARGS__); \ - } -#define ULASERR(...) ULASINFO() fprintf(ulaserr, __VA_ARGS__); -#define ULASWARN(...) ULASINFO() fprintf(ulaserr, __VA_ARGS__); -#define ULASPANIC(...) \ - { \ - ULASINFO(); \ - fprintf(ulaserr, __VA_ARGS__); \ - exit(-1); \ - } + +/* deprecaated legacy log macros */ +#define ULASDBG ulas_dbg +#define ULASERR ulas_err +#define ULASWARN ulas_warn +#define ULASPANIC ulas_panic + #define ULASWARNLEVEL(level) (ulascfg.warn_level & (level)) /* format macros */ @@ -118,13 +115,13 @@ extern unsigned long defslen; * only be uesd to evalulate an expression that needs to be evaled during * all passes and nothing else! */ -#define ULAS_EVALEXPRS(...) \ +#define ULAS_EVALEXPRS_BEGIN \ { \ int pass = ulas.pass; \ - ulas.pass = ULAS_PASS_FINAL; \ - __VA_ARGS__; \ - ulas.pass = pass; \ - } + ulas.pass = ULAS_PASS_FINAL; +#define ULAS_EVALEXPRS_END \ + ulas.pass = pass; \ + } /** * Output target files @@ -703,6 +700,12 @@ unsigned int ulas_strnlen(const char *s, unsigned int max); unsigned int ulas_strlcat(char *dst, const char *src, unsigned int max); +/* ulas log functions */ +int ulas_dbg(const char *fmt, ...); +int ulas_err(const char *fmt, ...); +int ulas_warn(const char *fmt, ...); +int ulas_panic(const char *fmt, ...); + void ulas_help(void); void ulas_version(void); diff --git a/src/uldas.c b/src/uldas.c index 6f76c5e..87a3949 100644 --- a/src/uldas.c +++ b/src/uldas.c @@ -23,6 +23,8 @@ void ulas_dasm_instr_fout(FILE *src, FILE *dst, const struct ulas_instr *instr, const char *buf, unsigned long read) { int i; unsigned int bi; + + ULAS_UNUSED(src); if (ulas.pass != ULAS_PASS_FINAL) { return; } @@ -72,6 +74,7 @@ void ulas_dasm_instr_fout(FILE *src, FILE *dst, const struct ulas_instr *instr, /* fallback if no instruction was found */ void ulas_dasm_db_fout(FILE *src, FILE *dst, const char *buf, unsigned long read) { + ULAS_UNUSED(src); ulas.address++; if (ulas.pass != ULAS_PASS_FINAL) { return; -- 2.30.2