diff options
-rw-r--r-- | Makefile.am | 7 | ||||
-rw-r--r-- | configure.ac | 5 | ||||
-rw-r--r-- | examples/Makefile.am | 3 | ||||
-rw-r--r-- | scheme/Makefile.am | 35 | ||||
-rw-r--r-- | scheme/dry-run.scm (renamed from examples/dry-run.scm) | 17 | ||||
-rw-r--r-- | scheme/format.scm | 36 | ||||
-rw-r--r-- | scheme/idest/format/shortlist.scm | 22 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/cmdline.opt | 14 | ||||
-rw-r--r-- | src/editem.c | 2 | ||||
-rw-r--r-- | src/guile.c | 55 | ||||
-rw-r--r-- | src/idest.h | 5 | ||||
-rw-r--r-- | src/main.c | 29 |
13 files changed, 219 insertions, 14 deletions
diff --git a/Makefile.am b/Makefile.am index 3b985e8..e19d967 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,7 +15,12 @@ # along with Idest. If not, see <http://www.gnu.org/licenses/>. ACLOCAL_AMFLAGS = -I gint -I m4 -SUBDIRS=gnu libid3tag gint src doc examples + +if IDEST_COND_GUILE + SCHEME_DIR = scheme +endif + +SUBDIRS=gnu libid3tag gint src doc examples $(SCHEME_DIR) .PHONY: ChangeLog ChangeLog: diff --git a/configure.ac b/configure.ac index 1c33889..772ea62 100644 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,8 @@ GINT_INIT([gint],[1.8 with-guile nodoc], [status_guile=yes], [status_guile=no]) +AM_CONDITIONAL([IDEST_COND_GUILE],[test $status_guile = yes]) + AC_CONFIG_SUBDIRS(libid3tag) AC_CONFIG_COMMANDS([status],[ @@ -67,5 +69,6 @@ AC_CONFIG_FILES([Makefile gint/Makefile src/Makefile doc/Makefile - examples/Makefile]) + examples/Makefile + scheme/Makefile]) AC_OUTPUT diff --git a/examples/Makefile.am b/examples/Makefile.am index 73b4717..018a3f8 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -16,12 +16,9 @@ EXTRA_DIST = \ delcomm.scm\ - dry-run.scm\ list1.scm\ list2.scm\ shortlist.scm\ settitle.scm -sitedir = @GUILE_SITE@/$(PACKAGE) -site_DATA=dry-run.scm diff --git a/scheme/Makefile.am b/scheme/Makefile.am new file mode 100644 index 0000000..9ca46c8 --- /dev/null +++ b/scheme/Makefile.am @@ -0,0 +1,35 @@ +# This file is part of Idest +# 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/>. + +EXTRA_DIST=\ + dry-run.scm\ + format.scm + +sitedir = @GUILE_SITE@/$(PACKAGE) + +site_DATA=\ + dry-run.scm\ + format.scm + +dist-hook: + tar -C $(srcdir) -c -f - --exclude-vcs idest | \ + tar -C $(distdir) -x -f - + +versionsitedir = $(sitedir)/$(VERSION) + +install-data-local: + tar -c -f - idest | (cd $(DESTDIR)/$(versionsitedir); tar -x -f -) + diff --git a/examples/dry-run.scm b/scheme/dry-run.scm index 637ad8c..a77f3d8 100644 --- a/examples/dry-run.scm +++ b/scheme/dry-run.scm @@ -1,9 +1,18 @@ ;; dry-run.scm - run a script and show the frames it produces. +;; This file is part of Idest ;; Copyright (C) 2011 Sergey Poznyakoff -;; License GPLv3+: GNU GPL version 3 or later -;; <http://gnu.org/licenses/gpl.html> -;; This is free software: you are free to change and redistribute it. -;; There is NO WARRANTY, to the extent permitted by law. +;; 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/>. (let* ((cmd (command-line)) (progname (car cmd))) diff --git a/scheme/format.scm b/scheme/format.scm new file mode 100644 index 0000000..61a98cc --- /dev/null +++ b/scheme/format.scm @@ -0,0 +1,36 @@ +;; This file is part of Idest +;; Copyright (C) 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/>. + +(define-module (format)) + +(use-modules (guile-user)) + +(let ((cmd (command-line)) + (mod-pathname #f) + (saved-load-hook %load-hook)) + + (set! %load-hook (lambda (filename) + (set! mod-pathname filename) + (set! %load-hook saved-load-hook))) + + (let ((mod-name (list-ref cmd 1))) + (set-program-arguments (cons (car cmd) (list-tail cmd 2))) + (set! idest-main + (module-ref + (resolve-module (list 'idest 'format (string->symbol mod-name))) + 'idest-main)) + + (if (not idest-readonly) + (error (format #f "~A wants to modify files!" mod-pathname))))) diff --git a/scheme/idest/format/shortlist.scm b/scheme/idest/format/shortlist.scm new file mode 100644 index 0000000..fb83036 --- /dev/null +++ b/scheme/idest/format/shortlist.scm @@ -0,0 +1,22 @@ +;; shortlist.scm - List file name, artist and year, on a single line. +;; Copyright (C) 2011 Sergey Poznyakoff +;; License GPLv3+: GNU GPL version 3 or later +;; <http://gnu.org/licenses/gpl.html> +;; This is free software: you are free to change and redistribute it. +;; There is NO WARRANTY, to the extent permitted by law. + +(define-module (idest format shortlist)) + +(define (get-frame code frames) + (or (assoc-ref + (or (assoc-ref frames code) '()) + 'text) + "unknown")) + +(define-public (idest-main name frames) + (format #t "~A: ~A by ~A, ~A~%" + name + (get-frame "TIT2" frames) ; Title + (get-frame "TPE1" frames) ; Artist + (get-frame "TDRC" frames))) ; Year + diff --git a/src/Makefile.am b/src/Makefile.am index db5513a..f9db6c8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -49,4 +49,5 @@ include ../gint/gint.mk AM_CPPFLAGS=\ -DGUILE_SITE=\"@GUILE_SITE@\"\ - -DPKG_SITE=\"$(sitedir)\"
\ No newline at end of file + -DPKG_SITE=\"$(sitedir)\"\ + -DVERSION_SITE=\"$(sitedir)/$(VERSION)\" diff --git a/src/cmdline.opt b/src/cmdline.opt index 36478f0..3fc84e4 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -189,6 +189,12 @@ BEGIN optind = argc; /* Stop argument processing */ END +OPTION(format,H,NAME, + [<apply external format NAME>]) +BEGIN + format_name = optarg; +END + OPTION(function,f,NAME, [<guile function to call>]) BEGIN @@ -203,7 +209,13 @@ BEGIN else guile_debug = 1; END - + +OPTION(load-path,P,PATH, + [<set load path>]) +BEGIN + guile_add_load_path(optarg); +END + >]) OPTIONS_END diff --git a/src/editem.c b/src/editem.c index 69dd6dc..f7e99e9 100644 --- a/src/editem.c +++ b/src/editem.c @@ -90,7 +90,7 @@ ed_item_dup(struct ed_item const *orig) return copy; } -static const char * +const char * str_split_col(const char *str, size_t *plen, size_t *pn) { size_t n; diff --git a/src/guile.c b/src/guile.c index d09f121..08baf00 100644 --- a/src/guile.c +++ b/src/guile.c @@ -570,8 +570,54 @@ make_file_name(const char *dir, const char *file_name) strcpy(ptr + len, file_name); return ptr; } + +static gl_list_t user_load_path_list; static void +path_item_dispose(const void *elt) +{ + free((void*)elt); +} + +void +guile_add_load_path(const char *arg) +{ + char *p; + size_t n, len; + + if (!user_load_path_list) + user_load_path_list = + gl_list_create_empty(&gl_linked_list_implementation, + NULL, + NULL, + path_item_dispose, + true); + + for (len = strlen(arg); len; arg = p) { + char *s; + p = str_split_col(arg, &len, &n); + s = xmalloc(n + 1); + memcpy(s, arg, n); + s[n] = 0; + gl_list_add_first(user_load_path_list, s); + } +} + +static void +flush_user_load_path() +{ + gl_list_iterator_t itr; + const void *p; + + itr = gl_list_iterator(user_load_path_list); + while (gl_list_iterator_next(&itr, &p, NULL)) + load_path_prepend(p); + gl_list_iterator_free(&itr); + gl_list_free(user_load_path_list); + user_load_path_list = NULL; +} + +static void load_startup_file() { int i; @@ -580,7 +626,9 @@ load_startup_file() load_path_prepend(GUILE_SITE); load_path_prepend(PKG_SITE); + flush_user_load_path(); load_path_prepend("."); + load_path_prepend(VERSION_SITE); argv[0] = xstrdup(init_name); argv[1] = make_file_name(getenv("HOME"), init_name); @@ -624,6 +672,8 @@ guile_init(int *pargc, char ***pargv) #endif } + scm_c_export("idest-main", "idest-readonly", NULL); + load_startup_file(); guile_load(guile_script, !strchr(guile_script, '/'), guile_argv); @@ -686,4 +736,9 @@ guile_init(int *pargc, char **pargv) { } +void +guile_add_load_path(const char *arg) +{ +} + #endif diff --git a/src/idest.h b/src/idest.h index 2ae2b96..83b1d9d 100644 --- a/src/idest.h +++ b/src/idest.h @@ -98,6 +98,8 @@ char *field_binary_to_string(union id3_field *field); void input_list_add_assignment(const char *name, const char *value); +void list_supported_frames(void); + /* slist.c */ typedef int (*string_list_action_fn) (const char *, void *); @@ -171,6 +173,8 @@ struct ed_item const *ed_list_locate(gl_list_t list, struct id3_frame *frame, idest_frame_cmp_t cmp); +const char *str_split_col(const char *str, size_t *plen, size_t *pn); + /* backup.c */ int backup_file(const char *file); @@ -180,4 +184,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); @@ -29,6 +29,8 @@ int all_frames = 0; char *source_file; struct id3_tag *source_tag; +char *format_name; + struct item_info { int item_id; @@ -154,6 +156,13 @@ void (*id3_mode[])(const char *) = { }; int mode = MODE_QUERY; +const char *mode_option_str[] = { + "--query", + "--set", + "--delete", + "--info", + "--list-frames" +}; #include "cmdline.h" @@ -167,10 +176,26 @@ main(int argc, char **argv) get_options(argc, argv); if (!default_version_option) default_version_option = IDEST_ID3V_1|IDEST_ID3V_2; - + argc -= optind; argv += optind; + if (format_name) { + int i; + + if (mode_set) + error(1, 0, "--format cannot be used with %s", + mode_option_str[mode]); + if (guile_script) + error(1, 0, "--format cannot be used with --script"); + + guile_script = "format"; + guile_argv = xcalloc(argc + 2, sizeof(guile_argv[0])); + guile_argv[0] = format_name; + for (i = 0; i <= argc; i++) + guile_argv[i + 1] = argv[i]; + } + guile_init(&argc, &argv); if (mode == MODE_LIST) { @@ -179,7 +204,7 @@ main(int argc, char **argv) list_supported_frames(); exit(0); } - + if (argc == 0) error(1, 0, "no files"); |