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