Mercurial > hg > octave-lyh
annotate src/toplev.cc @ 7752:40c428ea3408
initial implementation of dbup and dbdown
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 04 May 2008 03:42:19 -0400 |
parents | a059b5679fbb |
children | 6b521b1e3631 |
rev | line source |
---|---|
1683 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
4 2004, 2005, 2006, 2007 John W. Eaton | |
1683 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1683 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1683 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <cassert> | |
4489 | 29 #include <cerrno> |
1683 | 30 #include <cstdlib> |
31 #include <cstring> | |
4221 | 32 #include <new> |
1683 | 33 |
3503 | 34 #include <fstream> |
35 #include <iostream> | |
5765 | 36 #include <sstream> |
1728 | 37 #include <string> |
38 | |
1683 | 39 #ifdef HAVE_UNISTD_H |
2442 | 40 #ifdef HAVE_SYS_TYPES_H |
1683 | 41 #include <sys/types.h> |
2442 | 42 #endif |
1683 | 43 #include <unistd.h> |
44 #endif | |
45 | |
2926 | 46 #include "cmd-edit.h" |
47 #include "file-ops.h" | |
1683 | 48 #include "lo-error.h" |
2370 | 49 #include "lo-mappers.h" |
3020 | 50 #include "oct-env.h" |
4153 | 51 #include "quit.h" |
1755 | 52 #include "str-vec.h" |
1683 | 53 |
2492 | 54 #include <defaults.h> |
1683 | 55 #include "defun.h" |
56 #include "error.h" | |
57 #include "file-io.h" | |
58 #include "input.h" | |
59 #include "lex.h" | |
2492 | 60 #include <oct-conf.h> |
1742 | 61 #include "oct-hist.h" |
2162 | 62 #include "oct-map.h" |
2862 | 63 #include "oct-obj.h" |
1683 | 64 #include "pager.h" |
65 #include "parse.h" | |
66 #include "pathsearch.h" | |
67 #include "procstream.h" | |
2370 | 68 #include "ov.h" |
2985 | 69 #include "pt-jump.h" |
2982 | 70 #include "pt-stmt.h" |
1683 | 71 #include "sighandlers.h" |
72 #include "sysdep.h" | |
2693 | 73 #include "syswait.h" |
1750 | 74 #include "toplev.h" |
1683 | 75 #include "unwind-prot.h" |
76 #include "utils.h" | |
77 #include "variables.h" | |
2492 | 78 #include <version.h> |
1683 | 79 |
3020 | 80 // TRUE means we are exiting via the builtin exit or quit functions. |
81 static bool quitting_gracefully = false; | |
1683 | 82 |
4217 | 83 // TRUE means we are ready to interpret commands, but not everything |
84 // is ready for interactive use. | |
85 bool octave_interpreter_ready = false; | |
86 | |
4172 | 87 // TRUE means we've processed all the init code and we are good to go. |
88 bool octave_initialized = false; | |
89 | |
1683 | 90 // Current command to execute. |
91 tree_statement_list *global_command = 0; | |
92 | |
4238 | 93 // Pointer to parent function that is currently being evaluated. |
4748 | 94 octave_function *curr_parent_function = 0; |
4238 | 95 |
5743 | 96 octave_call_stack *octave_call_stack::instance = 0; |
97 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
98 int |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
99 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
|
100 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
101 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
|
102 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
103 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
|
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 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
106 int |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
107 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
|
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 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
|
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 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
|
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 |
5744 | 114 octave_user_script * |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
115 octave_call_stack::do_caller_user_script (void) const |
5744 | 116 { |
117 octave_user_script *retval = 0; | |
118 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
119 for (const_iterator p = cs.begin (); p != cs.end (); p++) |
5744 | 120 { |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
121 const call_stack_elt& elt = *p; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
122 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
123 octave_function *f = elt.fcn; |
5744 | 124 |
125 if (f && f->is_user_script ()) | |
126 { | |
127 retval = dynamic_cast<octave_user_script *> (f); | |
128 break; | |
129 } | |
130 } | |
131 | |
132 return retval; | |
133 } | |
134 | |
5743 | 135 octave_user_function * |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
136 octave_call_stack::do_caller_user_function (void) const |
5743 | 137 { |
138 octave_user_function *retval = 0; | |
139 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
140 for (const_iterator p = cs.begin (); p != cs.end (); p++) |
5743 | 141 { |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
142 const call_stack_elt& elt = *p; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
143 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
144 octave_function *f = elt.fcn; |
5743 | 145 |
146 if (f && f->is_user_function ()) | |
147 { | |
148 retval = dynamic_cast<octave_user_function *> (f); | |
149 break; | |
150 } | |
151 } | |
152 | |
153 return retval; | |
154 } | |
155 | |
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
|
156 octave_user_code * |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
157 octave_call_stack::do_caller_user_code (void) const |
5744 | 158 { |
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
|
159 octave_user_code *retval = 0; |
5744 | 160 |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
161 for (const_iterator p = cs.begin (); p != cs.end (); p++) |
5744 | 162 { |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
163 const call_stack_elt& elt = *p; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
164 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
165 octave_function *f = elt.fcn; |
5744 | 166 |
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
|
167 if (f && f->is_user_code ()) |
5744 | 168 { |
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
|
169 retval = dynamic_cast<octave_user_code *> (f); |
5744 | 170 break; |
171 } | |
172 } | |
173 | |
174 return retval; | |
175 } | |
176 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
177 Octave_map |
7736 | 178 octave_call_stack::do_backtrace (int n) 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
|
179 { |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
180 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
|
181 |
7736 | 182 int nframes = cs.size () - n; |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
183 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
184 if (n >= 0 && nframes > 0) |
7736 | 185 { |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
186 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
|
187 |
7736 | 188 keys(0) = "file"; |
189 keys(1) = "name"; | |
190 keys(2) = "line"; | |
191 keys(3) = "column"; | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
192 keys(4) = "scope"; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
193 keys(5) = "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
|
194 |
7736 | 195 Cell file (nframes, 1); |
196 Cell name (nframes, 1); | |
197 Cell line (nframes, 1); | |
198 Cell column (nframes, 1); | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
199 Cell scope (nframes, 1); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
200 Cell context (nframes, 1); |
7736 | 201 |
202 octave_idx_type k = 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
|
203 |
7736 | 204 for (const_iterator p = cs.begin () + n; p != cs.end (); 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
|
205 { |
7736 | 206 const call_stack_elt& elt = *p; |
207 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
208 scope(k) = elt.scope; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
209 context(k) = elt.context; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
210 |
7736 | 211 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
|
212 |
7736 | 213 if (f) |
214 { | |
215 file(k) = f->fcn_file_name (); | |
216 name(k) = f->name (); | |
217 | |
218 tree_statement *stmt = elt.stmt; | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
219 |
7736 | 220 if (stmt) |
221 { | |
222 line(k) = stmt->line (); | |
223 column(k) = stmt->column (); | |
224 } | |
225 else | |
226 { | |
227 line(k) = -1; | |
228 column(k) = -1; | |
229 } | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
230 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
231 else |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
232 { |
7736 | 233 file(k) = "<unknown>"; |
234 name(k) = "<unknown>"; | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
235 line(k) = -1; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
236 column(k) = -1; |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
237 } |
7736 | 238 |
239 k++; | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
240 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
241 |
7736 | 242 retval.assign ("file", file); |
243 retval.assign ("name", name); | |
244 retval.assign ("line", line); | |
245 retval.assign ("column", column); | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
246 retval.assign ("scope", scope); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
247 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
|
248 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
249 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
250 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
|
251 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
252 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
253 bool |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
254 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
|
255 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
256 bool retval = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
257 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
258 if (n < cs.size ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
259 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
260 retval = true; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
261 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
262 curr_frame = n; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
263 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
264 const call_stack_elt& elt = cs[n]; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
265 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
266 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
|
267 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
268 if (verbose) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
269 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
270 octave_function *f = elt.fcn; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
271 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
|
272 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
273 tree_statement *s = elt.stmt; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
274 int l = -1; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
275 int c = -1; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
276 if (s) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
277 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
278 l = s->line (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
279 c = s->column (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
280 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
281 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
282 octave_stdout << "stopped in " << nm |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
283 << " at line " << l << " column " << c |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
284 << " (" << elt.scope << "[" << elt.context << "])" |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
285 << std::endl; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
286 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
287 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
288 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
289 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
290 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
291 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
292 bool |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
293 octave_call_stack::do_goto_frame_relative (int n, bool verbose) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
294 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
295 bool retval = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
296 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
297 size_t sz = cs.size (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
298 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
299 if (n == 0) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
300 retval = true; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
301 else if ((n > 0 && static_cast<size_t> (n) < sz - curr_frame) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
302 || (n < 0 && static_cast<size_t> (-n) < curr_frame)) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
303 retval = goto_frame (curr_frame + n, verbose); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
304 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
305 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
306 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
307 |
5744 | 308 void |
4180 | 309 recover_from_exception (void) |
310 { | |
311 can_interrupt = true; | |
4182 | 312 octave_interrupt_immediately = 0; |
4180 | 313 octave_interrupt_state = 0; |
5142 | 314 octave_signal_caught = 0; |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7409
diff
changeset
|
315 octave_exception_state = octave_no_exception; |
4180 | 316 octave_restore_signal_mask (); |
317 octave_catch_interrupts (); | |
318 } | |
319 | |
1907 | 320 int |
5189 | 321 main_loop (void) |
1907 | 322 { |
2016 | 323 octave_save_signal_mask (); |
324 | |
3020 | 325 can_interrupt = true; |
1907 | 326 |
5142 | 327 octave_signal_hook = octave_signal_handler; |
4429 | 328 octave_interrupt_hook = unwind_protect::run_all; |
329 octave_bad_alloc_hook = unwind_protect::run_all; | |
330 | |
2554 | 331 octave_catch_interrupts (); |
1907 | 332 |
4172 | 333 octave_initialized = true; |
334 | |
1907 | 335 // The big loop. |
336 | |
4153 | 337 int retval = 0; |
1907 | 338 do |
339 { | |
4180 | 340 try |
1907 | 341 { |
7336 | 342 symbol_table::reset_scope (); |
2620 | 343 |
4318 | 344 reset_error_handler (); |
345 | |
4153 | 346 reset_parser (); |
2620 | 347 |
4753 | 348 // This is the same as yyparse in parse.y. |
349 retval = octave_parse (); | |
2620 | 350 |
4153 | 351 if (retval == 0) |
352 { | |
353 if (global_command) | |
3804 | 354 { |
4153 | 355 global_command->eval (); |
3883 | 356 |
4153 | 357 delete global_command; |
3883 | 358 |
4153 | 359 global_command = 0; |
3883 | 360 |
4171 | 361 OCTAVE_QUIT; |
362 | |
3883 | 363 if (! (interactive || forced_interactive)) |
364 { | |
4207 | 365 bool quit = (tree_return_command::returning |
366 || tree_break_command::breaking); | |
4153 | 367 |
4207 | 368 if (tree_return_command::returning) |
369 tree_return_command::returning = 0; | |
4153 | 370 |
4207 | 371 if (tree_break_command::breaking) |
372 tree_break_command::breaking--; | |
4153 | 373 |
374 if (quit) | |
375 break; | |
376 } | |
377 | |
378 if (error_state) | |
379 { | |
380 if (! (interactive || forced_interactive)) | |
381 { | |
382 // We should exit with a non-zero status. | |
383 retval = 1; | |
384 break; | |
385 } | |
386 } | |
387 else | |
388 { | |
389 if (octave_completion_matches_called) | |
390 octave_completion_matches_called = false; | |
391 else | |
392 command_editor::increment_current_command_number (); | |
3883 | 393 } |
394 } | |
4153 | 395 else if (parser_end_of_input) |
396 break; | |
2620 | 397 } |
4153 | 398 } |
4182 | 399 catch (octave_interrupt_exception) |
4153 | 400 { |
4180 | 401 recover_from_exception (); |
5629 | 402 octave_stdout << "\n"; |
4180 | 403 } |
4181 | 404 catch (std::bad_alloc) |
4180 | 405 { |
406 recover_from_exception (); | |
407 std::cerr | |
6680 | 408 << "error: memory exhausted or requested size too large for range of Octave's index type -- trying to return to prompt" |
409 << std::endl; | |
1907 | 410 } |
411 } | |
412 while (retval == 0); | |
413 | |
414 return retval; | |
415 } | |
416 | |
1683 | 417 // Fix up things before exiting. |
418 | |
419 void | |
3162 | 420 clean_up_and_exit (int retval) |
421 { | |
3216 | 422 do_octave_atexit (); |
1683 | 423 |
5451 | 424 sysdep_cleanup (); |
425 | |
3162 | 426 exit (retval == EOF ? 0 : retval); |
1683 | 427 } |
428 | |
3180 | 429 DEFUN (quit, args, nargout, |
3332 | 430 "-*- texinfo -*-\n\ |
431 @deftypefn {Built-in Function} {} exit (@var{status})\n\ | |
432 @deftypefnx {Built-in Function} {} quit (@var{status})\n\ | |
433 Exit the current Octave session. If the optional integer value\n\ | |
434 @var{status} is supplied, pass that value to the operating system as the\n\ | |
6615 | 435 Octave's exit status. The default value is zero.\n\ |
3333 | 436 @end deftypefn") |
1683 | 437 { |
2086 | 438 octave_value_list retval; |
2068 | 439 |
3180 | 440 if (nargout == 0) |
2068 | 441 { |
3180 | 442 int exit_status = 0; |
443 | |
444 quitting_gracefully = true; | |
1683 | 445 |
3180 | 446 if (args.length () > 0) |
447 { | |
3202 | 448 int tmp = args(0).nint_value (); |
1683 | 449 |
3202 | 450 if (! error_state) |
451 exit_status = tmp; | |
3180 | 452 } |
453 | |
454 clean_up_and_exit (exit_status); | |
2068 | 455 } |
3180 | 456 else |
457 error ("quit: invalid number of output arguments"); | |
2068 | 458 |
1683 | 459 return retval; |
460 } | |
461 | |
462 DEFALIAS (exit, quit); | |
463 | |
1957 | 464 DEFUN (warranty, , , |
3446 | 465 "-*- texinfo -*-\n\ |
466 @deftypefn {Built-in Function} {} warranty ()\n\ | |
467 Describe the conditions for copying and distributing Octave.\n\ | |
468 @end deftypefn") | |
1683 | 469 { |
2086 | 470 octave_value_list retval; |
1683 | 471 |
3922 | 472 octave_stdout << "\n" \ |
473 OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\ | |
474 \n\ | |
1683 | 475 This program is free software; you can redistribute it and/or modify\n\ |
476 it under the terms of the GNU General Public License as published by\n\ | |
7016 | 477 the Free Software Foundation; either version 3 of the License, or\n\ |
1683 | 478 (at your option) any later version.\n\ |
479 \n\ | |
480 This program is distributed in the hope that it will be useful,\n\ | |
481 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ | |
482 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ | |
483 GNU General Public License for more details.\n\ | |
484 \n\ | |
485 You should have received a copy of the GNU General Public License\n\ | |
7016 | 486 along with this program. If not, see <http://www.gnu.org/licenses/>.\n\ |
1683 | 487 \n"; |
488 | |
489 return retval; | |
490 } | |
491 | |
492 // Execute a shell command. | |
493 | |
1965 | 494 static void |
495 cleanup_iprocstream (void *p) | |
496 { | |
3060 | 497 iprocstream *cmd = static_cast<iprocstream *> (p); |
498 | |
499 octave_child_list::remove (cmd->pid ()); | |
500 | |
501 delete cmd; | |
1965 | 502 } |
503 | |
6316 | 504 static int |
505 wait_for_input (int fid) | |
506 { | |
507 int retval = -1; | |
508 | |
509 #if defined (HAVE_SELECT) | |
510 if (fid >= 0) | |
511 { | |
512 fd_set set; | |
513 | |
514 FD_ZERO (&set); | |
515 FD_SET (fid, &set); | |
516 | |
517 retval = select (FD_SETSIZE, &set, 0, 0, 0); | |
518 } | |
519 #else | |
520 retval = 1; | |
521 #endif | |
522 | |
523 return retval; | |
524 } | |
525 | |
2086 | 526 static octave_value_list |
3523 | 527 run_command_and_return_output (const std::string& cmd_str) |
2083 | 528 { |
2086 | 529 octave_value_list retval; |
2083 | 530 |
531 iprocstream *cmd = new iprocstream (cmd_str.c_str ()); | |
532 | |
3060 | 533 if (cmd) |
2083 | 534 { |
3060 | 535 unwind_protect::add (cleanup_iprocstream, cmd); |
536 | |
537 if (*cmd) | |
538 { | |
6316 | 539 int fid = cmd->file_number (); |
2095 | 540 |
6316 | 541 std::ostringstream output_buf; |
4494 | 542 |
3060 | 543 char ch; |
3147 | 544 |
4489 | 545 for (;;) |
3147 | 546 { |
4489 | 547 if (cmd->get (ch)) |
548 output_buf.put (ch); | |
549 else | |
550 { | |
551 if (! cmd->eof () && errno == EAGAIN) | |
552 { | |
553 cmd->clear (); | |
3147 | 554 |
6316 | 555 if (wait_for_input (fid) != 1) |
556 break; | |
4489 | 557 } |
558 else | |
559 break; | |
560 } | |
3147 | 561 } |
562 | |
3252 | 563 int cmd_status = cmd->close (); |
2083 | 564 |
3060 | 565 if (WIFEXITED (cmd_status)) |
566 cmd_status = WEXITSTATUS (cmd_status); | |
567 else | |
568 cmd_status = 127; | |
2083 | 569 |
5659 | 570 retval(0) = (double) cmd_status; |
5765 | 571 retval(1) = output_buf.str (); |
3060 | 572 } |
573 | |
574 unwind_protect::run (); | |
2083 | 575 } |
576 else | |
577 error ("unable to start subprocess for `%s'", cmd_str.c_str ()); | |
578 | |
579 return retval; | |
580 } | |
581 | |
5285 | 582 enum system_exec_type { et_sync, et_async }; |
583 | |
1957 | 584 DEFUN (system, args, nargout, |
3301 | 585 "-*- texinfo -*-\n\ |
586 @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})\n\ | |
587 Execute a shell command specified by @var{string}. The second\n\ | |
588 argument is optional. If @var{type} is @code{\"async\"}, the process\n\ | |
589 is started in the background and the process id of the child process\n\ | |
590 is returned immediately. Otherwise, the process is started, and\n\ | |
591 Octave waits until it exits. If @var{type} argument is omitted, a\n\ | |
592 value of @code{\"sync\"} is assumed.\n\ | |
2083 | 593 \n\ |
3301 | 594 If two input arguments are given (the actual value of\n\ |
595 @var{return_output} is irrelevant) and the subprocess is started\n\ | |
596 synchronously, or if @var{system} is called with one input argument and\n\ | |
597 one or more output arguments, the output from the command is returned.\n\ | |
5097 | 598 Otherwise, if the subprocess is executed synchronously, its output is\n\ |
2321 | 599 sent to the standard output. To send the output of a command executed\n\ |
3301 | 600 with @var{system} through the pager, use a command like\n\ |
2321 | 601 \n\ |
3301 | 602 @example\n\ |
603 disp (system (cmd, 1));\n\ | |
604 @end example\n\ | |
2321 | 605 \n\ |
3301 | 606 @noindent\n\ |
2321 | 607 or\n\ |
608 \n\ | |
3301 | 609 @example\n\ |
610 printf (\"%s\n\", system (cmd, 1));\n\ | |
611 @end example\n\ | |
612 \n\ | |
5659 | 613 The @code{system} function can return two values. The first is the\n\ |
614 exit status of the command and the second is any output from the\n\ | |
615 command that was written to the standard output stream. For example,\n\ | |
3301 | 616 \n\ |
617 @example\n\ | |
5717 | 618 [status, output] = system (\"echo foo; exit 2\");\n\ |
3301 | 619 @end example\n\ |
620 \n\ | |
621 @noindent\n\ | |
622 will set the variable @code{output} to the string @samp{foo}, and the\n\ | |
623 variable @code{status} to the integer @samp{2}.\n\ | |
624 @end deftypefn") | |
1683 | 625 { |
2086 | 626 octave_value_list retval; |
1683 | 627 |
3834 | 628 unwind_protect::begin_frame ("Fsystem"); |
629 | |
1683 | 630 int nargin = args.length (); |
631 | |
2083 | 632 if (nargin > 0 && nargin < 4) |
1683 | 633 { |
5672 | 634 bool return_output = (nargout > 1 || nargin > 1); |
2083 | 635 |
3523 | 636 std::string cmd_str = args(0).string_value (); |
2083 | 637 |
5285 | 638 system_exec_type type = et_sync; |
2083 | 639 |
640 if (! error_state) | |
641 { | |
642 if (nargin > 2) | |
643 { | |
3523 | 644 std::string type_str = args(2).string_value (); |
1683 | 645 |
2083 | 646 if (! error_state) |
647 { | |
648 if (type_str == "sync") | |
5285 | 649 type = et_sync; |
2083 | 650 else if (type_str == "async") |
5285 | 651 type = et_async; |
2083 | 652 else |
653 error ("system: third arg must be \"sync\" or \"async\""); | |
654 } | |
655 else | |
656 error ("system: third argument must be a string"); | |
657 } | |
658 } | |
659 else | |
3523 | 660 error ("system: expecting std::string as first argument"); |
1683 | 661 |
2083 | 662 if (! error_state) |
663 { | |
7104 | 664 #if defined (__WIN32__) && ! defined (__CYGWIN__) |
665 // Work around weird double-quote handling on Windows systems. | |
666 if (type == et_sync) | |
667 cmd_str = "\"" + cmd_str + "\""; | |
668 #endif | |
669 | |
5285 | 670 if (type == et_async) |
2083 | 671 { |
6222 | 672 // FIXME -- maybe this should go in sysdep.cc? |
4086 | 673 #ifdef HAVE_FORK |
2083 | 674 pid_t pid = fork (); |
675 | |
676 if (pid < 0) | |
677 error ("system: fork failed -- can't create child process"); | |
678 else if (pid == 0) | |
679 { | |
5775 | 680 // FIXME -- should probably replace this |
3273 | 681 // call with something portable. |
682 | |
5510 | 683 execl ("/bin/sh", "sh", "-c", cmd_str.c_str (), |
684 static_cast<void *> (0)); | |
3273 | 685 |
686 panic_impossible (); | |
2083 | 687 } |
688 else | |
4254 | 689 retval(0) = pid; |
6222 | 690 #elif defined (__WIN32__) |
691 STARTUPINFO si; | |
692 PROCESS_INFORMATION pi; | |
693 ZeroMemory (&si, sizeof (si)); | |
694 ZeroMemory (&pi, sizeof (pi)); | |
695 OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length()+1); | |
6676 | 696 strcpy (xcmd_str, cmd_str.c_str ()); |
6222 | 697 |
698 if (! CreateProcess (0, xcmd_str, 0, 0, FALSE, 0, 0, 0, &si, &pi)) | |
699 error ("system: CreateProcess failed -- can't create child process"); | |
700 else | |
701 { | |
702 retval(0) = pi.dwProcessId; | |
703 CloseHandle (pi.hProcess); | |
704 CloseHandle (pi.hThread); | |
705 } | |
4086 | 706 #else |
707 error ("asynchronous system calls are not supported"); | |
708 #endif | |
2083 | 709 } |
2321 | 710 else if (return_output) |
711 retval = run_command_and_return_output (cmd_str); | |
2083 | 712 else |
2321 | 713 { |
714 int status = system (cmd_str.c_str ()); | |
715 | |
716 // The value in status is as returned by waitpid. If | |
717 // the process exited normally, extract the actual exit | |
718 // status of the command. Otherwise, return 127 as a | |
719 // failure code. | |
720 | |
2693 | 721 if (WIFEXITED (status)) |
722 status = WEXITSTATUS (status); | |
2321 | 723 |
4233 | 724 retval(0) = status; |
2321 | 725 } |
2083 | 726 } |
1683 | 727 } |
728 else | |
5823 | 729 print_usage (); |
1683 | 730 |
3834 | 731 unwind_protect::run_frame ("Fsystem"); |
732 | |
1683 | 733 return retval; |
734 } | |
735 | |
736 DEFALIAS (shell_cmd, system); | |
737 | |
5775 | 738 // FIXME -- this should really be static, but that causes |
2614 | 739 // problems on some systems. |
6680 | 740 std::list<std::string> octave_atexit_functions; |
2077 | 741 |
742 void | |
743 do_octave_atexit (void) | |
744 { | |
3216 | 745 static bool deja_vu = false; |
746 | |
2077 | 747 while (! octave_atexit_functions.empty ()) |
748 { | |
6680 | 749 std::string fcn = octave_atexit_functions.front (); |
4214 | 750 |
6680 | 751 octave_atexit_functions.pop_front (); |
2077 | 752 |
5237 | 753 reset_error_handler (); |
754 | |
4233 | 755 feval (fcn, octave_value_list (), 0); |
3215 | 756 |
757 flush_octave_stdout (); | |
2077 | 758 } |
3216 | 759 |
760 if (! deja_vu) | |
761 { | |
762 deja_vu = true; | |
763 | |
6068 | 764 // Do this explicitly so that destructors for mex file objects |
765 // are called, so that functions registered with mexAtExit are | |
766 // called. | |
6072 | 767 clear_mex_functions (); |
6068 | 768 |
3216 | 769 command_editor::restore_terminal_state (); |
770 | |
5775 | 771 // FIXME -- is this needed? Can it cause any trouble? |
3216 | 772 raw_mode (0); |
773 | |
5305 | 774 octave_history_write_timestamp (); |
775 | |
3216 | 776 command_history::clean_up_and_save (); |
777 | |
778 close_files (); | |
779 | |
780 cleanup_tmp_files (); | |
781 | |
782 flush_octave_stdout (); | |
783 | |
5305 | 784 if (! quitting_gracefully && (interactive || forced_interactive)) |
5629 | 785 { |
786 octave_stdout << "\n"; | |
787 | |
788 // Yes, we want this to be separate from the call to | |
789 // flush_octave_stdout above. | |
790 | |
791 flush_octave_stdout (); | |
792 } | |
3216 | 793 } |
2077 | 794 } |
795 | |
7409 | 796 void |
797 octave_add_atexit_function (const std::string& fname) | |
798 { | |
799 octave_atexit_functions.push_front (fname); | |
800 } | |
801 | |
802 bool | |
803 octave_remove_atexit_function (const std::string& fname) | |
804 { | |
805 bool found = false; | |
806 | |
807 for (std::list<std::string>::iterator p = octave_atexit_functions.begin (); | |
808 p != octave_atexit_functions.end (); p++) | |
809 { | |
810 if (*p == fname) | |
811 { | |
812 octave_atexit_functions.erase (p); | |
813 found = true; | |
814 break; | |
815 } | |
816 } | |
817 | |
818 return found; | |
819 } | |
820 | |
821 | |
6680 | 822 DEFUN (atexit, args, nargout, |
3332 | 823 "-*- texinfo -*-\n\ |
824 @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\ | |
825 Register a function to be called when Octave exits. For example,\n\ | |
2077 | 826 \n\ |
3332 | 827 @example\n\ |
828 @group\n\ | |
6620 | 829 function bye_bye ()\n\ |
830 disp (\"Bye bye\");\n\ | |
3332 | 831 endfunction\n\ |
6620 | 832 atexit (\"bye_bye\");\n\ |
3332 | 833 @end group\n\ |
834 @end example\n\ | |
835 \n\ | |
836 @noindent\n\ | |
6620 | 837 will print the message \"Bye bye\" when Octave exits.\n\ |
6680 | 838 \n\ |
839 @deftypefnx {Built-in Function} {} atexit (@var{fcn}, @var{flag})\n\ | |
840 Register or unregister a function to be called when Octave exits,\n\ | |
841 depending on @var{flag}. If @var{flag} is true, the function is\n\ | |
842 registered, if @var{flag} is false, it is unregistered. For example,\n\ | |
843 after registering the function @code{bye_bye} as above,\n\ | |
844 \n\ | |
845 @example\n\ | |
846 atexit (\"bye_bye\", false);\n\ | |
847 @end example\n\ | |
848 \n\ | |
849 @noindent\n\ | |
850 will remove the function from the list and Octave will not call\n\ | |
851 the function @code{bye_by} when it exits.\n\ | |
852 \n\ | |
7001 | 853 Note that @code{atexit} only removes the first occurrence of a function\n\ |
6680 | 854 from the list, so if a function was placed in the list multiple\n\ |
855 times with @code{atexit}, it must also be removed from the list\n\ | |
856 multiple times.\n\ | |
3333 | 857 @end deftypefn") |
2077 | 858 { |
2086 | 859 octave_value_list retval; |
2077 | 860 |
861 int nargin = args.length (); | |
862 | |
6680 | 863 if (nargin == 1 || nargin == 2) |
2077 | 864 { |
3523 | 865 std::string arg = args(0).string_value (); |
2077 | 866 |
867 if (! error_state) | |
6680 | 868 { |
869 bool add_mode = true; | |
870 | |
871 if (nargin == 2) | |
872 { | |
873 add_mode = args(1).bool_value (); | |
874 | |
875 if (error_state) | |
876 error ("atexit: second argument must be a logical value"); | |
877 } | |
878 | |
879 if (! error_state) | |
880 { | |
881 if (add_mode) | |
7409 | 882 octave_add_atexit_function (arg); |
6680 | 883 else |
884 { | |
7409 | 885 bool found = octave_remove_atexit_function (arg); |
6680 | 886 |
887 if (nargout > 0) | |
888 retval(0) = found; | |
889 } | |
890 } | |
891 } | |
2077 | 892 else |
6680 | 893 error ("atexit: argument must be a string"); |
2077 | 894 } |
895 else | |
5823 | 896 print_usage (); |
2077 | 897 |
898 return retval; | |
899 } | |
900 | |
2689 | 901 DEFUN (octave_config_info, args, , |
3301 | 902 "-*- texinfo -*-\n\ |
903 @deftypefn {Built-in Function} {} octave_config_info (@var{option})\n\ | |
904 Return a structure containing configuration and installation\n\ | |
905 information for Octave.\n\ | |
2689 | 906 \n\ |
3301 | 907 if @var{option} is a string, return the configuration information for the\n\ |
2689 | 908 specified option.\n\ |
909 \n\ | |
3301 | 910 @end deftypefn") |
2162 | 911 { |
2689 | 912 octave_value retval; |
913 | |
4128 | 914 #if defined (ENABLE_DYNAMIC_LINKING) |
2689 | 915 bool octave_supports_dynamic_linking = true; |
916 #else | |
917 bool octave_supports_dynamic_linking = false; | |
918 #endif | |
919 | |
4357 | 920 static bool initialized = false; |
921 static Octave_map m; | |
2162 | 922 |
6274 | 923 struct conf_info_struct |
924 { | |
925 bool subst_home; | |
926 const char *key; | |
927 const char *val; | |
928 }; | |
929 | |
930 static const conf_info_struct conf_info[] = | |
4357 | 931 { |
6274 | 932 { false, "ALL_CFLAGS", OCTAVE_CONF_ALL_CFLAGS }, |
933 { false, "ALL_CXXFLAGS", OCTAVE_CONF_ALL_CXXFLAGS }, | |
934 { false, "ALL_FFLAGS", OCTAVE_CONF_ALL_FFLAGS }, | |
935 { false, "ALL_LDFLAGS", OCTAVE_CONF_ALL_LDFLAGS }, | |
936 { false, "AR", OCTAVE_CONF_AR }, | |
937 { false, "ARFLAGS", OCTAVE_CONF_ARFLAGS }, | |
938 { false, "BLAS_LIBS", OCTAVE_CONF_BLAS_LIBS }, | |
939 { false, "CC", OCTAVE_CONF_CC }, | |
940 { false, "CC_VERSION", OCTAVE_CONF_CC_VERSION }, | |
941 { false, "CFLAGS", OCTAVE_CONF_CFLAGS }, | |
942 { false, "CPICFLAG", OCTAVE_CONF_CPICFLAG }, | |
943 { false, "CPPFLAGS", OCTAVE_CONF_CPPFLAGS }, | |
944 { false, "CURL_LIBS", OCTAVE_CONF_CURL_LIBS }, | |
945 { false, "CXX", OCTAVE_CONF_CXX }, | |
946 { false, "CXXCPP", OCTAVE_CONF_CXXCPP }, | |
947 { false, "CXXFLAGS", OCTAVE_CONF_CXXFLAGS }, | |
948 { false, "CXXPICFLAG", OCTAVE_CONF_CXXPICFLAG }, | |
949 { false, "CXX_VERSION", OCTAVE_CONF_CXX_VERSION }, | |
950 { false, "DEFAULT_PAGER", OCTAVE_DEFAULT_PAGER }, | |
951 { false, "DEFS", OCTAVE_CONF_DEFS }, | |
952 { false, "DL_LD", OCTAVE_CONF_DL_LD }, | |
953 { false, "DL_LDFLAGS", OCTAVE_CONF_DL_LDFLAGS }, | |
954 { false, "ENABLE_DYNAMIC_LINKING", OCTAVE_CONF_ENABLE_DYNAMIC_LINKING }, | |
955 { false, "EXEEXT", OCTAVE_CONF_EXEEXT }, | |
956 { false, "F2C", OCTAVE_CONF_F2C }, | |
957 { false, "F2CFLAGS", OCTAVE_CONF_F2CFLAGS }, | |
958 { false, "F77", OCTAVE_CONF_F77 }, | |
959 { false, "F77_FLOAT_STORE_FLAG", OCTAVE_CONF_F77_FLOAT_STORE_FLAG }, | |
960 { false, "FC", OCTAVE_CONF_FC }, | |
961 { false, "FFLAGS", OCTAVE_CONF_FFLAGS }, | |
962 { false, "FFTW_LIBS", OCTAVE_CONF_FFTW_LIBS }, | |
963 { false, "FLIBS", OCTAVE_CONF_FLIBS }, | |
964 { false, "FPICFLAG", OCTAVE_CONF_FPICFLAG }, | |
965 { false, "GLPK_LIBS", OCTAVE_CONF_GLPK_LIBS }, | |
7361 | 966 { false, "GNUPLOT", OCTAVE_CONF_GNUPLOT }, |
6274 | 967 { false, "INCFLAGS", OCTAVE_CONF_INCFLAGS }, |
968 { false, "LDFLAGS", OCTAVE_CONF_LDFLAGS }, | |
969 { false, "LD_CXX", OCTAVE_CONF_LD_CXX }, | |
970 { false, "LD_STATIC_FLAG", OCTAVE_CONF_LD_STATIC_FLAG }, | |
971 { false, "LEX", OCTAVE_CONF_LEX }, | |
972 { false, "LEXLIB", OCTAVE_CONF_LEXLIB }, | |
973 { false, "LFLAGS", OCTAVE_CONF_LFLAGS }, | |
974 { false, "LIBCRUFT", OCTAVE_CONF_LIBCRUFT }, | |
975 { false, "LIBEXT", OCTAVE_CONF_LIBEXT }, | |
976 { false, "LIBFLAGS", OCTAVE_CONF_LIBFLAGS }, | |
977 { false, "LIBOCTAVE", OCTAVE_CONF_LIBOCTAVE }, | |
978 { false, "LIBOCTINTERP", OCTAVE_CONF_LIBOCTINTERP }, | |
979 { false, "LIBREADLINE", OCTAVE_CONF_LIBREADLINE }, | |
980 { false, "LIBS", OCTAVE_CONF_LIBS }, | |
981 { false, "LN_S", OCTAVE_CONF_LN_S }, | |
982 { false, "MKOCTFILE_DL_LDFLAGS", OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS }, | |
983 { false, "RANLIB", OCTAVE_CONF_RANLIB }, | |
984 { false, "RDYNAMIC_FLAG", OCTAVE_CONF_RDYNAMIC_FLAG }, | |
985 { false, "RLD_FLAG", OCTAVE_CONF_RLD_FLAG }, | |
986 { false, "SED", OCTAVE_CONF_SED }, | |
987 { false, "SHARED_LIBS", OCTAVE_CONF_SHARED_LIBS }, | |
988 { false, "SHLEXT", OCTAVE_CONF_SHLEXT }, | |
989 { false, "SHLEXT_VER", OCTAVE_CONF_SHLEXT_VER }, | |
990 { false, "SH_LD", OCTAVE_CONF_SH_LD }, | |
991 { false, "SH_LDFLAGS", OCTAVE_CONF_SH_LDFLAGS }, | |
992 { false, "SONAME_FLAGS", OCTAVE_CONF_SONAME_FLAGS }, | |
993 { false, "STATIC_LIBS", OCTAVE_CONF_STATIC_LIBS }, | |
994 { false, "UGLY_DEFS", OCTAVE_CONF_UGLY_DEFS }, | |
995 { false, "USE_64_BIT_IDX_T", OCTAVE_CONF_USE_64_BIT_IDX_T }, | |
996 { false, "XTRA_CFLAGS", OCTAVE_CONF_XTRA_CFLAGS }, | |
997 { false, "XTRA_CXXFLAGS", OCTAVE_CONF_XTRA_CXXFLAGS }, | |
998 { false, "YACC", OCTAVE_CONF_YACC }, | |
999 { false, "YFLAGS", OCTAVE_CONF_YFLAGS }, | |
1000 { false, "api_version", OCTAVE_API_VERSION }, | |
1001 { true, "archlibdir", OCTAVE_ARCHLIBDIR }, | |
1002 { true, "bindir", OCTAVE_BINDIR }, | |
1003 { false, "canonical_host_type", OCTAVE_CANONICAL_HOST_TYPE }, | |
1004 { false, "config_opts", OCTAVE_CONF_config_opts }, | |
1005 { true, "datadir", OCTAVE_DATADIR }, | |
1006 { true, "datarootdir", OCTAVE_DATAROOTDIR }, | |
6276 | 1007 { true, "exec_prefix", OCTAVE_EXEC_PREFIX }, |
6274 | 1008 { true, "fcnfiledir", OCTAVE_FCNFILEDIR }, |
1009 { true, "imagedir", OCTAVE_IMAGEDIR }, | |
1010 { true, "includedir", OCTAVE_INCLUDEDIR }, | |
1011 { true, "infodir", OCTAVE_INFODIR }, | |
6276 | 1012 { true, "infofile", OCTAVE_INFOFILE }, |
6274 | 1013 { true, "libdir", OCTAVE_LIBDIR }, |
1014 { true, "libexecdir", OCTAVE_LIBEXECDIR }, | |
6311 | 1015 { true, "localapiarchlibdir", OCTAVE_LOCALAPIARCHLIBDIR }, |
6274 | 1016 { true, "localapifcnfiledir", OCTAVE_LOCALAPIFCNFILEDIR }, |
1017 { true, "localapioctfiledir", OCTAVE_LOCALAPIOCTFILEDIR }, | |
1018 { true, "localarchlibdir", OCTAVE_LOCALARCHLIBDIR }, | |
1019 { true, "localfcnfiledir", OCTAVE_LOCALFCNFILEDIR }, | |
1020 { true, "localoctfiledir", OCTAVE_LOCALOCTFILEDIR }, | |
1021 { true, "localstartupfiledir", OCTAVE_LOCALSTARTUPFILEDIR }, | |
1022 { true, "localverarchlibdir", OCTAVE_LOCALVERARCHLIBDIR }, | |
1023 { true, "localverfcnfiledir", OCTAVE_LOCALVERFCNFILEDIR }, | |
1024 { true, "localveroctfiledir", OCTAVE_LOCALVEROCTFILEDIR }, | |
1025 { true, "man1dir", OCTAVE_MAN1DIR }, | |
1026 { false, "man1ext", OCTAVE_MAN1EXT }, | |
1027 { true, "mandir", OCTAVE_MANDIR }, | |
1028 { true, "octfiledir", OCTAVE_OCTFILEDIR }, | |
1029 { true, "octincludedir", OCTAVE_OCTINCLUDEDIR }, | |
1030 { true, "octlibdir", OCTAVE_OCTLIBDIR }, | |
6276 | 1031 { true, "prefix", OCTAVE_PREFIX }, |
6274 | 1032 { true, "startupfiledir", OCTAVE_STARTUPFILEDIR }, |
1033 { false, "version", OCTAVE_VERSION }, | |
1034 { false, 0, 0 } | |
4357 | 1035 }; |
1036 | |
1037 if (! initialized) | |
1038 { | |
4675 | 1039 m.assign ("dld", octave_value (octave_supports_dynamic_linking)); |
4357 | 1040 |
4697 | 1041 oct_mach_info::float_format ff = oct_mach_info::native_float_format (); |
1042 m.assign ("float_format", | |
1043 octave_value (oct_mach_info::float_format_as_string (ff))); | |
1044 | |
1045 m.assign ("words_big_endian", | |
1046 octave_value (oct_mach_info::words_big_endian ())); | |
1047 | |
1048 m.assign ("words_little_endian", | |
1049 octave_value (oct_mach_info::words_little_endian ())); | |
1050 | |
4357 | 1051 int i = 0; |
4440 | 1052 |
1053 while (true) | |
4357 | 1054 { |
6274 | 1055 const conf_info_struct& elt = conf_info[i++]; |
1056 | |
1057 const char *key = elt.key; | |
4357 | 1058 |
1059 if (key) | |
6274 | 1060 { |
1061 if (elt.subst_home) | |
1062 m.assign (key, octave_value (subst_octave_home (elt.val))); | |
1063 else | |
1064 m.assign (key, octave_value (elt.val)); | |
1065 } | |
4357 | 1066 else |
1067 break; | |
1068 } | |
1069 | |
4691 | 1070 bool unix_system = true; |
7013 | 1071 bool mac_system = false; |
4691 | 1072 bool windows_system = false; |
1073 | |
1074 #if defined (WIN32) | |
1075 windows_system = true; | |
1076 #if !defined (__CYGWIN__) | |
1077 unix_system = false; | |
1078 #endif | |
1079 #endif | |
1080 | |
7010 | 1081 #if defined (__APPLE__) && defined (__MACH__) |
1082 mac_system = true; | |
1083 #endif | |
1084 | |
4691 | 1085 m.assign ("unix", octave_value (unix_system)); |
7010 | 1086 m.assign ("mac", octave_value (mac_system)); |
4691 | 1087 m.assign ("windows", octave_value (windows_system)); |
1088 | |
4357 | 1089 initialized = true; |
1090 } | |
2162 | 1091 |
2689 | 1092 int nargin = args.length (); |
1093 | |
1094 if (nargin == 1) | |
1095 { | |
3523 | 1096 std::string arg = args(0).string_value (); |
2689 | 1097 |
1098 if (! error_state) | |
4675 | 1099 { |
1100 Cell c = m.contents (arg.c_str ()); | |
5199 | 1101 |
1102 if (c.is_empty ()) | |
1103 error ("octave_config_info: no info for `%s'", arg.c_str ()); | |
1104 else | |
1105 retval = c(0); | |
4675 | 1106 } |
2689 | 1107 } |
1108 else if (nargin == 0) | |
4233 | 1109 retval = m; |
2689 | 1110 else |
5823 | 1111 print_usage (); |
2689 | 1112 |
1113 return retval; | |
2162 | 1114 } |
1115 | |
1683 | 1116 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE) |
2806 | 1117 |
1683 | 1118 int debug_new_delete = 0; |
1119 | |
1120 typedef void (*vfp)(void); | |
1121 extern vfp __new_handler; | |
1122 | |
1123 void * | |
1124 __builtin_new (size_t sz) | |
1125 { | |
1126 void *p; | |
1127 | |
1128 /* malloc (0) is unpredictable; avoid it. */ | |
1129 if (sz == 0) | |
1130 sz = 1; | |
2800 | 1131 p = malloc (sz); |
1683 | 1132 while (p == 0) |
1133 { | |
1134 (*__new_handler) (); | |
2800 | 1135 p = malloc (sz); |
1683 | 1136 } |
1137 | |
1138 if (debug_new_delete) | |
5629 | 1139 std::cerr << "__builtin_new: " << p << std::endl; |
1683 | 1140 |
1141 return p; | |
1142 } | |
1143 | |
1144 void | |
1145 __builtin_delete (void *ptr) | |
1146 { | |
1147 if (debug_new_delete) | |
5629 | 1148 std::cerr << "__builtin_delete: " << ptr << std::endl; |
1683 | 1149 |
1150 if (ptr) | |
1151 free (ptr); | |
1152 } | |
2806 | 1153 |
1683 | 1154 #endif |
1155 | |
1156 /* | |
1157 ;;; Local Variables: *** | |
1158 ;;; mode: C++ *** | |
1159 ;;; End: *** | |
1160 */ |