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