diff rvinterf/tmsh/main.c @ 260:c146f38d2b5f

rvinterf subdir structure made a little more sensible
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 05 Feb 2014 04:02:13 +0000
parents rvinterf/etm/main.c@2847b6cbd915
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/main.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,86 @@
+/*
+ * This module contains the main() function for fc-tmsh.
+ */
+
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+char *socket_pathname = "/tmp/rvinterf_socket";
+int ttyhacks, dflag;
+
+int sock;
+
+extern char *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
+
+main(argc, argv)
+	char **argv;
+{
+	extern int optind;
+	extern char *optarg;
+	int c;
+	fd_set fds;
+
+	while ((c = getopt(argc, argv, "B:dl:s:w:")) != EOF)
+		switch (c) {
+		case 'B':
+			rvinterf_Bopt = optarg;
+			continue;
+		case 'd':
+			dflag++;
+			continue;
+		case 'l':
+			rvinterf_lopt = optarg;
+			continue;
+		case 's':
+			socket_pathname = optarg;
+			continue;
+		case 'w':
+			rvinterf_wopt = optarg;
+			continue;
+		case '?':
+		default:
+usage:			fprintf(stderr,
+				"usage: %s [options] [ttyport]\n", argv[0]);
+			exit(1);
+		}
+	switch (argc - optind) {
+	case 0:
+		if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
+			fprintf(stderr,
+      "%s: -B, -l and -w options are meaningful only when launching rvinterf\n",
+				argv[0]);
+			exit(1);
+		}
+		break;
+	case 1:
+		launch_rvinterf(argv[optind]);
+		break;
+	default:
+		goto usage;
+	}
+
+	ttyhacks = isatty(0) && !dflag;
+	init();
+	tty_init();
+	for (;;) {
+		FD_ZERO(&fds);
+		FD_SET(0, &fds);
+		FD_SET(sock, &fds);
+		c = select(sock+1, &fds, 0, 0, 0);
+		if (c < 0) {
+			if (errno == EINTR)
+				continue;
+			tty_cleanup();
+			perror("select");
+			exit(1);
+		}
+		if (FD_ISSET(0, &fds))
+			handle_tty_input();
+		if (FD_ISSET(sock, &fds))
+			handle_rvinterf_input();
+		fflush(stdout);
+	}
+}