Mercurial > hg > octave-nkf
annotate src/octave.cc @ 10250:2d47356a7a1a
use gnulib getcwd module
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 03 Feb 2010 03:07:06 -0500 |
parents | b0485f5a921e |
children | 57a59eae83cc |
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 | |
10250 | 338 local_rc = octave_env::make_absolute (initfile); |
4804 | 339 |
6598 | 340 home_rc_already_executed = same_file (home_rc, local_rc); |
2239 | 341 } |
342 } | |
343 | |
344 if (! home_rc_already_executed) | |
4804 | 345 { |
346 if (local_rc.empty ()) | |
10250 | 347 local_rc = octave_env::make_absolute (initfile); |
4804 | 348 |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
349 source_file (local_rc, context, verbose, require_file); |
4804 | 350 } |
2239 | 351 } |
1 | 352 } |
353 | |
5189 | 354 static int |
355 execute_eval_option_code (const std::string& code) | |
356 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
357 unwind_protect frame; |
5189 | 358 |
7202 | 359 octave_save_signal_mask (); |
360 | |
361 can_interrupt = true; | |
362 | |
363 octave_signal_hook = octave_signal_handler; | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
364 octave_interrupt_hook = 0; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
365 octave_bad_alloc_hook = 0; |
7202 | 366 |
367 octave_catch_interrupts (); | |
368 | |
369 octave_initialized = true; | |
370 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
371 frame.protect_var (interactive); |
5189 | 372 |
373 interactive = false; | |
374 | |
375 int parse_status = 0; | |
376 | |
6487 | 377 try |
378 { | |
379 eval_string (code, false, parse_status, 0); | |
380 } | |
7202 | 381 catch (octave_interrupt_exception) |
382 { | |
383 recover_from_exception (); | |
384 octave_stdout << "\n"; | |
9383 | 385 if (quitting_gracefully) |
386 clean_up_and_exit (exit_status); | |
7202 | 387 } |
6487 | 388 catch (std::bad_alloc) |
389 { | |
6680 | 390 std::cerr << "error: memory exhausted or requested size too large for range of Octave's index type -- eval failed" |
391 << std::endl; | |
6487 | 392 } |
5189 | 393 |
394 return parse_status; | |
395 } | |
396 | |
397 static void | |
398 execute_command_line_file (const std::string& fname) | |
399 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
400 unwind_protect frame; |
5189 | 401 |
7202 | 402 octave_save_signal_mask (); |
403 | |
404 can_interrupt = true; | |
405 | |
406 octave_signal_hook = octave_signal_handler; | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
407 octave_interrupt_hook = 0; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
408 octave_bad_alloc_hook = 0; |
7202 | 409 |
410 octave_catch_interrupts (); | |
411 | |
412 octave_initialized = true; | |
413 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
414 frame.protect_var (interactive); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
415 frame.protect_var (reading_script_file); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
416 frame.protect_var (input_from_command_line_file); |
5189 | 417 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
418 frame.protect_var (curr_fcn_file_name); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
419 frame.protect_var (curr_fcn_file_full_name); |
5189 | 420 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
421 frame.protect_var (octave_program_invocation_name); |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9999
diff
changeset
|
422 frame.protect_var (octave_program_name); |
5189 | 423 |
424 interactive = false; | |
425 reading_script_file = true; | |
426 input_from_command_line_file = true; | |
427 | |
428 curr_fcn_file_name = fname; | |
429 curr_fcn_file_full_name = curr_fcn_file_name; | |
430 | |
5780 | 431 octave_program_invocation_name = curr_fcn_file_name; |
5189 | 432 |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
433 size_t pos = curr_fcn_file_name.find_last_of (file_ops::dir_sep_chars ()); |
5189 | 434 |
8021 | 435 std::string tmp = (pos != std::string::npos) |
5189 | 436 ? curr_fcn_file_name.substr (pos+1) : curr_fcn_file_name; |
437 | |
5780 | 438 octave_program_name = tmp; |
5189 | 439 |
6504 | 440 try |
441 { | |
7715
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
442 std::string context; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
443 bool verbose = false; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
444 bool require_file = true; |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
445 |
5b4d278ec828
parse scripts completely before executing
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
446 source_file (fname, context, verbose, require_file, "octave"); |
6504 | 447 } |
7202 | 448 catch (octave_interrupt_exception) |
449 { | |
450 recover_from_exception (); | |
451 octave_stdout << "\n"; | |
9383 | 452 if (quitting_gracefully) |
453 clean_up_and_exit (exit_status); | |
7202 | 454 } |
6504 | 455 catch (std::bad_alloc) |
456 { | |
6680 | 457 std::cerr << "error: memory exhausted or requested size too large for range of Octave's index type -- execution of " |
458 << fname << " failed" << std::endl; | |
6504 | 459 } |
5189 | 460 } |
461 | |
581 | 462 // Usage message with extra help. |
463 | |
1 | 464 static void |
465 verbose_usage (void) | |
466 { | |
3922 | 467 std::cout << OCTAVE_NAME_VERSION_COPYRIGHT_COPYING_AND_WARRANTY "\n\ |
1613 | 468 \n\ |
469 Usage: octave [options]\n\ | |
470 \n\ | |
471 Options:\n\ | |
1119 | 472 \n\ |
3180 | 473 --debug, -d Enter parser debugging mode.\n\ |
8923
d47290508a55
document --doc-cache-file option
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
474 --doc-cache-file FILE Use doc cache file FILE.\n\ |
3180 | 475 --echo-commands, -x Echo commands as they are executed.\n\ |
5191 | 476 --eval CODE Evaluate CODE. Exit when done unless --persist.\n\ |
1613 | 477 --exec-path PATH Set path for executing subprograms.\n\ |
3180 | 478 --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
|
479 --image-path PATH Add PATH to head of image search path.\n\ |
1613 | 480 --info-file FILE Use top-level info file FILE.\n\ |
481 --info-program PROGRAM Use PROGRAM for reading info files.\n\ | |
3180 | 482 --interactive, -i Force interactive behavior.\n\ |
6938 | 483 --line-editing Force readline use for command-line editing.\n\ |
3180 | 484 --no-history, -H Don't save commands to the history list\n\ |
2470 | 485 --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
|
486 --no-init-path Don't initialize function search path.\n\ |
2212 | 487 --no-line-editing Don't use readline for command-line editing.\n\ |
2470 | 488 --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
|
489 --no-window-system Disable window system, including graphics.\n\ |
3238 | 490 --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
|
491 --path PATH, -p PATH Add PATH to head of function search path.\n\ |
5189 | 492 --persist Go interactive after --eval or reading from FILE.\n\ |
3180 | 493 --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
|
494 --traditional Set variables for closer MATLAB compatibility.\n\ |
3180 | 495 --verbose, -V Enable verbose output in some cases.\n\ |
496 --version, -v Print version number and exit.\n\ | |
1119 | 497 \n\ |
5190 | 498 FILE Execute commands from FILE. Exit when done\n\ |
5191 | 499 unless --persist is also specified.\n\ |
4829 | 500 \n" |
501 OCTAVE_WWW_STATEMENT "\n\ | |
4356 | 502 \n" |
503 OCTAVE_CONTRIB_STATEMENT "\n\ | |
504 \n" | |
505 OCTAVE_BUGS_STATEMENT "\n"; | |
285 | 506 |
613 | 507 exit (0); |
1 | 508 } |
509 | |
581 | 510 // Terse usage messsage. |
511 | |
1 | 512 static void |
513 usage (void) | |
514 { | |
3531 | 515 std::cerr << "usage: " << usage_string << "\n"; |
1 | 516 exit (1); |
517 } | |
518 | |
519 static void | |
520 print_version_and_exit (void) | |
521 { | |
3922 | 522 std::cout << OCTAVE_NAME_VERSION_COPYRIGHT_COPYING_WARRANTY_AND_BUGS "\n"; |
1 | 523 exit (0); |
524 } | |
525 | |
721 | 526 static void |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
527 lo_error_handler (const char *fmt, ...) |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
528 { |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
529 va_list args; |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
530 va_start (args, fmt); |
9753
892e2aa7bc75
improve error messages by auto-prepending current function name
Jaroslav Hajek <highegg@gmail.com>
parents:
9724
diff
changeset
|
531 verror_with_cfn (fmt, args); |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
532 va_end (args); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
533 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
534 octave_throw_execution_exception (); |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
535 } |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
536 |
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
537 static void |
721 | 538 initialize_error_handlers () |
539 { | |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
540 set_liboctave_error_handler (lo_error_handler); |
3325 | 541 set_liboctave_warning_handler (warning); |
5781 | 542 set_liboctave_warning_with_id_handler (warning_with_id); |
721 | 543 } |
544 | |
1410 | 545 // What happens on --traditional. |
546 | |
547 static void | |
548 maximum_braindamage (void) | |
549 { | |
5189 | 550 persist = true; |
551 | |
5794 | 552 bind_internal_variable ("PS1", ">> "); |
553 bind_internal_variable ("PS2", ""); | |
554 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
|
555 bind_internal_variable ("confirm_recursive_rmdir", false); |
5794 | 556 bind_internal_variable ("crash_dumps_octave_core", false); |
557 bind_internal_variable ("default_save_options", "-mat-binary"); | |
558 bind_internal_variable ("fixed_point_format", true); | |
559 bind_internal_variable ("history_timestamp_format_string", | |
5305 | 560 "%%-- %D %I:%M %p --%%"); |
5794 | 561 bind_internal_variable ("page_screen_output", false); |
562 bind_internal_variable ("print_empty_dimensions", false); | |
5904 | 563 |
9584
0fcbfddaa87f
allow abbreviated graphics property names to match, with optional warning
John W. Eaton <jwe@octave.org>
parents:
9383
diff
changeset
|
564 disable_warning ("Octave:abbreviated-property-match"); |
6159 | 565 disable_warning ("Octave:fopen-file-in-path"); |
5904 | 566 disable_warning ("Octave:function-name-clash"); |
6159 | 567 disable_warning ("Octave:load-file-in-path"); |
1410 | 568 } |
569 | |
581 | 570 // You guessed it. |
571 | |
1 | 572 int |
4368 | 573 octave_main (int argc, char **argv, int embedded) |
1 | 574 { |
3019 | 575 octave_env::set_program_name (argv[0]); |
576 | |
5780 | 577 octave_program_invocation_name = octave_env::get_program_invocation_name (); |
578 octave_program_name = octave_env::get_program_name (); | |
579 | |
2205 | 580 // The order of these calls is important. The call to |
2926 | 581 // install_defaults must come before install_builtins because |
3019 | 582 // default variable values must be available for the variables to be |
2205 | 583 // installed, and the call to install_builtins must come before the |
584 // options are processed because some command line options override | |
5794 | 585 // defaults by calling bind_internal_variable. |
721 | 586 |
5844 | 587 init_signals (); |
588 | |
1 | 589 sysdep_init (); |
590 | |
4159 | 591 // The idea here is to force xerbla to be referenced so that we will |
592 // link to our own version instead of the one provided by the BLAS | |
593 // library. But octave_NaN should never be -1, so we should never | |
594 // actually call xerbla. | |
595 | |
596 if (octave_NaN == -1) | |
597 F77_FUNC (xerbla, XERBLA) ("octave", 13, 6L); | |
598 | |
721 | 599 initialize_error_handlers (); |
223 | 600 |
5794 | 601 initialize_default_warning_state (); |
602 | |
2926 | 603 install_defaults (); |
1 | 604 |
1792 | 605 initialize_pathsearch (); |
1744 | 606 |
4368 | 607 if (! embedded) |
608 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
|
609 else |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
610 quit_allowed = false; |
2205 | 611 |
612 initialize_file_io (); | |
613 | |
2375 | 614 install_types (); |
615 | |
616 install_ops (); | |
2205 | 617 |
618 install_builtins (); | |
619 | |
6938 | 620 bool forced_line_editing = false; |
621 | |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
622 bool read_history_file = true; |
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
623 |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
624 while (true) |
1 | 625 { |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
626 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
|
627 |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
628 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
|
629 |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
630 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
|
631 break; |
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
632 |
139 | 633 switch (optc) |
1 | 634 { |
3180 | 635 case 'H': |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
636 read_history_file = false; |
5794 | 637 bind_internal_variable ("saving_history", false); |
3180 | 638 break; |
639 | |
793 | 640 case 'V': |
2239 | 641 verbose_flag = true; |
793 | 642 break; |
643 | |
1 | 644 case 'd': |
4753 | 645 // This is the same as yydebug in parse.y. |
646 octave_debug++; | |
1 | 647 break; |
777 | 648 |
1 | 649 case 'f': |
2239 | 650 read_init_files = false; |
651 read_site_files = false; | |
1 | 652 break; |
777 | 653 |
1 | 654 case 'h': |
655 case '?': | |
656 verbose_usage (); | |
657 break; | |
777 | 658 |
1 | 659 case 'i': |
3019 | 660 forced_interactive = true; |
1 | 661 break; |
777 | 662 |
1 | 663 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
|
664 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
|
665 load_path::set_command_line_path (optarg); |
1 | 666 break; |
777 | 667 |
1 | 668 case 'q': |
2239 | 669 inhibit_startup_message = true; |
1 | 670 break; |
777 | 671 |
1 | 672 case 'x': |
2205 | 673 { |
674 double tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_CMD_LINE); | |
5794 | 675 bind_internal_variable ("echo_executing_commands", tmp); |
2205 | 676 } |
1 | 677 break; |
777 | 678 |
1 | 679 case 'v': |
680 print_version_and_exit (); | |
681 break; | |
777 | 682 |
8861 | 683 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
|
684 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
|
685 bind_internal_variable ("doc_cache_file", optarg); |
8861 | 686 break; |
687 | |
5189 | 688 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
|
689 if (optarg) |
5193 | 690 { |
691 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
|
692 code_to_eval = optarg; |
5193 | 693 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
|
694 code_to_eval += std::string (" ") + optarg; |
5193 | 695 } |
5189 | 696 break; |
697 | |
1613 | 698 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
|
699 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
|
700 set_exec_path (optarg); |
5814 | 701 break; |
702 | |
703 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
|
704 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
|
705 set_image_path (optarg); |
1613 | 706 break; |
707 | |
186 | 708 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
|
709 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
|
710 bind_internal_variable ("info_file", optarg); |
186 | 711 break; |
777 | 712 |
1613 | 713 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
|
714 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
|
715 bind_internal_variable ("info_program", optarg); |
1613 | 716 break; |
717 | |
9132
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
718 case LINE_EDITING_OPTION: |
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
719 forced_line_editing = true; |
eb1747dbd360
Update help strings for command line options
Rik <rdrider0-list@yahoo.com>
parents:
9009
diff
changeset
|
720 break; |
6938 | 721 |
2239 | 722 case NO_INIT_FILE_OPTION: |
723 read_init_files = false; | |
724 break; | |
725 | |
9336
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
726 case NO_INIT_PATH_OPTION: |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
727 set_initial_path = false; |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
728 break; |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
729 |
1821 | 730 case NO_LINE_EDITING_OPTION: |
3019 | 731 line_editing = false; |
2239 | 732 break; |
733 | |
734 case NO_SITE_FILE_OPTION: | |
735 read_site_files = 0; | |
1821 | 736 break; |
737 | |
9335
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
738 case NO_WINDOW_SYSTEM_OPTION: |
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
739 display_info::no_window_system (); |
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
740 break; |
f2d354df53ee
new option, --no-window-system
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
741 |
9336
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
742 case PERSIST_OPTION: |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
743 persist = true; |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
744 break; |
98c6b3aa0b7b
octave.cc: keep long options in alphabetized
John W. Eaton <jwe@octave.org>
parents:
9335
diff
changeset
|
745 |
1410 | 746 case TRADITIONAL_OPTION: |
2239 | 747 traditional = true; |
1410 | 748 break; |
749 | |
1 | 750 default: |
751 usage (); | |
752 break; | |
753 } | |
754 } | |
755 | |
2077 | 756 // Make sure we clean up when we exit. Also allow users to register |
757 // functions. If we don't have atexit or on_exit, we're going to | |
758 // leave some junk files around if we exit abnormally. | |
759 | |
760 atexit (do_octave_atexit); | |
1 | 761 |
9320
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
762 // 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
|
763 // interactive. |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
764 |
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
|
765 // 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
|
766 // 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
|
767 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
|
768 |
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
|
769 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
|
770 |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
771 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
|
772 line_editing = false; |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
773 |
9321
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
9320
diff
changeset
|
774 // 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
|
775 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
|
776 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
|
777 |
1358 | 778 // These can come after command line args since none of them set any |
779 // defaults that might be changed by command line options. | |
581 | 780 |
9320
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
781 if (line_editing) |
080dc45ea682
don't garble readline settings when line editing is disabled
Jaroslav Hajek <highegg@gmail.com>
parents:
9260
diff
changeset
|
782 initialize_command_input (); |
315 | 783 |
578 | 784 if (! inhibit_startup_message) |
3538 | 785 std::cout << OCTAVE_STARTUP_MESSAGE "\n" << std::endl; |
578 | 786 |
1410 | 787 if (traditional) |
788 maximum_braindamage (); | |
789 | |
4217 | 790 octave_interpreter_ready = true; |
791 | |
5654 | 792 initialize_version_info (); |
793 | |
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
|
794 // 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
|
795 // 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
|
796 |
e0a6e54f5a19
octave.cc (octave_main): make all command-line arguments available to startup scripts
John W. Eaton <jwe@octave.org>
parents:
8021
diff
changeset
|
797 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
|
798 |
6365 | 799 load_path::initialize (set_initial_path); |
4217 | 800 |
2239 | 801 execute_startup_files (); |
1651 | 802 |
8273
2c1ba965b486
skip reading history file with --no-history option
John W. Eaton <jwe@octave.org>
parents:
8099
diff
changeset
|
803 initialize_history (read_history_file); |
1 | 804 |
578 | 805 if (! inhibit_startup_message && reading_startup_message_printed) |
3538 | 806 std::cout << std::endl; |
578 | 807 |
1358 | 808 // If there is an extra argument, see if it names a file to read. |
809 // Additional arguments are taken as command line options for the | |
810 // script. | |
1 | 811 |
10195
b49d47b637b7
use getopt directly instead of the (mostly useless) prog_args wrapper class
John W. Eaton <jwe@octave.org>
parents:
10191
diff
changeset
|
812 int last_arg_idx = optind; |
3019 | 813 |
1817 | 814 int remaining_args = argc - last_arg_idx; |
3019 | 815 |
5189 | 816 if (! code_to_eval.empty ()) |
149 | 817 { |
5189 | 818 int parse_status = execute_eval_option_code (code_to_eval); |
819 | |
5242 | 820 if (! (persist || remaining_args > 0)) |
5502 | 821 clean_up_and_exit (parse_status || error_state ? 1 : 0); |
1 | 822 } |
823 | |
5189 | 824 if (remaining_args > 0) |
825 { | |
826 // If we are running an executable script (#! /bin/octave) then | |
827 // we should only see the args passed to the script. | |
828 | |
829 intern_argv (remaining_args, argv+last_arg_idx); | |
830 | |
831 execute_command_line_file (argv[last_arg_idx]); | |
832 | |
833 if (! persist) | |
5502 | 834 clean_up_and_exit (error_state ? 1 : 0); |
5189 | 835 } |
836 | |
837 // Avoid counting commands executed from startup files. | |
838 | |
839 command_editor::reset_current_command_number (1); | |
840 | |
841 // Now argv should have the full set of args. | |
842 intern_argv (argc, argv); | |
843 | |
844 if (! embedded) | |
845 switch_to_buffer (create_buffer (get_input_from_stdin ())); | |
846 | |
1358 | 847 // Force input to be echoed if not really interactive, but the user |
848 // has forced interactive behavior. | |
1 | 849 |
1907 | 850 if (! interactive && forced_interactive) |
287 | 851 { |
2926 | 852 command_editor::blink_matching_paren (false); |
1588 | 853 |
5775 | 854 // FIXME -- is this the right thing to do? |
1588 | 855 |
5794 | 856 bind_internal_variable ("echo_executing_commands", ECHO_CMD_LINE); |
287 | 857 } |
1 | 858 |
4368 | 859 if (embedded) |
5502 | 860 { |
5775 | 861 // FIXME -- do we need to do any cleanup here before |
5502 | 862 // returning? If we don't, what will happen to Octave functions |
863 // that have been registered to execute with atexit, for example? | |
864 | |
865 return 1; | |
866 } | |
4368 | 867 |
5189 | 868 int retval = main_loop (); |
1 | 869 |
1005 | 870 if (retval == 1 && ! error_state) |
871 retval = 0; | |
872 | |
1 | 873 clean_up_and_exit (retval); |
4247 | 874 |
875 return 0; | |
1 | 876 } |
877 | |
5780 | 878 DEFUN (argv, args, , |
879 "-*- texinfo -*-\n\ | |
880 @deftypefn {Built-in Function} {} argv ()\n\ | |
881 Return the command line arguments passed to Octave. For example,\n\ | |
882 if you invoked Octave using the command\n\ | |
883 \n\ | |
884 @example\n\ | |
885 octave --no-line-editing --silent\n\ | |
886 @end example\n\ | |
887 \n\ | |
888 @noindent\n\ | |
889 @code{argv} would return a cell array of strings with the elements\n\ | |
890 @code{--no-line-editing} and @code{--silent}.\n\ | |
891 \n\ | |
892 If you write an executable Octave script, @code{argv} will return the\n\ | |
893 list of arguments passed to the script. @xref{Executable Octave Programs},\n\ | |
894 for an example of how to create an executable Octave script.\n\ | |
895 @end deftypefn") | |
896 { | |
897 octave_value retval; | |
898 | |
899 if (args.length () == 0) | |
900 retval = Cell (octave_argv); | |
901 else | |
5823 | 902 print_usage (); |
5780 | 903 |
904 return retval; | |
905 } | |
906 | |
907 DEFUN (program_invocation_name, args, , | |
908 "-*- texinfo -*-\n\ | |
9724
f22bbc5d56e9
Fix various incorrect usages of TeXinfo deffn and deftypefn macros
Rik <rdrider0-list@yahoo.com>
parents:
9584
diff
changeset
|
909 @deftypefn {Built-in Function} {} program_invocation_name ()\n\ |
5780 | 910 Return the name that was typed at the shell prompt to run Octave.\n\ |
911 \n\ | |
912 If executing a script from the command line (e.g., @code{octave foo.m})\n\ | |
913 or using an executable Octave script, the program name is set to the\n\ | |
914 name of the script. @xref{Executable Octave Programs}, for an example of\n\ | |
915 how to create an executable Octave script.\n\ | |
916 @seealso{program_name}\n\ | |
917 @end deftypefn") | |
918 { | |
919 octave_value retval; | |
920 | |
921 if (args.length () == 0) | |
922 retval = octave_program_invocation_name; | |
923 else | |
5823 | 924 print_usage (); |
5780 | 925 |
926 return retval; | |
927 } | |
928 | |
929 DEFUN (program_name, args, , | |
930 "-*- texinfo -*-\n\ | |
931 @deftypefn {Built-in Function} {} program_name ()\n\ | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8273
diff
changeset
|
932 Return the last component of the value returned by\n\ |
5780 | 933 @code{program_invocation_name}.\n\ |
934 @seealso{program_invocation_name}\n\ | |
935 @end deftypefn") | |
936 { | |
937 octave_value retval; | |
938 | |
939 if (args.length () == 0) | |
940 retval = octave_program_name; | |
941 else | |
5823 | 942 print_usage (); |
5780 | 943 |
944 return retval; | |
945 } |