summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2015-11-05 21:20:23 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2015-11-05 21:20:23 (GMT)
commit6f8dc538dab2a9284802b63e80fd4f03bb0dff34 (patch) (side-by-side diff)
tree387372a6dc1c8e04aa81e19b19820c8d75351f67
parent353839b7a29a53aa754b98b02ede449c737a873a (diff)
downloadidest-6f8dc538dab2a9284802b63e80fd4f03bb0dff34.tar.gz
idest-6f8dc538dab2a9284802b63e80fd4f03bb0dff34.tar.bz2
Bugfixes.
1. Fix --convert option so it can be used to remove unnecessary ID3 formats (e.g. --convert=2). 2. Fix processing of unknown frames in Guile code. 3. Fix setpic and pic modules. * scheme/idest/batch/setpic.scm (read-picture): Use binary i/o. * scheme/idest/format/pic.scm (save-picture): Likewise. * scheme/idest/list-modules.scm: Minor changes. * src/frametab.gperf (frame_field_from_rawdata): New function. * src/getopt.m4: Update copyright years. * src/guile.c (set_frame_from_rawdata): Use frame_field_from_rawdata. * src/idest.h (frame_field_from_rawdata): New proto. * src/idop.c (set_tag_options): Always call id3_tag_options.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--scheme/idest/batch/setpic.scm24
-rw-r--r--scheme/idest/format/pic.scm27
-rw-r--r--scheme/idest/list-modules.scm6
-rw-r--r--src/frametab.gperf111
-rw-r--r--src/getopt.m44
-rw-r--r--src/guile.c18
-rw-r--r--src/idest.h6
-rw-r--r--src/idop.c9
8 files changed, 167 insertions, 38 deletions
diff --git a/scheme/idest/batch/setpic.scm b/scheme/idest/batch/setpic.scm
index c0670a3..834a571 100644
--- a/scheme/idest/batch/setpic.scm
+++ b/scheme/idest/batch/setpic.scm
@@ -1,8 +1,8 @@
;; This file is part of Idest
-;; Copyright (C) 2011 Sergey Poznyakoff
+;; Copyright (C) 2011, 2015 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.
;;
@@ -13,33 +13,33 @@
;;
;; 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 (idest batch setpic))
-(use-modules (ice-9 getopt-long))
+(use-modules (ice-9 getopt-long)
+ (rnrs io ports))
(define-public description
"set attached picture from a file")
(define-public idest-main #f)
(define (read-picture file)
(with-output-to-string
(lambda ()
- (with-input-from-file
- file
- (lambda ()
- (let loop ((chr (read-char)))
+ (let ((port (open-file-input-port file)))
+ (let ((get-byte (lambda () (get-u8 port))))
+ (let loop ((n (get-byte)))
(cond
- ((not (eof-object? chr))
- (let ((n (char->integer chr)))
- (if (< n 16)
- (display "0"))
- (display (number->string n 16)))
- (loop (read-char))))))))))
+ ((not (eof-object? n))
+ (if (< n 16)
+ (display "0"))
+ (display (number->string n 16))
+ (loop (get-byte))))))
+ (close-port port)))))
(define-public (idest-init)
(let* ((cmd (command-line))
(progname (car cmd))
(description "")
(mime-type #f)
diff --git a/scheme/idest/format/pic.scm b/scheme/idest/format/pic.scm
index 0e42f25..5e831fb 100644
--- a/scheme/idest/format/pic.scm
+++ b/scheme/idest/format/pic.scm
@@ -1,8 +1,8 @@
;; This file is part of Idest
-;; Copyright (C) 2011 Sergey Poznyakoff
+;; Copyright (C) 2011, 2015 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.
;;
@@ -14,12 +14,13 @@
;; 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 (idest format pic))
(use-modules (ice-9 getopt-long)
+ (rnrs io ports)
(srfi srfi-1))
(define-public description
"show attached picture (APIC frame) or save it on disk")
(define-public idest-main #f)
@@ -69,28 +70,44 @@
((#\P) (assoc-ref data 'pic-type))
((#\I) (number->string (getpid))))
(substring seg 1)))
segments))))
(define (save-picture name data)
+ (let ((port (open-file-output-port name)))
+ (for-each
+ (lambda (c) (put-u8 port c))
+ (let string->bytelist ((str data)
+ (bytelist '()))
+ (cond
+ ((string-null? str)
+ (reverse bytelist))
+ (else
+ (string->bytelist
+ (substring str 2)
+ (cons
+ (string->number (substring str 0 2) 16)
+ bytelist))))))
+ (close-port port)))
+
+(define (save-picture-0 name data)
(with-output-to-file
name
(lambda ()
(for-each
- write-char
+ (lambda (c) (put-u8 (current-output-port) c))
(let string->bytelist ((str data)
(bytelist '()))
(cond
((string-null? str)
(reverse bytelist))
(else
(string->bytelist
(substring str 2)
(cons
- (integer->char
- (string->number (substring str 0 2) 16))
+ (string->number (substring str 0 2) 16)
bytelist)))))))))
(define-public (idest-init)
(let* ((cmd (command-line))
(progname (car cmd))
(description #f)
@@ -201,7 +218,7 @@
(let ((res (system* viewer file-name)))
(delete-file file-name)
(if (= res 256)
(exit 1)))))))
pictures))))))))
- \ No newline at end of file
+
diff --git a/scheme/idest/list-modules.scm b/scheme/idest/list-modules.scm
index c69d331..880dbf8 100644
--- a/scheme/idest/list-modules.scm
+++ b/scheme/idest/list-modules.scm
@@ -1,8 +1,8 @@
;; This file is part of Idest
-;; Copyright (C) 2011 Sergey Poznyakoff
+;; Copyright (C) 2011, 2015 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.
;;
@@ -89,13 +89,13 @@
prev)
'()
%load-path)
(lambda (a b)
(string<? (car a) (car b))))))
- ;; Try out each candidate and print ist name, directory and description
+ ;; Try out each candidate and print its name, directory and description
;; if it happens to be a valid idest format module.
;; Take care not to bail out on errors. Disable %load-hook as it migh
;; clobber the output.
(set! %load-hook #f)
(for-each
(lambda (candidate)
@@ -108,13 +108,13 @@
(module-ref mod 'idest-main)
; Print module name
(display (car candidate))
; Its directory, if required
(if print-dir
(format #t " (~A)" (cdr candidate)))
- ; A colon, and description (if any
+ ; A colon, and description (if any)
(format #t ": ~A~%"
(catch #t
(lambda ()
(module-ref mod 'description))
(lambda (key . args)
"no description")))))
diff --git a/src/frametab.gperf b/src/frametab.gperf
index e716954..80d60f9 100644
--- a/src/frametab.gperf
+++ b/src/frametab.gperf
@@ -1,9 +1,9 @@
%{
/* This file is part of Idest.
- Copyright (C) 2009-2011 Sergey Poznyakoff
+ Copyright (C) 2009-2011, 2015 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.
@@ -83,13 +83,13 @@ frame_field_from_string(struct id3_frame *frame, int n, const char *value)
return IDEST_ERR_BADFIELD;
type = frametype->fields[n];
field = id3_frame_field(frame, n);
if (!field)
return IDEST_ERR_NOFIELD;
- if (frametype->fields[n] == ID3_FIELD_TYPE_TEXTENCODING) {
+ if (type == ID3_FIELD_TYPE_TEXTENCODING) {
/* Special case */
if (id3_field_settextencoding(field,
latin1_option ?
ID3_FIELD_TEXTENCODING_ISO_8859_1
: ID3_FIELD_TEXTENCODING_UTF_8))
rc = IDEST_ERR_SET;
@@ -183,12 +183,119 @@ frame_field_from_string(struct id3_frame *frame, int n, const char *value)
}
if (rc == 0 && res)
rc = IDEST_ERR_SET;
return rc;
}
+int
+frame_field_from_rawdata(struct id3_frame *frame, int n,
+ enum id3_field_type type,
+ const char *value)
+{
+ int rc = 0, res = 0;
+ union id3_field *field;
+ id3_ucs4_t *ucs4;
+
+ field = id3_frame_field(frame, n);
+ if (!field)
+ return IDEST_ERR_NOFIELD;
+ if (type == ID3_FIELD_TYPE_TEXTENCODING) {
+ /* Special case */
+ if (id3_field_settextencoding(field,
+ latin1_option ?
+ ID3_FIELD_TEXTENCODING_ISO_8859_1
+ : ID3_FIELD_TEXTENCODING_UTF_8))
+ rc = IDEST_ERR_SET;
+ return rc;
+ }
+
+ switch (type) {
+ case ID3_FIELD_TYPE_INT8:
+ case ID3_FIELD_TYPE_INT16:
+ case ID3_FIELD_TYPE_INT24:
+ case ID3_FIELD_TYPE_INT32: {
+ char *p;
+ signed long number = strtoul(value, &p, 10);
+ if (*p)
+ rc = IDEST_ERR_BADCONV;
+ else
+ res = id3_field_setint(field, number);
+ break;
+ }
+
+ case ID3_FIELD_TYPE_LATIN1:
+ case ID3_FIELD_TYPE_LATIN1FULL:
+ /* FIXME: Recode */
+ res = id3_field_setlatin1(field, (id3_latin1_t const *)value);
+ break;
+
+ case ID3_FIELD_TYPE_LATIN1LIST:
+ /* FIXME */
+ rc = IDEST_ERR_NOTSUPP;
+ break;
+
+ case ID3_FIELD_TYPE_STRING:
+ if (latin1_option)
+ ucs4 = id3_latin1_ucs4duplicate(
+ (const id3_latin1_t *)value);
+ else
+ ucs4 = id3_utf8_ucs4duplicate(
+ (const id3_utf8_t *)value);
+ res = id3_field_setstring(field, ucs4);
+ free(ucs4);
+ break;
+
+ case ID3_FIELD_TYPE_STRINGFULL:
+ if (latin1_option)
+ ucs4 = id3_latin1_ucs4duplicate(
+ (const id3_latin1_t *)value);
+ else
+ ucs4 = id3_utf8_ucs4duplicate(
+ (const id3_utf8_t *)value);
+ res = id3_field_setfullstring(field, ucs4);
+ free(ucs4);
+ break;
+
+ case ID3_FIELD_TYPE_STRINGLIST:
+ if (latin1_option)
+ ucs4 = id3_latin1_ucs4duplicate(
+ (const id3_latin1_t *)value);
+ else
+ ucs4 = id3_utf8_ucs4duplicate(
+ (const id3_utf8_t *)value);
+ res = id3_field_setstrings(field, 1, &ucs4);
+ free(ucs4);
+ break;
+
+ case ID3_FIELD_TYPE_LANGUAGE:
+ res = id3_field_setlanguage(field, value);
+ break;
+
+ case ID3_FIELD_TYPE_FRAMEID:
+ res = id3_field_setframeid(field, value);
+ break;
+
+ case ID3_FIELD_TYPE_DATE:
+ /* FIXME: Convert and copy 8 bytes into
+ field->immediate.value */
+ rc = IDEST_ERR_NOTSUPP;
+ break;
+
+ case ID3_FIELD_TYPE_INT32PLUS:
+ case ID3_FIELD_TYPE_BINARYDATA:
+ rc = field_binary_from_string(field, value);
+ break;
+
+ default:
+ rc = IDEST_ERR_BADTYPE;
+ }
+ if (rc == 0 && res)
+ rc = IDEST_ERR_SET;
+ return rc;
+}
+
static int
encode_qv(struct id3_frame *frame, int frameoff, const struct ed_item *item)
{
int i;
for (i = 0; i < item->qc; i++) {
diff --git a/src/getopt.m4 b/src/getopt.m4
index 9267de2..2e8d01d 100644
--- a/src/getopt.m4
+++ b/src/getopt.m4
@@ -1,8 +1,8 @@
dnl This file is part of GNU Rush.
-dnl Copyright (C) 2007-2011 Sergey Poznyakoff.
+dnl Copyright (C) 2007-2011, 2015 Sergey Poznyakoff.
dnl
dnl GNU Rush is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 3, or (at your option)
dnl any later version.
dnl
@@ -454,13 +454,13 @@ print_usage(void)
}
const char version_etc_copyright[] =
/* Do *not* mark this string for translation. %s is a copyright
symbol suitable for this locale, and %d is the copyright
year. */
- "Copyright %s 2005-2011 Sergey Poznyakoff";
+ "Copyright %s 2005-2011, 2015 Sergey Poznyakoff";
void
print_version_only(const char *program_version, FILE *stream)
{
fprintf (stream, "%s\n", program_version);
/* TRANSLATORS: Translate "(C)" to the copyright symbol
diff --git a/src/guile.c b/src/guile.c
index e59b49c..7fe052f 100644
--- a/src/guile.c
+++ b/src/guile.c
@@ -1,8 +1,8 @@
/* This file is part of Idest.
- Copyright (C) 2009-2011 Sergey Poznyakoff
+ Copyright (C) 2009-2011, 2015 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.
@@ -380,15 +380,17 @@ ed_item_from_scm(struct ed_item *itm, SCM list)
static int
set_frame_from_rawdata(struct id3_frame *frame, SCM list)
{
for (; !scm_is_null(list); list = SCM_CDR(list)) {
SCM cell = SCM_CAR(list);
int n = scm_to_int(SCM_CAR(cell));
- int rc;
+ int type = scm_to_int(SCM_CAR(SCM_CDR(cell)));
char *value = scm_to_locale_string(SCM_CAR(SCM_CDR(SCM_CDR(cell))));
- rc = frame_field_from_string(frame, n, value);
+ int rc;
+
+ rc = frame_field_from_rawdata(frame, n, type, value);
free(value);
if (rc)
return rc;
}
return 0;
}
@@ -417,17 +419,17 @@ scm_to_tag(SCM scm, struct id3_tag *tag)
if (!scm_is_string(x))
scm_misc_error(NULL,
"Wrong car type: ~S",
scm_list_1(elt));
id = scm_to_locale_string(x);
- frametype = id3_frametype_lookup(id, strlen(id));
- if (!frametype)
- idest_guile_error("guile-transform",
- id, SCM_BOOL_F,
- IDEST_ERR_BADTYPE);
+ /* frametype = id3_frametype_lookup(id, strlen(id)); */
+ /* if (!frametype) */
+ /* idest_guile_error("guile-transform", */
+ /* id, SCM_BOOL_F, */
+ /* IDEST_ERR_BADTYPE); */
ed_item_zero(&itm);
memcpy(itm.id, id, sizeof(itm.id));
itm.name = id;
x = SCM_CDR(elt);
diff --git a/src/idest.h b/src/idest.h
index 3d18135..977fdd1 100644
--- a/src/idest.h
+++ b/src/idest.h
@@ -1,8 +1,8 @@
/* This file is part of Idest.
- Copyright (C) 2009-2011 Sergey Poznyakoff
+ Copyright (C) 2009-2011, 2015 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.
@@ -93,12 +93,16 @@ void query_tags(const char *name);
void info_id3(const char *name);
char *field_to_string(union id3_field *field, int isgenre);
int field_binary_from_string(union id3_field *field, const char *str);
char *field_binary_to_string(union id3_field *field);
+int frame_field_from_rawdata(struct id3_frame *frame, int n,
+ enum id3_field_type type,
+ const char *value);
+
void input_list_add_assignment(const char *name, const char *value);
void list_supported_frames(void);
/* slist.c */
diff --git a/src/idop.c b/src/idop.c
index 353bd46..0ce4c65 100644
--- a/src/idop.c
+++ b/src/idop.c
@@ -1,8 +1,8 @@
/* This file is part of Idest.
- Copyright (C) 2009-2011 Sergey Poznyakoff
+ Copyright (C) 2009-2011, 2015 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.
@@ -374,16 +374,15 @@ set_tag_options(struct id3_tag *tag, int vopt)
int opts = 0;
if (vopt & IDEST_ID3V_1)
opts |= ID3_TAG_OPTION_ID3V1;
if (!(vopt & IDEST_ID3V_2))
opts |= ID3_TAG_OPTION_NO_ID3V2;
- if (opts)
- id3_tag_options(tag,
- ID3_TAG_OPTION_ID3V1|ID3_TAG_OPTION_NO_ID3V2,
- opts);
+ id3_tag_options(tag,
+ ID3_TAG_OPTION_ID3V1|ID3_TAG_OPTION_NO_ID3V2,
+ opts);
}
int
guess_file_tag_options(struct id3_file *file, int *modified)
{
int vopt = version_option;

Return to:

Send suggestions and report system problems to the System administrator.