File:
[ELWIX - Embedded LightWeight unIX -] /
libaitcli /
example /
test.c
Revision
1.6:
download - view:
text,
annotated -
select for diffs -
revision graph
Fri Nov 22 15:17:22 2013 UTC (10 years, 8 months ago) by
misho
Branches:
MAIN
CVS tags:
cli4_5,
cli4_4,
cli4_3,
cli4_2,
cli4_1,
cli4_0,
cli3_9,
cli3_8,
cli3_7,
HEAD,
CLI4_4,
CLI4_3,
CLI4_2,
CLI4_1,
CLI4_0,
CLI3_9,
CLI3_8,
CLI3_7,
CLI3_6
version 3.6
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: 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:
70: // ---------------------------------------
71:
72: int
73: main(int argc, char **argv)
74: {
75: int ret;
76: linebuffer_t *t;
77:
78: // ret = cliExec(commands, "test>");
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");
82: ret = cliLoop(t, NULL, 10);
83: cliEnd(t);
84:
85: return 0;
86: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>