Commit cd5e7f10 authored by Michael Smith's avatar Michael Smith

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).

svn path=/trunk/vorbis-tools/; revision=2086
parent 5a030214
......@@ -194,7 +194,47 @@ int simple_utf8_encode(const char *from, char **to, const char *encoding)
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)
......
......@@ -47,7 +47,7 @@ typedef struct {
/* 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 @@ int main(int argc, char **argv)
/* 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 @@ int main(int argc, char **argv)
***********/
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]);
}
}
/**********
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment