# HG changeset patch
# User Ben Abbott  <bpabbott@mac.com>
# Date 1295127166 18000
# Node ID 6311072873fa7679c3aa0f9d7fa0de100f0f4ff9
# Parent  a34ccc8e2f8e83cee0896b9cd11ab5369e2dbc40
print.m: For the DOS shell, connect the pipe to ghostscript. When needed, redirect to NUL instead of /dev/null.

diff --git a/scripts/ChangeLog b/scripts/ChangeLog
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,8 @@
+2011-01-15  Ben Abbott <bpabbott@mac.com>
+
+	* plot/print.m: For the DOS shell, connect the pipe to ghostscript.
+	When needed, redirect to NUL instead of /dev/null.
+
 2011-01-15  John W. Eaton  <jwe@octave.org>
 
 	* deprecated/krylovb: Move here from linear-algebra.
diff --git a/scripts/plot/print.m b/scripts/plot/print.m
--- a/scripts/plot/print.m
+++ b/scripts/plot/print.m
@@ -320,15 +320,19 @@
         h = setdiff (h, hnone);
         m = numel (props);
         for n = 1:numel(h)
-          rgb = get (h(n), color_props{c});
-          props(m+n).h = h(n);
-          props(m+n).name = color_props{c};
-          props(m+n).value = {get(h(n), color_props{c})};
-          xfer = repmat ([0.30, 0.59, 0.11], size (rgb, 1), 1);
-          if (isnumeric (rgb))
-            ## convert RGB color to RGB gray scale
-            ggg = repmat (sum (xfer .* rgb, 2), 1, 3);
-            set (h(n), color_props{c}, ggg)
+          if (ishandle (h(n)))
+            ## Need to verify objects exist since callbacks may delete objects
+            ## as the colors for others are modified.
+            rgb = get (h(n), color_props{c});
+            props(end+1).h = h(n);
+            props(end).name = color_props{c};
+            props(end).value = {get(h(n), color_props{c})};
+            if (isnumeric (rgb))
+              ## convert RGB color to RGB gray scale
+              xfer = repmat ([0.30, 0.59, 0.11], size (rgb, 1), 1);
+              ggg = repmat (sum (xfer .* rgb, 2), 1, 3);
+              set (h(n), color_props{c}, ggg)
+            endif
           endif
         endfor
       endfor
@@ -400,7 +404,7 @@
   ## output must be piped.
 
   ## DOS Shell:
-  ##   copy con <filein> & epstool -bbox -preview-tiff <filein> <fileout> & del <filein>
+  ##   gs.exe [...] -sOutputFile=<filein> - & epstool -bbox -preview-tiff <filein> <fileout> & del <filein>
   ## Unix Shell;
   ##   cat > <filein> ; epstool -bbox -preview-tiff <filein> <fileout> ; rm <filein>
 
@@ -473,7 +477,11 @@
       endif
       if (pipein)
         if (dos_shell)
-          cmd = sprintf ("copy con %s & %s", filein, cmd);
+          gs_cmd = __ghostscript__ ("binary", opts.ghostscript.binary,
+                                    "device", "epswrite",
+                                    "source", "-",
+                                    "output", filein)
+          cmd = sprintf ("%s %s & %s", gs_cmd, filein, cmd);
         else
           cmd = sprintf ("cat > %s ; %s", filein, cmd);
         endif
@@ -501,13 +509,21 @@
   else
     if (pipein && pipeout)
       if (dos_shell)
-        cmd = sprintf ("copy con %s & type %s", filein, fileout);
+        cmd = __ghostscript__ ("binary", opts.ghostscript.binary,
+                               "device", "epswrite",
+                               "source", "-",
+                               "output", "-");
       else
         cmd = " cat ";
       endif
     elseif (pipein && ! pipeout)
       if (dos_shell)
-        cmd = sprintf (" copy con %s ", fileout);
+        ## ghostscript expects double, not single, quotes
+        fileout(fileout="'") = "\"";
+        cmd = __ghostscript__ ("binary", opts.ghostscript.binary,
+                               "device", "epswrite",
+                               "source", "-",
+                               "output", fileout);
       else
         cmd = sprintf (" cat > %s ", fileout);
       endif
@@ -538,7 +554,7 @@
   if (! isempty (opts.fig2dev_binary))
     if (dos_shell)
       ## FIXME - is this the right thing to do for DOS?
-      cmd = sprintf ("%s -L %s 2> /dev/null", opts.fig2dev_binary, devopt);
+      cmd = sprintf ("%s -L %s 2> NUL", opts.fig2dev_binary, devopt);
     else
       cmd = sprintf ("%s -L %s 2> /dev/null", opts.fig2dev_binary, devopt);
     endif
@@ -611,7 +627,7 @@
   dos_shell = (ispc () && ! isunix ());
   if (! isempty (opts.pstoedit_binary))
     if (dos_shell)
-      cmd = sprintf ("%s -f %s 2> /dev/null", opts.pstoedit_binary, devopt);
+      cmd = sprintf ("%s -f %s 2> NUL", opts.pstoedit_binary, devopt);
     else
       ## FIXME - is this the right thing to do for DOS?
       cmd = sprintf ("%s -f %s 2> /dev/null", opts.pstoedit_binary, devopt);
