3 * $Id: sw.c,v 1.2 1999/07/16 12:50:43 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.2 1999/07/16 12:50:43 mdw
33 * Replace deprecated `mdwopt' flag name with new version.
35 * Revision 1.1.1.1 1999/06/02 16:53:33 mdw
40 /*----- Header files ------------------------------------------------------*/
53 #include <mLib/alloc.h>
54 #include <mLib/dstr.h>
56 #include <mLib/mdwopt.h>
57 #include <mLib/quis.h>
58 #include <mLib/report.h>
69 /*----- Static variables --------------------------------------------------*/
71 static cmd *cmds = CMD_LINK;
73 /*----- Global option variables -------------------------------------------*
75 * It'd be nicer if these could be parsed by the build commands, but alas
76 * this is not to be. Consider `sw configure --arch=i386-linux
77 * --with-diffutils': how is the program to know which options are for it and
78 * which are for the remote one? The `configure' command is important,
79 * because it does some hairy stuff under the covers (inserting magical
80 * options, and running `../configure'), so I can't just require `sw run
81 * configure'. Requiring the user to always put in a `--' to separate the
82 * two lots of options is horrific. So they get picked up at the main
83 * program and stuffed into global variables.
85 * On the other hand, there is the advantage that `--output' options can be
86 * put in an environment variable here.
89 const char *opt_output = 0;
90 const char *opt_arch = 0;
91 unsigned int opt_flags;
93 /*----- Helpful GNUy message routines -------------------------------------*/
95 /* --- @version@ --- */
97 static void version(FILE *fp)
99 fprintf(fp, "%s v. " VERSION "\n", QUIS);
102 /* --- @usage@ --- */
104 static void usage(FILE *fp)
106 fprintf(fp, "Usage: %s [-fbi] [-a arch,...] [-o style] command [args]\n",
112 static void help(FILE *fp, int full)
119 Performs various handy jobs with multiple-architecture builds.\n\
121 There are some options which affect a few of the available commands:\n\
123 -a, --arch=ARCH,... Only build on the named architectures.\n\
124 -b, --beep Beep when the build is complete.\n\
125 -i, --install Mark architectures as done when build succeeds.\n\
126 -f, --force Run build commands on installed architectures.\n\
127 -o, --output=STYLE Display output in a particular style. Use style\n\
128 `help' for a list.\n\
132 fputs("The various commands provided are:\n\n", fp);
133 for (p = cmds; p; p = p->next) {
138 "`%s' is an [mdw] production, brought to you in association with the\n\
139 European Bioinformatics Institute.\n", QUIS);
141 fputs("The various commands, in summary:\n\n", fp);
142 for (p = cmds; p; p = p->next) {
143 size_t sz = strcspn(p->help, "\n\t");
144 fwrite(p->help, 1, sz, fp);
148 "\nType `%s --help-full' for complete information. There's a lot of it!\n",
153 /*----- Main code ---------------------------------------------------------*/
157 * Arguments: @int argc@ = number of command line arguments
158 * @char *argv[]@ = array of command line strings
160 * Returns: Zero on success, nonzero on failure.
162 * Use: Main program. Parses some trivial arguments out, and
163 * dispatches control to one of the subprogram handlers.
166 int main(int argc, char *argv[])
174 /* --- Initialize the support library --- */
179 /* --- Parse command line flags --- */
182 static struct option opt[] = {
184 /* --- Standard GNUy help options --- */
186 { "help", 0, 0, 'h' },
187 { "help-full", 0, 0, 'H' },
188 { "version", 0, 0, 'v' },
189 { "usage", 0, 0, 'u' },
191 /* --- Build options --- *
195 { "arch", OPTF_ARGREQ, 0, 'a' },
196 { "force", 0, 0, 'f' },
197 { "install", 0, 0, 'i' },
198 { "output", OPTF_ARGREQ, 0, 'o' },
199 { "beep", 0, 0, 'b' },
201 /* --- Internal-use-only magical options --- *
203 * You get what you deserve if you use this.
206 { "me", OPTF_ARGREQ, 0, '=' },
207 { "remote", OPTF_ARGREQ, 0, '!' },
209 /* --- Termination marker --- */
213 int i = mdwopt(argc, argv, "+hHvu a:bfio:", opt, 0, 0, OPTF_ENVVAR);
219 /* --- GNUy help --- */
234 /* --- Build options --- */
240 opt_flags |= optFlag_force;
243 opt_flags |= optFlag_beep;
246 opt_flags |= optFlag_install;
252 /* --- Magical options for internal use --- */
258 swrsh_remote(optarg);
261 /* --- The user screwed up --- */
269 if (f & f_bogus || argc == optind) {
274 /* --- Pick up the operation name --- */
282 const char *which = argv[0];
283 size_t sz = strlen(which);
285 for (p = cmds; p; p = p->next) {
286 if (strncmp(which, p->name, sz) == 0) {
287 if (p->name[sz] == 0) {
291 die(1, "ambiguous command name `%s'", which);
297 die(1, "unknown command name `%s'", which);
298 signal(SIGPIPE, SIG_IGN);
300 return (chosen->cmd(argc, argv));
301 CATCH switch (exc_type) {
303 die(1, "not enough memory");
311 /*----- That's all, folks -------------------------------------------------*/