Fixed memory leaks resulting from fn_interp_vars et. al.
[pspp-builds.git] / src / output / postscript.c
index f54ef1684f222ced82d22140d2c636c173748528..5d0d577607687132fb95cf7c5f2db8a23341d215 100644 (file)
 
 #include <config.h>
 
-/*this #if encloses the remainder of the file. */
-#if !NO_POSTSCRIPT
-
 #include <ctype.h>
 #include "chart.h"
-#include "message.h"
+#include <libpspp/message.h>
 #include <errno.h>
 #include <limits.h>
 #include <stdlib.h>
 #include <unistd.h>
 #endif
 
-#include "alloc.h"
-#include "bit-vector.h"
-#include "message.h"
-#include "filename.h"
+#include <libpspp/alloc.h>
+#include <libpspp/bit-vector.h>
+#include <libpspp/compiler.h>
+#include <libpspp/message.h>
+#include <data/filename.h>
 #include "font.h"
 #include "getline.h"
-#include "hash.h"
+#include <libpspp/hash.h>
 #include "intprops.h"
-#include "misc.h"
+#include <libpspp/misc.h>
 #include "output.h"
 #include "manager.h"
-#include "start-date.h"
-#include "version.h"
+#include <libpspp/start-date.h>
+#include <libpspp/version.h>
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -1395,8 +1393,8 @@ postopen (struct file_ext *f)
   
   if (!outp_title)
     {
-      dict[16].value = cp = local_alloc (strlen (dict[17].value) + 30);
-      sprintf (cp, "PSPP (%s)", dict[17].value);
+      dict[16].value = cp = local_alloc (16);
+      strcpy (cp, "PSPP");
     }
   else
     {
@@ -1408,7 +1406,7 @@ postopen (struct file_ext *f)
   while (-1 != getline (&buf, &buf_size, prologue_file))
     {
       char *cp;
-      char *buf2;
+
       int len;
 
       cp = strstr (buf, "!eps");
@@ -1438,18 +1436,16 @@ postopen (struct file_ext *f)
        output_encodings (this);
       else
        {
-         char *beg;
-         beg = buf2 = fn_interp_vars (buf, ps_get_var);
-         len = strlen (buf2);
-         while (isspace ((unsigned char) *beg))
-           beg++, len--;
-         if (beg[len - 1] == '\n')
-           len--;
-         if (beg[len - 1] == '\r')
-           len--;
-         fwrite (beg, len, 1, f->file);
+         struct string line;
+         ds_create(&line, buf);
+         fn_interp_vars(&line, ps_get_var);
+         ds_ltrim_spaces(&line);
+         len = ds_length(&line);
+         fwrite (ds_c_str(&line), len, 1, f->file);
+
+         ds_destroy(&line);
+
          fputs (x->eol, f->file);
-         free (buf2);
        }
     }
   if (ferror (f->file))
@@ -3044,5 +3040,3 @@ struct outp_class epsf_class =
   ps_chart_finalise
 
 };
-
-#endif /* NO_POSTSCRIPT */