File:  [ELWIX - Embedded LightWeight unIX -] / libaitcli / example / test.c
Revision 1.7: download - view: text, annotated - select for diffs - revision graph
Tue Mar 19 10:06:37 2024 UTC (8 weeks, 1 day ago) by misho
Branches: MAIN
CVS tags: cli4_6, HEAD, CLI4_5
Version 4.5

#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 }
};
*/

static int
oho(void *buf, int idx, char **argv)
{
	printf("Oho!!!! level 0\n");
	return 0;
}

static int
boho(void *buf, int idx, char **argv)
{
	printf("Boho !!!! level 1\n");
	return 0;
}

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

int
main(int argc, char **argv)
{
	int ret;
	linebuffer_t *t;

//	ret = cliExec(commands, "test>");
	t = cliInit(0, 1, argv[1]);
	cli_addCommand(t, "oho", 1, oho, "oho [args]", "oho - is test level 0");
	cli_addCommand(t, "boho", 2, boho, "boho [args]", "boho - is test level 1");
	ret = cliLoop(t, NULL, -1);
	cliEnd(t);

	return 0;
}

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