aboutsummaryrefslogtreecommitdiff
path: root/src/guile.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-07-11 18:03:38 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-07-11 18:13:27 +0300
commit824a3865403c2c1a90533a1799c3ba9e277c2ce1 (patch)
treed3443aa8f29c2d207652428855f0c2acd9b910ad /src/guile.c
parentfa9805ce540e5443206d9e0fb9b34908bd8439bc (diff)
downloadidest-824a3865403c2c1a90533a1799c3ba9e277c2ce1.tar.gz
idest-824a3865403c2c1a90533a1799c3ba9e277c2ce1.tar.bz2
Change Scheme representation of frame lists.
* doc/idest.texi: Update * src/guile.c (field_to_scm): Support all conversions, except ID3_FIELD_TYPE_BINARYDATA. (frame_to_scm): Rewrite taking into account new frame list format. (scm_to_tag): Likewise. (setval): Remove. * src/idop.c (set_frame_value): Accept any frame type.
Diffstat (limited to 'src/guile.c')
-rw-r--r--src/guile.c158
1 files changed, 106 insertions, 52 deletions
diff --git a/src/guile.c b/src/guile.c
index 600295d..e225083 100644
--- a/src/guile.c
+++ b/src/guile.c
@@ -30,7 +30,12 @@ char *guile_function;
char **guile_argv;
SCM_GLOBAL_VARIABLE_INIT (sym_idest_main, "idest-main", SCM_EOL);
-SCM_GLOBAL_VARIABLE_INIT (sym_idest_readonly, "idest-readonly", SCM_BOOL_F);
+SCM_GLOBAL_VARIABLE_INIT(sym_idest_readonly, "idest-readonly", SCM_BOOL_F);
+
+SCM_GLOBAL_SYMBOL(idest_text, "text");
+SCM_GLOBAL_SYMBOL(idest_lang, "lang");
+SCM_GLOBAL_SYMBOL(idest_class, "class");
+SCM_GLOBAL_SYMBOL(idest_descr, "descr");
@@ -57,11 +62,11 @@ static SCM
scheme_safe_exec_body(void *data)
{
struct scheme_exec_data *ed = data;
- return ed->handler (ed->data);
+ return ed->handler(ed->data);
}
static int
-guile_safe_exec(SCM (*handler) (void *data), void *data, SCM *result)
+guile_safe_exec(SCM (*handler)(void *data), void *data, SCM *result)
{
jmp_buf jmp_env;
struct scheme_exec_data ed;
@@ -158,22 +163,46 @@ field_to_scm(union id3_field *field, int genre)
{
id3_ucs4_t const *ucs4;
char *str;
- SCM ret;
+ SCM ret = SCM_EOL;
switch (id3_field_type(field)) {
case ID3_FIELD_TYPE_TEXTENCODING:
+ case ID3_FIELD_TYPE_INT8:
+ case ID3_FIELD_TYPE_INT16:
+ case ID3_FIELD_TYPE_INT24:
+ case ID3_FIELD_TYPE_INT32:
+ case ID3_FIELD_TYPE_INT32PLUS:
+ ret = scm_from_long(field->number.value);
break;
+
case ID3_FIELD_TYPE_LATIN1:
case ID3_FIELD_TYPE_LATIN1FULL:
+ /* FIXME */
+ ret = scm_from_locale_string(id3_field_getlatin1(field));
+ break;
+
case ID3_FIELD_TYPE_LATIN1LIST:
+ /* FIXME */
break;
+
case ID3_FIELD_TYPE_STRING:
+ ucs4 = id3_field_getstring(field);;
+ if (ucs4) {
+ str = idest_ucs4_cvt(ucs4);
+ ret = scm_from_locale_string(str);
+ free(str);
+ } else
+ ret = SCM_BOOL_F;
break;
+
case ID3_FIELD_TYPE_STRINGFULL:
ucs4 = id3_field_getfullstring(field);
- str = idest_ucs4_cvt(ucs4);
- ret = scm_from_locale_string(str);
- free(str);
+ if (ucs4) {
+ str = idest_ucs4_cvt(ucs4);
+ ret = scm_from_locale_string(str);
+ free(str);
+ } else
+ ret = SCM_BOOL_F;
break;
case ID3_FIELD_TYPE_STRINGLIST:
@@ -183,12 +212,11 @@ field_to_scm(union id3_field *field, int genre)
case ID3_FIELD_TYPE_LANGUAGE:
case ID3_FIELD_TYPE_FRAMEID:
case ID3_FIELD_TYPE_DATE:
- case ID3_FIELD_TYPE_INT8:
- case ID3_FIELD_TYPE_INT16:
- case ID3_FIELD_TYPE_INT24:
- case ID3_FIELD_TYPE_INT32:
- case ID3_FIELD_TYPE_INT32PLUS:
+ ret = scm_from_locale_string(field->immediate.value);
+ break;
+
case ID3_FIELD_TYPE_BINARYDATA:
+ /* FIXME */
ret = SCM_EOL;
}
return ret;
@@ -197,33 +225,52 @@ field_to_scm(union id3_field *field, int genre)
static SCM
frame_to_scm(struct id3_frame *frame)
{
- int id = frame_id(frame->id);
SCM val;
-
- switch (id) {
- case item_title:
- case item_artist:
- case item_album:
- case item_year:
- case item_track:
- val = field_to_scm(id3_frame_field(frame, 1), 0);
+ union id3_field *field;
+
+ switch (frame_id(frame->id)) {
+ case item_comment:
+ field = id3_frame_field(frame, 3);
+ val = scm_list_1(
+ scm_cons(idest_text,
+ scm_from_locale_string(
+ field_to_string(field, 0))));
+
+ field = id3_frame_field(frame, 1);
+ if (!field)
+ break;
+ val = scm_cons(
+ scm_cons(idest_lang,
+ scm_from_locale_string(
+ field_to_string(field, 0))),
+ val);
+ field = id3_frame_field(frame, 2);
+ if (!field)
+ break;
+ val = scm_cons(
+ scm_cons(idest_class,
+ scm_from_locale_string(
+ field_to_string(field, 0))),
+ val);
break;
-
+
case item_genre:
- val = field_to_scm(id3_frame_field(frame, 1), 1);
- break;
-
- case item_comment:
- val = field_to_scm(id3_frame_field(frame, 3), 0);
+ val = scm_list_1(
+ scm_cons(idest_text,
+ field_to_scm(id3_frame_field(frame, 1), 1)));
break;
default:
- val = SCM_EOL;
+ val = scm_list_1(
+ scm_cons(idest_text,
+ field_to_scm(id3_frame_field(frame, 1), 0)));
+ break;
}
-
- if (val != SCM_EOL)
- return scm_cons(scm_from_locale_string(frame->id), val);
- return SCM_EOL;
+ return scm_cons(scm_from_locale_string(frame->id),
+ scm_cons(
+ scm_cons(idest_descr,
+ scm_from_locale_string(frame->description)),
+ val));
}
static SCM
@@ -250,27 +297,16 @@ tag_to_scm(struct id3_tag *tag)
return scm_first;
}
-static void
-setval(struct id3_tag *tag, char *id, char *value)
-{
- struct id3_frame *frame;
- frame = id3_tag_findframe(tag, id, 0);
- if (!frame) {
- frame = id3_frame_new(id);
- if (id3_tag_attachframe(tag, frame))
- error(1, 0, "cannot attach new frame");
- }
- set_frame_value(frame, value);
-}
-
static int
scm_to_tag(SCM scm, struct id3_tag *tag)
{
int modified = 0;
- for (; !scm_is_null (scm) && scm_is_pair(scm); scm = SCM_CDR(scm)) {
- char *id, *value;
- SCM x;
+ for (; !scm_is_null(scm) && scm_is_pair(scm); scm = SCM_CDR(scm)) {
+ struct id3_frame *frame;
+ struct ed_item itm;
+ char *id;
+ SCM x, text;
SCM elt = SCM_CAR(scm);
if (!scm_is_pair(elt))
scm_misc_error(NULL,
@@ -284,17 +320,35 @@ scm_to_tag(SCM scm, struct id3_tag *tag)
scm_list_1(elt));
id = scm_to_locale_string(x);
+ memset(&itm, 0, sizeof(itm));
+
x = SCM_CDR(elt);
- if (!scm_is_string(x))
+
+ if (scm_is_string(x)) {
+ itm.v.value = scm_to_locale_string(x);
+ } else if (scm_is_pair(x) &&
+ (text = scm_assoc_ref(x, idest_text)) != SCM_BOOL_F) {
+ itm.v.value = scm_to_locale_string(text);
+ text = scm_assoc_ref(x, idest_lang);
+ if (text != SCM_BOOL_F)
+ itm.lang = scm_to_locale_string(text);
+ text = scm_assoc_ref(x, idest_class);
+ if (text != SCM_BOOL_F)
+ itm.class = scm_to_locale_string(text);
+ } else
scm_misc_error(NULL,
"Wrong cdr type: ~S",
scm_list_1(elt));
- value = scm_to_locale_string(x);
- setval(tag, id, value);
+ frame = id3_frame_new(id);
+ if (id3_tag_attachframe(tag, frame))
+ error(1, 0, "cannot attach new frame");
+ set_frame_value(frame, itm);
modified |= 1;
free(id);
- free(value);
+ free(itm.v.value);
+ free(itm.class);
+ free(itm.lang);
}
return modified;
}

Return to:

Send suggestions and report system problems to the System administrator.