5 * (c) 2020 Mark Wooding
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Runlisp, a tool for invoking Common Lisp scripts.
12 * Runlisp is free software: you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 3 of the License, or (at your
15 * option) any later version.
17 * Runlisp is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License
23 * along with Runlisp. If not, see <https://www.gnu.org/licenses/>.
26 /*----- Header files ------------------------------------------------------*/
45 /*----- Common Lisp runes -------------------------------------------------*/
47 /* A common preamble rune to do the necessary things.
49 * We need to ensure that `asdf' (and therefore `uiop') is loaded. And we
50 * should arrange for `:runlisp-script' to find its way into the `*features*'
51 * list so that scripts can notice that they're being invoked from the
52 * command line rather than loaded into a resident session, and actually do
55 #define COMMON_PRELUDE_RUNE \
57 "(setf *load-verbose* nil *compile-verbose* nil) " \
58 "(require \"asdf\") " \
59 "(funcall (intern \"REGISTER-IMMUTABLE-SYSTEM\" " \
60 "(find-package \"ASDF\")) " \
62 "(set-dispatch-macro-character " \
64 "(lambda (#1=#:stream #2=#:char #3=#:arg) " \
65 "(declare (ignore #2# #3#)) " \
66 "(values (read-line #1#)))) " \
67 "(pushnew :runlisp-script *features*))"
69 /* Get `uiop' to re-check the command-line arguments following an image
72 #define IMAGE_RESTORE_RUNE \
73 "(uiop:call-image-restore-hook)"
75 /* Some Lisps leave crud in the `COMMON-LISP-USER' package. Clear it out. */
76 #define CLEAR_CL_USER_RUNE \
77 "(let ((#4=#:pkg (find-package \"COMMON-LISP-USER\"))) " \
78 "(with-package-iterator (#5=#:next #4# :internal) " \
79 "(loop (multiple-value-bind (#6=#:anyp #7=#:sym #8=#:how) " \
81 "(declare (ignore #8#)) " \
82 "(unless #6# (return)) " \
83 "(unintern #7# #4#)))))"
85 /*----- The Lisp implementation table -------------------------------------*/
87 /* The systems, in decreasing order of (not quite my personal) preference.
88 * This list is used to initialize various tables and constants.
90 #define LISP_SYSTEMS(_) \
99 #define DEFSYS(sys) sys##_INDEX,
106 #define DEFFLAG(sys) sys##_FLAG = 1 << sys##_INDEX,
107 LISP_SYSTEMS(DEFFLAG)
110 #define SETFLAG(sys) | sys##_FLAG
111 LISP_SYSTEMS(SETFLAG)
118 #define DECLENTRY(sys) \
119 static void run_##sys(struct argstate *, const char *);
120 LISP_SYSTEMS(DECLENTRY)
123 static const struct systab {
126 void (*run)(struct argstate *, const char *);
128 #define SYSENTRY(sys) { #sys, sys##_FLAG, run_##sys },
129 LISP_SYSTEMS(SYSENTRY)
133 static const struct systab *find_system(const char *name)
135 const struct systab *sys;
138 for (i = 0; i < NSYS; i++) {
140 if (STRCMP(name, ==, sys->name)) return (sys);
142 lose("unknown Lisp system `%s'", name);
145 static void lisp_quote_string(struct dstr *d, const char *p)
150 n = strcspn(p, "\"\\");
151 if (n) { dstr_putm(d, p, n); p += n; }
153 dstr_putc(d, '\\'); dstr_putc(d, *p++);
158 static const char *expand_rune(struct dstr *d, const char *rune, ...)
160 const struct argv *av;
166 n = strcspn(rune, "%");
167 if (n) { dstr_putm(d, rune, n); rune += n; }
170 case '%': dstr_putc(d, '%'); break;
171 case 'e': lisp_quote_string(d, va_arg(ap, const char *)); break;
173 av = va_arg(ap, const struct argv *);
174 for (i = 0; i < av->n; i++) {
175 if (i) dstr_putc(d, ' ');
177 lisp_quote_string(d, av->v[i]);
181 default: lose("*** BUG unknown expansion `%%%c'", *rune);
189 /*----- Argument processing -----------------------------------------------*/
192 const struct systab *sys[NSYS];
196 #define SYSLIST_INIT { { 0 }, 0, 0 }
207 struct syslist allow, pref;
210 #define ARGSTATE_INIT { 0, 1, 0, SYSLIST_INIT, SYSLIST_INIT, ARGV_INIT }
212 /*----- Running programs --------------------------------------------------*/
215 static int file_exists_p(const struct argstate *arg, const char *path,
220 if (stat(path, &st)) {
221 if (arg && arg->verbose > 2) moan("file `%s' not found", path);
223 } else if (!(S_ISREG(st.st_mode))) {
224 if (arg && arg->verbose > 2) moan("`%s' is not a regular file", path);
226 } else if ((f&FEF_EXEC) && access(path, X_OK)) {
227 if (arg && arg->verbose > 2) moan("file `%s' is not executable", path);
230 if (arg && arg->verbose > 2) moan("found file `%s'", path);
235 static int found_in_path_p(const struct argstate *arg, const char *prog)
237 struct dstr p = DSTR_INIT, d = DSTR_INIT;
240 size_t n, avail, proglen;
243 if (strchr(prog, '/')) return (file_exists_p(arg, prog, 0));
244 path = getenv("PATH");
251 avail = p.sz - p.len;
252 n = confstr(_CS_PATH, p.p + p.len, avail);
253 if (avail > n) { i++; assert(i < 2); dstr_ensure(&p, n); goto again; }
256 q = p.p; proglen = strlen(prog);
260 if (q[n]) dstr_putm(&d, q, n);
261 else dstr_putc(&d, '.');
263 dstr_putm(&d, prog, proglen);
265 if (file_exists_p(arg, d.p, FEF_EXEC)) {
266 if (arg->verbose == 2) moan("found program `%s'", d.p);
269 q += n; if (!*q) break; else q++;
274 static void try_exec(const struct argstate *arg, struct argv *av)
276 struct dstr d = DSTR_INIT;
279 assert(av->n); argv_appendz(av);
280 if (arg->verbose > 1) {
281 for (i = 0; i < av->n; i++) {
282 if (i) { dstr_putc(&d, ','); dstr_putc(&d, ' '); }
284 lisp_quote_string(&d, av->v[i]);
288 moan("trying %s...", d.p);
291 { if (found_in_path_p(arg, av->v[0])) exit(0); }
293 execvp(av->v[0], (/*unconst*/ char **)av->v);
295 lose("failed to exec `%s': %s", av->v[0], strerror(errno));
297 if (arg->verbose > 1) moan("`%s' not found", av->v[0]);
301 static const char *getenv_or_default(const char *var, const char *dflt)
302 { const char *p = getenv(var); return (p ? p : dflt); }
304 /*----- Invoking Lisp systems ---------------------------------------------*/
306 /* Steel Bank Common Lisp. */
308 static void run_sbcl(struct argstate *arg, const char *script)
310 struct dstr d = DSTR_INIT;
312 argv_prependl(&arg->av, "--script", script, END);
314 dstr_puts(&d, arg->imagedir);
316 dstr_puts(&d, "sbcl+asdf.core");
317 if (!(arg->f&F_NODUMP) && file_exists_p(arg, d.p, 0))
318 argv_prependl(&arg->av,
320 "--eval", IMAGE_RESTORE_RUNE,
323 argv_prependl(&arg->av, "--eval", COMMON_PRELUDE_RUNE, END);
325 argv_prependl(&arg->av, getenv_or_default("SBCL", "sbcl"),
328 try_exec(arg, &arg->av);
332 /* Clozure Common Lisp. */
334 #define CCL_QUIT_RUNE \
337 static void run_ccl(struct argstate *arg, const char *script)
339 struct dstr d = DSTR_INIT;
341 argv_prependl(&arg->av, "-b", "-n", "-Q",
347 dstr_puts(&d, arg->imagedir);
349 dstr_puts(&d, "ccl+asdf.image");
350 if (!(arg->f&F_NODUMP) && file_exists_p(arg, d.p, 0))
351 argv_prependl(&arg->av, "-I", d.p, "-e", IMAGE_RESTORE_RUNE, END);
353 argv_prependl(&arg->av, "-e", COMMON_PRELUDE_RUNE, END);
355 argv_prepend(&arg->av, getenv_or_default("CCL", "ccl"));
356 try_exec(arg, &arg->av);
362 * CLisp causes much sadness. Superficially, it's the most sensible of all
363 * of the systems supported here: you just run `clisp SCRIPT -- ARGS ...' and
366 * The problems come when you want to do some preparatory work (e.g., load
367 * `asdf') and then run the script. There's a `-x' option to evaluate some
368 * Lisp code, but it has three major deficiencies.
370 * * It insists on printing the values of the forms it evaluates. It
371 * prints a blank line even if the form goes out of its way to produce no
372 * values at all. So the whole thing has to be a single top-level form
373 * which quits the Lisp rather than returning.
375 * * For some idiotic reason, you can have /either/ `-x' forms /or/ a
376 * script, but not both. So we have to include the `load' here
377 * explicitly. I suppose that was inevitable because we have to inhibit
378 * printing of the result forms, but it's still a separate source of
381 * * The icing on the cake: the `-x' forms are collectively concatenated --
382 * without spaces! -- and used to build a string stream, which is then
383 * assigned over the top of `*standard-input*', making the original stdin
384 * somewhat fiddly to track down.
386 * There's an `-i' option which will load a file without any of this
387 * stupidity, but nothing analogous for immediate expressions.
390 #define CLISP_COMMON_STARTUP_RUNES \
391 "(setf *standard-input* (ext:make-stream :input)) " \
392 "(load \"%e\" :verbose nil :print nil) " \
395 #define CLISP_STARTUP_RUNE \
397 COMMON_PRELUDE_RUNE " " \
398 CLISP_COMMON_STARTUP_RUNES ")"
400 #define CLISP_STARTUP_IMAGE_RUNE \
402 IMAGE_RESTORE_RUNE " " \
403 CLISP_COMMON_STARTUP_RUNES ")"
405 static void run_clisp(struct argstate *arg, const char *script)
407 struct dstr d = DSTR_INIT, dd = DSTR_INIT;
409 dstr_puts(&d, arg->imagedir);
411 dstr_puts(&d, "clisp+asdf.mem");
412 if (!(arg->f&F_NODUMP) && file_exists_p(arg, d.p, 0))
413 argv_prependl(&arg->av, "-M", d.p, "-q",
414 "-x", expand_rune(&dd, CLISP_STARTUP_IMAGE_RUNE, script),
418 argv_prependl(&arg->av, "-norc", "-q",
419 "-x", expand_rune(&dd, CLISP_STARTUP_RUNE, script),
423 argv_prepend(&arg->av, getenv_or_default("CLISP", "clisp"));
424 try_exec(arg, &arg->av);
431 /* Embeddable Common Lisp. *
433 * ECL is changing its command-line option syntax in version 16. I have no
434 * idea why they think the result can ever be worth the pain of a transition.
443 #define ECL_STARTUP_RUNE \
445 COMMON_PRELUDE_RUNE " " \
446 CLEAR_CL_USER_RUNE ")"
448 static void run_ecl(struct argstate *arg, const char *script)
450 struct dstr d = DSTR_INIT;
452 dstr_puts(&d, arg->imagedir);
454 dstr_puts(&d, "ecl+asdf");
455 if (!(arg->f&F_NODUMP) && file_exists_p(arg, d.p, FEF_EXEC)) {
456 argv_prependl(&arg->av, "-s", script, "--", END);
457 argv_prependl(&arg->av, d.p, END);
459 argv_prependl(&arg->av, ECLOPT "shell", script, "--", END);
460 argv_prependl(&arg->av, getenv_or_default("ECL", "ecl"), ECLOPT "norc",
461 ECLOPT "eval", ECL_STARTUP_RUNE,
464 try_exec(arg, &arg->av);
467 /* Carnegie--Mellon University Common Lisp. */
469 #define CMUCL_STARTUP_RUNE \
471 "(setf ext:*require-verbose* nil) " \
472 COMMON_PRELUDE_RUNE ")"
473 #define CMUCL_QUIT_RUNE \
476 static void run_cmucl(struct argstate *arg, const char *script)
478 struct dstr d = DSTR_INIT;
480 argv_prependl(&arg->av,
482 "-eval", CMUCL_QUIT_RUNE,
486 dstr_puts(&d, arg->imagedir);
488 dstr_puts(&d, "cmucl+asdf.core");
489 if (!(arg->f&F_NODUMP) && file_exists_p(arg, d.p, 0))
490 argv_prependl(&arg->av, "-core", d.p, "-eval", IMAGE_RESTORE_RUNE, END);
492 argv_prependl(&arg->av, "-batch", "-noinit", "-nositeinit", "-quiet",
493 "-eval", CMUCL_STARTUP_RUNE,
496 argv_prepend(&arg->av, getenv_or_default("CMUCL", "cmucl"));
497 try_exec(arg, &arg->av);
501 /* Armed Bear Common Lisp. *
503 * CLisp made a worthy effort, but ABCL still manages to take the price.
505 * * ABCL manages to avoid touching the `stderr' stream at all, ever. Its
506 * startup machinery finds `stdout' (as `java.lang.System.out'), wraps it
507 * up in a Lisp stream, and uses the result as `*standard-output*' and
508 * `*error-output*' (and a goodly number of other things too). So we
509 * must manufacture a working `stderr' the hard way.
511 * * There doesn't appear to be any easy way to prevent toplevel errors
512 * from invoking the interactive debugger. For extra fun, the debugger
513 * reads from `stdin' by default, so an input file which somehow manages
514 * to break the script can then take over its brain by providing Lisp
515 * forms for the debugger to evaluate.
518 #define ABCL_STARTUP_RUNE \
519 "(let ((#9=#:script \"%e\")) " \
520 COMMON_PRELUDE_RUNE " " \
521 CLEAR_CL_USER_RUNE " " \
523 /* Replace the broken `*error-output*' stream with a working \
524 * copy of `stderr'. \
526 "(setf *error-output* " \
527 "(java:jnew \"org.armedbear.lisp.Stream\" " \
528 "'sys::system-stream " \
529 "(java:jfield \"java.lang.System\" \"err\") " \
533 /* Trap errors signalled by the script and arrange for them \
534 * to actually kill the process rather than ending up in the \
535 * interactive debugger. \
537 "(handler-case (load #9# :verbose nil :print nil) " \
539 "(format *error-output* \"~A (unhandled error): ~A~%%\" " \
541 "(ext:quit :status 255))))"
543 static void run_abcl(struct argstate *arg, const char *script)
545 struct dstr d = DSTR_INIT;
547 argv_prependl(&arg->av, getenv_or_default("ABCL", "abcl"),
548 "--batch", "--noinform", "--noinit", "--nosystem",
549 "--eval", expand_rune(&d, ABCL_STARTUP_RUNE, script),
552 try_exec(arg, &arg->av);
556 /*----- Main code ---------------------------------------------------------*/
558 static void version(FILE *fp)
559 { fprintf(fp, "%s, version %s\n", progname, PACKAGE_VERSION); }
561 static void usage(FILE *fp)
563 fprintf(fp, "usage: %s [-CDEnqv] [-I IMAGEDIR] "
564 "[-L SYS,SYS,...] [-P SYS,SYS,...]\n"
565 "\t[--] SCRIPT [ARGUMENTS ...] |\n"
566 "\t[-e EXPR] [-p EXPR] [-l FILE] [--] [ARGUMENTS ...]\n",
570 static void help(FILE *fp)
572 version(fp); fputc('\n', fp); usage(fp);
575 --help Show this help text and exit successfully.\n\
576 --version Show the version number and exit successfully.\n\
577 -C Clear the list of preferred Lisp systems.\n\
578 -D Run system Lisp images, rather than custom images.\n\
579 -E Don't read embedded options from the script.\n\
580 -I IMAGEDIR Look for custom images in IMAGEDIR rather than\n\
582 -L SYS,SYS,... Only use the listed Lisp systems.the script.\n\
583 -P SYS,SYS,... Prefer the listed Lisp systems.\n\
584 -e EXPR Evaluate EXPR (can be repeated).\n\
585 -l FILE Load FILE (can be repeated).\n\
586 -n Don't actually run the script (useful with `-v')\n\
587 -p EXPR Print (`prin1') EXPR (can be repeated).\n\
588 -q Don't print warning messages.\n\
589 -v Print informational messages (repeat for even more).\n",
593 static void push_eval_op(struct argstate *arg, char op, const char *val)
599 moan("must use `-e', `-p', or `-l' on command line");
606 p[0] = op; memcpy(p + 1, val, n);
607 argv_append(&arg->av, p);
610 /* Parse a comma-separated list of system names SPEC, and add the named
613 static void parse_syslist(const char *spec, const struct argstate *arg,
614 struct syslist *list, const char *what)
616 char *copy = xstrdup(spec), *p = copy, *q;
617 const struct systab *sys;
622 if (p[n]) q = p + n + 1;
624 p[n] = 0; sys = find_system(p);
625 if (list->f&sys->f) {
626 if (arg->verbose > 0)
627 moan("ignoring duplicate system `%s' in %s list", p, what);
629 list->sys[list->n++] = sys;
638 /* Parse a vector ARGS of command-line arguments. Update ARG with the
639 * results. NARG is the number of arguments, and *I_INOUT is the current
640 * index into the vector, to be updated on exit to identify the first
641 * non-option argument (or the end of the vector).
643 static void parse_arguments(struct argstate *arg, const char *const *args,
644 size_t nargs, size_t *i_inout)
650 if (*i_inout >= nargs) break;
652 if (STRCMP(o, ==, "--help")) { help(stdout); exit(0); }
653 else if (STRCMP(o, ==, "--version")) { version(stdout); exit(0); }
654 if (!*o || *o != '-' || !o[1]) break;
656 if (STRCMP(o, ==, "--")) break;
662 #define GETARG do { \
666 if (*i_inout >= nargs) goto noarg; \
667 a = args[(*i_inout)++]; \
671 case 'C': arg->pref.n = 0; arg->pref.f = 0; break;
672 case 'D': arg->f |= F_NODUMP; break;
673 case 'E': arg->f |= F_NOEMBED; break;
674 case 'e': GETARG; push_eval_op(arg, '!', a); break;
675 case 'p': GETARG; push_eval_op(arg, '?', a); break;
676 case 'l': GETARG; push_eval_op(arg, '<', a); break;
677 case 'n': arg->f |= F_NOACT; break;
678 case 'q': if (arg->verbose) arg->verbose--; break;
679 case 'v': arg->verbose++; break;
683 GETARG; arg->imagedir = xstrdup(a);
688 parse_syslist(a, arg, &arg->allow, "allowed");
693 parse_syslist(a, arg, &arg->pref, "preferred");
697 moan("unknown option `%c'", opt);
709 moan("missing argument for `-%c'", opt);
715 /* Parse a string P into words (destructively), and process them as
716 * command-line options, updating ARG. Non-option arguments are not
717 * permitted. If `SOSF_EMACS' is set in FLAGS, then ignore `-*- ... -*-'
718 * editor turds. If `SOSF_ENDOK' is set, then accept `--' and ignore
719 * whatever comes after; otherwise, reject all positional arguments.
721 #define SOSF_EMACS 1u
722 #define SOSF_ENDOK 2u
723 static void scan_options_from_string(char *p, struct argstate *arg,
725 const char *what, const char *file)
727 struct argv av = ARGV_INIT;
735 while (ISSPACE(*p)) p++;
737 if ((flags&SOSF_EMACS) && p[0] == '-' && p[1] == '*' && p[2] == '-') {
738 p = strstr(p + 3, "-*-");
739 if (!p) lose("unfinished local-variables list in %s `%s'", what, file);
742 if ((flags&SOSF_ENDOK) &&
743 p[0] == '-' && p[1] == '-' && (!p[2] || ISSPACE(p[2])))
745 argv_append(&av, p); q = p;
748 else if (f&f_escape) { *q++ = *p; f &= ~f_escape; }
749 else if (st && *p == st) st = 0;
750 else if (st != '\'' && *p == '\\') f |= f_escape;
751 else if (!st && (*p == '"' || *p == '\'')) st = *p;
752 else if (!st && ISSPACE(*p)) break;
759 if (f&f_escape) lose("unfinished escape in %s `%s'", what, file);
760 if (st) lose("unfinished `%c' string in %s `%s'", st, what, file);
763 i = 0; parse_arguments(arg, av.v, av.n, &i);
765 lose("positional argument `%s' in %s `%s'", av.v[i], what, file);
771 /* Read SCRIPT, and check for a `@RUNLISP:' marker in the second line. If
772 * there is one, parse options from it, and update ARG.
774 static void check_for_embedded_args(const char *script, struct argstate *arg)
776 struct dstr d = DSTR_INIT;
780 fp = fopen(script, "r");
781 if (!fp) lose("can't read script `%s': %s", script, strerror(errno));
783 if (dstr_readline(&d, fp)) goto end;
784 dstr_reset(&d); if (dstr_readline(&d, fp)) goto end;
786 p = strstr(d.p, "@RUNLISP:");
788 scan_options_from_string(p + 9, arg, SOSF_EMACS | SOSF_ENDOK,
789 "embedded options in script", script);
794 lose("error reading script `%s': %s", script, strerror(errno));
800 /* Read the file PATH (if it exists) and update ARG with the arguments parsed
801 * from it. Ignore blank lines and (Unix- or Lisp-style) comments.
803 static void read_config_file(const char *path, struct argstate *arg)
806 struct dstr d = DSTR_INIT;
809 fp = fopen(path, "r");
811 if (errno == ENOENT) {
812 if (arg->verbose > 2)
813 moan("ignoring nonexistent configuration file `%s'", path);
816 lose("failed to open configuration file `%s': %s",
817 path, strerror(errno));
819 if (arg->verbose > 1)
820 moan("reading configuration file `%s'", path);
823 if (dstr_readline(&d, fp)) break;
825 while (ISSPACE(*p)) p++;
826 if (!*p || *p == ';' || *p == '#') continue;
827 scan_options_from_string(p, arg, 0, "configuration file `%s'", path);
830 lose("invalid options in configuration file `%s'", path);
835 lose("error reading configuration file `%s': %s",
836 path, strerror(errno));
842 int main(int argc, char *argv[])
844 struct dstr d = DSTR_INIT;
845 const char *script, *p;
850 struct argstate arg = ARGSTATE_INIT;
852 /* Scan the command line. This gets low priority, since it's probably
853 * from the script shebang.
855 set_progname(argv[0]); i = 1;
856 parse_arguments(&arg, (const char *const *)argv, argc, &i);
858 if ((i >= argc && !arg.av.n) || (arg.f&F_BOGUS))
859 { usage(stderr); exit(255); }
861 /* Prepare the argument vector. Keep track of the number of arguments
862 * here: we'll need to refer to this later.
866 if (!(arg.f&F_NOEMBED)) check_for_embedded_args(script, &arg);
868 lose("invalid options in `%s' embedded option list", script);
870 script = getenv("RUNLISP_EVAL");
871 if (!script) script = DATADIR "/eval.lisp";
872 argv_append(&arg.av, "--");
874 argv_appendn(&arg.av, (const char *const *)argv + i, argc - i);
877 /* Find the user's home directory. (Believe them if they set something
880 home = getenv("HOME");
882 pw = getpwuid(getuid());
883 if (!pw) lose("can't find user in password database");
887 /* Check user configuration file `~/.runlisprc'. */
889 dstr_puts(&d, home); dstr_putc(&d, '/'); dstr_puts(&d, ".runlisprc");
890 read_config_file(d.p, &arg);
892 /* Check user configuration file `~/.config/runlisprc'. */
894 p = getenv("XDG_CONFIG_HOME");
898 { dstr_puts(&d, home); dstr_putc(&d, '/'); dstr_puts(&d, ".config"); }
899 dstr_putc(&d, '/'); dstr_puts(&d, "runlisprc");
900 read_config_file(d.p, &arg);
902 /* Finally, check the environment variables. */
903 p = getenv("RUNLISP_OPTIONS");
906 scan_options_from_string(t, &arg, 0,
907 "environment variable", "RUNLISP_OPTIONS");
911 lose("invalid options in environment variable `RUNLISP_OPTIONS'");
913 arg.imagedir = getenv("RUNLISP_IMAGEDIR");
914 if (!arg.imagedir) arg.imagedir = IMAGEDIR;
917 /* If no systems are listed as acceptable, try them all. */
920 moan("no explicitly allowed implementations: allowing all");
921 for (i = 0; i < NSYS; i++) arg.allow.sys[i] = &systab[i];
922 arg.allow.n = NSYS; arg.allow.f = (1u << NSYS) - 1;
925 /* Print what we're going to do. */
926 if (arg.verbose > 2) {
927 dstr_reset(&d); p = "";
928 for (i = 0; i < arg.allow.n; i++)
929 { dstr_puts(&d, p); p = ", "; dstr_puts(&d, arg.allow.sys[i]->name); }
930 dstr_putz(&d); moan("permitted Lisps: %s", d.p);
932 dstr_reset(&d); p = "";
933 for (i = 0; i < arg.pref.n; i++)
934 { dstr_puts(&d, p); p = ", "; dstr_puts(&d, arg.pref.sys[i]->name); }
935 dstr_putz(&d); moan("preferred Lisps: %s", d.p);
937 dstr_reset(&d); p = "";
938 for (i = 0; i < arg.pref.n; i++)
939 if (arg.pref.sys[i]->f&arg.allow.f)
940 { dstr_puts(&d, p); p = ", "; dstr_puts(&d, arg.pref.sys[i]->name); }
941 for (i = 0; i < arg.allow.n; i++)
942 if (!(arg.allow.sys[i]->f&arg.pref.f))
943 { dstr_puts(&d, p); p = ", "; dstr_puts(&d, arg.allow.sys[i]->name); }
944 moan("overall preference order: %s", d.p);
947 /* Inform `uiop' of the script name.
949 * As an aside, this is a terrible interface. It's too easy to forget to
950 * set it. (To illustrate this, `cl-launch -x' indeed forgets to set it.)
951 * If you're lucky, the script just thinks that its argument is `nil', in
952 * which case maybe it can use `*load-pathname*' as a fallback. If you're
953 * unlucky, your script was invoked (possibly indirectly) by another
954 * script, and now you've accidentally inherited the calling script's name.
956 * It would have been far better simply to repeat the script name as the
957 * first user argument, if nothing else had come readily to mind.
959 if (setenv("__CL_ARGV0", script, 1))
960 lose("failed to set script-name environment variable");
962 /* Work through the list of preferred Lisp systems, trying the ones which
965 for (i = 0; i < arg.pref.n; i++)
966 if (arg.pref.sys[i]->f&arg.allow.f) {
967 arg.av.o += arg.av.n - n; arg.av.v += arg.av.n - n; arg.av.n = n;
968 arg.pref.sys[i]->run(&arg, script);
971 /* That didn't work. Try the remaining allowed systems, in the given
974 for (i = 0; i < arg.allow.n; i++)
975 if (!(arg.allow.sys[i]->f&arg.pref.f)) {
976 arg.av.o += arg.av.n - n; arg.av.v += arg.av.n - n; arg.av.n = n;
977 arg.allow.sys[i]->run(&arg, script);
980 /* No joy. Give up. */
981 argv_release(&arg.av);
982 lose("no supported Lisp systems found");
985 /*----- That's all, folks -------------------------------------------------*/