This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Small addition to guile command line arguments?
- To: guile at sourceware dot cygnus dot com
- Subject: Small addition to guile command line arguments?
- From: Eric Moore <moore at chem dot cmu dot edu>
- Date: Sun, 16 Jan 2000 22:44:55 -0500 (EST)
I was just writing some scripts/programs in guile, and trying to break
them up into several files, so needed to set the load path. Since one
of the things I was working on was a cgi script, I couldn't use the
GUILE_LOAD_PATH environment variable, so as an alternative to adding
(set! %load-path (cons "directory" %load-path))
to the top of the file, I thought it might be nice if guile took a -L
command-line option to allow search directories to the load path at
runtime, which makes testing and the like a bit easier (for me)..
So if people think it's worth adding, I have a patch below. It's not
very elegant, but should do the trick, and is pretty much in keeping
with the manner shell switches are handled.
Index: libguile/script.c
===================================================================
RCS file: /cvs/guile/guile/guile-core/libguile/script.c,v
retrieving revision 1.24
diff -b -u -r1.24 script.c
--- script.c 1999/12/12 20:35:02 1.24
+++ script.c 2000/01/17 03:43:28
@@ -372,6 +372,7 @@
"remaining arguments as the value of (command-line).\n"
"\n"
" -l FILE load Scheme source code from FILE\n"
+ " -L DIRECTORY add DIRECTORY to the load path\n"
" -e FUNCTION after reading script, apply FUNCTION to\n"
" command line arguments\n"
" -ds do -s script at this point\n"
@@ -395,6 +396,9 @@
SCM_SYMBOL (sym_load_user_init, "load-user-init");
SCM_SYMBOL (sym_top_repl, "top-repl");
SCM_SYMBOL (sym_quit, "quit");
+SCM_SYMBOL (sym_load_path, "%load-path");
+SCM_SYMBOL (sym_set, "set!");
+SCM_SYMBOL (sym_cons, "cons");
/* Given an array of command-line switches, return a Scheme expression
@@ -491,6 +495,18 @@
break;
}
+ else if (! strcmp (argv[i], "-L"))
+ {
+ if (++i < argc)
+ tail = scm_cons (SCM_LIST3 (sym_set, sym_load_path,
+ SCM_LIST3 (sym_cons,
+ scm_makfrom0str(argv[i]),
+ sym_load_path)),
+ tail);
+ else
+ scm_shell_usage (1, "missing argument to -L switch");
+ }
+
else if (! strcmp (argv[i], "-l")) /* load a file */
{
if (++i < argc)