changeset 1199:a79edf59d5d8

Improve use of probing in dumpmod, mod2wav and ppl.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Mar 2015 16:22:11 +0200
parents 5d20c80df290
children 1587a2f0a2bc
files tools/dumpmod.c tools/mod2wav.c tools/ppl.c
diffstat 3 files changed, 43 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/tools/dumpmod.c	Thu Mar 05 16:14:40 2015 +0200
+++ b/tools/dumpmod.c	Thu Mar 05 16:22:11 2015 +0200
@@ -438,24 +438,36 @@
     // Read module file
     dmMsg(1, "Reading file: %s\n", optFilename);
 #ifdef JSS_SUP_XM
-    dmMsg(1, "* Trying XM...\n");
     result = jssLoadXM(file, &mod, TRUE);
 #endif
 #ifdef JSS_SUP_JSSMOD
-    if (result != 0)
+    dmfreset(file);
+    if (result != DMERR_OK)
     {
-        dmfseek(file, 0L, SEEK_SET);
         dmMsg(1, "* Trying JSSMOD ...\n");
         result = jssLoadJSSMOD(file, &mod, TRUE);
+        dmfreset(file);
+        if (result == DMERR_OK)
+            result = jssLoadJSSMOD(file, &mod, FALSE);
+    }
+    else
+    {
+        dmMsg(2, "* Trying XM...\n");
+        result = jssLoadXM(file, &mod, FALSE);
     }
 #endif
     dmf_close(file);
+
+    // Check for errors, we still might have some data tho
     if (result != DMERR_OK)
     {
         dmErrorMsg("Error loading module file, %d: %s\n",
             result, dmErrorStr(result));
+    }
+
+    // Check if we have anything
+    if (mod == NULL)
         return 3;
-    }
 
     // Print out information
     if (optViewGeneralInfo)
--- a/tools/mod2wav.c	Thu Mar 05 16:14:40 2015 +0200
+++ b/tools/mod2wav.c	Thu Mar 05 16:22:11 2015 +0200
@@ -161,26 +161,38 @@
     }
 
     // Read module file
-    fprintf(stderr, "Reading file: %s\n", optInFilename);
+    dmMsg(1, "Reading file: %s\n", optInFilename);
 #ifdef JSS_SUP_XM
-    fprintf(stderr, "* Trying XM...\n");
     result = jssLoadXM(inFile, &mod, TRUE);
 #endif
 #ifdef JSS_SUP_JSSMOD
-    if (result != 0)
+    dmfreset(inFile);
+    if (result != DMERR_OK)
     {
-        dmfseek(inFile, 0L, SEEK_SET);
         dmMsg(1, "* Trying JSSMOD ...\n");
         result = jssLoadJSSMOD(inFile, &mod, TRUE);
+        dmfreset(inFile);
+        if (result == DMERR_OK)
+            result = jssLoadJSSMOD(inFile, &mod, FALSE);
+    }
+    else
+    {
+        dmMsg(2, "* Trying XM...\n");
+        result = jssLoadXM(inFile, &mod, FALSE);
     }
 #endif
     dmf_close(inFile);
+
+    // Check for errors, we still might have some data tho
     if (result != DMERR_OK)
     {
         dmErrorMsg("Error loading module file, %d: %s\n",
             result, dmErrorStr(result));
+    }
+
+    // Check if we have anything
+    if (mod == NULL)
         return 3;
-    }
 
     // Try to convert it
     if ((result = jssConvertModuleForPlaying(mod)) != DMERR_OK)
--- a/tools/ppl.c	Thu Mar 05 16:14:40 2015 +0200
+++ b/tools/ppl.c	Thu Mar 05 16:22:11 2015 +0200
@@ -588,15 +588,22 @@
     // Read module file
     dmMsg(1, "Reading file: %s\n", optFilename);
 #ifdef JSS_SUP_XM
-    dmMsg(2, "* Trying XM...\n");
     result = jssLoadXM(file, &engine.mod, TRUE);
 #endif
 #ifdef JSS_SUP_JSSMOD
-    if (result != 0)
+    dmfreset(file);
+    if (result != DMERR_OK)
     {
-        dmfseek(file, 0L, SEEK_SET);
         dmMsg(1, "* Trying JSSMOD ...\n");
         result = jssLoadJSSMOD(file, &engine.mod, TRUE);
+        dmfreset(file);
+        if (result == DMERR_OK)
+            result = jssLoadJSSMOD(file, &engine.mod, FALSE);
+    }
+    else
+    {
+        dmMsg(2, "* Trying XM...\n");
+        result = jssLoadXM(file, &engine.mod, FALSE);
     }
 #endif
     dmf_close(file);