diff src/dmsimple.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 2c6b092328be
children b7c01d4ca984
line wrap: on
line diff
--- a/src/dmsimple.c	Fri Feb 27 02:21:57 2015 +0200
+++ b/src/dmsimple.c	Fri Feb 27 03:58:25 2015 +0200
@@ -53,7 +53,8 @@
             break;
         
         default:
-            dmError("Unknown option '%s'.\n", currArg);
+            dmError(DMERR_INTERNAL,
+                "Unknown option '%s'.\n", currArg);
             return FALSE;
     }
     
@@ -124,7 +125,8 @@
     engine.screen = SDL_SetVideoMode(width, height, depth, flags);
     if (engine.screen == NULL)
     {
-        dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
+        dmError(DMERR_INIT_FAIL,
+            "Can't SDL_SetVideoMode(): %s\n", SDL_GetError());
         return FALSE;
     }
 
@@ -257,8 +259,8 @@
             sscanf(str, "textEnterToStart %s", engine.setupTextEnterToStart) != 1
             )
         {
-            dmError("Syntax error in configuration:\n%s\n", buf);
-            res = DMERR_INVALID_DATA;
+            res = dmError(DMERR_INVALID_DATA,
+                "Syntax error in configuration:\n%s\n", buf);
             goto out;
         }
     }
@@ -296,7 +298,8 @@
     SDL_Rect **modes = SDL_ListModes(engine.screen->format, engine.screen->flags | SDL_FULLSCREEN);
     if (modes == (SDL_Rect**) 0)
     {
-        dmError("No compatible video resolutions/depths available at all. Bailing out.\n");
+        dmError(DMERR_INIT_FAIL,
+            "No compatible video resolutions/depths available at all. Bailing out.\n");
         goto out;
     }
     
@@ -310,7 +313,8 @@
 
     if (nengineModeList == 0)
     {
-        dmError("Umm, no modes found.\n");
+        dmError(DMERR_INIT_FAIL,
+            "Umm, no modes found.\n");
         goto out;
     }
 
@@ -363,7 +367,8 @@
 
     if (menuBgImage == NULL || menuBarImage == NULL)
     {
-        dmError("Could not instantiate setup screen images, %d: %s\n",
+        dmError(result,
+            "Could not instantiate setup screen images, %d: %s\n",
             result, dmErrorStr(result));
         goto out;
     }
@@ -371,7 +376,8 @@
     if (menuBgImage->w != DM_VSETUP_WIDTH ||
         menuBgImage->h != DM_VSETUP_HEIGHT)
     {
-        dmError("Setup screen background image does not match "
+        dmError(DMERR_INIT_FAIL,
+            "Setup screen background image does not match "
             "required dimensions (%dx%d vs %dx%d)\n",
             menuBgImage->w, menuBgImage->h,
             DM_VSETUP_WIDTH, DM_VSETUP_HEIGHT);
@@ -388,7 +394,8 @@
     }
     if (result != DMERR_OK)
     {
-        dmError("Could not instantiate setup screen font, %d: %s\n",
+        dmError(result,
+            "Could not instantiate setup screen font, %d: %s\n",
             result, dmErrorStr(result));
         goto out;
     }
@@ -398,7 +405,8 @@
         engine.screen->w, engine.screen->h);
     if (tmp == NULL)
     {
-        dmError("Could not convert setup screen background image.\n");
+        dmError(DMERR_MALLOC,
+            "Could not convert setup screen background image.\n");
         goto out;
     }
 
@@ -478,7 +486,7 @@
         engine.frameTime = SDL_GetTicks();
         if (SDL_MUSTLOCK(engine.screen) && SDL_LockSurface(engine.screen) != 0)
         {
-            dmError("Can't lock surface.\n");
+            dmError(DMERR_INTERNAL, "Can't lock surface.\n");
             goto out;
         }
 
@@ -610,7 +618,9 @@
     if ((err = dmResourcesInit(&engine.resources, engine.optPackFilename,
         engine.optDataPath, engine.optResFlags, engineClassifier)) != DMERR_OK)
     {
-        dmError("Could not initialize resource manager, #%d: %s.\n", err, dmErrorStr(err));
+        dmError(err,
+            "Could not initialize resource manager, #%d: %s.\n",
+            err, dmErrorStr(err));
         goto error_exit;
     }
 
@@ -618,7 +628,9 @@
     dmPrint(1, "Initializing libSDL.\n");
     if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
     {
-        dmError("Could not initialize SDL: %s\n", SDL_GetError());
+        dmError(DMERR_INIT_FAIL,
+            "Could not initialize SDL: %s\n",
+            SDL_GetError());
         goto error_exit;
     }
     initSDL = TRUE;
@@ -667,23 +679,25 @@
 
             if ((engine.jssDev = jvmInit(engine.jssFormat, engine.optAfmt.channels, engine.optAfmt.freq, JMIX_AUTO)) == NULL)
             {
-                dmError("jvmInit() returned NULL, voi perkele.\n");
+                dmError(DMERR_INIT_FAIL,
+                    "jvmInit() returned NULL, voi perkele.\n");
                 goto error_exit;
             }
 
             if ((engine.jssPlr = jmpInit(engine.jssDev)) == NULL)
             {
-                dmError("jmpInit() returned NULL\n");
+                dmError(DMERR_INIT_FAIL,
+                    "jmpInit() returned NULL\n");
                 goto error_exit;
             }
 #else
-            dmError("miniJSS support not included.\n");
+            dmError(DMERR_INTERNAL, "miniJSS support not included.\n");
 #endif
             break;
 
         case DM_ASETUP_TREMOR:
 #ifndef DM_USE_TREMOR
-            dmError("Tremor support not included.\n");
+            dmError(DMERR_INTERNAL, "Tremor support not included.\n");
 #endif
             break;
     }
@@ -695,7 +709,9 @@
 
     if ((err = engineInitAudioParts(&engine)) != DMERR_OK)
     {
-        dmError("engineInitAudioParts() failed: #%d: %s\n", err, dmErrorStr(err));
+        dmError(err,
+            "engineInitAudioParts() failed: #%d: %s\n",
+            err, dmErrorStr(err));
         goto error_exit;
     }
 
@@ -703,7 +719,9 @@
     if (engine.demoInitPreVideo != NULL &&
        (err = engine.demoInitPreVideo(&engine)) != DMERR_OK)
     {
-        dmError("demoInitPreVideo() failed, #%d: %s\n", err, dmErrorStr(err));
+        dmError(err,
+            "demoInitPreVideo() failed, #%d: %s\n",
+            err, dmErrorStr(err));
         goto error_exit;
     }
 
@@ -713,7 +731,9 @@
     if (engine.demoInitPostVideo != NULL &&
        (err = engine.demoInitPostVideo(&engine)) != DMERR_OK)
     {
-        dmError("demoInitPostVideo() failed, #%d: %s\n", err, dmErrorStr(err));
+        dmError(err,
+            "demoInitPostVideo() failed, #%d: %s\n",
+            err, dmErrorStr(err));
         goto error_exit;
     }
 
@@ -740,7 +760,8 @@
     // Initialize effects
     if ((err = engineInitializeEffects(&engine)) != DMERR_OK)
     {
-        dmError("Effects initialization failed, #%d: %s\n",
+        dmError(err,
+            "Effects initialization failed, #%d: %s\n",
             err, dmErrorStr(err));
         goto error_exit;
     }
@@ -751,14 +772,16 @@
     {
         if ((err = dmLoadTimeline(engine.timeline, &engine.tl)) != DMERR_OK)
         {
-            dmError("Error loading timeline, #%d: %s\n", err,
-                dmErrorStr(err));
+            dmError(err,
+                "Error loading timeline, #%d: %s\n",
+                err, dmErrorStr(err));
             goto error_exit;
         }
 
         if ((err = dmPrepareTimeline(engine.tl, engine.ptl)) != DMERR_OK)
         {
-            dmError("Error creating prepared timeline, #%d: %s\n",
+            dmError(err,
+                "Error creating prepared timeline, #%d: %s\n",
                 err, dmErrorStr(err));
             goto error_exit;
         }
@@ -833,7 +856,7 @@
 
         if (SDL_MUSTLOCK(engine.screen) && SDL_LockSurface(engine.screen) != 0)
         {
-            dmError("Can't lock surface.\n");
+            dmError(DMERR_INTERNAL, "Can't lock surface.\n");
             goto error_exit;
         }