comparison src/toplev.cc @ 3834:414e694c9e6a

[project @ 2001-05-17 13:45:41 by jwe]
author jwe
date Thu, 17 May 2001 13:45:42 +0000
parents 1a809dae77db
children bbe74a066592
comparison
equal deleted inserted replaced
3833:f3278ec3ccb7 3834:414e694c9e6a
86 tree_statement_list *global_command = 0; 86 tree_statement_list *global_command = 0;
87 87
88 // Pointer to function that is currently being evaluated. 88 // Pointer to function that is currently being evaluated.
89 octave_user_function *curr_function = 0; 89 octave_user_function *curr_function = 0;
90 90
91 // Original value of TEXMFDBS environment variable.
92 std::string octave_original_texmfdbs;
93
91 // Top level context (?) 94 // Top level context (?)
92 jmp_buf toplevel; 95 jmp_buf toplevel;
93 96
94 int 97 int
95 main_loop (void) 98 main_loop (void)
379 error ("unable to start subprocess for `%s'", cmd_str.c_str ()); 382 error ("unable to start subprocess for `%s'", cmd_str.c_str ());
380 383
381 return retval; 384 return retval;
382 } 385 }
383 386
387 static void
388 restore_texmfdbs_envvar (void *ptr)
389 {
390 std::string *s = static_cast<std::string *> (ptr);
391
392 octave_env::putenv ("TEXMFDBS", *s);
393 }
394
384 DEFUN (system, args, nargout, 395 DEFUN (system, args, nargout,
385 "-*- texinfo -*-\n\ 396 "-*- texinfo -*-\n\
386 @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})\n\ 397 @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})\n\
387 Execute a shell command specified by @var{string}. The second\n\ 398 Execute a shell command specified by @var{string}. The second\n\
388 argument is optional. If @var{type} is @code{\"async\"}, the process\n\ 399 argument is optional. If @var{type} is @code{\"async\"}, the process\n\
422 will set the variable @code{output} to the string @samp{foo}, and the\n\ 433 will set the variable @code{output} to the string @samp{foo}, and the\n\
423 variable @code{status} to the integer @samp{2}.\n\ 434 variable @code{status} to the integer @samp{2}.\n\
424 @end deftypefn") 435 @end deftypefn")
425 { 436 {
426 octave_value_list retval; 437 octave_value_list retval;
438
439 unwind_protect::begin_frame ("Fsystem");
427 440
428 int nargin = args.length (); 441 int nargin = args.length ();
429 442
430 if (nargin > 0 && nargin < 4) 443 if (nargin > 0 && nargin < 4)
431 { 444 {
459 else 472 else
460 error ("system: expecting std::string as first argument"); 473 error ("system: expecting std::string as first argument");
461 474
462 if (! error_state) 475 if (! error_state)
463 { 476 {
477 // The value of TEXMFDBS that Octave puts in the environment
478 // will cause trouble if we are asked to run TeX, so we
479 // should reset it to whatever it was before Octave started.
480 //
481 // XXX FIXME XXX -- it would be better to fix the
482 // kpathsearch library to not always do TeX-specific
483 // things...
484
485 static string odb;
486
487 odb = octave_env::getenv ("TEXMFDBS");
488
489 unwind_protect::add (restore_texmfdbs_envvar, &odb);
490
491 octave_env::putenv ("TEXMFDBS", octave_original_texmfdbs);
492
464 if (type == async) 493 if (type == async)
465 { 494 {
466 pid_t pid = fork (); 495 pid_t pid = fork ();
467 496
468 if (pid < 0) 497 if (pid < 0)
497 } 526 }
498 } 527 }
499 } 528 }
500 else 529 else
501 print_usage ("system"); 530 print_usage ("system");
531
532 unwind_protect::run_frame ("Fsystem");
502 533
503 return retval; 534 return retval;
504 } 535 }
505 536
506 DEFALIAS (shell_cmd, system); 537 DEFALIAS (shell_cmd, system);