--- libaitio/src/Attic/cli.c 2010/03/09 13:47:02 1.1.2.2 +++ libaitio/src/Attic/cli.c 2010/03/11 13:29:56 1.1.2.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.1.2.2 2010/03/09 13:47:02 misho Exp $ +* $Id: cli.c,v 1.1.2.4 2010/03/11 13:29:56 misho Exp $ * *************************************************************************/ #include "global.h" @@ -74,10 +74,23 @@ int io_Cmd_Unsupported(void *cmds, FILE *out, char ** // ------------------------------------------------------------ +/* + * io_Comp_Filename() Builtin helper function for filename completion arguments + * @text = Text line + * @state = Position state + * return: NULL not found filename, != NULL filename +*/ +char *io_Comp_Filename(const char *text, int state) +{ + return rl_filename_completion_function(text, state); +} + +// ------------------------------------------------------------ + #pragma GCC visibility push(hidden) ioCommands_t io_stdCmds[] = { - { "test", io_Cmd_Unsupported, "Test - Don`t use default command structure!", "test ", NULL }, + { "test", io_Cmd_Unsupported, "Test - Don`t use default command structure!", "test ", io_Comp_Filename }, { "-------", NULL, "---------------------", NULL, NULL }, { "help", io_Cmd_Help, "Help screen", "help [command] ", NULL }, { "exit", io_Cmd_Exit, "Exit from console", "exit ", NULL }, @@ -131,10 +144,11 @@ int ioCLIExec(ioCommands_t *cmdList, FILE *out, const { int len = strlen(text); - for (i = state; cmdList[i].cmd_name; i++) + for (i = state; cmdList[i].cmd_name; i++) { if (strncmp(cmdList[i].cmd_name, "---", 3) && !strncmp(cmdList[i].cmd_name, text, len)) return strdup(cmdList[i].cmd_name); + } return NULL; } @@ -142,10 +156,12 @@ int ioCLIExec(ioCommands_t *cmdList, FILE *out, const if (!start) matches = rl_completion_matches(text, cmdCompGet); else - for (i = 0; cmdList[i].cmd_name; i++) - if (cmdList[i].cmd_comp && !strncmp(rl_line_buffer, - cmdList[i].cmd_name, strlen(cmdList[i].cmd_name))) + for (i = 0; cmdList[i].cmd_name; i++) { + if (!cmdList[i].cmd_comp) + continue; + if (!strncmp(rl_line_buffer, cmdList[i].cmd_name, strlen(cmdList[i].cmd_name))) matches = rl_completion_matches(text, cmdList[i].cmd_comp); + } return matches; }