"main().";
exit_err(init_win_meta(screen, &win_meta), &world, err_winmem);
world.wins.meta = &win_meta;
- struct Win win_keys = init_win_from_file(&world, "Keys", draw_keys_win);
- world.wins.keys = &win_keys;
+ world.wins.keys = init_win_from_file(&world, "Keys", draw_keys_win);
set_cleanup_flag(CLEANUP_WIN_KEYS);
- struct Win win_info = init_win_from_file(&world, "Info", draw_info_win);
- world.wins.info = &win_info;
+ world.wins.info = init_win_from_file(&world, "Info", draw_info_win);
set_cleanup_flag(CLEANUP_WIN_INFO);
- struct Win win_log = init_win_from_file(&world, "Log", draw_log_win);
- world.wins.log = &win_log;
+ world.wins.log = init_win_from_file(&world, "Log", draw_log_win);
set_cleanup_flag(CLEANUP_WIN_LOG);
- struct Win win_map = init_win_from_file(&world, "Map", draw_map_win);
- world.wins.map = &win_map;
+ world.wins.map = init_win_from_file(&world, "Map", draw_map_win);
set_cleanup_flag(CLEANUP_WIN_MAP);
sorted_wintoggle(&world);
#include "keybindings.h" /* for KeysWinData, KeyBinding structs */
#include "command_db.h" /* for free_command_db() */
#include "windows.h" /* for Win struct */
+#include "wincontrol.h" /* for free_win() */
}
if (cleanup_flags & CLEANUP_WIN_INFO)
{
- free(world->wins.info->_title);
+ free_win(world->wins.info);
}
if (cleanup_flags & CLEANUP_WIN_MAP)
{
- free(world->wins.map->_title);
+ free_win(world->wins.map);
}
if (cleanup_flags & CLEANUP_WIN_LOG)
{
- free(world->wins.log->_title);
+ free_win(world->wins.log);
}
if (cleanup_flags & CLEANUP_WIN_KEYS)
{
- free(world->wins.keys->_title);
+ free_win(world->wins.keys);
}
}
-extern struct Win init_win_from_file(struct World * world, char * w_name,
- void (* f) (struct Win *))
+extern void free_win(struct Win * win)
+{
+ free(win->_title);
+ free(win);
+}
+
+
+
+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/windows/";
exit_err(fclose(file), world, err);
struct WinMeta * wmeta = world->wins.meta;
- struct Win w;
- init_win(wmeta, &w, title, height, width, world, f);
+ struct Win * w = malloc(sizeof(struct Win));
+ init_win(wmeta, w, title, height, width, world, f);
free(title);
return w;
}
+/* Free allocated memory for an initialized Win struct. */
+extern void free_win(struct Win * win);
+
+
+
+
/* Wrapper around init_win() that reads the desired window size and title from a
* file at the path prefixing the provided win name "w_name" with
* "config/windows/". "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 *));
+extern struct Win * init_win_from_file(struct World * world, char * w_name,
+ void (* f) (struct Win *));