Mercurial > octave
annotate src/toplev.cc @ 10212:56f7734f5448
fix process creation failure handling in system()
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 28 Jan 2010 07:12:59 +0100 |
parents | 095a1e670e68 |
children | 57a59eae83cc |
rev | line source |
---|---|
1683 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
8920 | 4 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton |
1683 | 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. | |
1683 | 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/>. | |
1683 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <cassert> | |
4489 | 29 #include <cerrno> |
1683 | 30 #include <cstdlib> |
31 #include <cstring> | |
4221 | 32 #include <new> |
1683 | 33 |
3503 | 34 #include <fstream> |
35 #include <iostream> | |
5765 | 36 #include <sstream> |
1728 | 37 #include <string> |
38 | |
1683 | 39 #include <sys/types.h> |
40 #include <unistd.h> | |
41 | |
2926 | 42 #include "cmd-edit.h" |
43 #include "file-ops.h" | |
1683 | 44 #include "lo-error.h" |
2370 | 45 #include "lo-mappers.h" |
3020 | 46 #include "oct-env.h" |
4153 | 47 #include "quit.h" |
1755 | 48 #include "str-vec.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8347
diff
changeset
|
49 #include "oct-locbuf.h" |
1683 | 50 |
2492 | 51 #include <defaults.h> |
1683 | 52 #include "defun.h" |
53 #include "error.h" | |
54 #include "file-io.h" | |
55 #include "input.h" | |
56 #include "lex.h" | |
2492 | 57 #include <oct-conf.h> |
1742 | 58 #include "oct-hist.h" |
2162 | 59 #include "oct-map.h" |
2862 | 60 #include "oct-obj.h" |
1683 | 61 #include "pager.h" |
62 #include "parse.h" | |
63 #include "pathsearch.h" | |
64 #include "procstream.h" | |
2370 | 65 #include "ov.h" |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8581
diff
changeset
|
66 #include "pt-eval.h" |
2985 | 67 #include "pt-jump.h" |
2982 | 68 #include "pt-stmt.h" |
1683 | 69 #include "sighandlers.h" |
70 #include "sysdep.h" | |
2693 | 71 #include "syswait.h" |
1750 | 72 #include "toplev.h" |
1683 | 73 #include "unwind-prot.h" |
74 #include "utils.h" | |
75 #include "variables.h" | |
2492 | 76 #include <version.h> |
1683 | 77 |
9217
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9187
diff
changeset
|
78 void (*octave_exit) (int) = ::exit; |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9187
diff
changeset
|
79 |
9255
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
80 // TRUE means the quit() call is allowed. |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
81 bool quit_allowed = true; |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
82 |
3020 | 83 // TRUE means we are exiting via the builtin exit or quit functions. |
9383 | 84 bool quitting_gracefully = false; |
85 // This stores the exit status. | |
86 int exit_status = 0; | |
1683 | 87 |
4217 | 88 // TRUE means we are ready to interpret commands, but not everything |
89 // is ready for interactive use. | |
90 bool octave_interpreter_ready = false; | |
91 | |
4172 | 92 // TRUE means we've processed all the init code and we are good to go. |
93 bool octave_initialized = false; | |
94 | |
1683 | 95 // Current command to execute. |
96 tree_statement_list *global_command = 0; | |
97 | |
5743 | 98 octave_call_stack *octave_call_stack::instance = 0; |
99 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
100 int |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
101 octave_call_stack::do_current_line (void) const |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
102 { |
9484
bbe033dcfe13
make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents:
9483
diff
changeset
|
103 tree_statement *stmt = do_current_statement (); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
104 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
105 return stmt ? stmt->line () : -1; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
106 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
107 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
108 int |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
109 octave_call_stack::do_current_column (void) const |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
110 { |
9484
bbe033dcfe13
make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents:
9483
diff
changeset
|
111 tree_statement *stmt = do_current_statement (); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
112 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
113 return stmt ? stmt->column () : -1; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
114 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
115 |
7877 | 116 int |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
117 octave_call_stack::do_caller_user_code_line (void) const |
7877 | 118 { |
119 int retval = -1; | |
120 | |
7890 | 121 const_iterator p = cs.end (); |
122 | |
123 while (p != cs.begin ()) | |
7877 | 124 { |
7890 | 125 const call_stack_elt& elt = *(--p); |
7877 | 126 |
127 octave_function *f = elt.fcn; | |
128 | |
129 if (f && f->is_user_code ()) | |
130 { | |
131 tree_statement *stmt = elt.stmt; | |
132 | |
133 if (stmt) | |
134 { | |
135 retval = stmt->line (); | |
136 break; | |
137 } | |
138 } | |
139 } | |
140 | |
141 return retval; | |
142 } | |
143 | |
144 int | |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
145 octave_call_stack::do_caller_user_code_column (void) const |
7877 | 146 { |
147 int retval = -1; | |
148 | |
7890 | 149 const_iterator p = cs.end (); |
150 | |
151 while (p != cs.begin ()) | |
7877 | 152 { |
7890 | 153 const call_stack_elt& elt = *(--p); |
7877 | 154 |
155 octave_function *f = elt.fcn; | |
156 | |
157 if (f && f->is_user_code ()) | |
158 { | |
159 tree_statement *stmt = elt.stmt; | |
160 | |
161 if (stmt) | |
162 { | |
163 retval = stmt->column (); | |
164 break; | |
165 } | |
166 } | |
167 } | |
168 | |
169 return retval; | |
170 } | |
171 | |
7901 | 172 size_t |
173 octave_call_stack::do_num_user_code_frames (octave_idx_type& curr_user_frame) const | |
174 { | |
175 size_t retval = 0; | |
176 | |
177 curr_user_frame = 0; | |
178 | |
179 // Look for the caller of dbstack. | |
180 size_t frame = cs[curr_frame].prev; | |
181 | |
182 bool found = false; | |
183 | |
184 size_t k = cs.size (); | |
185 | |
186 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++) | |
187 { | |
188 octave_function *f = (*p).fcn; | |
189 | |
190 if (--k == frame) | |
191 found = true; | |
192 | |
193 if (f && f->is_user_code ()) | |
194 { | |
195 if (! found) | |
196 curr_user_frame++; | |
197 | |
198 retval++; | |
199 } | |
200 } | |
201 | |
202 // We counted how many user frames were not the one, in reverse. | |
203 // Now set curr_user_frame to be the index in the other direction. | |
204 curr_user_frame = retval - curr_user_frame - 1; | |
205 | |
206 return retval; | |
207 } | |
208 | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
209 octave_user_code * |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
210 octave_call_stack::do_caller_user_code (size_t nskip) const |
5744 | 211 { |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
212 octave_user_code *retval = 0; |
5744 | 213 |
7890 | 214 const_iterator p = cs.end (); |
215 | |
216 while (p != cs.begin ()) | |
5744 | 217 { |
7890 | 218 const call_stack_elt& elt = *(--p); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
219 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
220 octave_function *f = elt.fcn; |
5744 | 221 |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
222 if (f && f->is_user_code ()) |
5744 | 223 { |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
224 if (nskip > 0) |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
225 nskip--; |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
226 else |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
227 { |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
228 retval = dynamic_cast<octave_user_code *> (f); |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
229 break; |
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
230 } |
5744 | 231 } |
232 } | |
233 | |
234 return retval; | |
235 } | |
236 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
237 Octave_map |
7901 | 238 octave_call_stack::do_backtrace (size_t nskip, |
239 octave_idx_type& curr_user_frame) const | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
240 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
241 Octave_map retval; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
242 |
7901 | 243 size_t user_code_frames = do_num_user_code_frames (curr_user_frame); |
244 | |
245 size_t nframes = nskip <= user_code_frames ? user_code_frames - nskip : 0; | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
246 |
7901 | 247 // Our list is reversed. |
248 curr_user_frame = nframes - curr_user_frame - 1; | |
249 | |
250 Cell keys (6, 1); | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
251 |
7901 | 252 keys(0) = "file"; |
253 keys(1) = "name"; | |
254 keys(2) = "line"; | |
255 keys(3) = "column"; | |
256 keys(4) = "scope"; | |
257 keys(5) = "context"; | |
7890 | 258 |
7901 | 259 Cell file (nframes, 1); |
260 Cell name (nframes, 1); | |
261 Cell line (nframes, 1); | |
262 Cell column (nframes, 1); | |
263 Cell scope (nframes, 1); | |
264 Cell context (nframes, 1); | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
265 |
7901 | 266 if (nframes > 0) |
267 { | |
268 int k = 0; | |
269 | |
270 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++) | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
271 { |
7901 | 272 const call_stack_elt& elt = *p; |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
273 |
7736 | 274 octave_function *f = elt.fcn; |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
275 |
7901 | 276 if (f && f->is_user_code ()) |
7736 | 277 { |
7901 | 278 if (nskip > 0) |
279 nskip--; | |
7736 | 280 else |
281 { | |
7901 | 282 scope(k) = elt.scope; |
283 context(k) = elt.context; | |
284 | |
285 file(k) = f->fcn_file_name (); | |
286 std::string parent_fcn_name = f->parent_fcn_name (); | |
287 if (parent_fcn_name == std::string ()) | |
288 name(k) = f->name (); | |
289 else | |
290 name(k) = f->parent_fcn_name () + Vfilemarker + f->name (); | |
291 | |
292 tree_statement *stmt = elt.stmt; | |
293 | |
294 if (stmt) | |
295 { | |
296 line(k) = stmt->line (); | |
297 column(k) = stmt->column (); | |
298 } | |
299 else | |
300 { | |
301 line(k) = -1; | |
302 column(k) = -1; | |
303 } | |
304 | |
305 k++; | |
7736 | 306 } |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
307 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
308 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
309 |
7736 | 310 retval.assign ("file", file); |
311 retval.assign ("name", name); | |
312 retval.assign ("line", line); | |
313 retval.assign ("column", column); | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
314 retval.assign ("scope", scope); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
315 retval.assign ("context", context); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
316 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
317 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
318 return retval; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
319 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
320 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
321 bool |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
322 octave_call_stack::do_goto_frame (size_t n, bool verbose) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
323 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
324 bool retval = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
325 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
326 if (n < cs.size ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
327 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
328 retval = true; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
329 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
330 curr_frame = n; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
331 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
332 const call_stack_elt& elt = cs[n]; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
333 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
334 symbol_table::set_scope_and_context (elt.scope, elt.context); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
335 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
336 if (verbose) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
337 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
338 octave_function *f = elt.fcn; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
339 std::string nm = f ? f->name () : std::string ("<unknown>"); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
340 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
341 tree_statement *s = elt.stmt; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
342 int l = -1; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
343 int c = -1; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
344 if (s) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
345 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
346 l = s->line (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
347 c = s->column (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
348 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
349 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
350 octave_stdout << "stopped in " << nm |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
351 << " at line " << l << " column " << c |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
352 << " (" << elt.scope << "[" << elt.context << "])" |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
353 << std::endl; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
354 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
355 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
356 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
357 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
358 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
359 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
360 bool |
7901 | 361 octave_call_stack::do_goto_frame_relative (int nskip, bool verbose) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
362 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
363 bool retval = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
364 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
365 int incr = 0; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
366 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
367 if (nskip < 0) |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
368 incr = -1; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
369 else if (nskip > 0) |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
370 incr = 1; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
371 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
372 // Start looking with the caller of dbup/dbdown/keyboard. |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
373 size_t frame = cs[curr_frame].prev; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
374 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
375 while (true) |
7890 | 376 { |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
377 if ((incr < 0 && frame == 0) || (incr > 0 && frame == cs.size () - 1)) |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
378 break; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
379 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
380 frame += incr; |
7901 | 381 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
382 const call_stack_elt& elt = cs[frame]; |
7901 | 383 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
384 octave_function *f = elt.fcn; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
385 |
9990
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
386 if (frame == 0 || (f && f->is_user_code ())) |
7901 | 387 { |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
388 if (nskip > 0) |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
389 nskip--; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
390 else if (nskip < 0) |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
391 nskip++; |
7901 | 392 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
393 if (nskip == 0) |
7901 | 394 { |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
395 curr_frame = frame; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
396 cs[cs.size () - 1].prev = curr_frame; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
397 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
398 symbol_table::set_scope_and_context (elt.scope, elt.context); |
7901 | 399 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
400 if (verbose) |
7901 | 401 { |
9990
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
402 std::ostringstream buf; |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
403 |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
404 if (f) |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
405 { |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
406 tree_statement *s = elt.stmt; |
7901 | 407 |
9990
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
408 int l = s ? s->line () : -1; |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
409 int c = s ? s->column () : -1; |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
410 |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
411 buf << f->name () << ": " << " line " << l |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
412 << ", column " << c << std::endl; |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
413 } |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
414 else |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
415 buf << "at top level" << std::endl; |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
416 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
417 octave_stdout << buf.str (); |
7901 | 418 } |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
419 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
420 retval = true; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
421 break; |
7901 | 422 } |
423 } | |
424 | |
425 // There is no need to set scope and context here. That will | |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
426 // happen when the dbup/dbdown/keyboard frame is popped and we |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
427 // jump to the new "prev" frame set above. |
7890 | 428 } |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
429 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
430 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
431 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
432 |
5744 | 433 void |
7901 | 434 octave_call_stack::do_goto_caller_frame (void) |
435 { | |
436 size_t frame = curr_frame; | |
437 | |
438 bool skipped = false; | |
439 | |
440 while (frame != 0) | |
441 { | |
442 frame = cs[frame].prev; | |
443 | |
444 const call_stack_elt& elt = cs[frame]; | |
445 | |
446 octave_function *f = elt.fcn; | |
447 | |
8581
6adcafc70c32
toplev.cc (octave_call_stack::do_goto_caller_frame): allow caller frame to be base frame
John W. Eaton <jwe@octave.org>
parents:
8574
diff
changeset
|
448 if (frame == 0 || (f && f->is_user_code ())) |
7901 | 449 { |
450 if (! skipped) | |
451 // We found the current user code frame, so skip it. | |
452 skipped = true; | |
453 else | |
454 { | |
455 // We found the caller user code frame. | |
456 call_stack_elt tmp (elt); | |
457 tmp.prev = curr_frame; | |
458 | |
459 curr_frame = cs.size (); | |
460 | |
461 cs.push_back (tmp); | |
462 | |
463 symbol_table::set_scope_and_context (tmp.scope, tmp.context); | |
464 | |
465 break; | |
466 } | |
467 } | |
468 } | |
469 } | |
470 | |
471 void | |
472 octave_call_stack::do_goto_base_frame (void) | |
473 { | |
474 call_stack_elt tmp (cs[0]); | |
475 tmp.prev = curr_frame; | |
476 | |
477 curr_frame = cs.size (); | |
478 | |
479 cs.push_back (tmp); | |
480 | |
481 symbol_table::set_scope_and_context (tmp.scope, tmp.context); | |
482 } | |
483 | |
484 void | |
8013
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
485 octave_call_stack::do_backtrace_error_message (void) const |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
486 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
487 if (error_state > 0) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
488 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
489 error_state = -1; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
490 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
491 error ("called from:"); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
492 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
493 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
494 if (! cs.empty ()) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
495 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
496 const call_stack_elt& elt = cs.back (); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
497 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
498 octave_function *fcn = elt.fcn; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
499 tree_statement *stmt = elt.stmt; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
500 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
501 std::string fcn_name = "?unknown?"; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
502 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
503 if (fcn) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
504 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
505 fcn_name = fcn->fcn_file_name (); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
506 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
507 if (fcn_name.empty ()) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
508 fcn_name = fcn->name (); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
509 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
510 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
511 int line = stmt ? stmt->line () : -1; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
512 int column = stmt ? stmt->column () : -1; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
513 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
514 error (" %s at line %d, column %d", |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
515 fcn_name.c_str (), line, column); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
516 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
517 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
518 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
519 void |
4180 | 520 recover_from_exception (void) |
521 { | |
522 can_interrupt = true; | |
4182 | 523 octave_interrupt_immediately = 0; |
4180 | 524 octave_interrupt_state = 0; |
5142 | 525 octave_signal_caught = 0; |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7409
diff
changeset
|
526 octave_exception_state = octave_no_exception; |
4180 | 527 octave_restore_signal_mask (); |
528 octave_catch_interrupts (); | |
529 } | |
530 | |
1907 | 531 int |
5189 | 532 main_loop (void) |
1907 | 533 { |
2016 | 534 octave_save_signal_mask (); |
535 | |
3020 | 536 can_interrupt = true; |
1907 | 537 |
5142 | 538 octave_signal_hook = octave_signal_handler; |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
539 octave_interrupt_hook = 0; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
540 octave_bad_alloc_hook = 0; |
4429 | 541 |
2554 | 542 octave_catch_interrupts (); |
1907 | 543 |
4172 | 544 octave_initialized = true; |
545 | |
1907 | 546 // The big loop. |
547 | |
4153 | 548 int retval = 0; |
1907 | 549 do |
550 { | |
4180 | 551 try |
1907 | 552 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
553 unwind_protect frame; |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
554 |
4318 | 555 reset_error_handler (); |
556 | |
4153 | 557 reset_parser (); |
2620 | 558 |
10186
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
559 if (symbol_table::at_top_level ()) |
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
560 tree_evaluator::reset_debug_state (); |
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
561 |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
562 // Do this with an unwind-protect cleanup function so that |
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
563 // the forced variables will be unmarked in the event of an |
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
564 // interrupt. |
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
565 symbol_table::scope_id scope = symbol_table::top_scope (); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
566 frame.add_fcn (symbol_table::unmark_forced_variables, scope); |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
567 |
4753 | 568 // This is the same as yyparse in parse.y. |
569 retval = octave_parse (); | |
2620 | 570 |
4153 | 571 if (retval == 0) |
572 { | |
7913
f46e73bcb85b
toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
573 if (global_command) |
3804 | 574 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8581
diff
changeset
|
575 global_command->accept (*current_evaluator); |
3883 | 576 |
7913
f46e73bcb85b
toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
577 delete global_command; |
3883 | 578 |
7913
f46e73bcb85b
toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents:
7903
diff
changeset
|
579 global_command = 0; |
3883 | 580 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
581 octave_quit (); |
4171 | 582 |
3883 | 583 if (! (interactive || forced_interactive)) |
584 { | |
4207 | 585 bool quit = (tree_return_command::returning |
586 || tree_break_command::breaking); | |
4153 | 587 |
4207 | 588 if (tree_return_command::returning) |
589 tree_return_command::returning = 0; | |
4153 | 590 |
4207 | 591 if (tree_break_command::breaking) |
592 tree_break_command::breaking--; | |
4153 | 593 |
594 if (quit) | |
595 break; | |
596 } | |
597 | |
598 if (error_state) | |
599 { | |
600 if (! (interactive || forced_interactive)) | |
601 { | |
602 // We should exit with a non-zero status. | |
603 retval = 1; | |
604 break; | |
605 } | |
606 } | |
607 else | |
608 { | |
609 if (octave_completion_matches_called) | |
610 octave_completion_matches_called = false; | |
611 else | |
612 command_editor::increment_current_command_number (); | |
3883 | 613 } |
614 } | |
4153 | 615 else if (parser_end_of_input) |
616 break; | |
2620 | 617 } |
4153 | 618 } |
4182 | 619 catch (octave_interrupt_exception) |
4153 | 620 { |
4180 | 621 recover_from_exception (); |
9383 | 622 octave_stdout << "\n"; |
623 if (quitting_gracefully) | |
624 { | |
625 clean_up_and_exit (exit_status); | |
626 break; // If user has overriden the exit func. | |
627 } | |
4180 | 628 } |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
629 catch (octave_execution_exception) |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
630 { |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
631 recover_from_exception (); |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
632 std::cerr |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
633 << "error: unhandled execution exception -- trying to return to prompt" |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
634 << std::endl; |
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
635 } |
4181 | 636 catch (std::bad_alloc) |
4180 | 637 { |
638 recover_from_exception (); | |
639 std::cerr | |
6680 | 640 << "error: memory exhausted or requested size too large for range of Octave's index type -- trying to return to prompt" |
641 << std::endl; | |
1907 | 642 } |
643 } | |
644 while (retval == 0); | |
645 | |
646 return retval; | |
647 } | |
648 | |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
649 // Call a function with exceptions handled to avoid problems with |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
650 // errors while shutting down. |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
651 |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
652 #define IGNORE_EXCEPTION(E) \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
653 catch (E) \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
654 { \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
655 std::cerr << "error: ignoring " #E " while preparing to exit" << std::endl; \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
656 recover_from_exception (); \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
657 } |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
658 |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
659 #define SAFE_CALL(F, ARGS) \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
660 try \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
661 { \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
662 F ARGS; \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
663 } \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
664 IGNORE_EXCEPTION (octave_interrupt_exception) \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
665 IGNORE_EXCEPTION (octave_execution_exception) \ |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
666 IGNORE_EXCEPTION (std::bad_alloc) |
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
667 |
1683 | 668 // Fix up things before exiting. |
669 | |
670 void | |
3162 | 671 clean_up_and_exit (int retval) |
672 { | |
3216 | 673 do_octave_atexit (); |
1683 | 674 |
9981
692ab4eaf965
clean up top-level variables when exiting Octave
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
675 // Clean up symbol table. |
692ab4eaf965
clean up top-level variables when exiting Octave
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
676 SAFE_CALL (symbol_table::cleanup, ()); |
692ab4eaf965
clean up top-level variables when exiting Octave
Jaroslav Hajek <highegg@gmail.com>
parents:
9794
diff
changeset
|
677 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
678 SAFE_CALL (sysdep_cleanup, ()) |
5451 | 679 |
9217
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9187
diff
changeset
|
680 if (octave_exit) |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9187
diff
changeset
|
681 (*octave_exit) (retval == EOF ? 0 : retval); |
1683 | 682 } |
683 | |
3180 | 684 DEFUN (quit, args, nargout, |
3332 | 685 "-*- texinfo -*-\n\ |
686 @deftypefn {Built-in Function} {} exit (@var{status})\n\ | |
687 @deftypefnx {Built-in Function} {} quit (@var{status})\n\ | |
688 Exit the current Octave session. If the optional integer value\n\ | |
689 @var{status} is supplied, pass that value to the operating system as the\n\ | |
6615 | 690 Octave's exit status. The default value is zero.\n\ |
3333 | 691 @end deftypefn") |
1683 | 692 { |
2086 | 693 octave_value_list retval; |
2068 | 694 |
9255
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
695 if (! quit_allowed) |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
696 error ("quit: not supported in embedded mode."); |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
697 else if (nargout == 0) |
2068 | 698 { |
3180 | 699 if (args.length () > 0) |
700 { | |
3202 | 701 int tmp = args(0).nint_value (); |
1683 | 702 |
3202 | 703 if (! error_state) |
704 exit_status = tmp; | |
3180 | 705 } |
706 | |
9383 | 707 if (! error_state) |
708 { | |
709 quitting_gracefully = true; | |
710 | |
711 // Simulate interrupt. | |
712 | |
713 octave_interrupt_state = -1; | |
714 | |
715 octave_throw_interrupt_exception (); | |
716 } | |
2068 | 717 } |
3180 | 718 else |
719 error ("quit: invalid number of output arguments"); | |
2068 | 720 |
1683 | 721 return retval; |
722 } | |
723 | |
724 DEFALIAS (exit, quit); | |
725 | |
1957 | 726 DEFUN (warranty, , , |
3446 | 727 "-*- texinfo -*-\n\ |
728 @deftypefn {Built-in Function} {} warranty ()\n\ | |
729 Describe the conditions for copying and distributing Octave.\n\ | |
730 @end deftypefn") | |
1683 | 731 { |
2086 | 732 octave_value_list retval; |
1683 | 733 |
3922 | 734 octave_stdout << "\n" \ |
735 OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\ | |
736 \n\ | |
1683 | 737 This program is free software; you can redistribute it and/or modify\n\ |
738 it under the terms of the GNU General Public License as published by\n\ | |
7016 | 739 the Free Software Foundation; either version 3 of the License, or\n\ |
1683 | 740 (at your option) any later version.\n\ |
741 \n\ | |
742 This program is distributed in the hope that it will be useful,\n\ | |
743 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ | |
744 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ | |
745 GNU General Public License for more details.\n\ | |
746 \n\ | |
747 You should have received a copy of the GNU General Public License\n\ | |
7016 | 748 along with this program. If not, see <http://www.gnu.org/licenses/>.\n\ |
1683 | 749 \n"; |
750 | |
751 return retval; | |
752 } | |
753 | |
754 // Execute a shell command. | |
755 | |
6316 | 756 static int |
757 wait_for_input (int fid) | |
758 { | |
759 int retval = -1; | |
760 | |
761 #if defined (HAVE_SELECT) | |
762 if (fid >= 0) | |
763 { | |
764 fd_set set; | |
765 | |
766 FD_ZERO (&set); | |
767 FD_SET (fid, &set); | |
768 | |
769 retval = select (FD_SETSIZE, &set, 0, 0, 0); | |
770 } | |
771 #else | |
772 retval = 1; | |
773 #endif | |
774 | |
775 return retval; | |
776 } | |
777 | |
2086 | 778 static octave_value_list |
3523 | 779 run_command_and_return_output (const std::string& cmd_str) |
2083 | 780 { |
2086 | 781 octave_value_list retval; |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
782 unwind_protect frame; |
2083 | 783 |
784 iprocstream *cmd = new iprocstream (cmd_str.c_str ()); | |
785 | |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
786 frame.add_delete (cmd); |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
787 frame.add_fcn (octave_child_list::remove, cmd->pid ()); |
3060 | 788 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
789 if (*cmd) |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
790 { |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
791 int fid = cmd->file_number (); |
2095 | 792 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
793 std::ostringstream output_buf; |
4494 | 794 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
795 char ch; |
3147 | 796 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
797 for (;;) |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
798 { |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
799 if (cmd->get (ch)) |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
800 output_buf.put (ch); |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
801 else |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
802 { |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
803 if (! cmd->eof () && errno == EAGAIN) |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
804 { |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
805 cmd->clear (); |
3147 | 806 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
807 if (wait_for_input (fid) != 1) |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
808 break; |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
809 } |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
810 else |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
811 break; |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
812 } |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
813 } |
3147 | 814 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
815 int cmd_status = cmd->close (); |
2083 | 816 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
817 if (WIFEXITED (cmd_status)) |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
818 cmd_status = WEXITSTATUS (cmd_status); |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
819 else |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
820 cmd_status = 127; |
2083 | 821 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
822 retval(0) = cmd_status; |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
823 retval(1) = output_buf.str (); |
2083 | 824 } |
825 else | |
826 error ("unable to start subprocess for `%s'", cmd_str.c_str ()); | |
827 | |
828 return retval; | |
829 } | |
830 | |
5285 | 831 enum system_exec_type { et_sync, et_async }; |
832 | |
1957 | 833 DEFUN (system, args, nargout, |
3301 | 834 "-*- texinfo -*-\n\ |
835 @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})\n\ | |
836 Execute a shell command specified by @var{string}. The second\n\ | |
837 argument is optional. If @var{type} is @code{\"async\"}, the process\n\ | |
838 is started in the background and the process id of the child process\n\ | |
839 is returned immediately. Otherwise, the process is started, and\n\ | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8013
diff
changeset
|
840 Octave waits until it exits. If the @var{type} argument is omitted, a\n\ |
3301 | 841 value of @code{\"sync\"} is assumed.\n\ |
2083 | 842 \n\ |
3301 | 843 If two input arguments are given (the actual value of\n\ |
844 @var{return_output} is irrelevant) and the subprocess is started\n\ | |
845 synchronously, or if @var{system} is called with one input argument and\n\ | |
846 one or more output arguments, the output from the command is returned.\n\ | |
5097 | 847 Otherwise, if the subprocess is executed synchronously, its output is\n\ |
2321 | 848 sent to the standard output. To send the output of a command executed\n\ |
3301 | 849 with @var{system} through the pager, use a command like\n\ |
2321 | 850 \n\ |
3301 | 851 @example\n\ |
852 disp (system (cmd, 1));\n\ | |
853 @end example\n\ | |
2321 | 854 \n\ |
3301 | 855 @noindent\n\ |
2321 | 856 or\n\ |
857 \n\ | |
3301 | 858 @example\n\ |
9079
4d610aba7347
Cleanup documentation for system.texi, package.texi
Rik <rdrider0-list@yahoo.com>
parents:
9035
diff
changeset
|
859 printf (\"%s\\n\", system (cmd, 1));\n\ |
3301 | 860 @end example\n\ |
861 \n\ | |
5659 | 862 The @code{system} function can return two values. The first is the\n\ |
863 exit status of the command and the second is any output from the\n\ | |
864 command that was written to the standard output stream. For example,\n\ | |
3301 | 865 \n\ |
866 @example\n\ | |
5717 | 867 [status, output] = system (\"echo foo; exit 2\");\n\ |
3301 | 868 @end example\n\ |
869 \n\ | |
870 @noindent\n\ | |
871 will set the variable @code{output} to the string @samp{foo}, and the\n\ | |
872 variable @code{status} to the integer @samp{2}.\n\ | |
873 @end deftypefn") | |
1683 | 874 { |
2086 | 875 octave_value_list retval; |
1683 | 876 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
877 unwind_protect frame; |
3834 | 878 |
1683 | 879 int nargin = args.length (); |
880 | |
2083 | 881 if (nargin > 0 && nargin < 4) |
1683 | 882 { |
5672 | 883 bool return_output = (nargout > 1 || nargin > 1); |
2083 | 884 |
3523 | 885 std::string cmd_str = args(0).string_value (); |
2083 | 886 |
5285 | 887 system_exec_type type = et_sync; |
2083 | 888 |
889 if (! error_state) | |
890 { | |
891 if (nargin > 2) | |
892 { | |
3523 | 893 std::string type_str = args(2).string_value (); |
1683 | 894 |
2083 | 895 if (! error_state) |
896 { | |
897 if (type_str == "sync") | |
5285 | 898 type = et_sync; |
2083 | 899 else if (type_str == "async") |
5285 | 900 type = et_async; |
2083 | 901 else |
902 error ("system: third arg must be \"sync\" or \"async\""); | |
903 } | |
904 else | |
905 error ("system: third argument must be a string"); | |
906 } | |
907 } | |
908 else | |
3523 | 909 error ("system: expecting std::string as first argument"); |
1683 | 910 |
2083 | 911 if (! error_state) |
912 { | |
7104 | 913 #if defined (__WIN32__) && ! defined (__CYGWIN__) |
914 // Work around weird double-quote handling on Windows systems. | |
915 if (type == et_sync) | |
916 cmd_str = "\"" + cmd_str + "\""; | |
917 #endif | |
918 | |
5285 | 919 if (type == et_async) |
2083 | 920 { |
6222 | 921 // FIXME -- maybe this should go in sysdep.cc? |
4086 | 922 #ifdef HAVE_FORK |
2083 | 923 pid_t pid = fork (); |
924 | |
925 if (pid < 0) | |
926 error ("system: fork failed -- can't create child process"); | |
927 else if (pid == 0) | |
928 { | |
5775 | 929 // FIXME -- should probably replace this |
3273 | 930 // call with something portable. |
931 | |
5510 | 932 execl ("/bin/sh", "sh", "-c", cmd_str.c_str (), |
933 static_cast<void *> (0)); | |
3273 | 934 |
935 panic_impossible (); | |
2083 | 936 } |
937 else | |
4254 | 938 retval(0) = pid; |
6222 | 939 #elif defined (__WIN32__) |
940 STARTUPINFO si; | |
941 PROCESS_INFORMATION pi; | |
942 ZeroMemory (&si, sizeof (si)); | |
943 ZeroMemory (&pi, sizeof (pi)); | |
944 OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length()+1); | |
6676 | 945 strcpy (xcmd_str, cmd_str.c_str ()); |
6222 | 946 |
947 if (! CreateProcess (0, xcmd_str, 0, 0, FALSE, 0, 0, 0, &si, &pi)) | |
948 error ("system: CreateProcess failed -- can't create child process"); | |
949 else | |
950 { | |
951 retval(0) = pi.dwProcessId; | |
952 CloseHandle (pi.hProcess); | |
953 CloseHandle (pi.hThread); | |
954 } | |
4086 | 955 #else |
956 error ("asynchronous system calls are not supported"); | |
957 #endif | |
2083 | 958 } |
2321 | 959 else if (return_output) |
960 retval = run_command_and_return_output (cmd_str); | |
2083 | 961 else |
2321 | 962 { |
963 int status = system (cmd_str.c_str ()); | |
964 | |
965 // The value in status is as returned by waitpid. If | |
966 // the process exited normally, extract the actual exit | |
967 // status of the command. Otherwise, return 127 as a | |
968 // failure code. | |
969 | |
2693 | 970 if (WIFEXITED (status)) |
971 status = WEXITSTATUS (status); | |
2321 | 972 |
4233 | 973 retval(0) = status; |
2321 | 974 } |
2083 | 975 } |
1683 | 976 } |
977 else | |
5823 | 978 print_usage (); |
1683 | 979 |
980 return retval; | |
981 } | |
982 | |
983 DEFALIAS (shell_cmd, system); | |
984 | |
5775 | 985 // FIXME -- this should really be static, but that causes |
2614 | 986 // problems on some systems. |
6680 | 987 std::list<std::string> octave_atexit_functions; |
2077 | 988 |
989 void | |
990 do_octave_atexit (void) | |
991 { | |
3216 | 992 static bool deja_vu = false; |
993 | |
2077 | 994 while (! octave_atexit_functions.empty ()) |
995 { | |
6680 | 996 std::string fcn = octave_atexit_functions.front (); |
4214 | 997 |
6680 | 998 octave_atexit_functions.pop_front (); |
2077 | 999 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1000 SAFE_CALL (reset_error_handler, ()) |
5237 | 1001 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1002 SAFE_CALL (feval, (fcn, octave_value_list (), 0)) |
3215 | 1003 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1004 SAFE_CALL (flush_octave_stdout, ()) |
2077 | 1005 } |
3216 | 1006 |
1007 if (! deja_vu) | |
1008 { | |
1009 deja_vu = true; | |
1010 | |
6068 | 1011 // Do this explicitly so that destructors for mex file objects |
1012 // are called, so that functions registered with mexAtExit are | |
1013 // called. | |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1014 SAFE_CALL (clear_mex_functions, ()) |
6068 | 1015 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1016 SAFE_CALL (command_editor::restore_terminal_state, ()) |
3216 | 1017 |
5775 | 1018 // FIXME -- is this needed? Can it cause any trouble? |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1019 SAFE_CALL (raw_mode, (0)) |
3216 | 1020 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1021 SAFE_CALL (octave_history_write_timestamp, ()) |
5305 | 1022 |
8735
afbfd7f4fd93
toplev.cc (do_octave_atexit): only save history if Vsaving_history is true
John W. Eaton <jwe@octave.org>
parents:
8719
diff
changeset
|
1023 if (Vsaving_history) |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1024 SAFE_CALL (command_history::clean_up_and_save, ()) |
3216 | 1025 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1026 SAFE_CALL (close_files, ()) |
3216 | 1027 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1028 SAFE_CALL (cleanup_tmp_files, ()) |
3216 | 1029 |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1030 SAFE_CALL (flush_octave_stdout, ()) |
3216 | 1031 |
5305 | 1032 if (! quitting_gracefully && (interactive || forced_interactive)) |
5629 | 1033 { |
1034 octave_stdout << "\n"; | |
1035 | |
1036 // Yes, we want this to be separate from the call to | |
1037 // flush_octave_stdout above. | |
1038 | |
9452
deb668d53e60
toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents:
9396
diff
changeset
|
1039 SAFE_CALL (flush_octave_stdout, ()) |
5629 | 1040 } |
3216 | 1041 } |
2077 | 1042 } |
1043 | |
7409 | 1044 void |
1045 octave_add_atexit_function (const std::string& fname) | |
1046 { | |
1047 octave_atexit_functions.push_front (fname); | |
1048 } | |
1049 | |
1050 bool | |
1051 octave_remove_atexit_function (const std::string& fname) | |
1052 { | |
1053 bool found = false; | |
1054 | |
1055 for (std::list<std::string>::iterator p = octave_atexit_functions.begin (); | |
1056 p != octave_atexit_functions.end (); p++) | |
1057 { | |
1058 if (*p == fname) | |
1059 { | |
1060 octave_atexit_functions.erase (p); | |
1061 found = true; | |
1062 break; | |
1063 } | |
1064 } | |
1065 | |
1066 return found; | |
1067 } | |
1068 | |
1069 | |
6680 | 1070 DEFUN (atexit, args, nargout, |
3332 | 1071 "-*- texinfo -*-\n\ |
1072 @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\ | |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1073 @deftypefnx {Built-in Function} {} atexit (@var{fcn}, @var{flag})\n\ |
3332 | 1074 Register a function to be called when Octave exits. For example,\n\ |
2077 | 1075 \n\ |
3332 | 1076 @example\n\ |
1077 @group\n\ | |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1078 function last_words ()\n\ |
6620 | 1079 disp (\"Bye bye\");\n\ |
3332 | 1080 endfunction\n\ |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1081 atexit (\"last_words\");\n\ |
3332 | 1082 @end group\n\ |
1083 @end example\n\ | |
1084 \n\ | |
1085 @noindent\n\ | |
6620 | 1086 will print the message \"Bye bye\" when Octave exits.\n\ |
6680 | 1087 \n\ |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1088 The additional argument @var{flag} will register or unregister\n\ |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1089 @var{fcn} from the list of functions to be called when Octave\n\ |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1090 exits. If @var{flag} is true, the function is registered, and if\n\ |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1091 @var{flag} is false, it is unregistered. For example,\n\ |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1092 after registering the function @code{last_words} above,\n\ |
6680 | 1093 \n\ |
1094 @example\n\ | |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1095 atexit (\"last_words\", false);\n\ |
6680 | 1096 @end example\n\ |
1097 \n\ | |
1098 @noindent\n\ | |
1099 will remove the function from the list and Octave will not call\n\ | |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1100 @code{last_words} when it exits.\n\ |
6680 | 1101 \n\ |
7001 | 1102 Note that @code{atexit} only removes the first occurrence of a function\n\ |
6680 | 1103 from the list, so if a function was placed in the list multiple\n\ |
1104 times with @code{atexit}, it must also be removed from the list\n\ | |
1105 multiple times.\n\ | |
3333 | 1106 @end deftypefn") |
2077 | 1107 { |
2086 | 1108 octave_value_list retval; |
2077 | 1109 |
1110 int nargin = args.length (); | |
1111 | |
6680 | 1112 if (nargin == 1 || nargin == 2) |
2077 | 1113 { |
3523 | 1114 std::string arg = args(0).string_value (); |
2077 | 1115 |
1116 if (! error_state) | |
6680 | 1117 { |
1118 bool add_mode = true; | |
1119 | |
1120 if (nargin == 2) | |
1121 { | |
1122 add_mode = args(1).bool_value (); | |
1123 | |
1124 if (error_state) | |
1125 error ("atexit: second argument must be a logical value"); | |
1126 } | |
1127 | |
1128 if (! error_state) | |
1129 { | |
1130 if (add_mode) | |
7409 | 1131 octave_add_atexit_function (arg); |
6680 | 1132 else |
1133 { | |
7409 | 1134 bool found = octave_remove_atexit_function (arg); |
6680 | 1135 |
1136 if (nargout > 0) | |
1137 retval(0) = found; | |
1138 } | |
1139 } | |
1140 } | |
2077 | 1141 else |
6680 | 1142 error ("atexit: argument must be a string"); |
2077 | 1143 } |
1144 else | |
5823 | 1145 print_usage (); |
2077 | 1146 |
1147 return retval; | |
1148 } | |
1149 | |
2689 | 1150 DEFUN (octave_config_info, args, , |
3301 | 1151 "-*- texinfo -*-\n\ |
1152 @deftypefn {Built-in Function} {} octave_config_info (@var{option})\n\ | |
1153 Return a structure containing configuration and installation\n\ | |
1154 information for Octave.\n\ | |
2689 | 1155 \n\ |
3301 | 1156 if @var{option} is a string, return the configuration information for the\n\ |
2689 | 1157 specified option.\n\ |
1158 \n\ | |
3301 | 1159 @end deftypefn") |
2162 | 1160 { |
2689 | 1161 octave_value retval; |
1162 | |
4128 | 1163 #if defined (ENABLE_DYNAMIC_LINKING) |
2689 | 1164 bool octave_supports_dynamic_linking = true; |
1165 #else | |
1166 bool octave_supports_dynamic_linking = false; | |
1167 #endif | |
1168 | |
4357 | 1169 static bool initialized = false; |
1170 static Octave_map m; | |
2162 | 1171 |
6274 | 1172 struct conf_info_struct |
1173 { | |
1174 bool subst_home; | |
1175 const char *key; | |
1176 const char *val; | |
1177 }; | |
1178 | |
1179 static const conf_info_struct conf_info[] = | |
4357 | 1180 { |
6274 | 1181 { false, "ALL_CFLAGS", OCTAVE_CONF_ALL_CFLAGS }, |
1182 { false, "ALL_CXXFLAGS", OCTAVE_CONF_ALL_CXXFLAGS }, | |
1183 { false, "ALL_FFLAGS", OCTAVE_CONF_ALL_FFLAGS }, | |
1184 { false, "ALL_LDFLAGS", OCTAVE_CONF_ALL_LDFLAGS }, | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1185 { false, "AMD_CPPFLAGS", OCTAVE_CONF_AMD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1186 { false, "AMD_LDFLAGS", OCTAVE_CONF_AMD_LDFLAGS }, |
9514 | 1187 { false, "AMD_LIBS", OCTAVE_CONF_AMD_LIBS }, |
6274 | 1188 { false, "AR", OCTAVE_CONF_AR }, |
1189 { false, "ARFLAGS", OCTAVE_CONF_ARFLAGS }, | |
9568
d3fccc4c4b9e
use OCTAVE_CHECK_LIBRARY to check for ARPACK
John W. Eaton <jwe@octave.org>
parents:
9542
diff
changeset
|
1190 { false, "ARPACK_CPPFLAGS", OCTAVE_CONF_ARPACK_CPPFLAGS }, |
d3fccc4c4b9e
use OCTAVE_CHECK_LIBRARY to check for ARPACK
John W. Eaton <jwe@octave.org>
parents:
9542
diff
changeset
|
1191 { false, "ARPACK_LDFLAGS", OCTAVE_CONF_ARPACK_LDFLAGS }, |
9514 | 1192 { false, "ARPACK_LIBS", OCTAVE_CONF_ARPACK_LIBS }, |
6274 | 1193 { false, "BLAS_LIBS", OCTAVE_CONF_BLAS_LIBS }, |
8772
aeedc045cfe3
toplev.cc (Foctave_config_info): add CARBON_LIBS, X11_INCFLAGS, and X11_LIBS to the struct
John W. Eaton <jwe@octave.org>
parents:
8735
diff
changeset
|
1194 { false, "CARBON_LIBS", OCTAVE_CONF_CARBON_LIBS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1195 { false, "CAMD_CPPFLAGS", OCTAVE_CONF_CAMD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1196 { false, "CAMD_LDFLAGS", OCTAVE_CONF_CAMD_LDFLAGS }, |
9514 | 1197 { false, "CAMD_LIBS", OCTAVE_CONF_CAMD_LIBS }, |
6274 | 1198 { false, "CC", OCTAVE_CONF_CC }, |
1199 { false, "CC_VERSION", OCTAVE_CONF_CC_VERSION }, | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1200 { false, "CCOLAMD_CPPFLAGS", OCTAVE_CONF_CCOLAMD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1201 { false, "CCOLAMD_LDFLAGS", OCTAVE_CONF_CCOLAMD_LDFLAGS }, |
9514 | 1202 { false, "CCOLAMD_LIBS", OCTAVE_CONF_CCOLAMD_LIBS }, |
6274 | 1203 { false, "CFLAGS", OCTAVE_CONF_CFLAGS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1204 { false, "CHOLMOD_CPPFLAGS", OCTAVE_CONF_CHOLMOD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1205 { false, "CHOLMOD_LDFLAGS", OCTAVE_CONF_CHOLMOD_LDFLAGS }, |
9514 | 1206 { false, "CHOLMOD_LIBS", OCTAVE_CONF_CHOLMOD_LIBS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1207 { false, "COLAMD_CPPFLAGS", OCTAVE_CONF_COLAMD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1208 { false, "COLAMD_LDFLAGS", OCTAVE_CONF_COLAMD_LDFLAGS }, |
9514 | 1209 { false, "COLAMD_LIBS", OCTAVE_CONF_COLAMD_LIBS }, |
6274 | 1210 { false, "CPICFLAG", OCTAVE_CONF_CPICFLAG }, |
1211 { false, "CPPFLAGS", OCTAVE_CONF_CPPFLAGS }, | |
9519
ee99f9f37505
improve configure checks for qhull and curl libs
John W. Eaton <jwe@octave.org>
parents:
9515
diff
changeset
|
1212 { false, "CURL_CPPFLAGS", OCTAVE_CONF_CURL_CPPFLAGS }, |
ee99f9f37505
improve configure checks for qhull and curl libs
John W. Eaton <jwe@octave.org>
parents:
9515
diff
changeset
|
1213 { false, "CURL_LDFLAGS", OCTAVE_CONF_CURL_LDFLAGS }, |
6274 | 1214 { false, "CURL_LIBS", OCTAVE_CONF_CURL_LIBS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1215 { false, "CXSPARSE_CPPFLAGS", OCTAVE_CONF_CXSPARSE_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1216 { false, "CXSPARSE_LDFLAGS", OCTAVE_CONF_CXSPARSE_LDFLAGS }, |
9514 | 1217 { false, "CXSPARSE_LIBS", OCTAVE_CONF_CXSPARSE_LIBS }, |
6274 | 1218 { false, "CXX", OCTAVE_CONF_CXX }, |
1219 { false, "CXXCPP", OCTAVE_CONF_CXXCPP }, | |
1220 { false, "CXXFLAGS", OCTAVE_CONF_CXXFLAGS }, | |
1221 { false, "CXXPICFLAG", OCTAVE_CONF_CXXPICFLAG }, | |
1222 { false, "CXX_VERSION", OCTAVE_CONF_CXX_VERSION }, | |
1223 { false, "DEFAULT_PAGER", OCTAVE_DEFAULT_PAGER }, | |
1224 { false, "DEFS", OCTAVE_CONF_DEFS }, | |
1225 { false, "DL_LD", OCTAVE_CONF_DL_LD }, | |
1226 { false, "DL_LDFLAGS", OCTAVE_CONF_DL_LDFLAGS }, | |
9515 | 1227 { false, "DL_LIBS", OCTAVE_CONF_DL_LIBS }, |
6274 | 1228 { false, "ENABLE_DYNAMIC_LINKING", OCTAVE_CONF_ENABLE_DYNAMIC_LINKING }, |
1229 { false, "EXEEXT", OCTAVE_CONF_EXEEXT }, | |
1230 { false, "F77", OCTAVE_CONF_F77 }, | |
1231 { false, "F77_FLOAT_STORE_FLAG", OCTAVE_CONF_F77_FLOAT_STORE_FLAG }, | |
1232 { false, "FC", OCTAVE_CONF_FC }, | |
1233 { false, "FFLAGS", OCTAVE_CONF_FFLAGS }, | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1234 { false, "FFTW3_CPPFLAGS", OCTAVE_CONF_FFTW3_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1235 { false, "FFTW3_LDFLAGS", OCTAVE_CONF_FFTW3_LDFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1236 { false, "FFTW3_LIBS", OCTAVE_CONF_FFTW3_LIBS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1237 { false, "FFTW3F_CPPFLAGS", OCTAVE_CONF_FFTW3F_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1238 { false, "FFTW3F_LDFLAGS", OCTAVE_CONF_FFTW3F_LDFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1239 { false, "FFTW3F_LIBS", OCTAVE_CONF_FFTW3F_LIBS }, |
6274 | 1240 { false, "FLIBS", OCTAVE_CONF_FLIBS }, |
1241 { false, "FPICFLAG", OCTAVE_CONF_FPICFLAG }, | |
9514 | 1242 { false, "FT2_LIBS", OCTAVE_CONF_FT2_LIBS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1243 { false, "GLPK_CPPFLAGS", OCTAVE_CONF_GLPK_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1244 { false, "GLPK_LDFLAGS", OCTAVE_CONF_GLPK_LDFLAGS }, |
6274 | 1245 { false, "GLPK_LIBS", OCTAVE_CONF_GLPK_LIBS }, |
7361 | 1246 { false, "GNUPLOT", OCTAVE_CONF_GNUPLOT }, |
9514 | 1247 { false, "GRAPHICS_LIBS", OCTAVE_CONF_GRAPHICS_LIBS }, |
9542
f5ec5dc66824
use OCTAVE_CHECK_LIBRARY to check for HDF5
John W. Eaton <jwe@octave.org>
parents:
9538
diff
changeset
|
1248 { false, "HDF5_CPPFLAGS", OCTAVE_CONF_HDF5_CPPFLAGS }, |
f5ec5dc66824
use OCTAVE_CHECK_LIBRARY to check for HDF5
John W. Eaton <jwe@octave.org>
parents:
9538
diff
changeset
|
1249 { false, "HDF5_LDFLAGS", OCTAVE_CONF_HDF5_LDFLAGS }, |
9514 | 1250 { false, "HDF5_LIBS", OCTAVE_CONF_HDF5_LIBS }, |
6274 | 1251 { false, "INCFLAGS", OCTAVE_CONF_INCFLAGS }, |
9794
0d4613a736e9
convert build system to use automake and libtool
John W. Eaton <jwe@octave.org>
parents:
9575
diff
changeset
|
1252 { false, "LAPACK_LIBS", OCTAVE_CONF_LAPACK_LIBS }, |
6274 | 1253 { false, "LDFLAGS", OCTAVE_CONF_LDFLAGS }, |
1254 { false, "LD_CXX", OCTAVE_CONF_LD_CXX }, | |
1255 { false, "LD_STATIC_FLAG", OCTAVE_CONF_LD_STATIC_FLAG }, | |
1256 { false, "LEX", OCTAVE_CONF_LEX }, | |
1257 { false, "LEXLIB", OCTAVE_CONF_LEXLIB }, | |
1258 { false, "LFLAGS", OCTAVE_CONF_LFLAGS }, | |
1259 { false, "LIBCRUFT", OCTAVE_CONF_LIBCRUFT }, | |
1260 { false, "LIBEXT", OCTAVE_CONF_LIBEXT }, | |
1261 { false, "LIBFLAGS", OCTAVE_CONF_LIBFLAGS }, | |
1262 { false, "LIBOCTAVE", OCTAVE_CONF_LIBOCTAVE }, | |
1263 { false, "LIBOCTINTERP", OCTAVE_CONF_LIBOCTINTERP }, | |
1264 { false, "LIBS", OCTAVE_CONF_LIBS }, | |
1265 { false, "LN_S", OCTAVE_CONF_LN_S }, | |
9575
55ecaefb7d0f
Use pkg-config to configure GraphicsMagick++.
David Grundberg <individ@acc.umu.se>
parents:
9572
diff
changeset
|
1266 { false, "MAGICK_CPPFLAGS", OCTAVE_CONF_MAGICK_CPPFLAGS }, |
55ecaefb7d0f
Use pkg-config to configure GraphicsMagick++.
David Grundberg <individ@acc.umu.se>
parents:
9572
diff
changeset
|
1267 { false, "MAGICK_LDFLAGS", OCTAVE_CONF_MAGICK_LDFLAGS }, |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7923
diff
changeset
|
1268 { false, "MAGICK_LIBS", OCTAVE_CONF_MAGICK_LIBS }, |
6274 | 1269 { false, "MKOCTFILE_DL_LDFLAGS", OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS }, |
9514 | 1270 { false, "OPENGL_LIBS", OCTAVE_CONF_OPENGL_LIBS }, |
1271 { false, "PTHREAD_CFLAGS", OCTAVE_CONF_PTHREAD_CFLAGS }, | |
1272 { false, "PTHREAD_LIBS", OCTAVE_CONF_PTHREAD_LIBS }, | |
9519
ee99f9f37505
improve configure checks for qhull and curl libs
John W. Eaton <jwe@octave.org>
parents:
9515
diff
changeset
|
1273 { false, "QHULL_CPPFLAGS", OCTAVE_CONF_QHULL_CPPFLAGS }, |
ee99f9f37505
improve configure checks for qhull and curl libs
John W. Eaton <jwe@octave.org>
parents:
9515
diff
changeset
|
1274 { false, "QHULL_LDFLAGS", OCTAVE_CONF_QHULL_LDFLAGS }, |
9514 | 1275 { false, "QHULL_LIBS", OCTAVE_CONF_QHULL_LIBS }, |
9570
1ab56c73ec7c
use OCTAVE_CHECK_LIBRARY to check for qrupdate library
John W. Eaton <jwe@octave.org>
parents:
9568
diff
changeset
|
1276 { false, "QRUPDATE_CPPFLAGS", OCTAVE_CONF_QRUPDATE_CPPFLAGS }, |
1ab56c73ec7c
use OCTAVE_CHECK_LIBRARY to check for qrupdate library
John W. Eaton <jwe@octave.org>
parents:
9568
diff
changeset
|
1277 { false, "QRUPDATE_LDFLAGS", OCTAVE_CONF_QRUPDATE_LDFLAGS }, |
9514 | 1278 { false, "QRUPDATE_LIBS", OCTAVE_CONF_QRUPDATE_LIBS }, |
6274 | 1279 { false, "RANLIB", OCTAVE_CONF_RANLIB }, |
1280 { false, "RDYNAMIC_FLAG", OCTAVE_CONF_RDYNAMIC_FLAG }, | |
9515 | 1281 { false, "READLINE_LIBS", OCTAVE_CONF_READLINE_LIBS }, |
9514 | 1282 { false, "REGEX_LIBS", OCTAVE_CONF_REGEX_LIBS }, |
6274 | 1283 { false, "RLD_FLAG", OCTAVE_CONF_RLD_FLAG }, |
1284 { false, "SED", OCTAVE_CONF_SED }, | |
1285 { false, "SHARED_LIBS", OCTAVE_CONF_SHARED_LIBS }, | |
1286 { false, "SHLEXT", OCTAVE_CONF_SHLEXT }, | |
1287 { false, "SHLEXT_VER", OCTAVE_CONF_SHLEXT_VER }, | |
1288 { false, "SH_LD", OCTAVE_CONF_SH_LD }, | |
1289 { false, "SH_LDFLAGS", OCTAVE_CONF_SH_LDFLAGS }, | |
1290 { false, "SONAME_FLAGS", OCTAVE_CONF_SONAME_FLAGS }, | |
1291 { false, "STATIC_LIBS", OCTAVE_CONF_STATIC_LIBS }, | |
9515 | 1292 { false, "TERM_LIBS", OCTAVE_CONF_TERM_LIBS }, |
6274 | 1293 { false, "UGLY_DEFS", OCTAVE_CONF_UGLY_DEFS }, |
9572
ab8a163f2052
use OCTAVE_CHECK_LIB to check for UMFPACK
John W. Eaton <jwe@octave.org>
parents:
9570
diff
changeset
|
1294 { false, "UMFPACK_CPPFLAGS", OCTAVE_CONF_UMFPACK_CPPFLAGS }, |
ab8a163f2052
use OCTAVE_CHECK_LIB to check for UMFPACK
John W. Eaton <jwe@octave.org>
parents:
9570
diff
changeset
|
1295 { false, "UMFPACK_LDFLAGS", OCTAVE_CONF_UMFPACK_LDFLAGS }, |
9514 | 1296 { false, "UMFPACK_LIBS", OCTAVE_CONF_UMFPACK_LIBS }, |
6274 | 1297 { false, "USE_64_BIT_IDX_T", OCTAVE_CONF_USE_64_BIT_IDX_T }, |
8772
aeedc045cfe3
toplev.cc (Foctave_config_info): add CARBON_LIBS, X11_INCFLAGS, and X11_LIBS to the struct
John W. Eaton <jwe@octave.org>
parents:
8735
diff
changeset
|
1298 { false, "X11_INCFLAGS", OCTAVE_CONF_X11_INCFLAGS }, |
aeedc045cfe3
toplev.cc (Foctave_config_info): add CARBON_LIBS, X11_INCFLAGS, and X11_LIBS to the struct
John W. Eaton <jwe@octave.org>
parents:
8735
diff
changeset
|
1299 { false, "X11_LIBS", OCTAVE_CONF_X11_LIBS }, |
6274 | 1300 { false, "XTRA_CFLAGS", OCTAVE_CONF_XTRA_CFLAGS }, |
1301 { false, "XTRA_CXXFLAGS", OCTAVE_CONF_XTRA_CXXFLAGS }, | |
1302 { false, "YACC", OCTAVE_CONF_YACC }, | |
1303 { false, "YFLAGS", OCTAVE_CONF_YFLAGS }, | |
9538
d0239bddf621
use OCTAVE_CHECK_LIB to check for zlib
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
1304 { false, "Z_CPPFLAGS", OCTAVE_CONF_Z_CPPFLAGS }, |
d0239bddf621
use OCTAVE_CHECK_LIB to check for zlib
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
1305 { false, "Z_LDFLAGS", OCTAVE_CONF_Z_LDFLAGS }, |
d0239bddf621
use OCTAVE_CHECK_LIB to check for zlib
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
1306 { false, "Z_LIBS", OCTAVE_CONF_Z_LIBS }, |
6274 | 1307 { false, "api_version", OCTAVE_API_VERSION }, |
1308 { true, "archlibdir", OCTAVE_ARCHLIBDIR }, | |
1309 { true, "bindir", OCTAVE_BINDIR }, | |
1310 { false, "canonical_host_type", OCTAVE_CANONICAL_HOST_TYPE }, | |
1311 { false, "config_opts", OCTAVE_CONF_config_opts }, | |
1312 { true, "datadir", OCTAVE_DATADIR }, | |
1313 { true, "datarootdir", OCTAVE_DATAROOTDIR }, | |
6276 | 1314 { true, "exec_prefix", OCTAVE_EXEC_PREFIX }, |
6274 | 1315 { true, "fcnfiledir", OCTAVE_FCNFILEDIR }, |
1316 { true, "imagedir", OCTAVE_IMAGEDIR }, | |
1317 { true, "includedir", OCTAVE_INCLUDEDIR }, | |
1318 { true, "infodir", OCTAVE_INFODIR }, | |
6276 | 1319 { true, "infofile", OCTAVE_INFOFILE }, |
6274 | 1320 { true, "libdir", OCTAVE_LIBDIR }, |
1321 { true, "libexecdir", OCTAVE_LIBEXECDIR }, | |
6311 | 1322 { true, "localapiarchlibdir", OCTAVE_LOCALAPIARCHLIBDIR }, |
6274 | 1323 { true, "localapifcnfiledir", OCTAVE_LOCALAPIFCNFILEDIR }, |
1324 { true, "localapioctfiledir", OCTAVE_LOCALAPIOCTFILEDIR }, | |
1325 { true, "localarchlibdir", OCTAVE_LOCALARCHLIBDIR }, | |
1326 { true, "localfcnfiledir", OCTAVE_LOCALFCNFILEDIR }, | |
1327 { true, "localoctfiledir", OCTAVE_LOCALOCTFILEDIR }, | |
1328 { true, "localstartupfiledir", OCTAVE_LOCALSTARTUPFILEDIR }, | |
1329 { true, "localverarchlibdir", OCTAVE_LOCALVERARCHLIBDIR }, | |
1330 { true, "localverfcnfiledir", OCTAVE_LOCALVERFCNFILEDIR }, | |
1331 { true, "localveroctfiledir", OCTAVE_LOCALVEROCTFILEDIR }, | |
1332 { true, "man1dir", OCTAVE_MAN1DIR }, | |
1333 { false, "man1ext", OCTAVE_MAN1EXT }, | |
1334 { true, "mandir", OCTAVE_MANDIR }, | |
1335 { true, "octfiledir", OCTAVE_OCTFILEDIR }, | |
8719
679c270b7584
install DOC and NEWS in $octetcdir
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
1336 { true, "octetcdir", OCTAVE_OCTETCDIR }, |
6274 | 1337 { true, "octincludedir", OCTAVE_OCTINCLUDEDIR }, |
1338 { true, "octlibdir", OCTAVE_OCTLIBDIR }, | |
6276 | 1339 { true, "prefix", OCTAVE_PREFIX }, |
6274 | 1340 { true, "startupfiledir", OCTAVE_STARTUPFILEDIR }, |
1341 { false, "version", OCTAVE_VERSION }, | |
1342 { false, 0, 0 } | |
4357 | 1343 }; |
1344 | |
1345 if (! initialized) | |
1346 { | |
4675 | 1347 m.assign ("dld", octave_value (octave_supports_dynamic_linking)); |
4357 | 1348 |
4697 | 1349 oct_mach_info::float_format ff = oct_mach_info::native_float_format (); |
1350 m.assign ("float_format", | |
1351 octave_value (oct_mach_info::float_format_as_string (ff))); | |
1352 | |
1353 m.assign ("words_big_endian", | |
1354 octave_value (oct_mach_info::words_big_endian ())); | |
1355 | |
1356 m.assign ("words_little_endian", | |
1357 octave_value (oct_mach_info::words_little_endian ())); | |
1358 | |
4357 | 1359 int i = 0; |
4440 | 1360 |
1361 while (true) | |
4357 | 1362 { |
6274 | 1363 const conf_info_struct& elt = conf_info[i++]; |
1364 | |
1365 const char *key = elt.key; | |
4357 | 1366 |
1367 if (key) | |
6274 | 1368 { |
1369 if (elt.subst_home) | |
1370 m.assign (key, octave_value (subst_octave_home (elt.val))); | |
1371 else | |
1372 m.assign (key, octave_value (elt.val)); | |
1373 } | |
4357 | 1374 else |
1375 break; | |
1376 } | |
1377 | |
4691 | 1378 bool unix_system = true; |
7013 | 1379 bool mac_system = false; |
4691 | 1380 bool windows_system = false; |
1381 | |
1382 #if defined (WIN32) | |
1383 windows_system = true; | |
1384 #if !defined (__CYGWIN__) | |
1385 unix_system = false; | |
1386 #endif | |
1387 #endif | |
1388 | |
8574
83b8c739d626
toplev.cc: check OCTAVE_USE_OS_X_API instead of __APPLE__ && __MACH__
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1389 #if defined (OCTAVE_USE_OS_X_API) |
7010 | 1390 mac_system = true; |
1391 #endif | |
1392 | |
4691 | 1393 m.assign ("unix", octave_value (unix_system)); |
7010 | 1394 m.assign ("mac", octave_value (mac_system)); |
4691 | 1395 m.assign ("windows", octave_value (windows_system)); |
1396 | |
4357 | 1397 initialized = true; |
1398 } | |
2162 | 1399 |
2689 | 1400 int nargin = args.length (); |
1401 | |
1402 if (nargin == 1) | |
1403 { | |
3523 | 1404 std::string arg = args(0).string_value (); |
2689 | 1405 |
1406 if (! error_state) | |
4675 | 1407 { |
1408 Cell c = m.contents (arg.c_str ()); | |
5199 | 1409 |
1410 if (c.is_empty ()) | |
1411 error ("octave_config_info: no info for `%s'", arg.c_str ()); | |
1412 else | |
1413 retval = c(0); | |
4675 | 1414 } |
2689 | 1415 } |
1416 else if (nargin == 0) | |
4233 | 1417 retval = m; |
2689 | 1418 else |
5823 | 1419 print_usage (); |
2689 | 1420 |
1421 return retval; | |
2162 | 1422 } |
1423 | |
1683 | 1424 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE) |
2806 | 1425 |
1683 | 1426 int debug_new_delete = 0; |
1427 | |
1428 typedef void (*vfp)(void); | |
1429 extern vfp __new_handler; | |
1430 | |
1431 void * | |
1432 __builtin_new (size_t sz) | |
1433 { | |
1434 void *p; | |
1435 | |
1436 /* malloc (0) is unpredictable; avoid it. */ | |
1437 if (sz == 0) | |
1438 sz = 1; | |
2800 | 1439 p = malloc (sz); |
1683 | 1440 while (p == 0) |
1441 { | |
1442 (*__new_handler) (); | |
2800 | 1443 p = malloc (sz); |
1683 | 1444 } |
1445 | |
1446 if (debug_new_delete) | |
5629 | 1447 std::cerr << "__builtin_new: " << p << std::endl; |
1683 | 1448 |
1449 return p; | |
1450 } | |
1451 | |
1452 void | |
1453 __builtin_delete (void *ptr) | |
1454 { | |
1455 if (debug_new_delete) | |
5629 | 1456 std::cerr << "__builtin_delete: " << ptr << std::endl; |
1683 | 1457 |
1458 if (ptr) | |
1459 free (ptr); | |
1460 } | |
2806 | 1461 |
1683 | 1462 #endif |