File:  [ELWIX - Embedded LightWeight unIX -] / libaitcli / example / test.c
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Fri Apr 16 13:20:29 2010 UTC (14 years, 1 month ago) by misho
Branches: MAIN
CVS tags: HEAD
Initial revision

#include <stdio.h>
#include <string.h>
#include <aitcli.h>


// This export commands, good place for write is global header file
CLI_REGISTER_COMMANDS(commands)
//

// ---------------------------------------------------------------

int cmd_test1(void *cmds, int idx, FILE *out, char ** __restrict args)
{
	cliCommands_t *c = cmds;

	if (!args || !args[1]) {
		cli_PrintHelp(out, cmds, idx);
		return -1;
	}

	cli_Printf(out, "I`m in test1 %s!\n", args[1]);

	return 0;
}

int cmd_show(void *cmds __attribute__((unused)), int idx, FILE *out, char ** __restrict args)
{
	if (!args)
		return -1;

	cli_Printf(out, "I`m in show!\n");

	return 0;
}

// ---------------------------------------------------------------

const char *arg2[] = { "1_<get|set>", "2_[range]", NULL };
CLI_MAKE_COMP_ARGS(comp_2arg, arg2)
const char *show[] = { "1_[from_event]", "2_[to_event]", NULL };
CLI_MAKE_COMP_ARGS(comp_show, show)

CLI_MAKE_COMP_COMMANDS(comp_help, commands)

cliCommands_t commands[] = {
	{ "test1", cmd_test1, "Test1 function", "test1 <get|set> [range] <cr>", comp_2arg }, 
	{ "test0", cli_Cmd_Unsupported, "Test0 function", "test0 <cr>", NULL }, 
	{ "show", cmd_show, "Show information", "show [from_event] [to_event] <cr>", comp_show }, 
	{ "-------", NULL, "---------------------", NULL, NULL }, 
	{ "help", cli_Cmd_Help, "Help screen", "help [command] <cr>", comp_help }, 
	{ "exit", cli_Cmd_Exit, "Exit from console", "exit <cr>", NULL }, 
	{ NULL, NULL, NULL, NULL, NULL }
};


// ---------------------------------------

int main()
{
	int ret;

	ret = cliExec(commands, stdout, "test>");

	return 0;
}

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