comparison rvinterf/etmsync/tmsmain.c @ 269:20ed7a320b12

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