calling them also fits the window config into a new terminal screen size.
/* src/client/cleanup.c */
#include "cleanup.h"
+#include <ncurses.h> /* for endwin() */
#include <stdint.h> /* uint32_t */
#include <stdlib.h> /* free() */
#include "command_db.h" /* free_command_db() */
#include "misc.h" /* unload_interface_conf() */
-#include "windows.h" /* free_winmeta_and_endwin() */
#include "world.h" /* world global */
free(world.map.cells);
free(world.log);
free(world.player_inventory);
- if (cleanup_flags & CLEANUP_INTERFACE)/* Must come pre ncurses cleanup, */
- { /* for by closing all windows it */
- unload_interface_conf(); /* relies on world.wmeta data freed */
- } /* by free_winmeta_and_endwin(). */
+ if (cleanup_flags & CLEANUP_INTERFACE)
+ {
+ unload_interface_conf();
+ }
if (cleanup_flags & CLEANUP_NCURSES)
{
- free_winmeta_and_endwin();
+ endwin();
}
if (cleanup_flags & CLEANUP_COMMANDS)
{
#include "command_db.h" /* init_command_db() */
#include "io.h" /* io_loop(), try_send() */
#include "misc.h" /* load_interface_conf() */
-#include "windows.h" /* init_win_meta(); */
+#include "windows.h" /* init_wmeta_and_ncurses(); */
#include "world.h" /* struct World */
set_cleanup_func(cleanup);
/* Initialize the whole interface. */
- init_win_meta();
+ init_wmeta_and_ncurses();
keypad(world.wmeta.screen, TRUE);
init_command_db(); /* The command DB needs to be initialized before */
load_interface_conf(); /* the interface, whose keybindings depend on it. */
/* src/client/misc.c */
#include "misc.h"
-#include <stdint.h> /* uint8_t, uint16_t */
+#include <ncurses.h> /* delwin(), getmaxy(), getmaxx(), newpad() */
+#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
+#include "../common/rexit.h" /* exit_err() */
#include "cleanup.h" /* for set_cleanup_flag() */
#include "keybindings.h" /* init_keybindings(), free_keybindings(),
* save_keybindings()
init_keybindings("confclient/keybindings_wingeom", &world.kb_wingeom);
init_keybindings("confclient/keybindings_winkeys", &world.kb_winkeys);
init_winconfs();
+ char * err_s = "load_interface_conf() makes illegaly large virtual screen.";
+ char * err_m = "load_interface_conf(): memory alloc error via newpad().";
+ uint32_t maxy_test = getmaxy(world.wmeta.screen);
+ uint32_t maxx_test = getmaxx(world.wmeta.screen);
+ exit_err(maxy_test > UINT16_MAX || maxx_test > UINT16_MAX, err_s);
+ world.wmeta.padsize.y = maxy_test;
+ world.wmeta.padsize.x = maxx_test;
+ world.wmeta.pad = newpad(world.wmeta.padsize.y, 1);
+ exit_err(NULL == world.wmeta.pad, err_m);
init_wins();
sorted_wintoggle_and_activate();
set_cleanup_flag(CLEANUP_INTERFACE);
suspend_win(world.wmeta.active);
}
free_winconfs();
+ delwin(world.wmeta.pad);
}
-/* Save / load / unload (free) / reload interface configuration data. */
+/* Save / load (init) / unload (free/dissolve) / reload interface configuration
+ * data, world.wmeta.pad (initialized before opening any windows to the height
+ * of the terminal screen and a width of 1) and window chains.
+ */
extern void save_interface_conf();
extern void load_interface_conf();
extern void unload_interface_conf();
#include <stdio.h> /* sprintf() */
#include <stdlib.h> /* free() */
#include <string.h> /* strlen(), memcpy(), strnlen() */
-#include <ncurses.h> /* pnoutrefresh(), doupdate(), werase(), wnoutrefresh(),
- * erase(), getmaxx(), getmaxy(), delwin(), endwin(),
- * initscr(), noecho(), curs_set(), newpad(), mvwaddch(),
- * mvwaddstr(), wresize(), chtype
+#include <ncurses.h> /* chtype, pnoutrefresh(), doupdate(), werase(), erase(),
+ * wnoutrefresh(), getmaxx(), getmaxy(), initscr(),
+ * noecho(), curs_set(), newpad(), mvwaddch(), mvwaddstr(),
+ * wresize()
*/
#include "../common/rexit.h" /* for exit_err() */
#include "../common/try_malloc.h" /* for try_malloc() */
-extern void init_win_meta()
+extern void init_wmeta_and_ncurses()
{
- char * err_s = "init_win_meta() creates virtual screen beyond legal size.";
- char * err_m = "init_win_meta() triggers memory alloc error via newpad().";
world.wmeta.screen = initscr();
set_cleanup_flag(CLEANUP_NCURSES);
noecho();
curs_set(0);
- uint32_t maxy_test = getmaxy(world.wmeta.screen);
- uint32_t maxx_test = getmaxx(world.wmeta.screen);
- exit_err(maxy_test > UINT16_MAX || maxx_test > UINT16_MAX, err_s);
- world.wmeta.padsize.y = maxy_test;
- world.wmeta.padsize.x = maxx_test;
+ world.wmeta.padsize.y = 0;
+ world.wmeta.padsize.x = 0;
world.wmeta.chain_start = 0;
world.wmeta.chain_end = 0;
world.wmeta.pad_offset = 0;
- world.wmeta.pad = newpad(world.wmeta.padsize.y, 1);
- exit_err(NULL == world.wmeta.pad, err_m);
+ world.wmeta.pad = NULL;
world.wmeta.active = 0;
}
-extern void free_winmeta_and_endwin()
-{
- delwin(world.wmeta.pad);
- endwin();
-}
-
-
-
extern void free_win(struct Win * win)
{
free(win->title);
-/* Initialize ncurses and world.wmeta on terminal screen. All struct members
- * initialize to 0, except for .screen, the newly created virtual screen .pad
- * and its .padsize (height: that of the terminal screen; width: 1 cell).
+/* Initialize world.wmeta and ncurses on terminal screen. All struct members
+ * initialize to 0 (.pad = NULL), except for .screen (= initscr()).
*/
-extern void init_win_meta();
+extern void init_wmeta_and_ncurses();
/* Initialize a Win child "wp" of "wmeta" to "title", "height" and "width" and
* appoint "func"() as its .draw. Initialize other members to 0.
extern void init_win(struct Win ** wp, char * title, int16_t height,
int16_t width, void * func);
-/* Free memory initialized below world.wmeta and run endwin(). */
-extern void free_winmeta_and_endwin();
-
/* Free memory initianized Win structs. */
extern void free_win(struct Win * win);