comparison rvinterf/asyncshell/main.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 bd873572ef2c
comparison
equal deleted inserted replaced
871:a5c8f48003cd 872:5e46679bdb6a
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 ttyhacks = isatty(0) && !dflag;
73 init();
74 tty_init();
75 for (;;) {
76 FD_ZERO(&fds);
77 FD_SET(0, &fds);
78 FD_SET(sock, &fds);
79 c = select(sock+1, &fds, 0, 0, 0);
80 if (c < 0) {
81 if (errno == EINTR)
82 continue;
83 tty_cleanup();
84 perror("select");
85 exit(1);
86 }
87 if (FD_ISSET(0, &fds))
88 handle_tty_input();
89 if (FD_ISSET(sock, &fds))
90 handle_rvinterf_input();
91 fflush(stdout);
92 }
93 }