--- cli-script.c.orig 2010-05-17 22:28:12.000000000 +0300 +++ cli-script.c 2011-03-09 11:37:04.917093842 +0200 @@ -1416,8 +1350,9 @@ CMD_POST_HOOK }; struct command_line *cmds; - struct cmd_list_element *c, *newc, *hookc = 0, **list; - char *tem, *comfull; + struct cmd_list_element *c, *newc, *hookc = 0, **list; + char *tem, *tem2, *comfull; + char tembuf[MAX_TMPBUF]; char tmpbuf[MAX_TMPBUF]; int hook_type = CMD_NO_HOOK; int hook_name_size = 0; --- cli-script.c.orig 2010-05-17 22:28:12.000000000 +0300 +++ cli-script.c 2011-03-09 11:37:04.917093842 +0200 @@ -1430,8 +1365,11 @@ comfull = comname; list = validate_comname (&comname); + strncpy(tembuf, comname, MAX_TMPBUF); + tembuf[MAX_TMPBUF-1] = 0; + /* Look it up, and verify that we got an exact match. */ - tem = comname; + tem = tembuf; c = lookup_cmd (&tem, *list, "", -1, 1); if (c && strcmp (comname, c->name) != 0) c = 0; --- cli-script.c.orig 2010-05-17 22:28:12.000000000 +0300 +++ cli-script.c 2011-03-09 11:37:04.917093842 +0200 @@ -1465,11 +1402,26 @@ if (hook_type != CMD_NO_HOOK) { + /* Convert _ characters into spaces, to allow hooking prefix commands */ + tem = tembuf + hook_name_size; + tem2 = strchr(tem, '_'); + while (tem2) + { + *tem2 = ' '; + tem2 = strchr(tem2+1, '_'); + } + /* Look up cmd it hooks, and verify that we got an exact match. */ - tem = comname + hook_name_size; hookc = lookup_cmd (&tem, *list, "", -1, 0); - if (hookc && strcmp (comname + hook_name_size, hookc->name) != 0) + while (hookc && *tem) + { + /* tem might point to the argument of a prefix command */ + if (hookc->prefixlist) + hookc = lookup_cmd (&tem, *hookc->prefixlist, "", -1, 0); + else hookc = 0; + } + if (!hookc) { warning (_("Your new `%s' command does not hook any existing command."),