summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorPaolo Capriotti <p.capriotti@gmail.com>2012-03-22 20:16:27 +0000
committerPaolo Capriotti <p.capriotti@gmail.com>2012-03-22 20:18:34 +0000
commitee8bf699516dd8e603e26a7c862538e83da2c250 (patch)
tree23470ff249b2c5fbb9e36d332ab28a0b6d8967bd /utils
parent7441207a0d9dde743b0c25a177de26799b55fea8 (diff)
downloadhaskell-ee8bf699516dd8e603e26a7c862538e83da2c250.tar.gz
hp2ps: escape backslashes when generating output file (#5800).
Diffstat (limited to 'utils')
-rw-r--r--utils/hp2ps/Key.c22
1 files changed, 20 insertions, 2 deletions
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 <stdio.h>
#include <math.h>
+#include <string.h>
+#include <stdlib.h>
#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);
}