changeset 2264:e25fa516b53a

Add helper function dmC64ImageDumpLine() for printing information out in dmC64ImageDump() and use it.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 17 Jun 2019 01:44:54 +0300
parents 891acec47aa0
children 48b48251610a
files tools/lib64util.c
diffstat 1 files changed, 72 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64util.c	Mon Jun 17 01:42:00 2019 +0300
+++ b/tools/lib64util.c	Mon Jun 17 01:44:54 2019 +0300
@@ -33,26 +33,39 @@
 }
 
 
+static void dmC64ImageDumpLine(FILE *fh, const char *indent, const char *field, const char *fmt, ...)
+{
+    va_list ap;
+
+    fputs(indent, fh);
+    fprintf(fh, "%-20s: ", field);
+    va_start(ap, fmt);
+    vfprintf(fh, fmt, ap);
+    va_end(ap);
+    fputs("\n", fh);
+}
+
+
 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt, const char *indent)
 {
     char typeStr[64];
 
     if (fmt != NULL)
     {
-        fprintf(fh,
-            "%sFormat              : %s [%s]\n",
-            indent, fmt->name, fmt->fext);
+        dmC64ImageDumpLine(fh, indent,
+            "Format", "%s [%s]",
+            fmt->name, fmt->fext);
     }
 
     if (img != NULL)
     {
         dmC64GetImageTypeString(typeStr, sizeof(typeStr), img->fmt->type, TRUE);
 
-        fprintf(fh,
-            "%sType                : %s\n"
-            "%sInternal blocks     : %d\n",
-            indent, typeStr,
-            indent, img->nblocks);
+        dmC64ImageDumpLine(fh, indent,
+            "Type", "%s", typeStr);
+
+        dmC64ImageDumpLine(fh, indent,
+            "Internal blocks", "%d", img->nblocks);
 
         if (img->fmt->type & D64_FMT_ILACE)
         {
@@ -63,39 +76,68 @@
                 case D64_ILACE_RES: tmps = "resolution"; break;
                 default: tmps = "ERROR"; break;
             }
-            fprintf(fh,
-                "%sInterlace type      : %s\n",
-                indent, tmps);
+            dmC64ImageDumpLine(fh, indent,
+                "Interlace type", "%s", tmps);
         }
 
         if (img->fmt->type & D64_FMT_FLI)
         {
-            fprintf(fh,
-                "%sFLI type            : %d\n",
-                indent, img->extraInfo[D64_EI_FLI_TYPE]);
+            dmC64ImageDumpLine(fh, indent,
+                "FLI type", "%d",
+                img->extraInfo[D64_EI_FLI_TYPE]);
         }
 
-        fprintf(fh,
-            "%sWidth x Height      : %d x %d\n"
-            "%sCHwidth x CHheight  : %d x %d\n"
-            "%sd020 / border       : %d ($%02x)\n"
-            "%sd021 / background   : %d ($%02x)\n",
-            indent, img->fmt->width, img->fmt->height,
-            indent, img->fmt->chWidth, img->fmt->chHeight,
-            indent, img->d020, img->d020,
-            indent, img->bgcolor, img->bgcolor);
+        dmC64ImageDumpLine(fh, indent,
+            "Width x Height", "%d x %d pixels",
+            img->fmt->width, img->fmt->height);
+
+        dmC64ImageDumpLine(fh, indent,
+            "CHwidth x CHheight", "%d x %d",
+            img->fmt->chWidth, img->fmt->chHeight);
+
+        dmC64ImageDumpLine(fh, indent,
+            "d020 / border", "%d ($%02x)",
+            img->d020, img->d020);
+
+        dmC64ImageDumpLine(fh, indent,
+            "d021 / background", "%d ($%02x)",
+            img->bgcolor, img->bgcolor);
+
+        if (img->fmt->type & D64_FMT_CHAR)
+        {
+            if ((img->fmt->type & D64_FMT_MODE_MASK) == (D64_FMT_MC | D64_FMT_ECM))
+            {
+                dmC64ImageDumpLine(fh, indent,
+                    "d022", "%d ($%02x)",
+                    img->d022, img->d022);
+                dmC64ImageDumpLine(fh, indent,
+                    "d023", "%d ($%02x)",
+                    img->d023, img->d023);
+            }
+
+            if ((img->fmt->type & D64_FMT_MODE_MASK) == D64_FMT_ECM)
+            {
+                dmC64ImageDumpLine(fh, indent,
+                    "d024", "%d ($%02x)",
+                    img->d024, img->d024);
+            }
+        }
     }
     else
     if (fmt != NULL)
     {
         dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE);
-        fprintf(fh,
-            "%sType                : %s\n"
-            "%sWidth x Height      : %d x %d\n"
-            "%sCHwidth x CHheight  : %d x %d\n",
-            indent, typeStr,
-            indent, fmt->format->width, fmt->format->height,
-            indent, fmt->format->chWidth, fmt->format->chHeight);
+
+        dmC64ImageDumpLine(fh, indent,
+            "Type", "%s", typeStr);
+
+        dmC64ImageDumpLine(fh, indent,
+            "Width x Height", "%d x %d pixels",
+            fmt->format->width, fmt->format->height);
+
+        dmC64ImageDumpLine(fh, indent,
+            "CHwidth x CHheight", "%d x %d",
+            fmt->format->chWidth, fmt->format->chHeight);
     }
 }