home · contact · privacy
Moved textfile_sizes() to readwrite library.
[plomrogue] / src / keybindings.c
index 6fabea65ed499074ef9deb3e65077e8572f0ab64..75fe72826a3ec15cbf642afedac05d08ea90b364 100644 (file)
@@ -3,27 +3,28 @@
 
 
 #include "keybindings.h"
-#include <stdlib.h>  /* for malloc(), free(), atoi() */
-#include <stdint.h>  /* for uint16_t */
-#include <ncurses.h> /* for keycode defines in get_keyname() */
-#include <string.h>  /* for strchr(), strlen(), strcmp(), memcpy()*/
-#include "windows.h" /* for draw_all_wins() and WinMeta struct */
-#include "misc.h"    /* for texfile_sizes() */
-#include "main.h"    /* for World struct */
-#include "rexit.h"   /* for err_exit() */
+#include <stdlib.h>    /* for malloc(), free(), atoi() */
+#include <stdint.h>    /* for uint16_t */
+#include <ncurses.h>   /* for keycode defines in get_keyname() */
+#include <string.h>    /* for strchr(), strlen(), strcmp(), memcpy()*/
+#include "windows.h"   /* for draw_all_wins() and WinMeta struct */
+#include "readwrite.h" /* for texfile_sizes() */
+#include "main.h"      /* for World struct */
+#include "rexit.h"     /* for err_exit() */
 
 
 
 extern void init_keybindings(struct World * world)
 {
-    FILE * file = fopen("keybindings", "r");
+    FILE * file = fopen("config/keybindings", "r");
     uint16_t lines, linemax;
-    textfile_sizes(file, &linemax, &lines);
+    char * err = "textfile_sizes() in init_keybindings() returns error.";
+    exit_err(textfile_sizes(file, &linemax, &lines), world, err);
     struct KeyBinding * keybindings = malloc(lines * sizeof(struct KeyBinding));
-    char * command = malloc(linemax);
+    char * command = malloc(linemax + 1);
     uint16_t commcount = 0;
     char * cmdptr;
-    while (fgets(command, linemax, file))
+    while (fgets(command, linemax + 1, file))
     {
         keybindings[commcount].key = atoi(command);
         cmdptr = strchr(command, ' ') + 1;
@@ -49,7 +50,7 @@ extern void save_keybindings(struct World * world)
     struct KeysWinData * keyswindata = (struct KeysWinData *)
                                        world->keyswindata;
     struct KeyBinding * keybindings = world->keybindings;
-    FILE * file = fopen("keybindings", "w");
+    FILE * file = fopen("config/keybindings", "w");
     uint16_t linemax = 0;
     uint16_t i;
     for (i = 0; i <= keyswindata->max; i++)