From 4e72a992b4cd5d17b20f8fc6e56f1c0ccffdf88e Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Sun, 27 Sep 2009 12:45:28 +0000 Subject: [PATCH] Fix argument-handling for the /hostname (/irchost) command - now you can do /hostname 2 instead of /hostname #2. git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@75 13b04d17-f746-0410-82c6-800466cd88b0 --- source/commands.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/source/commands.c b/source/commands.c index 1b5b896..120ebc2 100644 --- a/source/commands.c +++ b/source/commands.c @@ -2948,21 +2948,31 @@ BUILT_IN_COMMAND(e_hostname) { int norev = 0; char *newhost = NULL; + char *arg = next_arg(args, &args); - if (args && !strcasecmp(args, "-norev")) + if (arg && !strcasecmp(arg, "-norev")) { norev = 1; - next_arg(args, &args); + arg = next_arg(args, &args); } - if (args && *args && *args != '#') + if (arg && *arg && *arg != '#' && !is_number(arg)) { - malloc_strcpy(&newhost, args); + malloc_strcpy(&newhost, arg); } else { Virtuals *virtuals, *new; int i; + int switch_to = 0; + + if (arg) + { + if (*arg == '#') + arg++; + + switch_to = my_atol(arg); + } get_local_addrs(&virtuals, norev); @@ -2974,14 +2984,11 @@ BUILT_IN_COMMAND(e_hostname) put_it("%s", convert_output_format("$G Current hostnames available", NULL, NULL)); put_it("%s", convert_output_format("%K[%W$[3]0%K] %B$1", "%d %s", i, new->hostname)); - if (args && *args) - { - if (*args == '#') args++; - if (args && *args && (i == my_atol(args))) - malloc_strcpy(&newhost, new->hostname); - } + if (i == switch_to) + newhost = new->hostname; + else + new_free(&new->hostname); new_free(&new->address); - new_free(&new->hostname); new_free(&new); } }