From 9e631a7513ed34c27a36cacd0b22cfb2fd695dad Mon Sep 17 00:00:00 2001 From: crunchy Date: Sat, 12 Oct 2002 20:06:21 +0000 Subject: add alias support for commands and extended argument completion --- mpiosh/readline.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'mpiosh/readline.c') diff --git a/mpiosh/readline.c b/mpiosh/readline.c index 0b8731d..5427b9f 100644 --- a/mpiosh/readline.c +++ b/mpiosh/readline.c @@ -2,7 +2,7 @@ * * Author: Andreas Büsching * - * $Id: readline.c,v 1.1 2002/10/12 18:31:45 crunchy Exp $ + * $Id: readline.c,v 1.2 2002/10/12 20:06:22 crunchy Exp $ * * Copyright (C) 2001 Andreas Büsching * @@ -41,7 +41,9 @@ mpiosh_readline_init(void) char * mpiosh_readline_comp_cmd(const char *text, int state) { - static mpiosh_cmd_t *cmd = NULL; + static mpiosh_cmd_t * cmd = NULL; + static char ** alias = NULL; + char *cmd_text = NULL; if (state == 0) { @@ -49,12 +51,30 @@ mpiosh_readline_comp_cmd(const char *text, int state) } while (cmd->cmd) { - if ((*text == '\0') || (strstr(cmd->cmd, text) == cmd->cmd)) { - cmd_text = strdup(cmd->cmd); - cmd++; - break; + if (!alias) { + if ((*text == '\0') || (strstr(cmd->cmd, text) == cmd->cmd)) { + cmd_text = strdup(cmd->cmd); + if (cmd->aliases) alias = cmd->aliases; + else cmd++; + break; + } + if (cmd->aliases) alias = cmd->aliases; + else cmd++; + } else { + int break_it = 0; + + while (*alias) { + if (strstr(*alias, text) == *alias) { + cmd_text = strdup(*alias); + alias++; + break_it = 1; + break; + } + alias++; + } + if (break_it) break; + if (*alias == NULL) cmd++, alias = NULL; } - cmd++; } return cmd_text; -- cgit v1.2.3