From 39fdeb0c9ae2fd180dd7063cbce562ec1b89f4af Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 17 May 2015 17:34:29 +0200 Subject: [PATCH] src/frontend/plotting/gnuplot.c, enforce "noenhanced text" mode Contrary to older versions gnuplot 5 uses "enhanced text mode" per default. The strings which we pass to gnuplot don't have "latex" semantics, thus consistently enforce "noenhanced text mode". Add a function quote_gnuplot_string() to escape and quote strings in such a way that they will arrive in gnuplot unmodified. --- src/frontend/plotting/gnuplot.c | 46 +++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/src/frontend/plotting/gnuplot.c b/src/frontend/plotting/gnuplot.c index 8c83d4887..5e29a644a 100644 --- a/src/frontend/plotting/gnuplot.c +++ b/src/frontend/plotting/gnuplot.c @@ -21,6 +21,27 @@ #define GP_MAXVECTORS 64 +static void +quote_gnuplot_string(FILE *stream, char *s) +{ + fputc('"', stream); + + for (; *s; s++) + switch (*s) { + case '\n': + fputs("\\n", stream); + break; + case '"': + case '\\': + fputc('\\', stream); + default: + fputc(*s, stream); + } + + fputc('"', stream); +} + + void ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlabel, char *ylabel, GRIDTYPE gridtype, PLOTTYPE plottype, struct dvec *vecs) { @@ -111,21 +132,29 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab /* Set up the file header. */ #if !defined(__MINGW__) && !defined(_MSC_VER) - fprintf(file, "set terminal X11\n"); + fprintf(file, "set terminal X11 noenhanced\n"); +#else + fprintf(file, "set termoption noenhanced\n"); #endif if (title) { text = cp_unquote(title); - fprintf(file, "set title \"%s\"\n", text); + fprintf(file, "set title "); + quote_gnuplot_string(file, text); + fprintf(file, "\n"); tfree(text); } if (xlabel) { text = cp_unquote(xlabel); - fprintf(file, "set xlabel \"%s\"\n", text); + fprintf(file, "set xlabel "); + quote_gnuplot_string(file, text); + fprintf(file, "\n"); tfree(text); } if (ylabel) { text = cp_unquote(ylabel); - fprintf(file, "set ylabel \"%s\"\n", text); + fprintf(file, "set ylabel "); + quote_gnuplot_string(file, text); + fprintf(file, "\n"); tfree(text); } if (!nogrid) { @@ -197,17 +226,18 @@ ft_gnuplot(double *xlims, double *ylims, char *filename, char *title, char *xlab if (v->v_name) { i = i + 2; if (i > 2) fprintf(file, ",\\\n"); - fprintf(file, "\'%s\' using %d:%d with %s lw %d title \"%s\" ", - filename_data, i-1, i, plotstyle, linewidth, v->v_name); + fprintf(file, "\'%s\' using %d:%d with %s lw %d title ", + filename_data, i-1, i, plotstyle, linewidth); + quote_gnuplot_string(file, v->v_name); } } fprintf(file, "\n"); fprintf(file, "set terminal push\n"); if (terminal_type == 1) { - fprintf(file, "set terminal postscript eps color\n"); + fprintf(file, "set terminal postscript eps color noenhanced\n"); fprintf(file, "set out \'%s.eps\'\n", filename); } else { - fprintf(file, "set terminal png\n"); + fprintf(file, "set terminal png noenhanced\n"); fprintf(file, "set out \'%s.png\'\n", filename); } fprintf(file, "replot\n");