aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-07-26 23:09:29 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-07-26 23:09:29 +0300
commit11bbc1b9d551ceb2783c575d2d1d4d451d7e4ecf (patch)
tree5ccf070967875b7309579307f93e550881720bdc
parent7deb822b3b7789f5b3a982895b30ec757d1ab5f2 (diff)
downloadidest-11bbc1b9d551ceb2783c575d2d1d4d451d7e4ecf.tar.gz
idest-11bbc1b9d551ceb2783c575d2d1d4d451d7e4ecf.tar.bz2
Various improvements.
* src/Makefile.am: Initialize MAINTAINERCLEANFILES. * src/cmdline.opt: New options: --prepend-load-path and --no-init-files. * src/guile.c (no_init_files_option): New variable. (guile_load): Bail out on error. (load_path_prepend): Rewrite. (load_path_append): New function. (user_load_path_list): Replace with user_path_list (array). (guile_add_load_path): Second arg indicates which list to modify. (flush_user_load_path): Argument indicates which list to flush. (load_startup_file): Don't touch load path. It is done elsewhere. (guile_init): Set up load path. Call load_startup_file unless no_init_files_option is set. * src/idest.h (no_init_files_option): New extern. (guile_add_load_path): Change signature. * src/main.c (main): Fix coredump.
-rw-r--r--src/Makefile.am1
-rw-r--r--src/cmdline.opt15
-rw-r--r--src/guile.c75
-rw-r--r--src/idest.h3
-rw-r--r--src/main.c5
5 files changed, 63 insertions, 36 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index f9db6c8..1cd02d8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -43,6 +43,7 @@ GPERF_FLAGS=-tCcTnD -K id
DOT_X_FILES = guile.x
CLEANFILES=
DISTCLEANFILES=
+MAINTAINERCLEANFILES=
sitedir = @GUILE_SITE@/$(PACKAGE)
site_DATA=
include ../gint/gint.mk
diff --git a/src/cmdline.opt b/src/cmdline.opt
index 0043164..c43d285 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -219,11 +219,22 @@ BEGIN
END
OPTION(load-path,P,PATH,
- [<set load path>])
+ [<append PATH to the load path>])
BEGIN
- guile_add_load_path(optarg);
+ guile_add_load_path(optarg, 1);
END
+OPTION(prepend-load-path,p,PATH,
+ [<prepend PATH to the load path>])
+BEGIN
+ guile_add_load_path(optarg, 0);
+END
+
+OPTION(no-init-files,N,,
+ [<do not load Scheme init files>])
+BEGIN
+ no_init_files_option = 1;
+END
>])
OPTIONS_END
diff --git a/src/guile.c b/src/guile.c
index 2f77106..901d398 100644
--- a/src/guile.c
+++ b/src/guile.c
@@ -20,6 +20,7 @@
#include <libguile.h>
#include <setjmp.h>
+int no_init_files_option;
int guile_inited = 0;
int guile_debug = 1;
char **guile_argv;
@@ -99,12 +100,12 @@ load_handler_path(void *data)
return SCM_UNDEFINED;
}
-static int
+static void
guile_load(char **argv, int use_path)
{
if (guile_safe_exec(use_path ? load_handler_path : load_handler,
argv, NULL))
- exit(1);
+ error(1, 0, "cannot load %s", argv[0]);
}
static void
@@ -522,19 +523,27 @@ load_path_prepend(const char *dir)
SCM *pscm;
path_scm = SCM_VARIABLE_REF(scm_c_lookup("%load-path"));
- for (scm = path_scm; !scm_is_null(scm); scm = SCM_CDR(scm)) {
- SCM val = SCM_CAR(scm);
- if (scm_is_string(val)) {
- char *s = scm_to_locale_string(val);
- int rc = strcmp(s, dir);
- free(s);
- if (rc == 0)
+ scm = scm_from_locale_string(dir);
+ if (scm_member(scm, path_scm) != SCM_BOOL_F)
return;
- }
+
+ pscm = SCM_VARIABLE_LOC(scm_c_lookup("%load-path"));
+ *pscm = scm_cons(scm, path_scm);
}
+static void
+load_path_append(const char *dir)
+{
+ SCM scm, path_scm;
+ SCM *pscm;
+
+ path_scm = SCM_VARIABLE_REF(scm_c_lookup("%load-path"));
+ scm = scm_from_locale_string(dir);
+ if (scm_member(scm, path_scm) != SCM_BOOL_F)
+ return;
+
pscm = SCM_VARIABLE_LOC(scm_c_lookup("%load-path"));
- *pscm = scm_cons(scm_from_locale_string(dir), path_scm);
+ *pscm = scm_append(scm_list_2(path_scm, scm_list_1(scm)));
}
static char *
@@ -551,7 +560,7 @@ make_file_name(const char *dir, const char *file_name)
return ptr;
}
-static gl_list_t user_load_path_list;
+static gl_list_t user_path_list[2];
static void
path_item_dispose(const void *elt)
@@ -560,13 +569,13 @@ path_item_dispose(const void *elt)
}
void
-guile_add_load_path(const char *arg)
+guile_add_load_path(const char *arg, int li)
{
- char *p;
+ const char *p;
size_t n, len;
- if (!user_load_path_list)
- user_load_path_list =
+ if (!user_path_list[li])
+ user_path_list[li] =
gl_list_create_empty(&gl_linked_list_implementation,
NULL,
NULL,
@@ -579,23 +588,24 @@ guile_add_load_path(const char *arg)
s = xmalloc(n + 1);
memcpy(s, arg, n);
s[n] = 0;
- gl_list_add_first(user_load_path_list, s);
+ ((li == 0) ? gl_list_add_first : gl_list_add_last)
+ (user_path_list[li], s);
}
}
static void
-flush_user_load_path()
+flush_user_load_path(int li)
{
- if (user_load_path_list) {
+ if (user_path_list[li]) {
gl_list_iterator_t itr;
const void *p;
- itr = gl_list_iterator(user_load_path_list);
+ itr = gl_list_iterator(user_path_list[li]);
while (gl_list_iterator_next(&itr, &p, NULL))
- load_path_prepend(p);
+ ((li == 0) ? load_path_prepend : load_path_append)(p);
gl_list_iterator_free(&itr);
- gl_list_free(user_load_path_list);
- user_load_path_list = NULL;
+ gl_list_free(user_path_list[li]);
+ user_path_list[li] = NULL;
}
}
@@ -606,12 +616,6 @@ load_startup_file()
const char init_name[] = ".idest.scm";
char *argv[4];
- load_path_prepend(GUILE_SITE);
- load_path_prepend(PKG_SITE);
- load_path_prepend(VERSION_SITE);
- flush_user_load_path();
- load_path_prepend(".");
-
argv[0] = xstrdup(init_name);
argv[1] = make_file_name(getenv("HOME"), init_name);
argv[2] = make_file_name(PKG_SITE, "idest.scm");
@@ -619,9 +623,7 @@ load_startup_file()
for (i = 0; argv[i]; i++) {
if (access(argv[i], R_OK) == 0) {
- if (guile_load(argv + i, 0))
- error(1, 0, "cannot load startup script %s",
- argv[i]);
+ guile_load(argv + i, 0);
break;
}
free(argv[i]);
@@ -656,6 +658,15 @@ guile_init(int *pargc, char ***pargv)
scm_c_export("idest-main", "idest-readonly", NULL);
+ /* Set up load path */
+ flush_user_load_path(1);
+ load_path_prepend(GUILE_SITE);
+ load_path_prepend(PKG_SITE);
+ load_path_prepend(".");
+ load_path_prepend(VERSION_SITE);
+ flush_user_load_path(0);
+
+ if (!no_init_files_option)
load_startup_file();
guile_load(guile_argv, !strchr(guile_argv[0], '/'));
diff --git a/src/idest.h b/src/idest.h
index b23a02f..5668474 100644
--- a/src/idest.h
+++ b/src/idest.h
@@ -80,6 +80,7 @@ extern unsigned version_option;
extern unsigned default_version_option;
extern int guile_debug;
extern char **guile_argv;
+extern int no_init_files_option;
/* idop.c */
int set_frame_value(struct id3_frame *frame, const struct ed_item *item);
@@ -181,5 +182,5 @@ int backup_file(const char *file);
void guile_init(int *pargc, char ***pargv);
int guile_transform(const char *file, struct id3_tag *tag);
int guile_list(const char *file, struct id3_tag *tag);
-void guile_add_load_path(const char *arg);
+void guile_add_load_path(const char *arg, int li);
diff --git a/src/main.c b/src/main.c
index f32be10..e3a82df 100644
--- a/src/main.c
+++ b/src/main.c
@@ -218,8 +218,11 @@ main(int argc, char **argv)
*--guile_argv = "batch";
}
- if (dry_run_option)
+ if (dry_run_option) {
+ if (!guile_argv)
+ error(1, 0, "--dry-run used without --script or --format or --batch");
*--guile_argv = "dry-run";
+ }
guile_init(&argc, &argv);

Return to:

Send suggestions and report system problems to the System administrator.