summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJanne Hyvärinen <cse@sci.fi>2013-04-25 08:58:08 +1000
committerErik de Castro Lopo <erikd@mega-nerd.com>2013-04-25 08:58:08 +1000
commitcc9f39216639f91c2f1cd800407fce91e4f49522 (patch)
tree79d7fa4186fa050283a442aee360c9e4635d7a83
parentf6585b0bdc22577b125342542087722dd97629a7 (diff)
downloadflac-cc9f39216639f91c2f1cd800407fce91e4f49522.tar.gz
Metaflac UTF-8 fixes (Windows)
Metaflac can now print all console supported characters from tags on the screen. It also fixes metaflac to be able to import its own exports back without non-ascii characters getting mutilated. And --no-utf8-convert now works properly with import and export commands. Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
-rw-r--r--src/metaflac/operations.c2
-rw-r--r--src/metaflac/operations_shorthand_vorbiscomment.c7
-rw-r--r--src/metaflac/utils.c10
-rw-r--r--src/share/utf8/utf8.c4
4 files changed, 16 insertions, 7 deletions
diff --git a/src/metaflac/operations.c b/src/metaflac/operations.c
index e01fa5c6..92352931 100644
--- a/src/metaflac/operations.c
+++ b/src/metaflac/operations.c
@@ -551,7 +551,7 @@ void write_metadata(const char *filename, FLAC__StreamMetadata *block, unsigned
unsigned i, j;
/*@@@ yuck, should do this with a varargs function or something: */
-#define PPR if(filename)flac_printf("%s:",filename);
+#define PPR if(filename) { if(raw) printf("%s:",filename); else flac_printf("%s:",filename); }
PPR; printf("METADATA block #%u\n", block_number);
PPR; printf(" type: %u (%s)\n", (unsigned)block->type, block->type < FLAC__METADATA_TYPE_UNDEFINED? FLAC__MetadataTypeString[block->type] : "UNKNOWN");
PPR; printf(" is last: %s\n", block->is_last? "true":"false");
diff --git a/src/metaflac/operations_shorthand_vorbiscomment.c b/src/metaflac/operations_shorthand_vorbiscomment.c
index 3d381a57..19f96029 100644
--- a/src/metaflac/operations_shorthand_vorbiscomment.c
+++ b/src/metaflac/operations_shorthand_vorbiscomment.c
@@ -96,7 +96,11 @@ FLAC__bool do_shorthand_operation__vorbis_comment(const char *filename, FLAC__bo
ok = remove_vc_firstfield(filename, block, operation->argument.vc_field_name.value, needs_write);
break;
case OP__SET_VC_FIELD:
+#ifdef _WIN32 /* do not convert anything or things will break */
+ ok = set_vc_field(filename, block, &operation->argument.vc_field, needs_write, true);
+#else
ok = set_vc_field(filename, block, &operation->argument.vc_field, needs_write, raw);
+#endif
break;
case OP__IMPORT_VC_FROM:
ok = import_vc_from(filename, block, &operation->argument.filename, needs_write, raw);
@@ -245,9 +249,7 @@ FLAC__bool set_vc_field(const char *filename, FLAC__StreamMetadata *block, const
}
else {
FLAC__bool needs_free = false;
-#ifdef _WIN32 /* do not convert anything or things will break */
entry.entry = (FLAC__byte *)field->field;
-#else
if(raw) {
entry.entry = (FLAC__byte *)field->field;
}
@@ -259,7 +261,6 @@ FLAC__bool set_vc_field(const char *filename, FLAC__StreamMetadata *block, const
flac_fprintf(stderr, "%s: ERROR: converting comment '%s' to UTF-8\n", filename, field->field);
return false;
}
-#endif
entry.length = strlen((const char *)entry.entry);
if(!FLAC__format_vorbiscomment_entry_is_legal(entry.entry, entry.length)) {
if(needs_free)
diff --git a/src/metaflac/utils.c b/src/metaflac/utils.c
index 8b910110..be5a3c1f 100644
--- a/src/metaflac/utils.c
+++ b/src/metaflac/utils.c
@@ -229,13 +229,18 @@ void write_vc_field(const char *filename, const FLAC__StreamMetadata_VorbisComme
{
if(0 != entry->entry) {
if(filename)
- fprintf(f, "%s:", filename);
+ flac_fprintf(f, "%s:", filename);
if(!raw) {
/*
* WATCHOUT: comments that contain an embedded null will
* be truncated by utf_decode().
*/
+#ifdef _WIN32 /* if we are outputting to console, we need to use proper print functions to show unicode characters */
+ if (f == stdout || f == stderr) {
+ flac_fprintf(f, "%s", entry->entry);
+ } else {
+#endif
char *converted;
if(utf8_decode((const char *)entry->entry, &converted) >= 0) {
@@ -245,6 +250,9 @@ void write_vc_field(const char *filename, const FLAC__StreamMetadata_VorbisComme
else {
(void) local_fwrite(entry->entry, 1, entry->length, f);
}
+#ifdef _WIN32
+ }
+#endif
}
else {
(void) local_fwrite(entry->entry, 1, entry->length, f);
diff --git a/src/share/utf8/utf8.c b/src/share/utf8/utf8.c
index beb815af..18495fef 100644
--- a/src/share/utf8/utf8.c
+++ b/src/share/utf8/utf8.c
@@ -203,7 +203,7 @@ int utf8_decode(const char *from, char **to)
return -1;
}
- chars = WideCharToMultiByte(GetConsoleCP(), WC_COMPOSITECHECK, unicode,
+ chars = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, unicode,
-1, NULL, 0, NULL, NULL);
if(chars < 0) /* underflow check */
@@ -224,7 +224,7 @@ int utf8_decode(const char *from, char **to)
return -1;
}
- err = WideCharToMultiByte(GetConsoleCP(), WC_COMPOSITECHECK, unicode,
+ err = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, unicode,
-1, *to, chars, NULL, NULL);
if(err != chars)
{