summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2011-07-26 20:09:29 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-07-26 20:09:29 (GMT)
commit11bbc1b9d551ceb2783c575d2d1d4d451d7e4ecf (patch) (side-by-side diff)
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.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/Makefile.am1
-rw-r--r--src/cmdline.opt87
-rw-r--r--src/guile.c81
-rw-r--r--src/idest.h3
-rw-r--r--src/main.c7
5 files changed, 103 insertions, 76 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
@@ -1,25 +1,25 @@
/* This file is part of Idest. -*- c -*-
Copyright (C) 2009-2011 Sergey Poznyakoff
-
+
Idest is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
-
+
Idest is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with Idest. If not, see <http://www.gnu.org/licenses/>. */
static int mode_set = 0;
#define SET_MODE(m) do { \
- if (mode_set++ && mode != m) \
- error(1, 0, "only one of -q, -s, -d may be used"); \
- mode = m; \
- } while(0)
+ if (mode_set++ && mode != m) \
+ error(1, 0, "only one of -q, -s, -d may be used"); \
+ mode = m; \
+ } while(0)
static unsigned
get_version_list(const char *arg)
@@ -48,10 +48,10 @@ get_version_list(const char *arg)
}
return vers;
}
-
+
OPTIONS_BEGIN(gnu, "idest",
- [<idest - ID3 Edit and Scripting Tool>],
- [<FILE [FILE...]>])
+ [<idest - ID3 Edit and Scripting Tool>],
+ [<FILE [FILE...]>])
GROUP([<Operation mode>])
@@ -74,12 +74,12 @@ OPTION(set,s,FIELD=VALUE,
[<set FIELD to VALUE>])
BEGIN
char *p;
-
+
SET_MODE(MODE_MOD);
p = strchr(optarg, '=');
if (!p)
error(1, 0, "missing `=' sign in assignment");
- *p++ = 0;
+ *p++ = 0;
input_list_add_assignment(optarg, p);
END
@@ -89,18 +89,18 @@ BEGIN
SET_MODE(MODE_DELETE);
if (optarg)
parse_filter_items(optarg);
-END
+END
OPTION(info,i,,
[<display information about ID3 tags>])
BEGIN
SET_MODE(MODE_INFO);
-END
+END
OPTION(copy,c,FILE,
[<copy frames from FILE>])
BEGIN
- source_file = optarg;
+ source_file = optarg;
END
OPTION(list-frames,L,,
@@ -110,7 +110,7 @@ BEGIN
END
GROUP([<Operation modifiers>])
-
+
OPTION(filter,F,FRAME-LIST,
[<operate only on matching frames>])
BEGIN
@@ -125,7 +125,7 @@ END
OPTION(default-id-version,U,VERSION,
[<create new tags in the given ID3 version>])
-BEGIN
+BEGIN
default_version_option = get_version_list(optarg);
END
@@ -139,19 +139,19 @@ OPTION(latin1,,,
[<force latin1 output>])
BEGIN
latin1_option = 1;
-END
+END
OPTION(verbose,v,,
[<verbosely list files processed>])
BEGIN
- verbose_option = 1;
-END
+ verbose_option = 1;
+END
OPTION(describe,D,,
[<print verbose frame descriptions instead of short names>])
BEGIN
describe_option = 1;
-END
+END
GROUP([<Backup options>])
@@ -159,23 +159,23 @@ OPTION(backup,,[CONTROL],
[<backup before modifying, choose version CONTROL>])
BEGIN
if (optarg)
- backup_type = xget_version ("--backup", optarg);
+ backup_type = xget_version ("--backup", optarg);
else
backup_type = xget_version ("VERSION_CONTROL",
- getenv("VERSION_CONTROL"));
+ getenv("VERSION_CONTROL"));
END
OPTION(backup-suffix,,SUF,
[<set backup suffix, instead of the default ~>])
BEGIN
simple_backup_suffix = optarg;
-END
+END
OPTION(backup-directory,,DIR,
[<backup to given DIR>])
BEGIN
backup_dir = optarg;
-END
+END
IFDEF(GUILE_VERSION,[<
@@ -185,24 +185,24 @@ OPTION(script,S,FILE,
[<read Guile script from FILE; this stops further argument processing>])
BEGIN
set_guile_argv(argc - optind, argv + optind); /* Save rest of arguments */
- *--guile_argv = optarg;
- optind = argc; /* Stop argument processing */
+ *--guile_argv = optarg;
+ optind = argc; /* Stop argument processing */
END
OPTION(format,H,NAME,
[<apply external format NAME; this stops further argument processing>])
BEGIN
- format_name = optarg;
- stop = 1; /* Stop argument processing */
+ format_name = optarg;
+ stop = 1; /* Stop argument processing */
END
OPTION(batch,B,NAME,
[<apply batch modification module NAME; this stops further argument processing>])
BEGIN
batch_name = optarg;
- stop = 1; /* Stop argument processing */
+ stop = 1; /* Stop argument processing */
END
-
+
OPTION(dry-run,n,,
[<run the script, print modified frames but do not write them to the file>])
BEGIN
@@ -213,17 +213,28 @@ OPTION(trace,,[LEVEL],
[<start with debugging evaluator and backtraces>])
BEGIN
if (optarg)
- guile_debug = atoi(optarg);
+ guile_debug = atoi(optarg);
else
- guile_debug = 1;
-END
+ guile_debug = 1;
+END
OPTION(load-path,P,PATH,
- [<set load path>])
+ [<append PATH to the load path>])
+BEGIN
+ 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
- guile_add_load_path(optarg);
+ no_init_files_option = 1;
END
-
>])
OPTIONS_END
@@ -236,7 +247,7 @@ get_options(int argc, char *argv[])
char *p;
/* See if we've been given any assignment arguments */
while (p = strchr(argv[optind], '=')) {
- *p++ = 0;
+ *p++ = 0;
input_list_add_assignment(argv[optind++], p);
}
}
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
@@ -520,21 +521,29 @@ load_path_prepend(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, 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"));
- 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)
- return;
- }
- }
+ 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,7 +658,16 @@ guile_init(int *pargc, char ***pargv)
scm_c_export("idest-main", "idest-readonly", NULL);
- load_startup_file();
+ /* 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,9 +218,12 @@ 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);
if (mode == MODE_LIST) {

Return to:

Send suggestions and report system problems to the System administrator.