FreeCalypso > hg > freecalypso-sw
annotate rvinterf/etmsync/fsiomain.c @ 360:f9d78057d766
tfc139 hack works!
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Thu, 15 May 2014 11:09:45 +0000 |
parents | 792f164b63a6 |
children | 7b805007dcfc |
rev | line source |
---|---|
275
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module contains the main() function for fc-fsio. |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <stdio.h> |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdlib.h> |
276
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
7 #include <unistd.h> |
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
8 #include "exitcodes.h" |
275
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 char *socket_pathname = "/tmp/rvinterf_socket"; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 int sock; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 main(argc, argv) |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 char **argv; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 { |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 extern int optind; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 extern char *optarg; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 int c, sopt = 0; |
276
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
21 char command[512]; |
275
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 while ((c = getopt(argc, argv, "B:l:p:s:w:")) != EOF) |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 switch (c) { |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 case 'B': |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 rvinterf_Bopt = optarg; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 continue; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 case 'l': |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 rvinterf_lopt = optarg; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 continue; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 case 'p': |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 rvinterf_ttyport = optarg; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 continue; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 case 's': |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 socket_pathname = optarg; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 sopt++; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 continue; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 case 'w': |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 rvinterf_wopt = optarg; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 continue; |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 case '?': |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 default: |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 usage: fprintf(stderr, |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 "usage: %s [options] [command]\n", argv[0]); |
276
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
45 exit(ERROR_USAGE); |
275
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 } |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 if (rvinterf_ttyport) { |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 if (sopt) { |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 fprintf(stderr, |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 "%s error: -p and -s options are mutually exclusive\n", |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 argv[0]); |
276
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
52 exit(ERROR_USAGE); |
275
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 } |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 launch_rvinterf(); |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 } else { |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) { |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 fprintf(stderr, |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 "%s error: -B, -l and -w options are meaningful only when launching rvinterf\n", |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 argv[0]); |
276
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
60 exit(ERROR_USAGE); |
275
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 } |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 connect_local_socket(); |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 } |
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 |
296
792f164b63a6
fc-fsio: cpout now works the way it should
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
280
diff
changeset
|
65 setlinebuf(stdout); |
280
f304f9bcde3b
fc-fsio: single command invokation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
277
diff
changeset
|
66 if (argv[optind]) |
f304f9bcde3b
fc-fsio: single command invokation implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
277
diff
changeset
|
67 return dispatch_ready_argv(argc - optind, argv + optind); |
276
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
68 for (;;) { |
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
69 if (isatty(0)) { |
277
e23fc1228efd
fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
276
diff
changeset
|
70 rx_control(0); |
276
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
71 fputs("fsio> ", stdout); |
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
72 fflush(stdout); |
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
73 } |
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
74 if (!fgets(command, sizeof command, stdin)) |
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
75 exit(0); |
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
76 parse_and_dispatch_cmd(command, 0); |
909f00c15f27
more fc-fsio foundation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
275
diff
changeset
|
77 } |
275
cedf09b6b5ac
started laying the foundation for fc-fsio host utility
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 } |