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