view rvinterf/asyncshell/usercmd.c @ 875:dab341e172de

fc-shell: sysprim sending (sp command) implemented
author Space Falcon <falcon@ivan.Harhan.ORG>
date Sat, 30 May 2015 07:41:23 +0000
parents 72d64c172d85
children 4661b84260a0
line wrap: on
line source

/*
 * This module implements interactive fc-shell 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_disable();
extern void cmd_enable();
extern void cmd_sendsp();

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

static struct cmdtab {
	char *cmd;
	void (*func)();
} cmdtab[] = {
	{"disable", cmd_disable},
	{"enable", cmd_enable},
	{"exit", cmd_exit},
	{"quit", cmd_exit},
	{"sp", cmd_sendsp},
	{0, 0}
};

void
dispatch_user_cmd()
{
	char *cp, *np;
	struct cmdtab *tp;

	for (cp = usercmd; isspace(*cp); cp++)
		;
	if (!*cp || *cp == '#')
		return;
	for (np = cp; *cp && !isspace(*cp); cp++)
		;
	if (*cp)
		*cp++ = '\0';
	for (tp = cmdtab; tp->cmd; tp++)
		if (!strcmp(tp->cmd, np))
			break;
	if (tp->func)
		tp->func(cp);
	else
		printf("error: no such command\n");
}