annotate rvinterf/tmsh/main.c @ 495:06ad5e30e8d0

target-utils: wait_ARM_cycles() changed to 4 cycles per loop
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 25 May 2019 18:51:19 +0000
parents e40bb5a6c6b9
children
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
422
c1aadfcd185f rvinterf client refactoring: libasync clients converted to use libinterf
Mychaela Falconia <falcon@freecalypso.org>
parents: 71
diff changeset
12 extern char *socket_pathname;
c1aadfcd185f rvinterf client refactoring: libasync clients converted to use libinterf
Mychaela Falconia <falcon@freecalypso.org>
parents: 71
diff changeset
13 extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
c1aadfcd185f rvinterf client refactoring: libasync clients converted to use libinterf
Mychaela Falconia <falcon@freecalypso.org>
parents: 71
diff changeset
14 extern int sock;
c1aadfcd185f rvinterf client refactoring: libasync clients converted to use libinterf
Mychaela Falconia <falcon@freecalypso.org>
parents: 71
diff changeset
15
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 int ttyhacks, dflag;
71
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
17 int oneshot_nowait;
0
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 main(argc, argv)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char **argv;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern int optind;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 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
24 int c, sopt = 0;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 fd_set fds;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
71
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
27 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
28 switch (c) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 case 'B':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 rvinterf_Bopt = optarg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 case 'd':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 dflag++;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 case 'l':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 rvinterf_lopt = optarg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 continue;
71
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
38 case 'n':
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
39 oneshot_nowait++;
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
40 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
41 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
42 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
43 continue;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 case 's':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 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
46 sopt++;
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 case 'w':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 rvinterf_wopt = optarg;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 case '?':
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 default:
71
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
53 /* error msg already printed */
65
21a79f465d6a fc-tmsh: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
54 exit(ERROR_USAGE);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
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
56 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
57 if (sopt) {
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 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
59 "%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
60 argv[0]);
65
21a79f465d6a fc-tmsh: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
61 exit(ERROR_USAGE);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
423
e40bb5a6c6b9 rvinterf clients: implemented 30 ms delay for batch ops with -p
Mychaela Falconia <falcon@freecalypso.org>
parents: 422
diff changeset
63 launch_rvinterf(argv[optind] && !oneshot_nowait);
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
64 } 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
65 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
66 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
67 "%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
68 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
69 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
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
71 connect_local_socket();
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
71
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
74 if (argv[optind])
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
75 return oneshot_command(argc - optind, argv + optind);
27c41e4b21ae fc-tmsh one-shot operation mode implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 70
diff changeset
76
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 ttyhacks = isatty(0) && !dflag;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 init();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 tty_init();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 for (;;) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 FD_ZERO(&fds);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 FD_SET(0, &fds);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 FD_SET(sock, &fds);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 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
85 if (c < 0) {
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 if (errno == EINTR)
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 continue;
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 tty_cleanup();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 perror("select");
65
21a79f465d6a fc-tmsh: use the newly adopted exit code convention
Mychaela Falconia <falcon@freecalypso.org>
parents: 0
diff changeset
90 exit(ERROR_UNIX);
0
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (FD_ISSET(0, &fds))
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 handle_tty_input();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 if (FD_ISSET(sock, &fds))
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 handle_rvinterf_input();
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 fflush(stdout);
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
e7502631a0f9 initial import from freecalypso-sw rev 1033:5ab737ac3ad7
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }