diff tools/lib64gfx.c @ 958:985225a93aeb

Add error code parameter to dmError() and dmErrorVA().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 27 Feb 2015 03:58:25 +0200
parents 93898b9a04ad
children d0898867ec4c
line wrap: on
line diff
--- a/tools/lib64gfx.c	Fri Feb 27 02:21:57 2015 +0200
+++ b/tools/lib64gfx.c	Fri Feb 27 03:58:25 2015 +0200
@@ -668,16 +668,16 @@
 {
     if (op->bank < 0 || op->bank >= C64_SCR_MAX_BANK)
     {
-        dmError("Invalid bank %d definition in generic encode/decode operator %d @ #%d.\n",
+        return dmError(DMERR_INTERNAL,
+            "Invalid bank %d definition in generic encode/decode operator %d @ #%d.\n",
             op->bank, op->type, i);
-        return DMERR_INTERNAL;
     }
 
     if (op->type < 0 || op->type >= DT_LAST)
     {
-        dmError("Invalid encode/decode operator type %d @ #%d.\n",
+        return dmError(DMERR_INTERNAL,
+            "Invalid encode/decode operator type %d @ #%d.\n",
             op->type, i);
-        return DMERR_INTERNAL;
     }
 
     return DMERR_OK;
@@ -742,8 +742,8 @@
 
     if (fmt->nencdecOps < 0 || fmt->nencdecOps >= D64_MAX_ENCDEC_OPS)
     {
-        dmError("Invalid number of enc/dec ops in format. Internal error.\n");
-        return DMERR_INTERNAL;
+        return dmError(DMERR_INTERNAL,
+            "Invalid number of enc/dec ops in format. Internal error.\n");
     }
 
     // Clear the image structure, set basics
@@ -768,19 +768,19 @@
         // Check size
         if (!dmC64GetOpSize(op, fmt, &size))
         {
-            dmError("Decode op SIZE out of bounds, op #%d type=%d, offs=%d ($%04x), "
+            return dmError(DMERR_INVALID_DATA,
+                "Decode op SIZE out of bounds, op #%d type=%d, offs=%d ($%04x), "
                 "bank=%d, size=%d ($%04x) vs. allocated %d ($%04x)\n",
                 i, op->type, op->offs, op->offs, op->bank, size, size, op->size, op->size);
-            return DMERR_INVALID_DATA;
         }
 
         // Do we need to reallocate some more space?
         if (op->offs + size > len)
         {
-            dmError("Decode out of bounds, op #%d type=%d, offs=%d ($%04x), "
+            return dmError(DMERR_INVALID_DATA,
+                "Decode out of bounds, op #%d type=%d, offs=%d ($%04x), "
                 "bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
                 i, op->type, op->offs, op->offs, op->bank, size, size, len, len);
-            return DMERR_INVALID_DATA;
         }
 
         src = buf + op->offs;
@@ -804,10 +804,10 @@
                     case DC_D023: img->d023 = *src; break;
                     case DC_D024: img->d024 = *src; break;
                     default:
-                        dmError("Unhandled DT_COLOR_REG mode %d in ",
-                        "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
-                        op->size, i, op->offs, op->offs, op->bank, size, size, len, len);
-                        return DMERR_INTERNAL;
+                        return dmError(DMERR_INTERNAL,
+                            "Unhandled DT_COLOR_REG mode %d in ",
+                            "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
+                            op->size, i, op->offs, op->offs, op->bank, size, size, len, len);
                 }
                 break;
 
@@ -821,10 +821,10 @@
                     case DC_D023: img->d023 = op->offs; break;
                     case DC_D024: img->d024 = op->offs; break;
                     default:
-                        dmError("Unhandled DT_COLOR_SET mode %d in ",
-                        "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
-                        op->size, i, op->offs, op->offs, op->bank, size, size, len, len);
-                        return DMERR_INTERNAL;
+                        return dmError(DMERR_INTERNAL,
+                            "Unhandled DT_COLOR_SET mode %d in ",
+                            "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
+                            op->size, i, op->offs, op->offs, op->bank, size, size, len, len);
                 }
                 break;
 
@@ -844,27 +844,27 @@
                         break;
 
                     default:
-                        dmError("Unhandled DT_CHAR_CONFIG mode %d in ",
-                        "op #%d, bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
-                        op->offs, i, op->bank, size, size, len, len);
-                        return DMERR_INTERNAL;
+                        return dmError(DMERR_INTERNAL,
+                            "Unhandled DT_CHAR_CONFIG mode %d in ",
+                            "op #%d, bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
+                            op->offs, i, op->bank, size, size, len, len);
                 }
                 break;
 
             case DT_DEC_FUNCTION:
                 if (op->decfunction == NULL)
                 {
-                    dmError("Decode op is a function, but function ptr is NULL: "
+                    return dmError(DMERR_INTERNAL,
+                        "Decode op is a function, but function ptr is NULL: "
                         "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
                         i, op->offs, op->offs, op->bank, size, size, len, len);
-                    return DMERR_INTERNAL;
                 }
                 if (!op->decfunction(img, op, buf, len))
                 {
-                    dmError("Decode op custom function failed: op #%d, "
+                    return dmError(DMERR_INTERNAL,
+                        "Decode op custom function failed: op #%d, "
                         "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
                         i, op->offs, op->offs, op->bank, size, size, len, len);
-                    return DMERR_INTERNAL;
                 }
                 break;
         }
@@ -885,8 +885,8 @@
 
     if (fmt->nencdecOps < 0 || fmt->nencdecOps >= D64_MAX_ENCDEC_OPS)
     {
-        dmError("Invalid number of enc/dec ops in format. Internal error.\n");
-        return DMERR_INTERNAL;
+        return dmError(DMERR_INTERNAL,
+            "Invalid number of enc/dec ops in format. Internal error.\n");
     }
 
     // Allocate the output buffer
@@ -898,9 +898,9 @@
 
     if ((buf = dmMalloc(allocated)) == NULL)
     {
-        dmError("Could not allocate %d bytes of memory for C64 image encoding buffer.\n",
+        return dmError(DMERR_MALLOC,
+            "Could not allocate %d bytes of memory for C64 image encoding buffer.\n",
             allocated);
-        res = DMERR_MALLOC;
         goto error;
     }
 
@@ -918,10 +918,11 @@
         // Check size
         if (!dmC64GetOpSize(op, fmt, &size))
         {
-            dmError("Decode op SIZE out of bounds, op #%d type=%d, offs=%d ($%04x), "
+            res = dmError(DMERR_INVALID_DATA,
+                "Decode op SIZE out of bounds, op #%d type=%d, offs=%d ($%04x), "
                 "bank=%d, size=%d ($%04x) vs. allocated %d ($%04x)\n",
                 i, op->type, op->offs, op->offs, op->bank, size, size, op->size, op->size);
-            return DMERR_INVALID_DATA;
+            goto error;
         }
 
         // Do we need to reallocate some more space?
@@ -934,9 +935,9 @@
 
             if ((buf = dmRealloc(buf, allocated)) == NULL)
             {
-                dmError("Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n",
+                res = dmError(DMERR_MALLOC,
+                    "Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n",
                     allocated);
-                res = DMERR_MALLOC;
                 goto error;
             }
         }
@@ -963,28 +964,31 @@
                     case DC_D023: *dst = img->d023; break;
                     case DC_D024: *dst = img->d024; break;
                     default:
-                        dmError("Unhandled DT_COLOR_REG mode %d in ",
-                        "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
-                        op->size, i, op->offs, op->offs, op->bank, size, size, *plen, *plen);
-                        return DMERR_INTERNAL;
+                        res = dmError(DMERR_INTERNAL,
+                            "Unhandled DT_COLOR_REG mode %d in ",
+                            "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
+                            op->size, i, op->offs, op->offs, op->bank, size, size, *plen, *plen);
+                        goto error;
                 }
                 break;
 
             case DT_ENC_FUNCTION:
                 if (op->encfunction == NULL)
                 {
-                    dmError("Encode op is a function, but function ptr is NULL: "
+                    res = dmError(DMERR_INTERNAL,
+                        "Encode op is a function, but function ptr is NULL: "
                         "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
                         i, op->offs, op->offs, op->bank, size, size, *plen, *plen);
-                    return DMERR_INTERNAL;
+                    goto error;
                 }
                 /*
                 if (!op->encfunction(op, buf, len))
                 {
-                    dmError("Encode op custom function failed: op #%d, "
+                    res = dmError(DMERR_INTERNAL,
+                        "Encode op custom function failed: op #%d, "
                         "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
                         i, op->offs, op->offs, op->bank, size, size, len, len);
-                    return DMERR_INTERNAL;
+                    goto out;
                 }
                 */
                 break;