Annotation of libaitcli/example/test.c, revision 1.4

1.1       misho       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
1.3       misho       7: //CLI_REGISTER_COMMANDS(commands)
1.1       misho       8: //
                      9: 
                     10: // ---------------------------------------------------------------
1.3       misho      11: /*
1.1       misho      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: };
1.3       misho      54: */
1.1       misho      55: 
1.4     ! misho      56: static int
        !            57: oho(void *buf, int idx, char **argv)
        !            58: {
        !            59:        printf("Oho!!!! level 0\n");
        !            60:        return 0;
        !            61: }
        !            62: 
        !            63: static int
        !            64: boho(void *buf, int idx, char **argv)
        !            65: {
        !            66:        printf("Boho !!!! level 1\n");
        !            67:        return 0;
        !            68: }
        !            69: 
1.1       misho      70: // ---------------------------------------
                     71: 
1.4     ! misho      72: int
        !            73: main(int argc, char **argv)
1.1       misho      74: {
                     75:        int ret;
1.3       misho      76:        linebuffer_t *t;
1.1       misho      77: 
1.3       misho      78: //     ret = cliExec(commands, "test>");
1.4     ! misho      79:        t = cliInit(0, 1, argv[1]);
        !            80:        cli_addCommand(t, "oho", 1, oho, "oho [args]", "oho - is test level 0");
        !            81:        cli_addCommand(t, "boho", 2, boho, "boho [args]", "boho - is test level 1");
1.3       misho      82:        ret = cliLoop(t, NULL);
                     83:        cliEnd(t);
1.1       misho      84: 
                     85:        return 0;
                     86: }

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