3 * $Id: main.c,v 1.3 2002/02/02 19:21:53 mdw Exp $
7 * (c) 2001 Mark Wooding
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Jog: Programming for a jogging machine.
14 * Jog is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * Jog is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Jog; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Header files ------------------------------------------------------*/
44 #include <mLib/alloc.h>
45 #include <mLib/mdwopt.h>
46 #include <mLib/quis.h>
47 #include <mLib/report.h>
48 #include <mLib/trace.h>
55 #include "tx-serial-unix.h"
57 /*----- Shutdown stuff ----------------------------------------------------*/
59 static int sigtab
[] = { SIGINT
, SIGQUIT
, SIGTERM
, SIGHUP
, -1 };
61 static void tidy(void)
67 static void sigtidy(int sig
)
74 /*----- Help functions ----------------------------------------------------*/
76 static void usage(FILE *fp
)
79 Usage: $ [-t TRANSPORT] [-f FILE] [-c CONFIG] [-a AUDIR] [-x SIZE]\n\
84 static void version(FILE *fp
)
86 pquis(fp
, "$, version " VERSION
"\n");
89 static void help(FILE *fp
)
97 -h, --help Print this help message.\n\
98 -v, --version Show the version number.\n\
99 -u, --usage Show terse usage summary.\n\
101 -t, --transport=NAME Use transport type NAME.\n\
102 -f, --tx-file=FILE Communicate using the named FILE.\n\
103 -c, --tx-config=CONFIG Use CONFIG as transport configuration.\n\
105 -a, --audio=DIR Set directory containing audio samples.\n\
106 -x, --cache-max=SIZE Maximum size for audio sample cache.\n\
111 /*----- Main code ---------------------------------------------------------*/
113 int main(int argc
, char *argv
[])
118 const char *audir
= 0;
119 size_t aumax
= AU_CACHEMAX
;
125 for (i
= 0; sigtab
[i
] >= 0; i
++)
126 signal(sigtab
[i
], sigtidy
);
130 T( trace_on(stderr
, 0u); )
131 if ((txname
= getenv("JOGTX")) != 0)
134 txname
= txlist
->name
;
137 static const struct option opt
[] = {
139 /* --- Standard help options --- */
141 { "help", 0, 0, 'h' },
142 { "version", 0, 0, 'v' },
143 { "usage", 0, 0, 'u' },
145 /* --- Transport configuration stuff --- */
147 { "transport", OPTF_ARGREQ
, 0, 't' },
148 { "transport-config",
149 OPTF_ARGREQ
, 0, 'c' },
150 { "tx-config", OPTF_ARGREQ
, 0, 'c' },
151 { "txconfig", OPTF_ARGREQ
, 0, 'c' },
152 { "config", OPTF_ARGREQ
, 0, 'c' },
154 OPTF_ARGREQ
, 0, 'f' },
155 { "tx-file", OPTF_ARGREQ
, 0, 'f' },
156 { "txfile", OPTF_ARGREQ
, 0, 'f' },
157 { "file", OPTF_ARGREQ
, 0, 'f' },
159 /* --- Audio configuration stuff --- */
162 OPTF_ARGREQ
, 0, 'a' },
164 OPTF_ARGREQ
, 0, 'x' },
166 OPTF_ARGREQ
, 0, 'x' },
168 /* --- Debugging stuff --- */
171 { "trace", OPTF_ARGREQ
, 0, 'T' },
174 /* --- End marker --- */
180 static const trace_opt tropt
[] = {
181 { 'x', T_TX
, "transport layer" },
182 { 's', T_TXSYS
, "low-level transport" },
183 { 'a', T_AU
, "audio subsystem" },
184 { 'y', T_AUSYS
, "system-specific audio" },
185 { 'A', T_ALL
, "all of the above" },
190 i
= mdwopt(argc
, argv
, "hvu" "t:c:f:" "a:x:" T("T:"), opt
, 0, 0, 0);
196 /* --- Standard help options --- */
208 /* --- Transport configuration stuff --- */
220 /* --- Audio configuration stuff --- */
226 aumax
= strtoul(optarg
, 0, 0);
229 /* --- Tracing --- */
233 trace_level(traceopt(tropt
, optarg
, tracing(), 0));
245 if ((f
& f_bogus
) || optind
> argc
- 1) {
250 au_init(audir
, aumax
);
251 rc
= rx_runfile(argv
[optind
],
252 argc
- optind
- 1, (const char *const *)argv
+ optind
+ 1);
253 return (rc ? EXIT_FAILURE
: 0);
256 /*----- That's all, folks -------------------------------------------------*/