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