3 * $Id: sw.c,v 1.3 1999/09/10 15:27:32 mdw Exp $
5 * Main driver code for sw-tools
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of sw-tools.
14 * sw-tools 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 * sw-tools 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 sw-tools; 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.3 1999/09/10 15:27:32 mdw
33 * Include `%'-escape substitution.
35 * Revision 1.2 1999/07/16 12:50:43 mdw
36 * Replace deprecated `mdwopt' flag name with new version.
38 * Revision 1.1.1.1 1999/06/02 16:53:33 mdw
43 /*----- Header files ------------------------------------------------------*/
56 #include <mLib/alloc.h>
57 #include <mLib/dstr.h>
59 #include <mLib/mdwopt.h>
60 #include <mLib/quis.h>
61 #include <mLib/report.h>
72 /*----- Static variables --------------------------------------------------*/
74 static cmd
*cmds
= CMD_LINK
;
76 /*----- Global option variables -------------------------------------------*
78 * It'd be nicer if these could be parsed by the build commands, but alas
79 * this is not to be. Consider `sw configure --arch=i386-linux
80 * --with-diffutils': how is the program to know which options are for it and
81 * which are for the remote one? The `configure' command is important,
82 * because it does some hairy stuff under the covers (inserting magical
83 * options, and running `../configure'), so I can't just require `sw run
84 * configure'. Requiring the user to always put in a `--' to separate the
85 * two lots of options is horrific. So they get picked up at the main
86 * program and stuffed into global variables.
88 * On the other hand, there is the advantage that `--output' options can be
89 * put in an environment variable here.
92 const char *opt_output
= 0;
93 const char *opt_arch
= 0;
94 unsigned int opt_flags
= optFlag_percent
;
96 /*----- Helpful GNUy message routines -------------------------------------*/
98 /* --- @version@ --- */
100 static void version(FILE *fp
)
102 fprintf(fp
, "%s v. " VERSION
"\n", QUIS
);
105 /* --- @usage@ --- */
107 static void usage(FILE *fp
)
109 fprintf(fp
, "Usage: %s [-fbip] [-a arch,...] [-o style] command [args]\n",
115 static void help(FILE *fp
, int full
)
122 Performs various handy jobs with multiple-architecture builds.\n\
124 There are some options which affect a few of the available commands:\n\
126 -a, --arch=ARCH,... Only build on the named architectures.\n\
127 -b, --beep Beep when the build is complete.\n\
128 -i, --install Mark architectures as done when build succeeds.\n\
129 -f, --force Run build commands on installed architectures.\n\
130 -p, --percent Enable `%'-escapes in build command arguments.\n\
131 -o, --output=STYLE Display output in a particular style. Use style\n\
132 `help' for a list.\n\
136 fputs("The various commands provided are:\n\n", fp
);
137 for (p
= cmds
; p
; p
= p
->next
) {
142 "`%s' is an [mdw] production, brought to you in association with the\n\
143 European Bioinformatics Institute.\n", QUIS
);
145 fputs("The various commands, in summary:\n\n", fp
);
146 for (p
= cmds
; p
; p
= p
->next
) {
147 size_t sz
= strcspn(p
->help
, "\n\t");
148 fwrite(p
->help
, 1, sz
, fp
);
152 "\nType `%s --help-full' for complete information. There's a lot of it!\n",
157 /*----- Main code ---------------------------------------------------------*/
161 * Arguments: @int argc@ = number of command line arguments
162 * @char *argv[]@ = array of command line strings
164 * Returns: Zero on success, nonzero on failure.
166 * Use: Main program. Parses some trivial arguments out, and
167 * dispatches control to one of the subprogram handlers.
170 int main(int argc
, char *argv
[])
178 /* --- Initialize the support library --- */
183 /* --- Parse command line flags --- */
186 static struct option opt
[] = {
188 /* --- Standard GNUy help options --- */
190 { "help", 0, 0, 'h' },
191 { "help-full", 0, 0, 'H' },
192 { "version", 0, 0, 'v' },
193 { "usage", 0, 0, 'u' },
195 /* --- Build options --- *
199 { "arch", OPTF_ARGREQ
, 0, 'a' },
200 { "force", 0, 0, 'f' },
201 { "install", 0, 0, 'i' },
202 { "output", OPTF_ARGREQ
, 0, 'o' },
203 { "beep", OPTF_NEGATE
, 0, 'b' },
204 { "percent", OPTF_NEGATE
, 0, 'p' },
205 { "escape", OPTF_NEGATE
, 0, 'p' },
207 /* --- Internal-use-only magical options --- *
209 * You get what you deserve if you use this.
212 { "me", OPTF_ARGREQ
, 0, '=' },
213 { "remote", OPTF_ARGREQ
, 0, '!' },
215 /* --- Termination marker --- */
219 int i
= mdwopt(argc
, argv
, "+hHvu a:b+p+fio:", opt
, 0, 0,
220 OPTF_ENVVAR
| OPTF_NEGATION
);
226 /* --- GNUy help --- */
241 /* --- Build options --- */
247 opt_flags
|= optFlag_force
;
250 opt_flags
|= optFlag_beep
;
252 case 'b' | OPTF_NEGATED
:
253 opt_flags
&= ~optFlag_beep
;
256 opt_flags
|= optFlag_percent
;
258 case 'p' | OPTF_NEGATED
:
259 opt_flags
&= ~optFlag_percent
;
262 opt_flags
|= optFlag_install
;
268 /* --- Magical options for internal use --- */
274 swrsh_remote(optarg
);
277 /* --- The user screwed up --- */
285 if (f
& f_bogus
|| argc
== optind
) {
290 /* --- Pick up the operation name --- */
298 const char *which
= argv
[0];
299 size_t sz
= strlen(which
);
301 for (p
= cmds
; p
; p
= p
->next
) {
302 if (strncmp(which
, p
->name
, sz
) == 0) {
303 if (p
->name
[sz
] == 0) {
307 die(1, "ambiguous command name `%s'", which
);
313 die(1, "unknown command name `%s'", which
);
314 signal(SIGPIPE
, SIG_IGN
);
316 return (chosen
->cmd(argc
, argv
));
317 CATCH
switch (exc_type
) {
319 die(1, "not enough memory");
327 /*----- That's all, folks -------------------------------------------------*/