changeset 146:263cd25749a1

Simplify data printing.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 13 Jun 2017 01:42:56 +0300
parents 3cc3bea20157
children f636c55c7cc4
files sidinfo.c
diffstat 1 files changed, 47 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/sidinfo.c	Tue Jun 13 01:27:17 2017 +0300
+++ b/sidinfo.c	Tue Jun 13 01:42:56 2017 +0300
@@ -449,54 +449,73 @@
 }
 
 
-static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const PSFOption *opt, const char *xfmt, const char *xaltfmt, ...)
+static void siPrintPSIDInfoLine(FILE *outFile, BOOL *shown, const PSFStackItem *item, const char *d_str, const int d_int)
 {
-    va_list ap;
-    const char *fmt = optHexadecimal ? (xaltfmt != NULL ? xaltfmt : xfmt) : xfmt;
+    const PSFOption *opt = &optPSOptions[item->cmd];
+    char *str = NULL;
+
+    switch (opt->type)
+    {
+        case OTYPE_INT:
+            str = th_strdup_printf(optHexadecimal ? "$%04x" : "%d", d_int);
+            break;
+
+        case OTYPE_STR:
+            str = th_strdup(d_str);
+            break;
+    }
 
     siPrintFieldPrefix(outFile, opt);
 
-    va_start(ap, xaltfmt);
-    vfprintf(outFile, fmt, ap);
-    va_end(ap);
+    if (str != NULL)
+        fputs(str, outFile);
 
     siPrintFieldSeparator(outFile);
+    th_free(str);
+
     *shown = TRUE;
 }
 
 
-#define PR(xfmt, xaltfmt, ...) siPrintPSIDInfoLine(outFile, shown, opt, xfmt, xaltfmt, __VA_ARGS__ )
+#define PR(d_str, d_int) siPrintPSIDInfoLine(outFile, shown, item, d_str, d_int)
 
 
 static void siPrintPSIDInformationField(FILE *outFile, const char *filename, const PSIDHeader *psid, BOOL *shown, const PSFStackItem *item)
 {
     const PSFOption *opt = &optPSOptions[item->cmd];
+    char tmp[64];
+
     switch (item->cmd)
     {
-        case  0: PR("%s", NULL, filename); break;
-        case  1: PR("%s", NULL, psid->magic); break;
-        case  2: PR("%d.%d", NULL, (psid->version & 0xff), (psid->version >> 8)); break;
-        case  3: PR("%s", NULL, (psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in"); break;
+        case  0: PR(filename, -1); break;
+        case  1: PR(psid->magic, -1); break;
+        case  2:
+            snprintf(tmp, sizeof(tmp), "%d.%d", (psid->version & 0xff), (psid->version >> 8));
+            PR(tmp, -1);
+            break;
+        case  3:
+            PR((psid->flags & PSF_PLAYER_TYPE) ? "Compute! SIDPlayer MUS" : "Normal built-in", -1);
+            break;
         case  4:
             if (psid->version >= 2)
-                PR("%s", NULL, (psid->flags & PSF_PLAYSID_TUNE) ? "PlaySID" : "C64 compatible");
+                PR((psid->flags & PSF_PLAYSID_TUNE) ? (psid->isRSID ? "C64 BASIC" : "PlaySID") : "C64 compatible", -1);
             break;
         case  5:
             if (psid->version >= 2)
-                PR("%s", NULL, si_get_sid_clock_str((psid->flags >> 2) & PSF_CLOCK_MASK));
+                PR(si_get_sid_clock_str((psid->flags >> 2) & PSF_CLOCK_MASK), -1);
             break;
         case  6:
             if (psid->version >= 2)
-                PR("%s", NULL, si_get_sid_model_str((psid->flags >> 4) & PSF_MODEL_MASK));
+                PR(si_get_sid_model_str((psid->flags >> 4) & PSF_MODEL_MASK), -1);
             break;
 
-        case  7: PR("%d", "$%08x", psid->dataOffset); break;
-        case  8: PR("%d", "$%08x", psid->dataSize); break;
-        case  9: PR("%d", "$%04x", psid->loadAddress); break;
-        case 10: PR("%d", "$%04x", psid->initAddress); break;
-        case 11: PR("%d", "$%04x", psid->playAddress); break;
-        case 12: PR("%d", "$%04x", psid->nSongs); break;
-        case 13: PR("%d", "$%04x", psid->startSong); break;
+        case  7: PR(NULL, psid->dataOffset); break;
+        case  8: PR(NULL, psid->dataSize); break;
+        case  9: PR(NULL, psid->loadAddress); break;
+        case 10: PR(NULL, psid->initAddress); break;
+        case 11: PR(NULL, psid->playAddress); break;
+        case 12: PR(NULL, psid->nSongs); break;
+        case 13: PR(NULL, psid->startSong); break;
 
         case 14:
             if (psid->version >= 3)
@@ -505,7 +524,7 @@
                 if (flags == PSF_MODEL_UNKNOWN)
                     flags = (psid->flags >> 4) & PSF_MODEL_MASK;
 
-                PR("%s", NULL, si_get_sid_model_str(flags));
+                PR(si_get_sid_model_str(flags), -1);
             }
             break;
         case 15:
@@ -515,21 +534,21 @@
                 if (flags == PSF_MODEL_UNKNOWN)
                     flags = (psid->flags >> 4) & PSF_MODEL_MASK;
 
-                PR("%s", NULL, si_get_sid_model_str(flags));
+                PR(si_get_sid_model_str(flags), -1);
             }
             break;
         case 16:
             if (psid->version >= 3)
-                PR("%d", "$%04x", 0xD000 | (psid->sid2Addr << 4));
+                PR(NULL, 0xD000 | (psid->sid2Addr << 4));
             break;
         case 17:
             if (psid->version >= 4)
-                PR("%d", "$%04x", 0xD000 | (psid->sid3Addr << 4));
+                PR(NULL, 0xD000 | (psid->sid3Addr << 4));
             break;
 
-        case 18: PR("%s", NULL, psid->sidName); break;
-        case 19: PR("%s", NULL, psid->sidAuthor); break;
-        case 20: PR("%s", NULL, psid->sidCopyright); break;
+        case 18: PR(psid->sidName, -1); break;
+        case 19: PR(psid->sidAuthor, -1); break;
+        case 20: PR(psid->sidCopyright, -1); break;
 
         case 21:
             {