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