3 * $Id: main.c,v 1.2 2002/01/30 09:27:55 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 /*----- Revision history --------------------------------------------------*
32 * Revision 1.2 2002/01/30 09:27:55 mdw
33 * Parse tracing options on the command-line.
35 * Revision 1.1 2002/01/25 19:34:45 mdw
40 /*----- Header files ------------------------------------------------------*/
51 #include <mLib/alloc.h>
52 #include <mLib/mdwopt.h>
53 #include <mLib/quis.h>
54 #include <mLib/report.h>
55 #include <mLib/trace.h>
61 #include "tx-serial-unix.h"
63 /*----- Shutdown stuff ----------------------------------------------------*/
65 static int sigtab
[] = { SIGINT
, SIGQUIT
, SIGTERM
, SIGHUP
, -1 };
67 static void tidy(void)
72 static void sigtidy(int sig
)
79 /*----- Help functions ----------------------------------------------------*/
81 static void usage(FILE *fp
)
84 Usage: $ [-t TRANSPORT] [-f FILE] [-c CONFIG] SCRIPT ARG...\n\
88 static void version(FILE *fp
)
90 pquis(fp
, "$, version " VERSION
"\n");
93 static void help(FILE *fp
)
101 -h, --help Print this help message.\n\
102 -v, --version Show the version number.\n\
103 -u, --usage Show terse usage summary.\n\
105 -t, --transport=NAME Use transport type NAME.\n\
106 -f, --tx-file=FILE Communicate using the named FILE.\n\
107 -c, --tx-config=CONFIG Use CONFIG as transport configuration.\n\
112 /*----- Main code ---------------------------------------------------------*/
114 int main(int argc
, char *argv
[])
124 for (i
= 0; sigtab
[i
] >= 0; i
++)
125 signal(sigtab
[i
], sigtidy
);
129 T( trace_on(stderr
, 0u); )
130 if ((txname
= getenv("JOGTX")) != 0)
133 txname
= txlist
->name
;
136 static const struct option opt
[] = {
138 /* --- Standard help options --- */
140 { "help", 0, 0, 'h' },
141 { "version", 0, 0, 'v' },
142 { "usage", 0, 0, 'u' },
144 /* --- Transport configuration stuff --- */
146 { "transport", OPTF_ARGREQ
, 0, 't' },
147 { "transport-config",
148 OPTF_ARGREQ
, 0, 'c' },
149 { "tx-config", OPTF_ARGREQ
, 0, 'c' },
150 { "txconfig", OPTF_ARGREQ
, 0, 'c' },
151 { "config", OPTF_ARGREQ
, 0, 'c' },
153 OPTF_ARGREQ
, 0, 'f' },
154 { "tx-file", OPTF_ARGREQ
, 0, 'f' },
155 { "txfile", OPTF_ARGREQ
, 0, 'f' },
156 { "file", OPTF_ARGREQ
, 0, 'f' },
158 /* --- Debugging stuff --- */
161 { "trace", OPTF_ARGREQ
, 0, 'T' },
164 /* --- End marker --- */
170 static const trace_opt tropt
[] = {
171 { 'x', T_TX
, "transport layer" },
172 { 's', T_TXSYS
, "low-level transport" },
173 { 'A', T_ALL
, "all of the above" },
178 i
= mdwopt(argc
, argv
, "hvu" "t:c:f:" T("T:"), opt
, 0, 0, 0);
184 /* --- Standard help options --- */
196 /* --- Transport configuration stuff --- */
208 /* --- Tracing --- */
212 trace_level(traceopt(tropt
, optarg
, tracing(), 0));
224 if ((f
& f_bogus
) || optind
> argc
- 1) {
229 rc
= rx_runfile(argv
[optind
],
230 argc
- optind
- 1, (const char *const *)argv
+ optind
+ 1);
231 return (rc ? EXIT_FAILURE
: 0);
234 /*----- That's all, folks -------------------------------------------------*/