FreeCalypso > hg > freecalypso-tools
annotate rvinterf/etmsync/tmsmain.c @ 305:3d79116be312
doc/Compal-calibration: fc-readcal failed approach documented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 20 Nov 2017 17:51:23 +0000 |
parents | 20ed7a320b12 |
children | e40bb5a6c6b9 |
rev | line source |
---|---|
269
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module contains the main() function for fc-tmsync. |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdlib.h> |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <unistd.h> |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "exitcodes.h" |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 extern char *socket_pathname; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 main(argc, argv) |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 char **argv; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern int optind; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern char *optarg; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 int c, sopt = 0; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char command[512]; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 while ((c = getopt(argc, argv, "+B:l:p:s:w:")) != EOF) |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 switch (c) { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 case 'B': |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 rvinterf_Bopt = optarg; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 continue; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 case 'l': |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 rvinterf_lopt = optarg; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 continue; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 case 'p': |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 rvinterf_ttyport = optarg; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 continue; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 case 's': |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 socket_pathname = optarg; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 sopt++; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 continue; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 case 'w': |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 rvinterf_wopt = optarg; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 continue; |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 case '?': |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 default: |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 /* error msg already printed */ |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(ERROR_USAGE); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (rvinterf_ttyport) { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (sopt) { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 fprintf(stderr, |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 "%s error: -p and -s options are mutually exclusive\n", |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 argv[0]); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(ERROR_USAGE); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 launch_rvinterf(); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } else { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 fprintf(stderr, |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 "%s error: -B, -l and -w options are meaningful only when launching rvinterf\n", |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 argv[0]); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 exit(ERROR_USAGE); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 connect_local_socket(); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 setlinebuf(stdout); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (argv[optind]) |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 return dispatch_ready_argv(argc - optind, argv + optind); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 for (;;) { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (isatty(0)) { |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 rx_control(0); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 fputs("tmsync> ", stdout); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 fflush(stdout); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (!fgets(command, sizeof command, stdin)) |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 exit(0); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 parse_and_dispatch_cmd(command, 0); |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
20ed7a320b12
fc-tmsync skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |