GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
octave.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2015 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 // Born February 20, 1992.
24 
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28 
29 #include <cassert>
30 #include <clocale>
31 #include <cstdlib>
32 #include <cstring>
33 #include <ctime>
34 
35 #include <iostream>
36 
37 #include <fcntl.h>
38 #include <getopt.h>
39 #include <sys/types.h>
40 #include <unistd.h>
41 
42 #include "cmd-edit.h"
43 #include "f77-fcn.h"
44 #include "file-ops.h"
45 #include "file-stat.h"
46 #include "lo-error.h"
47 #include "oct-env.h"
48 #include "str-vec.h"
49 
50 #include "builtins.h"
51 #include "defaults.h"
52 #include "Cell.h"
53 #include "defun.h"
54 #include "display.h"
55 #include "error.h"
56 #include "file-io.h"
57 #include "help.h"
58 #include "input.h"
59 #include "lex.h"
60 #include "load-path.h"
61 #include "load-save.h"
62 #include "octave.h"
63 #include "oct-conf.h"
64 #include "oct-hist.h"
65 #include "oct-map.h"
66 #include "oct-mutex.h"
67 #include "oct-obj.h"
68 #include "ops.h"
69 #include "options-usage.h"
70 #include "ov.h"
71 #include "ov-classdef.h"
72 #include "ov-range.h"
73 #include "toplev.h"
74 #include "parse.h"
75 #include "procstream.h"
76 #include "sighandlers.h"
77 #include "sysdep.h"
78 #include "unwind-prot.h"
79 #include "utils.h"
80 #include "variables.h"
81 #include <version.h>
82 
83 // Kluge.
84 extern "C" F77_RET_T
86  const octave_idx_type&
88 
89 extern void install_builtins (void);
90 
94 
95 // The command-line options.
97 
98 // The name used to invoke Octave.
99 static std::string octave_program_invocation_name;
100 
101 // The last component of octave_program_invocation_name.
102 static std::string octave_program_name;
103 
104 // TRUE means we are using readline.
105 // (--no-line-editing)
106 static bool line_editing = true;
107 
108 // TRUE means we read ~/.octaverc and ./.octaverc.
109 // (--norc; --no-init-file; -f)
110 static bool read_init_files = true;
111 
112 // TRUE means we read the site-wide octaverc files.
113 // (--norc; --no-site-file; -f)
114 static bool read_site_files = true;
115 
116 // TRUE means we set the initial path to configured defaults.
117 // (--no-init-path)
118 static bool set_initial_path = true;
119 
120 // TRUE means we don't print the usual startup message.
121 // (--quiet; --silent; -q)
122 static bool inhibit_startup_message = false;
123 
124 // If TRUE, print verbose info in some cases.
125 // (--verbose; -V)
126 static bool verbose_flag = false;
127 
128 // If TRUE, force the GUI to start.
129 // (--force-gui)
130 static bool force_gui_option = false;
131 
132 // If TRUE don't start the GUI.
133 // (--no-gui)
134 static bool no_gui_option = false;
135 
136 // If TRUE, force readline command line editing.
137 // (--line-editing)
138 static bool forced_line_editing = false;
139 
140 // If TRUE, initialize history list from saved history file.
141 // (--no-history; -H)
142 static bool read_history_file = true;
143 
144 // The value of "path" specified on the command line.
145 // (--path; -p)
146 static std::list<std::string> command_line_path;
147 
148 // The value for "EXEC_PATH" specified on the command line.
149 // (--exec-path)
150 static std::string exec_path;
151 
152 // The value for "IMAGE_PATH" specified on the command line.
153 // (--image-path)
154 static std::string image_path;
155 
156 // If TRUE, ignore the window system even if it is available.
157 // (--no-window-system, -W)
158 static bool no_window_system = false;
159 
160 // The code to evaluate at startup
161 // (--eval CODE)
162 static std::string code_to_eval;
163 
164 // If TRUE, don't exit after evaluating code given by --eval option.
165 // (--persist)
166 static bool persist = false;
167 
168 // If TRUE, the GUI should be started.
169 static bool start_gui = false;
170 
171 // If TRUE use traditional (maximally MATLAB compatible) settings
172 // (--traditional)
173 static bool traditional = false;
174 
175 // TRUE if this is a program and no interpreter and interaction is
176 // needed. For example, an octave program with shebang line, or code
177 // from eval without persist.
178 static bool an_octave_program = false;
179 
180 // Store the command-line options for later use.
181 
182 static void
183 intern_argv (int argc, char **argv)
184 {
185  assert (symbol_table::at_top_level ());
186 
187  symbol_table::assign (".nargin.", argc - 1);
188 
189  symbol_table::mark_hidden (".nargin.");
190 
191  if (argc > 0)
192  {
193  octave_argv.resize (argc - 1);
194 
195  // Skip program name in argv.
196  int i = argc;
197  while (--i > 0)
198  octave_argv[i-1] = *(argv+i);
199  }
200 }
201 
202 DEFUN (__version_info__, args, ,
203  "-*- texinfo -*-\n\
204 @deftypefn {Built-in Function} {retval =} __version_info__ (@var{name}, @var{version}, @var{release}, @var{date})\n\
205 Undocumented internal function.\n\
206 @end deftypefn")
207 {
208  octave_value retval;
209 
210  static octave_map vinfo;
211 
212  int nargin = args.length ();
213 
214  if (nargin == 4)
215  {
216  if (vinfo.nfields () == 0)
217  {
218  vinfo.assign ("Name", args (0));
219  vinfo.assign ("Version", args (1));
220  vinfo.assign ("Release", args (2));
221  vinfo.assign ("Date", args (3));
222  }
223  else
224  {
225  octave_idx_type n = vinfo.numel () + 1;
226 
227  vinfo.resize (dim_vector (n, 1));
228 
229  octave_value idx (n);
230 
231  vinfo.assign (idx, "Name", Cell (octave_value (args (0))));
232  vinfo.assign (idx, "Version", Cell (octave_value (args (1))));
233  vinfo.assign (idx, "Release", Cell (octave_value (args (2))));
234  vinfo.assign (idx, "Date", Cell (octave_value (args (3))));
235  }
236  }
237  else if (nargin == 0)
238  retval = vinfo;
239  else
240  print_usage ();
241 
242  return retval;
243 }
244 
245 static void
247 {
248  octave_value_list args;
249 
250  args(3) = OCTAVE_RELEASE_DATE;
251  args(2) = OCTAVE_RELEASE;
252  args(1) = OCTAVE_VERSION;
253  args(0) = "GNU Octave";
254 
255  F__version_info__ (args, 0);
256 }
257 
258 static void
259 gripe_safe_source_exception (const std::string& file, const std::string& msg)
260 {
261  std::cerr << "error: " << msg << "\n"
262  << "error: execution of " << file << " failed\n"
263  << "error: trying to make my way to a command prompt"
264  << std::endl;
265 }
266 
267 // Execute commands from a file and catch potential exceptions in a consistent
268 // way. This function should be called anywhere we might parse and execute
269 // commands from a file before before we have entered the main loop in
270 // toplev.cc.
271 
272 static void
273 safe_source_file (const std::string& file_name,
274  const std::string& context = std::string (),
275  bool verbose = false, bool require_file = true,
276  const std::string& warn_for = std::string ())
277 {
278  try
279  {
280  source_file (file_name, context, verbose, require_file, warn_for);
281  }
282  catch (octave_interrupt_exception)
283  {
285  octave_stdout << "\n";
288  }
289  catch (octave_execution_exception)
290  {
292  gripe_safe_source_exception (file_name, "unhandled execution exception");
293  }
294 }
295 
296 // Initialize by reading startup files.
297 
298 static void
300 {
301  unwind_protect frame;
302 
303  std::string context;
304 
305  bool verbose = (verbose_flag && ! inhibit_startup_message);
306 
307  bool require_file = false;
308 
309  if (read_site_files)
310  {
311  // Execute commands from the site-wide configuration file.
312  // First from the file $(prefix)/lib/octave/site/m/octaverc
313  // (if it exists), then from the file
314  // $(prefix)/share/octave/$(version)/m/octaverc (if it exists).
315 
316  safe_source_file (Vlocal_site_defaults_file, context, verbose,
317  require_file);
318 
319  safe_source_file (Vsite_defaults_file, context, verbose, require_file);
320  }
321 
322  if (read_init_files)
323  {
324  // Try to execute commands from $HOME/$OCTAVE_INITFILE and
325  // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set,
326  // .octaverc is assumed.
327 
328  bool home_rc_already_executed = false;
329 
330  std::string initfile = octave_env::getenv ("OCTAVE_INITFILE");
331 
332  if (initfile.empty ())
333  initfile = ".octaverc";
334 
335  std::string home_dir = octave_env::get_home_directory ();
336 
337  std::string home_rc = octave_env::make_absolute (initfile, home_dir);
338 
339  std::string local_rc;
340 
341  if (! home_rc.empty ())
342  {
343  safe_source_file (home_rc, context, verbose, require_file);
344 
345  // Names alone are not enough.
346 
347  file_stat fs_home_rc (home_rc);
348 
349  if (fs_home_rc)
350  {
351  // We want to check for curr_dir after executing home_rc
352  // because doing that may change the working directory.
353 
354  local_rc = octave_env::make_absolute (initfile);
355 
356  home_rc_already_executed = same_file (home_rc, local_rc);
357  }
358  }
359 
360  if (! home_rc_already_executed)
361  {
362  if (local_rc.empty ())
363  local_rc = octave_env::make_absolute (initfile);
364 
365  safe_source_file (local_rc, context, verbose, require_file);
366  }
367  }
368 }
369 
370 static int
371 execute_eval_option_code (const std::string& code)
372 {
373  unwind_protect frame;
374 
376 
377  can_interrupt = true;
378 
382 
384 
385  octave_initialized = true;
386 
387  frame.protect_var (interactive);
388 
389  interactive = false;
390 
391  int parse_status = 0;
392 
393  try
394  {
395  eval_string (code, false, parse_status, 0);
396  }
397  catch (octave_interrupt_exception)
398  {
400  octave_stdout << "\n";
403  }
404  catch (octave_execution_exception)
405  {
407  std::cerr << "error: unhandled execution exception -- eval failed"
408  << std::endl;
409  }
410 
411  return parse_status;
412 }
413 
414 static void
415 execute_command_line_file (const std::string& fname)
416 {
417  unwind_protect frame;
418 
420 
421  can_interrupt = true;
422 
426 
428 
429  octave_initialized = true;
430 
431  frame.protect_var (interactive);
432 
435 
436  interactive = false;
437 
439 
440  size_t pos = fname.find_last_of (file_ops::dir_sep_chars ());
441 
443  = (pos != std::string::npos) ? fname.substr (pos+1) : fname;
444 
445  std::string context;
446  bool verbose = false;
447  bool require_file = true;
448 
449  safe_source_file (fname, context, verbose, require_file, "octave");
450 }
451 
452 static void
453 lo_error_handler (const char *fmt, ...)
454 {
455  va_list args;
456  va_start (args, fmt);
457  verror_with_cfn (fmt, args);
458  va_end (args);
459 
461 }
462 
463 static void
464 lo_error_with_id_handler (const char *id, const char *fmt, ...)
465 {
466  va_list args;
467  va_start (args, fmt);
468  verror_with_id_cfn (id, fmt, args);
469  va_end (args);
470 
472 }
473 
474 static void
476 {
481 }
482 
483 // What internal options get configured by --traditional.
484 
485 static void
487 {
488  persist = true;
489 
490  FPS1 (octave_value (">> "));
491  FPS2 (octave_value (""));
492  FPS4 (octave_value (""));
493  Fbeep_on_error (octave_value (true));
498  Fdisable_range (octave_value (true));
500  Fhistory_timestamp_format_string (octave_value ("%%-- %D %I:%M %p --%%"));
503  Fsave_default_options (octave_value ("-mat-binary"));
505 
506  disable_warning ("Octave:abbreviated-property-match");
507  disable_warning ("Octave:data-file-in-path");
508  disable_warning ("Octave:function-name-clash");
509  disable_warning ("Octave:possible-matlab-short-circuit-operator");
510 }
511 
512 // EMBEDDED is declared int instead of bool because this function is
513 // declared extern "C".
514 
515 int
516 octave_main (int argc, char **argv, int embedded)
517 {
518  octave_process_command_line (argc, argv);
519 
520  sysdep_init ();
521 
522  install_defaults ();
523 
524  octave_initialize_interpreter (argc, argv, embedded);
525 
526  return octave_execute_interpreter ();
527 }
528 
529 void
530 octave_process_command_line (int argc, char **argv)
531 {
532  octave_cmdline_argc = argc;
533  octave_cmdline_argv = argv;
534 
535  while (true)
536  {
537  int long_idx;
538 
539  int optc = getopt_long (argc, argv, short_opts, long_opts, &long_idx);
540 
541  if (optc < 0)
542  break;
543 
544  switch (optc)
545  {
546  case '?':
547  // Unrecognized option. getopt_long already printed a message about
548  // it, so we will just print the usage string and exit.
550  break;
551 
552  case 'H':
553  Fhistory_save (octave_value (false));
554  read_history_file = false;
555  break;
556 
557  case 'W':
558  no_window_system = true;
559  break;
560 
561  case 'V':
562  verbose_flag = true;
563  break;
564 
565  case 'd':
566  // This is the same as yydebug in parse.y.
567  octave_debug++;
568  break;
569 
570  case 'f':
571  read_init_files = false;
572  read_site_files = false;
573  break;
574 
575  case 'h':
577  break;
578 
579  case 'i':
580  forced_interactive = true;
581  break;
582 
583  case 'p':
584  if (optarg)
585  command_line_path.push_back (optarg);
586  break;
587 
588  case 'q':
590  break;
591 
592  case 'x':
593  {
596  }
597  break;
598 
599  case 'v':
601  break;
602 
604  if (optarg)
606  break;
607 
609  if (optarg)
610  Fdoc_cache_file (octave_value (optarg));
611  break;
612 
613  case EVAL_OPTION:
614  if (optarg)
615  {
616  if (code_to_eval.empty ())
617  code_to_eval = optarg;
618  else
619  code_to_eval += std::string (" ") + optarg;
620  }
621  break;
622 
623  case EXEC_PATH_OPTION:
624  if (optarg)
625  exec_path = optarg;
626  break;
627 
628  case FORCE_GUI_OPTION:
629  force_gui_option = true;
630  break;
631 
632  case IMAGE_PATH_OPTION:
633  if (optarg)
634  image_path = optarg;
635  break;
636 
637  case INFO_FILE_OPTION:
638  if (optarg)
639  Finfo_file (octave_value (optarg));
640  break;
641 
642  case INFO_PROG_OPTION:
643  if (optarg)
644  Finfo_program (octave_value (optarg));
645  break;
646 
647  case DEBUG_JIT_OPTION:
648  Fdebug_jit (octave_value (true));
649  break;
650 
651  case JIT_COMPILER_OPTION:
652  Fjit_enable (octave_value (true));
653  break;
654 
655  case LINE_EDITING_OPTION:
656  forced_line_editing = true;
657  break;
658 
659  case NO_GUI_OPTION:
660  no_gui_option = true;
661  break;
662 
663  case NO_INIT_FILE_OPTION:
664  read_init_files = false;
665  break;
666 
667  case NO_INIT_PATH_OPTION:
668  set_initial_path = false;
669  break;
670 
672  line_editing = false;
673  break;
674 
675  case NO_SITE_FILE_OPTION:
676  read_site_files = 0;
677  break;
678 
679  case PERSIST_OPTION:
680  persist = true;
681  break;
682 
684  if (optarg)
685  Ftexi_macros_file (octave_value (optarg));
686  break;
687 
688  case TRADITIONAL_OPTION:
689  traditional = true;
690  break;
691 
692  default:
693  // getopt_long should print a message about unrecognized options and
694  // return '?', which is handled above. If we end up here, it is
695  // because there was an option but we forgot to handle it.
696  // That should be fatal.
697  panic_impossible ();
698  break;
699  }
700  }
701 
702  // Check for various incompatible argument pairs
704  {
705  error ("only one of --force-gui and --no-gui may be used");
706 
708  }
709 
710  bool script_file = (argc - optind) > 0;
711  if (! code_to_eval.empty () && script_file)
712  {
713  error ("--eval \"CODE\" and script file are mutually exclusive options");
714 
716  }
717  an_octave_program = (script_file || ! code_to_eval.empty ()) && ! persist;
718 
719 }
720 
721 // EMBEDDED is declared int instead of bool because this function is
722 // declared extern "C".
723 
724 void
725 octave_initialize_interpreter (int argc, char **argv, int embedded)
726 {
727  // Matlab uses "C" locale for LC_NUMERIC class regardless of local setting
728  setlocale (LC_NUMERIC, "C");
729  setlocale (LC_TIME, "C");
730  octave_env::putenv ("LC_NUMERIC", "C");
731  octave_env::putenv ("LC_TIME", "C");
732 
733  octave_embedded = embedded;
734 
736 
739 
741 
743 
744  // Initialize default warning state before --traditional option
745  // that may reset them.
746 
748 
749  if (traditional)
751 
752  init_signals ();
753 
754  octave_ieee_init ();
755 
756  // The idea here is to force xerbla to be referenced so that we will link to
757  // our own version instead of the one provided by the BLAS library. But
758  // octave_NaN should never be -1, so we should never actually call xerbla.
759 
760  if (octave_NaN == -1)
761  F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6));
762 
764 
765  if (! embedded)
767  else
768  quit_allowed = false;
769 
771 
772  install_types ();
773 
774  install_ops ();
775 
776  install_builtins ();
777 
778  install_classdef ();
779 
780  for (std::list<std::string>::const_iterator it = command_line_path.begin ();
781  it != command_line_path.end (); it++)
783 
784  if (! exec_path.empty ())
786 
787  if (! image_path.empty ())
789 
790  if (no_window_system)
792 
793  // Is input coming from a terminal? If so, we are probably interactive.
794 
795  // If stdin is not a tty, then we are reading commands from a pipe or
796  // a redirected file.
797  bool stdin_is_tty = gnulib::isatty (fileno (stdin));
798 
799  interactive = (! embedded && ! an_octave_program && stdin_is_tty
800  && gnulib::isatty (fileno (stdout)));
801 
802  // Check if the user forced an interactive session. If he
803  // unnecessarily did so, reset forced_interactive to false.
804  if (forced_interactive)
805  {
806  if (interactive)
807  forced_interactive = false;
808  else
809  interactive = true;
810  }
811 
813  line_editing = false;
814 
815  // Also skip start-up message unless session is interactive.
816  if (! interactive)
818 
819  // Force default line editor if we don't want readline editing.
820  if (! line_editing)
822 
823  // These can come after command line args since none of them set any
824  // defaults that might be changed by command line options.
825 
826  if (line_editing)
828 
830 
832 
833  // Make all command-line arguments available to startup files,
834  // including PKG_ADD files.
835 
836  intern_argv (argc, argv);
837 
839 
841 }
842 
843 int
845 {
847  std::cout << octave_startup_message () << "\n" << std::endl;
848 
850 
852 
854  std::cout << std::endl;
855 
856  // Execute any code specified with --eval 'CODE'
857  if (! code_to_eval.empty ())
858  {
859  int parse_status = execute_eval_option_code (code_to_eval);
860 
861  if (! persist)
862  {
863  quitting_gracefully = true;
864 
865  clean_up_and_exit (parse_status || error_state ? 1 : 0);
866  }
867  }
868 
869  // If there is an extra argument, see if it names a file to read.
870  // Additional arguments are taken as command line options for the script.
871 
872  int last_arg_idx = optind;
873  int remaining_args = octave_cmdline_argc - last_arg_idx;
874 
875  if (remaining_args > 0)
876  {
877  // If we are running an executable script (#! /bin/octave) then
878  // we should only see the args passed to the script.
879 
880  intern_argv (remaining_args, octave_cmdline_argv+last_arg_idx);
881 
882  execute_command_line_file (octave_cmdline_argv[last_arg_idx]);
883 
884  if (! persist)
885  {
886  quitting_gracefully = true;
887 
888  clean_up_and_exit (error_state ? 1 : 0);
889  }
890  }
891 
892  // Avoid counting commands executed from startup files.
893 
895 
896  // Now argv should have the full set of args.
897  intern_argv (octave_cmdline_argc, octave_cmdline_argv);
898 
899  // Force input to be echoed if not really interactive,
900  // but the user has forced interactive behavior.
901 
902  if (forced_interactive)
903  {
905 
906  // FIXME: is this the right thing to do?
908  }
909 
910  if (octave_embedded)
911  {
912  // FIXME: Do we need to do any cleanup here before returning?
913  // If we don't, what will happen to Octave functions that have been
914  // registered to execute with atexit, for example?
915 
916  return 1;
917  }
918 
919  int retval = main_loop ();
920 
921  quitting_gracefully = true;
922 
923  clean_up_and_exit (retval, true);
924 
925  return retval;
926 }
927 
928 static bool
930 {
931  if (no_window_system)
932  return false;
933 
934  std::string err_msg;
935  if (! display_info::display_available (err_msg))
936  {
937  if (! (inhibit_startup_message || err_msg.empty ()))
938  warning (err_msg.c_str ());
939 
940  return false;
941  }
942 
943  if (force_gui_option)
944  return true;
945 
946  if (no_gui_option)
947  return false;
948 
949  if (persist)
950  return true;
951 
952  // If stdin is not a tty, then assume we are reading commands from a pipe or
953  // a redirected file and the GUI should not start. If this is not the case
954  // (for example, starting from a desktop "launcher" with no terminal) and you
955  // want to start the GUI, you may use the --force-gui option to start the GUI.
956 
957  if (! gnulib::isatty (fileno (stdin)))
958  return false;
959 
960  // If we have code to eval or execute from a file, and we are going to exit
961  // immediately after executing it, don't start the gui.
962 
963  int last_arg_idx = optind;
964  int remaining_args = octave_cmdline_argc - last_arg_idx;
965 
966  if (! code_to_eval.empty () || remaining_args > 0)
967  return false;
968 
969  return true;
970 }
971 
972 // Return int instead of bool because this function is declared extern "C".
973 
974 int
976 {
978  return start_gui;
979 }
980 
981 DEFUN (isguirunning, args, ,
982  "-*- texinfo -*-\n\
983 @deftypefn {Built-in Function} {} isguirunning ()\n\
984 Return true if Octave is running in GUI mode and false otherwise.\n\
985 @seealso{have_window_system}\n\
986 @end deftypefn")
987 {
988  octave_value retval;
989 
990  if (args.length () == 0)
991  retval = start_gui;
992  else
993  print_usage ();
994 
995  return retval;
996 }
997 
998 /*
999 %!assert (islogical (isguirunning ()))
1000 %!error isguirunning (1)
1001 */
1002 
1003 DEFUN (argv, args, ,
1004  "-*- texinfo -*-\n\
1005 @deftypefn {Built-in Function} {} argv ()\n\
1006 Return the command line arguments passed to Octave.\n\
1007 \n\
1008 For example, if you invoked Octave using the command\n\
1009 \n\
1010 @example\n\
1011 octave --no-line-editing --silent\n\
1012 @end example\n\
1013 \n\
1014 @noindent\n\
1015 @code{argv} would return a cell array of strings with the elements\n\
1016 @option{--no-line-editing} and @option{--silent}.\n\
1017 \n\
1018 If you write an executable Octave script, @code{argv} will return the list\n\
1019 of arguments passed to the script. @xref{Executable Octave Programs}, for\n\
1020 an example of how to create an executable Octave script.\n\
1021 @end deftypefn")
1022 {
1023  octave_value retval;
1024 
1025  if (args.length () == 0)
1026  retval = Cell (octave_argv);
1027  else
1028  print_usage ();
1029 
1030  return retval;
1031 }
1032 
1033 /*
1034 %!assert (iscellstr (argv ()))
1035 %!error argv (1)
1036 */
1037 
1038 DEFUN (program_invocation_name, args, ,
1039  "-*- texinfo -*-\n\
1040 @deftypefn {Built-in Function} {} program_invocation_name ()\n\
1041 Return the name that was typed at the shell prompt to run Octave.\n\
1042 \n\
1043 If executing a script from the command line (e.g., @code{octave foo.m})\n\
1044 or using an executable Octave script, the program name is set to the\n\
1045 name of the script. @xref{Executable Octave Programs}, for an example of\n\
1046 how to create an executable Octave script.\n\
1047 @seealso{program_name}\n\
1048 @end deftypefn")
1049 {
1050  octave_value retval;
1051 
1052  if (args.length () == 0)
1054  else
1055  print_usage ();
1056 
1057  return retval;
1058 }
1059 
1060 /*
1061 %!assert (ischar (program_invocation_name ()))
1062 %!error program_invocation_name (1)
1063 */
1064 
1065 DEFUN (program_name, args, ,
1066  "-*- texinfo -*-\n\
1067 @deftypefn {Built-in Function} {} program_name ()\n\
1068 Return the last component of the value returned by\n\
1069 @code{program_invocation_name}.\n\
1070 @seealso{program_invocation_name}\n\
1071 @end deftypefn")
1072 {
1073  octave_value retval;
1074 
1075  if (args.length () == 0)
1076  retval = octave_program_name;
1077  else
1078  print_usage ();
1079 
1080  return retval;
1081 }
1082 
1083 /*
1084 %!assert (ischar (program_name ()))
1085 %!error program_name (1)
1086 */
#define LINE_EDITING_OPTION
Definition: options-usage.h:59
void warning_with_id(const char *id, const char *fmt,...)
Definition: error.cc:696
void set_exec_path(const std::string &path_arg)
Definition: defaults.cc:253
static bool force_gui_option
Definition: octave.cc:130
std::string Vsite_defaults_file
Definition: defaults.cc:96
static bool traditional
Definition: octave.cc:173
#define NO_GUI_OPTION
Definition: options-usage.h:60
#define F77_CHAR_ARG_LEN(l)
Definition: f77-fcn.h:253
Definition: Cell.h:35
int octave_execute_interpreter(void)
Definition: octave.cc:844
void install_classdef(void)
static std::string octave_program_invocation_name
Definition: octave.cc:99
static void mark_hidden(const std::string &name)
Definition: symtab.h:1939
subroutine xerbla(SRNAME, INFO)
Definition: xerbla.f:1
bool same_file(const std::string &f, const std::string &g)
Definition: utils.cc:133
static std::string get_program_name(void)
Definition: oct-env.cc:160
static bool line_editing
Definition: octave.cc:106
void(* octave_interrupt_hook)(void)=0
Definition: quit.cc:35
static bool at_top_level(void)
Definition: symtab.h:1303
OCTINTERP_API octave_value_list Fhistory_save(const octave_value_list &=octave_value_list(), int=0)
Definition: oct-hist.cc:866
static void octave_print_version_and_exit(void)
bool quit_allowed
Definition: toplev.cc:91
std::string octave_startup_message(bool html)
Definition: version.cc:118
void assign(const std::string &k, const Cell &val)
Definition: oct-map.h:348
int exit_status
Definition: toplev.cc:96
OCTINTERP_API octave_value_list Finfo_program(const octave_value_list &=octave_value_list(), int=0)
Definition: help.cc:1503
void octave_prepare_hdf5(void)
Definition: load-save.cc:1265
void source_file(const std::string &file_name, const std::string &context, bool verbose, bool require_file, const std::string &warn_for)
Definition: oct-parse.cc:8405
#define OCTAVE_RELEASE
Definition: defaults.h:188
static string_vector octave_argv
Definition: octave.cc:96
static bool inhibit_startup_message
Definition: octave.cc:122
void recover_from_exception(void)
Definition: toplev.cc:547
OCTINTERP_API octave_value_list Fdisable_diagonal_matrix(const octave_value_list &=octave_value_list(), int=0)
Definition: ov.cc:3318
OCTINTERP_API void print_usage(void)
Definition: defun.cc:51
void octave_save_signal_mask(void)
Definition: cquit.c:67
OCTINTERP_API octave_value_list Fjit_enable(const octave_value_list &=octave_value_list(), int=0)
Definition: pt-jit.cc:2575
OCTINTERP_API octave_value_list FPS1(const octave_value_list &=octave_value_list(), int=0)
Definition: input.cc:1310
static void putenv(const std::string &name, const std::string &value)
Definition: oct-env.cc:245
F77_RET_T F77_FUNC(xerbla, XERBLA)(F77_CONST_CHAR_ARG_DECL
static void reset_current_command_number(int n)
Definition: cmd-edit.cc:1175
OCTINTERP_API octave_value_list Fconfirm_recursive_rmdir(const octave_value_list &=octave_value_list(), int=0)
Definition: dirfns.cc:808
int octave_embedded
Definition: octave.cc:93
#define INFO_FILE_OPTION
Definition: options-usage.h:55
static void initialize_version_info(void)
Definition: octave.cc:246
void protect_var(T &var)
static void lo_error_with_id_handler(const char *id, const char *fmt,...)
Definition: octave.cc:464
#define DEBUG_JIT_OPTION
Definition: options-usage.h:57
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:44
OCTINTERP_API octave_value_list FPS4(const octave_value_list &=octave_value_list(), int=0)
Definition: input.cc:1352
void error(const char *fmt,...)
Definition: error.cc:476
octave_interrupt_handler octave_catch_interrupts(void)
Definition: sighandlers.cc:563
bool forced_interactive
Definition: input.cc:107
#define PERSIST_OPTION
Definition: options-usage.h:65
void install_types(void)
Definition: ov.cc:2865
static void execute_startup_files(void)
Definition: octave.cc:299
void(* octave_bad_alloc_hook)(void)=0
Definition: quit.cc:36
static void initialize_error_handlers()
Definition: octave.cc:475
static bool an_octave_program
Definition: octave.cc:178
bool quitting_gracefully
Definition: toplev.cc:94
static void set_program_name(const std::string &s)
Definition: oct-env.cc:174
static void set_command_line_path(const std::string &p)
Definition: load-path.h:264
void set_image_path(const std::string &path)
Definition: defaults.cc:292
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
Definition: oct-parse.cc:8810
OCTINTERP_API octave_value_list Fpage_screen_output(const octave_value_list &=octave_value_list(), int=0)
Definition: pager.cc:704
octave_idx_type numel(void) const
Definition: oct-map.h:372
bool octave_initialized
Definition: toplev.cc:103
#define IMAGE_PATH_OPTION
Definition: options-usage.h:54
OCTINTERP_API octave_value_list Fdebug_jit(const octave_value_list &=octave_value_list(), int=0)
Definition: pt-jit.cc:2553
static void intern_argv(int argc, char **argv)
Definition: octave.cc:183
#define NO_SITE_FILE_OPTION
Definition: options-usage.h:64
static void init(void)
#define EXEC_PATH_OPTION
Definition: options-usage.h:52
int octave_main(int argc, char **argv, int embedded)
Definition: octave.cc:516
OCTINTERP_API octave_value_list Fbeep_on_error(const octave_value_list &=octave_value_list(), int=0)
Definition: error.cc:2088
static bool no_window_system
Definition: octave.cc:158
int octave_starting_gui(void)
Definition: octave.cc:975
#define TRADITIONAL_OPTION
Definition: options-usage.h:67
static bool verbose_flag
Definition: octave.cc:126
#define NO_LINE_EDITING_OPTION
Definition: options-usage.h:63
static void gripe_safe_source_exception(const std::string &file, const std::string &msg)
Definition: octave.cc:259
OCTINTERP_API octave_value_list Ftexi_macros_file(const octave_value_list &=octave_value_list(), int=0)
Definition: help.cc:1453
struct option long_opts[]
Definition: options-usage.h:68
void octave_ieee_init(void)
Definition: lo-ieee.cc:221
OCTINTERP_API octave_value_list Fdisable_range(const octave_value_list &=octave_value_list(), int=0)
Definition: ov.cc:3362
char ** octave_cmdline_argv
Definition: octave.cc:92
#define TEXI_MACROS_FILE_OPTION
Definition: options-usage.h:66
void initialize_history(bool read_history_file)
Definition: oct-hist.cc:563
void set_liboctave_warning_with_id_handler(liboctave_warning_with_id_handler f)
Definition: lo-error.c:91
static std::string exec_path
Definition: octave.cc:150
void octave_initialize_interpreter(int argc, char **argv, int embedded)
Definition: octave.cc:725
#define OCTAVE_RELEASE_DATE
Definition: version.h:45
OCTINTERP_API octave_value_list Fdisable_permutation_matrix(const octave_value_list &=octave_value_list(), int=0)
Definition: ov.cc:3288
static std::string code_to_eval
Definition: octave.cc:162
static std::string get_program_invocation_name(void)
Definition: oct-env.cc:167
void install_ops(void)
Definition: ops.cc:138
static std::list< std::string > command_line_path
Definition: octave.cc:146
void verror_with_cfn(const char *fmt, va_list args)
Definition: error.cc:485
OCTINTERP_API octave_value_list Fhistory_timestamp_format_string(const octave_value_list &=octave_value_list(), int=0)
Definition: oct-hist.cc:849
static void octave_print_terse_usage_and_exit(void)
void install_signal_handlers(void)
Definition: sighandlers.cc:628
void verror_with_id_cfn(const char *id, const char *fmt, va_list args)
Definition: error.cc:515
static bool read_site_files
Definition: octave.cc:114
void octave_throw_execution_exception(void)
Definition: quit.cc:61
static void maximum_braindamage(void)
Definition: octave.cc:486
bool interactive
Definition: input.cc:103
OCTINTERP_API octave_value_list Fcrash_dumps_octave_core(const octave_value_list &=octave_value_list(), int=0)
Definition: load-save.cc:1802
int main_loop(void)
Definition: toplev.cc:559
octave_idx_type nfields(void) const
Definition: oct-map.h:327
void initialize_command_input(void)
Definition: input.cc:475
static llvm::LLVMContext & context
Definition: jit-typeinfo.cc:76
#define EVAL_OPTION
Definition: options-usage.h:51
OCTINTERP_API octave_value_list Fecho_executing_commands(const octave_value_list &=octave_value_list(), int=0)
Definition: input.cc:1404
static bool no_gui_option
Definition: octave.cc:134
void resize(octave_idx_type n, const std::string &rfv=std::string())
Definition: str-vec.h:91
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
Definition: oct-env.cc:132
static void lo_error_handler(const char *fmt,...)
Definition: octave.cc:453
static int execute_eval_option_code(const std::string &code)
Definition: octave.cc:371
OCTAVE_EXPORT octave_value_list F__version_info__(const octave_value_list &args, int)
Definition: octave.cc:206
void set_liboctave_error_handler(liboctave_error_handler f)
Definition: lo-error.c:64
void octave_process_command_line(int argc, char **argv)
Definition: octave.cc:530
int error_state
Definition: error.cc:101
static std::string getenv(const std::string &name)
Definition: oct-env.cc:238
static void initialize(bool set_initial_path=false)
Definition: load-path.h:50
F77_RET_T const octave_idx_type & F77_CHAR_ARG_LEN_DECL
Definition: octave.cc:87
OCTINTERP_API octave_value_list Fsave_default_options(const octave_value_list &=octave_value_list(), int=0)
Definition: load-save.cc:1822
void initialize_default_warning_state(void)
Definition: error.cc:1743
void set_liboctave_warning_handler(liboctave_warning_handler f)
Definition: lo-error.c:82
void set_liboctave_error_with_id_handler(liboctave_error_with_id_handler f)
Definition: lo-error.c:73
#define panic_impossible()
Definition: error.h:33
void clean_up_and_exit(int status, bool safe_to_return)
Definition: toplev.cc:760
std::string Vlocal_site_defaults_file
Definition: defaults.cc:95
static void assign(const std::string &name, const octave_value &value=octave_value(), scope_id scope=xcurrent_scope, context_id context=xdefault_context, bool force_add=false)
Definition: symtab.h:1335
OCTINTERP_API octave_value_list Fprint_empty_dimensions(const octave_value_list &=octave_value_list(), int=0)
Definition: pr-output.cc:4165
#define F77_RET_T
Definition: f77-fcn.h:264
static bool persist
Definition: octave.cc:166
bool can_interrupt
Definition: sighandlers.cc:61
#define OCTAVE_VERSION
Definition: main.cc:46
void octave_signal_handler(void)
Definition: sighandlers.cc:269
void disable_warning(const std::string &id)
Definition: error.cc:1737
void warning(const char *fmt,...)
Definition: error.cc:681
static std::string dir_sep_chars(void)
Definition: file-ops.h:68
static std::string octave_program_name
Definition: octave.cc:102
void(* octave_signal_hook)(void)=0
Definition: quit.cc:34
static bool set_initial_path
Definition: octave.cc:118
#define octave_stdout
Definition: pager.h:144
static void no_window_system(void)
Definition: display.h:83
#define octave_NaN
Definition: lo-ieee.h:37
#define F77_CONST_CHAR_ARG_DECL
Definition: f77-fcn.h:255
static const char * short_opts
Definition: options-usage.h:45
static void force_default_editor(void)
Definition: cmd-edit.cc:989
static bool display_available(void)
Definition: display.h:70
std::list< octave_value_list > idx
Definition: oct-lvalue.h:103
#define DOC_CACHE_FILE_OPTION
Definition: options-usage.h:50
static bool forced_line_editing
Definition: octave.cc:138
#define BUILT_IN_DOCSTRINGS_FILE_OPTION
Definition: options-usage.h:49
octave_idx_type length(void) const
Definition: oct-map.h:373
static void octave_print_verbose_usage_and_exit(void)
static bool read_init_files
Definition: octave.cc:110
OCTINTERP_API octave_value_list Finfo_file(const octave_value_list &=octave_value_list(), int=0)
Definition: help.cc:1477
static bool start_gui
Definition: octave.cc:169
int octave_debug
static void safe_source_file(const std::string &file_name, const std::string &context=std::string(), bool verbose=false, bool require_file=true, const std::string &warn_for=std::string())
Definition: octave.cc:273
void resize(const dim_vector &dv, bool fill=false)
Definition: oct-map.cc:546
OCTINTERP_API octave_value_list Ffixed_point_format(const octave_value_list &=octave_value_list(), int=0)
Definition: pr-output.cc:4135
void init_signals(void)
Definition: siglist.c:45
void initialize_file_io(void)
Definition: file-io.cc:88
static void blink_matching_paren(bool flag)
Definition: cmd-edit.cc:1196
#define NO_INIT_PATH_OPTION
Definition: options-usage.h:62
void install_defaults(void)
Definition: defaults.cc:419
#define NO_INIT_FILE_OPTION
Definition: options-usage.h:61
static void execute_command_line_file(const std::string &fname)
Definition: octave.cc:415
OCTINTERP_API octave_value_list FPS2(const octave_value_list &=octave_value_list(), int=0)
Definition: input.cc:1332
#define INFO_PROG_OPTION
Definition: options-usage.h:56
int octave_cmdline_argc
Definition: octave.cc:91
OCTINTERP_API octave_value_list Fbuilt_in_docstrings_file(const octave_value_list &=octave_value_list(), int=0)
Definition: help.cc:972
OCTINTERP_API octave_value_list Fdoc_cache_file(const octave_value_list &=octave_value_list(), int=0)
Definition: help.cc:1427
bool reading_startup_message_printed
Definition: oct-parse.cc:149
void install_builtins(void)
Definition: builtins.cc:1708
bool octave_interpreter_ready
Definition: toplev.cc:100
static std::string image_path
Definition: octave.cc:154
void set_default_prompts(void)
Definition: input.cc:139
#define FORCE_GUI_OPTION
Definition: options-usage.h:53
#define JIT_COMPILER_OPTION
Definition: options-usage.h:58
static bool check_starting_gui(void)
Definition: octave.cc:929
void sysdep_init(void)
Definition: sysdep.cc:309
static bool read_history_file
Definition: octave.cc:142
OCTINTERP_API octave_value_list Fstruct_levels_to_print(const octave_value_list &=octave_value_list(), int=0)
Definition: ov-struct.cc:2338
static std::string get_home_directory(void)
Definition: oct-env.cc:146