From: Christian Heller Date: Wed, 26 Mar 2014 04:35:13 +0000 (+0100) Subject: Got rid of misc.h. Split off remains into array_append.h and control.h. X-Git-Tag: tce~799 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/static/gitweb.css?a=commitdiff_plain;h=539f4419afa0966d67b341dc6b30a6174bd3f844;p=plomrogue Got rid of misc.h. Split off remains into array_append.h and control.h. --- diff --git a/TODO b/TODO index 971c47a..825be24 100644 --- a/TODO +++ b/TODO @@ -25,5 +25,3 @@ CLIENT: - enable toggling of window borders - make log scrollable - -- re-organize code: empty misc.h into proper modules, split up windows.h diff --git a/src/client/array_append.c b/src/client/array_append.c new file mode 100644 index 0000000..f4391c7 --- /dev/null +++ b/src/client/array_append.c @@ -0,0 +1,24 @@ +/* src/client/array_append.c */ + +#include "array_append.h" +#include /* size_t */ +#include /* uint32_t */ +#include /* free() */ +#include /* memcpy() */ +#include "../common/try_malloc.h" /* try_malloc() */ + + + +extern void array_append(uint32_t old_n, size_t region_size, void * new_region, + void ** ptr_old_array) +{ + char * f_name = "array_append()"; + uint32_t old_size = old_n * region_size; + uint32_t new_size = old_size + region_size; + char * new_array = try_malloc(new_size, f_name); + memcpy(new_array, * ptr_old_array, old_size); + memcpy(new_array + (old_n * region_size), new_region, region_size); + free(* ptr_old_array); + * ptr_old_array = new_array; +} + diff --git a/src/client/array_append.h b/src/client/array_append.h new file mode 100644 index 0000000..b7cc7ef --- /dev/null +++ b/src/client/array_append.h @@ -0,0 +1,23 @@ +/* src/client/array_append.h + * + * Small memory management helper. + */ + +#ifndef ARRAY_APPEND_H +#define ARRAY_APPEND_H + +#include /* size_t */ +#include /* uint32_t */ + + + +/* Append to array pointed to by "ptr_old_array" of "old_n" elements of + * "region_size" "new region". + */ +extern void array_append(uint32_t old_n, size_t region_size, void * new_region, + void ** ptr_old_array); + + + +#endif + diff --git a/src/client/command_db.c b/src/client/command_db.c index 3837d2a..06329fc 100644 --- a/src/client/command_db.c +++ b/src/client/command_db.c @@ -10,7 +10,7 @@ #include "../common/readwrite.h" /* try_fopen(),try_fclose(),textfile_width() */ #include "../common/rexit.h" /* exit_trouble() */ #include "../common/try_malloc.h" /* try_malloc() */ -#include "misc.h" /* array_append() */ +#include "array_append.h" /* array_append() */ #include "world.h" /* global world */ #include "cleanup.h" /* set_cleanup_flag() */ diff --git a/src/client/control.c b/src/client/control.c index ed44d12..1961334 100644 --- a/src/client/control.c +++ b/src/client/control.c @@ -10,7 +10,6 @@ * mod_selected_keyb(), move_keyb_selection() */ #include "map.h" /* for map_scroll(), map_center() */ -#include "misc.h" /* nav_inventory() */ #include "wincontrol.h" /* shift_active_win(), resize_active_win(), * toggle_win_size_type(), toggle_window(), * cycle_active_win(), scroll_v_screen(), @@ -21,6 +20,9 @@ +/* Move world.inventory_sel up ("dir"="u") or down (else) as far as possible. */ +static void nav_inventory(char dir); + /* If "command"'s .dsc_short fits "match", apply "f" with provided char * arguments and return 1; else, return 0. */ @@ -43,6 +45,26 @@ static uint8_t try_server_commands(struct Command * command); +static void nav_inventory(char dir) +{ + if ('u' == dir) + { + world.player_inventory_select = world.player_inventory_select + - (world.player_inventory_select > 0); + return; + } + uint8_t n_elems = 0; + uint8_t i; + for (i = 0; '\0' != world.player_inventory[i]; i++) + { + n_elems = n_elems + ('\n' == world.player_inventory[i]); + } + world.player_inventory_select = world.player_inventory_select + + (world.player_inventory_select < n_elems); +} + + + static uint8_t try_0args(struct Command * command, char * match, void (* f) ()) { if (!strcmp(command->dsc_short, match)) diff --git a/src/client/interface_conf.c b/src/client/interface_conf.c index a67cb55..57dff9a 100644 --- a/src/client/interface_conf.c +++ b/src/client/interface_conf.c @@ -1,6 +1,6 @@ /* src/client/interface_conf.c */ -#include "misc.h" +#include "interface_conf.h" #include /* delwin() */ #include /* uint8_t, uint32_t */ #include /* FILE, sprintf() */ diff --git a/src/client/io.c b/src/client/io.c index 19dbb39..477700f 100644 --- a/src/client/io.c +++ b/src/client/io.c @@ -19,7 +19,6 @@ */ #include "control.h" /* try_key() */ #include "map.h" /* map_center() */ -#include "misc.h" /* reset_windows() */ #include "windows.h" /* reset_windows_on_winch(), draw_all_wins() */ #include "world.h" /* world global */ diff --git a/src/client/keybindings.c b/src/client/keybindings.c index 29e6c05..10cbffb 100644 --- a/src/client/keybindings.c +++ b/src/client/keybindings.c @@ -11,7 +11,7 @@ #include "../common/readwrite.h" /* try_fwrite()*/ #include "../common/try_malloc.h" /* try_malloc() */ #include "command_db.h" /* get_command() */ -#include "misc.h" /* array_append() */ +#include "array_append.h" /* array_append() */ #include "windows.h" /* draw_all_wins() */ #include "world.h" /* global world */ diff --git a/src/client/map.c b/src/client/map.c index 5e4e9c6..7292c89 100644 --- a/src/client/map.c +++ b/src/client/map.c @@ -2,8 +2,7 @@ #include "map.h" #include /* uint8_t */ -#include "misc.h" /* center_offset() */ -#include "windows.h" /* struct Win, get_win_by_id() */ +#include "windows.h" /* struct Win, center_offset(), get_win_by_id() */ #include "world.h" /* for global world */ diff --git a/src/client/misc.c b/src/client/misc.c deleted file mode 100644 index 329fe7a..0000000 --- a/src/client/misc.c +++ /dev/null @@ -1,44 +0,0 @@ -/* src/client/misc.c */ - -#include "misc.h" -#include /* size_t */ -#include /* uint8_t, uint32_t */ -#include /* free() */ -#include /* memcpy() */ -#include "../common/try_malloc.h" /* try_malloc() */ -#include "world.h" /* global world */ - - - -extern void nav_inventory(char dir) -{ - if ('u' == dir) - { - world.player_inventory_select = world.player_inventory_select - - (world.player_inventory_select > 0); - return; - } - uint8_t n_elems = 0; - uint8_t i; - for (i = 0; '\0' != world.player_inventory[i]; i++) - { - n_elems = n_elems + ('\n' == world.player_inventory[i]); - } - world.player_inventory_select = world.player_inventory_select - + (world.player_inventory_select < n_elems); -} - - - -extern void array_append(uint32_t old_n, size_t region_size, void * new_region, - void ** ptr_old_array) -{ - char * f_name = "array_append()"; - uint32_t old_size = old_n * region_size; - uint32_t new_size = old_size + region_size; - char * new_array = try_malloc(new_size, f_name); - memcpy(new_array, * ptr_old_array, old_size); - memcpy(new_array + (old_n * region_size), new_region, region_size); - free(* ptr_old_array); - * ptr_old_array = new_array; -} diff --git a/src/client/misc.h b/src/client/misc.h deleted file mode 100644 index 9733d39..0000000 --- a/src/client/misc.h +++ /dev/null @@ -1,26 +0,0 @@ -/* src/client/misc.h - * - * Miscellaneous routines that have not yet found a proper parent module. Having - * LOTS of stuff in here is a sure sign that better modularization is in order. - */ - -#ifndef MISC_H -#define MISC_H - -#include /* size_t */ -#include /* uint32_t */ - - - -/* Move world.inventory_sel up ("dir"="u") or down (else) as far as possible. */ -extern void nav_inventory(char dir); - -/* Append to array pointed to by "ptr_old_array" of "old_n" elements of - * "region_size" "new region". - */ -extern void array_append(uint32_t old_n, size_t region_size, void * new_region, - void ** ptr_old_array); - - - -#endif diff --git a/src/client/windows.c b/src/client/windows.c index 9b923fa..c08ada2 100644 --- a/src/client/windows.c +++ b/src/client/windows.c @@ -16,6 +16,7 @@ #include "../common/rexit.h" /* exit_trouble(), exit_err() */ #include "../common/try_malloc.h" /* try_malloc() */ #include "../common/yx_uint16.h" /* struct yx_uint16 */ +#include "array_append.h" /* array_append() */ #include "draw_wins.h" /* draw_winconf_geometry(), draw_winconf_keybindings(), * draw_win_inventory(), draw_win_info(), draw_win_log(), * draw_win_available_keybindings(), draw_win_map(), @@ -26,7 +27,6 @@ #include "keybindings.h" /* write_keybidings_to_file(), * read_keybindings_from_file() */ -#include "misc.h" /* array_append() */ #include "wincontrol.h" /* toggle_window() */ #include "world.h" /* global world */