changeset 27622:df8942d19b7b

Allow printing with Octave installed in path with parenthesis (bug #49718) * print.m (pstoedit, svgconvert, fig2dev, epstool), __ghostscript__.m: Quote file names and escape strings that will be used as format strings. * __opengl_print__.m: Ditto. On Windows, quote the complete string for the pipe because it has a strange logic that sometimes removes the outer quotes.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Mon, 02 Sep 2019 21:21:58 +0200
parents 39fac14ab25a
children 698c8b08fe8c
files scripts/plot/util/print.m scripts/plot/util/private/__ghostscript__.m scripts/plot/util/private/__opengl_print__.m
diffstat 3 files changed, 29 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/util/print.m	Sun Nov 03 10:09:15 2019 -0500
+++ b/scripts/plot/util/print.m	Mon Sep 02 21:21:58 2019 +0200
@@ -824,9 +824,9 @@
     pipein = true;
     filein = [tempname() ".eps"];
     if (dos_shell)
-      cleanup = sprintf ("& del %s ", strrep (filein, '/', '\'));
+      cleanup = sprintf ('& del "%s" ', strrep (filein, '/', '\'));
     else
-      cleanup = sprintf ("; rm %s ", filein);
+      cleanup = sprintf ('; rm "%s" ', filein);
     endif
   else
     pipein = false;
@@ -836,9 +836,9 @@
     pipeout = true;
     fileout = [tempname() ".eps"];
     if (dos_shell)
-      cleanup = [cleanup, sprintf("& del %s ", strrep (fileout, '/', '\'))];
+      cleanup = [cleanup, sprintf('& del "%s" ', strrep (fileout, '/', '\'))];
     else
-      cleanup = [cleanup, sprintf("; rm %s ", fileout)];
+      cleanup = [cleanup, sprintf('; rm "%s" ', fileout)];
     endif
   else
     pipeout = false;
@@ -1078,15 +1078,15 @@
       cmd = sprintf ("%s -f %s 2> NUL", opts.pstoedit_binary, devopt);
     else
       cmd = sprintf ("%s -f %s 2> /dev/null", opts.pstoedit_binary, devopt);
-      endi;f
     endif
   else
     cmd = svgconvert (opts, devopt);
     if (dos_shell)
-      cmd = sprintf ("%s & %s -ssp -f %s %%s 2> NUL", cmd, ...
-                     opts.pstoedit_binary, devopt);
+      cmd = sprintf ('%s & %s -ssp -f %s "%%s" 2> NUL', cmd, ...
+                     undo_string_escapes (opts.pstoedit_binary), ...
+                     undo_string_escapes (devopt));
     else
-      cmd = sprintf ("%s ; %s -ssp -f %s %%s 2> /dev/null", cmd,  ...
+      cmd = sprintf ('%s ; %s -ssp -f %s "%%s" 2> /dev/null', cmd,  ...
                      opts.pstoedit_binary, devopt);
     endif
   endif
@@ -1116,9 +1116,10 @@
       fontdir = __octave_config_info__ ("octfontsdir");
     endif
 
-    cmd = sprintf ("%s - %%s %3.2f %s %d \"%%s\"", opts.svgconvert_binary, ...
+    cmd = sprintf ('%s - %%s %3.2f "%s" %d "%%s"', ...
+                   undo_string_escapes (opts.svgconvert_binary), ...
                    get (0, "screenpixelsperinch"), ...
-                   fullfile (fontdir, "FreeSans.otf"), 1);
+                   undo_string_escapes (fullfile (fontdir, "FreeSans.otf")), 1);
 
     if (opts.debug)
       fprintf ("svgconvert command: '%s'\n", cmd);
--- a/scripts/plot/util/private/__ghostscript__.m	Sun Nov 03 10:09:15 2019 -0500
+++ b/scripts/plot/util/private/__ghostscript__.m	Mon Sep 02 21:21:58 2019 +0200
@@ -124,9 +124,9 @@
     else
       offsetfile = [tempname() ".ps"];
       if (dos_shell)
-        cleanup_cmd = ["del " strrep(offsetfile, '/', '\')];
+        cleanup_cmd = sprintf ('del "%s"', strrep (offsetfile, '/', '\'));
       else
-        cleanup_cmd = ["rm " offsetfile];
+        cleanup_cmd = sprintf ('rm "%s"', strrep (offsetfile, '/', '\'));
       endif
     endif
     unwind_protect
@@ -176,7 +176,7 @@
     endif
   endif
   if (! isempty (offsetfile) && format_for_printer)
-    cmd = sprintf ("%s %s", cmd, offsetfile);
+    cmd = sprintf ('%s "%s"', cmd, offsetfile);
   endif
   if (! isempty (opts.source))
     cmd = sprintf ("%s %s", cmd, opts.source);
--- a/scripts/plot/util/private/__opengl_print__.m	Sun Nov 03 10:09:15 2019 -0500
+++ b/scripts/plot/util/private/__opengl_print__.m	Mon Sep 02 21:21:58 2019 +0200
@@ -65,16 +65,16 @@
       gl2ps_device{2} = "tex";
       if (dos_shell)
         ## FIXME: this will only work on MinGW with the MSYS shell
-        pipeline = {sprintf("cat > %s-inc.%s", name, suffix)};
-        pipeline{2} = sprintf ("cat > %s.tex", name);
+        pipeline = {sprintf('cat > "%s-inc.%s"', name, suffix)};
+        pipeline{2} = sprintf ('cat > "%s.tex"', name);
       else
-        pipeline = {sprintf("cat > %s-inc.%s", name, suffix)};
-        pipeline{2} = sprintf ("cat > %s.tex", name);
+        pipeline = {sprintf('cat > "%s-inc.%s"', name, suffix)};
+        pipeline{2} = sprintf ('cat > "%s.tex"', name);
       endif
     case "tikz"
       ## format GL2PS_PGF
       gl2ps_device = {"pgf"};
-      pipeline = {sprintf("cat > %s", opts.name)};
+      pipeline = {sprintf('cat > "%s"', opts.name)};
     case "svg"
       ## format GL2PS_SVG
       gl2ps_device = {"svg"};
@@ -85,7 +85,7 @@
       if (! isempty (svgcmd))
         pipeline = {sprintf(svgcmd, "svg", opts.name)};
       else
-        pipeline = {sprintf("cat > %s", opts.name)};
+        pipeline = {sprintf('cat > "%s"', opts.name)};
       endif
     case fig2dev_devices
       cmd_fig2dev = opts.fig2dev_cmd (opts, opts.devopt);
@@ -96,12 +96,12 @@
           opts.name = opts.name(1:end-numel(ext));
         endif
         opts.name = [opts.name ".ps"];
-        cmd = sprintf ("%s | %s > %s", cmd_pstoedit, cmd_fig2dev, opts.name);
+        cmd = sprintf ('%s | %s > "%s"', cmd_pstoedit, cmd_fig2dev, opts.name);
         gl2ps_device = {"eps"};
         pipeline = {cmd};
         cmd_fig2dev = opts.fig2dev_cmd (opts, "pstex_t");
         gl2ps_device{2} = "eps";
-        pipeline{2} = sprintf ("%s | %s > %s", cmd_pstoedit,
+        pipeline{2} = sprintf ('%s | %s > "%s"', cmd_pstoedit,
                                cmd_fig2dev, strrep(opts.name, ".ps", ".tex"));
       else
         ## Using svgconvert
@@ -109,7 +109,7 @@
         opts.unlink = [opts.unlink tmp];
         cmd_pstoedit = sprintf (opts.pstoedit_cmd (opts, "fig"), ...
                                 "pdf", tmp, tmp);
-        cmd = sprintf ("%s | %s > %s", cmd_pstoedit, cmd_fig2dev, opts.name);
+        cmd = sprintf ('%s | %s > "%s"', cmd_pstoedit, cmd_fig2dev, opts.name);
         gl2ps_device = {"svg"};
         pipeline = {cmd};
       endif
@@ -124,7 +124,7 @@
       opts.unlink = [opts.unlink tmp];
       cmd = sprintf (opts.pstoedit_cmd (opts), "pdf", tmp, tmp);
       gl2ps_device = {"svg"};
-      pipeline = {sprintf("%s > %s", cmd, opts.name)};
+      pipeline = {sprintf('%s > "%s"', cmd, opts.name)};
     case opts.ghostscript.device
       svgcmd = "";
       if (opts.svgconvert)
@@ -193,7 +193,11 @@
             && (strcmp (get (opts.figure, "__gl_window__"), "on")
                 || __have_feature__ ("QT_OFFSCREEN"))))
       ## Use toolkits "print_figure" method
-      drawnow (gl2ps_device{n}, ['|' pipeline{n}]);
+      if (ispc () && ! isunix ())
+        drawnow (gl2ps_device{n}, ['| "' pipeline{n} '"']);
+      else
+        drawnow (gl2ps_device{n}, ["| " pipeline{n}]);
+      endif
     else
       error ("print: figure must be visible or qt toolkit must be used with __gl_window__ property 'on' or QT_OFFSCREEN feature available");
     endif