aboutsummaryrefslogtreecommitdiff
path: root/src/guile.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-07-10 22:29:32 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-07-10 22:29:32 +0300
commit8da9ed187d4e0b8b358e12a5fb69233601581772 (patch)
tree361ff4a34aca6ab588d5039350eb2c3541e720d0 /src/guile.c
parent218818d2366c1ed01b4ded1b12faf299eaf93859 (diff)
downloadidest-8da9ed187d4e0b8b358e12a5fb69233601581772.tar.gz
idest-8da9ed187d4e0b8b358e12a5fb69233601581772.tar.bz2
Guile scripts can access and modify command line arguments.
* NEWS: Update. * src/cmdline.opt (--script): Stop argument processing. * src/guile.c (guile_argv): New variable. (guile_load): Take command line arguments as the 3rd argument. All uses updated. (guile_init): Allow the script to alter command line arguments. * src/idest.h (guile_argv): New proto. (guile_init): Change signature. * src/main.c (main): Call guile_init before checking argc.
Diffstat (limited to 'src/guile.c')
-rw-r--r--src/guile.c49
1 files changed, 36 insertions, 13 deletions
diff --git a/src/guile.c b/src/guile.c
index 4e05886..600295d 100644
--- a/src/guile.c
+++ b/src/guile.c
@@ -27,6 +27,7 @@ int guile_inited = 0;
int guile_debug = 1;
char *guile_script;
char *guile_function;
+char **guile_argv;
SCM_GLOBAL_VARIABLE_INIT (sym_idest_main, "idest-main", SCM_EOL);
SCM_GLOBAL_VARIABLE_INIT (sym_idest_readonly, "idest-readonly", SCM_BOOL_F);
@@ -106,14 +107,19 @@ load_handler_path(void *data)
}
static int
-guile_load(char *filename, int use_path)
+guile_load(char *filename, int use_path, char **argv)
{
struct load_closure lc;
- char *argv[2];
- argv[0] = filename;
- argv[1] = NULL;
- lc.argc = 1;
- lc.argv = argv;
+ if (argv) {
+ lc.argc = -1;
+ lc.argv = argv;
+ } else {
+ char *s_argv[2];
+ s_argv[0] = filename;
+ s_argv[1] = NULL;
+ lc.argc = 1;
+ lc.argv = s_argv;
+ }
lc.filename = filename;
return guile_safe_exec(use_path ? load_handler_path : load_handler,
&lc, NULL);
@@ -375,7 +381,7 @@ try_file(const char *dir, const char *file_name)
strcpy(ptr + len, file_name);
if (access(ptr, R_OK) == 0) {
- if (guile_load(ptr, 0))
+ if (guile_load(ptr, 0, NULL))
error(1, 0, "cannot load startup script %s", ptr);
return 0;
}
@@ -394,7 +400,7 @@ load_startup_file()
load_path_prepend(".");
if (access(init_name, R_OK) == 0) {
- if (guile_load((char*)init_name, 0) == 0)
+ if (guile_load((char*)init_name, 0, NULL) == 0)
return;
error(1, 0, "cannot load startup script %s", init_name);
}
@@ -406,9 +412,11 @@ load_startup_file()
}
void
-guile_init()
+guile_init(int *pargc, char ***pargv)
{
- SCM readonly, proc;
+ SCM readonly, proc, args;
+ int argc, i;
+ char **argv;
if (!guile_script)
return;
@@ -428,8 +436,23 @@ guile_init()
load_startup_file();
- guile_load(guile_script, !strchr(guile_script, '/'));
-
+ guile_load(guile_script, !strchr(guile_script, '/'), guile_argv);
+
+ /* Read command line arguments */
+ args = scm_program_arguments();
+ argc = scm_to_int(scm_length(args));
+ /* Note: argv[0] is the script name. We will skip it. */
+ argv = xcalloc(argc, sizeof(argv[0]));
+ argc--;
+ for (i = 0, args = SCM_CDR(args); i < argc;
+ i++, args = SCM_CDR(args)) {
+ SCM sarg = SCM_CAR(args);
+ argv[i] = scm_to_locale_string(sarg);
+ }
+ argv[i] = NULL;
+ *pargc = argc;
+ *pargv = argv;
+
proc = SCM_VARIABLE_REF(sym_idest_main);
if (proc == SCM_EOL) {
if (guile_function) {
@@ -469,7 +492,7 @@ guile_list(const char *file, struct id3_tag *tag)
}
void
-guile_init()
+guile_init(int *pargc, char **pargv)
{
}

Return to:

Send suggestions and report system problems to the System administrator.