port: fixed all remaining c89 warnings origin/cleanup-and-c89-port
authorLukas Krickl <lukas@krickl.dev>
Mon, 23 Mar 2026 04:29:20 +0000 (05:29 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 23 Mar 2026 04:29:20 +0000 (05:29 +0100)
Enabled -wextra

makefile
src/ulas.c
src/ulas.h
src/uldas.c

index 9c2c872a70e53365aa38a793616deb650e90ef24..c41b6f238cb7b3c0a54518b9d8796597798834dd 100644 (file)
--- 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)
        
 
index 8f91af7e357b0761d5ff296afa7d999bdc3bfe35..b6c133aa58329377d1e178c02c9d4fd972371d4a 100644 (file)
@@ -5,6 +5,7 @@
 #include <string.h>
 #include <assert.h>
 #include <sys/time.h>
+#include <stdarg.h>
 #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:
index 1460e9b5f8293c3bfa32db59e503f8183a5327f6..3d81b28668f83063beae6b7e64c2b1fae09ff691 100644 (file)
@@ -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);
 
index 6f76c5ebb5da138f8b9594b96db82477401fa22f..87a39492fb905fc7d377abd8491be818ed7e363a 100644 (file)
@@ -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;