From ee8bf699516dd8e603e26a7c862538e83da2c250 Mon Sep 17 00:00:00 2001
From: Paolo Capriotti
Date: Thu, 22 Mar 2012 20:16:27 +0000
Subject: hp2ps: escape backslashes when generating output file (#5800).
---
utils/hp2ps/Key.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
(limited to 'utils/hp2ps/Key.c')
diff --git a/utils/hp2ps/Key.c b/utils/hp2ps/Key.c
index 5fa76ab6d7..eda839597a 100644
--- a/utils/hp2ps/Key.c
+++ b/utils/hp2ps/Key.c
@@ -1,11 +1,14 @@
#include "Main.h"
#include
#include
+#include
+#include
#include "Defines.h"
#include "Dimensions.h"
#include "HpFile.h"
#include "Shade.h"
#include "PsFile.h"
+#include "Utilities.h"
/* own stuff */
#include "Key.h"
@@ -36,7 +39,18 @@ void Key(void)
}
}
-
+static void
+escape(char *result, const char *name)
+{
+ while (*name != '\0')
+ {
+ if (*name == '\\')
+ {
+ *result++ = '\\';
+ }
+ *result++ = *name++;
+ }
+}
static void
KeyEntry(floatish centreline, char *name, floatish colour)
@@ -65,5 +79,9 @@ KeyEntry(floatish centreline, char *name, floatish colour)
fprintf(psfp, "HE%d setfont\n", NORMAL_FONT);
fprintf(psfp, "%f %f moveto\n", kstart + (floatish) KEY_BOX_WIDTH + 2 * borderspace, namebase);
- fprintf(psfp, "(%s) show\n", name);
+ // escape backslashes in 'name'
+ char *escaped_name = (char*) xmalloc(strlen(name) * 2 + 1);
+ escape(escaped_name, name);
+ fprintf(psfp, "(%s) show\n", escaped_name);
+ free(escaped_name);
}
--
cgit v1.2.1