|
version 1.1.2.1, 2010/03/09 12:44:40
|
version 1.1.2.3, 2010/03/11 00:17:52
|
|
Line 9
|
Line 9
|
| #include "global.h" |
#include "global.h" |
| |
|
| |
|
| static int cmd_exit(void *cmds, FILE *out, char ** __restrict args) | /* |
| | * io_Cmd_Exit() Builtin helper function for Exit from Cli |
| | * @cmds = Commands list |
| | * @out = Output handle |
| | * @args = Parsed arguments array |
| | * return: 1 exit from Cli! |
| | */ |
| | int io_Cmd_Exit(void *cmds, FILE *out, char ** __restrict args) |
| { |
{ |
| return 1; |
return 1; |
| } |
} |
| |
|
| static int cmd_help(void *cmds, FILE *out, char ** __restrict args) | /* |
| | * io_Cmd_Help() Builtin helper function for Help screen |
| | * @cmds = Commands list |
| | * @out = Output handle |
| | * @args = Parsed arguments array |
| | * return: -1 error, 0 = ok |
| | */ |
| | int io_Cmd_Help(void *cmds, FILE *out, char ** __restrict args) |
| { |
{ |
| register int i; |
register int i; |
| ioCommands_t *commands = cmds; |
ioCommands_t *commands = cmds; |
|
Line 45 static int cmd_help(void *cmds, FILE *out, char ** __r
|
Line 59 static int cmd_help(void *cmds, FILE *out, char ** __r
|
| return 0; |
return 0; |
| } |
} |
| |
|
| static int cmd_unsupported(void *cmds, FILE *out, char ** __restrict args) | /* |
| | * io_Cmd_Unsupported() Builtin helper function for unsupported commands |
| | * @cmds = Commands list |
| | * @out = Output handle |
| | * @args = Parsed arguments array |
| | * return: -1 error, 0 = ok, 1 exit from Cli! |
| | */ |
| | int io_Cmd_Unsupported(void *cmds, FILE *out, char ** __restrict args) |
| { |
{ |
| fprintf(out, "Command %s not supported in this version ...\n", args[0]); |
fprintf(out, "Command %s not supported in this version ...\n", args[0]); |
| return 0; |
return 0; |
|
Line 53 static int cmd_unsupported(void *cmds, FILE *out, char
|
Line 74 static int 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) |
#pragma GCC visibility push(hidden) |
| |
|
| ioCommands_t io_stdCmds[] = { |
ioCommands_t io_stdCmds[] = { |
| { "test", cmd_unsupported, "Test - Don`t use default command structure!", "test <cr>", NULL }, | { "test", io_Cmd_Unsupported, "Test - Don`t use default command structure!", "test <cr>", NULL }, |
| { "-------", NULL, "---------------------", NULL, NULL }, |
{ "-------", NULL, "---------------------", NULL, NULL }, |
| { "help", cmd_help, "Help screen", "help [command] <cr>", NULL }, | { "help", io_Cmd_Help, "Help screen", "help [command] <cr>", NULL }, |
| { "exit", cmd_exit, "Exit from console", "exit <cr>", NULL }, | { "exit", io_Cmd_Exit, "Exit from console", "exit <cr>", NULL }, |
| { NULL, NULL, NULL, NULL } |
{ NULL, NULL, NULL, NULL } |
| }; |
}; |
| |
|
|
Line 68 ioCommands_t io_stdCmds[] = {
|
Line 102 ioCommands_t io_stdCmds[] = {
|
| // ------------------------------------------------------------ |
// ------------------------------------------------------------ |
| |
|
| /* |
/* |
| * ioCLIInit() Initialize CLI features | * ioCLIComp() Initialize completion CLI features |
| * @cmdList = Commands list | |
| * @out = Output handle | |
| * @cmdComplete = Completion function |
* @cmdComplete = Completion function |
| * @cmdEntry = Compentry function |
* @cmdEntry = Compentry function |
| * return: none |
* return: none |
| */ |
*/ |
| void ioCLIInit(ioCommands_t *cmdList, FILE *out, io_Completion_t *cmdComplete, io_CompEntry_t *cmdEntry) | inline void ioCLIComp(io_Completion_t *cmdComplete, io_CompEntry_t *cmdEntry) |
| { |
{ |
| ioCommands_t *cmds = cmdList ? cmdList : io_stdCmds; |
|
| |
|
| inline int inline_help() |
|
| { |
|
| cmd_help(cmds, out, NULL); |
|
| rl_on_new_line(); |
|
| return 0; |
|
| } |
|
| |
|
| rl_bind_key('?', inline_help); |
|
| // command completon |
// command completon |
| rl_attempted_completion_function = cmdComplete; |
rl_attempted_completion_function = cmdComplete; |
| rl_completion_entry_function = cmdEntry; |
rl_completion_entry_function = cmdEntry; |
|
Line 106 int ioCLIExec(ioCommands_t *cmdList, FILE *out, const
|
Line 128 int ioCLIExec(ioCommands_t *cmdList, FILE *out, const
|
| register int i; |
register int i; |
| ioCommands_t *cmd = NULL; |
ioCommands_t *cmd = NULL; |
| |
|
| if (!cmdList) | inline int inline_help() |
| return -1; | { |
| | io_Cmd_Help(cmdList ? cmdList : io_stdCmds, out, NULL); |
| | rl_on_new_line(); |
| | return 0; |
| | } |
| | |
| | char **io_stdCompletion(const char *text, int start, int end) |
| | { |
| | register int i; |
| | char **matches = NULL; |
| | |
| | char *cmdCompGet(const char *text, int state) |
| | { |
| | int len = strlen(text); |
| | |
| | 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; |
| | } |
| | |
| | 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))) |
| | matches = rl_completion_matches(text, cmdList[i].cmd_comp); |
| | |
| | return matches; |
| | } |
| | char *io_stdCompEntry(const char *ignore, int invoking_key) |
| | { |
| | return NULL; |
| | } |
| | |
| | rl_bind_key('?', inline_help); |
| | if (!rl_attempted_completion_function) |
| | ioCLIComp(io_stdCompletion, io_stdCompEntry); |
| |
|
| do { |
do { |
| line = readline(csPrompt); |
line = readline(csPrompt); |