view rvinterf/tmsh/usercmd.c @ 554:3a0ce0ea4035

gsm-fw/L1/tpudrv/tpudrv.h: Leonardo version replaced with LoCosto-based one; l1dmacro_rx_nb() and l1dmacro_rx_cont() prototypes fixed not to include the csf_filter_choice parameter in the Calypso configuration
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 04 Aug 2014 04:57:24 +0000
parents 4c6bee98e002
children 1ee80bcb0fd0
line wrap: on
line source

/*
 * This module implements fc-tmsh user command dispatch.
 */

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>

extern char usercmd[];

extern void cmd_abbr();
extern void cmd_abbw();
extern void cmd_check_ffs1();
extern void cmd_dieid();
extern void cmd_etmpkt();
extern void cmd_ffs2();
extern void cmd_ping();
extern void cmd_r8();
extern void cmd_r16();
extern void cmd_r32();
extern void cmd_set_imeisv();
extern void cmd_set_pcm_string();
extern void cmd_set_rfcap();
extern void cmd_tgtreset();
extern void cmd_version();
extern void cmd_w8();
extern void cmd_w16();
extern void cmd_w32();

void
cmd_exit()
{
	tty_cleanup();
	exit(0);
}

static struct cmdtab {
	char *cmd;
	int minargs;
	int maxargs;
	void (*func)();
} cmdtab[] = {
	{"abbr", 2, 2, cmd_abbr},
	{"abbw", 3, 3, cmd_abbw},
	{"check-ffs1", 0, 0, cmd_check_ffs1},
	{"dieid", 0, 0, cmd_dieid},
	{"etmpkt", 1, 253, cmd_etmpkt},
	{"exit", 0, 0, cmd_exit},
	{"ffs2", 1, 3, cmd_ffs2},
	{"ping", 0, 2, cmd_ping},
	{"quit", 0, 0, cmd_exit},
	{"r8", 1, 2, cmd_r8},
	{"r16", 1, 2, cmd_r16},
	{"r32", 1, 2, cmd_r32},
	{"set-imeisv", 2, 2, cmd_set_imeisv},
	{"set-pcm-string", 2, 2, cmd_set_pcm_string},
	{"set-rfcap", 16, 16, cmd_set_rfcap},
	{"tgtreset", 0, 0, cmd_tgtreset},
	{"version", 1, 1, cmd_version},
	{"w8", 2, 246, cmd_w8},
	{"w16", 2, 123, cmd_w16},
	{"w32", 2, 62, cmd_w32},
	{0, 0, 0, 0}
};

void
dispatch_user_cmd()
{
	char *argv[257];
	char *cp, **ap;
	struct cmdtab *tp;

	for (cp = usercmd; isspace(*cp); cp++)
		;
	if (!*cp || *cp == '#')
		return;
	argv[0] = cp;
	while (*cp && !isspace(*cp))
		cp++;
	if (*cp)
		*cp++ = '\0';
	for (tp = cmdtab; tp->cmd; tp++)
		if (!strcmp(tp->cmd, argv[0]))
			break;
	if (!tp->func) {
		printf("error: no such command\n");
		return;
	}
	for (ap = argv + 1; ; ) {
		while (isspace(*cp))
			cp++;
		if (!*cp || *cp == '#')
			break;
		if (ap - argv - 1 >= tp->maxargs) {
			printf("error: too many arguments\n");
			return;
		}
		if (*cp == '"') {
			*ap++ = ++cp;
			while (*cp && *cp != '"')
				cp++;
			if (*cp != '"') {
				printf("error: unterminated quoted string\n");
				return;
			}
			*cp++ = '\0';
		} else {
			*ap++ = cp;
			while (*cp && !isspace(*cp))
				cp++;
			if (*cp)
				*cp++ = '\0';
		}
	}
	if (ap - argv - 1 < tp->minargs) {
		printf("error: too few arguments\n");
		return;
	}
	*ap = 0;
	tp->func(ap - argv, argv);
}