summaryrefslogtreecommitdiff
path: root/src/metaflac
diff options
context:
space:
mode:
authorErik de Castro Lopo <erikd@mega-nerd.com>2013-04-21 18:05:21 +1000
committerErik de Castro Lopo <erikd@mega-nerd.com>2013-04-21 18:05:25 +1000
commitf9d33d96e579cb4619b01eee772e1e8f1fab8adf (patch)
treec1edc272d1d61035a47a6d58a7a7cec62c67cbf3 /src/metaflac
parente8ffe523f8b2703a27983d2717cb36f7ed02e7c9 (diff)
downloadflac-f9d33d96e579cb4619b01eee772e1e8f1fab8adf.tar.gz
Metaflac hex dump UTF-8 and locale fix.
Change metaflac hexdump function so utf-8 decoding is only used for filename printing and changed hex output printing to not rely only on isprint. That function seems to return true for tabulator control character under Windows when application isn't using C-locale. Patch (with one minor tweak) from Janne Hyvärinen <cse@sci.fi>.
Diffstat (limited to 'src/metaflac')
-rw-r--r--src/metaflac/utils.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/metaflac/utils.c b/src/metaflac/utils.c
index af17d5ba..8b910110 100644
--- a/src/metaflac/utils.c
+++ b/src/metaflac/utils.c
@@ -77,17 +77,23 @@ void local_strcat(char **dest, const char *source)
safe_strncpy((*dest)+ndest, source, ndest + nsource + 1);
}
+static inline int local_isprint(int c)
+{
+ if (c < 32) return 0;
+ return isprint(c);
+}
+
void hexdump(const char *filename, const FLAC__byte *buf, unsigned bytes, const char *indent)
{
unsigned i, left = bytes;
const FLAC__byte *b = buf;
for(i = 0; i < bytes; i += 16) {
- flac_printf("%s%s%s%08X: "
+ flac_printf("%s%s", filename? filename:"", filename? ":":"");
+ printf("%s%08X: "
"%02X %02X %02X %02X %02X %02X %02X %02X "
"%02X %02X %02X %02X %02X %02X %02X %02X "
"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n",
- filename? filename:"", filename? ":":"",
indent, i,
left > 0? (unsigned char)b[ 0] : 0,
left > 1? (unsigned char)b[ 1] : 0,
@@ -105,22 +111,22 @@ void hexdump(const char *filename, const FLAC__byte *buf, unsigned bytes, const
left > 13? (unsigned char)b[13] : 0,
left > 14? (unsigned char)b[14] : 0,
left > 15? (unsigned char)b[15] : 0,
- (left > 0) ? (isprint(b[ 0]) ? b[ 0] : '.') : ' ',
- (left > 1) ? (isprint(b[ 1]) ? b[ 1] : '.') : ' ',
- (left > 2) ? (isprint(b[ 2]) ? b[ 2] : '.') : ' ',
- (left > 3) ? (isprint(b[ 3]) ? b[ 3] : '.') : ' ',
- (left > 4) ? (isprint(b[ 4]) ? b[ 4] : '.') : ' ',
- (left > 5) ? (isprint(b[ 5]) ? b[ 5] : '.') : ' ',
- (left > 6) ? (isprint(b[ 6]) ? b[ 6] : '.') : ' ',
- (left > 7) ? (isprint(b[ 7]) ? b[ 7] : '.') : ' ',
- (left > 8) ? (isprint(b[ 8]) ? b[ 8] : '.') : ' ',
- (left > 9) ? (isprint(b[ 9]) ? b[ 9] : '.') : ' ',
- (left > 10) ? (isprint(b[10]) ? b[10] : '.') : ' ',
- (left > 11) ? (isprint(b[11]) ? b[11] : '.') : ' ',
- (left > 12) ? (isprint(b[12]) ? b[12] : '.') : ' ',
- (left > 13) ? (isprint(b[13]) ? b[13] : '.') : ' ',
- (left > 14) ? (isprint(b[14]) ? b[14] : '.') : ' ',
- (left > 15) ? (isprint(b[15]) ? b[15] : '.') : ' '
+ (left > 0) ? (local_isprint(b[ 0]) ? b[ 0] : '.') : ' ',
+ (left > 1) ? (local_isprint(b[ 1]) ? b[ 1] : '.') : ' ',
+ (left > 2) ? (local_isprint(b[ 2]) ? b[ 2] : '.') : ' ',
+ (left > 3) ? (local_isprint(b[ 3]) ? b[ 3] : '.') : ' ',
+ (left > 4) ? (local_isprint(b[ 4]) ? b[ 4] : '.') : ' ',
+ (left > 5) ? (local_isprint(b[ 5]) ? b[ 5] : '.') : ' ',
+ (left > 6) ? (local_isprint(b[ 6]) ? b[ 6] : '.') : ' ',
+ (left > 7) ? (local_isprint(b[ 7]) ? b[ 7] : '.') : ' ',
+ (left > 8) ? (local_isprint(b[ 8]) ? b[ 8] : '.') : ' ',
+ (left > 9) ? (local_isprint(b[ 9]) ? b[ 9] : '.') : ' ',
+ (left > 10) ? (local_isprint(b[10]) ? b[10] : '.') : ' ',
+ (left > 11) ? (local_isprint(b[11]) ? b[11] : '.') : ' ',
+ (left > 12) ? (local_isprint(b[12]) ? b[12] : '.') : ' ',
+ (left > 13) ? (local_isprint(b[13]) ? b[13] : '.') : ' ',
+ (left > 14) ? (local_isprint(b[14]) ? b[14] : '.') : ' ',
+ (left > 15) ? (local_isprint(b[15]) ? b[15] : '.') : ' '
);
left -= 16;
b += 16;