diff rvinterf/tmsh/main.c @ 70:2c6dca514a20

fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 26 Oct 2016 23:33:21 +0000
parents 21a79f465d6a
children 27c41e4b21ae
line wrap: on
line diff
--- a/rvinterf/tmsh/main.c	Wed Oct 26 23:17:03 2016 +0000
+++ b/rvinterf/tmsh/main.c	Wed Oct 26 23:33:21 2016 +0000
@@ -10,6 +10,7 @@
 #include "exitcodes.h"
 
 char *socket_pathname = "/tmp/rvinterf_socket";
+char *rvinterf_ttyport;
 int ttyhacks, dflag;
 
 int sock;
@@ -21,10 +22,10 @@
 {
 	extern int optind;
 	extern char *optarg;
-	int c;
+	int c, sopt = 0;
 	fd_set fds;
 
-	while ((c = getopt(argc, argv, "B:dl:s:w:")) != EOF)
+	while ((c = getopt(argc, argv, "B:dl:p:s:w:")) != EOF)
 		switch (c) {
 		case 'B':
 			rvinterf_Bopt = optarg;
@@ -35,8 +36,12 @@
 		case 'l':
 			rvinterf_lopt = optarg;
 			continue;
+		case 'p':
+			rvinterf_ttyport = optarg;
+			continue;
 		case 's':
 			socket_pathname = optarg;
+			sopt++;
 			continue;
 		case 'w':
 			rvinterf_wopt = optarg;
@@ -44,23 +49,25 @@
 		case '?':
 		default:
 usage:			fprintf(stderr,
-				"usage: %s [options] [ttyport]\n", argv[0]);
+				"usage: %s [options] [command]\n", argv[0]);
 			exit(ERROR_USAGE);
 		}
-	switch (argc - optind) {
-	case 0:
-		if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
+	if (rvinterf_ttyport) {
+		if (sopt) {
 			fprintf(stderr,
-      "%s: -B, -l and -w options are meaningful only when launching rvinterf\n",
+			"%s error: -p and -s options are mutually exclusive\n",
 				argv[0]);
 			exit(ERROR_USAGE);
 		}
-		break;
-	case 1:
-		launch_rvinterf(argv[optind]);
-		break;
-	default:
-		goto usage;
+		launch_rvinterf(rvinterf_ttyport);
+	} else {
+		if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
+			fprintf(stderr,
+"%s error: -B, -l and -w options are meaningful only when launching rvinterf\n",
+				argv[0]);
+			exit(ERROR_USAGE);
+		}
+		connect_local_socket();
 	}
 
 	ttyhacks = isatty(0) && !dflag;