comparison src/octave.cc @ 1358:dc9c01f66a19

[project @ 1995-09-05 21:10:01 by jwe]
author jwe
date Tue, 05 Sep 1995 21:12:04 +0000
parents 94697d007075
children ed5757e3333b
comparison
equal deleted inserted replaced
1357:749071f48336 1358:dc9c01f66a19
157 static int read_init_files = 1; 157 static int read_init_files = 1;
158 158
159 // Nonzero means we printed messages about reading startup files. 159 // Nonzero means we printed messages about reading startup files.
160 static int reading_startup_message_printed = 0; 160 static int reading_startup_message_printed = 0;
161 161
162 // Nonzero means we don\'t print the usual startup message. 162 // Nonzero means we don't print the usual startup message.
163 // (--quiet; --silent; -q) 163 // (--quiet; --silent; -q)
164 static int inhibit_startup_message = 0; 164 static int inhibit_startup_message = 0;
165 165
166 // Usage message 166 // Usage message
167 static const char *usage_string = 167 static const char *usage_string =
168 "octave [-?Vdfhiqvx] [-p path] [--debug] [--help] [--ignore-init-file]\n\ 168 "octave [-?Vdfhiqvx] [-p path] [--debug] [--help] [--ignore-init-file]\n\
169 [--info-file file] [--interactive] [--path path] [--silent]\n\ 169 [--info-file file] [--interactive] [--path path] [--silent]\n\
170 [--verbose] [--version] [--echo-commands] [file]"; 170 [--verbose] [--version] [--echo-commands] [file]";
171 171
172 // This is here so that it\'s more likely that the usage message and 172 // This is here so that it's more likely that the usage message and
173 // the real set of options will agree. 173 // the real set of options will agree.
174 static const char *short_opts = "?Vdfhip:qvx"; 174 static const char *short_opts = "?Vdfhip:qvx";
175 175
176 // Long options. See the comments in getopt.h for the meanings of the 176 // Long options. See the comments in getopt.h for the meanings of the
177 // fields in this structure. 177 // fields in this structure.
261 sprintf (putenv_cmd, "PATH=%s" SEPCHAR_STR "%s", arch_dir, bin_dir); 261 sprintf (putenv_cmd, "PATH=%s" SEPCHAR_STR "%s", arch_dir, bin_dir);
262 } 262 }
263 263
264 putenv (putenv_cmd); 264 putenv (putenv_cmd);
265 265
266 // This may seem odd, but doing it this way means that we don't have 266 // This may seem odd, but doing it this way means that we don't have
267 // to modify the kpathsea library... 267 // to modify the kpathsea library...
268 268
269 char *odb = getenv ("OCTAVE_DB_DIR"); 269 char *odb = getenv ("OCTAVE_DB_DIR");
270 270
271 if (odb) 271 if (odb)
272 putenv (strconcat ("TEXMF=", odb)); 272 putenv (strconcat ("TEXMF=", odb));
381 unwind_protect_int (input_from_startup_file); 381 unwind_protect_int (input_from_startup_file);
382 input_from_startup_file = 1; 382 input_from_startup_file = 1;
383 383
384 int verbose = (verbose_flag && ! inhibit_startup_message); 384 int verbose = (verbose_flag && ! inhibit_startup_message);
385 385
386 // Execute commands from the site-wide configuration file. 386 // Execute commands from the site-wide configuration file.
387 387
388 char *sd = get_site_defaults (); 388 char *sd = get_site_defaults ();
389 389
390 parse_and_execute (sd, 0, verbose); 390 parse_and_execute (sd, 0, verbose);
391 391
392 // Try to execute commands from $HOME/.octaverc and ./.octaverc. 392 // Try to execute commands from $HOME/.octaverc and ./.octaverc.
393 393
394 char *home_rc = 0; 394 char *home_rc = 0;
395 if (home_directory) 395 if (home_directory)
396 { 396 {
397 home_rc = strconcat (home_directory, "/.octaverc"); 397 home_rc = strconcat (home_directory, "/.octaverc");
398 parse_and_execute (home_rc, 0, verbose); 398 parse_and_execute (home_rc, 0, verbose);
399 } 399 }
400 400
401 // Names alone are not enough. 401 // Names alone are not enough.
402 402
403 struct stat home_rc_statbuf; 403 struct stat home_rc_statbuf;
404 stat (home_rc, &home_rc_statbuf); 404 stat (home_rc, &home_rc_statbuf);
405 delete [] home_rc; 405 delete [] home_rc;
406 406
470 if (retval == EOF) 470 if (retval == EOF)
471 retval = 0; 471 retval = 0;
472 472
473 exit (retval); 473 exit (retval);
474 474
475 // This is bogus but should prevent g++ from giving a warning saying 475 // This is bogus but should prevent g++ from giving a warning saying
476 // that this volatile function does return. 476 // that this volatile function does return.
477 477
478 panic_impossible (); 478 panic_impossible ();
479 } 479 }
480 480
481 static void 481 static void
496 // You guessed it. 496 // You guessed it.
497 497
498 int 498 int
499 main (int argc, char **argv) 499 main (int argc, char **argv)
500 { 500 {
501 // The order of these calls is important, and initialize_globals must 501 // The order of these calls is important, and initialize_globals
502 // come before the options are processed because some command line 502 // must come before the options are processed because some command
503 // options override defaults. 503 // line options override defaults.
504 504
505 init_user_prefs (); 505 init_user_prefs ();
506 506
507 initialize_pager (); 507 initialize_pager ();
508 508
565 break; 565 break;
566 } 566 }
567 } 567 }
568 568
569 #if defined (HAVE_ATEXIT) || (HAVE_ON_EXIT) 569 #if defined (HAVE_ATEXIT) || (HAVE_ON_EXIT)
570 // Make sure we clean up when we exit. If we don't have atexit or 570 // Make sure we clean up when we exit. If we don't have atexit or
571 // on_exit, we're going to leave some junk files around if we exit 571 // on_exit, we're going to leave some junk files around if we exit
572 // abnormally. 572 // abnormally.
573 atexit (cleanup_tmp_files); 573 atexit (cleanup_tmp_files);
574 #endif 574 #endif
575 575
576 // These can come after command line args since none of them set any 576 // These can come after command line args since none of them set any
577 // defaults that might be changed by command line options. 577 // defaults that might be changed by command line options.
578 578
579 install_signal_handlers (); 579 install_signal_handlers ();
580 580
581 initialize_history (); 581 initialize_history ();
582 582
601 } 601 }
602 602
603 if (! inhibit_startup_message && reading_startup_message_printed) 603 if (! inhibit_startup_message && reading_startup_message_printed)
604 cout << endl; 604 cout << endl;
605 605
606 // Avoid counting commands executed from startup files. 606 // Avoid counting commands executed from startup files.
607
607 current_command_number = 1; 608 current_command_number = 1;
608 609
609 // If there is an extra argument, see if it names a file to read. 610 // If there is an extra argument, see if it names a file to read.
610 // Additional arguments are taken as command line options for the 611 // Additional arguments are taken as command line options for the
611 // script. 612 // script.
612 613
613 int remaining_args = argc - optind; 614 int remaining_args = argc - optind;
614 if (remaining_args > 0) 615 if (remaining_args > 0)
615 { 616 {
616 if (remaining_args == 1) 617 if (remaining_args == 1)
639 intern_argv (argc, argv); 640 intern_argv (argc, argv);
640 641
641 switch_to_buffer (create_buffer (get_input_from_stdin ())); 642 switch_to_buffer (create_buffer (get_input_from_stdin ()));
642 } 643 }
643 644
644 // Force input to be echoed if not really interactive, but the user 645 // Force input to be echoed if not really interactive, but the user
645 // has forced interactive behavior. 646 // has forced interactive behavior.
646 647
647 if (!interactive && forced_interactive) 648 if (!interactive && forced_interactive)
648 { 649 {
649 rl_blink_matching_paren = 0; 650 rl_blink_matching_paren = 0;
650 echo_input = 1; 651 echo_input = 1;
651 } 652 }
652 653
653 if (! (interactive || forced_interactive)) 654 if (! (interactive || forced_interactive))
654 using_readline = 0; 655 using_readline = 0;
655 656
656 // Allow the user to interrupt us without exiting. 657 // Allow the user to interrupt us without exiting.
657 658
658 volatile sig_handler *saved_sigint_handler = signal (SIGINT, SIG_IGN); 659 volatile sig_handler *saved_sigint_handler = signal (SIGINT, SIG_IGN);
659 660
660 if (setjmp (toplevel) != 0) 661 if (setjmp (toplevel) != 0)
661 { 662 {
666 667
667 can_interrupt = 1; 668 can_interrupt = 1;
668 669
669 signal (SIGINT, saved_sigint_handler); 670 signal (SIGINT, saved_sigint_handler);
670 671
671 // The big loop. 672 // The big loop.
672 673
673 int retval; 674 int retval;
674 do 675 do
675 { 676 {
676 curr_sym_tab = top_level_sym_tab; 677 curr_sym_tab = top_level_sym_tab;
863 864
864 reset_parser (); 865 reset_parser ();
865 866
866 parse_status = yyparse (); 867 parse_status = yyparse ();
867 868
868 // Important to reset the idea of where input is coming from before 869 // Important to reset the idea of where input is coming from before
869 // trying to eval the command we just parsed -- it might contain the 870 // trying to eval the command we just parsed -- it might contain the
870 // name of an function file that still needs to be parsed! 871 // name of an function file that still needs to be parsed!
871 872
872 tree_statement_list *command = global_command; 873 tree_statement_list *command = global_command;
873 874
874 run_unwind_frame ("eval_string"); 875 run_unwind_frame ("eval_string");
875 876
907 { 908 {
908 error ("eval: expecting string argument"); 909 error ("eval: expecting string argument");
909 return -1.0; 910 return -1.0;
910 } 911 }
911 912
912 // Yes Virginia, we always print here... 913 // Yes Virginia, we always print here...
913 914
914 return eval_string (string, 1, 1, parse_status, nargout); 915 return eval_string (string, 1, 1, parse_status, nargout);
915 } 916 }
916 917
917 DEFUN ("eval", Feval, Seval, 2, 1, 918 DEFUN ("eval", Feval, Seval, 2, 1,
988 989
989 output_buf << ends; 990 output_buf << ends;
990 991
991 int status = cmd.close (); 992 int status = cmd.close ();
992 993
993 // The value in status is as returned by waitpid. If the process 994 // The value in status is as returned by waitpid. If the
994 // exited normally, extract the actual exit status of the command. 995 // process exited normally, extract the actual exit status of
995 // Otherwise, return 127 as a failure code. 996 // the command. Otherwise, return 127 as a failure code.
996 997
997 if ((status & 0xff) == 0) 998 if ((status & 0xff) == 0)
998 status = (status & 0xff00) >> 8; 999 status = (status & 0xff00) >> 8;
999 else 1000 else
1000 status = 127; 1001 status = 127;