From: Christian Heller Date: Thu, 29 Aug 2013 20:49:48 +0000 (+0200) Subject: Read default order of windows from file config/toggle_win_order. X-Git-Tag: tce~1006 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bdb.prefix%7D%7D/static/%27%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28escapeHTML%28span%5B2%5D%29%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28%27?a=commitdiff_plain;h=385ac8287af0e5e5b5ab0539b47cda9b8dcbec58;p=plomrogue Read default order of windows from file config/toggle_win_order. --- diff --git a/src/main.c b/src/main.c index 6c60afa..06f53ab 100644 --- a/src/main.c +++ b/src/main.c @@ -220,10 +220,7 @@ int main(int argc, char *argv[]) struct Win win_map = init_win(&win_meta, "Map", 0, width_mapwin, &world, draw_map_win); world.wins.map = &win_map; - toggle_window(&win_meta, world.wins.keys); - toggle_window(&win_meta, world.wins.map); - toggle_window(&win_meta, world.wins.info); - toggle_window(&win_meta, world.wins.log); + sorted_wintoggle(&world); /* Replay mode. */ int key; diff --git a/src/wincontrol.c b/src/wincontrol.c index 4d166e8..acb6c56 100644 --- a/src/wincontrol.c +++ b/src/wincontrol.c @@ -1,11 +1,61 @@ /* wincontrol.c */ #include "wincontrol.h" -#include /* for uint8_t */ +#include /* for strlen() */ +#include /* for uint8_t, uint16_t */ #include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(), * resize_active_win(), struct Win, struct WinMeta */ #include "yx_uint16.h" /* for yx_uint16 struct */ +#include "main.h" /* for Wins struct */ +#include "misc.h" /* for textfile_sizes() */ +#include "rexit.h" /* for exit_err() */ +#include "main.h" /* for World, Wins structs */ + + + + +extern void sorted_wintoggle(struct World * world) +{ + char * err = "Trouble in sorted_wintoggle() with fopen() on file " + "'config/toggle_win_order'."; + FILE * file = fopen("config/toggle_win_order", "r"); + exit_err(NULL == file, world, err); + uint16_t linemax; + textfile_sizes(file, &linemax, NULL); + char win_order[linemax]; + err = "Trouble in sorted_wintoggle() with fgets() on file " + "'config/toggle_win_order'."; + exit_err(NULL == fgets(win_order, linemax, file), world, err); + err = "Trouble in sorted_wintoggle() with fclose() on file " + "'toggle_win_order'."; + exit_err(fclose(file), world, err); + + char c; + uint8_t i = 0; + for (; i < linemax; i++) + { + c = win_order[i]; + if ('k' == c) + { + toggle_window(world->wins.meta, world->wins.keys); + } + else if ('m' == c) + { + toggle_window(world->wins.meta, world->wins.map); + } + else if ('i' == c) + { + toggle_window(world->wins.meta, world->wins.info); + } + else if ('l' == c) + { + toggle_window(world->wins.meta, world->wins.log); + } + } +} + + extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win) diff --git a/src/wincontrol.h b/src/wincontrol.h index 18ac01c..017c18b 100644 --- a/src/wincontrol.h +++ b/src/wincontrol.h @@ -12,6 +12,15 @@ #include /* for uint8_t */ struct Win; struct WinMeta; +struct World; + + + +/* 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. + */ +extern void sorted_wintoggle(struct World * world);