Annotation of libaitcli/src/cli.c, revision 1.2
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.2 ! misho 6: * $Id: cli.c,v 1.1.1.1.4.3 2010/06/07 12:30:28 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
1.2 ! misho 14: * @buffer = CLI buffer
1.1 misho 15: * @idx = Selected command ID
16: * @args = Parsed arguments array
1.2 ! misho 17: * return: RETCODE_EOF exit from Cli!
1.1 misho 18: */
1.2 ! misho 19: int cli_Cmd_Exit(void * __restrict buffer, int idx, char ** __restrict args)
1.1 misho 20: {
1.2 ! misho 21: cli_Printf(buffer, "\n");
! 22: return RETCODE_EOF;
1.1 misho 23: }
24:
25: /*
26: * cli_Cmd_Help() Builtin helper function for Help screen
1.2 ! misho 27: * @buffer = CLI buffer
1.1 misho 28: * @idx = Selected command ID
29: * @args = Parsed arguments array
1.2 ! misho 30: * return: RETCODE_ERR in error or RETCODE_OK
1.1 misho 31: */
1.2 ! misho 32: int cli_Cmd_Help(void * __restrict buffer, int idx, char ** __restrict args)
1.1 misho 33: {
1.2 ! misho 34: linebuffer_t *buf = buffer;
! 35: struct tagCommand *cmd;
1.1 misho 36:
1.2 ! misho 37: if (!buffer) {
! 38: cli_SetErr(EINVAL, "Error:: invalid input parameters ...");
! 39: return RETCODE_ERR;
! 40: }
1.1 misho 41:
1.2 ! misho 42: cli_Printf(buf, "\n");
1.1 misho 43: if (!args) {
1.2 ! misho 44: SLIST_FOREACH(cmd, &buf->line_cmds, cmd_next)
! 45: cli_Printf(buf, "%s\t\t%s\n", cmd->cmd_name, cmd->cmd_help);
1.1 misho 46: } else {
47: if (!args[1])
1.2 ! misho 48: cli_Printf(buf, "Help screen::\n");
1.1 misho 49: else
50: if (!strncmp(args[1], "---", 3))
1.2 ! misho 51: return RETCODE_OK;
1.1 misho 52:
1.2 ! misho 53: SLIST_FOREACH(cmd, &buf->line_cmds, cmd_next) {
! 54: if (args[1] && (cmd->cmd_level != buf->line_level || strcmp(args[1], cmd->cmd_name)))
1.1 misho 55: continue;
56:
1.2 ! misho 57: cli_Printf(buf, "%s%s\t\t%s\n", args[1] ? "Syntax::\n\t" : "", cmd->cmd_name,
! 58: args[1] ? cmd->cmd_info: cmd->cmd_help);
1.1 misho 59: }
60: }
1.2 ! misho 61: cli_Printf(buffer, "\r");
1.1 misho 62:
1.2 ! misho 63: return RETCODE_OK;
1.1 misho 64: }
65:
66: /*
67: * cli_Cmd_Unsupported() Builtin helper function for unsupported commands
1.2 ! misho 68: * @buffer = CLI buffer
1.1 misho 69: * @idx = Selected command ID
70: * @args = Parsed arguments array
1.2 ! misho 71: * return: RETCODE_OK ok
1.1 misho 72: */
1.2 ! misho 73: int cli_Cmd_Unsupported(void * __restrict buffer, int idx, char ** __restrict args)
1.1 misho 74: {
1.2 ! misho 75: cli_Printf(buffer, "Command %s not supported in this version ...\n", args[0]);
! 76: return RETCODE_OK;
1.1 misho 77: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>