--- libaitio/src/Attic/cli.c 2010/03/11 00:17:52 1.1.2.3 +++ libaitio/src/Attic/cli.c 2010/03/18 23:40:56 1.1.2.5 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: cli.c,v 1.1.2.3 2010/03/11 00:17:52 misho Exp $ +* $Id: cli.c,v 1.1.2.5 2010/03/18 23:40:56 misho Exp $ * *************************************************************************/ #include "global.h" @@ -38,12 +38,16 @@ int io_Cmd_Help(void *cmds, FILE *out, char ** __restr if (!args) { fprintf(out, "\n"); - for (i = 0; commands[i].cmd_name; i++) + fflush(out); + for (i = 0; commands[i].cmd_name; i++) { fprintf(out, "%s\t\t%s\n", commands[i].cmd_name, commands[i].cmd_doc); + fflush(out); + } } else { - if (!args[1]) + if (!args[1]) { fprintf(out, "Help screen::\n"); - else + fflush(out); + } else if (!strncmp(args[1], "---", 3)) return 0; @@ -53,6 +57,7 @@ int io_Cmd_Help(void *cmds, FILE *out, char ** __restr fprintf(out, "%s%s\t\t%s\n", args[1] ? "Syntax::\n\t" : "", commands[i].cmd_name, args[1] ? commands[i].cmd_help : commands[i].cmd_doc); + fflush(out); } } @@ -69,6 +74,7 @@ int io_Cmd_Help(void *cmds, FILE *out, char ** __restr int io_Cmd_Unsupported(void *cmds, FILE *out, char ** __restrict args) { fprintf(out, "Command %s not supported in this version ...\n", args[0]); + fflush(out); return 0; } @@ -90,7 +96,7 @@ char *io_Comp_Filename(const char *text, int 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 }, @@ -144,10 +150,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; } @@ -155,10 +162,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; } @@ -204,6 +213,7 @@ int ioCLIExec(ioCommands_t *cmdList, FILE *out, const } if (!cmd) { fprintf(out, "Command '%s' not found!\n", items[0]); + fflush(out); ret = -1; } else ret = cmd->cmd_func(cmdList, out, items);