diff rvinterf/asyncshell/usercmd.c @ 872:5e46679bdb6a

fc-shell skeleton created
author Space Falcon <falcon@ivan.Harhan.ORG>
date Sat, 30 May 2015 06:42:32 +0000
parents
children 72d64c172d85
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/asyncshell/usercmd.c	Sat May 30 06:42:32 2015 +0000
@@ -0,0 +1,51 @@
+/*
+ * 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[];
+
+void
+cmd_exit()
+{
+	tty_cleanup();
+	exit(0);
+}
+
+static struct cmdtab {
+	char *cmd;
+	void (*func)();
+} cmdtab[] = {
+	{"exit", cmd_exit},
+	{"quit", cmd_exit},
+	{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");
+}