[Tux4kids-tuxtype-dev] [Patch] Add and check a return value to LoadSettings()

Jerome Portal jerome.portal.2 at gmail.com
Fri Apr 12 13:15:35 UTC 2013


Hello,

I read a FIXME in src/main.c talking about missing return values, so I
added what was needed to the LoadSettings() function, that didn't check
itself the return value of the function it calls. I don't exit the main if
it fails as it was the previous behaviour of the program, and not having a
setting file isn't a real problem with the use of default values :

>From dd9e77ef531c4010e4dddb5859e303d495e40726 Mon Sep 17 00:00:00 2001
From: Jerome Portal <jerome.portal.2 at gmail.com>
Date: Fri, 12 Apr 2013 15:03:18 +0200
Subject: [PATCH 2/2] Add and check a return value to LoadSettings().

---
 src/funcs.h |    2 +-
 src/main.c  |    5 ++++-
 src/setup.c |   10 ++++++++--
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/funcs.h b/src/funcs.h
index cfe8a73..0a16332 100644
--- a/src/funcs.h
+++ b/src/funcs.h
@@ -108,7 +108,7 @@ void InstructLaser(void);
 /* In setup.c: */
 void GraphicsInit(void);
 void LibInit(Uint32 lib_flags);
-void LoadSettings(void);
+int LoadSettings(void);
 void SaveSettings(void);
 int SetupPaths(const char* theme_dir);
 void Cleanup(void);
diff --git a/src/main.c b/src/main.c
index 34b2d6c..feb5201 100644
--- a/src/main.c
+++ b/src/main.c
@@ -55,7 +55,10 @@ int main(int argc, char *argv[])
     fprintf(stderr, "Error - SetupPaths() failed, exiting program.\n");
     return 0;
   }
-  LoadSettings();    // Second, read saved any saved settings
+  if (!LoadSettings())    // Second, read saved any saved settings
+  {
+    fprintf(stderr, "Warning - LoadSettings() failed, continuing with
default settings.\n");
+  }

   // Third, check command line args as these should override saved settings
   if (argc > 1) /* FIXME this could go into something like
HandleCommandArgs() */
diff --git a/src/setup.c b/src/setup.c
index 7e5ca3b..47a5e89 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -226,7 +226,7 @@ void LibInit(Uint32 lib_flags)
 /* Load the settings from a file... make sure to update SaveSettings if
you change
  *  what can be saved/loaded
  */
-void LoadSettings(void)
+int LoadSettings(void)
 {
   char fn[FNLEN];
 //     char setting[FNLEN];
@@ -249,7 +249,13 @@ void LoadSettings(void)

   LOG("LoadSettings: trying to open settings file\n");

-  load_settings_filename(fn);
+  if (load_settings_filename(fn) != 1)
+  {
+    fprintf(stderr, "LoadSettings: Failed to load settings\n");
+    return 0;
+  }
+
+  return 1;
 }


-- 
1.7.9.5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/tux4kids-tuxtype-dev/attachments/20130412/e3c35cd2/attachment.html>


More information about the Tux4kids-tuxtype-dev mailing list