From d0b137d5a5c2b7032ad5be64a875998e0ff045be Mon Sep 17 00:00:00 2001 From: boercher Date: Sun, 17 Jul 2005 16:14:22 +0000 Subject: [PATCH] - new option -prev, corrections for option -next - clients gets more information if an error occurs - use sock_printf() and sock_printf_error() if necessary --- server/commands/menu_commands.c | 248 ++++++++++++++++---------------- 1 file changed, 123 insertions(+), 125 deletions(-) diff --git a/server/commands/menu_commands.c b/server/commands/menu_commands.c index 7c3314a..126029d 100644 --- a/server/commands/menu_commands.c +++ b/server/commands/menu_commands.c @@ -41,9 +41,27 @@ /* Local functions */ MenuEventFunc(menu_commands_handler); -int set_parent(Menu *menu, char *parentid, Client *client); +int set_predecessor(MenuItem *item, char *itemid, Client *client); int set_successor(MenuItem *item, char *itemid, Client *client); -MenuItem * search_item(char *menu_id); + + +/** small utility for debug output of command line. */ +static char *argv2string(int argc, char **argv) +{ + char *rtn = NULL; + int len; + int i; + for (i = len = 0; i < argc; ++i) + len += strlen(argv[i]) + 1; + rtn = malloc(len + 1); + rtn[0] = '\0'; + for (i = len = 0; i < argc; ++i) + { + strcat(rtn, argv[i]); + strcat(rtn, " "); + } + return rtn; +} /************************************************************************* @@ -85,12 +103,12 @@ menu_add_item_func (Client * c, int argc, char **argv) return 1; if (!c->name) { - sock_send_string (c->sock, "huh? You need to give your client a name first\n"); + sock_send_error(c->sock, "You need to give your client a name first\n"); return 0; } if ((argc < 4 )) { - sock_send_string (c->sock, "huh? Usage: menu_add_item []\n"); + sock_send_error(c->sock, "Usage: menu_add_item []\n"); return 0; } @@ -113,20 +131,20 @@ menu_add_item_func (Client * c, int argc, char **argv) menu = menu_find_item (c->menu, menu_id, true); } if (!menu) { - sock_send_string (c->sock, "huh? Cannot find menu id\n"); + sock_send_error(c->sock, "Cannot find menu id\n"); return 0; } item = menu_find_item (c->menu, item_id, true); if (item) { - sock_send_string (c->sock, "huh? Item id already in use\n"); + sock_send_error(c->sock, "Item id already in use\n"); return 0; } /* Find menuitem type */ itemtype = menuitem_typename_to_type (argv[3]); if (itemtype == -1) { - sock_send_string (c->sock, "huh? Invalid menuitem type\n"); + sock_send_error(c->sock, "Invalid menuitem type\n"); return 0; } @@ -225,7 +243,7 @@ menu_del_item_func (Client * c, int argc, char **argv) return 1; if ((argc < 3 )) { - sock_send_string (c->sock, "huh? Usage: menu_del_item \n"); + sock_send_error(c->sock, "Usage: menu_del_item \n"); return 0; } @@ -234,7 +252,7 @@ menu_del_item_func (Client * c, int argc, char **argv) /* Does the client have a menu already ? */ if (!c->menu) { - sock_send_string (c->sock, "huh? Client has no menu\n"); + sock_send_error(c->sock, "Client has no menu\n"); return 0; } @@ -246,13 +264,13 @@ menu_del_item_func (Client * c, int argc, char **argv) menu = menu_find_item (c->menu, menu_id, true); } if (!menu) { - sock_send_string (c->sock, "huh? Cannot find menu id\n"); + sock_send_error(c->sock, "Cannot find menu id\n"); return 0; } item = menu_find_item (c->menu, item_id, true); if (!item) { - sock_send_string (c->sock, "huh? Cannot find item\n"); + sock_send_error(c->sock, "Cannot find item\n"); return 0; } menuscreen_inform_item_destruction (item); @@ -287,10 +305,12 @@ menu_del_item_func (Client * c, int argc, char **argv) * Sets the visible text. * -is_hidden false|true (false) * If the item currently should not appear in a menu. + * -prev id () + * Sets the predecessor of this item (what happens after "Escape") * - * menu: - * -parent id () - * Sets the parent of this item. + * For all except menus: + * -next id () + * Sets the successor of this item (what happens after "Enter") * * action: * -menu_result none|close|quit (none) @@ -383,7 +403,7 @@ menu_set_item_func (Client * c, int argc, char **argv) } option_table[] = { { -1, "text", STRING, offsetof(MenuItem,text) }, { -1, "is_hidden", BOOLEAN, offsetof(MenuItem,is_hidden) }, - { MENUITEM_MENU, "parent", STRING, -1 }, + { -1, "prev", STRING, -1 }, { -1, "next", STRING, -1 }, { MENUITEM_ACTION, "menu_result", STRING, -1 }, { MENUITEM_CHECKBOX, "value", CHECKBOX_VALUE, offsetof(MenuItem,data.checkbox.value) }, @@ -413,8 +433,8 @@ menu_set_item_func (Client * c, int argc, char **argv) { -1, NULL, -1, -1 } }; - debug (RPT_DEBUG, "%s( Client [%d], %s, %s )", - __FUNCTION__, c->sock, argv[1], argv[2]); + debug (RPT_DEBUG, "%s( Client [%d]: %s)", + __FUNCTION__, c->sock, argv2string(argc, argv)); bool bool_value = false; CheckboxValue checkbox_value = CHECKBOX_OFF; short short_value = 0; @@ -427,13 +447,12 @@ menu_set_item_func (Client * c, int argc, char **argv) char * menu_id; char * item_id; int argnr; - char buf[80]; if (!c->ack) return 1; if ((argc < 4 )) { - sock_send_string (c->sock, "huh? Usage: menu_set_item {