diff tools/gfxconv.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 ff18d2511843
children 6d5edc6af2ad
line wrap: on
line diff
--- a/tools/gfxconv.c	Fri Feb 27 02:21:57 2015 +0200
+++ b/tools/gfxconv.c	Fri Feb 27 03:58:25 2015 +0200
@@ -320,7 +320,7 @@
 
     if ((end = split = strchr(opt, ':')) == NULL)
     {
-        dmError("Invalid %s value '%s', expected <(#|%)RRGGBB|[$|0x]index>:<[$|0x]index>.\n", msg, opt);
+        dmErrorMsg("Invalid %s value '%s', expected <(#|%)RRGGBB|[$|0x]index>:<[$|0x]index>.\n", msg, opt);
         goto error;
     }
 
@@ -344,7 +344,7 @@
         if (sscanf(opt + 1, "%2x%2x%2x", &colR, &colG, &colB) != 3 &&
             sscanf(opt + 1, "%2X%2X%2X", &colR, &colG, &colB) != 3)
         {
-            dmError("Invalid %s value '%s', expected a hex triplet, got '%s'.\n", msg, popt, opt + 1);
+            dmErrorMsg("Invalid %s value '%s', expected a hex triplet, got '%s'.\n", msg, popt, opt + 1);
             goto error;
         }
 
@@ -357,7 +357,7 @@
     {
         if (!dmGetIntVal(opt, &value->from))
         {
-            dmError("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt);
+            dmErrorMsg("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt);
             goto error;
         }
         value->triplet = FALSE;
@@ -370,19 +370,19 @@
     // Parse destination value
     if (!dmGetIntVal(split, &value->to))
     {
-        dmError("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split);
+        dmErrorMsg("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split);
         goto error;
     }
 
     if (!value->triplet && value->from > 255)
     {
-        dmError("Invalid %s map source color index value %d, must be [0..255].\n", msg, value->from);
+        dmErrorMsg("Invalid %s map source color index value %d, must be [0..255].\n", msg, value->from);
         goto error;
     }
 
     if (value->to > nmax)
     {
-        dmError("Invalid %s map destination color index value %d, must be [0..%d].\n", msg, value->to, nmax);
+        dmErrorMsg("Invalid %s map destination color index value %d, must be [0..%d].\n", msg, value->to, nmax);
         goto error;
     }
 
@@ -419,13 +419,13 @@
         char *split = strchr(opt, ':');
         if (split != NULL)
         {
-            dmError("Unexpected ':' in indexed %s '%s'.\n", msg, opt);
+            dmErrorMsg("Unexpected ':' in indexed %s '%s'.\n", msg, opt);
             return FALSE;
         }
 
         if (!dmGetIntVal(opt, &value[index]))
         {
-            dmError("Invalid %s value '%s', could not parse.\n", msg, opt);
+            dmErrorMsg("Invalid %s value '%s', could not parse.\n", msg, opt);
             return FALSE;
         }
     }
@@ -467,7 +467,7 @@
     if ((fp = fopen(filename, "r")) == NULL)
     {
         res = dmGetErrno();
-        dmError("Could not open color remap file '%s' for reading, %d: %s\n",
+        dmErrorMsg("Could not open color remap file '%s' for reading, %d: %s\n",
             res, dmErrorStr(res));
         return res;
     }
@@ -486,7 +486,7 @@
                 (*nvalue)++;
                 if (*nvalue >= nmax)
                 {
-                    dmError("Too many mapping pairs in '%s', maximum is %d.\n",
+                    dmErrorMsg("Too many mapping pairs in '%s', maximum is %d.\n",
                         filename, nmax);
                     goto error;
                 }
@@ -527,7 +527,7 @@
                     case 'b': optInFormat = FFMT_BITMAP; break;
                     case 'i': optInFormat = FFMT_IMAGE; break;
                     default:
-                        dmError("Invalid input format '%s'.\n", optArg);
+                        dmErrorMsg("Invalid input format '%s'.\n", optArg);
                         return FALSE;
                 }
             
@@ -546,7 +546,7 @@
                                 optInMulticolor = FALSE;
                             else
                             {
-                                dmError("Invalid input subformat for sprite/char: '%s', should be 'mc' or 'sc'.\n",
+                                dmErrorMsg("Invalid input subformat for sprite/char: '%s', should be 'mc' or 'sc'.\n",
                                     tmp);
                                 return FALSE;
                             }
@@ -555,7 +555,7 @@
                         case FFMT_BITMAP:
                             if (!dmGetC64FormatByExt(tmp, &optInFormat, &optInSubFormat))
                             {
-                                dmError("Invalid bitmap subformat '%s', see format list for valid bformats.\n",
+                                dmErrorMsg("Invalid bitmap subformat '%s', see format list for valid bformats.\n",
                                     tmp);
                                 return FALSE;
                             }
@@ -576,7 +576,7 @@
         case 4:
             if (!dmGetIntVal(optArg, &optInSkip))
             {
-                dmError("Invalid skip value argument '%s'.\n", optArg);
+                dmErrorMsg("Invalid skip value argument '%s'.\n", optArg);
                 return FALSE;
             }
             break;
@@ -585,7 +585,7 @@
             if (!dmGetFormatByExt(optArg, &optOutFormat, &optOutSubFormat) &&
                 !dmGetC64FormatByExt(optArg, &optOutFormat, &optOutSubFormat))
             {
-                dmError("Invalid output format '%s'.\n", optArg);
+                dmErrorMsg("Invalid output format '%s'.\n", optArg);
                 return FALSE;
             }
             break;
@@ -611,7 +611,7 @@
         case 7:
             if (sscanf(optArg, "%d", &optItemCount) != 1)
             {
-                dmError("Invalid count value argument '%s'.\n", optArg);
+                dmErrorMsg("Invalid count value argument '%s'.\n", optArg);
                 return FALSE;
             }
             break;
@@ -627,18 +627,18 @@
                     optSpec.scaleY = optSpec.scaleX;
                 else
                 {
-                    dmError("Invalid scale option value '%s', should be <n> or <w>:<h>.\n", optArg);
+                    dmErrorMsg("Invalid scale option value '%s', should be <n> or <w>:<h>.\n", optArg);
                     return FALSE;
                 }
             }
             if (optSpec.scaleX < 1 || optSpec.scaleX > 50)
             {
-                dmError("Invalid X scale value '%d'.\n", optSpec.scaleX);
+                dmErrorMsg("Invalid X scale value '%d'.\n", optSpec.scaleX);
                 return FALSE;
             }
             if (optSpec.scaleY < 1 || optSpec.scaleY > 50)
             {
-                dmError("Invalid Y scale value '%d'.\n", optSpec.scaleY);
+                dmErrorMsg("Invalid Y scale value '%d'.\n", optSpec.scaleY);
                 return FALSE;
             }
             break;
@@ -646,12 +646,12 @@
         case 11:
             if (sscanf(optArg, "%d", &optPlanedWidth) != 1)
             {
-                dmError("Invalid planed width value argument '%s'.\n", optArg);
+                dmErrorMsg("Invalid planed width value argument '%s'.\n", optArg);
                 return FALSE;
             }
             if (optPlanedWidth < 1 || optPlanedWidth > 512)
             {
-                dmError("Invalid planed width value '%d' [1..512].\n", optPlanedWidth);
+                dmErrorMsg("Invalid planed width value '%d' [1..512].\n", optPlanedWidth);
                 return FALSE;
             }
             break;
@@ -665,7 +665,7 @@
                 int tmp = atoi(optArg);
                 if (tmp < 1 || tmp > 8)
                 {
-                    dmError("Invalid bitplanes/bpp value '%s'.\n", optArg);
+                    dmErrorMsg("Invalid bitplanes/bpp value '%s'.\n", optArg);
                     return FALSE;
                 }
                 optSpec.nplanes = tmp;
@@ -696,7 +696,7 @@
                     }
                     else
                     {
-                        dmError("No remap filename given.\n");
+                        dmErrorMsg("No remap filename given.\n");
                         return FALSE;
                     }
                 }
@@ -738,14 +738,14 @@
                 }
                 else
                 {
-                    dmError("Invalid crop mode / argument '%s'.\n", optArg);
+                    dmErrorMsg("Invalid crop mode / argument '%s'.\n", optArg);
                     return FALSE;
                 }
             }
             break;
 
         default:
-            dmError("Unknown option '%s'.\n", currArg);
+            dmErrorMsg("Unknown option '%s'.\n", currArg);
             return FALSE;
     }
 
@@ -759,7 +759,7 @@
         optInFilename = currArg;
     else
     {
-        dmError("Source filename already specified, extraneous argument '%s'.\n",
+        dmErrorMsg("Source filename already specified, extraneous argument '%s'.\n",
              currArg);
         return FALSE;
     }
@@ -865,7 +865,7 @@
 
     if (npal == NULL || mapping == NULL || mapped == NULL || used == NULL)
     {
-        dmError("Could not allocate memory for reused palette.\n");
+        dmErrorMsg("Could not allocate memory for reused palette.\n");
         return DMERR_MALLOC;
     }
 
@@ -1040,7 +1040,7 @@
     if ((outFile = fopen(filename, "wb")) == NULL)
     {
         res = dmGetErrno();
-        dmError("Error opening output file '%s', %d: %s\n",
+        dmErrorMsg("Error opening output file '%s', %d: %s\n",
             filename, res, dmErrorStr(res));
         goto error;
     }
@@ -1048,7 +1048,7 @@
     if (!dm_fwrite_str(outFile, buf, bufSize))
     {
         res = dmGetErrno();
-        dmError("Error writing image data to '%s', %d: %s\n",
+        dmErrorMsg("Error writing image data to '%s', %d: %s\n",
             filename, res, dmErrorStr(res));
     }
 
@@ -1110,7 +1110,7 @@
 
                 // Open data file for writing
                 if ((fp = fopen(dataFilename, "w")) == NULL)
-                    dmError("Could not create '%s'.\n", dataFilename);
+                    dmErrorMsg("Could not create '%s'.\n", dataFilename);
 
                 dmFree(dataFilename);
 
@@ -1271,14 +1271,14 @@
 
         default:
             ret = DMERR_INVALID_ARGS;
-            dmError("Invalid output format %d, internal error.\n", outFormat);
+            dmErrorMsg("Invalid output format %d, internal error.\n", outFormat);
             goto error;
     }
 
     if (outBlockW < 1 || outBlockH < 1)
     {
         ret = DMERR_INVALID_ARGS;
-        dmError("Source image dimensions too small for conversion, block dimensions %d x %d.\n",
+        dmErrorMsg("Source image dimensions too small for conversion, block dimensions %d x %d.\n",
             outBlockW, outBlockH);
         goto error;
     }
@@ -1286,14 +1286,14 @@
     if ((outFile = fopen(filename, "wb")) == NULL)
     {
         ret = dmGetErrno();
-        dmError("Could not open '%s' for writing, %d: %s.\n",
+        dmErrorMsg("Could not open '%s' for writing, %d: %s.\n",
             filename, ret, dmErrorStr(ret));
         goto error;
     }
 
     if ((buf = dmMalloc(outBufSize)) == NULL)
     {
-        dmError("Could not allocate %d bytes for conversion buffer.\n",
+        dmErrorMsg("Could not allocate %d bytes for conversion buffer.\n",
             outBufSize);
         goto error;
     }
@@ -1330,7 +1330,7 @@
         if (!dm_fwrite_str(outFile, buf, outBufSize))
         {
             ret = dmGetErrno();
-            dmError("Error writing data block %d,%d to '%s', %d: %s\n",
+            dmErrorMsg("Error writing data block %d,%d to '%s', %d: %s\n",
                 bx, by, filename, ret, dmErrorStr(ret));
             goto error;
         }
@@ -1371,13 +1371,13 @@
             break;
 
         default:
-            dmError("Invalid input format %d, internal error.\n", optInFormat);
+            dmErrorMsg("Invalid input format %d, internal error.\n", optInFormat);
             return -1;
     }
 
     if ((bufData = dmMalloc(bufSize)) == NULL)
     {
-        dmError("Could not allocate temporary buffer of %d bytes.\n", bufSize);
+        dmErrorMsg("Could not allocate temporary buffer of %d bytes.\n", bufSize);
         return -2;
     }
 
@@ -1396,7 +1396,7 @@
         if ((outFile = fopen(optOutFilename, "w")) == NULL)
         {
             int res = dmGetErrno();
-            dmError("Error opening output file '%s', %d: %s\n",
+            dmErrorMsg("Error opening output file '%s', %d: %s\n",
                   optOutFilename, res, dmErrorStr(res));
             goto error;
         }
@@ -1407,7 +1407,7 @@
 
             if (fread(bufData, 1, bufSize, inFile) != bufSize)
             {
-                dmError("Could not read full bufferful (%d bytes) of data at 0x%x.\n",
+                dmErrorMsg("Could not read full bufferful (%d bytes) of data at 0x%x.\n",
                     bufSize, dataOffs);
                 error = TRUE;
             }
@@ -1439,7 +1439,7 @@
         {
             if (optOutFilename == NULL)
             {
-                dmError("Sequential image output requires filename template.\n");
+                dmErrorMsg("Sequential image output requires filename template.\n");
                 goto error;
             }
 
@@ -1454,7 +1454,7 @@
             int outIWidth, outIHeight;
             if (optItemCount <= 0)
             {
-                dmError("Single-image output requires count to be set (-n).\n");
+                dmErrorMsg("Single-image output requires count to be set (-n).\n");
                 goto error;
             }
             
@@ -1477,7 +1477,7 @@
 
             if (fread(bufData, 1, bufSize, inFile) != bufSize)
             {
-                dmError("Could not read full bufferful (%d bytes) of data at 0x%x.\n",
+                dmErrorMsg("Could not read full bufferful (%d bytes) of data at 0x%x.\n",
                     bufSize, dataOffs);
                 break;
             }
@@ -1485,7 +1485,7 @@
             if ((err = dmC64ConvertCSDataToImage(outImage, outX * outWidthPX, outY * outHeight,
                 bufData, outWidth, outHeight, optInMulticolor, optColors)) != DMERR_OK)
             {
-                dmError("Internal error in conversion of raw data to bitmap: %d.\n", err);
+                dmErrorMsg("Internal error in conversion of raw data to bitmap: %d.\n", err);
                 break;
             }
 
@@ -1496,14 +1496,14 @@
                 outFilename = dm_strdup_printf("%s%04d.%s", optOutFilename, itemCount, convFormatList[optOutFormat].fext);
                 if (outFilename == NULL)
                 {
-                    dmError("Could not allocate memory for filename template?\n");
+                    dmErrorMsg("Could not allocate memory for filename template?\n");
                     goto error;
                 }
                 
                 eres = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE);
                 if (eres != DMERR_OK)
                 {
-                    dmError("Error writing output image, %s.\n",
+                    dmErrorMsg("Error writing output image, %s.\n",
                         dmErrorStr(eres));
                 }
 
@@ -1526,7 +1526,7 @@
             int eres = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE);
             if (eres != DMERR_OK)
             {
-                dmError("Error writing output image, %s.\n",
+                dmErrorMsg("Error writing output image, %s.\n",
                     dmErrorStr(eres));
             }
         }
@@ -1538,7 +1538,7 @@
     {
         if (optSequential)
         {
-            dmError("Sequential output not supported for spr/char -> bitmap conversion.\n");
+            dmErrorMsg("Sequential output not supported for spr/char -> bitmap conversion.\n");
             goto error;
         }
     }
@@ -1575,7 +1575,7 @@
 #ifndef DM_USE_LIBPNG
     if (optOutFormat == IMGFMT_PNG)
     {
-        dmError("PNG output format support not compiled in, sorry.\n");
+        dmErrorMsg("PNG output format support not compiled in, sorry.\n");
         goto error;
     }
 #endif
@@ -1596,8 +1596,8 @@
     {
         if (optInFormat == FFMT_AUTO)
         {
-            dmError("Standard input cannot be used without specifying input format.\n");
-            dmError("Perhaps you should try using --help\n");
+            dmErrorMsg("Standard input cannot be used without specifying input format.\n");
+            dmErrorMsg("Perhaps you should try using --help\n");
             goto error;
         }
         inFile = stdin;
@@ -1606,7 +1606,7 @@
     if ((inFile = fopen(optInFilename, "rb")) == NULL)
     {
         int res = dmGetErrno();
-        dmError("Error opening input file '%s', %d: %s\n",
+        dmErrorMsg("Error opening input file '%s', %d: %s\n",
               optInFilename, res, dmErrorStr(res));
         goto error;
     }
@@ -1638,7 +1638,7 @@
             optInFormat = FFMT_BITMAP;
         else
         {
-            dmError("Could not decode input image.\n");
+            dmErrorMsg("Could not decode input image.\n");
             exit(3);
         }
     }
@@ -1658,7 +1658,7 @@
 
     if (optInFormat == FFMT_AUTO)
     {
-        dmError("No input format specified, and could not be determined automatically.\n");
+        dmErrorMsg("No input format specified, and could not be determined automatically.\n");
         exit(1);
     }
 
@@ -1666,7 +1666,7 @@
     if (fseek(inFile, optInSkip, SEEK_SET) != 0)
     {
         int res = dmGetErrno();
-        dmError("Could not seek to file position %d (0x%x): %s\n",
+        dmErrorMsg("Could not seek to file position %d (0x%x): %s\n",
             optInSkip, optInSkip, dmErrorStr(res));
         goto error;
     }
@@ -1702,7 +1702,7 @@
 
                 if (optOutFilename == NULL)
                 {
-                    dmError("Output filename not set, required for bitmap formats.\n");
+                    dmErrorMsg("Output filename not set, required for bitmap formats.\n");
                     goto error;
                 }
 
@@ -1713,7 +1713,7 @@
 
                         if (res != DMERR_OK || outImage == NULL)
                         {
-                            dmError("Error in bitmap to image conversion.\n");
+                            dmErrorMsg("Error in bitmap to image conversion.\n");
                             goto error;
                         }
 
@@ -1731,7 +1731,7 @@
 
                         if (res != DMERR_OK || outImage == NULL)
                         {
-                            dmError("Error in bitmap to template image conversion.\n");
+                            dmErrorMsg("Error in bitmap to template image conversion.\n");
                             goto error;
                         }
 
@@ -1739,7 +1739,7 @@
                         break;
 
                     default:
-                        dmError("Unsupported output format for bitmap/image conversion.\n");
+                        dmErrorMsg("Unsupported output format for bitmap/image conversion.\n");
                         break;
                 }
                 
@@ -1754,7 +1754,7 @@
 
                 if (optOutFilename == NULL)
                 {
-                    dmError("Output filename not set, required for image formats.\n");
+                    dmErrorMsg("Output filename not set, required for image formats.\n");
                     goto error;
                 }
 
@@ -1763,7 +1763,7 @@
                 if (ifmt->readFILE != NULL)
                     res = ifmt->readFILE(inFile, &outImage);
                 else
-                    dmError("Unsupported input image format for bitmap/image conversion.\n");
+                    dmErrorMsg("Unsupported input image format for bitmap/image conversion.\n");
 
                 if (res != DMERR_OK || outImage == NULL)
                     break;
@@ -1780,13 +1780,13 @@
                         break;
 
                     default:
-                        dmError("Unsupported output format for bitmap/image conversion.\n");
+                        dmErrorMsg("Unsupported output format for bitmap/image conversion.\n");
                         break;
                 }
 
                 if (res != DMERR_OK)
                 {
-                    dmError("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n",
+                    dmErrorMsg("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n",
                         dmErrorStr(res));
                 }