3 * $Id: sw.c,v 1.1 1999/06/02 16:53:33 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.1 1999/06/02 16:53:33 mdw
37 /*----- Header files ------------------------------------------------------*/
50 #include <mLib/alloc.h>
51 #include <mLib/dstr.h>
53 #include <mLib/mdwopt.h>
54 #include <mLib/quis.h>
55 #include <mLib/report.h>
66 /*----- Static variables --------------------------------------------------*/
68 static cmd *cmds = CMD_LINK;
70 /*----- Global option variables -------------------------------------------*
72 * It'd be nicer if these could be parsed by the build commands, but alas
73 * this is not to be. Consider `sw configure --arch=i386-linux
74 * --with-diffutils': how is the program to know which options are for it and
75 * which are for the remote one? The `configure' command is important,
76 * because it does some hairy stuff under the covers (inserting magical
77 * options, and running `../configure'), so I can't just require `sw run
78 * configure'. Requiring the user to always put in a `--' to separate the
79 * two lots of options is horrific. So they get picked up at the main
80 * program and stuffed into global variables.
82 * On the other hand, there is the advantage that `--output' options can be
83 * put in an environment variable here.
86 const char *opt_output = 0;
87 const char *opt_arch = 0;
88 unsigned int opt_flags;
90 /*----- Helpful GNUy message routines -------------------------------------*/
92 /* --- @version@ --- */
94 static void version(FILE *fp)
96 fprintf(fp, "%s v. " VERSION "\n", QUIS);
101 static void usage(FILE *fp)
103 fprintf(fp, "Usage: %s [-fbi] [-a arch,...] [-o style] command [args]\n",
109 static void help(FILE *fp, int full)
116 Performs various handy jobs with multiple-architecture builds.\n\
118 There are some options which affect a few of the available commands:\n\
120 -a, --arch=ARCH,... Only build on the named architectures.\n\
121 -b, --beep Beep when the build is complete.\n\
122 -i, --install Mark architectures as done when build succeeds.\n\
123 -f, --force Run build commands on installed architectures.\n\
124 -o, --output=STYLE Display output in a particular style. Use style\n\
125 `help' for a list.\n\
129 fputs("The various commands provided are:\n\n", fp);
130 for (p = cmds; p; p = p->next) {
135 "`%s' is an [mdw] production, brought to you in association with the\n\
136 European Bioinformatics Institute.\n", QUIS);
138 fputs("The various commands, in summary:\n\n", fp);
139 for (p = cmds; p; p = p->next) {
140 size_t sz = strcspn(p->help, "\n\t");
141 fwrite(p->help, 1, sz, fp);
145 "\nType `%s --help-full' for complete information. There's a lot of it!\n",
150 /*----- Main code ---------------------------------------------------------*/
154 * Arguments: @int argc@ = number of command line arguments
155 * @char *argv[]@ = array of command line strings
157 * Returns: Zero on success, nonzero on failure.
159 * Use: Main program. Parses some trivial arguments out, and
160 * dispatches control to one of the subprogram handlers.
163 int main(int argc, char *argv[])
171 /* --- Initialize the support library --- */
176 /* --- Parse command line flags --- */
179 static struct option opt[] = {
181 /* --- Standard GNUy help options --- */
183 { "help", 0, 0, 'h' },
184 { "help-full", 0, 0, 'H' },
185 { "version", 0, 0, 'v' },
186 { "usage", 0, 0, 'u' },
188 /* --- Build options --- *
192 { "arch", OPTF_ARGREQ, 0, 'a' },
193 { "force", 0, 0, 'f' },
194 { "install", 0, 0, 'i' },
195 { "output", OPTF_ARGREQ, 0, 'o' },
196 { "beep", 0, 0, 'b' },
198 /* --- Internal-use-only magical options --- *
200 * You get what you deserve if you use this.
203 { "me", OPTF_ARGREQ, 0, '=' },
204 { "remote", OPTF_ARGREQ, 0, '!' },
206 /* --- Termination marker --- */
210 int i = mdwopt(argc, argv, "+hHvu a:bfio:", opt, 0, 0, gFlag_envVar);
216 /* --- GNUy help --- */
231 /* --- Build options --- */
237 opt_flags |= optFlag_force;
240 opt_flags |= optFlag_beep;
243 opt_flags |= optFlag_install;
249 /* --- Magical options for internal use --- */
255 swrsh_remote(optarg);
258 /* --- The user screwed up --- */
266 if (f & f_bogus || argc == optind) {
271 /* --- Pick up the operation name --- */
279 const char *which = argv[0];
280 size_t sz = strlen(which);
282 for (p = cmds; p; p = p->next) {
283 if (strncmp(which, p->name, sz) == 0) {
284 if (p->name[sz] == 0) {
288 die(1, "ambiguous command name `%s'", which);
294 die(1, "unknown command name `%s'", which);
295 signal(SIGPIPE, SIG_IGN);
297 return (chosen->cmd(argc, argv));
298 CATCH switch (exc_type) {
300 die(1, "not enough memory");
308 /*----- That's all, folks -------------------------------------------------*/