home · contact · privacy
Got rid of misc.h. Split off remains into array_append.h and control.h.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 26 Mar 2014 04:35:13 +0000 (05:35 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 26 Mar 2014 04:35:13 +0000 (05:35 +0100)
12 files changed:
TODO
src/client/array_append.c [new file with mode: 0644]
src/client/array_append.h [new file with mode: 0644]
src/client/command_db.c
src/client/control.c
src/client/interface_conf.c
src/client/io.c
src/client/keybindings.c
src/client/map.c
src/client/misc.c [deleted file]
src/client/misc.h [deleted file]
src/client/windows.c

diff --git a/TODO b/TODO
index 971c47ad93295ba0682e5adbf4a48c4faa8dba58..825be244f0d58bf5a243e396d5540ae7084a14ea 100644 (file)
--- 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 (file)
index 0000000..f4391c7
--- /dev/null
@@ -0,0 +1,24 @@
+/* src/client/array_append.c */
+
+#include "array_append.h"
+#include <stddef.h> /* size_t */
+#include <stdint.h> /* uint32_t */
+#include <stdlib.h> /* free() */
+#include <string.h> /* 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 (file)
index 0000000..b7cc7ef
--- /dev/null
@@ -0,0 +1,23 @@
+/* src/client/array_append.h
+ *
+ * Small memory management helper.
+ */
+
+#ifndef ARRAY_APPEND_H
+#define ARRAY_APPEND_H
+
+#include <stddef.h> /* size_t */
+#include <stdint.h> /* 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
+
index 3837d2ab888bb6c8fdb0f86aad4f2964a9b9acb7..06329fc28b63934e18741845003366ec6ae6f1ee 100644 (file)
@@ -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() */
 
index ed44d120c63c24aa63768cd5cd727ccd6e03ed94..1961334c0015064f103b825f64aaf89651652000 100644 (file)
@@ -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))
index a67cb55b1805936970228cdd1cfe65e0a9fcf839..57dff9a50f06a6b823e1b0583dad088468d0e722 100644 (file)
@@ -1,6 +1,6 @@
 /* src/client/interface_conf.c */
 
-#include "misc.h"
+#include "interface_conf.h"
 #include <ncurses.h> /* delwin() */
 #include <stdint.h> /* uint8_t, uint32_t */
 #include <stdio.h> /* FILE, sprintf() */
index 19dbb39478bdc7ee51129862c69c78e678c1fe4c..477700f9df096e522781a450bce93b3a59bf7b39 100644 (file)
@@ -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 */
 
index 29e6c05c8150b349cb8a5a9246969a33585c4e96..10cbffba43f48d261f389ca8a3f02d9a27a11b85 100644 (file)
@@ -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 */
 
index 5e4e9c6f769d7cc640a2fbd450ae2414a6bae9bd..7292c89151a8ecb62a0a0b6c7c3d53e7f67c4e79 100644 (file)
@@ -2,8 +2,7 @@
 
 #include "map.h"
 #include <stdint.h> /* 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 (file)
index 329fe7a..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/* src/client/misc.c */
-
-#include "misc.h"
-#include <stddef.h> /* size_t */
-#include <stdint.h> /* uint8_t, uint32_t */
-#include <stdlib.h> /* free() */
-#include <string.h> /* 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 (file)
index 9733d39..0000000
+++ /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 <stddef.h> /* size_t */
-#include <stdint.h> /* 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
index 9b923fad24ef1ebe6ac94b38b9b5ff7676209f70..c08ada265a56d596a174decd5bb71250e6843839 100644 (file)
@@ -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 */