# HG changeset patch
# User Pantxo Diribarne <pantxo.diribarne@gmail.com>
# Date 1567452118 -7200
#      Mon Sep 02 21:21:58 2019 +0200
# Node ID 15cb240227eedbafcb9e5aeb583668edec11b93c
# Parent  45bb5bbaf2913e4a52190d45e542618eb20f74df
Allow printing with Octave installed in path with parenthesis (bug #49718)

* print.m (pstoedit, svgconvert, fig2dev, epstool): Quote binary and file path.
* __ghostscript__.m: Ditto.
* __opengl_print__.m: Ditto.

diff -r 45bb5bbaf291 -r 15cb240227ee scripts/plot/util/print.m
--- a/scripts/plot/util/print.m	Fri Nov 01 18:16:49 2019 -0400
+++ 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);
diff -r 45bb5bbaf291 -r 15cb240227ee scripts/plot/util/private/__ghostscript__.m
--- a/scripts/plot/util/private/__ghostscript__.m	Fri Nov 01 18:16:49 2019 -0400
+++ 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);
diff -r 45bb5bbaf291 -r 15cb240227ee scripts/plot/util/private/__opengl_print__.m
--- a/scripts/plot/util/private/__opengl_print__.m	Fri Nov 01 18:16:49 2019 -0400
+++ 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
