comparison scripts/plot/print.m @ 9847:131d8c70920a

print.m: Properly set the default ghostscript_binary under Windows.
author Ben Abbott <bpabbott@mac.com>
date Sun, 22 Nov 2009 16:47:39 -0500
parents 09da0bd91412
children 9c4f403bec2b
comparison
equal deleted inserted replaced
9846:1d90fc211872 9847:131d8c70920a
187 debug = false; 187 debug = false;
188 debug_file = "octave-print-commands.log"; 188 debug_file = "octave-print-commands.log";
189 special_flag = "textnormal"; 189 special_flag = "textnormal";
190 tight_flag = false; 190 tight_flag = false;
191 resolution = ""; 191 resolution = "";
192 if (isunix ()) 192
193 persistent ghostscript_binary = "gs"; 193 persistent ghostscript_binary = "";
194 elseif (ispc ()) 194 if (isempty (ghostscript_binary))
195 if (~isempty (getenv ("GSC"))) 195 ghostscript_binary = getenv ("GSC");
196 persistent ghostscript_binary = getenv ("GSC"); 196 ng = 0;
197 if (isunix ())
198 ## Unix - Includes Mac OSX and Cygwin.
199 gs_binaries = {"gs", "gs.exe"};
197 else 200 else
198 persistent ghostscript_binary = "gswin32c"; 201 ## pc - Includes Win32 and mingw.
199 endif 202 gs_binaries = {"gs.exe", "gswin32c.exe"};
203 endif
204 while (ng < numel (gs_binaries) && isempty (ghostscript_binary))
205 ng = ng + 1;
206 ghostscript_binary = file_in_path (EXEC_PATH, gs_binaries{ng});
207 endwhile
200 endif 208 endif
201 209
202 old_fig = get (0, "currentfigure"); 210 old_fig = get (0, "currentfigure");
203 unwind_protect 211 unwind_protect
204 ## Ensure the last figure is on the screen for single line commands like 212 ## Ensure the last figure is on the screen for single line commands like
233 devopt = tolower(arg(3:end)); 241 devopt = tolower(arg(3:end));
234 elseif (length (arg) > 2 && arg(1:2) == "-P") 242 elseif (length (arg) > 2 && arg(1:2) == "-P")
235 printer = arg; 243 printer = arg;
236 elseif ((length (arg) > 2) && arg(1:2) == "-G") 244 elseif ((length (arg) > 2) && arg(1:2) == "-G")
237 ghostscript_binary = arg(3:end); 245 ghostscript_binary = arg(3:end);
246 if (exist (ghostscript_binary, "file") != 2)
247 ghostscript_binary = file_in_path (EXEC_PATH, ghostscript_binary);
248 endif
249 if (isempty (ghostscript_binary))
250 error ("print.m: Ghostscript binary ""%s"" could not be located", arg(3:end))
251 endif
238 elseif (length (arg) > 2 && arg(1:2) == "-F") 252 elseif (length (arg) > 2 && arg(1:2) == "-F")
239 idx = rindex (arg, ":"); 253 idx = rindex (arg, ":");
240 if (idx) 254 if (idx)
241 font = arg(3:idx-1); 255 font = arg(3:idx-1);
242 fontsize = arg(idx+1:length(arg)); 256 fontsize = arg(idx+1:length(arg));
257 else 271 else
258 error ("print: expecting inputs to be character string options or a figure handle"); 272 error ("print: expecting inputs to be character string options or a figure handle");
259 endif 273 endif
260 endfor 274 endfor
261 275
262 if (isunix ()) 276 have_ghostscript = (exist (ghostscript_binary, "file") == 2);
263 [status, output] = system (sprintf ("which %s 2>&1", ghostscript_binary));
264 have_ghostscript = (status == 0);
265 elseif (ispc ())
266 [status, output] = system (sprintf ("if exist \"%s\" ( exit /B 1 ) else ( exit /B 0 )", ghostscript_binary));
267 have_ghostscript = (status ~= 0);
268 endif
269 277
270 doprint = isempty (name); 278 doprint = isempty (name);
271 if (doprint) 279 if (doprint)
272 if (isempty (devopt)) 280 if (isempty (devopt))
273 if (use_color < 0) 281 if (use_color < 0)