[xiph-cvs] cvs commit: vorbis-tools/vorbiscomment vcomment.c
Michael Smith
msmith at xiph.org
Tue Sep 25 01:59:55 PDT 2001
msmith 01/09/25 01:59:55
Modified: share utf8.c
vorbiscomment vcomment.c
Log:
Implementation of utf8 decoding for platforms with iconv, along with
support for this in vorbiscomment (falling back to just printing it raw
when it fails, as it will on platforms without iconv, for now).
Revision Changes Path
1.2 +40 -0 vorbis-tools/share/utf8.c
Index: utf8.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/share/utf8.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- utf8.c 2001/09/22 22:49:51 1.1
+++ utf8.c 2001/09/25 08:59:54 1.2
@@ -194,7 +194,47 @@
int utf8_decode(char *from, char **to, const char *encoding)
{
+#ifdef HAVE_ICONV
+ static unsigned char buffer[BUFSIZE];
+ char *from_p, *to_p;
+ size_t from_left, to_left;
+ iconv_t cd;
+ cd = iconv_open(encoding, "UTF-8");
+ if(cd == (iconv_t)(-1))
+ {
+ perror("iconv_open");
+ }
+
+ from_left = strlen(from);
+ to_left = BUFSIZE;
+ from_p = from;
+ to_p = buffer;
+
+ if(iconv(cd, (ICONV_CONST char **)(&from_p), &from_left, &to_p,
+ &to_left) == (size_t)-1)
+ {
+ iconv_close(cd);
+ switch(errno)
+ {
+ case E2BIG:
+ case EILSEQ:
+ case EINVAL:
+ return 3;
+ default:
+ perror("iconv");
+ }
+ }
+ else
+ {
+ iconv_close(cd);
+ }
+ *to = malloc(BUFSIZE - to_left + 1);
+ buffer[BUFSIZE - to_left] = 0;
+ strcpy(*to, buffer);
+ return 0;
+#else
return 1; /* Dummy stub */
+#endif /* HAVE_ICONV */
}
charset_map *get_map(const char *encoding)
1.13 +13 -4 vorbis-tools/vorbiscomment/vcomment.c
Index: vcomment.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-tools/vorbiscomment/vcomment.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- vcomment.c 2001/09/25 06:25:26 1.12
+++ vcomment.c 2001/09/25 08:59:55 1.13
@@ -47,7 +47,7 @@
/* prototypes */
void usage(void);
-void print_comments(FILE *out, vorbis_comment *vc);
+void print_comments(FILE *out, vorbis_comment *vc, char *encoding);
int add_comment(char *line, vorbis_comment *vc, char *encoding);
param_t *new_param(void);
@@ -98,7 +98,7 @@
/* extract and display the comments */
vc = vcedit_comments(state);
- print_comments(param->com, vc);
+ print_comments(param->com, vc, param->encoding);
/* done */
vcedit_clear(state);
@@ -177,12 +177,21 @@
***********/
-void print_comments(FILE *out, vorbis_comment *vc)
+void print_comments(FILE *out, vorbis_comment *vc, char *encoding)
{
int i;
+ char *decoded_value;
for (i = 0; i < vc->comments; i++)
- fprintf(out, "%s\n", vc->user_comments[i]);
+ {
+ if (utf8_decode(vc->user_comments[i], &decoded_value, encoding) == 0)
+ {
+ fprintf(out, "%s\n", decoded_value);
+ free(decoded_value);
+ }
+ else
+ fprintf(out, "%s\n", vc->user_comments[i]);
+ }
}
/**********
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list