+static uint8_t set_string_if_char_match(char c, char c_to_match,
+ char ** string, char * string_to_set)
+{
+ if (c == c_to_match)
+ {
+ *string = string_to_set;
+ return 1;
+ }
+ return 0;
+}
+
+
+
+static char * build_server_message_with_argument(struct Command * cmd)
+{
+ char * f_name = "build_server_message_with_argument()";
+ uint8_t command_size = strlen(cmd->server_msg);
+ char * arg_str;
+ uint8_t arg_size;
+ if ('i' == cmd->arg)
+ {
+ arg_size = 3;
+ arg_str = try_malloc(arg_size + 1, f_name);
+ int test = sprintf(arg_str, "%d",world.player_inventory_select);
+ exit_trouble(test < 0, f_name, "sprintf()");
+ }
+ else if ( set_string_if_char_match(cmd->arg, 'd', &arg_str, "east")
+ || set_string_if_char_match(cmd->arg, 'c', &arg_str, "south-east")
+ || set_string_if_char_match(cmd->arg, 'x', &arg_str, "south-west")
+ || set_string_if_char_match(cmd->arg, 's', &arg_str, "west")
+ || set_string_if_char_match(cmd->arg, 'w', &arg_str, "north-west")
+ || set_string_if_char_match(cmd->arg, 'e', &arg_str, "north-east"))
+ {
+ arg_size = strlen(arg_str);
+ }
+ else
+ {
+ exit_err(1, "Illegal server command argument.");
+ }
+ char * msg = try_malloc(command_size + 1 + arg_size + 1, f_name);
+ int test = sprintf(msg, "%s %s", cmd->server_msg, arg_str);
+ exit_trouble(test < 0, f_name, "sprintf()");
+ if ('i' == cmd->arg)
+ {
+ free(arg_str);
+ }
+ return msg;
+}
+
+
+