home · contact · privacy
Removed indirection in control.c and therefore unused is_command_id_shortdsc().
[plomrogue] / src / client / control.c
index 1ccaf453a5bd9ab8d19300e7840b4dd296b0ce12..bdbdfec409a62bf7757d35c65d849c7f5dc01be9 100644 (file)
@@ -3,11 +3,11 @@
 #include "control.h"
 #include <stdint.h> /* uint8_t, uint16_t */
 #include <stdio.h> /* sprintf() */
-#include <string.h> /* strlen() */
-#include "command_db.h" /* get_command_id(), is_command_id_shortdsc() */
+#include <string.h> /* strlen(), strcmp() */
+#include "command_db.h" /* get_command_id() */
 #include "io.h" /* try_send() */
-#include "keybindings.h" /* struct KeyBindingDB, get_actionname_to_keycode(),
-                         * get_keycode_to_action(), mod_selected_keyb(),
+#include "keybindings.h" /* struct KeyBindingDB, get_command_to_keycode(),
+                          * get_keycode_to_command(), mod_selected_keyb(),
                           * move_keyb_mod_selection()
                           */
 #include "map_window.h" /* for map_scroll(), map_center() */
 
 
 
-/* If "cmd" matches "match" in get_available_keycode_to_action(), execute "f"
- * with provided char arguments and return 1; else only return 0.
+/* If "keycode" matches "match" in get_available_keycode_to_command(), execute
+ * "f" with provided char arguments and return 1; else only return 0.
  */
-static uint8_t try_cmd_0args(int cmd, char * match, void (* f) ());
-static uint8_t try_cmd_1args(int cmd, char * match, void (* f) (char), char c);
-static uint8_t try_cmd_2args(int cmd, char * match,
+static uint8_t try_cmd_0args(int keycode, char * match, void (* f) ());
+static uint8_t try_cmd_1args(int keycode, char * match,
+                             void (* f) (char), char c);
+static uint8_t try_cmd_2args(int keycode, char * match,
                              void (* f) (char, char), char c1, char c2);
 
-/* If "action" is id of command named "match", send (via try_send()) a string
- * of "match" + " " + the string representation of "arg" to the server.
+/* If "command" matches "match", send (via try_send()) a string of
+ * "command_message" + " " + the string representation of "arg" to the server.
  */
-static uint8_t try_player_cmd(int action, char * match, char * command,
-                              uint8_t arg);
+static uint8_t try_player_cmd(char * command, char * match,
+                              char * command_message, uint8_t arg);
 
-/* Return keycode to action of "name" if available in current window config. */
-static uint16_t get_available_keycode_to_action(char * name);
+/* Return keycode to "command" if it is available in current window config. */
+static uint16_t get_available_keycode_to_command(char * command);
 
 /* Return pointer to global keybindings or to keybindings for wingeometry config
  * (c = "g") or winkeys config (c = "k") or active window's keybindings ("w").
@@ -51,9 +52,9 @@ static void wrap_mv_kb_mod(char c1, char c2);
 
 
 
-static uint8_t try_cmd_0args(int cmd, char * match, void (* f) ())
+static uint8_t try_cmd_0args(int keycode, char * match, void (* f) ())
 {
-    if (cmd == get_available_keycode_to_action(match))
+    if (keycode == get_available_keycode_to_command(match))
     {
         f();
         return 1;
@@ -63,9 +64,10 @@ static uint8_t try_cmd_0args(int cmd, char * match, void (* f) ())
 
 
 
-static uint8_t try_cmd_1args(int cmd, char * match, void (* f) (char), char c)
+static uint8_t try_cmd_1args(int keycode, char * match,
+                             void (* f) (char), char c)
 {
-    if (cmd == get_available_keycode_to_action(match))
+    if (keycode == get_available_keycode_to_command(match))
     {
         f(c);
         return 1;
@@ -75,10 +77,10 @@ static uint8_t try_cmd_1args(int cmd, char * match, void (* f) (char), char c)
 
 
 
-static uint8_t try_cmd_2args(int cmd, char * match,
+static uint8_t try_cmd_2args(int keycode, char * match,
                              void (* f) (char, char), char c1, char c2)
 {
-    if (cmd == get_available_keycode_to_action(match))
+    if (keycode == get_available_keycode_to_command(match))
     {
         f(c1, c2);
         return 1;
@@ -88,15 +90,15 @@ static uint8_t try_cmd_2args(int cmd, char * match,
 
 
 
-static uint8_t try_player_cmd(int action, char * match, char * command,
-                              uint8_t arg)
+static uint8_t try_player_cmd(char * command, char * match,
+                              char * command_message, uint8_t arg)
 {
-    if (is_command_id_shortdsc(action, match))
+    if (!strcmp(command, match))
     {
-        uint8_t command_size = strlen(command);
+        uint8_t command_size = strlen(command_message);
         uint8_t arg_size = 3;
         char msg[command_size + 1 + arg_size + 1];
-        sprintf(msg, "%s %d", command, arg);
+        sprintf(msg, "%s %d", command_message, arg);
         try_send(msg);
         return 1;
     }
@@ -105,25 +107,25 @@ static uint8_t try_player_cmd(int action, char * match, char * command,
 
 
 
-static uint16_t get_available_keycode_to_action(char * name)
+static uint16_t get_available_keycode_to_command(char * command)
 {
-    uint16_t keycode = get_keycode_to_action(world.kb_global.kbs, name);
+    uint16_t keycode = get_keycode_to_command(world.kb_global.kbs, command);
     if (0 != keycode || 0 == world.wmeta.active)
     {
         return keycode;
     }
     struct WinConf * wc = get_winconf_by_win(world.wmeta.active);
-    if (0 == wc->view)
+    if      (0 == wc->view)
     {
-        keycode = get_keycode_to_action(wc->kb.kbs, name);
+        keycode = get_keycode_to_command(wc->kb.kbs, command);
     }
     else if (1 == wc->view)
     {
-        keycode = get_keycode_to_action(world.kb_wingeom.kbs, name);
+        keycode = get_keycode_to_command(world.kb_wingeom.kbs, command);
     }
     else if (2 == wc->view)
     {
-        keycode = get_keycode_to_action(world.kb_winkeys.kbs, name);
+        keycode = get_keycode_to_command(world.kb_winkeys.kbs, command);
     }
     return keycode;
 }
@@ -168,26 +170,23 @@ static void wrap_mv_kb_mod(char c1, char c2)
 
 extern uint8_t player_control(int key)
 {
-    char * action_name = get_actionname_to_keycode(world.kb_global.kbs, key);
-    if (NULL == action_name && 0 != world.wmeta.active)
+    char * cmd = get_command_to_keycode(world.kb_global.kbs, key);
+    if (NULL == cmd && 0 != world.wmeta.active)
     {
         struct WinConf * wc = get_winconf_by_win(world.wmeta.active);
-        action_name = get_actionname_to_keycode(wc->kb.kbs, key);
+        cmd = get_command_to_keycode(wc->kb.kbs, key);
     }
-    if (NULL != action_name)
+    if (NULL != cmd
+        && (   try_player_cmd(cmd, "wait", "wait", 0)
+            || try_player_cmd(cmd, "drop", "drop",world.player_inventory_select)
+            || try_player_cmd(cmd, "pick", "pick_up", 0)
+            || try_player_cmd(cmd, "use", "use", world.player_inventory_select)
+            || try_player_cmd(cmd, "player_u", "move", 'N')
+            || try_player_cmd(cmd, "player_d", "move", 'S')
+            || try_player_cmd(cmd, "player_r", "move", 'E')
+            || try_player_cmd(cmd, "player_l", "move", 'W')))
     {
-        uint8_t id = get_command_id(action_name);
-        if (   try_player_cmd(id, "wait", "wait", 0)
-            || try_player_cmd(id, "drop", "drop", world.player_inventory_select)
-            || try_player_cmd(id, "pick", "pick_up", 0)
-            || try_player_cmd(id, "use", "use", world.player_inventory_select)
-            || try_player_cmd(id, "player_u", "move", 'N')
-            || try_player_cmd(id, "player_d", "move", 'S')
-            || try_player_cmd(id, "player_r", "move", 'E')
-            || try_player_cmd(id, "player_l", "move", 'W'))
-        {
-            return 1;
-        }
+        return 1;
     }
     return 0;
 }
@@ -227,7 +226,7 @@ extern uint8_t winkeyb_control(int key)
 
 extern uint8_t meta_control(int key)
 {
-    uint8_t ret = 2 * (key == get_available_keycode_to_action("quit"));
+    uint8_t ret = 2 * (key == get_available_keycode_to_command("quit"));
     if (   (0 == ret)
         && (   try_cmd_0args(key, "winconf", toggle_winconfig)
             || try_cmd_0args(key, "reload_conf", reload_interface_conf)