File:  [ELWIX - Embedded LightWeight unIX -] / libaitcli / example / test.c
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Wed Mar 16 17:24:03 2011 UTC (13 years, 3 months ago) by misho
Branches: MAIN
CVS tags: cli3_3, cli3_2, cli3_1, cli3_0, cli2_3, cli2_2, cli2_1, HEAD, CLI3_2, CLI3_1, CLI3_0, CLI2_3, CLI2_2, CLI2_1, CLI2_0
2.0

    1: #include <stdio.h>
    2: #include <string.h>
    3: #include <aitcli.h>
    4: 
    5: 
    6: // This export commands, good place for write is global header file
    7: //CLI_REGISTER_COMMANDS(commands)
    8: //
    9: 
   10: // ---------------------------------------------------------------
   11: /*
   12: int cmd_test1(void *cmds, int idx, FILE *out, char ** __restrict args)
   13: {
   14: 	cliCommands_t *c = cmds;
   15: 
   16: 	if (!args || !args[1]) {
   17: 		cli_PrintHelp(out, cmds, idx);
   18: 		return -1;
   19: 	}
   20: 
   21: 	cli_Printf(out, "I`m in test1 %s!\n", args[1]);
   22: 
   23: 	return 0;
   24: }
   25: 
   26: int cmd_show(void *cmds __attribute__((unused)), int idx, FILE *out, char ** __restrict args)
   27: {
   28: 	if (!args)
   29: 		return -1;
   30: 
   31: 	cli_Printf(out, "I`m in show!\n");
   32: 
   33: 	return 0;
   34: }
   35: 
   36: // ---------------------------------------------------------------
   37: 
   38: const char *arg2[] = { "1_<get|set>", "2_[range]", NULL };
   39: CLI_MAKE_COMP_ARGS(comp_2arg, arg2)
   40: const char *show[] = { "1_[from_event]", "2_[to_event]", NULL };
   41: CLI_MAKE_COMP_ARGS(comp_show, show)
   42: 
   43: CLI_MAKE_COMP_COMMANDS(comp_help, commands)
   44: 
   45: cliCommands_t commands[] = {
   46: 	{ "test1", cmd_test1, "Test1 function", "test1 <get|set> [range] <cr>", comp_2arg }, 
   47: 	{ "test0", cli_Cmd_Unsupported, "Test0 function", "test0 <cr>", NULL }, 
   48: 	{ "show", cmd_show, "Show information", "show [from_event] [to_event] <cr>", comp_show }, 
   49: 	{ "-------", NULL, "---------------------", NULL, NULL }, 
   50: 	{ "help", cli_Cmd_Help, "Help screen", "help [command] <cr>", comp_help }, 
   51: 	{ "exit", cli_Cmd_Exit, "Exit from console", "exit <cr>", NULL }, 
   52: 	{ NULL, NULL, NULL, NULL, NULL }
   53: };
   54: */
   55: 
   56: // ---------------------------------------
   57: 
   58: int main()
   59: {
   60: 	int ret;
   61: 	linebuffer_t *t;
   62: 
   63: //	ret = cliExec(commands, "test>");
   64: 	t = cliInit(0, 1, "test>");
   65: 	ret = cliLoop(t, NULL);
   66: 	cliEnd(t);
   67: 
   68: 	return 0;
   69: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>