3 * $Id: main.c,v 1.1 2002/01/25 19:34:45 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.1 2002/01/25 19:34:45 mdw
37 /*----- Header files ------------------------------------------------------*/
48 #include <mLib/alloc.h>
49 #include <mLib/mdwopt.h>
50 #include <mLib/quis.h>
51 #include <mLib/report.h>
52 #include <mLib/trace.h>
57 #include "tx-serial-unix.h"
59 /*----- Shutdown stuff ----------------------------------------------------*/
61 static int sigtab
[] = { SIGINT
, SIGQUIT
, SIGTERM
, SIGHUP
, -1 };
63 static void tidy(void)
68 static void sigtidy(int sig
)
75 /*----- Help functions ----------------------------------------------------*/
77 static void usage(FILE *fp
)
79 pquis(fp
, "Usage: $ [-t TRANSPORT] [-f FILE] [-c CONFIG] SCRIPT [ARG]\n");
82 static void version(FILE *fp
)
84 pquis(fp
, "$, version " VERSION
"\n");
87 static void help(FILE *fp
)
95 -h, --help Print this help message.\n\
96 -v, --version Show the version number.\n\
97 -u, --usage Show terse usage summary.\n\
99 -t, --transport=NAME Use transport type NAME.\n\
100 -f, --tx-file=FILE Communicate using the named FILE.\n\
101 -c, --tx-config=CONFIG Use CONFIG as transport configuration.\n\
106 /*----- Main code ---------------------------------------------------------*/
108 int main(int argc
, char *argv
[])
118 for (i
= 0; sigtab
[i
] >= 0; i
++)
119 signal(sigtab
[i
], sigtidy
);
123 trace_on(stderr
, 0u);
124 if ((txname
= getenv("JOGTX")) != 0)
127 txname
= txlist
->name
;
130 static const struct option opt
[] = {
132 /* --- Standard help options --- */
134 { "help", 0, 0, 'h' },
135 { "version", 0, 0, 'v' },
136 { "usage", 0, 0, 'u' },
138 /* --- Transport configuration stuff --- */
140 { "transport", OPTF_ARGREQ
, 0, 't' },
141 { "transport-config",
142 OPTF_ARGREQ
, 0, 'c' },
143 { "tx-config", OPTF_ARGREQ
, 0, 'c' },
144 { "txconfig", OPTF_ARGREQ
, 0, 'c' },
145 { "config", OPTF_ARGREQ
, 0, 'c' },
147 OPTF_ARGREQ
, 0, 'f' },
148 { "tx-file", OPTF_ARGREQ
, 0, 'f' },
149 { "txfile", OPTF_ARGREQ
, 0, 'f' },
150 { "file", OPTF_ARGREQ
, 0, 'f' },
152 /* --- End marker --- */
157 i
= mdwopt(argc
, argv
, "hvut:c:f:", opt
, 0, 0, 0);
163 /* --- Standard help options --- */
175 /* --- Transport configuration stuff --- */
195 if ((f
& f_bogus
) || (optind
!= argc
- 1 && optind
!= argc
- 2)) {
200 rc
= rx_runfile(argv
[optind
],
201 argc
- optind
- 1, (const char *const *)argv
+ optind
+ 1);
202 return (rc ? EXIT_FAILURE
: 0);
205 /*----- That's all, folks -------------------------------------------------*/