Mercurial > hg > octave-lyh
annotate src/octave.cc @ 10244:b0485f5a921e
assume atexit exists
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 02 Feb 2010 02:45:14 -0500 |
parents | b49d47b637b7 |
children | 2d47356a7a1a |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
8920 | 4 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
24 // Born February 20, 1992. | |
25 | |
240 | 26 #ifdef HAVE_CONFIG_H |
1192 | 27 #include <config.h> |
1 | 28 #endif |
29 | |
1355 | 30 #include <cassert> |
31 #include <cstdlib> | |
32 #include <cstring> | |
33 #include <ctime> | |
34 | |
3503 | 35 #include <iostream> |
1355 | 36 |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
37 #include <getopt.h> |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
38 |
2926 | 39 #include "cmd-edit.h" |
3690 | 40 #include "f77-fcn.h" |
4097 | 41 #include "file-ops.h" |
2926 | 42 #include "file-stat.h" |
240 | 43 #include "lo-error.h" |
2926 | 44 #include "oct-env.h" |
3019 | 45 #include "pathsearch.h" |
1907 | 46 #include "str-vec.h" |
223 | 47 |
2492 | 48 #include <defaults.h> |
3933 | 49 #include "Cell.h" |
1355 | 50 #include "defun.h" |
9335
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
51 #include "display.h" |
1355 | 52 #include "error.h" |
53 #include "file-io.h" | |
1 | 54 #include "input.h" |
55 #include "lex.h" | |
5832 | 56 #include "load-path.h" |
4113 | 57 #include "octave.h" |
1742 | 58 #include "oct-hist.h" |
5654 | 59 #include "oct-map.h" |
3195 | 60 #include "oct-obj.h" |
2375 | 61 #include "ops.h" |
1670 | 62 #include "toplev.h" |
1 | 63 #include "parse.h" |
562 | 64 #include "procstream.h" |
1355 | 65 #include "sighandlers.h" |
66 #include "sysdep.h" | |
2375 | 67 #include "ov.h" |
1 | 68 #include "unwind-prot.h" |
1355 | 69 #include "utils.h" |
70 #include "variables.h" | |
2492 | 71 #include <version.h> |
1 | 72 |
4159 | 73 // Kluge. |
5990 | 74 extern "C" F77_RET_T |
75 F77_FUNC (xerbla, XERBLA) (F77_CONST_CHAR_ARG_DECL, const octave_idx_type& | |
76 F77_CHAR_ARG_LEN_DECL); | |
4159 | 77 |
2910 | 78 extern void install_builtins (void); |
79 | |
1907 | 80 // The command-line options. |
81 static string_vector octave_argv; | |
1 | 82 |
5780 | 83 // The name used to invoke Octave. |
84 static std::string | |
85 octave_program_invocation_name; | |
86 | |
87 // The last component of octave_program_invocation_name. | |
88 static std::string octave_program_name; | |
89 | |
2239 | 90 // TRUE means we read ~/.octaverc and ./.octaverc. |
91 // (--norc; --no-init-file; -f) | |
92 static bool read_init_files = true; | |
93 | |
94 // TRUE means we read the site-wide octaverc files. | |
95 // (--norc; --no-site-file; -f) | |
2240 | 96 static bool read_site_files = true; |
1 | 97 |
6365 | 98 // TRUE means we set the initial path to configured defaults. |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
99 // (--no-init-path) |
6365 | 100 static bool set_initial_path = true; |
101 | |
3019 | 102 // TRUE means we don't print the usual startup message. |
616 | 103 // (--quiet; --silent; -q) |
2239 | 104 static bool inhibit_startup_message = false; |
1 | 105 |
3019 | 106 // TRUE means we turn on compatibility options. |
1410 | 107 // (--traditional) |
2239 | 108 static bool traditional = false; |
1410 | 109 |
3019 | 110 // If TRUE, print verbose info in some cases. |
1825 | 111 // (--verbose; -V) |
2239 | 112 static bool verbose_flag = false; |
1825 | 113 |
1 | 114 // Usage message |
139 | 115 static const char *usage_string = |
5189 | 116 "octave [-?HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE]\n\ |
5814 | 117 [--exec-path path] [--help] [--image-path path] [--info-file file]\n\ |
9336
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
118 [--info-program prog] [--interactive] [--line-editing]\n\ |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
119 [--no-history] [--no-init-file] [--no-init-path] [--no-line-editing]\n\ |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
120 [--no-site-file] [--no-window-system] [-p path] [--path path]\n\ |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
121 [--silent] [--traditional] [--verbose] [--version] [file]"; |
1 | 122 |
1358 | 123 // This is here so that it's more likely that the usage message and |
1410 | 124 // the real set of options will agree. Note: the `+' must come first |
125 // to prevent getopt from permuting arguments! | |
3180 | 126 static const char *short_opts = "+?HVdfhip:qvx"; |
139 | 127 |
5189 | 128 // The code to evaluate at startup (--eval CODE) |
129 static std::string code_to_eval; | |
130 | |
131 // If TRUE, don't exit after evaluating code given by --eval option. | |
132 static bool persist = false; | |
4356 | 133 |
1103 | 134 // Long options. See the comments in getopt.h for the meanings of the |
135 // fields in this structure. | |
8861 | 136 #define DOC_CACHE_FILE_OPTION 1 |
137 #define EVAL_OPTION 2 | |
138 #define EXEC_PATH_OPTION 3 | |
139 #define IMAGE_PATH_OPTION 4 | |
140 #define INFO_FILE_OPTION 5 | |
141 #define INFO_PROG_OPTION 6 | |
9336
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
142 #define LINE_EDITING_OPTION 7 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
143 #define NO_INIT_FILE_OPTION 8 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
144 #define NO_INIT_PATH_OPTION 9 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
145 #define NO_LINE_EDITING_OPTION 10 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
146 #define NO_SITE_FILE_OPTION 11 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
147 #define NO_WINDOW_SYSTEM_OPTION 12 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
148 #define PERSIST_OPTION 13 |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
149 #define TRADITIONAL_OPTION 14 |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
150 struct option long_opts[] = |
139 | 151 { |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
152 { "braindead", no_argument, 0, TRADITIONAL_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
153 { "debug", no_argument, 0, 'd' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
154 { "doc-cache-file", required_argument, 0, DOC_CACHE_FILE_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
155 { "echo-commands", no_argument, 0, 'x' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
156 { "eval", required_argument, 0, EVAL_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
157 { "exec-path", required_argument, 0, EXEC_PATH_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
158 { "help", no_argument, 0, 'h' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
159 { "image-path", required_argument, 0, IMAGE_PATH_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
160 { "info-file", required_argument, 0, INFO_FILE_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
161 { "info-program", required_argument, 0, INFO_PROG_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
162 { "interactive", no_argument, 0, 'i' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
163 { "line-editing", no_argument, 0, LINE_EDITING_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
164 { "no-history", no_argument, 0, 'H' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
165 { "no-init-file", no_argument, 0, NO_INIT_FILE_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
166 { "no-init-path", no_argument, 0, NO_INIT_PATH_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
167 { "no-line-editing", no_argument, 0, NO_LINE_EDITING_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
168 { "no-site-file", no_argument, 0, NO_SITE_FILE_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
169 { "no-window-system", no_argument, 0, NO_WINDOW_SYSTEM_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
170 { "norc", no_argument, 0, 'f' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
171 { "path", required_argument, 0, 'p' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
172 { "persist", no_argument, 0, PERSIST_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
173 { "quiet", no_argument, 0, 'q' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
174 { "silent", no_argument, 0, 'q' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
175 { "traditional", no_argument, 0, TRADITIONAL_OPTION }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
176 { "verbose", no_argument, 0, 'V' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
177 { "version", no_argument, 0, 'v' }, |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
178 { 0, 0, 0, 0 } |
139 | 179 }; |
1 | 180 |
1355 | 181 // Store the command-line options for later use. |
182 | |
183 static void | |
184 intern_argv (int argc, char **argv) | |
185 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
186 assert (symbol_table::at_top_level ()); |
4892 | 187 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
188 symbol_table::varref (".nargin.") = argc - 1; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
189 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7715
diff
changeset
|
190 symbol_table::mark_hidden (".nargin."); |
3195 | 191 |
1355 | 192 if (argc > 1) |
193 { | |
7336 | 194 octave_argv.resize (argc - 1); |
3933 | 195 |
2495 | 196 // Skip program name in argv. |
3933 | 197 int i = argc; |
198 while (--i > 0) | |
5780 | 199 octave_argv[i-1] = *(argv+i); |
1355 | 200 } |
201 } | |
202 | |
1792 | 203 static void |
204 initialize_pathsearch (void) | |
205 { | |
206 // This may seem odd, but doing it this way means that we don't have | |
207 // to modify the kpathsea library... | |
208 | |
3523 | 209 std::string odb = octave_env::getenv ("OCTAVE_DB_PATH"); |
3141 | 210 |
211 // For backward compatibility. | |
1792 | 212 |
2926 | 213 if (odb.empty ()) |
3141 | 214 odb = octave_env::getenv ("OCTAVE_DB_DIR"); |
1792 | 215 |
3141 | 216 if (odb.empty ()) |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
217 odb = Vdata_dir + file_ops::dir_sep_str () + "octave:" |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
218 + Vlibexec_dir + file_ops::dir_sep_str () + "octave"; |
1792 | 219 } |
220 | |
5654 | 221 DEFUN (__version_info__, args, , |
222 "-*- texinfo -*-\n\ | |
6678 | 223 @deftypefn {Built-in Function} {retval =} __version_info__ (@var{name}, @var{version}, @var{release}, @var{date})\n\ |
6945 | 224 Undocumented internal function.\n\ |
5654 | 225 @end deftypefn") |
226 { | |
227 octave_value retval; | |
228 | |
229 static Octave_map vinfo; | |
230 | |
231 int nargin = args.length (); | |
232 | |
5658 | 233 if (nargin == 4) |
5654 | 234 { |
6639 | 235 if (vinfo.nfields () == 0) |
5781 | 236 { |
237 vinfo.assign ("Name", args (0)); | |
238 vinfo.assign ("Version", args (1)); | |
239 vinfo.assign ("Release", args (2)); | |
240 vinfo.assign ("Date", args (3)); | |
241 } | |
242 else | |
243 { | |
244 octave_idx_type n = vinfo.numel () + 1; | |
5654 | 245 |
5781 | 246 vinfo.resize (dim_vector (n, 1)); |
247 | |
248 octave_value idx (n); | |
249 | |
250 vinfo.assign (idx, "Name", Cell (octave_value (args (0)))); | |
251 vinfo.assign (idx, "Version", Cell (octave_value (args (1)))); | |
252 vinfo.assign (idx, "Release", Cell (octave_value (args (2)))); | |
253 vinfo.assign (idx, "Date", Cell (octave_value (args (3)))); | |
254 } | |
5654 | 255 } |
256 else if (nargin == 0) | |
257 retval = vinfo; | |
258 else | |
5823 | 259 print_usage (); |
5654 | 260 |
261 return retval; | |
262 } | |
263 | |
264 static void | |
265 initialize_version_info (void) | |
266 { | |
267 octave_value_list args; | |
268 | |
5658 | 269 args(3) = OCTAVE_RELEASE_DATE; |
270 args(2) = OCTAVE_RELEASE; | |
5654 | 271 args(1) = OCTAVE_VERSION; |
272 args(0) = "GNU Octave"; | |
273 | |
274 F__version_info__ (args, 0); | |
275 } | |
276 | |
581 | 277 // Initialize by reading startup files. |
278 | |
1 | 279 static void |
280 execute_startup_files (void) | |
281 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
282 unwind_protect frame; |
315 | 283 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
284 frame.protect_var (input_from_startup_file); |
1651 | 285 |
3019 | 286 input_from_startup_file = true; |
315 | 287 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
288 std::string context; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
289 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
290 bool verbose = (verbose_flag && ! inhibit_startup_message); |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
291 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
292 bool require_file = false; |
578 | 293 |
2239 | 294 if (read_site_files) |
1 | 295 { |
2239 | 296 // Execute commands from the site-wide configuration file. |
297 // First from the file $(prefix)/lib/octave/site/m/octaverc | |
298 // (if it exists), then from the file | |
3597 | 299 // $(prefix)/share/octave/$(version)/m/octaverc (if it exists). |
1755 | 300 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
301 source_file (Vlocal_site_defaults_file, context, verbose, require_file); |
1755 | 302 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
303 source_file (Vsite_defaults_file, context, verbose, require_file); |
1 | 304 } |
305 | |
2239 | 306 if (read_init_files) |
307 { | |
2512 | 308 // Try to execute commands from $HOME/$OCTAVE_INITFILE and |
309 // $OCTAVE_INITFILE. If $OCTAVE_INITFILE is not set, .octaverc | |
310 // is assumed. | |
2239 | 311 |
4804 | 312 bool home_rc_already_executed = false; |
2512 | 313 |
3523 | 314 std::string initfile = octave_env::getenv ("OCTAVE_INITFILE"); |
2512 | 315 |
2926 | 316 if (initfile.empty ()) |
2512 | 317 initfile = ".octaverc"; |
318 | |
3523 | 319 std::string home_dir = octave_env::get_home_directory (); |
2926 | 320 |
4804 | 321 std::string home_rc = octave_env::make_absolute (initfile, home_dir); |
322 | |
323 std::string local_rc; | |
2239 | 324 |
5781 | 325 if (! home_rc.empty ()) |
2239 | 326 { |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
327 source_file (home_rc, context, verbose, require_file); |
2239 | 328 |
329 // Names alone are not enough. | |
330 | |
331 file_stat fs_home_rc (home_rc); | |
332 | |
333 if (fs_home_rc) | |
334 { | |
4804 | 335 // We want to check for curr_dir after executing home_rc |
336 // because doing that may change the working directory. | |
337 | |
338 std::string curr_dir = octave_env::getcwd (); | |
339 | |
340 local_rc = octave_env::make_absolute (initfile, curr_dir); | |
341 | |
6598 | 342 home_rc_already_executed = same_file (home_rc, local_rc); |
2239 | 343 } |
344 } | |
345 | |
346 if (! home_rc_already_executed) | |
4804 | 347 { |
348 if (local_rc.empty ()) | |
349 { | |
350 std::string curr_dir = octave_env::getcwd (); | |
351 | |
352 local_rc = octave_env::make_absolute (initfile, curr_dir); | |
353 } | |
354 | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
355 source_file (local_rc, context, verbose, require_file); |
4804 | 356 } |
2239 | 357 } |
1 | 358 } |
359 | |
5189 | 360 static int |
361 execute_eval_option_code (const std::string& code) | |
362 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
363 unwind_protect frame; |
5189 | 364 |
7202 | 365 octave_save_signal_mask (); |
366 | |
367 can_interrupt = true; | |
368 | |
369 octave_signal_hook = octave_signal_handler; | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
370 octave_interrupt_hook = 0; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
371 octave_bad_alloc_hook = 0; |
7202 | 372 |
373 octave_catch_interrupts (); | |
374 | |
375 octave_initialized = true; | |
376 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
377 frame.protect_var (interactive); |
5189 | 378 |
379 interactive = false; | |
380 | |
381 int parse_status = 0; | |
382 | |
6487 | 383 try |
384 { | |
385 eval_string (code, false, parse_status, 0); | |
386 } | |
7202 | 387 catch (octave_interrupt_exception) |
388 { | |
389 recover_from_exception (); | |
390 octave_stdout << "\n"; | |
9383 | 391 if (quitting_gracefully) |
392 clean_up_and_exit (exit_status); | |
7202 | 393 } |
6487 | 394 catch (std::bad_alloc) |
395 { | |
6680 | 396 std::cerr << "error: memory exhausted or requested size too large for range of Octave's index type -- eval failed" |
397 << std::endl; | |
6487 | 398 } |
5189 | 399 |
400 return parse_status; | |
401 } | |
402 | |
403 static void | |
404 execute_command_line_file (const std::string& fname) | |
405 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
406 unwind_protect frame; |
5189 | 407 |
7202 | 408 octave_save_signal_mask (); |
409 | |
410 can_interrupt = true; | |
411 | |
412 octave_signal_hook = octave_signal_handler; | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
413 octave_interrupt_hook = 0; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
414 octave_bad_alloc_hook = 0; |
7202 | 415 |
416 octave_catch_interrupts (); | |
417 | |
418 octave_initialized = true; | |
419 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
420 frame.protect_var (interactive); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
421 frame.protect_var (reading_script_file); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
422 frame.protect_var (input_from_command_line_file); |
5189 | 423 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
424 frame.protect_var (curr_fcn_file_name); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
425 frame.protect_var (curr_fcn_file_full_name); |
5189 | 426 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
427 frame.protect_var (octave_program_invocation_name); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
428 frame.protect_var (octave_program_name); |
5189 | 429 |
430 interactive = false; | |
431 reading_script_file = true; | |
432 input_from_command_line_file = true; | |
433 | |
434 curr_fcn_file_name = fname; | |
435 curr_fcn_file_full_name = curr_fcn_file_name; | |
436 | |
5780 | 437 octave_program_invocation_name = curr_fcn_file_name; |
5189 | 438 |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
439 size_t pos = curr_fcn_file_name.find_last_of (file_ops::dir_sep_chars ()); |
5189 | 440 |
8021 | 441 std::string tmp = (pos != std::string::npos) |
5189 | 442 ? curr_fcn_file_name.substr (pos+1) : curr_fcn_file_name; |
443 | |
5780 | 444 octave_program_name = tmp; |
5189 | 445 |
6504 | 446 try |
447 { | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
448 std::string context; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
449 bool verbose = false; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
450 bool require_file = true; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
451 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
452 source_file (fname, context, verbose, require_file, "octave"); |
6504 | 453 } |
7202 | 454 catch (octave_interrupt_exception) |
455 { | |
456 recover_from_exception (); | |
457 octave_stdout << "\n"; | |
9383 | 458 if (quitting_gracefully) |
459 clean_up_and_exit (exit_status); | |
7202 | 460 } |
6504 | 461 catch (std::bad_alloc) |
462 { | |
6680 | 463 std::cerr << "error: memory exhausted or requested size too large for range of Octave's index type -- execution of " |
464 << fname << " failed" << std::endl; | |
6504 | 465 } |
5189 | 466 } |
467 | |
581 | 468 // Usage message with extra help. |
469 | |
1 | 470 static void |
471 verbose_usage (void) | |
472 { | |
3922 | 473 std::cout << OCTAVE_NAME_VERSION_COPYRIGHT_COPYING_AND_WARRANTY "\n\ |
1613 | 474 \n\ |
475 Usage: octave [options]\n\ | |
476 \n\ | |
477 Options:\n\ | |
1119 | 478 \n\ |
3180 | 479 --debug, -d Enter parser debugging mode.\n\ |
8923
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
480 --doc-cache-file FILE Use doc cache file FILE.\n\ |
3180 | 481 --echo-commands, -x Echo commands as they are executed.\n\ |
5191 | 482 --eval CODE Evaluate CODE. Exit when done unless --persist.\n\ |
1613 | 483 --exec-path PATH Set path for executing subprograms.\n\ |
3180 | 484 --help, -h, -? Print short help message and exit.\n\ |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
485 --image-path PATH Add PATH to head of image search path.\n\ |
1613 | 486 --info-file FILE Use top-level info file FILE.\n\ |
487 --info-program PROGRAM Use PROGRAM for reading info files.\n\ | |
3180 | 488 --interactive, -i Force interactive behavior.\n\ |
6938 | 489 --line-editing Force readline use for command-line editing.\n\ |
3180 | 490 --no-history, -H Don't save commands to the history list\n\ |
2470 | 491 --no-init-file Don't read the ~/.octaverc or .octaverc files.\n\ |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
492 --no-init-path Don't initialize function search path.\n\ |
2212 | 493 --no-line-editing Don't use readline for command-line editing.\n\ |
2470 | 494 --no-site-file Don't read the site-wide octaverc file.\n\ |
9335
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
495 --no-window-system Disable window system, including graphics.\n\ |
3238 | 496 --norc, -f Don't read any initialization files.\n\ |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
497 --path PATH, -p PATH Add PATH to head of function search path.\n\ |
5189 | 498 --persist Go interactive after --eval or reading from FILE.\n\ |
3180 | 499 --silent, -q Don't print message at startup.\n\ |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
500 --traditional Set variables for closer MATLAB compatibility.\n\ |
3180 | 501 --verbose, -V Enable verbose output in some cases.\n\ |
502 --version, -v Print version number and exit.\n\ | |
1119 | 503 \n\ |
5190 | 504 FILE Execute commands from FILE. Exit when done\n\ |
5191 | 505 unless --persist is also specified.\n\ |
4829 | 506 \n" |
507 OCTAVE_WWW_STATEMENT "\n\ | |
4356 | 508 \n" |
509 OCTAVE_CONTRIB_STATEMENT "\n\ | |
510 \n" | |
511 OCTAVE_BUGS_STATEMENT "\n"; | |
285 | 512 |
613 | 513 exit (0); |
1 | 514 } |
515 | |
581 | 516 // Terse usage messsage. |
517 | |
1 | 518 static void |
519 usage (void) | |
520 { | |
3531 | 521 std::cerr << "usage: " << usage_string << "\n"; |
1 | 522 exit (1); |
523 } | |
524 | |
525 static void | |
526 print_version_and_exit (void) | |
527 { | |
3922 | 528 std::cout << OCTAVE_NAME_VERSION_COPYRIGHT_COPYING_WARRANTY_AND_BUGS "\n"; |
1 | 529 exit (0); |
530 } | |
531 | |
721 | 532 static void |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
533 lo_error_handler (const char *fmt, ...) |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
534 { |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
535 va_list args; |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
536 va_start (args, fmt); |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
537 verror_with_cfn (fmt, args); |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
538 va_end (args); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
539 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
540 octave_throw_execution_exception (); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
541 } |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
542 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
543 static void |
721 | 544 initialize_error_handlers () |
545 { | |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
546 set_liboctave_error_handler (lo_error_handler); |
3325 | 547 set_liboctave_warning_handler (warning); |
5781 | 548 set_liboctave_warning_with_id_handler (warning_with_id); |
721 | 549 } |
550 | |
1410 | 551 // What happens on --traditional. |
552 | |
553 static void | |
554 maximum_braindamage (void) | |
555 { | |
5189 | 556 persist = true; |
557 | |
5794 | 558 bind_internal_variable ("PS1", ">> "); |
559 bind_internal_variable ("PS2", ""); | |
560 bind_internal_variable ("beep_on_error", true); | |
8473
4dd0213bb883
octave.cc (maximum_braindamage): set confirm_recursive_rmdir to false
John W. Eaton <jwe@octave.org>
parents:
8347
diff
changeset
|
561 bind_internal_variable ("confirm_recursive_rmdir", false); |
5794 | 562 bind_internal_variable ("crash_dumps_octave_core", false); |
563 bind_internal_variable ("default_save_options", "-mat-binary"); | |
564 bind_internal_variable ("fixed_point_format", true); | |
565 bind_internal_variable ("history_timestamp_format_string", | |
5305 | 566 "%%-- %D %I:%M %p --%%"); |
5794 | 567 bind_internal_variable ("page_screen_output", false); |
568 bind_internal_variable ("print_empty_dimensions", false); | |
5904 | 569 |
9584
0fcbfddaa87f
allow abbreviated graphics property names to match, with optional warning
John W. Eaton <jwe@octave.org>
parents:
9383
diff
changeset
|
570 disable_warning ("Octave:abbreviated-property-match"); |
6159 | 571 disable_warning ("Octave:fopen-file-in-path"); |
5904 | 572 disable_warning ("Octave:function-name-clash"); |
6159 | 573 disable_warning ("Octave:load-file-in-path"); |
1410 | 574 } |
575 | |
581 | 576 // You guessed it. |
577 | |
1 | 578 int |
4368 | 579 octave_main (int argc, char **argv, int embedded) |
1 | 580 { |
3019 | 581 octave_env::set_program_name (argv[0]); |
582 | |
5780 | 583 octave_program_invocation_name = octave_env::get_program_invocation_name (); |
584 octave_program_name = octave_env::get_program_name (); | |
585 | |
2205 | 586 // The order of these calls is important. The call to |
2926 | 587 // install_defaults must come before install_builtins because |
3019 | 588 // default variable values must be available for the variables to be |
2205 | 589 // installed, and the call to install_builtins must come before the |
590 // options are processed because some command line options override | |
5794 | 591 // defaults by calling bind_internal_variable. |
721 | 592 |
5844 | 593 init_signals (); |
594 | |
1 | 595 sysdep_init (); |
596 | |
4159 | 597 // The idea here is to force xerbla to be referenced so that we will |
598 // link to our own version instead of the one provided by the BLAS | |
599 // library. But octave_NaN should never be -1, so we should never | |
600 // actually call xerbla. | |
601 | |
602 if (octave_NaN == -1) | |
603 F77_FUNC (xerbla, XERBLA) ("octave", 13, 6L); | |
604 | |
721 | 605 initialize_error_handlers (); |
223 | 606 |
5794 | 607 initialize_default_warning_state (); |
608 | |
2926 | 609 install_defaults (); |
1 | 610 |
1792 | 611 initialize_pathsearch (); |
1744 | 612 |
4368 | 613 if (! embedded) |
614 install_signal_handlers (); | |
9255
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
615 else |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
616 quit_allowed = false; |
2205 | 617 |
618 initialize_file_io (); | |
619 | |
2375 | 620 install_types (); |
621 | |
622 install_ops (); | |
2205 | 623 |
624 install_builtins (); | |
625 | |
6938 | 626 bool forced_line_editing = false; |
627 | |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
628 bool read_history_file = true; |
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
629 |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
630 while (true) |
1 | 631 { |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
632 int long_idx; |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
633 |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
634 int optc = getopt_long (argc, argv, short_opts, long_opts, &long_idx); |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
635 |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
636 if (optc < 0) |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
637 break; |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
638 |
139 | 639 switch (optc) |
1 | 640 { |
3180 | 641 case 'H': |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
642 read_history_file = false; |
5794 | 643 bind_internal_variable ("saving_history", false); |
3180 | 644 break; |
645 | |
793 | 646 case 'V': |
2239 | 647 verbose_flag = true; |
793 | 648 break; |
649 | |
1 | 650 case 'd': |
4753 | 651 // This is the same as yydebug in parse.y. |
652 octave_debug++; | |
1 | 653 break; |
777 | 654 |
1 | 655 case 'f': |
2239 | 656 read_init_files = false; |
657 read_site_files = false; | |
1 | 658 break; |
777 | 659 |
1 | 660 case 'h': |
661 case '?': | |
662 verbose_usage (); | |
663 break; | |
777 | 664 |
1 | 665 case 'i': |
3019 | 666 forced_interactive = true; |
1 | 667 break; |
777 | 668 |
1 | 669 case 'p': |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
670 if (optarg) |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
671 load_path::set_command_line_path (optarg); |
1 | 672 break; |
777 | 673 |
1 | 674 case 'q': |
2239 | 675 inhibit_startup_message = true; |
1 | 676 break; |
777 | 677 |
1 | 678 case 'x': |
2205 | 679 { |
680 double tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_CMD_LINE); | |
5794 | 681 bind_internal_variable ("echo_executing_commands", tmp); |
2205 | 682 } |
1 | 683 break; |
777 | 684 |
1 | 685 case 'v': |
686 print_version_and_exit (); | |
687 break; | |
777 | 688 |
8861 | 689 case DOC_CACHE_FILE_OPTION: |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
690 if (optarg) |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
691 bind_internal_variable ("doc_cache_file", optarg); |
8861 | 692 break; |
693 | |
5189 | 694 case EVAL_OPTION: |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
695 if (optarg) |
5193 | 696 { |
697 if (code_to_eval.empty ()) | |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
698 code_to_eval = optarg; |
5193 | 699 else |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
700 code_to_eval += std::string (" ") + optarg; |
5193 | 701 } |
5189 | 702 break; |
703 | |
1613 | 704 case EXEC_PATH_OPTION: |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
705 if (optarg) |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
706 set_exec_path (optarg); |
5814 | 707 break; |
708 | |
709 case IMAGE_PATH_OPTION: | |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
710 if (optarg) |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
711 set_image_path (optarg); |
1613 | 712 break; |
713 | |
186 | 714 case INFO_FILE_OPTION: |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
715 if (optarg) |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
716 bind_internal_variable ("info_file", optarg); |
186 | 717 break; |
777 | 718 |
1613 | 719 case INFO_PROG_OPTION: |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
720 if (optarg) |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
721 bind_internal_variable ("info_program", optarg); |
1613 | 722 break; |
723 | |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
724 case LINE_EDITING_OPTION: |
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
725 forced_line_editing = true; |
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
726 break; |
6938 | 727 |
2239 | 728 case NO_INIT_FILE_OPTION: |
729 read_init_files = false; | |
730 break; | |
731 | |
9336
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
732 case NO_INIT_PATH_OPTION: |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
733 set_initial_path = false; |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
734 break; |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
735 |
1821 | 736 case NO_LINE_EDITING_OPTION: |
3019 | 737 line_editing = false; |
2239 | 738 break; |
739 | |
740 case NO_SITE_FILE_OPTION: | |
741 read_site_files = 0; | |
1821 | 742 break; |
743 | |
9335
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
744 case NO_WINDOW_SYSTEM_OPTION: |
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
745 display_info::no_window_system (); |
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
746 break; |
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
747 |
9336
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
748 case PERSIST_OPTION: |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
749 persist = true; |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
750 break; |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
751 |
1410 | 752 case TRADITIONAL_OPTION: |
2239 | 753 traditional = true; |
1410 | 754 break; |
755 | |
1 | 756 default: |
757 usage (); | |
758 break; | |
759 } | |
760 } | |
761 | |
2077 | 762 // Make sure we clean up when we exit. Also allow users to register |
763 // functions. If we don't have atexit or on_exit, we're going to | |
764 // leave some junk files around if we exit abnormally. | |
765 | |
766 atexit (do_octave_atexit); | |
1 | 767 |
9320
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
768 // Is input coming from a terminal? If so, we are probably |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
769 // interactive. |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
770 |
9999
653716f3d976
get_debug_input: force interactive input mode; don't get user input unless stdin is a tty
John W. Eaton <jwe@octave.org>
parents:
9753
diff
changeset
|
771 // If stdin is not a tty, then we are reading commands from a pipe or |
653716f3d976
get_debug_input: force interactive input mode; don't get user input unless stdin is a tty
John W. Eaton <jwe@octave.org>
parents:
9753
diff
changeset
|
772 // a redirected file. |
653716f3d976
get_debug_input: force interactive input mode; don't get user input unless stdin is a tty
John W. Eaton <jwe@octave.org>
parents:
9753
diff
changeset
|
773 stdin_is_tty = isatty (fileno (stdin)); |
653716f3d976
get_debug_input: force interactive input mode; don't get user input unless stdin is a tty
John W. Eaton <jwe@octave.org>
parents:
9753
diff
changeset
|
774 |
653716f3d976
get_debug_input: force interactive input mode; don't get user input unless stdin is a tty
John W. Eaton <jwe@octave.org>
parents:
9753
diff
changeset
|
775 interactive = (! embedded && stdin_is_tty && isatty (fileno (stdout))); |
9320
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
776 |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
777 if (! interactive && ! forced_line_editing) |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
778 line_editing = false; |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
779 |
9321
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
9320
diff
changeset
|
780 // Force default line editor if we don't want readline editing. |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
9320
diff
changeset
|
781 if (! line_editing) |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
9320
diff
changeset
|
782 command_editor::force_default_editor (); |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
9320
diff
changeset
|
783 |
1358 | 784 // These can come after command line args since none of them set any |
785 // defaults that might be changed by command line options. | |
581 | 786 |
9320
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
787 if (line_editing) |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
788 initialize_command_input (); |
315 | 789 |
578 | 790 if (! inhibit_startup_message) |
3538 | 791 std::cout << OCTAVE_STARTUP_MESSAGE "\n" << std::endl; |
578 | 792 |
1410 | 793 if (traditional) |
794 maximum_braindamage (); | |
795 | |
4217 | 796 octave_interpreter_ready = true; |
797 | |
5654 | 798 initialize_version_info (); |
799 | |
8099
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
800 // Make all command-line arguments available to startup files, |
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
801 // including PKG_ADD files. |
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
802 |
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
803 intern_argv (argc, argv); |
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
804 |
6365 | 805 load_path::initialize (set_initial_path); |
4217 | 806 |
2239 | 807 execute_startup_files (); |
1651 | 808 |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
809 initialize_history (read_history_file); |
1 | 810 |
578 | 811 if (! inhibit_startup_message && reading_startup_message_printed) |
3538 | 812 std::cout << std::endl; |
578 | 813 |
1358 | 814 // If there is an extra argument, see if it names a file to read. |
815 // Additional arguments are taken as command line options for the | |
816 // script. | |
1 | 817 |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
818 int last_arg_idx = optind; |
3019 | 819 |
1817 | 820 int remaining_args = argc - last_arg_idx; |
3019 | 821 |
5189 | 822 if (! code_to_eval.empty ()) |
149 | 823 { |
5189 | 824 int parse_status = execute_eval_option_code (code_to_eval); |
825 | |
5242 | 826 if (! (persist || remaining_args > 0)) |
5502 | 827 clean_up_and_exit (parse_status || error_state ? 1 : 0); |
1 | 828 } |
829 | |
5189 | 830 if (remaining_args > 0) |
831 { | |
832 // If we are running an executable script (#! /bin/octave) then | |
833 // we should only see the args passed to the script. | |
834 | |
835 intern_argv (remaining_args, argv+last_arg_idx); | |
836 | |
837 execute_command_line_file (argv[last_arg_idx]); | |
838 | |
839 if (! persist) | |
5502 | 840 clean_up_and_exit (error_state ? 1 : 0); |
5189 | 841 } |
842 | |
843 // Avoid counting commands executed from startup files. | |
844 | |
845 command_editor::reset_current_command_number (1); | |
846 | |
847 // Now argv should have the full set of args. | |
848 intern_argv (argc, argv); | |
849 | |
850 if (! embedded) | |
851 switch_to_buffer (create_buffer (get_input_from_stdin ())); | |
852 | |
1358 | 853 // Force input to be echoed if not really interactive, but the user |
854 // has forced interactive behavior. | |
1 | 855 |
1907 | 856 if (! interactive && forced_interactive) |
287 | 857 { |
2926 | 858 command_editor::blink_matching_paren (false); |
1588 | 859 |
5775 | 860 // FIXME -- is this the right thing to do? |
1588 | 861 |
5794 | 862 bind_internal_variable ("echo_executing_commands", ECHO_CMD_LINE); |
287 | 863 } |
1 | 864 |
4368 | 865 if (embedded) |
5502 | 866 { |
5775 | 867 // FIXME -- do we need to do any cleanup here before |
5502 | 868 // returning? If we don't, what will happen to Octave functions |
869 // that have been registered to execute with atexit, for example? | |
870 | |
871 return 1; | |
872 } | |
4368 | 873 |
5189 | 874 int retval = main_loop (); |
1 | 875 |
1005 | 876 if (retval == 1 && ! error_state) |
877 retval = 0; | |
878 | |
1 | 879 clean_up_and_exit (retval); |
4247 | 880 |
881 return 0; | |
1 | 882 } |
883 | |
5780 | 884 DEFUN (argv, args, , |
885 "-*- texinfo -*-\n\ | |
886 @deftypefn {Built-in Function} {} argv ()\n\ | |
887 Return the command line arguments passed to Octave. For example,\n\ | |
888 if you invoked Octave using the command\n\ | |
889 \n\ | |
890 @example\n\ | |
891 octave --no-line-editing --silent\n\ | |
892 @end example\n\ | |
893 \n\ | |
894 @noindent\n\ | |
895 @code{argv} would return a cell array of strings with the elements\n\ | |
896 @code{--no-line-editing} and @code{--silent}.\n\ | |
897 \n\ | |
898 If you write an executable Octave script, @code{argv} will return the\n\ | |
899 list of arguments passed to the script. @xref{Executable Octave Programs},\n\ | |
900 for an example of how to create an executable Octave script.\n\ | |
901 @end deftypefn") | |
902 { | |
903 octave_value retval; | |
904 | |
905 if (args.length () == 0) | |
906 retval = Cell (octave_argv); | |
907 else | |
5823 | 908 print_usage (); |
5780 | 909 |
910 return retval; | |
911 } | |
912 | |
913 DEFUN (program_invocation_name, args, , | |
914 "-*- texinfo -*-\n\ | |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9584
diff
changeset
|
915 @deftypefn {Built-in Function} {} program_invocation_name ()\n\ |
5780 | 916 Return the name that was typed at the shell prompt to run Octave.\n\ |
917 \n\ | |
918 If executing a script from the command line (e.g., @code{octave foo.m})\n\ | |
919 or using an executable Octave script, the program name is set to the\n\ | |
920 name of the script. @xref{Executable Octave Programs}, for an example of\n\ | |
921 how to create an executable Octave script.\n\ | |
922 @seealso{program_name}\n\ | |
923 @end deftypefn") | |
924 { | |
925 octave_value retval; | |
926 | |
927 if (args.length () == 0) | |
928 retval = octave_program_invocation_name; | |
929 else | |
5823 | 930 print_usage (); |
5780 | 931 |
932 return retval; | |
933 } | |
934 | |
935 DEFUN (program_name, args, , | |
936 "-*- texinfo -*-\n\ | |
937 @deftypefn {Built-in Function} {} program_name ()\n\ | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8273
diff
changeset
|
938 Return the last component of the value returned by\n\ |
5780 | 939 @code{program_invocation_name}.\n\ |
940 @seealso{program_invocation_name}\n\ | |
941 @end deftypefn") | |
942 { | |
943 octave_value retval; | |
944 | |
945 if (args.length () == 0) | |
946 retval = octave_program_name; | |
947 else | |
5823 | 948 print_usage (); |
5780 | 949 |
950 return retval; | |
951 } |