home · contact · privacy
Corrected off-by-one error in windows.c:refit_pad() that lead to failure of subpad...
[plomrogue] / src / command_db.c
index cbf6959e87322ff24a9a2d7e392160482450332f..25fcd24e90076da9ca8c5c75689c7b487525a6f3 100644 (file)
@@ -25,6 +25,41 @@ static void copy_tokenized_string(struct World * world,
 
 
 
+extern uint8_t is_command_id_shortdsc(struct World * world,
+                                      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(struct World * world, char * dsc_short)
+{
+    struct Command * cmd_ptr = world->cmd_db->cmds;
+    while (1)
+    {
+        if (0 == strcmp(dsc_short, cmd_ptr->dsc_short))
+        {
+            return cmd_ptr->id;
+        }
+        cmd_ptr = &cmd_ptr[1];
+    }
+}
+
+
+
 extern char * get_command_longdsc(struct World * world, char * dsc_short)
 {
     struct Command * cmd_ptr = world->cmd_db->cmds;
@@ -46,7 +81,8 @@ extern void init_command_db(struct World * world)
     FILE * file = fopen("config/commands", "r");
     exit_err(NULL == file, world, err);
     uint16_t lines, linemax;
-    textfile_sizes(file, &linemax, &lines);
+    err = "Trouble in init_cmds() with textfile_sizes().";
+    exit_err(textfile_sizes(file, &linemax, &lines), world, err);
     err = "Trouble in init_cmds() with malloc().";
     char * line = malloc(linemax);
     exit_err(NULL == line, world, err);
@@ -60,6 +96,7 @@ extern void init_command_db(struct World * world)
         copy_tokenized_string(world, &cmds[i].dsc_long, "\n", err);
         i++;
     }
+    free(line);
     world->cmd_db = malloc(sizeof(struct CommandDB));
     world->cmd_db->cmds = cmds;
     world->cmd_db->n = lines;