File:  [ELWIX - Embedded LightWeight unIX -] / libaitcli / src / cli.c
Revision 1.2: 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: cli2_1, HEAD, CLI2_0
2.0

/*************************************************************************
* (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
*  by Michael Pounov <misho@openbsd-bg.org>
*
* $Author: misho $
* $Id: cli.c,v 1.2 2011/03/16 17:24:03 misho Exp $
*
*************************************************************************/
#include "global.h"


/*
 * cli_Cmd_Exit() Builtin helper function for Exit from Cli
 * @buffer = CLI buffer
 * @idx = Selected command ID
 * @args = Parsed arguments array
 * return: RETCODE_EOF exit from Cli!
*/
int cli_Cmd_Exit(void * __restrict buffer, int idx, char ** __restrict args)
{
	cli_Printf(buffer, "\n");
	return RETCODE_EOF;
}

/*
 * cli_Cmd_Help() Builtin helper function for Help screen
 * @buffer = CLI buffer
 * @idx = Selected command ID
 * @args = Parsed arguments array
 * return: RETCODE_ERR in error or RETCODE_OK
*/
int cli_Cmd_Help(void * __restrict buffer, int idx, char ** __restrict args)
{
	linebuffer_t *buf = buffer;
	struct tagCommand *cmd;

	if (!buffer) {
		cli_SetErr(EINVAL, "Error:: invalid input parameters ...");
		return RETCODE_ERR;
	}

	cli_Printf(buf, "\n");
	if (!args) {
		SLIST_FOREACH(cmd, &buf->line_cmds, cmd_next)
			cli_Printf(buf, "%s\t\t%s\n", cmd->cmd_name, cmd->cmd_help);
	} else {
		if (!args[1])
			cli_Printf(buf, "Help screen::\n");
		else
			if (!strncmp(args[1], "---", 3))
				return RETCODE_OK;

		SLIST_FOREACH(cmd, &buf->line_cmds, cmd_next) {
			if (args[1] && (cmd->cmd_level != buf->line_level || strcmp(args[1], cmd->cmd_name)))
				continue;

			cli_Printf(buf, "%s%s\t\t%s\n", args[1] ? "Syntax::\n\t" : "", cmd->cmd_name, 
					args[1] ? cmd->cmd_info: cmd->cmd_help);
		}
	}
	cli_Printf(buffer, "\r");

	return RETCODE_OK;
}

/*
 * cli_Cmd_Unsupported() Builtin helper function for unsupported commands
 * @buffer = CLI buffer
 * @idx = Selected command ID
 * @args = Parsed arguments array
 * return: RETCODE_OK ok
*/
int cli_Cmd_Unsupported(void * __restrict buffer, int idx, char ** __restrict args)
{
	cli_Printf(buffer, "Command %s not supported in this version ...\n", args[0]);
	return RETCODE_OK;
}

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