[Vorbis-dev] [PATCH] Make vorbiscomment escape whitespace characters

Łukasz Stelmach
Sun, 05 May 2013 19:22:16 -0000

Make "vorbiscomment -e" escape the space (0x20) and tab (0x09)
characters. With this patch in place it is possible to use vorbiscomment
output with the "eval" command in shellscripts like:

    eval `vorbiscomment -e foo.ogg`
    test -z "$ARTIST" && echo Anonymous || echo $ARTIST

Signed-off-by: ?ukasz Stelmach <stlman at poczta.fm>
---
 vorbiscomment/vcomment.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/vorbiscomment/vcomment.c b/vorbiscomment/vcomment.c
index 3208410..2b33274 100644
--- a/vorbiscomment/vcomment.c
+++ b/vorbiscomment/vcomment.c
@@ -422,6 +422,14 @@ char *escape(const char *from, int fromsize)
 	char *s;
 	for (s = to; fromsize > 0; fromsize--, from++) {
 		switch (*from) {
+		case ' ':
+			*s++ = '\\';
+			*s++ = ' ';
+			break;
+		case '\t':
+			*s++ = '\\';
+			*s++ = 't';
+			break;
 		case '\n':
 			*s++ = '\\';
 			*s++ = 'n';
@@ -473,6 +481,12 @@ char *unescape(const char *from, int *tosize)
 		if (*from == '\\') {
 			from++;
 			switch (*from++) {
+			case ' ':
+				*s++ = ' ';
+				break;
+			case 't':
+				*s++ = '\t';
+				break;
 			case 'n':
 				*s++ = '\n';
 				break;
--
1.8.1.5