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