annotate rvinterf/tmsh/main.c @ 355:8fee530f7850

uptools/libcoding: implemented 8859-1 -> GSM7 encoding table
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 06 Feb 2018 19:27:19 +0000
parents 27c41e4b21ae
children c1aadfcd185f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module contains the main() function for fc-tmsh.
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/errno.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <unistd.h>
65
21a79f465d6a fc-tmsh: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
10 #include "exitcodes.h"
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 char *socket_pathname = "/tmp/rvinterf_socket";
70
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
13 char *rvinterf_ttyport;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 int ttyhacks, dflag;
71
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
15 int oneshot_nowait;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 int sock;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern char *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 main(argc, argv)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 char **argv;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern int optind;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 extern char *optarg;
70
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
26 int c, sopt = 0;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 fd_set fds;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
71
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
29 while ((c = getopt(argc, argv, "B:dl:np:s:w:")) != EOF)
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 switch (c) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 case 'B':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 rvinterf_Bopt = optarg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 case 'd':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 dflag++;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 case 'l':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 rvinterf_lopt = optarg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 continue;
71
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
40 case 'n':
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
41 oneshot_nowait++;
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
42 continue;
70
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
43 case 'p':
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
44 rvinterf_ttyport = optarg;
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
45 continue;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 case 's':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 socket_pathname = optarg;
70
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
48 sopt++;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 case 'w':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 rvinterf_wopt = optarg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 case '?':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 default:
71
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
55 /* error msg already printed */
65
21a79f465d6a fc-tmsh: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
56 exit(ERROR_USAGE);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
70
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
58 if (rvinterf_ttyport) {
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
59 if (sopt) {
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 fprintf(stderr,
70
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
61 "%s error: -p and -s options are mutually exclusive\n",
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 argv[0]);
65
21a79f465d6a fc-tmsh: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
63 exit(ERROR_USAGE);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
70
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
65 launch_rvinterf(rvinterf_ttyport);
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
66 } else {
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
67 if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
68 fprintf(stderr,
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
69 "%s error: -B, -l and -w options are meaningful only when launching rvinterf\n",
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
70 argv[0]);
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
71 exit(ERROR_USAGE);
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
72 }
2c6dca514a20 fc-tmsh works like fc-shell and fc-fsio now, following the -p convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 65
diff changeset
73 connect_local_socket();
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
71
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
76 if (argv[optind])
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
77 return oneshot_command(argc - optind, argv + optind);
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
78
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 ttyhacks = isatty(0) && !dflag;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 init();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 tty_init();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 for (;;) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 FD_ZERO(&fds);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 FD_SET(0, &fds);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 FD_SET(sock, &fds);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 c = select(sock+1, &fds, 0, 0, 0);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (c < 0) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (errno == EINTR)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 tty_cleanup();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 perror("select");
65
21a79f465d6a fc-tmsh: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
92 exit(ERROR_UNIX);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 if (FD_ISSET(0, &fds))
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 handle_tty_input();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (FD_ISSET(sock, &fds))
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 handle_rvinterf_input();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 fflush(stdout);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }