Read the first 5 chars, not the all string of LANG.
[supertux.git] / src / configfile.cpp
index df637ec..503dea1 100644 (file)
@@ -17,8 +17,9 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
-#include <stdlib.h>
+#include <cstdlib>
 #include <string>
+
 #include "configfile.h"
 #include "setup.h"
 #include "globals.h"
@@ -74,42 +75,43 @@ void loadconfig(void)
 
   LispReader reader(lisp_cdr(root_obj));
 
-  reader.read_bool("fullscreen", &use_fullscreen);
-  reader.read_bool("sound",      &use_sound);
-  reader.read_bool("music",      &use_music);
-  reader.read_bool("show_fps",   &show_fps);
+  reader.read_bool("fullscreen", use_fullscreen);
+  reader.read_bool("sound",      use_sound);
+  reader.read_bool("music",      use_music);
+  reader.read_bool("show_fps",   show_fps);
 
   std::string video;
-  reader.read_string ("video", &video);
+  reader.read_string ("video", video);
   if (video == "opengl")
     use_gl = true;
   else
     use_gl = false;
 
-  reader.read_int ("joystick", &joystick_num);
-  if (!(joystick_num >= 0))
-    use_joystick = false;
-  else
-    use_joystick = true;
-
-  reader.read_int ("joystick-x", &joystick_keymap.x_axis);
-  reader.read_int ("joystick-y", &joystick_keymap.y_axis);
-  reader.read_int ("joystick-a", &joystick_keymap.a_button);
-  reader.read_int ("joystick-b", &joystick_keymap.b_button);
-  reader.read_int ("joystick-start", &joystick_keymap.start_button);
-  reader.read_int ("joystick-deadzone", &joystick_keymap.dead_zone);
-
-  reader.read_int ("keyboard-jump", &keymap.jump);
-  reader.read_int ("keyboard-duck", &keymap.duck);
-  reader.read_int ("keyboard-left", &keymap.left);
-  reader.read_int ("keyboard-right", &keymap.right);
-  reader.read_int ("keyboard-fire", &keymap.fire);
+  reader.read_int ("joystick", joystick_num);
+
+  if (joystick_num >= 0)
+    {
+    reader.read_int ("joystick-x", joystick_keymap.x_axis);
+    reader.read_int ("joystick-y", joystick_keymap.y_axis);
+    reader.read_int ("joystick-a", joystick_keymap.a_button);
+    reader.read_int ("joystick-b", joystick_keymap.b_button);
+    reader.read_int ("joystick-start", joystick_keymap.start_button);
+    reader.read_int ("joystick-deadzone", joystick_keymap.dead_zone);
+    }
+
+  reader.read_int ("keyboard-jump", keymap.jump);
+  reader.read_int ("keyboard-activate", keymap.activate);
+  reader.read_int ("keyboard-duck", keymap.duck);
+  reader.read_int ("keyboard-left", keymap.left);
+  reader.read_int ("keyboard-right", keymap.right);
+  reader.read_int ("keyboard-fire", keymap.fire);
+
+  lisp_free(root_obj);
 }
 
 void saveconfig (void)
 {
   /* write settings to config file */
-
   FILE * config = opendata(config_filename, "w");
 
   if(config)
@@ -124,21 +126,25 @@ void saveconfig (void)
       fprintf(config, "\n\t;; either \"opengl\" or \"sdl\"\n");
       fprintf(config, "\t(video      \"%s\")\n", use_gl ? "opengl" : "sdl");
 
-      fprintf(config, "\n\t;; joystick number (-1 means no joystick):\n");
-      fprintf(config, "\t(joystick   %d)\n", use_joystick ? joystick_num : -1);
+      if(use_joystick)
+        {
+        fprintf(config, "\n\t;; joystick number:\n");
+        fprintf(config, "\t(joystick   %d)\n", joystick_num);
 
-      fprintf(config, "\t(joystick-x   %d)\n", joystick_keymap.x_axis);
-      fprintf(config, "\t(joystick-y   %d)\n", joystick_keymap.y_axis);
-      fprintf(config, "\t(joystick-a   %d)\n", joystick_keymap.a_button);
-      fprintf(config, "\t(joystick-b   %d)\n", joystick_keymap.b_button);
-      fprintf(config, "\t(joystick-start  %d)\n", joystick_keymap.start_button);
-      fprintf(config, "\t(joystick-deadzone  %d)\n", joystick_keymap.dead_zone);
+        fprintf(config, "\t(joystick-x   %d)\n", joystick_keymap.x_axis);
+        fprintf(config, "\t(joystick-y   %d)\n", joystick_keymap.y_axis);
+        fprintf(config, "\t(joystick-a   %d)\n", joystick_keymap.a_button);
+        fprintf(config, "\t(joystick-b   %d)\n", joystick_keymap.b_button);
+        fprintf(config, "\t(joystick-start  %d)\n", joystick_keymap.start_button);
+        fprintf(config, "\t(joystick-deadzone  %d)\n", joystick_keymap.dead_zone);
+        }
 
       fprintf(config, "\t(keyboard-jump  %d)\n", keymap.jump);
       fprintf(config, "\t(keyboard-duck  %d)\n", keymap.duck);
       fprintf(config, "\t(keyboard-left  %d)\n", keymap.left);
       fprintf(config, "\t(keyboard-right %d)\n", keymap.right);
       fprintf(config, "\t(keyboard-fire  %d)\n", keymap.fire);
+      fprintf(config, "\t(keyboard-activate  %d)\n", keymap.activate);
 
       fprintf(config, ")\n");
     }