From: Christian Heller Date: Sat, 2 Nov 2013 00:43:37 +0000 (+0100) Subject: Made single World struct a global variable, fitted a lot of code to this change,... X-Git-Tag: tce~937 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bdb.prefix%7D%7D/%7B%7Bprefix%7D%7D/todo?a=commitdiff_plain;h=7290dec4219eaa2325aa00ef6139f715743dba3a;p=plomrogue Made single World struct a global variable, fitted a lot of code to this change, on the way corrected some minor stylistic issues. --- diff --git a/src/command_db.c b/src/command_db.c index d89319d..34db4dc 100644 --- a/src/command_db.c +++ b/src/command_db.c @@ -5,7 +5,7 @@ #include /* for FILE typedef, fgets() */ #include /* for uint8_t */ #include /* for strlen(), strtok() */ -#include "main.h" /* for World struct */ +#include "main.h" /* for world global */ #include "rexit.h" /* for exit_err() */ #include "readwrite.h" /* for textfile_sizes(), try_fopen(), try_fclose() */ #include "misc.h" /* for try_malloc() */ @@ -13,21 +13,23 @@ /* Build string pointed to by "ch_ptr" from next token delimited by "delim". */ -static void copy_tokenized_string(struct World * world, char ** ch_ptr, - char * delim) +static void copy_tokenized_string(char ** ch_ptr, char * delim); + + + +static void copy_tokenized_string(char ** ch_ptr, char * delim) { char * f_name = "copy_tokenized_string()"; char * dsc_ptr = strtok(NULL, delim); - * ch_ptr = try_malloc(strlen(dsc_ptr) + 1, world, f_name); + * ch_ptr = try_malloc(strlen(dsc_ptr) + 1, f_name); memcpy(* ch_ptr, dsc_ptr, strlen(dsc_ptr) + 1); } -extern uint8_t is_command_id_shortdsc(struct World * world, - uint8_t id, char * shortdsc) +extern uint8_t is_command_id_shortdsc(uint8_t id, char * shortdsc) { - struct Command * cmd_ptr = world->cmd_db->cmds; + struct Command * cmd_ptr = world.cmd_db->cmds; while (1) { if (id == cmd_ptr->id) @@ -44,9 +46,9 @@ extern uint8_t is_command_id_shortdsc(struct World * world, -extern uint8_t get_command_id(struct World * world, char * dsc_short) +extern uint8_t get_command_id(char * dsc_short) { - struct Command * cmd_ptr = world->cmd_db->cmds; + struct Command * cmd_ptr = world.cmd_db->cmds; while (1) { if (0 == strcmp(dsc_short, cmd_ptr->dsc_short)) @@ -59,9 +61,9 @@ extern uint8_t get_command_id(struct World * world, char * dsc_short) -extern char * get_command_longdsc(struct World * world, char * dsc_short) +extern char * get_command_longdsc(char * dsc_short) { - struct Command * cmd_ptr = world->cmd_db->cmds; + struct Command * cmd_ptr = world.cmd_db->cmds; while (1) { if (0 == strcmp(dsc_short, cmd_ptr->dsc_short)) @@ -74,19 +76,18 @@ extern char * get_command_longdsc(struct World * world, char * dsc_short) -extern void init_command_db(struct World * world) +extern void init_command_db() { char * f_name = "init_command_db()"; char * err_s = "Trouble in init_cmds() with textfile_sizes()."; char * path = "config/commands"; - FILE * file = try_fopen(path, "r", world, f_name); + FILE * file = try_fopen(path, "r", f_name); uint16_t lines, linemax; - exit_err(textfile_sizes(file, &linemax, &lines), world, err_s); + exit_err(textfile_sizes(file, &linemax, &lines), err_s); char line[linemax + 1]; - struct Command * cmds = try_malloc(lines * sizeof(struct Command), - world, f_name); + struct Command * cmds = try_malloc(lines * sizeof(struct Command), f_name); uint8_t i = 0; while (fgets(line, linemax + 1, file)) { @@ -95,28 +96,28 @@ extern void init_command_db(struct World * world) break; } cmds[i].id = atoi(strtok(line, " ")); - copy_tokenized_string(world, &cmds[i].dsc_short, " "); - copy_tokenized_string(world, &cmds[i].dsc_long, "\n"); + copy_tokenized_string(&cmds[i].dsc_short, " "); + copy_tokenized_string(&cmds[i].dsc_long, "\n"); i++; } - try_fclose(file, world, f_name); + try_fclose(file, f_name); - world->cmd_db = try_malloc(sizeof(struct CommandDB), world, f_name); - world->cmd_db->cmds = cmds; - world->cmd_db->n = lines; + world.cmd_db = try_malloc(sizeof(struct CommandDB), f_name); + world.cmd_db->cmds = cmds; + world.cmd_db->n = lines; } -extern void free_command_db(struct World * world) +extern void free_command_db() { uint8_t i = 0; - while (i < world->cmd_db->n) + while (i < world.cmd_db->n) { - free(world->cmd_db->cmds[i].dsc_short); - free(world->cmd_db->cmds[i].dsc_long); + free(world.cmd_db->cmds[i].dsc_short); + free(world.cmd_db->cmds[i].dsc_long); i++; } - free(world->cmd_db->cmds); - free(world->cmd_db); + free(world.cmd_db->cmds); + free(world.cmd_db); } diff --git a/src/command_db.h b/src/command_db.h index f0baef9..bbc60f4 100644 --- a/src/command_db.h +++ b/src/command_db.h @@ -8,10 +8,7 @@ #ifndef COMMAND_DB_H #define COMMAND_DB_H - - #include /* for uint8_t */ -struct World; @@ -31,22 +28,21 @@ struct CommandDB /* Is "id" the ID of command whose dsc_short is "shortdsc"? Answer in binary. */ -extern uint8_t is_command_id_shortdsc(struct World * world, - uint8_t id, char * shortdsc); +extern uint8_t is_command_id_shortdsc(uint8_t id, char * shortdsc); /* Give short description of command ("dsc_short"), get its ID. */ -extern uint8_t get_command_id(struct World * world, char * dsc_short); +extern uint8_t get_command_id(char * dsc_short); /* Give short description of command ("dsc_short"), get long description. */ -extern char * get_command_longdsc(struct World * world, char * dsc_short); +extern char * get_command_longdsc(char * dsc_short); /* Read in CommandDB from file "config/commands" to world.cmd_db. */ -extern void init_command_db(struct World * world); +extern void init_command_db(); /* Free all memory allocated with init_command_db. */ -extern void free_command_db(struct World * world); +extern void free_command_db(); diff --git a/src/control.c b/src/control.c index 504b0f5..c7c7b1b 100644 --- a/src/control.c +++ b/src/control.c @@ -9,7 +9,7 @@ * move_keyb_mod_selection() */ #include "map.h" /* for map_scroll() */ -#include "main.h" /* for World struct */ +#include "main.h" /* for world global */ #include "rexit.h" /* for exit_err() */ #include "wincontrol.h" /* for scroll_pad(), toggle_window(), * growshrink_active_window(), toggle_winconfig(), @@ -27,95 +27,94 @@ -extern uint16_t get_available_keycode_to_action(struct World * world, - char * name) +extern uint16_t get_available_keycode_to_action(char * name) { - uint16_t keycode = get_keycode_to_action(world->kb_global.kbs, name); - if (0 != keycode || 0 == world->wmeta->active) + uint16_t keycode = get_keycode_to_action(world.kb_global.kbs, name); + if (0 != keycode || 0 == world.wmeta->active) { return keycode; } - struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active); + struct WinConf * wc = get_winconf_by_win(world.wmeta->active); if (0 == wc->view) { keycode = get_keycode_to_action(wc->kb.kbs, name); } else if (1 == wc->view) { - keycode = get_keycode_to_action(world->kb_wingeom.kbs, name); + keycode = get_keycode_to_action(world.kb_wingeom.kbs, name); } else if (2 == wc->view) { - keycode = get_keycode_to_action(world->kb_winkeys.kbs, name); + keycode = get_keycode_to_action(world.kb_winkeys.kbs, name); } return keycode; } -extern void record_control(int action, struct World * world) +extern void record_control(int action) { - if (is_command_id_shortdsc(world, action, "wait")) + if (is_command_id_shortdsc(action, "wait")) { - player_wait(world); + player_wait(); } - else if (is_command_id_shortdsc(world, action, "player_u")) + else if (is_command_id_shortdsc(action, "player_u")) { - move_player(world, NORTH); + move_player(NORTH); } - else if (is_command_id_shortdsc(world, action, "player_r")) + else if (is_command_id_shortdsc(action, "player_r")) { - move_player(world, EAST); + move_player(EAST); } - else if (is_command_id_shortdsc(world, action, "player_d")) + else if (is_command_id_shortdsc(action, "player_d")) { - move_player(world, SOUTH); + move_player(SOUTH); } - else if (is_command_id_shortdsc(world, action, "player_l")) + else if (is_command_id_shortdsc(action, "player_l")) { - move_player(world, WEST); + move_player(WEST); } - else if (is_command_id_shortdsc(world, action, "drop")) + else if (is_command_id_shortdsc(action, "drop")) { - player_drop(world); + player_drop(); } - else if (is_command_id_shortdsc(world, action, "pick")) + else if (is_command_id_shortdsc(action, "pick")) { - player_pick(world); + player_pick(); } } -extern uint8_t player_control(int key, struct World * world) +extern uint8_t player_control(int key) { - if (key == get_available_keycode_to_action(world, "wait")) + if (key == get_available_keycode_to_action("wait")) { - player_wait(world); + player_wait(); } - else if (key == get_available_keycode_to_action(world, "player_u")) + else if (key == get_available_keycode_to_action("player_u")) { - move_player(world, NORTH); + move_player(NORTH); } - else if (key == get_available_keycode_to_action(world, "player_r")) + else if (key == get_available_keycode_to_action("player_r")) { - move_player(world, EAST); + move_player(EAST); } - else if (key == get_available_keycode_to_action(world, "player_d")) + else if (key == get_available_keycode_to_action("player_d")) { - move_player(world, SOUTH); + move_player(SOUTH); } - else if (key == get_available_keycode_to_action(world, "player_l")) + else if (key == get_available_keycode_to_action("player_l")) { - move_player(world, WEST); + move_player(WEST); } - else if (key == get_available_keycode_to_action(world, "drop")) + else if (key == get_available_keycode_to_action("drop")) { - player_drop(world); + player_drop(); } - else if (key == get_available_keycode_to_action(world, "pick")) + else if (key == get_available_keycode_to_action("pick")) { - player_pick(world); + player_pick(); } else { @@ -126,42 +125,42 @@ extern uint8_t player_control(int key, struct World * world) -extern uint8_t wingeom_control(int key, struct World * world) +extern uint8_t wingeom_control(int key) { char * err_shift = "Trouble with shift_active_win() in wingeom_control()."; char * err_resize = "Trouble with growshrink_active_window() in " "wingeom_control()."; - if (key == get_available_keycode_to_action(world, "to_height_t")) + if (key == get_available_keycode_to_action("to_height_t")) { - toggle_win_height_type(world, world->wmeta->active); + toggle_win_height_type(world.wmeta->active); } - else if (key == get_available_keycode_to_action(world, "to_width_t")) + else if (key == get_available_keycode_to_action("to_width_t")) { - toggle_win_width_type(world, world->wmeta->active); + toggle_win_width_type(world.wmeta->active); } - else if (key == get_available_keycode_to_action(world, "grow_h")) + else if (key == get_available_keycode_to_action("grow_h")) { - exit_err(growshrink_active_window(world, '*'), world, err_resize); + exit_err(growshrink_active_window('*'), err_resize); } - else if (key == get_available_keycode_to_action(world, "shri_h")) + else if (key == get_available_keycode_to_action("shri_h")) { - exit_err(growshrink_active_window(world, '_'), world, err_resize); + exit_err(growshrink_active_window('_'), err_resize); } - else if (key == get_available_keycode_to_action(world, "grow_v")) + else if (key == get_available_keycode_to_action("grow_v")) { - exit_err(growshrink_active_window(world, '+'), world, err_resize); + exit_err(growshrink_active_window('+'), err_resize); } - else if (key == get_available_keycode_to_action(world, "shri_v")) + else if (key == get_available_keycode_to_action("shri_v")) { - exit_err(growshrink_active_window(world, '-'), world, err_resize); + exit_err(growshrink_active_window('-'), err_resize); } - else if (key == get_available_keycode_to_action(world, "shift_f")) + else if (key == get_available_keycode_to_action("shift_f")) { - exit_err(shift_active_win(world->wmeta, 'f'), world, err_shift); + exit_err(shift_active_win(world.wmeta, 'f'), err_shift); } - else if (key == get_available_keycode_to_action(world, "shift_b")) + else if (key == get_available_keycode_to_action("shift_b")) { - exit_err(shift_active_win(world->wmeta, 'b'), world, err_shift); + exit_err(shift_active_win(world.wmeta, 'b'), err_shift); } else { @@ -172,20 +171,20 @@ extern uint8_t wingeom_control(int key, struct World * world) -extern uint8_t winkeyb_control(int key, struct World * world) +extern uint8_t winkeyb_control(int key) { - struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active); - if (key == get_available_keycode_to_action(world, "w_keys_u")) + struct WinConf * wc = get_winconf_by_win(world.wmeta->active); + if (key == get_available_keycode_to_action("w_keys_u")) { move_keyb_mod_selection(&wc->kb, 'u'); } - else if (key == get_available_keycode_to_action(world, "w_keys_d")) + else if (key == get_available_keycode_to_action("w_keys_d")) { move_keyb_mod_selection(&wc->kb, 'd'); } - else if (key == get_available_keycode_to_action(world, "w_keys_m")) + else if (key == get_available_keycode_to_action("w_keys_m")) { - mod_selected_keyb(world, &wc->kb); + mod_selected_keyb(&wc->kb); } else { @@ -196,151 +195,144 @@ extern uint8_t winkeyb_control(int key, struct World * world) -extern uint8_t meta_control(int key, struct World * world) +extern uint8_t meta_control(int key) { - struct WinMeta * win_meta = world->wmeta; - struct Win * win_map = get_win_by_id(world, 'm'); + struct WinMeta * win_meta = world.wmeta; + struct Win * win_map = get_win_by_id('m'); char * err_toggle = "Trouble with toggle_window() in meta_control()."; - if (key == get_available_keycode_to_action(world, "quit")) + if (key == get_available_keycode_to_action("quit")) { return 1; } - else if (key == get_available_keycode_to_action(world, "winconf")) + else if (key == get_available_keycode_to_action("winconf")) { - toggle_winconfig(world, world->wmeta->active); + toggle_winconfig(world.wmeta->active); } - else if (key == get_available_keycode_to_action(world, "cyc_win_f")) + else if (key == get_available_keycode_to_action("cyc_win_f")) { - cycle_active_win(world->wmeta, 'f'); + cycle_active_win(world.wmeta, 'f'); } - else if (key == get_available_keycode_to_action(world, "cyc_win_b")) + else if (key == get_available_keycode_to_action("cyc_win_b")) { - cycle_active_win(world->wmeta, 'b'); + cycle_active_win(world.wmeta, 'b'); } - else if (key == get_available_keycode_to_action(world, "scrl_r")) + else if (key == get_available_keycode_to_action("scrl_r")) { scroll_pad(win_meta, '+'); } - else if (key == get_available_keycode_to_action(world, "scrl_l")) + else if (key == get_available_keycode_to_action("scrl_l")) { scroll_pad(win_meta, '-'); } - else if (key == get_available_keycode_to_action(world, "to_a_keywin")) + else if (key == get_available_keycode_to_action("to_a_keywin")) { - uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'k')); - exit_err(test, world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('k')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_g_keywin")) + else if (key == get_available_keycode_to_action("to_g_keywin")) { - uint8_t test = toggle_window(win_meta, get_win_by_id(world, '0')); - exit_err(test, world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('0')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_wg_keywin")) + else if (key == get_available_keycode_to_action("to_wg_keywin")) { - uint8_t test = toggle_window(win_meta, get_win_by_id(world, '1')); - exit_err(test, world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('1')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_wk_keywin")) + else if (key == get_available_keycode_to_action("to_wk_keywin")) { - uint8_t test = toggle_window(win_meta, get_win_by_id(world, '2')); - exit_err(test, world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('2')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_mapwin")) + else if (key == get_available_keycode_to_action("to_mapwin")) { - exit_err(toggle_window(win_meta, win_map), world, err_toggle); + exit_err(toggle_window(win_meta, win_map), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_infowin")) + else if (key == get_available_keycode_to_action("to_infowin")) { - uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'i')); - exit_err(test, world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('i')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_inv")) + else if (key == get_available_keycode_to_action("to_inv")) { - uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'c')); - exit_err(test, world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('c')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_logwin")) + else if (key == get_available_keycode_to_action("to_logwin")) { - uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'l')); - exit_err(test, world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('l')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "save_conf")) + else if (key == get_available_keycode_to_action("save_conf")) { - save_interface_conf(world); + save_interface_conf(); } - else if (key == get_available_keycode_to_action(world, "g_keys_u")) + else if (key == get_available_keycode_to_action("g_keys_u")) { - move_keyb_mod_selection(&world->kb_global, 'u'); + move_keyb_mod_selection(&world.kb_global, 'u'); } - else if (key == get_available_keycode_to_action(world, "g_keys_d")) + else if (key == get_available_keycode_to_action("g_keys_d")) { - move_keyb_mod_selection(&world->kb_global, 'd'); + move_keyb_mod_selection(&world.kb_global, 'd'); } - else if (key == get_available_keycode_to_action(world, "g_keys_m")) + else if (key == get_available_keycode_to_action("g_keys_m")) { - mod_selected_keyb(world, &world->kb_global); + mod_selected_keyb(&world.kb_global); } - else if (key == get_available_keycode_to_action(world, "wg_keys_u")) + else if (key == get_available_keycode_to_action("wg_keys_u")) { - move_keyb_mod_selection(&world->kb_wingeom, 'u'); + move_keyb_mod_selection(&world.kb_wingeom, 'u'); } - else if (key == get_available_keycode_to_action(world, "wg_keys_d")) + else if (key == get_available_keycode_to_action("wg_keys_d")) { - move_keyb_mod_selection(&world->kb_wingeom, 'd'); + move_keyb_mod_selection(&world.kb_wingeom, 'd'); } - else if (key == get_available_keycode_to_action(world, "wg_keys_m")) + else if (key == get_available_keycode_to_action("wg_keys_m")) { - mod_selected_keyb(world, &world->kb_wingeom); + mod_selected_keyb(&world.kb_wingeom); } - else if (key == get_available_keycode_to_action(world, "wk_keys_u")) + else if (key == get_available_keycode_to_action("wk_keys_u")) { - move_keyb_mod_selection(&world->kb_winkeys, 'u'); + move_keyb_mod_selection(&world.kb_winkeys, 'u'); } - else if (key == get_available_keycode_to_action(world, "wk_keys_d")) + else if (key == get_available_keycode_to_action("wk_keys_d")) { - move_keyb_mod_selection(&world->kb_winkeys, 'd'); + move_keyb_mod_selection(&world.kb_winkeys, 'd'); } - else if (key == get_available_keycode_to_action(world, "wk_keys_m")) + else if (key == get_available_keycode_to_action("wk_keys_m")) { - mod_selected_keyb(world, &world->kb_winkeys); + mod_selected_keyb(&world.kb_winkeys); } - else if (key == get_available_keycode_to_action(world, "map_u")) + else if (key == get_available_keycode_to_action("map_u")) { - map_scroll(win_map, world->map->size, NORTH); + map_scroll(win_map, world.map->size, NORTH); } - else if (key == get_available_keycode_to_action(world, "map_d")) + else if (key == get_available_keycode_to_action("map_d")) { - map_scroll(win_map, world->map->size, SOUTH); + map_scroll(win_map, world.map->size, SOUTH); } - else if (key == get_available_keycode_to_action(world, "map_r")) + else if (key == get_available_keycode_to_action("map_r")) { - map_scroll(win_map, world->map->size, EAST); + map_scroll(win_map, world.map->size, EAST); } - else if (key == get_available_keycode_to_action(world, "map_l")) + else if (key == get_available_keycode_to_action("map_l")) { - map_scroll(win_map, world->map->size, WEST); + map_scroll(win_map, world.map->size, WEST); } - else if (key == get_available_keycode_to_action(world, "map_c")) + else if (key == get_available_keycode_to_action("map_c")) { - struct MapObj * player = get_player(world); + struct MapObj * player = get_player(); win_map->center = player->pos; } - else if (key == get_available_keycode_to_action(world, "inv_u")) + else if (key == get_available_keycode_to_action("inv_u")) { - nav_inventory(world, 'u'); + nav_inventory('u'); } - else if (key == get_available_keycode_to_action(world, "inv_d")) + else if (key == get_available_keycode_to_action("inv_d")) { - nav_inventory(world, 'd'); + nav_inventory('d'); } - else if (key == get_available_keycode_to_action(world, "reload_conf")) + else if (key == get_available_keycode_to_action("reload_conf")) { - unload_interface_conf(world); - load_interface_conf(world); + unload_interface_conf(); + load_interface_conf(); } - else if (key == get_available_keycode_to_action(world, "winconf")) + else if (key == get_available_keycode_to_action("winconf")) { - toggle_winconfig(world, world->wmeta->active); + toggle_winconfig(world.wmeta->active); } return 0; } diff --git a/src/control.h b/src/control.h index 470b026..889bdbf 100644 --- a/src/control.h +++ b/src/control.h @@ -6,31 +6,27 @@ #ifndef CONTROL_H #define CONTROL_H - - #include /* for uint8_t */ -struct World; /* Return keycode to action of "name" if available in current window config. */ -extern uint16_t get_available_keycode_to_action(struct World * world, - char * name); +extern uint16_t get_available_keycode_to_action(char * name); /* Control the player character, either via recorded "action" or pressed "key". */ -extern void record_control(int action, struct World * world); -extern uint8_t player_control(int key, struct World * world); +extern void record_control(int action); +extern uint8_t player_control(int key); /* Control via "key" active window's geometry / keybindings in respective config * view. */ -extern uint8_t wingeom_control(int key, struct World * world); -extern uint8_t winkeyb_control(int key, struct World * world); +extern uint8_t wingeom_control(int key); +extern uint8_t winkeyb_control(int key); @@ -38,7 +34,7 @@ extern uint8_t winkeyb_control(int key, struct World * world); * the player character. If the "quit" action is called, return 1 (instead of * exiting directly). */ -extern uint8_t meta_control(int key, struct World * world); +extern uint8_t meta_control(int key); diff --git a/src/draw_wins.c b/src/draw_wins.c index 106d73a..1549d13 100644 --- a/src/draw_wins.c +++ b/src/draw_wins.c @@ -12,7 +12,7 @@ * get_player() */ #include "map.h" /* for Map struct */ -#include "main.h" /* for World struct */ +#include "main.h" /* for world global */ #include "command_db.h" /* for get_command_longdesc() */ #include "wincontrol.h" /* for WinConf struct, get_winconf_by_win() */ @@ -21,8 +21,7 @@ /* Apply to the winmap of Win "w" the new sizes "new_size_y" and "new_size_x" * to the degree that they extend it. Re-shape the window content accordingly. */ -static void try_resize_winmap(struct World * world, struct Win * w, - int new_size_y, int new_size_x); +static void try_resize_winmap(struct Win * w, int new_size_y, int new_size_x); /* In Win "w", write "ch" to coordinate "y"/"x". */ static void set_ch_on_yx(struct Win * w, int y, int x, chtype ch); @@ -30,45 +29,39 @@ static void set_ch_on_yx(struct Win * w, int y, int x, chtype ch); /* Add "text" into window "win". Break text at right window edge. Also break at * newlines. */ -static void add_text_with_linebreaks(struct World * world, struct Win * win, - char * text); +static void add_text_with_linebreaks(struct Win * win, char * text); /* Add "line" into window "w". Apply ncurses attribute "attri" to all * characters drawn. If "fill" is non-zero, fill the entire line until the * right window edge with empty characters ("attri" also applied on these). */ -static void add_line(struct World * world, struct Win * w, char * line, - attr_t attri, uint8_t fill); +static void add_line(struct Win * w, char * line, attr_t attri, uint8_t fill); /* Write "text" with add_text_with_linebreaks() as not starting from the top but * from bottom of "win". Draw only what fits in window (avoid scroll hints). */ -static void draw_text_from_bottom(struct World * world, struct Win * win, - char * text); +static void draw_text_from_bottom(struct Win * win, char * text); /* Draw onto "map" in "win" the objects in the chain at "start". */ -static void draw_map_objects(struct World * world, struct MapObj * start, - struct Map * map, struct Win * win); +static void draw_map_objects(struct MapObj * start, struct Map * map, + struct Win * win); /* Return keybinding list line via "kb_pp", iterate pointer pointed to by it. */ -static char * get_kb_line_and_iterate(struct World * world, - struct KeyBinding ** kb_pp); +static char * get_kb_line_and_iterate(struct KeyBinding ** kb_pp); /* Draw from line "start" on config view for keybindings defined at "kb". */ -static void draw_kb_view(struct World * world, struct Win * w, - struct KeyBiData * kb, uint8_t start); +static void draw_kb_view(struct Win * w, struct KeyBiData * kb, uint8_t start); /* Draw into window "w" from line "start" on a "title" followed by an empty * line followed by a list of all keybindings starting at kb_p. */ -static uint16_t draw_titled_keybinding_list(struct World * world, char * title, - struct Win * w, uint16_t start, +static uint16_t draw_titled_keybinding_list(char * title, struct Win * w, + uint16_t start, struct KeyBinding * kb_p); -static void try_resize_winmap(struct World * world, struct Win * w, - int new_size_y, int new_size_x) +static void try_resize_winmap(struct Win * w, int new_size_y, int new_size_x) { char * f_name = "try_resize_winmap()"; if (w->winmapsize.y >= new_size_y && w->winmapsize.x >= new_size_x) @@ -85,7 +78,7 @@ static void try_resize_winmap(struct World * world, struct Win * w, } chtype * old_winmap = w->winmap; uint32_t new_size = sizeof(chtype) * new_size_y * new_size_x; - w->winmap = try_malloc(new_size, world, f_name); + w->winmap = try_malloc(new_size, f_name); uint16_t y, x; for (y = 0; y < new_size_y; y++) { @@ -113,14 +106,13 @@ static void set_ch_on_yx(struct Win * w, int y, int x, chtype ch) -static void add_text_with_linebreaks(struct World * world, struct Win * win, - char * text) +static void add_text_with_linebreaks(struct Win * win, char * text) { uint16_t x, y; int16_t z = -1; for (y = win->winmapsize.y; ; y++) { - try_resize_winmap(world, win, y + 1, win->framesize.x); + try_resize_winmap(win, y + 1, win->framesize.x); for (x = 0; x < win->framesize.x; x++) { z++; @@ -147,19 +139,18 @@ static void add_text_with_linebreaks(struct World * world, struct Win * win, -static void add_line(struct World * world, struct Win * w, char * line, - attr_t attri, uint8_t fill) +static void add_line(struct Win * w, char * line, attr_t attri, uint8_t fill) { uint16_t y = w->winmapsize.y; uint16_t len_line = strlen(line); if (0 != fill && w->winmapsize.x < w->framesize.x && w->framesize.x > len_line) { - try_resize_winmap(world, w, y + 1, w->framesize.x); + try_resize_winmap(w, y + 1, w->framesize.x); } else { - try_resize_winmap(world, w, y + 1, strlen(line)); + try_resize_winmap(w, y + 1, strlen(line)); } uint16_t x = 0; for (; x < len_line; x++) @@ -177,8 +168,7 @@ static void add_line(struct World * world, struct Win * w, char * line, -static void draw_text_from_bottom(struct World * world, struct Win * win, - char * text) +static void draw_text_from_bottom(struct Win * win, char * text) { /* Determine number of lines text would have in a window of win's width, * but infinite height. Treat \n and \0 as control chars for incrementing @@ -238,14 +228,14 @@ static void draw_text_from_bottom(struct World * world, struct Win * win, text = text + (sizeof(char) * (z + 1)); } - try_resize_winmap(world, win, start_y, 1); - add_text_with_linebreaks(world, win, text); + try_resize_winmap(win, start_y, 1); + add_text_with_linebreaks(win, text); } -static void draw_map_objects(struct World * world, struct MapObj * start, - struct Map * map, struct Win * win) +static void draw_map_objects(struct MapObj * start, struct Map * map, + struct Win * win) { struct MapObj * o; struct MapObjDef * d; @@ -258,7 +248,7 @@ static void draw_map_objects(struct World * world, struct MapObj * start, if (( (0 == i && 0 == o->lifepoints) /* Draw in-animate */ || (1 == i && 0 < o->lifepoints))) /* objects first. */ { - d = get_map_object_def(world, o->type); + d = get_map_object_def(o->type); c = d->char_on_map; set_ch_on_yx(win, o->pos.y, o->pos.x, c); } @@ -268,15 +258,14 @@ static void draw_map_objects(struct World * world, struct MapObj * start, -static char * get_kb_line_and_iterate(struct World * world, - struct KeyBinding ** kb_pp) +static char * get_kb_line_and_iterate(struct KeyBinding ** kb_pp) { char * f_name = "get_kb_line_and_iterate()"; struct KeyBinding * kb_p = * kb_pp; - char * keyname = get_name_to_keycode(world, kb_p->key); - char * cmd_dsc = get_command_longdsc(world, kb_p->name); + char * keyname = get_name_to_keycode(kb_p->key); + char * cmd_dsc = get_command_longdsc(kb_p->name); uint16_t size = 9 + 1 + strlen(cmd_dsc) + 1; - char * line = try_malloc(size, world, f_name); + char * line = try_malloc(size, f_name); sprintf(line, "%-9s %s", keyname, cmd_dsc); free(keyname); * kb_pp = kb_p->next; @@ -285,12 +274,11 @@ static char * get_kb_line_and_iterate(struct World * world, -static void draw_kb_view(struct World * world, struct Win * w, - struct KeyBiData * kb, uint8_t start) +static void draw_kb_view(struct Win * w, struct KeyBiData * kb, uint8_t start) { if (0 == kb->kbs) { - add_line(world, w, "(none)", 0, 0); + add_line(w, "(none)", 0, 0); return; } struct KeyBinding * kb_p = kb->kbs; @@ -306,16 +294,16 @@ static void draw_kb_view(struct World * world, struct Win * w, attri = attri | A_BLINK; } } - char * kb_line = get_kb_line_and_iterate(world, &kb_p); - add_line(world, w, kb_line, attri, 1); + char * kb_line = get_kb_line_and_iterate(&kb_p); + add_line(w, kb_line, attri, 1); free(kb_line); } } -static uint16_t draw_titled_keybinding_list(struct World * world, char * title, - struct Win * w, uint16_t start, +static uint16_t draw_titled_keybinding_list(char * title, struct Win * w, + uint16_t start, struct KeyBinding * kb_p) { uint16_t y; @@ -324,20 +312,20 @@ static uint16_t draw_titled_keybinding_list(struct World * world, char * title, { if (0 == state) { - add_line(world, w, title, 0, 0); + add_line(w, title, 0, 0); y++; - add_line(world, w, " ", 0, 0); + add_line(w, " ", 0, 0); state = 1 + (0 == kb_p); continue; } - char * kb_line = get_kb_line_and_iterate(world, &kb_p); - add_line(world, w, kb_line, 0, 0); + char * kb_line = get_kb_line_and_iterate(&kb_p); + add_line(w, kb_line, 0, 0); free(kb_line); } if (2 == state) { char * none = "(none)"; - add_line(world, w, none, 0, 0); + add_line(w, none, 0, 0); y++; } return y; @@ -347,18 +335,16 @@ static uint16_t draw_titled_keybinding_list(struct World * world, char * title, extern void draw_win_log(struct Win * win) { - struct World * world = (struct World *) win->data; - draw_text_from_bottom(world, win, world->log); + draw_text_from_bottom(win, world.log); } extern void draw_win_map(struct Win * win) { - struct World * world = (struct World *) win->data; - struct Map * map = world->map; + struct Map * map = world.map; char * cells = map->cells; - try_resize_winmap(world, win, map->size.y, map->size.x); + try_resize_winmap(win, map->size.y, map->size.x); uint16_t z = 0; uint16_t x, y; for (y = 0; y < map->size.y; y++) @@ -369,51 +355,49 @@ extern void draw_win_map(struct Win * win) z++; } } - draw_map_objects(world, world->map_objs, map, win); + draw_map_objects(world.map_objs, map, win); } extern void draw_win_info(struct Win * win) { - struct World * world = (struct World *) win->data; char * dsc_turn = "Turn: "; char * dsc_hitpoints = "\nHitpoints: "; char * dsc_score = "\nScore: "; uint16_t maxl = strlen(dsc_turn) + strlen(dsc_hitpoints) + strlen(dsc_score) + 10 + 5 + 10; /* max strlens of numbers to be used */ char text[maxl + 1]; - struct MapObj * player = get_player(world); + struct MapObj * player = get_player(); sprintf(text, "%s%d%s%d%s%d", - dsc_turn, world->turn, + dsc_turn, world.turn, dsc_hitpoints, player->lifepoints, - dsc_score, world->score); - add_text_with_linebreaks(world, win, text); + dsc_score, world.score); + add_text_with_linebreaks(win, text); } extern void draw_win_inventory(struct Win * win) { - struct World * world = (struct World *) win->data; - struct MapObj * player = get_player(world); + struct MapObj * player = get_player(); if (NULL == player->owns) { - add_line(world, win, "(none)", 0, 0); + add_line(win, "(none)", 0, 0); return; } - win->center.y = world->inventory_select; + win->center.y = world.inventory_select; struct MapObj * owned = player->owns; uint8_t y; for (y = 0; NULL != owned; y++) { attr_t attri = 0; - if (y == world->inventory_select) + if (y == world.inventory_select) { attri = A_REVERSE; } - struct MapObjDef * mod = get_map_object_def(world, owned->type); - add_line(world, win, mod->name, attri, 0); + struct MapObjDef * mod = get_map_object_def(owned->type); + add_line(win, mod->name, attri, 0); owned = owned->next; } } @@ -422,65 +406,60 @@ extern void draw_win_inventory(struct Win * win) extern void draw_win_available_keybindings(struct Win * win) { - struct World * world = (struct World *) win->data; char * title = "Active window's keybindings:"; struct KeyBinding * kb_p; - struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active); + struct WinConf * wc = get_winconf_by_win(world.wmeta->active); if (0 == wc->view) { kb_p = wc->kb.kbs; } else if (1 == wc->view) { - kb_p = world->kb_wingeom.kbs; + kb_p = world.kb_wingeom.kbs; } else if (2 == wc->view) { - kb_p = world->kb_winkeys.kbs; + kb_p = world.kb_winkeys.kbs; } - uint16_t offset = draw_titled_keybinding_list(world, title, win, 0, kb_p); - add_line(world, win, " ", 0, 0); - draw_titled_keybinding_list(world, "Global keybindings", win, offset + 1, - world->kb_global.kbs); + uint16_t offset = draw_titled_keybinding_list(title, win, 0, kb_p); + add_line(win, " ", 0, 0); + struct KeyBinding * kbs_glo = world.kb_global.kbs; + draw_titled_keybinding_list("Global keybindings", win, offset + 1, kbs_glo); } extern void draw_win_keybindings_global(struct Win * win) { - struct World * world = (struct World *) win->data; - win->center.y = world->kb_global.select; - draw_kb_view(world, win, &world->kb_global, 0); + win->center.y = world.kb_global.select; + draw_kb_view(win, &world.kb_global, 0); } extern void draw_win_keybindings_winconf_geometry(struct Win * win) { - struct World * world = (struct World *) win->data; - win->center.y = world->kb_wingeom.select; - draw_kb_view(world, win, &world->kb_wingeom, 0); + win->center.y = world.kb_wingeom.select; + draw_kb_view(win, &world.kb_wingeom, 0); } extern void draw_win_keybindings_winconf_keybindings(struct Win * win) { - struct World * world = (struct World *) win->data; - win->center.y = world->kb_winkeys.select; - draw_kb_view(world, win, &world->kb_winkeys, 0); + win->center.y = world.kb_winkeys.select; + draw_kb_view(win, &world.kb_winkeys, 0); } extern void draw_winconf_keybindings(struct Win * win) { - struct World * world = (struct World *) win->data; - struct WinConf * wc = get_winconf_by_win(world, win); + struct WinConf * wc = get_winconf_by_win(win); char * title = "Window's keybindings:"; - add_line(world, win, title, 0, 0); - add_line(world, win, " ", 0, 0); - draw_kb_view(world, win, &wc->kb, 2); + add_line(win, title, 0, 0); + add_line(win, " ", 0, 0); + draw_kb_view(win, &wc->kb, 2); win->center.y = wc->kb.select + 2; } @@ -488,8 +467,7 @@ extern void draw_winconf_keybindings(struct Win * win) extern void draw_winconf_geometry(struct Win * win) { - struct World * world = (struct World *) win->data; - struct WinConf * wcp = get_winconf_by_win(world, win); + struct WinConf * wcp = get_winconf_by_win(/*&world, */win); char * title = "Window's geometry:\n"; char * h_d = "\nHeight to save: "; char * h_pos = " (width in cells)"; @@ -513,5 +491,5 @@ extern void draw_winconf_geometry(struct Win * win) char text[maxl + 1]; sprintf(text, "%s%s%d%s%s%d%s", title, h_d, wcp->height, h_t, w_d, wcp->width, w_t); - add_text_with_linebreaks(world, win, text); + add_text_with_linebreaks(win, text); } diff --git a/src/draw_wins.h b/src/draw_wins.h index 3ebdf76..af80a14 100644 --- a/src/draw_wins.h +++ b/src/draw_wins.h @@ -6,8 +6,6 @@ #ifndef DRAW_WINS_H #define DRAW_WINS_H - - #include /* for uint16_t */ struct Win; diff --git a/src/keybindings.c b/src/keybindings.c index 9443531..ffd7179 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -10,7 +10,7 @@ #include "readwrite.h" /* for texfile_sizes(), try_fopen(), try_fclose() * try_fclose_unlink_rename(), try_fwrite() */ -#include "main.h" /* for World struct */ +#include "main.h" /* for world global */ #include "rexit.h" /* for err_exit() */ #include "misc.h" /* for try_malloc() */ @@ -31,10 +31,10 @@ extern uint16_t get_keycode_to_action(struct KeyBinding * kb_p, char * name) -extern char * get_name_to_keycode(struct World * world, uint16_t keycode) +extern char * get_name_to_keycode(uint16_t keycode) { char * f_name = "get_name_to_keycode()"; - char * keyname = try_malloc(15, world, f_name); + char * keyname = try_malloc(15, f_name); if (32 < keycode && keycode < 127) { sprintf(keyname, "%c", keycode); @@ -147,15 +147,14 @@ extern struct KeyBinding * get_keyb_of_n(struct KeyBinding * kb_p, uint16_t n) -extern void init_keybindings(struct World * world, char * path, - struct KeyBiData * kbd) +extern void init_keybindings(char * path, struct KeyBiData * kbd) { char * f_name = "init_keybindings()"; - FILE * file = try_fopen(path, "r", world, f_name); + FILE * file = try_fopen(path, "r", f_name); uint16_t lines, linemax; char * err = "textfile_sizes() in init_keybindings() returns error."; - exit_err(textfile_sizes(file, &linemax, &lines), world, err); + exit_err(textfile_sizes(file, &linemax, &lines), err); char command[linemax + 1]; char * cmdptr; @@ -167,18 +166,18 @@ extern void init_keybindings(struct World * world, char * path, { break; } - * loc_last_ptr = try_malloc(sizeof(struct KeyBinding), world, f_name); + * loc_last_ptr = try_malloc(sizeof(struct KeyBinding), f_name); struct KeyBinding * kb_p = * loc_last_ptr; kb_p->next = 0; kb_p->key = atoi(command); cmdptr = strchr(command, ' ') + 1; - kb_p->name = try_malloc(strlen(cmdptr), world, f_name); + kb_p->name = try_malloc(strlen(cmdptr), f_name); memcpy(kb_p->name, cmdptr, strlen(cmdptr) - 1); kb_p->name[strlen(cmdptr) - 1] = '\0'; loc_last_ptr = & kb_p->next; } - try_fclose(file, world, f_name); + try_fclose(file, f_name); kbd->edit = 0; kbd->select = 0; @@ -186,14 +185,13 @@ extern void init_keybindings(struct World * world, char * path, -extern void save_keybindings(struct World * world, char * path, - struct KeyBiData * kbd) +extern void save_keybindings(char * path, struct KeyBiData * kbd) { char * f_name = "save_keybindings()"; char path_tmp[strlen(path) + 4 + 1]; sprintf(path_tmp, "%s_tmp", path); - FILE * file = try_fopen(path_tmp, "w", world, f_name); + FILE * file = try_fopen(path_tmp, "w", f_name); uint16_t linemax = 0; struct KeyBinding * kb_p = kbd->kbs; @@ -212,11 +210,11 @@ extern void save_keybindings(struct World * world, char * path, while (0 != kb_p) { snprintf(line, linemax, "%d %s\n", kb_p->key, kb_p->name); - try_fwrite(line, sizeof(char), strlen(line), file, world, f_name); + try_fwrite(line, sizeof(char), strlen(line), file, f_name); kb_p = kb_p->next; } - try_fclose_unlink_rename(file, path_tmp, path, world, f_name); + try_fclose_unlink_rename(file, path_tmp, path, f_name); } @@ -238,11 +236,11 @@ extern void free_keybindings(struct KeyBinding * kb_start) -extern void mod_selected_keyb(struct World * world, struct KeyBiData * kbd) +extern void mod_selected_keyb(struct KeyBiData * kbd) { kbd->edit = 1; - exit_err(draw_all_wins(world->wmeta), world, - "Trouble with draw_all_wins() in mod_selected_keyb()."); + char * err = "Trouble with draw_all_wins() in mod_selected_keyb()."; + exit_err(draw_all_wins(world.wmeta), err); int key = getch(); if (key < 1000) { diff --git a/src/keybindings.h b/src/keybindings.h index ce15e66..3d1b75e 100644 --- a/src/keybindings.h +++ b/src/keybindings.h @@ -6,10 +6,7 @@ #ifndef KEYBINDINGS_H #define KEYBINDINGS_H - - #include /* for uint16_t */ -struct World; @@ -40,7 +37,7 @@ extern uint16_t get_keycode_to_action(struct KeyBinding * keybindings, /* Return human-readable name (of maximum 9 chars) for "keycode" as matched by * ncurses.h; if none is found, return "UNKNOWN". */ -extern char * get_name_to_keycode(struct World * world, uint16_t keycode); +extern char * get_name_to_keycode(uint16_t keycode); /* Return number of keybindings in keybindings chain from "kb_p" on. */ extern uint16_t get_n_of_keybs(struct KeyBinding * kb_p); @@ -53,10 +50,8 @@ extern struct KeyBinding * get_keyb_of_n(struct KeyBinding * kb_p, uint16_t n); /* Initialize/save keybindings data from/to file at "path" to/from keybindings * data pointer "kbd". */ -extern void init_keybindings(struct World * world, char * path, - struct KeyBiData * kbd); -extern void save_keybindings(struct World * world, char * path, - struct KeyBiData * kbd); +extern void init_keybindings(char * path, struct KeyBiData * kbd); +extern void save_keybindings(char * path, struct KeyBiData * kbd); /* Free keybinding chain starting at "kb_start". */ extern void free_keybindings(struct KeyBinding * kb_start); @@ -67,7 +62,7 @@ extern void free_keybindings(struct KeyBinding * kb_start); * modify it, then unmark it again. Ensure there are max. three digits in the * keycode ASCII representation. */ -extern void mod_selected_keyb(struct World * world, struct KeyBiData * kbd); +extern void mod_selected_keyb(struct KeyBiData * kbd); /* Move keybinding modification selection upwards ("dir"=="u") or downwards * ("dir"=="d") within the limits of the keybindings chain length. diff --git a/src/main.c b/src/main.c index 4a7b57d..8826407 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ /* main.c */ -#include "main.h" +#include "main.h" /* for world global */ #include /* for atoi(), exit(), EXIT_FAILURE */ #include /* for FILE typedef, F_OK */ #include /* for initscr(), noecho(), curs_set(), keypad(), raw() */ @@ -33,10 +33,9 @@ int main(int argc, char *argv[]) { char * f_name = "main()"; - struct World world; world.turn = 0; /* Turns to 1 when map and objects are initalized. */ - init_command_db(&world); + init_command_db(); set_cleanup_flag(CLEANUP_COMMAND_DB); /* Check for corrupted savefile / recordfile savings. */ @@ -44,14 +43,14 @@ int main(int argc, char *argv[]) char * savefile = "savefile"; char * recordfile_tmp = "record_tmp"; char * savefile_tmp = "savefile_tmp"; - check_files_xor(savefile, recordfile, &world); - check_tempfile(recordfile_tmp, &world); - check_tempfile(savefile_tmp, &world); - check_tempfile("config/windows/Win_tmp_k", &world); - check_tempfile("config/windows/Win_tmp_m", &world); - check_tempfile("config/windows/Win_tmp_i", &world); - check_tempfile("config/windows/Win_tmp_l", &world); - check_tempfile("config/windows/toggle_order_tmp", &world); + check_files_xor(savefile, recordfile); + check_tempfile(recordfile_tmp); + check_tempfile(savefile_tmp); + check_tempfile("config/windows/Win_tmp_k"); + check_tempfile("config/windows/Win_tmp_m"); + check_tempfile("config/windows/Win_tmp_i"); + check_tempfile("config/windows/Win_tmp_l"); + check_tempfile("config/windows/toggle_order_tmp"); /* Read in startup options (i.e. replay option and replay start turn). */ int opt; @@ -80,10 +79,10 @@ int main(int argc, char *argv[]) /* Initialize log and map object definitions. */ world.score = 0; - world.log = try_calloc(1, sizeof(char), &world, f_name); + world.log = try_calloc(1, sizeof(char), f_name); set_cleanup_flag(CLEANUP_LOG); - update_log(&world, " "); - init_map_object_defs(&world, "config/defs"); + update_log(" "); + init_map_object_defs("config/defs"); set_cleanup_flag(CLEANUP_MAP_OBJECT_DEFS); world.map_obj_count = 0; @@ -93,7 +92,7 @@ int main(int argc, char *argv[]) FILE * file; if (1 == world.interactive && 0 == access(savefile, F_OK)) { - load_game(&world); + load_game(); set_cleanup_flag(CLEANUP_MAP_OBJECTS); } @@ -104,8 +103,8 @@ int main(int argc, char *argv[]) "in main())."; if (0 == world.interactive) { - file = try_fopen(recordfile, "r", &world, f_name); - exit_err(read_uint32_bigendian(file, &world.seed), &world, err_r); + file = try_fopen(recordfile, "r", f_name); + exit_err(read_uint32_bigendian(file, &world.seed), err_r); } /* For interactive-mode in newly started world, generate a start seed @@ -118,10 +117,9 @@ int main(int argc, char *argv[]) char * err_w = "Trouble recording new seed " "(write_uint32_bigendian() in main()) / writing to " "file 'record_tmp'."; - file = try_fopen(recordfile_tmp, "w", &world, f_name); - exit_err(write_uint32_bigendian(world.seed, file), &world, err_w); - try_fclose_unlink_rename(file, recordfile_tmp, recordfile, - &world, f_name); + file = try_fopen(recordfile_tmp, "w", f_name); + exit_err(write_uint32_bigendian(world.seed, file), err_w); + try_fclose_unlink_rename(file, recordfile_tmp, recordfile, f_name); } } @@ -135,12 +133,12 @@ int main(int argc, char *argv[]) if (0 == world.turn) { world.map_objs = NULL; - add_map_objects(&world, 0, 1); - add_map_objects(&world, 1, 1 + rrand() % 27); - add_map_objects(&world, 2, 1 + rrand() % 9); - add_map_objects(&world, 3, 1 + rrand() % 3); - add_map_objects(&world, 4, 1 + rrand() % 3); - add_map_objects(&world, 5, 1 + rrand() % 3); + add_map_objects(0, 1); + add_map_objects(1, 1 + rrand() % 27); + add_map_objects(2, 1 + rrand() % 9); + add_map_objects(3, 1 + rrand() % 3); + add_map_objects(4, 1 + rrand() % 3); + add_map_objects(5, 1 + rrand() % 3); set_cleanup_flag(CLEANUP_MAP_OBJECTS); world.turn = 1; } @@ -153,15 +151,15 @@ int main(int argc, char *argv[]) keypad(screen, TRUE); raw(); char * err_winmem = "Trouble with init_win_meta() in main ()."; - exit_err(init_win_meta(screen, &world.wmeta), &world, err_winmem); + exit_err(init_win_meta(screen, &world.wmeta), err_winmem); set_cleanup_flag(CLEANUP_WIN_META); - load_interface_conf(&world); + load_interface_conf(/*&world*/); set_cleanup_flag(CLEANUP_INTERFACE_CONF); err_winmem = "Trouble with draw_all_wins() in main()."; /* Focus map on player. */ - struct MapObj * player = get_player(&world); - struct Win * win_map = get_win_by_id(&world, 'm'); + struct MapObj * player = get_player(); + struct Win * win_map = get_win_by_id('m'); win_map->center = player->pos; /* Initialize player's inventory selection index to start position. */ @@ -182,40 +180,40 @@ int main(int argc, char *argv[]) { break; } - if (is_command_id_shortdsc(&world, action, "drop")) + if (is_command_id_shortdsc(action, "drop")) { world.inventory_select = getc(file); } - record_control(action, &world); + record_control(action); } } while (1) { draw_all_wins(world.wmeta); key = getch(); - wc = get_winconf_by_win(&world, world.wmeta->active); - if ( (1 == wc->view && wingeom_control(key, &world)) - || (2 == wc->view && winkeyb_control(key, &world))) + wc = get_winconf_by_win(world.wmeta->active); + if ( (1 == wc->view && wingeom_control(key)) + || (2 == wc->view && winkeyb_control(key))) { continue; } if ( EOF != action - && key == get_available_keycode_to_action(&world, "wait")) + && key == get_available_keycode_to_action("wait")) { action = getc(file); if (EOF != action) { - if (is_command_id_shortdsc(&world, action, "drop")) + if (is_command_id_shortdsc(action, "drop")) { world.inventory_select = getc(file); } - record_control(action, &world); + record_control(action); } } - else if (meta_control(key, &world)) + else if (meta_control(key)) { - try_fclose(file, &world, f_name); - exit_game(&world); + try_fclose(file, f_name); + exit_game(); } } } @@ -225,29 +223,29 @@ int main(int argc, char *argv[]) { while (1) { - save_game(&world); + save_game(); draw_all_wins(world.wmeta); key = getch(); - wc = get_winconf_by_win(&world, world.wmeta->active); - if (1 == wc->view && wingeom_control(key, &world)) + wc = get_winconf_by_win(world.wmeta->active); + if (1 == wc->view && wingeom_control(key)) { continue; } - else if (2 == wc->view && winkeyb_control(key, &world)) + else if (2 == wc->view && winkeyb_control(key)) { continue; } - if ( (1 == wc->view && wingeom_control(key, &world)) - || (2 == wc->view && winkeyb_control(key, &world)) - || (0 != player->lifepoints && player_control(key, &world))) + if ( (1 == wc->view && wingeom_control(key)) + || (2 == wc->view && winkeyb_control(key)) + || (0 != player->lifepoints && player_control(key))) { continue; } - if (meta_control(key, &world)) + if (meta_control(key)) { - exit_game(&world); + exit_game(); } } } diff --git a/src/main.h b/src/main.h index 8105d34..e4d62e2 100644 --- a/src/main.h +++ b/src/main.h @@ -6,10 +6,8 @@ #ifndef MAIN_H #define MAIN_H - - #include /* for uint32_t*/ -#include "keybindings.h" +#include "keybindings.h" /* for KeyBiData struct */ struct WinMeta; struct WinConf; struct Win; @@ -39,7 +37,7 @@ struct World struct MapObj * map_objs; /* Pointer to map objects chain start. */ uint8_t inventory_select; /* Player's inventory selection index. */ uint8_t old_inventory_select; /* Temporarily stores for recordfile */ -}; /* writing inventory selection index. */ +} world; /* writing inventory selection index. */ diff --git a/src/map.c b/src/map.c index 92d1558..629e813 100644 --- a/src/map.c +++ b/src/map.c @@ -5,18 +5,17 @@ #include "yx_uint16.h" /* for yx_uint16 and dir enums */ #include "rrand.h" /* for rrand() */ #include "windows.h" /* for struct Win */ -struct World; -struct Map init_map(struct World * world) +extern struct Map init_map() { char * f_name = "init_map()"; struct Map map; map.size.x = 64; map.size.y = 64; uint32_t size = map.size.x * map.size.y; - map.cells = try_malloc(size, world, f_name); + map.cells = try_malloc(size, f_name); uint16_t y, x; for (y = 0; y < map.size.y; y++) { @@ -54,7 +53,7 @@ struct Map init_map(struct World * world) -void map_scroll(struct Win * win, struct yx_uint16 map_size, enum dir d) +extern void map_scroll(struct Win * win, struct yx_uint16 map_size, enum dir d) { uint16_t offset; if ((NORTH == d || SOUTH == d) && map_size.y > win->framesize.y) diff --git a/src/map.h b/src/map.h index 8dfe446..7cc9871 100644 --- a/src/map.h +++ b/src/map.h @@ -6,10 +6,7 @@ #ifndef MAP_H #define MAP_H - - #include "yx_uint16.h" /* for yx_uint16 and dir enums */ -struct MapObj; struct Win; @@ -35,7 +32,7 @@ extern struct Map init_map(); /* Try to change the view center of map "win" of "map_size" into dir "d". */ -void map_scroll(struct Win * win, struct yx_uint16 map_size, enum dir d); +extern void map_scroll(struct Win * win, struct yx_uint16 map_size, enum dir d); diff --git a/src/map_object_actions.c b/src/map_object_actions.c index d486349..44e0263 100644 --- a/src/map_object_actions.c +++ b/src/map_object_actions.c @@ -10,7 +10,7 @@ */ #include "misc.h" /* for update_log(), turn_over() */ #include "map.h" /* for Map struct */ -#include "main.h" /* for World struct */ +#include "main.h" /* for world global */ #include "command_db.h" /* for get_command_id() */ @@ -18,17 +18,15 @@ /* One actor "wounds" another actor, decrementing his lifepoints and, if they * reach zero in the process, killing it. Generates appropriate log message. */ -static void actor_hits_actor(struct World * world, struct MapObj * hitter, - struct MapObj * hitted); +static void actor_hits_actor(struct MapObj * hitter, struct MapObj * hitted); -static void actor_hits_actor(struct World * world, struct MapObj * hitter, - struct MapObj * hitted) +static void actor_hits_actor(struct MapObj * hitter, struct MapObj * hitted) { - struct MapObjDef * mod_hitter = get_map_object_def(world, hitter->type); - struct MapObjDef * mod_hitted = get_map_object_def(world, hitted->type); - struct MapObj * player = get_player(world); + struct MapObjDef * mod_hitter = get_map_object_def(hitter->type); + struct MapObjDef * mod_hitted = get_map_object_def(hitted->type); + struct MapObj * player = get_player(); char * msg1 = "You"; char * msg2 = "wound"; char * msg3 = "you"; @@ -44,21 +42,21 @@ static void actor_hits_actor(struct World * world, struct MapObj * hitter, uint8_t len = 1 + strlen(msg1) + 1 + strlen(msg2) + 1 + strlen(msg3) + 2; char msg[len]; sprintf(msg, "\n%s %s %s.", msg1, msg2, msg3); - update_log(world, msg); + update_log(msg); hitted->lifepoints--; if (0 == hitted->lifepoints) { hitted->type = mod_hitted->corpse_id; if (player == hitted) { - update_log(world, " You die."); + update_log(" You die."); } else { - update_log(world, " It dies."); + update_log(" It dies."); if (player == hitter) { - world->score = world->score + mod_hitted->lifepoints; + world.score = world.score + mod_hitted->lifepoints; } } } @@ -66,12 +64,11 @@ static void actor_hits_actor(struct World * world, struct MapObj * hitter, -extern uint8_t move_actor(struct World * world, struct MapObj * actor, - enum dir d) +extern uint8_t move_actor(struct MapObj * actor, enum dir d) { struct yx_uint16 target = mv_yx_in_dir(d, actor->pos); struct MapObj * other_actor; - for (other_actor = world->map_objs; + for (other_actor = world.map_objs; other_actor != 0; other_actor = other_actor->next) { @@ -81,11 +78,11 @@ extern uint8_t move_actor(struct World * world, struct MapObj * actor, } if (yx_uint16_cmp(&target, &other_actor->pos)) { - actor_hits_actor(world, actor, other_actor); + actor_hits_actor(actor, other_actor); return 2; } } - if (is_passable(world->map, target)) + if (is_passable(world.map, target)) { set_object_position(actor, target); return 0; @@ -95,7 +92,7 @@ extern uint8_t move_actor(struct World * world, struct MapObj * actor, -extern void move_player(struct World * world, enum dir d) +extern void move_player(enum dir d) { char * dsc_dir; char * action_dsc_prototype = "player_"; @@ -123,7 +120,7 @@ extern void move_player(struct World * world, enum dir d) action_dsc[len_action_dsc_prototype] = 'l'; } action_dsc[len_action_dsc_prototype + 1] = '\0'; - uint8_t res = move_actor(world, get_player(world), d); + uint8_t res = move_actor(get_player(), d); if (1 >= res) { char * dsc_move = "You fail to move "; @@ -133,67 +130,64 @@ extern void move_player(struct World * world, enum dir d) } char msg[strlen(dsc_move) + strlen (dsc_dir) + 3]; sprintf(msg, "\n%s%s.", dsc_move, dsc_dir); - update_log(world, msg); + update_log(msg); } - turn_over(world, get_command_id(world, action_dsc)); + turn_over(get_command_id(action_dsc)); } -extern void player_wait(struct World * world) +extern void player_wait() { - update_log(world, "\nYou wait."); - turn_over(world, get_command_id(world, "wait")); + update_log("\nYou wait."); + turn_over(get_command_id("wait")); } extern char is_passable(struct Map * map, struct yx_uint16 pos) { - char passable = 0; + uint8_t passable = 0; if (0 <= pos.x && pos.x < map->size.x && 0 <= pos.y && pos.y < map->size.y) { - if ('.' == map->cells[pos.y * map->size.x + pos.x]) - { - passable = 1; - } + passable = (('.' == map->cells[pos.y * map->size.x + pos.x])); } return passable; } -extern void player_drop(struct World * world) +extern void player_drop() { - struct MapObj * player = get_player(world); + struct MapObj * player = get_player(); if (NULL == player->owns) { - update_log(world, "\nYou try to drop an object, but you own none."); - world->old_inventory_select = 0; + update_log("\nYou try to drop an object, but you own none."); + world.old_inventory_select = 0; } else { - world->old_inventory_select = world->inventory_select; + world.old_inventory_select = world.inventory_select; struct MapObj * owned = player->owns; uint8_t i = 0; - for (; i != world->inventory_select; i++, owned = owned->next); - if (0 < world->inventory_select) + for (; i != world.inventory_select; i++, owned = owned->next); + if (0 < world.inventory_select) { - world->inventory_select--; + world.inventory_select--; } - own_map_object(&world->map_objs, &player->owns, owned->id); - update_log(world, "\nYou drop an object."); + own_map_object(&world.map_objs, &player->owns, owned->id); + update_log("\nYou drop an object."); } - turn_over(world, get_command_id(world, "drop")); + turn_over(get_command_id("drop")); } -extern void player_pick(struct World * world) +extern void player_pick() { - struct MapObj * player = get_player(world); + struct MapObj * player = get_player(); struct MapObj * picked; - for (picked = world->map_objs; NULL != picked; picked = picked->next) + for (picked = world.map_objs; NULL != picked; picked = picked->next) { if (picked != player && yx_uint16_cmp(&picked->pos, &player->pos)) { @@ -202,13 +196,13 @@ extern void player_pick(struct World * world) } if (NULL == picked) { - update_log(world, "\nYou try to pick up an object, but there is none."); + update_log("\nYou try to pick up an object, but there is none."); } else { - own_map_object(&player->owns, &world->map_objs, picked->id); + own_map_object(&player->owns, &world.map_objs, picked->id); set_object_position(picked, player->pos); - update_log(world, "\nYou pick up an object."); + update_log("\nYou pick up an object."); } - turn_over(world, get_command_id(world, "pick")); + turn_over(get_command_id("pick")); } diff --git a/src/map_object_actions.h b/src/map_object_actions.h index b144f29..46dc92c 100644 --- a/src/map_object_actions.h +++ b/src/map_object_actions.h @@ -6,10 +6,7 @@ #ifndef MAP_OBJECT_ACTIONS_H #define MAP_OBJECT_ACTIONS_H - - #include "yx_uint16.h" /* for yx_uint16 coordinates */ -struct World; struct Map; struct MapObj; @@ -20,8 +17,7 @@ struct MapObj; * leads to its lifepoint decreasing by one and potentially its death), or the * target square is not passable and the move fails. */ -extern uint8_t move_actor(struct World * world, struct MapObj * actor, - enum dir d); +extern uint8_t move_actor(struct MapObj * actor, enum dir d); @@ -29,14 +25,14 @@ extern uint8_t move_actor(struct World * world, struct MapObj * actor, * the game log with appropriate messages on the move attempt and its results; * turns over to turn_over() when finished. */ -extern void move_player(struct World * world, enum dir d); +extern void move_player(enum dir d); /* Make player wait one turn, i.e. only update_log with a "you wait" message * and turn control over to the enemy. */ -extern void player_wait(struct World * world); +extern void player_wait(); @@ -48,10 +44,10 @@ extern char is_passable(struct Map * map, struct yx_uint16 pos); /* Make player drop to ground map ojbect indexed by world.inventory_select. */ -extern void player_drop(struct World * world); +extern void player_drop(); /* Make player pick up map object from ground. */ -extern void player_pick(struct World * world); +extern void player_pick(); diff --git a/src/map_objects.c b/src/map_objects.c index 3745fcf..4deaa08 100644 --- a/src/map_objects.c +++ b/src/map_objects.c @@ -8,15 +8,15 @@ #include "readwrite.h" /* for get_linemax(), try_fopen(), try_fclose() * [read/write]_uint[8/16/23][_bigendian]() */ -#include "misc.h" /* for try_malloc(), try_calloc(), find_passable_pos() */ -#include "main.h" /* for World struct */ +#include "misc.h" /* for try_malloc(), find_passable_pos() */ +#include "main.h" /* for world global */ #include "rexit.h" /* for err_exit() */ #include "yx_uint16.h" /* for yx_uint16 struct, yx_uint16_cmp() */ /* Write representation of "mo" and all of the map objects it owns to "file". */ -static void write_map_object(struct World * w, FILE * file, struct MapObj * mo); +static void write_map_object(FILE * file, struct MapObj * mo); @@ -25,7 +25,7 @@ static struct MapObj * get_map_object(struct MapObj * ptr, uint8_t id); -static void write_map_object(struct World * w, FILE * file, struct MapObj * mo) +static void write_map_object(FILE * file, struct MapObj * mo) { char * f_name = "write_map_object()"; struct MapObj * mo_ptr = mo->owns; @@ -41,10 +41,10 @@ static void write_map_object(struct World * w, FILE * file, struct MapObj * mo) } line[strlen(line) + 1] = '\0'; line[strlen(line)] = '\n'; - try_fwrite(line, strlen(line), 1, file, w, f_name); + try_fwrite(line, strlen(line), 1, file, f_name); for (mo_ptr = mo->owns; NULL != mo_ptr; mo_ptr = mo_ptr->next) { - write_map_object(w, file, mo_ptr); + write_map_object(file, mo_ptr); } } @@ -69,30 +69,30 @@ static struct MapObj * get_map_object(struct MapObj * ptr, uint8_t id) -extern void init_map_object_defs(struct World * world, char * filename) +extern void init_map_object_defs(char * filename) { char * f_name = "init_map_object_defs()"; - FILE * file = try_fopen(filename, "r", world, f_name); - uint16_t linemax = get_linemax(file, world, f_name); - struct MapObjDef ** last_mod_ptr_ptr = &world->map_obj_defs; + FILE * file = try_fopen(filename, "r", f_name); + uint16_t linemax = get_linemax(file, f_name); + struct MapObjDef ** last_mod_ptr_ptr = &world.map_obj_defs; char * delim = " "; char line[linemax + 1]; - while (try_fgets(line, linemax + 1, file, world, f_name)) + while (try_fgets(line, linemax + 1, file, f_name)) { struct MapObjDef * mod; - mod = try_malloc(sizeof(struct MapObjDef), world, f_name); + mod = try_malloc(sizeof(struct MapObjDef), f_name); mod->next = NULL; mod->id = atoi(strtok(line, delim)); mod->corpse_id = atoi(strtok(NULL, delim)); mod->char_on_map = * strtok(NULL, delim); mod->lifepoints = atoi(strtok(NULL, delim)); char * name = strtok(NULL, "\n"); - mod->name = try_malloc(strlen(name) + 1, world, f_name); + mod->name = try_malloc(strlen(name) + 1, f_name); memcpy(mod->name, name, strlen(name) + 1); * last_mod_ptr_ptr = mod; last_mod_ptr_ptr = &mod->next; } - try_fclose(file, world, f_name); + try_fclose(file, f_name); } @@ -110,28 +110,27 @@ extern void free_map_object_defs(struct MapObjDef * mod_start) -extern void write_map_objects(struct World * world, FILE * file) +extern void write_map_objects(FILE * file) { - struct MapObj * mo = world->map_objs; + struct MapObj * mo = world.map_objs; while (NULL != mo) { - write_map_object(world, file, mo); + write_map_object(file, mo); mo = mo->next; } } -extern void read_map_objects(struct World * world, FILE * file, char * line, - int linemax) +extern void read_map_objects(FILE * file, char * line, int linemax) { char * f_name = "read_map_objects()"; - struct MapObj ** mo_ptr_ptr = &world->map_objs; + struct MapObj ** mo_ptr_ptr = &world.map_objs; char * delim = " "; struct MapObj * mo; fpos_t pos; - exit_err(-1 == fgetpos(file, &pos), world, f_name); - while (try_fgets(line, linemax + 1, file, world, f_name)) + exit_err(-1 == fgetpos(file, &pos), f_name); + while (try_fgets(line, linemax + 1, file, f_name)) { mo = malloc(sizeof(struct MapObj)); mo->next = NULL; @@ -141,15 +140,15 @@ extern void read_map_objects(struct World * world, FILE * file, char * line, mo->pos.y = atoi(strtok(NULL, delim)); mo->pos.x = atoi(strtok(NULL, delim)); mo->owns = NULL; - if (mo->id > world->map_obj_count) + if (mo->id > world.map_obj_count) { - world->map_obj_count = mo->id; + world.map_obj_count = mo->id; } * mo_ptr_ptr = mo; mo_ptr_ptr = &mo->next; } - exit_err(-1 == fsetpos(file, &pos), world, f_name); - while (try_fgets(line, linemax + 1, file, world, f_name)) + exit_err(-1 == fsetpos(file, &pos), f_name); + while (try_fgets(line, linemax + 1, file, f_name)) { uint8_t id = atoi(strtok(line, delim)); strtok(NULL, delim); @@ -159,12 +158,12 @@ extern void read_map_objects(struct World * world, FILE * file, char * line, char * owned = strtok(NULL, "\n"); if (NULL != owned) { - mo = get_map_object(world->map_objs, id); + mo = get_map_object(world.map_objs, id); char * owned_id = ""; owned_id = strtok(owned, delim); while (NULL != owned_id) { - own_map_object(&mo->owns, &world->map_objs, + own_map_object(&mo->owns, &world.map_objs, (uint8_t) atoi(owned_id)); owned_id = strtok(NULL, delim); } @@ -174,23 +173,21 @@ extern void read_map_objects(struct World * world, FILE * file, char * line, -extern void add_map_object(struct World * world, uint8_t type) +extern void add_map_object(uint8_t type) { char * f_name = "add_map_object()"; - struct MapObjDef * mod = get_map_object_def(world, type); - struct MapObj * mo = try_malloc(sizeof(struct MapObj), world, f_name); - mo->id = world->map_obj_count; - world->map_obj_count++; + struct MapObjDef * mod = get_map_object_def(type); + struct MapObj * mo = try_malloc(sizeof(struct MapObj), f_name); + mo->id = world.map_obj_count; + world.map_obj_count++; mo->type = mod->id; mo->lifepoints = mod->lifepoints; while (1) { - struct yx_uint16 pos = find_passable_pos(world->map); + struct yx_uint16 pos = find_passable_pos(world.map); struct MapObj * mo_ptr; uint8_t clear = 1; - for (mo_ptr = world->map_objs; - mo_ptr != NULL; - mo_ptr = mo_ptr->next) + for (mo_ptr = world.map_objs; mo_ptr != NULL; mo_ptr = mo_ptr->next) { if (yx_uint16_cmp(&pos, &mo_ptr->pos) && 0 != mo_ptr->lifepoints) { @@ -206,7 +203,7 @@ extern void add_map_object(struct World * world, uint8_t type) } mo->owns = NULL; mo->next = NULL; - struct MapObj ** last_ptr_ptr = &world->map_objs; + struct MapObj ** last_ptr_ptr = &world.map_objs; struct MapObj * mo_ptr; while (NULL != * last_ptr_ptr) { @@ -218,12 +215,12 @@ extern void add_map_object(struct World * world, uint8_t type) -extern void add_map_objects(struct World * world, uint8_t type, uint8_t n) +extern void add_map_objects(uint8_t type, uint8_t n) { uint8_t i; for (i = 0; i < n; i++) { - add_map_object(world, type); + add_map_object(type); } } @@ -278,16 +275,16 @@ extern void own_map_object(struct MapObj ** target, struct MapObj ** source, -extern struct MapObj * get_player(struct World * world) +extern struct MapObj * get_player() { - return get_map_object(world->map_objs, 0); + return get_map_object(world.map_objs, 0); } -extern struct MapObjDef * get_map_object_def(struct World * w, uint8_t id) +extern struct MapObjDef * get_map_object_def(uint8_t id) { - struct MapObjDef * mod = w->map_obj_defs; + struct MapObjDef * mod = world.map_obj_defs; while (id != mod->id) { mod = mod->next; diff --git a/src/map_objects.h b/src/map_objects.h index 1489711..5cc6ee4 100644 --- a/src/map_objects.h +++ b/src/map_objects.h @@ -7,12 +7,9 @@ #ifndef MAP_OBJECTS_H #define MAP_OBJECTS_H - - #include /* for FILE typedef */ #include /* for uint8_t */ #include "yx_uint16.h" /* for yx_uint16 coordinates */ -struct World; @@ -41,7 +38,7 @@ struct MapObjDef /* Initialize map object defnitions chain from file at path "filename". */ -extern void init_map_object_defs(struct World * world, char * filename); +extern void init_map_object_defs(char * filename); @@ -54,19 +51,18 @@ extern void free_map_object_defs(struct MapObjDef * mod_start); * New animate objects are never placed in the same square with other animated * ones. */ -extern void add_map_object(struct World * world, uint8_t type); -extern void add_map_objects(struct World * world, uint8_t type, uint8_t n); +extern void add_map_object(uint8_t type); +extern void add_map_objects(uint8_t type, uint8_t n); /* Write map objects chain to "file". */ -extern void write_map_objects(struct World * world, FILE * file); +extern void write_map_objects(FILE * file); /* Read from "file" map objects chain; use "line" as char array for fgets() and * expect strings of max. "linemax" length. */ -extern void read_map_objects(struct World * world, FILE * file, - char * line, int linemax); +extern void read_map_objects(FILE * file, char * line, int linemax); @@ -82,12 +78,12 @@ extern void own_map_object(struct MapObj ** target, struct MapObj ** source, /* Get pointer to the MapObj struct that represents the player. */ -extern struct MapObj * get_player(struct World * world); +extern struct MapObj * get_player(); /* Get pointer to the map object definition of identifier "def_id". */ -extern struct MapObjDef * get_map_object_def(struct World * w, uint8_t id); +extern struct MapObjDef * get_map_object_def(uint8_t id); diff --git a/src/misc.c b/src/misc.c index bddf571..466defa 100644 --- a/src/misc.c +++ b/src/misc.c @@ -7,14 +7,14 @@ #include /* for strlen(), strcmp(), memcpy() */ #include /* for uint8_t, uint16_t */ #include "readwrite.h" /* for [read/write]_uint[8/16/32][_bigendian](), - * try_fopen(), try_fclose() + * try_fopen(), try_fclose(), get_linemax() */ #include "map_objects.h" /* for struct MapObj, get_player(), read_map_objects(), * write_map_objects() */ #include "map_object_actions.h" /* for is_passable(), move_actor() */ #include "map.h" /* for Map struct */ -#include "main.h" /* for World struct */ +#include "main.h" /* for world global */ #include "yx_uint16.h" /* for yx_uint16 struct */ #include "rrand.h" /* for rrand(), rrand_seed() */ #include "rexit.h" /* for exit_err() */ @@ -26,7 +26,7 @@ -extern char * trouble_msg(struct World * w, char * parent, char * child) +extern char * trouble_msg(char * parent, char * child) { char * p1 = "Trouble in "; char * p2 = " with "; @@ -34,36 +34,36 @@ extern char * trouble_msg(struct World * w, char * parent, char * child) uint16_t size = strlen(p1) + strlen(parent) + strlen(p2) + strlen(child) + strlen(p3) + 1; char * msg = malloc(size); - exit_err(NULL == msg, w, "malloc() in trouble_msg() failed."); + exit_err(NULL == msg, "malloc() in trouble_msg() failed."); sprintf(msg, "%s%s%s%s%s", p1, parent, p2, child, p3); return msg; } -extern void * try_malloc(size_t size, struct World * w, char * f) +extern void * try_malloc(size_t size, char * f) { - char * msg = trouble_msg(w, f, "malloc()"); + char * msg = trouble_msg(f, "malloc()"); void * p = malloc(size); - exit_err(NULL == p, w, msg); + exit_err(NULL == p, msg); free(msg); return p; } -extern void * try_calloc(size_t size1, size_t size2, struct World * w, char * f) +extern void * try_calloc(size_t size1, size_t size2, char * f) { - char * msg = trouble_msg(w, f, "calloc()"); + char * msg = trouble_msg(f, "calloc()"); void * p = calloc(size1, size2); - exit_err(NULL == p, w, msg); + exit_err(NULL == p, msg); free(msg); return p; } -extern void check_files_xor(char * p1, char * p2, struct World * w) +extern void check_files_xor(char * p1, char * p2) { char * msg1 = "A file '"; char * msg2 = "' exists, but no file '"; @@ -76,97 +76,97 @@ extern void check_files_xor(char * p1, char * p2, struct World * w) { sprintf(msg, "%s%s%s%s%s", msg1, p1, msg2, p2, msg3); errno = 0; - exit_err(1, w, msg); + exit_err(1, msg); } else if (access(p1, F_OK) && !access(p2, F_OK)) { sprintf(msg, "%s%s%s%s%s", msg1, p2, msg2, p1, msg3); errno = 0; - exit_err(1, w, msg); + exit_err(1, msg); } } -extern void check_tempfile(char * path, struct World * w) +extern void check_tempfile(char * path) { char * msg1 = "A file '"; char * msg2 = "' exists, probably from a corrupted previous file saving " - "process. To avoid corruption of game files, the game won't " - "start until it is removed or renamed."; + "process. To avoid corruption of game files, the game won't " + "start until it is removed or renamed."; uint16_t size = strlen(msg1) + strlen(path) + strlen(msg2); char msg[size]; sprintf(msg, "%s%s%s", msg1, path, msg2); - exit_err(!access(path, F_OK), w, msg); + exit_err(!access(path, F_OK), msg); } -extern void save_interface_conf(struct World * world) +extern void save_interface_conf() { - save_keybindings(world, "config/keybindings_global", &world->kb_global); - save_keybindings(world, "config/keybindings_wingeom", &world->kb_wingeom); - save_keybindings(world, "config/keybindings_winkeys", &world->kb_winkeys); - save_win_configs(world); + save_keybindings("config/keybindings_global", &world.kb_global); + save_keybindings("config/keybindings_wingeom", &world.kb_wingeom); + save_keybindings("config/keybindings_winkeys", &world.kb_winkeys); + save_win_configs(); } -extern void load_interface_conf(struct World * world) +extern void load_interface_conf() { - init_keybindings(world, "config/keybindings_global", &world->kb_global); - init_keybindings(world, "config/keybindings_wingeom", &world->kb_wingeom); - init_keybindings(world, "config/keybindings_winkeys", &world->kb_winkeys); - init_winconfs(world); - init_wins(world); - sorted_wintoggle_and_activate(world); + init_keybindings("config/keybindings_global", &world.kb_global); + init_keybindings("config/keybindings_wingeom", &world.kb_wingeom); + init_keybindings("config/keybindings_winkeys", &world.kb_winkeys); + init_winconfs(); + init_wins(); + sorted_wintoggle_and_activate(); } -extern void unload_interface_conf(struct World * world) +extern void unload_interface_conf() { - free_keybindings(world->kb_global.kbs); - free_keybindings(world->kb_wingeom.kbs); - free_keybindings(world->kb_winkeys.kbs); - while (0 != world->wmeta->active) + free_keybindings(world.kb_global.kbs); + free_keybindings(world.kb_wingeom.kbs); + free_keybindings(world.kb_winkeys.kbs); + while (0 != world.wmeta->active) { - suspend_win(world->wmeta, world->wmeta->active); + suspend_win(world.wmeta, world.wmeta->active); } - free_winconfs(world); + free_winconfs(); } -extern void update_log(struct World * world, char * text) +extern void update_log(char * text) { char * f_name = "update_log()"; static char * last_msg; /* TODO: valgrind is dissatisfied */ if (0 == last_msg) /* with this calloc'd pointer not */ { /* being freed. Rectify this? */ - last_msg = try_calloc(1, sizeof(char), world, f_name); + last_msg = try_calloc(1, sizeof(char), f_name); } char * new_text; - uint16_t len_old = strlen(world->log); + uint16_t len_old = strlen(world.log); if (0 == strcmp(last_msg, text)) { uint16_t len_whole = len_old + 1; - new_text = try_calloc(len_whole + 1, sizeof(char), world, f_name); - memcpy(new_text, world->log, len_old); + new_text = try_calloc(len_whole + 1, sizeof(char), f_name); + memcpy(new_text, world.log, len_old); memcpy(new_text + len_old, ".", 1); } else { uint16_t len_new = strlen(text); uint16_t len_whole = len_old + len_new + 1; - new_text = try_calloc(len_whole, sizeof(char), world, f_name); - memcpy(new_text, world->log, len_old); + new_text = try_calloc(len_whole, sizeof(char), f_name); + memcpy(new_text, world.log, len_old); memcpy(new_text + len_old, text, len_new); - last_msg = try_calloc(len_new + 1, sizeof(char), world, f_name); + last_msg = try_calloc(len_new + 1, sizeof(char), f_name); memcpy(last_msg, text, len_new); } - free(world->log); - world->log = new_text; + free(world.log); + world.log = new_text; } @@ -194,7 +194,7 @@ extern uint16_t center_offset(uint16_t pos, uint16_t mapsize, -extern void turn_over(struct World * world, char action) +extern void turn_over(char action) { char * f_name = "turn_over()"; char * err_write = "Trouble in turn_over() with write_uint8() " @@ -202,76 +202,73 @@ extern void turn_over(struct World * world, char action) char * recordfile_tmp = "record_tmp"; char * recordfile = "record"; - if (1 == world->interactive) + if (1 == world.interactive) { - FILE * file_old = try_fopen(recordfile, "r", world, f_name); - FILE * file_new = try_fopen(recordfile_tmp, "w", world, f_name); + FILE * file_old = try_fopen(recordfile, "r", f_name); + FILE * file_new = try_fopen(recordfile_tmp, "w", f_name); char c = fgetc(file_old); while (EOF != c) { - exit_err(write_uint8(c, file_new), world, err_write); + exit_err(write_uint8(c, file_new), err_write); c = fgetc(file_old); } - try_fclose(file_old, world, f_name); - exit_err(write_uint8(action, file_new), world, err_write); - if (is_command_id_shortdsc(world, action, "drop")) + try_fclose(file_old, f_name); + exit_err(write_uint8(action, file_new), err_write); + if (is_command_id_shortdsc(action, "drop")) { - uint8_t inventory_select = world->old_inventory_select; - exit_err(write_uint8(inventory_select, file_new), world, err_write); + uint8_t inventory_select = world.old_inventory_select; + exit_err(write_uint8(inventory_select, file_new), err_write); } - try_fclose_unlink_rename(file_new, recordfile_tmp, recordfile, - world, f_name); + try_fclose_unlink_rename(file_new, recordfile_tmp, recordfile, f_name); } - world->turn++; - rrand_seed(world->seed * world->turn); + world.turn++; + rrand_seed(world.seed * world.turn); struct MapObj * monster; - for (monster = world->map_objs; - monster != 0; - monster = monster->next) + for (monster = world.map_objs; monster != 0; monster = monster->next) { if (0 < monster->lifepoints && 0 != monster->id) { - move_actor(world, monster, rrand() % 5); + move_actor(monster, rrand() % 5); } } } -extern void save_game(struct World * world) +extern void save_game() { char * f_name = "save_game()"; char * savefile_tmp = "savefile_tmp"; char * savefile = "savefile"; - FILE * file = try_fopen(savefile_tmp, "w", world, f_name); + FILE * file = try_fopen(savefile_tmp, "w", f_name); char line[12]; - sprintf(line, "%d\n", world->seed); - try_fwrite(line, strlen(line), 1, file, world, f_name); - sprintf(line, "%d\n", world->turn); - try_fwrite(line, strlen(line), 1, file, world, f_name); - sprintf(line, "%d\n", world->score); - try_fwrite(line, strlen(line), 1, file, world, f_name); - write_map_objects(world, file); - try_fclose_unlink_rename(file, savefile_tmp, savefile, world, f_name); + sprintf(line, "%d\n", world.seed); + try_fwrite(line, strlen(line), 1, file, f_name); + sprintf(line, "%d\n", world.turn); + try_fwrite(line, strlen(line), 1, file, f_name); + sprintf(line, "%d\n", world.score); + try_fwrite(line, strlen(line), 1, file, f_name); + write_map_objects(file); + try_fclose_unlink_rename(file, savefile_tmp, savefile, f_name); } -extern void load_game(struct World * world) +extern void load_game() { char * f_name = "load_game2()"; char * filename = "savefile"; - FILE * file = try_fopen(filename, "r", world, f_name); - uint16_t linemax = get_linemax(file, world, f_name); + FILE * file = try_fopen(filename, "r", f_name); + uint16_t linemax = get_linemax(file, f_name); char line[linemax + 1]; - try_fgets(line, linemax + 1, file, world, f_name); - world->seed = atoi(line); - try_fgets(line, linemax + 1, file, world, f_name); - world->turn = atoi(line); - try_fgets(line, linemax + 1, file, world, f_name); - world->score = atoi(line); - read_map_objects(world, file, line, linemax); - try_fclose(file, world, f_name); + try_fgets(line, linemax + 1, file, f_name); + world.seed = atoi(line); + try_fgets(line, linemax + 1, file, f_name); + world.turn = atoi(line); + try_fgets(line, linemax + 1, file, f_name); + world.score = atoi(line); + read_map_objects(file, line, linemax); + try_fclose(file, f_name); } @@ -289,17 +286,17 @@ extern struct yx_uint16 find_passable_pos(struct Map * map) -extern void nav_inventory(struct World * world, char dir) +extern void nav_inventory(char dir) { if ('u' == dir) { - if (world->inventory_select > 0) + if (world.inventory_select > 0) { - world->inventory_select--; + world.inventory_select--; } return; } - struct MapObj * player = get_player(world); + struct MapObj * player = get_player(); struct MapObj * owned = player->owns; if (NULL == owned) { @@ -307,8 +304,8 @@ extern void nav_inventory(struct World * world, char dir) } uint8_t n_owned = 0; for (; NULL != owned->next; owned = owned->next, n_owned++); - if (world->inventory_select < n_owned) + if (world.inventory_select < n_owned) { - world->inventory_select++; + world.inventory_select++; } } diff --git a/src/misc.h b/src/misc.h index c823af6..ed906c2 100644 --- a/src/misc.h +++ b/src/misc.h @@ -7,47 +7,43 @@ #ifndef MISC_H #define MISC_H - - #include /* for size_t */ #include /* for uint16_t */ #include "yx_uint16.h" /* for yx_uint16 coordinates */ -struct World; struct Map; /* Returns message: "Trouble in ".parent." with ".child."." (try_*() helper) */ -extern char * trouble_msg(struct World * w, char * parent, char * child); +extern char * trouble_msg(char * parent, char * child); /* Wrappers to malloc(), calloc() from function called "f" calling exit_err() * with trouble_msg() error message if necessary. */ -extern void * try_malloc(size_t size, struct World * w, char * f); -extern void * try_calloc(size_t nmemb, size_t size, - struct World * w, char * f); +extern void * try_malloc(size_t size, char * f); +extern void * try_calloc(size_t nmemb, size_t size, char * f); /* Check if tempfile "path" exists, and if so, exit with explanation that. */ -extern void check_tempfile(char * path, struct World * f); +extern void check_tempfile(char * path); /* If one and only one of files at "p1", "p2" exists, fail with explanation. */ -extern void check_files_xor(char * p1, char * p2, struct World * w); +extern void check_files_xor(char * p1, char * p2); /* Save / load / unload (free) interface configuration data. */ -extern void save_interface_conf(struct World * world); -extern void load_interface_conf(struct World * world); -extern void unload_interface_conf(struct World * world); +extern void save_interface_conf(); +extern void load_interface_conf(); +extern void unload_interface_conf(); /* Update game log by appending "text", or by appending a "." if "text" is the * same as the last one passed. */ -extern void update_log(struct World * world, char * text); +extern void update_log(char * text); @@ -62,13 +58,13 @@ extern uint16_t center_offset(uint16_t pos, /* Record last player "action" in game record file "record, increment the game * turn and trigger enemy movement. */ -extern void turn_over(struct World * world, char action); +extern void turn_over(char action); /* Save or load current game data to / from file "savefile". */ -extern void save_game(struct World * world); -extern void load_game(struct World * world); +extern void save_game(); +extern void load_game(); @@ -82,7 +78,7 @@ extern struct yx_uint16 find_passable_pos(struct Map * map); /* Navigate (as far as possible) up (dir=='u') or (else) down in player's * inventory selection. */ -extern void nav_inventory(struct World * world, char dir); +extern void nav_inventory(char dir); diff --git a/src/readwrite.c b/src/readwrite.c index 657d817..4bdf5ae 100644 --- a/src/readwrite.c +++ b/src/readwrite.c @@ -9,7 +9,7 @@ #include /* for unlink() */ #include "rexit.h" /* for exit_err() */ #include "misc.h" /* for trouble_msg() */ -struct World; +#include "main.h" /* for world global */ @@ -33,7 +33,7 @@ static uint8_t write_uintX_bigendian(FILE * file, uint32_t x, uint8_t size); -extern FILE * try_fopen(char * path, char * mode, struct World * w, char * f) +extern FILE * try_fopen(char * path, char * mode, char * f) { char * msg1 = "Trouble in "; char * msg2 = " with fopen() (mode '"; @@ -44,27 +44,26 @@ extern FILE * try_fopen(char * path, char * mode, struct World * w, char * f) char msg[size]; sprintf(msg, "%s%s%s%s%s%s%s", msg1, f, msg2, mode, msg3, path, msg4); FILE * file_p = fopen(path, mode); - exit_err(NULL == file_p, w, msg); + exit_err(NULL == file_p, msg); return file_p; } -extern void try_fclose(FILE * file, struct World * w, char * f) +extern void try_fclose(FILE * file, char * f) { - char * msg = trouble_msg(w, f, "fclose()"); - exit_err(fclose(file), w, msg); + char * msg = trouble_msg(f, "fclose()"); + exit_err(fclose(file), msg); free(msg); } -extern char * try_fgets(char * line, int linemax, FILE * file, - struct World * w, char * f) +extern char * try_fgets(char * line, int linemax, FILE * file, char * f) { - char * msg = trouble_msg(w, f, "fgets()"); + char * msg = trouble_msg(f, "fgets()"); char * test = fgets(line, linemax, file); - exit_err(NULL == test && ferror(file), w, msg); + exit_err(NULL == test && ferror(file), msg); free(msg); return test; } @@ -72,19 +71,19 @@ extern char * try_fgets(char * line, int linemax, FILE * file, extern void try_fwrite(void * ptr, size_t size, size_t nmemb, FILE * stream, - struct World * w, char * f) + char * f) { - char * msg = trouble_msg(w, f, "fwrite()"); - exit_err(0 == fwrite(ptr, size, nmemb, stream), w, msg); + char * msg = trouble_msg(f, "fwrite()"); + exit_err(0 == fwrite(ptr, size, nmemb, stream), msg); free(msg); } extern void try_fclose_unlink_rename(FILE * file, char * p1, char * p2, - struct World * w, char * f) + char * f) { - try_fclose(file, w, f); + try_fclose(file, f); char * msg1 = "Trouble in "; char * msg4 = "'."; if (!access(p2, F_OK)) @@ -94,7 +93,7 @@ extern void try_fclose_unlink_rename(FILE * file, char * p1, char * p2, + strlen(f) + strlen(p2) + 1; char msg[size]; sprintf(msg, "%s%s%s%s%s", msg1, f, msg2, p2, msg4); - exit_err(unlink(p2), w, msg); + exit_err(unlink(p2), msg); } char * msg2 = " with rename() from '"; char * msg3 = "' to '"; @@ -102,16 +101,16 @@ extern void try_fclose_unlink_rename(FILE * file, char * p1, char * p2, + strlen(msg3) + strlen(p2) + strlen(msg4) + 1; char msg[size]; sprintf(msg, "%s%s%s%s%s%s%s", msg1, f, msg2, p1, msg3, p2, msg4); - exit_err(rename(p1, p2), w, msg); + exit_err(rename(p1, p2), msg); } -extern uint16_t get_linemax(FILE * file, struct World * w, char * f) +extern uint16_t get_linemax(FILE * file, char * f) { - char * msg = trouble_msg(w, f, "textfile_sizes()"); + char * msg = trouble_msg(f, "textfile_sizes()"); uint16_t linemax; - exit_err(textfile_sizes(file, &linemax, NULL), w, msg); + exit_err(textfile_sizes(file, &linemax, NULL), msg); free(msg); return linemax; } diff --git a/src/readwrite.h b/src/readwrite.h index 99d490c..2810820 100644 --- a/src/readwrite.h +++ b/src/readwrite.h @@ -6,21 +6,18 @@ #ifndef READWRITE_H #define READWRITE_H - - #include /* for FILE typedef */ #include /* for uint8_t, uint16_t, uint32_t */ -struct World; /* Wrappers to calling from function called "f" of fopen(), fclose(), fgets() * and fwrite() and calling exit_err() with appropriate error messages. */ -extern FILE * try_fopen(char * path, char * mode, struct World * w, char * f); -extern void try_fclose(FILE * file, struct World * w, char * f); +extern FILE * try_fopen(char * path, char * mode, char * f); +extern void try_fclose(FILE * file, char * f); extern void try_fwrite(void * ptr, size_t size, size_t nmemb, FILE * stream, - struct World * w, char * f); + char * f); @@ -28,8 +25,7 @@ extern void try_fwrite(void * ptr, size_t size, size_t nmemb, FILE * stream, * fgets() is returned unless it is NULL *and* ferror() indicates that an error * occured; otherwise end of file is assumed and NULL is returned properly. */ -extern char * try_fgets(char * line, int size, FILE * file, - struct World * w, char * f); +extern char * try_fgets(char * line, int size, FILE * file, char * f); @@ -38,7 +34,7 @@ extern char * try_fgets(char * line, int size, FILE * file, * Used for handling atomic saving of files via temp files. */ extern void try_fclose_unlink_rename(FILE * file, char * p1, char * p2, - struct World * w, char * f); + char * f); @@ -46,7 +42,7 @@ extern void try_fclose_unlink_rename(FILE * file, char * p1, char * p2, * length of "file", exit via exit_err() with trouble_msg()-generated error * message on failure. */ -extern uint16_t get_linemax(FILE * file, struct World * w, char * f); +extern uint16_t get_linemax(FILE * file, char * f); @@ -73,4 +69,6 @@ extern uint8_t write_uint8(uint8_t x, FILE * file); extern uint8_t write_uint16_bigendian(uint16_t x, FILE * file); extern uint8_t write_uint32_bigendian(uint32_t x, FILE * file); + + #endif diff --git a/src/rexit.c b/src/rexit.c index 5fa660e..6f14663 100644 --- a/src/rexit.c +++ b/src/rexit.c @@ -6,24 +6,23 @@ #include /* for uint8_t */ #include /* for endwin() */ #include /* for errno */ -#include "main.h" /* for World struct */ +#include "main.h" /* for world global */ #include "map.h" /* for Map struct */ #include "keybindings.h" /* for free_keybindings() */ #include "command_db.h" /* for free_command_db() */ #include "windows.h" /* for Win struct, free_win(), free_winmeta() */ #include "map_objects.h" /* for free_map_objects, free_map_object_defs() */ -#include "wincontrol.h" /* for free_winconfs() */ #include "misc.h" /* for unload_interface_conf() */ /* The clean-up routine and the flag resource by which it decides what to do. */ static uint32_t cleanup_flags = 0x0000; -static void cleanup(struct World * world); +static void cleanup(); -static void cleanup(struct World * world) +static void cleanup() { if (cleanup_flags & CLEANUP_NCURSES) { @@ -31,31 +30,31 @@ static void cleanup(struct World * world) } if (cleanup_flags & CLEANUP_MAP_OBJECTS) { - free_map_objects(world->map_objs); + free_map_objects(world.map_objs); } if (cleanup_flags & CLEANUP_MAP_OBJECT_DEFS) { - free_map_object_defs(world->map_obj_defs); + free_map_object_defs(world.map_obj_defs); } if (cleanup_flags & CLEANUP_LOG) { - free(world->log); + free(world.log); } if (cleanup_flags & CLEANUP_COMMAND_DB) { - free_command_db(world); + free_command_db(); } if (cleanup_flags & CLEANUP_MAP) { - free(world->map->cells); + free(world.map->cells); } if (cleanup_flags & CLEANUP_INTERFACE_CONF) { - unload_interface_conf(world); + unload_interface_conf(/*&world*/); } if (cleanup_flags & CLEANUP_WIN_META) { - free_winmeta(world->wmeta); + free_winmeta(world.wmeta); } } @@ -68,21 +67,21 @@ extern void set_cleanup_flag(enum cleanup_flag flag) -extern void exit_game(struct World * world) +extern void exit_game() { - cleanup(world); + cleanup(); exit(EXIT_SUCCESS); } -extern void exit_err(uint8_t err, struct World * world, char * msg) +extern void exit_err(uint8_t err, char * msg) { if (0 == err) { return; } - cleanup(world); + cleanup(); if (NULL == msg) { msg = "Details unknown."; diff --git a/src/rexit.h b/src/rexit.h index 4c6ddb0..3ccd470 100644 --- a/src/rexit.h +++ b/src/rexit.h @@ -10,7 +10,6 @@ #include /* for uint8_t */ -struct World; @@ -34,7 +33,7 @@ extern void set_cleanup_flag(enum cleanup_flag flag); /* Exit orderly, clean up. */ -extern void exit_game(struct World * world); +extern void exit_game(); @@ -43,7 +42,7 @@ extern void exit_game(struct World * world); * unknown", secondly of "err" as the "internal error code", and thirdly of * errno if it is non-zero. */ -extern void exit_err(uint8_t err, struct World * world, char * msg); +extern void exit_err(uint8_t err, char * msg); diff --git a/src/rrand.h b/src/rrand.h index 1b18057..47f561f 100644 --- a/src/rrand.h +++ b/src/rrand.h @@ -5,8 +5,6 @@ * srand() to ensure portable pseudo-randomness portability. */ - - #ifndef RRAND_H #define RRAND_H diff --git a/src/wincontrol.c b/src/wincontrol.c index 5680ff9..41ba945 100644 --- a/src/wincontrol.c +++ b/src/wincontrol.c @@ -15,7 +15,7 @@ * try_fgets(), try_fclose_unlink_rename(), try_fwrite() */ #include "rexit.h" /* for exit_err() */ -#include "main.h" /* for World struct */ +#include "main.h" /* for world global */ #include "draw_wins.h" /* for draw_win_map(), draw_win_info(), draw_win_og(), * draw_win_available_keybindings(), * draw_win_keybindings_global(), draw_win_inventory(), @@ -31,49 +31,49 @@ /* Return string "prefix" + "id"; malloc()'s string, remember to call free()! */ -static char * string_prefixed_id(struct World * world, char * prefix, char id); +static char * string_prefixed_id(char * prefix, char id); /* Create Winconf, init ->view/height_type/width_type to 0, ->id to "id". */ -static void create_winconf(struct World * world, char id, struct WinConf * wcp); +static void create_winconf(char id, struct WinConf * wcp); /* Initialize Winconf of "id" from appropriate config file.*/ -static void init_winconf_from_file(struct World * world, char id); +static void init_winconf_from_file(char id); /* Wrapper around init_win() called with values from Winconf of "id". */ -static void init_win_from_winconf(struct World * world, char id); +static void init_win_from_winconf(char id); /* Save title, draw function, size of window identified by "id" to conffile. */ -static void save_win_config(struct World * world, char id); +static void save_win_config(char id); /* Free data pointed to inside WinConf struct. */ -static void free_winconf_data(struct World * world, char id); +static void free_winconf_data(char id); /* Write geometry of a window to its WinConf, as positive or negative values * (dependent on state ofWinConf->height_type / WinConf->width_type). */ -static void set_winconf_geometry(struct World * world, char id); +static void set_winconf_geometry(char id); /* Get WinConf by "id"; get id of WinConf mothering "win". */ -static struct WinConf * get_winconf_by_id(struct World * world, char id); +static struct WinConf * get_winconf_by_id(char id); /* Get (Win->draw) function identified by "c"; NULL if c not mapped to one. */ static void * get_drawfunc_by_char(char c); -/* Iterate over bytes of world->winconf_ids array. Re-start after null byte. */ -static char get_next_winconf_id(struct World * world); +/* Iterate over bytes of world.winconf_ids array. Re-start after null byte. */ +static char get_next_winconf_id(); -static char * string_prefixed_id(struct World * world, char * prefix, char id) +static char * string_prefixed_id(char * prefix, char id) { uint8_t size = strlen(prefix) + 2; - char * path = try_malloc(size, world, "string_prefixed_id()"); + char * path = try_malloc(size, "string_prefixed_id()"); sprintf(path, "%s_", prefix); path[size - 2] = id; return path; @@ -81,7 +81,7 @@ static char * string_prefixed_id(struct World * world, char * prefix, char id) -static void create_winconf(struct World * world, char id, struct WinConf * wcp) +static void create_winconf(char id, struct WinConf * wcp) { wcp->id = id; wcp->view = 0; @@ -93,36 +93,35 @@ static void create_winconf(struct World * world, char id, struct WinConf * wcp) -static void init_winconf_from_file(struct World * world, char id) +static void init_winconf_from_file(char id) { char * tmp = "init_winconf_from_file() on window id '_'"; - char * context = try_malloc(strlen(tmp) + 1, world, - "init_winconf_from_file()"); + char * context = try_malloc(strlen(tmp) + 1, "init_winconf_from_file()"); memcpy(context, tmp, strlen(tmp) + 1); context[strlen(tmp) - 2] = id; - char * path = string_prefixed_id(world, "config/windows/Win_", id); - FILE * file = try_fopen(path, "r", world, context); + char * path = string_prefixed_id("config/windows/Win_", id); + FILE * file = try_fopen(path, "r", context); free(path); - uint16_t linemax = get_linemax(file, world, context); + uint16_t linemax = get_linemax(file, context); char line[linemax + 1]; - struct WinConf * winconf = get_winconf_by_id(world, id); - try_fgets(line, linemax + 1, file, world, context); - winconf->title = try_malloc(strlen(line), world, context); + struct WinConf * winconf = get_winconf_by_id(id); + try_fgets(line, linemax + 1, file, context); + winconf->title = try_malloc(strlen(line), context); memcpy(winconf->title, line, strlen(line) - 1); /* Eliminate newline char */ winconf->title[strlen(line) - 1] = '\0'; /* char at end of string. */ - try_fgets(line, linemax + 1, file, world, context); + try_fgets(line, linemax + 1, file, context); winconf->draw = line[0]; - try_fgets(line, linemax + 1, file, world, context); + try_fgets(line, linemax + 1, file, context); winconf->height = atoi(line); if (0 >= winconf->height) { winconf->height_type = 1; } - try_fgets(line, linemax + 1, file, world, context); + try_fgets(line, linemax + 1, file, context); winconf->width = atoi(line); if (0 >= winconf->width) { @@ -139,48 +138,48 @@ static void init_winconf_from_file(struct World * world, char id) { break; } - * loc_last_ptr = try_malloc(sizeof(struct KeyBinding), world, context); + * loc_last_ptr = try_malloc(sizeof(struct KeyBinding), context); struct KeyBinding * kb_p = * loc_last_ptr; kb_p->next = 0; kb_p->key = atoi(command); cmdptr = strchr(command, ' ') + 1; - kb_p->name = try_malloc(strlen(cmdptr), world, context); + kb_p->name = try_malloc(strlen(cmdptr), context); memcpy(kb_p->name, cmdptr, strlen(cmdptr) - 1); kb_p->name[strlen(cmdptr) - 1] = '\0'; loc_last_ptr = & kb_p->next; } - try_fclose(file, world, context); + try_fclose(file, context); free(context); } -static void init_win_from_winconf(struct World * world, char id) +static void init_win_from_winconf(char id) { char * tmp = "Trouble in init_win_from_file() with init_win() (win id: _)."; - char * err = try_malloc(strlen(tmp) + 1, world, "init_win_from_file()"); + char * err = try_malloc(strlen(tmp) + 1, "init_win_from_file()"); memcpy(err, tmp, strlen(tmp) + 1); err[strlen(tmp) - 3] = id; - struct WinConf * winconf = get_winconf_by_id(world, id); + struct WinConf * winconf = get_winconf_by_id(id); void * f = get_drawfunc_by_char(winconf->draw); - exit_err(NULL == f, world, err); - exit_err(init_win(world->wmeta, &winconf->win, winconf->title, - winconf->height, winconf->width, world, f), - world, err); + exit_err(NULL == f, err); + uint8_t test = init_win(world.wmeta, &winconf->win, winconf->title, + winconf->height, winconf->width, f); + exit_err(test, err); free(err); } -static void save_win_config(struct World * world, char id) +static void save_win_config(char id) { char * f_name = "save_win_config()"; - char * path_tmp = string_prefixed_id(world, "config/windows/Win_tmp_", id); - FILE * file = try_fopen(path_tmp, "w", world, f_name); + char * path_tmp = string_prefixed_id("config/windows/Win_tmp_", id); + FILE * file = try_fopen(path_tmp, "w", f_name); - struct WinConf * wc = get_winconf_by_id(world, id); + struct WinConf * wc = get_winconf_by_id(id); uint8_t size = strlen(wc->title) + 2; if (size < 7) { @@ -188,13 +187,13 @@ static void save_win_config(struct World * world, char id) } char line[size]; sprintf(line, "%s\n", wc->title); - try_fwrite(line, sizeof(char), strlen(line), file, world, f_name); + try_fwrite(line, sizeof(char), strlen(line), file, f_name); sprintf(line, "%c\n", wc->draw); - try_fwrite(line, sizeof(char), strlen(line), file, world, f_name); + try_fwrite(line, sizeof(char), strlen(line), file, f_name); sprintf(line, "%d\n", wc->height); - try_fwrite(line, sizeof(char), strlen(line), file, world, f_name); + try_fwrite(line, sizeof(char), strlen(line), file, f_name); sprintf(line, "%d\n", wc->width); - try_fwrite(line, sizeof(char), strlen(line), file, world, f_name); + try_fwrite(line, sizeof(char), strlen(line), file, f_name); uint16_t linemax = 0; struct KeyBinding * kb_p = wc->kb.kbs; @@ -213,21 +212,21 @@ static void save_win_config(struct World * world, char id) while (0 != kb_p) { snprintf(kb_line, linemax, "%d %s\n", kb_p->key, kb_p->name); - try_fwrite(kb_line, sizeof(char), strlen(kb_line), file, world, f_name); + try_fwrite(kb_line, sizeof(char), strlen(kb_line), file, f_name); kb_p = kb_p->next; } - char * path = string_prefixed_id(world, "config/windows/Win_", id); - try_fclose_unlink_rename(file, path_tmp, path, world, f_name); + char * path = string_prefixed_id("config/windows/Win_", id); + try_fclose_unlink_rename(file, path_tmp, path, f_name); free(path); free(path_tmp); } -static void free_winconf_data(struct World * world, char id) +static void free_winconf_data(char id) { - struct WinConf * wc = get_winconf_by_id(world, id); + struct WinConf * wc = get_winconf_by_id(id); free(wc->title); free_keybindings(wc->kb.kbs); free_win(wc->win); @@ -235,16 +234,16 @@ static void free_winconf_data(struct World * world, char id) -static void set_winconf_geometry(struct World * world, char id) +static void set_winconf_geometry(char id) { - struct WinConf * wcp = get_winconf_by_id(world, id); + struct WinConf * wcp = get_winconf_by_id(id); if (0 == wcp->height_type) { wcp->height = wcp->win->framesize.y; } else if (1 == wcp->height_type) { - wcp->height = wcp->win->framesize.y - world->wmeta->padsize.y + 1; + wcp->height = wcp->win->framesize.y - world.wmeta->padsize.y + 1; } if (0 == wcp->width_type) { @@ -252,20 +251,20 @@ static void set_winconf_geometry(struct World * world, char id) } else if (1 == wcp->width_type) { - wcp->width = wcp->win->framesize.x - world->wmeta->padsize.x; + wcp->width = wcp->win->framesize.x - world.wmeta->padsize.x; } } -static struct WinConf * get_winconf_by_id(struct World * world, char id) +static struct WinConf * get_winconf_by_id(char id) { uint8_t i = 0; while (1) { - if (id == world->winconfs[i].id) + if (id == world.winconfs[i].id) { - return &world->winconfs[i]; + return &world.winconfs[i]; } i++; } @@ -312,10 +311,10 @@ static void * get_drawfunc_by_char(char c) -static char get_next_winconf_id(struct World * world) +static char get_next_winconf_id() { static uint8_t i = 0; - char c = world->winconf_ids[i]; + char c = world.winconf_ids[i]; if (0 == c) { i = 0; @@ -329,15 +328,14 @@ static char get_next_winconf_id(struct World * world) -extern struct WinConf * get_winconf_by_win(struct World * world, - struct Win * win) +extern struct WinConf * get_winconf_by_win(struct Win * win) { uint8_t i = 0; while (1) { - if (win == world->winconfs[i].win) + if (win == world.winconfs[i].win) { - return &world->winconfs[i]; + return &world.winconfs[i]; } i++; } @@ -345,15 +343,15 @@ extern struct WinConf * get_winconf_by_win(struct World * world, -extern struct Win * get_win_by_id(struct World * world, char id) +extern struct Win * get_win_by_id(char id) { - struct WinConf * wc = get_winconf_by_id(world, id); + struct WinConf * wc = get_winconf_by_id(id); return wc->win; } -extern void init_winconfs(struct World * world) +extern void init_winconfs() { char * f_name = "init_winconfs()"; char * err_o = "Trouble in init_winconfs() with opendir()."; @@ -361,16 +359,15 @@ extern void init_winconfs(struct World * world) char * err_c = "Trouble in init_winconfs() with closedir()."; DIR * dp = opendir("config/windows"); - exit_err(NULL == dp, world, err_o); + exit_err(NULL == dp, err_o); struct dirent * fn; errno = 0; - char * winconf_ids = try_malloc(256, world, f_name); + char * winconf_ids = try_malloc(256, f_name); uint8_t i = 0; char id; while (NULL != (fn = readdir(dp))) { - if ( 5 == strlen(fn->d_name) - && fn->d_name == strstr(fn->d_name, "Win_")) + if (5 == strlen(fn->d_name) && fn->d_name == strstr(fn->d_name, "Win_")) { id = fn->d_name[4]; winconf_ids[i] = id; @@ -378,125 +375,125 @@ extern void init_winconfs(struct World * world) } } winconf_ids[i] = '\0'; - exit_err(errno, world, err_r); - exit_err(closedir(dp), world, err_c); - world->winconf_ids = try_malloc(strlen(winconf_ids) + 1, world, f_name); - memcpy(world->winconf_ids, winconf_ids, strlen(winconf_ids) + 1); + exit_err(errno, err_r); + exit_err(closedir(dp), err_c); + world.winconf_ids = try_malloc(strlen(winconf_ids) + 1, f_name); + memcpy(world.winconf_ids, winconf_ids, strlen(winconf_ids) + 1); free(winconf_ids); struct WinConf * winconfs; - winconfs = try_malloc(strlen(world->winconf_ids) * sizeof(struct WinConf), - world, f_name); + winconfs = try_malloc(strlen(world.winconf_ids) * sizeof(struct WinConf), + f_name); i = 0; - while (0 != (id = get_next_winconf_id(world))) + while (0 != (id = get_next_winconf_id())) { - create_winconf(world, id, &winconfs[i]); + create_winconf(id, &winconfs[i]); i++; } - world->winconfs = winconfs; - while (0 != (id = get_next_winconf_id(world))) + world.winconfs = winconfs; + while (0 != (id = get_next_winconf_id())) { - init_winconf_from_file(world, id); + init_winconf_from_file(id); i++; } } -extern void free_winconfs(struct World * world) +extern void free_winconfs() { char id; - while (0 != (id = get_next_winconf_id(world))) + while (0 != (id = get_next_winconf_id())) { - free_winconf_data(world, id); + free_winconf_data(id); } - free(world->winconf_ids); - free(world->winconfs); + free(world.winconf_ids); + free(world.winconfs); } -extern void init_wins(struct World * world) +extern void init_wins() { char id; - while (0 != (id = get_next_winconf_id(world))) + while (0 != (id = get_next_winconf_id())) { - init_win_from_winconf(world, id); + init_win_from_winconf(id); } } -extern void sorted_wintoggle_and_activate(struct World * world) +extern void sorted_wintoggle_and_activate() { char * f_name = "sorted_wintoggle_and_activate()"; char * path = "config/windows/toggle_order_and_active"; - FILE * file = try_fopen(path, "r", world, f_name); - uint16_t linemax = get_linemax(file, world, f_name); + FILE * file = try_fopen(path, "r", f_name); + uint16_t linemax = get_linemax(file, f_name); char win_order[linemax + 1]; - try_fgets(win_order, linemax + 1, file, world, f_name); + try_fgets(win_order, linemax + 1, file, f_name); uint8_t a = 0; - char * err = trouble_msg(world, f_name, "read_uint8()"); - exit_err(read_uint8(file, &a), world, err); + char * err = trouble_msg(f_name, "read_uint8()"); + exit_err(read_uint8(file, &a), err); free(err); - try_fclose(file, world, f_name); + try_fclose(file, f_name); uint8_t i = 0; for (; i < linemax - 1; i++) { - if (NULL == strchr(world->winconf_ids, win_order[i])) + if (NULL == strchr(world.winconf_ids, win_order[i])) { continue; } - struct Win * win = get_win_by_id(world, win_order[i]); - toggle_window(world->wmeta, win); + struct Win * win = get_win_by_id(win_order[i]); + toggle_window(world.wmeta, win); if (a == (uint8_t) win_order[i]) { - world->wmeta->active = win; + world.wmeta->active = win; } } } -extern void save_win_configs(struct World * world) +extern void save_win_configs() { char * f_name = "save_win_configs()"; char id; - while (0 != (id = get_next_winconf_id(world))) + while (0 != (id = get_next_winconf_id())) { - save_win_config(world, id); + save_win_config(id); } char * path = "config/windows/toggle_order_and_active"; char * path_tmp = "config/windows/toggle_order_and_active_tmp"; - FILE * file = try_fopen(path_tmp, "w", world, f_name); + FILE * file = try_fopen(path_tmp, "w", f_name); char line[6]; - struct Win * w_p = world->wmeta->chain_start; + struct Win * w_p = world.wmeta->chain_start; uint8_t i = 0; while (0 != w_p) { - struct WinConf * wc = get_winconf_by_win(world, w_p); + struct WinConf * wc = get_winconf_by_win(w_p); line[i] = wc->id; w_p = w_p->next; i++; } line[i] = '\n'; - try_fwrite(line, sizeof(char), strlen(line), file, world, f_name); - if (0 != world->wmeta->active) + try_fwrite(line, sizeof(char), strlen(line), file, f_name); + if (0 != world.wmeta->active) { - struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active); + struct WinConf * wc = get_winconf_by_win(world.wmeta->active); write_uint8(wc->id, file); } - try_fclose_unlink_rename(file, path_tmp, path, world, f_name); + try_fclose_unlink_rename(file, path_tmp, path, f_name); } @@ -515,9 +512,9 @@ extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win) -extern void toggle_winconfig(struct World * world, struct Win * win) +extern void toggle_winconfig(struct Win * win) { - struct WinConf * wcp = get_winconf_by_win(world, win); + struct WinConf * wcp = get_winconf_by_win(win); if (0 == wcp->view) { win->draw = draw_winconf_geometry; @@ -542,9 +539,9 @@ extern void toggle_winconfig(struct World * world, struct Win * win) -extern void toggle_win_height_type(struct World * world, struct Win * win) +extern void toggle_win_height_type(struct Win * win) { - struct WinConf * wcp = get_winconf_by_win(world, win); + struct WinConf * wcp = get_winconf_by_win(win); if (0 == wcp->height_type) { wcp->height_type = 1; @@ -553,15 +550,15 @@ extern void toggle_win_height_type(struct World * world, struct Win * win) { wcp->height_type = 0; } - set_winconf_geometry(world, wcp->id); + set_winconf_geometry(wcp->id); } -extern void toggle_win_width_type(struct World * world, struct Win * win) +extern void toggle_win_width_type(struct Win * win) { - struct WinConf * wcp = get_winconf_by_win(world, win); - if (0 == wcp->width_type && win->framesize.x <= world->wmeta->padsize.x) + struct WinConf * wcp = get_winconf_by_win(win); + if (0 == wcp->width_type && win->framesize.x <= world.wmeta->padsize.x) { wcp->width_type = 1; } @@ -569,7 +566,7 @@ extern void toggle_win_width_type(struct World * world, struct Win * win) { wcp->width_type = 0; } - set_winconf_geometry(world, wcp->id); + set_winconf_geometry(wcp->id); } @@ -588,11 +585,11 @@ extern void scroll_pad(struct WinMeta * win_meta, char dir) -extern uint8_t growshrink_active_window(struct World * world, char change) +extern uint8_t growshrink_active_window(char change) { - if (0 != world->wmeta->active) + if (0 != world.wmeta->active) { - struct yx_uint16 size = world->wmeta->active->framesize; + struct yx_uint16 size = world.wmeta->active->framesize; if (change == '-') { size.y--; @@ -609,14 +606,14 @@ extern uint8_t growshrink_active_window(struct World * world, char change) { size.x++; } - uint8_t x = resize_active_win(world->wmeta, size); - struct WinConf * wcp = get_winconf_by_win(world, world->wmeta->active); + uint8_t x = resize_active_win(world.wmeta, size); + struct WinConf * wcp = get_winconf_by_win(world.wmeta->active); if ( 1 == wcp->width_type - && world->wmeta->active->framesize.x > world->wmeta->padsize.x) + && world.wmeta->active->framesize.x > world.wmeta->padsize.x) { wcp->width_type = 0; } - set_winconf_geometry(world, wcp->id); + set_winconf_geometry(wcp->id); return x; } return 0; diff --git a/src/wincontrol.h b/src/wincontrol.h index 09d78c9..f73ab4a 100644 --- a/src/wincontrol.h +++ b/src/wincontrol.h @@ -7,14 +7,11 @@ #ifndef WINCONTROL_H #define WINCONTROL_H - - #include /* for uint8_t, int16_t */ #include "keybindings.h" /* for KeyBiData struct */ #include "yx_uint16.h" /* for yx_uint16 struct */ struct Win; struct WinMeta; -struct World; @@ -42,32 +39,31 @@ struct WinConf /* Get WinConf fathering "win"; get Win of WinConf of "id". */ -extern struct WinConf * get_winconf_by_win(struct World * world, - struct Win * win); -extern struct Win * get_win_by_id(struct World * world, char id); +extern struct WinConf * get_winconf_by_win(struct Win * win); +extern struct Win * get_win_by_id(char id); /* Create/initialize (from config files)/free Winconf structs. */ -extern void init_winconfs(struct World * world); -extern void free_winconfs(struct World * world); -extern void init_wins(struct World * world); +extern void init_winconfs(); +extern void free_winconfs(); +extern void init_wins(); -/* Toggle windows in world->wins in the order desribed by the first line of +/* Toggle windows in world.wins in the order desribed by the first line of * config/windows/toggle_order_and_active, wherein each character should - * correspond to one window whose ID is found in world->winconf_ids. Unknown + * correspond to one window whose ID is found in world.winconf_ids. Unknown * characters are silently ignored. The first character of the second line of * the file is also read to determine which window to focus as active (but only * if it fits the ID of a window thus toggled visible). */ -extern void sorted_wintoggle_and_activate(struct World * world); +extern void sorted_wintoggle_and_activate(); /* Save all window's configurations to their configuration files. */ -extern void save_win_configs(struct World * world); +extern void save_win_configs(); @@ -75,15 +71,15 @@ extern void save_win_configs(struct World * world); * for win->center for the various configuration views (y=0, x=0 for * winconf_geometry and x= for winconf_keys). */ -extern void toggle_winconfig(struct World * world, struct Win * win); +extern void toggle_winconfig(struct Win * win); /* Toggle interpretation type for Win's width/height of Win in WinConf. Width * only toggles to 1 if terminal window is at least as wide as WinConf->width. */ -extern void toggle_win_height_type(struct World * world, struct Win * win); -extern void toggle_win_width_type(struct World * world, struct Win * win); +extern void toggle_win_height_type(struct Win * win); +extern void toggle_win_width_type(struct Win * win); @@ -111,7 +107,7 @@ extern void scroll_pad(struct WinMeta * win_meta, char dir); * * Return 0 on success, 1 on (ncurses pad/window memory allocation) error. */ -extern uint8_t growshrink_active_window(struct World * world, char change); +extern uint8_t growshrink_active_window(char change); diff --git a/src/windows.c b/src/windows.c index 5165179..2b5ea39 100644 --- a/src/windows.c +++ b/src/windows.c @@ -485,8 +485,7 @@ extern uint8_t init_win_meta(WINDOW * screen, struct WinMeta ** wmp) extern uint8_t init_win(struct WinMeta * wmeta, struct Win ** wp, char * title, - int16_t height, int16_t width, - void * data, void * func) + int16_t height, int16_t width, void * func) { struct Win * w = malloc(sizeof(struct Win)); if (NULL == w) @@ -504,7 +503,6 @@ extern uint8_t init_win(struct WinMeta * wmeta, struct Win ** wp, char * title, return 1; } sprintf(w->title, "%s", title); - w->data = data; w->draw = func; w->center.y = 0; w->center.x = 0; diff --git a/src/windows.h b/src/windows.h index e768f54..2a8f72d 100644 --- a/src/windows.h +++ b/src/windows.h @@ -25,8 +25,6 @@ * 1 - memory allocation error * 2 - would force virtual screen to grow beyond width or height of 2^16 cells * - * TODO: Expose less internals to the API. - * * TODO: Think up a more intuitive window positioning algorithm or at least make * the chain that windows are positioned by visible. */ @@ -34,8 +32,6 @@ #ifndef WINDOWS_H #define WINDOWS_H - - #include /* for uint8_t, uint16_t, uint32_t */ #include /* for the WINDOW and chtype typedefs */ #include "yx_uint16.h" /* for yx_uint16 struct */ @@ -58,7 +54,6 @@ struct Win struct yx_uint16 center; /* window content center to focus window on */ char * title; /* title to be used in window title bar */ void (* draw) (struct Win *); /* how to draw window content ("data") */ - void * data; /* window content to be drawn by _draw() */ chtype * winmap; /* sequence of cells, sorted into lines ... */ struct yx_uint16 winmapsize; /* ... with these geometry infos */ }; @@ -91,8 +86,7 @@ extern uint8_t init_win_meta(WINDOW * screen, struct WinMeta ** wmeta); /* Initialize a window child of "wmeta" to "title", "height" and "width" and - * appointing "func"() to interpret and draw the content stored at "data" when - * the window is visible. + * appointing "func"() to interpret and draw the window when it's visible. * * Pass 0 for "width" to make the window as wide as the terminal screen. Pass * negative values for "width" to make the width so many cells smaller than that @@ -106,8 +100,7 @@ extern uint8_t init_win_meta(WINDOW * screen, struct WinMeta ** wmeta); * Other members of the Win struct are initialized to 0. */ extern uint8_t init_win(struct WinMeta * wmeta, struct Win ** w, char * title, - int16_t height, int16_t width, - void * data, void * func); + int16_t height, int16_t width, void * func); diff --git a/src/yx_uint16.h b/src/yx_uint16.h index 325b224..86812f4 100644 --- a/src/yx_uint16.h +++ b/src/yx_uint16.h @@ -7,8 +7,6 @@ #ifndef YX_UINT16_H #define YX_UINT16_H - - #include /* for uint8_t, uint16_t */