Somewhat improve code uniformity.
[neverball] / ball / main.c
index e2ccc61..3e22d45 100644 (file)
@@ -286,8 +286,9 @@ static void parse_args(int argc, char **argv)
 int main(int argc, char *argv[])
 {
     SDL_Joystick *joy = NULL;
-    int t1, t0;               /* ticks */
-    SDL_Surface *icon;        /* WM icon */
+    SDL_Surface *icon;
+
+    int t1, t0;
 
     language_init("neverball", CONFIG_LOCALE);
 
@@ -314,17 +315,14 @@ int main(int argc, char *argv[])
 
     language_set(language_from_code(config_simple_get_s(CONFIG_LANG)));
 
-    /* Prepare run without sdl */
+    /* Prepare run without SDL */
 
-    if (replay_path != NULL)
+    if (replay_path)
     {
         if (!level_replay(replay_path))
         {
-            fprintf(stderr, _("Replay file '%s': "), replay_path);
-            if (errno)
-                perror(NULL);
-            else
-                fprintf(stderr, _("Not a replay file\n"));
+            fprintf(stderr, _("Replay file '%s':  %s\n"), replay_path,
+                    errno ? strerror(errno) : _("Not a replay file"));
             return 1;
         }
         else if (display_info)
@@ -398,6 +396,16 @@ int main(int argc, char *argv[])
     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,  16);
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
 
+    /* Set the WM icon */
+
+    icon = IMG_Load(config_data("icon/neverball.png"));
+
+    if (icon)
+    {
+        SDL_WM_SetIcon(icon, NULL);
+        SDL_FreeSurface(icon);
+    }
+
     /* Initialize the video. */
 
     if (!config_mode(config_get_d(CONFIG_FULLSCREEN),
@@ -407,19 +415,17 @@ int main(int argc, char *argv[])
         return 1;
     }
 
-    /* Set the WM icon */
-
-    icon = IMG_Load(config_data("icon/neverball.png"));
-    SDL_WM_SetIcon(icon, NULL);
     SDL_WM_SetCaption(TITLE, TITLE);
 
     /* Initialize the run state. */
 
     init_state(&st_null);
-    if (replay_path != NULL)
+
+    if (replay_path)
     {
         level_replay(replay_path);
-        goto_demo_play(1);
+        demo_play_goto(1);
+        goto_state(&st_demo_play);
     }
     else if (level_path != NULL)
     {