home · contact · privacy
Removed indirection in control.c and therefore unused is_command_id_shortdsc().
authorChristian Heller <c.heller@plomlompom.de>
Tue, 21 Jan 2014 23:47:18 +0000 (00:47 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 21 Jan 2014 23:47:18 +0000 (00:47 +0100)
src/client/command_db.c
src/client/command_db.h
src/client/control.c
src/client/keybindings.h

index 4835392318ae2e161b54344fdaa6a32ecd64cb00..846f87ff579483e55ff355d6fb78213f0c57b644 100644 (file)
@@ -29,25 +29,6 @@ static void copy_tokenized_string(char ** ch_ptr, char * delim)
 
 
 
-extern uint8_t is_command_id_shortdsc(uint8_t id, char * shortdsc)
-{
-    struct Command * cmd_ptr = world.cmd_db.cmds;
-    while (1)
-    {
-        if (id == cmd_ptr->id)
-        {
-            if (strcmp(shortdsc, cmd_ptr->dsc_short))
-            {
-                return 0;
-            }
-            return 1;
-        }
-        cmd_ptr = &cmd_ptr[1];
-    }
-}
-
-
-
 extern uint8_t get_command_id(char * dsc_short)
 {
     struct Command * cmd_ptr = world.cmd_db.cmds;
index 769670baecacb39eae3e14357f288602849f35c4..0d4ffbae8e3653a5748b4de3b07bd257ca41215d 100644 (file)
@@ -26,9 +26,6 @@ struct CommandDB
 
 
 
-/* Is "id" the ID of command whose dsc_short is "shortdsc"? Answer in binary. */
-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(char * dsc_short);
 
index 64486e30eb9a808ad1fa951309a1c8edb3b1c938..bdbdfec409a62bf7757d35c65d849c7f5dc01be9 100644 (file)
@@ -3,8 +3,8 @@
 #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_command_to_keycode(),
                           * get_keycode_to_command(), mod_selected_keyb(),
@@ -32,11 +32,11 @@ static uint8_t try_cmd_1args(int keycode, char * match,
 static uint8_t try_cmd_2args(int keycode, char * match,
                              void (* f) (char, char), char c1, char c2);
 
-/* If "command_id" 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 command_id, char * match, char * command_name,
-                              uint8_t arg);
+static uint8_t try_player_cmd(char * command, char * match,
+                              char * command_message, uint8_t arg);
 
 /* Return keycode to "command" if it is available in current window config. */
 static uint16_t get_available_keycode_to_command(char * command);
@@ -90,15 +90,15 @@ static uint8_t try_cmd_2args(int keycode, char * match,
 
 
 
-static uint8_t try_player_cmd(int command_id, char * match, char * command_name,
-                              uint8_t arg)
+static uint8_t try_player_cmd(char * command, char * match,
+                              char * command_message, uint8_t arg)
 {
-    if (is_command_id_shortdsc(command_id, match))
+    if (!strcmp(command, match))
     {
-        uint8_t command_size = strlen(command_name);
+        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_name, arg);
+        sprintf(msg, "%s %d", command_message, arg);
         try_send(msg);
         return 1;
     }
@@ -115,7 +115,7 @@ static uint16_t get_available_keycode_to_command(char * command)
         return keycode;
     }
     struct WinConf * wc = get_winconf_by_win(world.wmeta.active);
-    if (0 == wc->view)
+    if      (0 == wc->view)
     {
         keycode = get_keycode_to_command(wc->kb.kbs, command);
     }
@@ -170,26 +170,23 @@ static void wrap_mv_kb_mod(char c1, char c2)
 
 extern uint8_t player_control(int key)
 {
-    char * command = get_command_to_keycode(world.kb_global.kbs, key);
-    if (NULL == command && 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);
-        command = get_command_to_keycode(wc->kb.kbs, key);
+        cmd = get_command_to_keycode(wc->kb.kbs, key);
     }
-    if (NULL != command)
+    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(command);
-        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;
 }
index e2031f3ea4515e7685576460cd1c3e02b381ac05..ea09d6582e5e2ab41a7d1fdedd37928d1c167277 100644 (file)
@@ -13,7 +13,7 @@
 struct KeyBinding
 {
   struct KeyBinding * next;
-  uint16_t key;    /* keycode */
+  uint16_t key;   /* keycode */
   char * command; /* name of command / functionality bound to keycode */
 };