comparison rvinterf/asyncshell/main.c @ 0:e7502631a0f9

initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 11 Jun 2016 00:13:35 +0000
parents
children d43d82cbfb85
comparison
equal deleted inserted replaced
-1:000000000000 0:e7502631a0f9
1 /*
2 * This module contains the main() function for fc-shell.
3 */
4
5 #include <sys/types.h>
6 #include <sys/errno.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10
11 char *socket_pathname = "/tmp/rvinterf_socket";
12 char *rvinterf_ttyport;
13 int ttyhacks, dflag;
14
15 int sock;
16
17 extern char *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
18
19 main(argc, argv)
20 char **argv;
21 {
22 extern int optind;
23 extern char *optarg;
24 int c, sopt = 0;
25 fd_set fds;
26
27 while ((c = getopt(argc, argv, "B:dl:p:s:w:")) != EOF)
28 switch (c) {
29 case 'B':
30 rvinterf_Bopt = optarg;
31 continue;
32 case 'd':
33 dflag++;
34 continue;
35 case 'l':
36 rvinterf_lopt = optarg;
37 continue;
38 case 'p':
39 rvinterf_ttyport = optarg;
40 continue;
41 case 's':
42 socket_pathname = optarg;
43 sopt++;
44 continue;
45 case 'w':
46 rvinterf_wopt = optarg;
47 continue;
48 case '?':
49 default:
50 usage: fprintf(stderr,
51 "usage: %s [options] [command]\n", argv[0]);
52 exit(1);
53 }
54 if (rvinterf_ttyport) {
55 if (sopt) {
56 fprintf(stderr,
57 "%s error: -p and -s options are mutually exclusive\n",
58 argv[0]);
59 exit(1);
60 }
61 launch_rvinterf(rvinterf_ttyport);
62 } else {
63 if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
64 fprintf(stderr,
65 "%s error: -B, -l and -w options are meaningful only when launching rvinterf\n",
66 argv[0]);
67 exit(1);
68 }
69 connect_local_socket();
70 }
71
72 if (argv[optind])
73 return oneshot_command(argc - optind, argv + optind);
74
75 ttyhacks = isatty(0) && !dflag;
76 init();
77 tty_init();
78 for (;;) {
79 FD_ZERO(&fds);
80 FD_SET(0, &fds);
81 FD_SET(sock, &fds);
82 c = select(sock+1, &fds, 0, 0, 0);
83 if (c < 0) {
84 if (errno == EINTR)
85 continue;
86 tty_cleanup();
87 perror("select");
88 exit(1);
89 }
90 if (FD_ISSET(0, &fds))
91 handle_tty_input();
92 if (FD_ISSET(sock, &fds))
93 handle_rvinterf_input();
94 fflush(stdout);
95 }
96 }