FreeCalypso > hg > freecalypso-tools
comparison rvinterf/tmsh/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 | 21a79f465d6a |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
1 /* | |
2 * This module contains the main() function for fc-tmsh. | |
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 int ttyhacks, dflag; | |
13 | |
14 int sock; | |
15 | |
16 extern char *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt; | |
17 | |
18 main(argc, argv) | |
19 char **argv; | |
20 { | |
21 extern int optind; | |
22 extern char *optarg; | |
23 int c; | |
24 fd_set fds; | |
25 | |
26 while ((c = getopt(argc, argv, "B:dl:s:w:")) != EOF) | |
27 switch (c) { | |
28 case 'B': | |
29 rvinterf_Bopt = optarg; | |
30 continue; | |
31 case 'd': | |
32 dflag++; | |
33 continue; | |
34 case 'l': | |
35 rvinterf_lopt = optarg; | |
36 continue; | |
37 case 's': | |
38 socket_pathname = optarg; | |
39 continue; | |
40 case 'w': | |
41 rvinterf_wopt = optarg; | |
42 continue; | |
43 case '?': | |
44 default: | |
45 usage: fprintf(stderr, | |
46 "usage: %s [options] [ttyport]\n", argv[0]); | |
47 exit(1); | |
48 } | |
49 switch (argc - optind) { | |
50 case 0: | |
51 if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) { | |
52 fprintf(stderr, | |
53 "%s: -B, -l and -w options are meaningful only when launching rvinterf\n", | |
54 argv[0]); | |
55 exit(1); | |
56 } | |
57 break; | |
58 case 1: | |
59 launch_rvinterf(argv[optind]); | |
60 break; | |
61 default: | |
62 goto usage; | |
63 } | |
64 | |
65 ttyhacks = isatty(0) && !dflag; | |
66 init(); | |
67 tty_init(); | |
68 for (;;) { | |
69 FD_ZERO(&fds); | |
70 FD_SET(0, &fds); | |
71 FD_SET(sock, &fds); | |
72 c = select(sock+1, &fds, 0, 0, 0); | |
73 if (c < 0) { | |
74 if (errno == EINTR) | |
75 continue; | |
76 tty_cleanup(); | |
77 perror("select"); | |
78 exit(1); | |
79 } | |
80 if (FD_ISSET(0, &fds)) | |
81 handle_tty_input(); | |
82 if (FD_ISSET(sock, &fds)) | |
83 handle_rvinterf_input(); | |
84 fflush(stdout); | |
85 } | |
86 } |