aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2015-11-05 23:20:23 +0200
committerSergey Poznyakoff <gray@gnu.org>2015-11-05 23:20:23 +0200
commit6f8dc538dab2a9284802b63e80fd4f03bb0dff34 (patch)
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.
-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,5 +1,5 @@
;; 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
@@ -16,7 +16,8 @@
(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")
@@ -26,17 +27,16 @@
(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))
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,5 +1,5 @@
;; 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
@@ -17,6 +17,7 @@
(define-module (idest format pic))
(use-modules (ice-9 getopt-long)
+ (rnrs io ports)
(srfi srfi-1))
(define-public description
@@ -72,11 +73,28 @@
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
@@ -86,8 +104,7 @@
(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)
@@ -204,4 +221,4 @@
(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,5 +1,5 @@
;; 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
@@ -92,7 +92,7 @@
(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.
@@ -111,7 +111,7 @@
; 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 ()
diff --git a/src/frametab.gperf b/src/frametab.gperf
index e716954..80d60f9 100644
--- a/src/frametab.gperf
+++ b/src/frametab.gperf
@@ -1,6 +1,6 @@
%{
/* 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
@@ -86,7 +86,7 @@ frame_field_from_string(struct id3_frame *frame, int n, const char *value)
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 ?
@@ -186,6 +186,113 @@ frame_field_from_string(struct id3_frame *frame, int n, const char *value)
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)
{
diff --git a/src/getopt.m4 b/src/getopt.m4
index 9267de2..2e8d01d 100644
--- a/src/getopt.m4
+++ b/src/getopt.m4
@@ -1,5 +1,5 @@
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
@@ -457,7 +457,7 @@ 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)
diff --git a/src/guile.c b/src/guile.c
index e59b49c..7fe052f 100644
--- a/src/guile.c
+++ b/src/guile.c
@@ -1,5 +1,5 @@
/* 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
@@ -383,9 +383,11 @@ 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;
@@ -420,11 +422,11 @@ scm_to_tag(SCM scm, struct id3_tag *tag)
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));
diff --git a/src/idest.h b/src/idest.h
index 3d18135..977fdd1 100644
--- a/src/idest.h
+++ b/src/idest.h
@@ -1,5 +1,5 @@
/* 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
@@ -96,6 +96,10 @@ 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);
diff --git a/src/idop.c b/src/idop.c
index 353bd46..0ce4c65 100644
--- a/src/idop.c
+++ b/src/idop.c
@@ -1,5 +1,5 @@
/* 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
@@ -377,10 +377,9 @@ set_tag_options(struct id3_tag *tag, int vopt)
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

Return to:

Send suggestions and report system problems to the System administrator.