Annotation of libaitcli/src/cli.c, revision 1.1.1.1.4.1
1.1 misho 1: /*************************************************************************
2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
3: * by Michael Pounov <misho@openbsd-bg.org>
4: *
5: * $Author: misho $
1.1.1.1.4.1! misho 6: * $Id: cli.c,v 1.1.1.1 2010/04/16 13:20:29 misho Exp $
1.1 misho 7: *
8: *************************************************************************/
9: #include "global.h"
10:
11:
12: /*
13: * cli_Cmd_Exit() Builtin helper function for Exit from Cli
14: * @cmds = Commands list
15: * @idx = Selected command ID
16: * @out = Output handle
17: * @args = Parsed arguments array
18: * return: 1 exit from Cli!
19: */
20: int cli_Cmd_Exit(void *cmds, int idx, FILE *out, char ** __restrict args)
21: {
22: return 1;
23: }
24:
25: /*
26: * cli_Cmd_Help() Builtin helper function for Help screen
27: * @cmds = Commands list
28: * @idx = Selected command ID
29: * @out = Output handle
30: * @args = Parsed arguments array
31: * return: -1 error, 0 = ok
32: */
1.1.1.1.4.1! misho 33: /*
1.1 misho 34: int cli_Cmd_Help(void *cmds, int idx, FILE *out, char ** __restrict args)
35: {
36: register int i;
37: cliCommands_t *commands = cmds;
38:
39: if (!cmds)
40: return -1;
41:
42: if (!args) {
43: cli_Printf(out, "\n");
44: for (i = 0; commands[i].cmd_name; i++)
45: cli_Printf(out, "%s\t\t%s\n", commands[i].cmd_name, commands[i].cmd_doc);
46: } else {
47: if (!args[1])
48: cli_Printf(out, "Help screen::\n");
49: else
50: if (!strncmp(args[1], "---", 3))
51: return 0;
52:
53: for (i = 0; commands[i].cmd_name; i++) {
54: if (args[1] && strcmp(args[1], commands[i].cmd_name))
55: continue;
56:
57: cli_Printf(out, "%s%s\t\t%s\n", args[1] ? "Syntax::\n\t" : "", commands[i].cmd_name,
58: args[1] ? commands[i].cmd_help : commands[i].cmd_doc);
59: }
60: }
61:
62: return 0;
63: }
1.1.1.1.4.1! misho 64: */
1.1 misho 65:
66: /*
67: * cli_Cmd_Unsupported() Builtin helper function for unsupported commands
68: * @cmds = Commands list
69: * @idx = Selected command ID
70: * @out = Output handle
71: * @args = Parsed arguments array
72: * return: -1 error, 0 = ok, 1 exit from Cli!
73: */
74: int cli_Cmd_Unsupported(void *cmds, int idx, FILE *out, char ** __restrict args)
75: {
1.1.1.1.4.1! misho 76: // cli_Printf(out, "Command %s not supported in this version ...\n", args[0]);
1.1 misho 77: return 0;
78: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>