diff tools/mod2wav.c @ 2565:d56a0e86067a

Improve error handling.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 28 Feb 2022 11:49:58 +0200
parents aacf3bd1cceb
children b205c60aa657
line wrap: on
line diff
--- a/tools/mod2wav.c	Mon Feb 28 10:18:38 2022 +0200
+++ b/tools/mod2wav.c	Mon Feb 28 11:49:58 2022 +0200
@@ -230,7 +230,7 @@
     JSSPlayer *plr = NULL;
     size_t bufLen = 1024*4, dataTotal, dataWritten, sampSize;
     Uint8 *dataBuf = NULL;
-    int res;
+    int res = DMERR_OK;
 
     dmInitProg("mod2wav", "XM/JSSMOD to WAV renderer", "0.2", NULL, NULL);
     dmVerbosity = 1;
@@ -238,18 +238,14 @@
     // Parse arguments
     if (!dmArgsProcess(argc, argv, optList, optListN,
         argHandleOpt, argHandleFile, OPTH_BAILOUT))
-    {
-        res = 1;
-        goto exit;
-    }
-
+        goto out;
 
     // Check arguments
     if (optInFilename == NULL || optOutFilename == NULL)
     {
         res = dmError(DMERR_INVALID_ARGS,
-            "Input or output file not specified. Try --help.\n");
-        goto exit;
+            "Input or output file not specified.\n");
+        goto out;
     }
 
     // Initialize miniJSS
@@ -260,7 +256,7 @@
     {
         dmErrorMsg("Error opening input file '%s': %s\n",
             optInFilename, dmErrorStr(res));
-        goto exit;
+        goto out;
     }
 
     // Read module file
@@ -296,7 +292,7 @@
     {
         dmErrorMsg("Error loading module file: %s\n",
             dmErrorStr(res));
-        goto exit;
+        goto out;
     }
 
     // Check if we have anything
@@ -304,7 +300,7 @@
     {
         res = dmError(DMERR_INIT_FAIL,
             "Could not load module file.\n");
-        goto exit;
+        goto out;
     }
 
     // Try to convert it
@@ -312,7 +308,7 @@
     {
         dmErrorMsg("Could not convert module for playing: %s\n",
             dmErrorStr(res));
-        goto exit;
+        goto out;
     }
 
     // Open mixer
@@ -321,7 +317,7 @@
     {
         res = dmError(DMERR_INIT_FAIL,
             "jvmInit() returned NULL\n");
-        goto exit;
+        goto out;
     }
 
     sampSize = jvmGetSampleSize(dev);
@@ -329,7 +325,7 @@
     {
         res = dmError(DMERR_MALLOC,
             "Could not allocate mixing buffer.\n");
-        goto exit;
+        goto out;
     }
 
     dmMsg(1, "Using fmt=%d, bits=%d, channels=%d, freq=%d [%" DM_PRIu_SIZE_T " / sample]\n",
@@ -340,7 +336,7 @@
     if ((plr = jmpInit(dev)) == NULL)
     {
         dmErrorMsg("jmpInit() returned NULL.\n");
-        goto exit;
+        goto out;
     }
 
     // Set callback
@@ -375,7 +371,7 @@
         res = dmGetErrno();
         dmErrorMsg("Error opening output file '%s': %s.\n",
             optInFilename, dmErrorStr(res));
-        goto exit;
+        goto out;
     }
 
     // Write initial header
@@ -407,7 +403,7 @@
             {
                 res = dmError(DMERR_FWRITE,
                     "Error writing audio data!\n");
-                goto exit;
+                goto out;
             }
             dataTotal += dataWritten;
         }
@@ -421,7 +417,7 @@
     {
         res = dmError(DMERR_FSEEK,
             "Error rewinding to header position!\n");
-        goto exit;
+        goto out;
     }
 
     dmWriteWAVHeader(outFile, jvmGetSampleRes(dev), optOutFreq, optOutChannels, dataTotal);
@@ -429,7 +425,7 @@
     // Done!
     dmMsg(1, "OK.\n");
 
-exit:
+out:
     if (outFile != NULL)
         fclose(outFile);