home · contact · privacy
Read in initial window sizes from files below config/.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 29 Aug 2013 22:55:38 +0000 (00:55 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 29 Aug 2013 22:55:38 +0000 (00:55 +0200)
config/Win_Info [new file with mode: 0644]
config/Win_Keys [new file with mode: 0644]
config/Win_Log [new file with mode: 0644]
config/Win_Map [new file with mode: 0644]
src/main.c
src/wincontrol.c
src/wincontrol.h

diff --git a/config/Win_Info b/config/Win_Info
new file mode 100644 (file)
index 0000000..5ebcc55
--- /dev/null
@@ -0,0 +1,2 @@
+3
+20
diff --git a/config/Win_Keys b/config/Win_Keys
new file mode 100644 (file)
index 0000000..8defa01
--- /dev/null
@@ -0,0 +1,2 @@
+0
+29
diff --git a/config/Win_Log b/config/Win_Log
new file mode 100644 (file)
index 0000000..245603a
--- /dev/null
@@ -0,0 +1,2 @@
+-4
+20
diff --git a/config/Win_Map b/config/Win_Map
new file mode 100644 (file)
index 0000000..7ed456a
--- /dev/null
@@ -0,0 +1,2 @@
+0
+-51
index f637aea1558ddcd8884db86c3c2f5d929ac0a342..bd25c4fcdd840244a72577ce78e9c912a11880bc 100644 (file)
@@ -204,18 +204,14 @@ int main(int argc, char *argv[])
                         "main().";
     exit_err(init_win_meta(screen, &win_meta), &world, err_winmem);
     world.wins.meta = &win_meta;
-    struct Win win_keys = init_win(&win_meta,
-                                   "Keys", 0,  29, &world, draw_keys_win);
-    struct Win win_info = init_win(&win_meta,
-                                   "Info", 3,  20, &world, draw_info_win);
-    struct Win win_log  = init_win(&win_meta,
-                                  "Log",  -4,  20, &world, draw_log_win);
-    struct Win win_map  = init_win(&win_meta,
-                                  "Map",   0, -51, &world, draw_map_win);
+    struct Win win_keys = init_win_from_file(&world, "Keys", draw_keys_win);
+    struct Win win_info = init_win_from_file(&world, "Info", draw_info_win);
+    struct Win win_log  = init_win_from_file(&world, "Log",  draw_log_win);
+    struct Win win_map  = init_win_from_file(&world, "Map",  draw_map_win);
     world.wins.keys = &win_keys;
-    world.wins.log = &win_log;
+    world.wins.log  = &win_log;
     world.wins.info = &win_info;
-    world.wins.map = &win_map;
+    world.wins.map  = &win_map;
     sorted_wintoggle(&world);
 
     /* Replay mode. */
index acb6c566cf02ea055544535d6117a6dc6ad5a9a8..4ebf9ef666a308d9fb6c5c5c94b3be8f9cfd7eee 100644 (file)
@@ -1,10 +1,11 @@
 /* wincontrol.c */
 
 #include "wincontrol.h"
+#include <stdlib.h> /* for malloc(), free() */
 #include <string.h> /* for strlen() */
 #include <stdint.h> /* for uint8_t, uint16_t */
 #include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(),
-                      * resize_active_win(), struct Win, struct WinMeta
+                      * resize_active_win(), init_win(), structs Win, WinMeta
                       */
 #include "yx_uint16.h" /* for yx_uint16 struct */
 #include "main.h" /* for Wins struct */
 
 
 
+extern struct Win init_win_from_file(struct World * world, char * w_name,
+                                     void (* f) (struct Win *))
+{
+    char * err = "Trouble in init_win_from_file() with malloc().";
+    char * prefix = "config/Win_";
+    uint8_t size = strlen(prefix) + strlen(w_name) + 1;
+    char * path = malloc(size);
+    exit_err(NULL == path, world, err);
+    sprintf(path, "%s%s", prefix, w_name);
+
+    err = "Trouble in init_win_from_file() with fopen().";
+    FILE * file = fopen(path, "r");
+    free(path);
+    exit_err(NULL == file, world, err);
+    uint16_t linemax;
+    textfile_sizes(file, &linemax, NULL);
+    char * line = malloc(linemax);
+    err = "Trouble in init_win_from_file() with fgets().";
+    exit_err(NULL == fgets(line, linemax, file), world, err);
+    int16_t height = atoi(line);
+    exit_err(NULL == fgets(line, linemax, file), world, err);
+    int16_t width = atoi(line);
+    free(line);
+    err = "Trouble in init_win_from_file() with fclose().";
+    exit_err(fclose(file), world, err);
+
+    struct WinMeta * wmeta = world->wins.meta;
+    return init_win(wmeta, w_name, height, width, world, f);
+}
+
+
 
 extern void sorted_wintoggle(struct World * world)
 {
index 017c18b677e7224b8c87d4fb80a849ce823dd61e..33c3b76f397296f1fd2774245c2b7d297c3bd749 100644 (file)
@@ -16,6 +16,16 @@ struct World;
 
 
 
+/* Wrapper around init_win() that reads the desired window size from a file
+ * at the path prefixing the provided win name "w_name" with "config/Win_".
+ * "f" is the window drawing function (Win._draw()).
+ */
+extern struct Win init_win_from_file(struct World * world, char * w_name,
+                                     void (* f) (struct Win *));
+
+
+
+
 /* Toggle windows in world->wins in the order desribed by the first line of
  * config/toggled_win_order, wherein each character may correspond to one
  * hardcoded window.