Mercurial > octave
annotate libinterp/interpfcn/toplev.cc @ 16317:ce5231908ea2
* toplev.cc: Include sys/select.h.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 15 Mar 2013 04:23:25 -0400 |
parents | 6ce905b89cee |
children | bef822a80ffb |
rev | line source |
---|---|
1683 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14073
diff
changeset
|
3 Copyright (C) 1995-2012 John W. Eaton |
1683 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1683 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1683 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <cassert> | |
4489 | 28 #include <cerrno> |
1683 | 29 #include <cstdlib> |
30 #include <cstring> | |
4221 | 31 #include <new> |
1683 | 32 |
3503 | 33 #include <fstream> |
34 #include <iostream> | |
5765 | 35 #include <sstream> |
1728 | 36 #include <string> |
37 | |
16317
ce5231908ea2
* toplev.cc: Include sys/select.h.
John W. Eaton <jwe@octave.org>
parents:
16292
diff
changeset
|
38 #include <sys/select.h> |
1683 | 39 #include <sys/types.h> |
40 #include <unistd.h> | |
41 | |
2926 | 42 #include "cmd-edit.h" |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12846
diff
changeset
|
43 #include "cmd-hist.h" |
2926 | 44 #include "file-ops.h" |
1683 | 45 #include "lo-error.h" |
2370 | 46 #include "lo-mappers.h" |
3020 | 47 #include "oct-env.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
48 #include "oct-locbuf.h" |
4153 | 49 #include "quit.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
50 #include "singleton-cleanup.h" |
1755 | 51 #include "str-vec.h" |
1683 | 52 |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
53 #include "defaults.h" |
1683 | 54 #include "defun.h" |
55 #include "error.h" | |
56 #include "file-io.h" | |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
57 #include "graphics.h" |
1683 | 58 #include "input.h" |
59 #include "lex.h" | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
60 #include "oct-conf.h" |
16170
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
16164
diff
changeset
|
61 #include "oct-conf-features.h" |
1742 | 62 #include "oct-hist.h" |
2162 | 63 #include "oct-map.h" |
2862 | 64 #include "oct-obj.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
65 #include "ov.h" |
1683 | 66 #include "pager.h" |
67 #include "parse.h" | |
68 #include "pathsearch.h" | |
69 #include "procstream.h" | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8581
diff
changeset
|
70 #include "pt-eval.h" |
2985 | 71 #include "pt-jump.h" |
2982 | 72 #include "pt-stmt.h" |
1683 | 73 #include "sighandlers.h" |
74 #include "sysdep.h" | |
2693 | 75 #include "syswait.h" |
1750 | 76 #include "toplev.h" |
1683 | 77 #include "unwind-prot.h" |
78 #include "utils.h" | |
79 #include "variables.h" | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
80 #include "version.h" |
1683 | 81 |
15756
ea1a1fb00744
Make the path to the shell interpreter configuable
Mike Miller <mtmiller@ieee.org>
parents:
15596
diff
changeset
|
82 #ifndef SHELL_PATH |
ea1a1fb00744
Make the path to the shell interpreter configuable
Mike Miller <mtmiller@ieee.org>
parents:
15596
diff
changeset
|
83 #define SHELL_PATH "/bin/sh" |
ea1a1fb00744
Make the path to the shell interpreter configuable
Mike Miller <mtmiller@ieee.org>
parents:
15596
diff
changeset
|
84 #endif |
ea1a1fb00744
Make the path to the shell interpreter configuable
Mike Miller <mtmiller@ieee.org>
parents:
15596
diff
changeset
|
85 |
9217
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9187
diff
changeset
|
86 void (*octave_exit) (int) = ::exit; |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9187
diff
changeset
|
87 |
9255
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
88 // TRUE means the quit() call is allowed. |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
89 bool quit_allowed = true; |
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
90 |
3020 | 91 // TRUE means we are exiting via the builtin exit or quit functions. |
9383 | 92 bool quitting_gracefully = false; |
93 // This stores the exit status. | |
94 int exit_status = 0; | |
1683 | 95 |
4217 | 96 // TRUE means we are ready to interpret commands, but not everything |
97 // is ready for interactive use. | |
98 bool octave_interpreter_ready = false; | |
99 | |
4172 | 100 // TRUE means we've processed all the init code and we are good to go. |
101 bool octave_initialized = false; | |
102 | |
5743 | 103 octave_call_stack *octave_call_stack::instance = 0; |
104 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
105 void |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
106 octave_call_stack::create_instance (void) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
107 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
108 instance = new octave_call_stack (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
109 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
110 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
111 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
112 instance->do_push (0, symbol_table::top_scope (), 0); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
113 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
114 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
115 } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
116 } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13981
diff
changeset
|
117 |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
118 int |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
119 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
|
120 { |
9484
bbe033dcfe13
make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents:
9483
diff
changeset
|
121 tree_statement *stmt = do_current_statement (); |
7734
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 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
|
124 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
125 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
126 int |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
127 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
|
128 { |
9484
bbe033dcfe13
make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents:
9483
diff
changeset
|
129 tree_statement *stmt = do_current_statement (); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
130 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
131 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
|
132 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
133 |
7877 | 134 int |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
135 octave_call_stack::do_caller_user_code_line (void) const |
7877 | 136 { |
137 int retval = -1; | |
138 | |
7890 | 139 const_iterator p = cs.end (); |
140 | |
141 while (p != cs.begin ()) | |
7877 | 142 { |
7890 | 143 const call_stack_elt& elt = *(--p); |
7877 | 144 |
145 octave_function *f = elt.fcn; | |
146 | |
147 if (f && f->is_user_code ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
148 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
149 tree_statement *stmt = elt.stmt; |
7877 | 150 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
151 if (stmt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
152 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
153 retval = stmt->line (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
154 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
155 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
156 } |
7877 | 157 } |
158 | |
159 return retval; | |
160 } | |
161 | |
162 int | |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
163 octave_call_stack::do_caller_user_code_column (void) const |
7877 | 164 { |
165 int retval = -1; | |
166 | |
7890 | 167 const_iterator p = cs.end (); |
168 | |
169 while (p != cs.begin ()) | |
7877 | 170 { |
7890 | 171 const call_stack_elt& elt = *(--p); |
7877 | 172 |
173 octave_function *f = elt.fcn; | |
174 | |
175 if (f && f->is_user_code ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
176 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
177 tree_statement *stmt = elt.stmt; |
7877 | 178 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
179 if (stmt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
180 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
181 retval = stmt->column (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
182 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
183 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
184 } |
7877 | 185 } |
186 | |
187 return retval; | |
188 } | |
189 | |
7901 | 190 size_t |
191 octave_call_stack::do_num_user_code_frames (octave_idx_type& curr_user_frame) const | |
192 { | |
193 size_t retval = 0; | |
194 | |
195 curr_user_frame = 0; | |
196 | |
197 // Look for the caller of dbstack. | |
198 size_t frame = cs[curr_frame].prev; | |
199 | |
200 bool found = false; | |
201 | |
202 size_t k = cs.size (); | |
203 | |
204 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++) | |
205 { | |
206 octave_function *f = (*p).fcn; | |
207 | |
208 if (--k == frame) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
209 found = true; |
7901 | 210 |
211 if (f && f->is_user_code ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
212 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
213 if (! found) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
214 curr_user_frame++; |
7901 | 215 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
216 retval++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
217 } |
7901 | 218 } |
219 | |
220 // We counted how many user frames were not the one, in reverse. | |
221 // Now set curr_user_frame to be the index in the other direction. | |
222 curr_user_frame = retval - curr_user_frame - 1; | |
223 | |
224 return retval; | |
225 } | |
226 | |
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
|
227 octave_user_code * |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7913
diff
changeset
|
228 octave_call_stack::do_caller_user_code (size_t nskip) const |
5744 | 229 { |
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
|
230 octave_user_code *retval = 0; |
5744 | 231 |
7890 | 232 const_iterator p = cs.end (); |
233 | |
234 while (p != cs.begin ()) | |
5744 | 235 { |
7890 | 236 const call_stack_elt& elt = *(--p); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
237 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
238 octave_function *f = elt.fcn; |
5744 | 239 |
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
|
240 if (f && f->is_user_code ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
241 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
242 if (nskip > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
243 nskip--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
244 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
245 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
246 retval = dynamic_cast<octave_user_code *> (f); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
247 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
248 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
249 } |
5744 | 250 } |
251 | |
252 return retval; | |
253 } | |
254 | |
10767
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
255 // Use static fields for the best efficiency. |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
256 // NOTE: C++0x will allow these two to be merged into one. |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
257 static const char *bt_fieldnames[] = { "file", "name", "line", |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
258 "column", "scope", "context", 0 }; |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
259 static const octave_fields bt_fields (bt_fieldnames); |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
260 |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
261 octave_map |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
262 octave_call_stack::empty_backtrace (void) |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
263 { |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
264 return octave_map (dim_vector (0, 1), bt_fields); |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
265 } |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
266 |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
267 octave_map |
7901 | 268 octave_call_stack::do_backtrace (size_t nskip, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
269 octave_idx_type& curr_user_frame) const |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
270 { |
7901 | 271 size_t user_code_frames = do_num_user_code_frames (curr_user_frame); |
272 | |
273 size_t nframes = nskip <= user_code_frames ? user_code_frames - nskip : 0; | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
274 |
7901 | 275 // Our list is reversed. |
276 curr_user_frame = nframes - curr_user_frame - 1; | |
277 | |
10767
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
278 octave_map retval (dim_vector (nframes, 1), bt_fields); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
279 |
10767
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
280 Cell& file = retval.contents (0); |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
281 Cell& name = retval.contents (1); |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
282 Cell& line = retval.contents (2); |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
283 Cell& column = retval.contents (3); |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
284 Cell& scope = retval.contents (4); |
2b041d3995a3
modernize some map usage on toplev.cc and error.cc
Jaroslav Hajek <highegg@gmail.com>
parents:
10411
diff
changeset
|
285 Cell& context = retval.contents (5); |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
286 |
7901 | 287 if (nframes > 0) |
288 { | |
289 int k = 0; | |
290 | |
291 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
292 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
293 const call_stack_elt& elt = *p; |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
294 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
295 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
|
296 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
297 if (f && f->is_user_code ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
298 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
299 if (nskip > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
300 nskip--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
301 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
302 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
303 scope(k) = elt.scope; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
304 context(k) = elt.context; |
7901 | 305 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
306 file(k) = f->fcn_file_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
307 std::string parent_fcn_name = f->parent_fcn_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
308 if (parent_fcn_name == std::string ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
309 name(k) = f->name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
310 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
311 name(k) = f->parent_fcn_name () + Vfilemarker + f->name (); |
7901 | 312 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
313 tree_statement *stmt = elt.stmt; |
7901 | 314 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
315 if (stmt) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
316 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
317 line(k) = stmt->line (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
318 column(k) = stmt->column (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
319 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
320 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
321 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
322 line(k) = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
323 column(k) = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
324 } |
7901 | 325 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
326 k++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
327 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
328 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
329 } |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
330 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
331 |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
332 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
|
333 } |
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7733
diff
changeset
|
334 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
335 bool |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
336 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
|
337 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
338 bool retval = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
339 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
340 if (n < cs.size ()) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
341 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
342 retval = true; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
343 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
344 curr_frame = n; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
345 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
346 const call_stack_elt& elt = cs[n]; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
347 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
348 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
|
349 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
350 if (verbose) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
351 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
352 octave_function *f = elt.fcn; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
353 std::string nm = f ? f->name () : std::string ("<unknown>"); |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
354 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
355 tree_statement *s = elt.stmt; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
356 int l = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
357 int c = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
358 if (s) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
359 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
360 l = s->line (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
361 c = s->column (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
362 } |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
363 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
364 octave_stdout << "stopped in " << nm |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
365 << " at line " << l << " column " << c |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
366 << " (" << elt.scope << "[" << elt.context << "])" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
367 << std::endl; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
368 } |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
369 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
370 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
371 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
372 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
373 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
374 bool |
7901 | 375 octave_call_stack::do_goto_frame_relative (int nskip, bool verbose) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
376 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
377 bool retval = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
378 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
379 int incr = 0; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
380 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
381 if (nskip < 0) |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
382 incr = -1; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
383 else if (nskip > 0) |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
384 incr = 1; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
385 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
386 // Start looking with the caller of dbup/dbdown/keyboard. |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
387 size_t frame = cs[curr_frame].prev; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
388 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
389 while (true) |
7890 | 390 { |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
391 if ((incr < 0 && frame == 0) || (incr > 0 && frame == cs.size () - 1)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
392 break; |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
393 |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
394 frame += incr; |
7901 | 395 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
396 const call_stack_elt& elt = cs[frame]; |
7901 | 397 |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
398 octave_function *f = elt.fcn; |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
399 |
9990
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
400 if (frame == 0 || (f && f->is_user_code ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
401 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
402 if (nskip > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
403 nskip--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
404 else if (nskip < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
405 nskip++; |
7901 | 406 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
407 if (nskip == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
408 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
409 curr_frame = frame; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
410 cs[cs.size () - 1].prev = curr_frame; |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
411 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
412 symbol_table::set_scope_and_context (elt.scope, elt.context); |
7901 | 413 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
414 if (verbose) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
415 { |
9990
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
416 std::ostringstream buf; |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
417 |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
418 if (f) |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
419 { |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
420 tree_statement *s = elt.stmt; |
7901 | 421 |
9990
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
422 int l = s ? s->line () : -1; |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
423 |
10839 | 424 buf << "stopped in " << f->name () |
425 << " at line " << l << std::endl; | |
9990
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
426 } |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
427 else |
2b008f1d3794
octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents:
9981
diff
changeset
|
428 buf << "at top level" << std::endl; |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
429 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
430 octave_stdout << buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
431 } |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
432 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
433 retval = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
434 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
435 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
436 } |
7901 | 437 |
438 // There is no need to set scope and context here. That will | |
9483
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
439 // happen when the dbup/dbdown/keyboard frame is popped and we |
25c2e92ee03c
correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents:
9452
diff
changeset
|
440 // jump to the new "prev" frame set above. |
7890 | 441 } |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
442 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
443 return retval; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
444 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
445 |
5744 | 446 void |
7901 | 447 octave_call_stack::do_goto_caller_frame (void) |
448 { | |
449 size_t frame = curr_frame; | |
450 | |
451 bool skipped = false; | |
452 | |
453 while (frame != 0) | |
454 { | |
455 frame = cs[frame].prev; | |
456 | |
457 const call_stack_elt& elt = cs[frame]; | |
458 | |
459 octave_function *f = elt.fcn; | |
460 | |
8581
6adcafc70c32
toplev.cc (octave_call_stack::do_goto_caller_frame): allow caller frame to be base frame
John W. Eaton <jwe@octave.org>
parents:
8574
diff
changeset
|
461 if (frame == 0 || (f && f->is_user_code ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
462 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
463 if (! skipped) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
464 // We found the current user code frame, so skip it. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
465 skipped = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
466 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
467 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
468 // We found the caller user code frame. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
469 call_stack_elt tmp (elt); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
470 tmp.prev = curr_frame; |
7901 | 471 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
472 curr_frame = cs.size (); |
7901 | 473 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
474 cs.push_back (tmp); |
7901 | 475 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
476 symbol_table::set_scope_and_context (tmp.scope, tmp.context); |
7901 | 477 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
478 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
479 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
480 } |
7901 | 481 } |
482 } | |
483 | |
484 void | |
485 octave_call_stack::do_goto_base_frame (void) | |
486 { | |
487 call_stack_elt tmp (cs[0]); | |
488 tmp.prev = curr_frame; | |
489 | |
490 curr_frame = cs.size (); | |
491 | |
492 cs.push_back (tmp); | |
493 | |
494 symbol_table::set_scope_and_context (tmp.scope, tmp.context); | |
495 } | |
496 | |
497 void | |
8013
b3e667f1ab4c
call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents:
8011
diff
changeset
|
498 octave_call_stack::do_backtrace_error_message (void) const |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
499 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
500 if (error_state > 0) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
501 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
502 error_state = -1; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
503 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
504 error ("called from:"); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
505 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
506 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
507 if (! cs.empty ()) |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
508 { |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
509 const call_stack_elt& elt = cs.back (); |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
510 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
511 octave_function *fcn = elt.fcn; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
512 tree_statement *stmt = elt.stmt; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
513 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
514 std::string fcn_name = "?unknown?"; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
515 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
516 if (fcn) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
517 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
518 fcn_name = fcn->fcn_file_name (); |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
519 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
520 if (fcn_name.empty ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
521 fcn_name = fcn->name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
522 } |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
523 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
524 int line = stmt ? stmt->line () : -1; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
525 int column = stmt ? stmt->column () : -1; |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
526 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
527 error (" %s at line %d, column %d", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
528 fcn_name.c_str (), line, column); |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
529 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
530 } |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
531 |
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7968
diff
changeset
|
532 void |
4180 | 533 recover_from_exception (void) |
534 { | |
535 can_interrupt = true; | |
4182 | 536 octave_interrupt_immediately = 0; |
4180 | 537 octave_interrupt_state = 0; |
5142 | 538 octave_signal_caught = 0; |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7409
diff
changeset
|
539 octave_exception_state = octave_no_exception; |
4180 | 540 octave_restore_signal_mask (); |
541 octave_catch_interrupts (); | |
542 } | |
543 | |
1907 | 544 int |
5189 | 545 main_loop (void) |
1907 | 546 { |
2016 | 547 octave_save_signal_mask (); |
548 | |
3020 | 549 can_interrupt = true; |
1907 | 550 |
5142 | 551 octave_signal_hook = octave_signal_handler; |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
552 octave_interrupt_hook = 0; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
553 octave_bad_alloc_hook = 0; |
4429 | 554 |
2554 | 555 octave_catch_interrupts (); |
1907 | 556 |
4172 | 557 octave_initialized = true; |
558 | |
1907 | 559 // The big loop. |
560 | |
16151 | 561 unwind_protect frame; |
562 | |
563 // octave_parser constructor sets this for us. | |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
564 frame.protect_var (LEXER); |
16151 | 565 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
566 octave_parser parser; |
16151 | 567 |
4153 | 568 int retval = 0; |
1907 | 569 do |
570 { | |
4180 | 571 try |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
572 { |
16151 | 573 unwind_protect inner_frame; |
9260
9c2349a51218
properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents:
9255
diff
changeset
|
574 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
575 reset_error_handler (); |
4318 | 576 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
577 parser.reset (); |
2620 | 578 |
10186
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
579 if (symbol_table::at_top_level ()) |
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
580 tree_evaluator::reset_debug_state (); |
095a1e670e68
make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
581 |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
582 retval = parser.run (); |
2620 | 583 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
584 if (retval == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
585 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
586 if (parser.stmt_list) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
587 { |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
588 parser.stmt_list->accept (*current_evaluator); |
3883 | 589 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
590 octave_quit (); |
4171 | 591 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
592 if (! (interactive || forced_interactive)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
593 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
594 bool quit = (tree_return_command::returning |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
595 || tree_break_command::breaking); |
4153 | 596 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
597 if (tree_return_command::returning) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
598 tree_return_command::returning = 0; |
4153 | 599 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
600 if (tree_break_command::breaking) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
601 tree_break_command::breaking--; |
4153 | 602 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
603 if (quit) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
604 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
605 } |
4153 | 606 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
607 if (error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
608 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
609 if (! (interactive || forced_interactive)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
610 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
611 // We should exit with a non-zero status. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
612 retval = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
613 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
614 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
615 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
616 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
617 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
618 if (octave_completion_matches_called) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
619 octave_completion_matches_called = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
620 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
621 command_editor::increment_current_command_number (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
622 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
623 } |
16288
fe3b9a51e625
rename curr_lexer, curr_parser, CURR_LEXER
John W. Eaton <jwe@octave.org>
parents:
16287
diff
changeset
|
624 else if (parser.lexer.end_of_input) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
625 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
626 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
627 } |
4182 | 628 catch (octave_interrupt_exception) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
629 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
630 recover_from_exception (); |
9383 | 631 octave_stdout << "\n"; |
632 if (quitting_gracefully) | |
633 { | |
634 clean_up_and_exit (exit_status); | |
635 break; // If user has overriden the exit func. | |
636 } | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
637 } |
8704
236ff50db90f
load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
638 catch (octave_execution_exception) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
639 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
640 recover_from_exception (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
641 std::cerr |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
642 << "error: unhandled execution exception -- trying to return to prompt" |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
643 << std::endl; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
644 } |
4181 | 645 catch (std::bad_alloc) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
646 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
647 recover_from_exception (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
648 std::cerr |
15244
c16357c4bdbb
attempt to display location of out of memory errors in interpreted code
John W. Eaton <jwe@octave.org>
parents:
15221
diff
changeset
|
649 << "error: out of memory -- trying to return to prompt" |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
650 << std::endl; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
651 } |
1907 | 652 } |
653 while (retval == 0); | |
654 | |
655 return retval; | |
656 } | |
657 | |
1683 | 658 // Fix up things before exiting. |
659 | |
660 void | |
3162 | 661 clean_up_and_exit (int retval) |
662 { | |
3216 | 663 do_octave_atexit (); |
1683 | 664 |
9217
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9187
diff
changeset
|
665 if (octave_exit) |
ee7cf4d963f3
smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents:
9187
diff
changeset
|
666 (*octave_exit) (retval == EOF ? 0 : retval); |
1683 | 667 } |
668 | |
11023
cb62c7401ea2
toplev.cc (Fquit): allow any number of output paramters
John W. Eaton <jwe@octave.org>
parents:
10890
diff
changeset
|
669 DEFUN (quit, args, , |
3332 | 670 "-*- texinfo -*-\n\ |
10840 | 671 @deftypefn {Built-in Function} {} exit (@var{status})\n\ |
3332 | 672 @deftypefnx {Built-in Function} {} quit (@var{status})\n\ |
673 Exit the current Octave session. If the optional integer value\n\ | |
674 @var{status} is supplied, pass that value to the operating system as the\n\ | |
6615 | 675 Octave's exit status. The default value is zero.\n\ |
3333 | 676 @end deftypefn") |
1683 | 677 { |
2086 | 678 octave_value_list retval; |
2068 | 679 |
9255
1c2d2c9f4a8d
don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents:
9217
diff
changeset
|
680 if (! quit_allowed) |
11590
4ced6b90fffb
style fixes for warning and error messages in source files
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
681 error ("quit: not supported in embedded mode"); |
11023
cb62c7401ea2
toplev.cc (Fquit): allow any number of output paramters
John W. Eaton <jwe@octave.org>
parents:
10890
diff
changeset
|
682 else |
2068 | 683 { |
3180 | 684 if (args.length () > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
685 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
686 int tmp = args(0).nint_value (); |
1683 | 687 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
688 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
689 exit_status = tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
690 } |
3180 | 691 |
9383 | 692 if (! error_state) |
693 { | |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
13973
diff
changeset
|
694 // Instead of simply calling exit, we simulate an interrupt |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
13973
diff
changeset
|
695 // with a request to exit cleanly so that no matter where the |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
13973
diff
changeset
|
696 // call to quit occurs, we will run the unwind_protect stack, |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
13973
diff
changeset
|
697 // clear the OCTAVE_LOCAL_BUFFER allocations, etc. before |
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
13973
diff
changeset
|
698 // exiting. |
9383 | 699 |
13981
5f8bc2f145f5
clean up octave_chunk_buffer storage before exit
John W. Eaton <jwe@octave.org>
parents:
13973
diff
changeset
|
700 quitting_gracefully = true; |
9383 | 701 |
702 octave_interrupt_state = -1; | |
703 | |
704 octave_throw_interrupt_exception (); | |
705 } | |
2068 | 706 } |
707 | |
1683 | 708 return retval; |
709 } | |
710 | |
711 DEFALIAS (exit, quit); | |
712 | |
1957 | 713 DEFUN (warranty, , , |
3446 | 714 "-*- texinfo -*-\n\ |
715 @deftypefn {Built-in Function} {} warranty ()\n\ | |
716 Describe the conditions for copying and distributing Octave.\n\ | |
717 @end deftypefn") | |
1683 | 718 { |
2086 | 719 octave_value_list retval; |
1683 | 720 |
3922 | 721 octave_stdout << "\n" \ |
722 OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\ | |
723 \n\ | |
11104 | 724 GNU Octave free software; you can redistribute it and/or modify\n\ |
1683 | 725 it under the terms of the GNU General Public License as published by\n\ |
7016 | 726 the Free Software Foundation; either version 3 of the License, or\n\ |
1683 | 727 (at your option) any later version.\n\ |
728 \n\ | |
11104 | 729 GNU Octave is distributed in the hope that it will be useful,\n\ |
1683 | 730 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ |
731 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ | |
732 GNU General Public License for more details.\n\ | |
733 \n\ | |
734 You should have received a copy of the GNU General Public License\n\ | |
7016 | 735 along with this program. If not, see <http://www.gnu.org/licenses/>.\n\ |
1683 | 736 \n"; |
737 | |
738 return retval; | |
739 } | |
740 | |
741 // Execute a shell command. | |
742 | |
6316 | 743 static int |
744 wait_for_input (int fid) | |
745 { | |
746 int retval = -1; | |
747 | |
748 #if defined (HAVE_SELECT) | |
749 if (fid >= 0) | |
750 { | |
751 fd_set set; | |
752 | |
753 FD_ZERO (&set); | |
754 FD_SET (fid, &set); | |
755 | |
10411 | 756 retval = gnulib::select (FD_SETSIZE, &set, 0, 0, 0); |
6316 | 757 } |
758 #else | |
759 retval = 1; | |
760 #endif | |
761 | |
762 return retval; | |
763 } | |
764 | |
2086 | 765 static octave_value_list |
3523 | 766 run_command_and_return_output (const std::string& cmd_str) |
2083 | 767 { |
2086 | 768 octave_value_list retval; |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
769 unwind_protect frame; |
2083 | 770 |
771 iprocstream *cmd = new iprocstream (cmd_str.c_str ()); | |
772 | |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
773 frame.add_delete (cmd); |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
774 frame.add_fcn (octave_child_list::remove, cmd->pid ()); |
3060 | 775 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
776 if (*cmd) |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
777 { |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
778 int fid = cmd->file_number (); |
2095 | 779 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
780 std::ostringstream output_buf; |
4494 | 781 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
782 char ch; |
3147 | 783 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
784 for (;;) |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
785 { |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
786 if (cmd->get (ch)) |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
787 output_buf.put (ch); |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
788 else |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
789 { |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
790 if (! cmd->eof () && errno == EAGAIN) |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
791 { |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
792 cmd->clear (); |
3147 | 793 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
794 if (wait_for_input (fid) != 1) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
795 break; |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
796 } |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
797 else |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
798 break; |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
799 } |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
800 } |
3147 | 801 |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
802 int cmd_status = cmd->close (); |
2083 | 803 |
15221
a83b7b2f95ee
avoid C-style cast warnings from GCC for wait-related macros
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
804 if (octave_wait::ifexited (cmd_status)) |
a83b7b2f95ee
avoid C-style cast warnings from GCC for wait-related macros
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
805 cmd_status = octave_wait::exitstatus (cmd_status); |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
806 else |
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
807 cmd_status = 127; |
2083 | 808 |
14018
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
809 retval(1) = output_buf.str (); |
10212
56f7734f5448
fix process creation failure handling in system()
Jaroslav Hajek <highegg@gmail.com>
parents:
10186
diff
changeset
|
810 retval(0) = cmd_status; |
2083 | 811 } |
812 else | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14156
diff
changeset
|
813 error ("unable to start subprocess for '%s'", cmd_str.c_str ()); |
2083 | 814 |
815 return retval; | |
816 } | |
817 | |
5285 | 818 enum system_exec_type { et_sync, et_async }; |
819 | |
1957 | 820 DEFUN (system, args, nargout, |
3301 | 821 "-*- texinfo -*-\n\ |
14018
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
822 @deftypefn {Built-in Function} {} system (\"@var{string}\")\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
823 @deftypefnx {Built-in Function} {} system (\"@var{string}\", @var{return_output})\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
824 @deftypefnx {Built-in Function} {} system (\"@var{string}\", @var{return_output}, @var{type})\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
825 @deftypefnx {Built-in Function} {[@var{status}, @var{output}] =} system (@dots{})\n\ |
11123
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
826 Execute a shell command specified by @var{string}.\n\ |
14018
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
827 If the optional argument @var{type} is \"async\", the process\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
828 is started in the background and the process ID of the child process\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
829 is returned immediately. Otherwise, the child process is started and\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
830 Octave waits until it exits. If the @var{type} argument is omitted, it\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
831 defaults to the value \"sync\".\n\ |
2083 | 832 \n\ |
14018
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
833 If @var{system} is called with one or more output arguments, or if the\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
834 optional argument @var{return_output} is true and the subprocess is started\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
835 synchronously, then the output from the command is returned as a variable. \n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
836 Otherwise, if the subprocess is executed synchronously, its output is sent\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
837 to the standard output. To send the output of a command executed with\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
838 @code{system} through the pager, use a command like\n\ |
2321 | 839 \n\ |
3301 | 840 @example\n\ |
14018
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
841 @group\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
842 [output, text] = system (\"cmd\");\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
843 disp (text);\n\ |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
844 @end group\n\ |
3301 | 845 @end example\n\ |
2321 | 846 \n\ |
3301 | 847 @noindent\n\ |
2321 | 848 or\n\ |
849 \n\ | |
3301 | 850 @example\n\ |
14018
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
851 printf (\"%s\\n\", nthargout (2, \"system\", \"cmd\"));\n\ |
3301 | 852 @end example\n\ |
853 \n\ | |
5659 | 854 The @code{system} function can return two values. The first is the\n\ |
855 exit status of the command and the second is any output from the\n\ | |
856 command that was written to the standard output stream. For example,\n\ | |
3301 | 857 \n\ |
858 @example\n\ | |
5717 | 859 [status, output] = system (\"echo foo; exit 2\");\n\ |
3301 | 860 @end example\n\ |
861 \n\ | |
862 @noindent\n\ | |
863 will set the variable @code{output} to the string @samp{foo}, and the\n\ | |
864 variable @code{status} to the integer @samp{2}.\n\ | |
11123
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
865 \n\ |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
866 For commands run asynchronously, @var{status} is the process id of the\n\ |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
867 command shell that is started to run the command.\n\ |
14018
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
868 @seealso{unix, dos}\n\ |
3301 | 869 @end deftypefn") |
1683 | 870 { |
2086 | 871 octave_value_list retval; |
1683 | 872 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9990
diff
changeset
|
873 unwind_protect frame; |
3834 | 874 |
1683 | 875 int nargin = args.length (); |
876 | |
2083 | 877 if (nargin > 0 && nargin < 4) |
1683 | 878 { |
11123
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
879 bool return_output = (nargin == 1 && nargout > 1); |
2083 | 880 |
5285 | 881 system_exec_type type = et_sync; |
2083 | 882 |
11123
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
883 if (nargin == 3) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
884 { |
11123
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
885 std::string type_str = args(2).string_value (); |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
886 |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
887 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
888 { |
11123
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
889 if (type_str == "sync") |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
890 type = et_sync; |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
891 else if (type_str == "async") |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
892 type = et_async; |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
893 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
894 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12208
diff
changeset
|
895 error ("system: TYPE must be \"sync\" or \"async\""); |
11123
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
896 return retval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
897 } |
11123
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
898 } |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
899 else |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
900 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12208
diff
changeset
|
901 error ("system: TYPE must be a character string"); |
11123
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
902 return retval; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
903 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
904 } |
11123
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
905 |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
906 if (nargin > 1) |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
907 { |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
908 return_output = args(1).is_true (); |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
909 |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
910 if (error_state) |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
911 { |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12208
diff
changeset
|
912 error ("system: RETURN_OUTPUT must be boolean value true or false"); |
11123
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
913 return retval; |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
914 } |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
915 } |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
916 |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
917 if (return_output && type == et_async) |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
918 { |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
919 error ("system: can't return output from commands run asynchronously"); |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
920 return retval; |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
921 } |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
922 |
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
923 std::string cmd_str = args(0).string_value (); |
1683 | 924 |
2083 | 925 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
926 { |
7104 | 927 #if defined (__WIN32__) && ! defined (__CYGWIN__) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
928 // Work around weird double-quote handling on Windows systems. |
7104 | 929 if (type == et_sync) |
930 cmd_str = "\"" + cmd_str + "\""; | |
931 #endif | |
932 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
933 if (type == et_async) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
934 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
935 // FIXME -- maybe this should go in sysdep.cc? |
4086 | 936 #ifdef HAVE_FORK |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
937 pid_t pid = fork (); |
2083 | 938 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
939 if (pid < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
940 error ("system: fork failed -- can't create child process"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
941 else if (pid == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
942 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
943 // FIXME -- should probably replace this |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
944 // call with something portable. |
3273 | 945 |
15756
ea1a1fb00744
Make the path to the shell interpreter configuable
Mike Miller <mtmiller@ieee.org>
parents:
15596
diff
changeset
|
946 execl (SHELL_PATH, "sh", "-c", cmd_str.c_str (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
947 static_cast<void *> (0)); |
3273 | 948 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
949 panic_impossible (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
950 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
951 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
952 retval(0) = pid; |
6222 | 953 #elif defined (__WIN32__) |
954 STARTUPINFO si; | |
955 PROCESS_INFORMATION pi; | |
956 ZeroMemory (&si, sizeof (si)); | |
957 ZeroMemory (&pi, sizeof (pi)); | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
958 OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length ()+1); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
959 strcpy (xcmd_str, cmd_str.c_str ()); |
6222 | 960 |
961 if (! CreateProcess (0, xcmd_str, 0, 0, FALSE, 0, 0, 0, &si, &pi)) | |
962 error ("system: CreateProcess failed -- can't create child process"); | |
963 else | |
964 { | |
965 retval(0) = pi.dwProcessId; | |
966 CloseHandle (pi.hProcess); | |
967 CloseHandle (pi.hThread); | |
968 } | |
4086 | 969 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
970 error ("asynchronous system calls are not supported"); |
4086 | 971 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
972 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
973 else if (return_output) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
974 retval = run_command_and_return_output (cmd_str); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
975 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
976 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
977 int status = system (cmd_str.c_str ()); |
2321 | 978 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
979 // The value in status is as returned by waitpid. If |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
980 // the process exited normally, extract the actual exit |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
981 // status of the command. Otherwise, return 127 as a |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
982 // failure code. |
2321 | 983 |
15221
a83b7b2f95ee
avoid C-style cast warnings from GCC for wait-related macros
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
984 if (octave_wait::ifexited (status)) |
a83b7b2f95ee
avoid C-style cast warnings from GCC for wait-related macros
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
985 status = octave_wait::exitstatus (status); |
2321 | 986 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
987 retval(0) = status; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
988 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
989 } |
11123
fbec4b3be59f
toplev.cc (Fsystem): allow optional return_output and type arguments to be specified independently
John W. Eaton <jwe@octave.org>
parents:
11104
diff
changeset
|
990 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12208
diff
changeset
|
991 error ("system: expecting string as first argument"); |
1683 | 992 } |
993 else | |
5823 | 994 print_usage (); |
1683 | 995 |
996 return retval; | |
997 } | |
998 | |
12846
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
999 /* |
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1000 %!test |
14018
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
1001 %! cmd = ls_command (); |
12846
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1002 %! [status, output] = system (cmd); |
14018
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
1003 %! assert (status, 0); |
12846
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1004 %! assert (ischar (output)); |
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1005 %! assert (! isempty (output)); |
14018
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
1006 |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
1007 %!error system () |
5d5685216876
Deprecate shell_cmd function and update system, dos, unix commands
Rik <octave@nomad.inbox5.com>
parents:
14016
diff
changeset
|
1008 %!error system (1, 2, 3) |
12846
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1009 */ |
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1010 |
5775 | 1011 // FIXME -- this should really be static, but that causes |
2614 | 1012 // problems on some systems. |
6680 | 1013 std::list<std::string> octave_atexit_functions; |
2077 | 1014 |
1015 void | |
1016 do_octave_atexit (void) | |
1017 { | |
3216 | 1018 static bool deja_vu = false; |
1019 | |
2077 | 1020 while (! octave_atexit_functions.empty ()) |
1021 { | |
6680 | 1022 std::string fcn = octave_atexit_functions.front (); |
4214 | 1023 |
6680 | 1024 octave_atexit_functions.pop_front (); |
2077 | 1025 |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
1026 OCTAVE_SAFE_CALL (reset_error_handler, ()); |
5237 | 1027 |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
1028 OCTAVE_SAFE_CALL (feval, (fcn, octave_value_list (), 0)); |
3215 | 1029 |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
1030 OCTAVE_SAFE_CALL (flush_octave_stdout, ()); |
2077 | 1031 } |
3216 | 1032 |
1033 if (! deja_vu) | |
1034 { | |
1035 deja_vu = true; | |
1036 | |
6068 | 1037 // Do this explicitly so that destructors for mex file objects |
1038 // are called, so that functions registered with mexAtExit are | |
1039 // called. | |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
1040 OCTAVE_SAFE_CALL (clear_mex_functions, ()); |
6068 | 1041 |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
1042 OCTAVE_SAFE_CALL (command_editor::restore_terminal_state, ()); |
3216 | 1043 |
5775 | 1044 // FIXME -- is this needed? Can it cause any trouble? |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
1045 OCTAVE_SAFE_CALL (raw_mode, (0)); |
3216 | 1046 |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
1047 OCTAVE_SAFE_CALL (octave_history_write_timestamp, ()); |
5305 | 1048 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12846
diff
changeset
|
1049 if (! command_history::ignoring_entries ()) |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
1050 OCTAVE_SAFE_CALL (command_history::clean_up_and_save, ()); |
3216 | 1051 |
14073
5cbc978a27e8
close all figures before closing all files (bug #35064)
John W. Eaton <jwe@octave.org>
parents:
14021
diff
changeset
|
1052 OCTAVE_SAFE_CALL (gh_manager::close_all_figures, ()); |
5cbc978a27e8
close all figures before closing all files (bug #35064)
John W. Eaton <jwe@octave.org>
parents:
14021
diff
changeset
|
1053 |
5cbc978a27e8
close all figures before closing all files (bug #35064)
John W. Eaton <jwe@octave.org>
parents:
14021
diff
changeset
|
1054 OCTAVE_SAFE_CALL (gtk_manager::unload_all_toolkits, ()); |
5cbc978a27e8
close all figures before closing all files (bug #35064)
John W. Eaton <jwe@octave.org>
parents:
14021
diff
changeset
|
1055 |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
1056 OCTAVE_SAFE_CALL (close_files, ()); |
3216 | 1057 |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
1058 OCTAVE_SAFE_CALL (cleanup_tmp_files, ()); |
3216 | 1059 |
14073
5cbc978a27e8
close all figures before closing all files (bug #35064)
John W. Eaton <jwe@octave.org>
parents:
14021
diff
changeset
|
1060 OCTAVE_SAFE_CALL (symbol_table::cleanup, ()); |
5cbc978a27e8
close all figures before closing all files (bug #35064)
John W. Eaton <jwe@octave.org>
parents:
14021
diff
changeset
|
1061 |
5cbc978a27e8
close all figures before closing all files (bug #35064)
John W. Eaton <jwe@octave.org>
parents:
14021
diff
changeset
|
1062 OCTAVE_SAFE_CALL (sysdep_cleanup, ()); |
5cbc978a27e8
close all figures before closing all files (bug #35064)
John W. Eaton <jwe@octave.org>
parents:
14021
diff
changeset
|
1063 |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
1064 OCTAVE_SAFE_CALL (flush_octave_stdout, ()); |
3216 | 1065 |
5305 | 1066 if (! quitting_gracefully && (interactive || forced_interactive)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1067 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1068 octave_stdout << "\n"; |
5629 | 1069 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1070 // Yes, we want this to be separate from the call to |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1071 // flush_octave_stdout above. |
5629 | 1072 |
14014
907d03def9d5
explicitly close figures in clean_up_and_exit instead of using an atexit function
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
1073 OCTAVE_SAFE_CALL (flush_octave_stdout, ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1074 } |
14073
5cbc978a27e8
close all figures before closing all files (bug #35064)
John W. Eaton <jwe@octave.org>
parents:
14021
diff
changeset
|
1075 |
14156
d5d3037cbc11
don't call singleton_cleanup_list::cleanup on exit.
John W. Eaton <jwe@octave.org>
parents:
14144
diff
changeset
|
1076 // Don't call singleton_cleanup_list::cleanup until we have the |
d5d3037cbc11
don't call singleton_cleanup_list::cleanup on exit.
John W. Eaton <jwe@octave.org>
parents:
14144
diff
changeset
|
1077 // problems with registering/unregistering types worked out. For |
d5d3037cbc11
don't call singleton_cleanup_list::cleanup on exit.
John W. Eaton <jwe@octave.org>
parents:
14144
diff
changeset
|
1078 // example, uncomment the following line, then use the make_int |
d5d3037cbc11
don't call singleton_cleanup_list::cleanup on exit.
John W. Eaton <jwe@octave.org>
parents:
14144
diff
changeset
|
1079 // function from the examples directory to create an integer |
d5d3037cbc11
don't call singleton_cleanup_list::cleanup on exit.
John W. Eaton <jwe@octave.org>
parents:
14144
diff
changeset
|
1080 // object and then exit Octave. Octave should crash with a |
d5d3037cbc11
don't call singleton_cleanup_list::cleanup on exit.
John W. Eaton <jwe@octave.org>
parents:
14144
diff
changeset
|
1081 // segfault when cleaning up the typinfo singleton. We need some |
d5d3037cbc11
don't call singleton_cleanup_list::cleanup on exit.
John W. Eaton <jwe@octave.org>
parents:
14144
diff
changeset
|
1082 // way to force new octave_value_X types that are created in |
d5d3037cbc11
don't call singleton_cleanup_list::cleanup on exit.
John W. Eaton <jwe@octave.org>
parents:
14144
diff
changeset
|
1083 // .oct files to be unregistered when the .oct file shared library |
d5d3037cbc11
don't call singleton_cleanup_list::cleanup on exit.
John W. Eaton <jwe@octave.org>
parents:
14144
diff
changeset
|
1084 // is unloaded. |
d5d3037cbc11
don't call singleton_cleanup_list::cleanup on exit.
John W. Eaton <jwe@octave.org>
parents:
14144
diff
changeset
|
1085 // |
d5d3037cbc11
don't call singleton_cleanup_list::cleanup on exit.
John W. Eaton <jwe@octave.org>
parents:
14144
diff
changeset
|
1086 // OCTAVE_SAFE_CALL (singleton_cleanup_list::cleanup, ()); |
14073
5cbc978a27e8
close all figures before closing all files (bug #35064)
John W. Eaton <jwe@octave.org>
parents:
14021
diff
changeset
|
1087 |
5cbc978a27e8
close all figures before closing all files (bug #35064)
John W. Eaton <jwe@octave.org>
parents:
14021
diff
changeset
|
1088 OCTAVE_SAFE_CALL (octave_chunk_buffer::clear, ()); |
3216 | 1089 } |
2077 | 1090 } |
1091 | |
7409 | 1092 void |
1093 octave_add_atexit_function (const std::string& fname) | |
1094 { | |
1095 octave_atexit_functions.push_front (fname); | |
1096 } | |
1097 | |
1098 bool | |
1099 octave_remove_atexit_function (const std::string& fname) | |
1100 { | |
1101 bool found = false; | |
1102 | |
1103 for (std::list<std::string>::iterator p = octave_atexit_functions.begin (); | |
1104 p != octave_atexit_functions.end (); p++) | |
1105 { | |
1106 if (*p == fname) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1107 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1108 octave_atexit_functions.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1109 found = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1110 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1111 } |
7409 | 1112 } |
1113 | |
1114 return found; | |
1115 } | |
1116 | |
1117 | |
6680 | 1118 DEFUN (atexit, args, nargout, |
3332 | 1119 "-*- texinfo -*-\n\ |
10840 | 1120 @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\ |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1121 @deftypefnx {Built-in Function} {} atexit (@var{fcn}, @var{flag})\n\ |
3332 | 1122 Register a function to be called when Octave exits. For example,\n\ |
2077 | 1123 \n\ |
3332 | 1124 @example\n\ |
1125 @group\n\ | |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1126 function last_words ()\n\ |
6620 | 1127 disp (\"Bye bye\");\n\ |
3332 | 1128 endfunction\n\ |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1129 atexit (\"last_words\");\n\ |
3332 | 1130 @end group\n\ |
1131 @end example\n\ | |
1132 \n\ | |
1133 @noindent\n\ | |
6620 | 1134 will print the message \"Bye bye\" when Octave exits.\n\ |
6680 | 1135 \n\ |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1136 The additional argument @var{flag} will register or unregister\n\ |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1137 @var{fcn} from the list of functions to be called when Octave\n\ |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1138 exits. If @var{flag} is true, the function is registered, and if\n\ |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1139 @var{flag} is false, it is unregistered. For example,\n\ |
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1140 after registering the function @code{last_words} above,\n\ |
6680 | 1141 \n\ |
1142 @example\n\ | |
9035
57649dcecb55
Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
1143 atexit (\"last_words\", false);\n\ |
6680 | 1144 @end example\n\ |
1145 \n\ | |
1146 @noindent\n\ | |
1147 will remove the function from the list and Octave will not call\n\ | |
9133
c0cef1436788
Update help text for sections 2.2 and 2.3 of basics.txi
Rik <rdrider0-list@yahoo.com>
parents:
9079
diff
changeset
|
1148 @code{last_words} when it exits.\n\ |
6680 | 1149 \n\ |
7001 | 1150 Note that @code{atexit} only removes the first occurrence of a function\n\ |
6680 | 1151 from the list, so if a function was placed in the list multiple\n\ |
1152 times with @code{atexit}, it must also be removed from the list\n\ | |
1153 multiple times.\n\ | |
3333 | 1154 @end deftypefn") |
2077 | 1155 { |
2086 | 1156 octave_value_list retval; |
2077 | 1157 |
1158 int nargin = args.length (); | |
1159 | |
6680 | 1160 if (nargin == 1 || nargin == 2) |
2077 | 1161 { |
3523 | 1162 std::string arg = args(0).string_value (); |
2077 | 1163 |
1164 if (! error_state) | |
6680 | 1165 { |
1166 bool add_mode = true; | |
1167 | |
1168 if (nargin == 2) | |
1169 { | |
1170 add_mode = args(1).bool_value (); | |
1171 | |
1172 if (error_state) | |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12208
diff
changeset
|
1173 error ("atexit: FLAG argument must be a logical value"); |
6680 | 1174 } |
1175 | |
1176 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1177 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1178 if (add_mode) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1179 octave_add_atexit_function (arg); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1180 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1181 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1182 bool found = octave_remove_atexit_function (arg); |
6680 | 1183 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1184 if (nargout > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1185 retval(0) = found; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1186 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1187 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1188 } |
2077 | 1189 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12208
diff
changeset
|
1190 error ("atexit: FCN argument must be a string"); |
2077 | 1191 } |
1192 else | |
5823 | 1193 print_usage (); |
2077 | 1194 |
1195 return retval; | |
1196 } | |
1197 | |
2689 | 1198 DEFUN (octave_config_info, args, , |
3301 | 1199 "-*- texinfo -*-\n\ |
12208
9611014e7cf1
Add function compare_versions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12195
diff
changeset
|
1200 @deftypefn {Built-in Function} {} octave_config_info ()\n\ |
9611014e7cf1
Add function compare_versions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12195
diff
changeset
|
1201 @deftypefnx {Built-in Function} {} octave_config_info (@var{option})\n\ |
3301 | 1202 Return a structure containing configuration and installation\n\ |
1203 information for Octave.\n\ | |
2689 | 1204 \n\ |
12208
9611014e7cf1
Add function compare_versions to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12195
diff
changeset
|
1205 If @var{option} is a string, return the configuration information for the\n\ |
2689 | 1206 specified option.\n\ |
1207 \n\ | |
3301 | 1208 @end deftypefn") |
2162 | 1209 { |
2689 | 1210 octave_value retval; |
1211 | |
4128 | 1212 #if defined (ENABLE_DYNAMIC_LINKING) |
2689 | 1213 bool octave_supports_dynamic_linking = true; |
1214 #else | |
1215 bool octave_supports_dynamic_linking = false; | |
1216 #endif | |
1217 | |
4357 | 1218 static bool initialized = false; |
11066
e678346a47d9
toplev.cc, sighandlers.cc, utils.cc, octave.cc, pt-eval.cc pt-idx.cc: Octave_map to octave_map and octave_scalar_map conversion
John W. Eaton <jwe@octave.org>
parents:
11023
diff
changeset
|
1219 static octave_scalar_map m; |
2162 | 1220 |
6274 | 1221 struct conf_info_struct |
1222 { | |
1223 bool subst_home; | |
1224 const char *key; | |
1225 const char *val; | |
1226 }; | |
1227 | |
1228 static const conf_info_struct conf_info[] = | |
4357 | 1229 { |
6274 | 1230 { false, "ALL_CFLAGS", OCTAVE_CONF_ALL_CFLAGS }, |
1231 { false, "ALL_CXXFLAGS", OCTAVE_CONF_ALL_CXXFLAGS }, | |
1232 { false, "ALL_FFLAGS", OCTAVE_CONF_ALL_FFLAGS }, | |
1233 { false, "ALL_LDFLAGS", OCTAVE_CONF_ALL_LDFLAGS }, | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1234 { false, "AMD_CPPFLAGS", OCTAVE_CONF_AMD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1235 { false, "AMD_LDFLAGS", OCTAVE_CONF_AMD_LDFLAGS }, |
9514 | 1236 { false, "AMD_LIBS", OCTAVE_CONF_AMD_LIBS }, |
6274 | 1237 { false, "AR", OCTAVE_CONF_AR }, |
1238 { false, "ARFLAGS", OCTAVE_CONF_ARFLAGS }, | |
14144
834df9f10963
remove ARPACK files from sources and restore configure checks for external ARPACK library
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1239 { false, "ARPACK_CPPFLAGS", OCTAVE_CONF_ARPACK_CPPFLAGS }, |
834df9f10963
remove ARPACK files from sources and restore configure checks for external ARPACK library
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1240 { false, "ARPACK_LDFLAGS", OCTAVE_CONF_ARPACK_LDFLAGS }, |
834df9f10963
remove ARPACK files from sources and restore configure checks for external ARPACK library
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1241 { false, "ARPACK_LIBS", OCTAVE_CONF_ARPACK_LIBS }, |
6274 | 1242 { false, "BLAS_LIBS", OCTAVE_CONF_BLAS_LIBS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1243 { false, "CAMD_CPPFLAGS", OCTAVE_CONF_CAMD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1244 { false, "CAMD_LDFLAGS", OCTAVE_CONF_CAMD_LDFLAGS }, |
9514 | 1245 { false, "CAMD_LIBS", OCTAVE_CONF_CAMD_LIBS }, |
15424
cabe2fa4566c
build: Add and organize octave_config_info variables.
Rik <rik@octave.org>
parents:
15307
diff
changeset
|
1246 { false, "CARBON_LIBS", OCTAVE_CONF_CARBON_LIBS }, |
6274 | 1247 { false, "CC", OCTAVE_CONF_CC }, |
15167
1c711a646fa7
Deprecate configure variables CC_VERSION, CXX_VERSION.
Rik <rik@octave.org>
parents:
15154
diff
changeset
|
1248 // FIXME: CC_VERSION is deprecated. Remove in version 3.12 |
6274 | 1249 { false, "CC_VERSION", OCTAVE_CONF_CC_VERSION }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1250 { false, "CCOLAMD_CPPFLAGS", OCTAVE_CONF_CCOLAMD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1251 { false, "CCOLAMD_LDFLAGS", OCTAVE_CONF_CCOLAMD_LDFLAGS }, |
9514 | 1252 { false, "CCOLAMD_LIBS", OCTAVE_CONF_CCOLAMD_LIBS }, |
6274 | 1253 { false, "CFLAGS", OCTAVE_CONF_CFLAGS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1254 { false, "CHOLMOD_CPPFLAGS", OCTAVE_CONF_CHOLMOD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1255 { false, "CHOLMOD_LDFLAGS", OCTAVE_CONF_CHOLMOD_LDFLAGS }, |
9514 | 1256 { false, "CHOLMOD_LIBS", OCTAVE_CONF_CHOLMOD_LIBS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1257 { false, "COLAMD_CPPFLAGS", OCTAVE_CONF_COLAMD_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1258 { false, "COLAMD_LDFLAGS", OCTAVE_CONF_COLAMD_LDFLAGS }, |
9514 | 1259 { false, "COLAMD_LIBS", OCTAVE_CONF_COLAMD_LIBS }, |
6274 | 1260 { false, "CPICFLAG", OCTAVE_CONF_CPICFLAG }, |
1261 { false, "CPPFLAGS", OCTAVE_CONF_CPPFLAGS }, | |
9519
ee99f9f37505
improve configure checks for qhull and curl libs
John W. Eaton <jwe@octave.org>
parents:
9515
diff
changeset
|
1262 { false, "CURL_CPPFLAGS", OCTAVE_CONF_CURL_CPPFLAGS }, |
ee99f9f37505
improve configure checks for qhull and curl libs
John W. Eaton <jwe@octave.org>
parents:
9515
diff
changeset
|
1263 { false, "CURL_LDFLAGS", OCTAVE_CONF_CURL_LDFLAGS }, |
6274 | 1264 { false, "CURL_LIBS", OCTAVE_CONF_CURL_LIBS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1265 { false, "CXSPARSE_CPPFLAGS", OCTAVE_CONF_CXSPARSE_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1266 { false, "CXSPARSE_LDFLAGS", OCTAVE_CONF_CXSPARSE_LDFLAGS }, |
9514 | 1267 { false, "CXSPARSE_LIBS", OCTAVE_CONF_CXSPARSE_LIBS }, |
6274 | 1268 { false, "CXX", OCTAVE_CONF_CXX }, |
1269 { false, "CXXCPP", OCTAVE_CONF_CXXCPP }, | |
1270 { false, "CXXFLAGS", OCTAVE_CONF_CXXFLAGS }, | |
1271 { false, "CXXPICFLAG", OCTAVE_CONF_CXXPICFLAG }, | |
15167
1c711a646fa7
Deprecate configure variables CC_VERSION, CXX_VERSION.
Rik <rik@octave.org>
parents:
15154
diff
changeset
|
1272 // FIXME: CXX_VERSION is deprecated. Remove in version 3.12 |
6274 | 1273 { false, "CXX_VERSION", OCTAVE_CONF_CXX_VERSION }, |
1274 { false, "DEFAULT_PAGER", OCTAVE_DEFAULT_PAGER }, | |
1275 { false, "DEFS", OCTAVE_CONF_DEFS }, | |
1276 { false, "DL_LD", OCTAVE_CONF_DL_LD }, | |
1277 { false, "DL_LDFLAGS", OCTAVE_CONF_DL_LDFLAGS }, | |
9515 | 1278 { false, "DL_LIBS", OCTAVE_CONF_DL_LIBS }, |
15167
1c711a646fa7
Deprecate configure variables CC_VERSION, CXX_VERSION.
Rik <rik@octave.org>
parents:
15154
diff
changeset
|
1279 { false, "GCC_VERSION", OCTAVE_CONF_GCC_VERSION }, |
1c711a646fa7
Deprecate configure variables CC_VERSION, CXX_VERSION.
Rik <rik@octave.org>
parents:
15154
diff
changeset
|
1280 { false, "GXX_VERSION", OCTAVE_CONF_GXX_VERSION }, |
6274 | 1281 { false, "ENABLE_DYNAMIC_LINKING", OCTAVE_CONF_ENABLE_DYNAMIC_LINKING }, |
1282 { false, "EXEEXT", OCTAVE_CONF_EXEEXT }, | |
1283 { false, "F77", OCTAVE_CONF_F77 }, | |
1284 { false, "F77_FLOAT_STORE_FLAG", OCTAVE_CONF_F77_FLOAT_STORE_FLAG }, | |
10331
6a50aa2cdf00
never compile ranlib with 8-byte integers
John W. Eaton <jwe@octave.org>
parents:
10315
diff
changeset
|
1285 { false, "F77_INTEGER_8_FLAG", OCTAVE_CONF_F77_INTEGER_8_FLAG }, |
6274 | 1286 { false, "FC", OCTAVE_CONF_FC }, |
1287 { false, "FFLAGS", OCTAVE_CONF_FFLAGS }, | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1288 { false, "FFTW3_CPPFLAGS", OCTAVE_CONF_FFTW3_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1289 { false, "FFTW3_LDFLAGS", OCTAVE_CONF_FFTW3_LDFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1290 { false, "FFTW3_LIBS", OCTAVE_CONF_FFTW3_LIBS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1291 { false, "FFTW3F_CPPFLAGS", OCTAVE_CONF_FFTW3F_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1292 { false, "FFTW3F_LDFLAGS", OCTAVE_CONF_FFTW3F_LDFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1293 { false, "FFTW3F_LIBS", OCTAVE_CONF_FFTW3F_LIBS }, |
6274 | 1294 { false, "FLIBS", OCTAVE_CONF_FLIBS }, |
1295 { false, "FPICFLAG", OCTAVE_CONF_FPICFLAG }, | |
15424
cabe2fa4566c
build: Add and organize octave_config_info variables.
Rik <rik@octave.org>
parents:
15307
diff
changeset
|
1296 { false, "FT2_CFLAGS", OCTAVE_CONF_FT2_CFLAGS }, |
9514 | 1297 { false, "FT2_LIBS", OCTAVE_CONF_FT2_LIBS }, |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1298 { false, "GLPK_CPPFLAGS", OCTAVE_CONF_GLPK_CPPFLAGS }, |
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9519
diff
changeset
|
1299 { false, "GLPK_LDFLAGS", OCTAVE_CONF_GLPK_LDFLAGS }, |
6274 | 1300 { false, "GLPK_LIBS", OCTAVE_CONF_GLPK_LIBS }, |
7361 | 1301 { false, "GNUPLOT", OCTAVE_CONF_GNUPLOT }, |
15424
cabe2fa4566c
build: Add and organize octave_config_info variables.
Rik <rik@octave.org>
parents:
15307
diff
changeset
|
1302 { false, "GRAPHICS_CFLAGS", OCTAVE_CONF_GRAPHICS_CFLAGS }, |
9514 | 1303 { false, "GRAPHICS_LIBS", OCTAVE_CONF_GRAPHICS_LIBS }, |
9542
f5ec5dc66824
use OCTAVE_CHECK_LIBRARY to check for HDF5
John W. Eaton <jwe@octave.org>
parents:
9538
diff
changeset
|
1304 { false, "HDF5_CPPFLAGS", OCTAVE_CONF_HDF5_CPPFLAGS }, |
f5ec5dc66824
use OCTAVE_CHECK_LIBRARY to check for HDF5
John W. Eaton <jwe@octave.org>
parents:
9538
diff
changeset
|
1305 { false, "HDF5_LDFLAGS", OCTAVE_CONF_HDF5_LDFLAGS }, |
9514 | 1306 { false, "HDF5_LIBS", OCTAVE_CONF_HDF5_LIBS }, |
9794
0d4613a736e9
convert build system to use automake and libtool
John W. Eaton <jwe@octave.org>
parents:
9575
diff
changeset
|
1307 { false, "LAPACK_LIBS", OCTAVE_CONF_LAPACK_LIBS }, |
6274 | 1308 { false, "LDFLAGS", OCTAVE_CONF_LDFLAGS }, |
1309 { false, "LD_CXX", OCTAVE_CONF_LD_CXX }, | |
1310 { false, "LD_STATIC_FLAG", OCTAVE_CONF_LD_STATIC_FLAG }, | |
1311 { false, "LEX", OCTAVE_CONF_LEX }, | |
1312 { false, "LEXLIB", OCTAVE_CONF_LEXLIB }, | |
1313 { false, "LFLAGS", OCTAVE_CONF_LFLAGS }, | |
1314 { false, "LIBEXT", OCTAVE_CONF_LIBEXT }, | |
1315 { false, "LIBFLAGS", OCTAVE_CONF_LIBFLAGS }, | |
1316 { false, "LIBOCTAVE", OCTAVE_CONF_LIBOCTAVE }, | |
1317 { false, "LIBOCTINTERP", OCTAVE_CONF_LIBOCTINTERP }, | |
1318 { false, "LIBS", OCTAVE_CONF_LIBS }, | |
15424
cabe2fa4566c
build: Add and organize octave_config_info variables.
Rik <rik@octave.org>
parents:
15307
diff
changeset
|
1319 { false, "LLVM_CPPFLAGS", OCTAVE_CONF_LLVM_CPPFLAGS }, |
cabe2fa4566c
build: Add and organize octave_config_info variables.
Rik <rik@octave.org>
parents:
15307
diff
changeset
|
1320 { false, "LLVM_LDFLAGS", OCTAVE_CONF_LLVM_LDFLAGS }, |
cabe2fa4566c
build: Add and organize octave_config_info variables.
Rik <rik@octave.org>
parents:
15307
diff
changeset
|
1321 { false, "LLVM_LIBS", OCTAVE_CONF_LLVM_LIBS }, |
6274 | 1322 { false, "LN_S", OCTAVE_CONF_LN_S }, |
9575
55ecaefb7d0f
Use pkg-config to configure GraphicsMagick++.
David Grundberg <individ@acc.umu.se>
parents:
9572
diff
changeset
|
1323 { false, "MAGICK_CPPFLAGS", OCTAVE_CONF_MAGICK_CPPFLAGS }, |
55ecaefb7d0f
Use pkg-config to configure GraphicsMagick++.
David Grundberg <individ@acc.umu.se>
parents:
9572
diff
changeset
|
1324 { false, "MAGICK_LDFLAGS", OCTAVE_CONF_MAGICK_LDFLAGS }, |
7926
d74f996e005d
__magick_read__.cc: configuration and style fixes
John W. Eaton <jwe@octave.org>
parents:
7923
diff
changeset
|
1325 { false, "MAGICK_LIBS", OCTAVE_CONF_MAGICK_LIBS }, |
6274 | 1326 { false, "MKOCTFILE_DL_LDFLAGS", OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS }, |
13010
edc5ec6e949b
maint: allow --enable-static --disable-dl to work again
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
1327 { false, "OCTAVE_LINK_DEPS", OCTAVE_CONF_OCTAVE_LINK_DEPS }, |
edc5ec6e949b
maint: allow --enable-static --disable-dl to work again
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
1328 { false, "OCTAVE_LINK_OPTS", OCTAVE_CONF_OCTAVE_LINK_OPTS }, |
edc5ec6e949b
maint: allow --enable-static --disable-dl to work again
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
1329 { false, "OCT_LINK_DEPS", OCTAVE_CONF_OCT_LINK_DEPS }, |
edc5ec6e949b
maint: allow --enable-static --disable-dl to work again
John W. Eaton <jwe@octave.org>
parents:
12989
diff
changeset
|
1330 { false, "OCT_LINK_OPTS", OCTAVE_CONF_OCT_LINK_OPTS }, |
9514 | 1331 { false, "OPENGL_LIBS", OCTAVE_CONF_OPENGL_LIBS }, |
1332 { false, "PTHREAD_CFLAGS", OCTAVE_CONF_PTHREAD_CFLAGS }, | |
1333 { false, "PTHREAD_LIBS", OCTAVE_CONF_PTHREAD_LIBS }, | |
9519
ee99f9f37505
improve configure checks for qhull and curl libs
John W. Eaton <jwe@octave.org>
parents:
9515
diff
changeset
|
1334 { false, "QHULL_CPPFLAGS", OCTAVE_CONF_QHULL_CPPFLAGS }, |
ee99f9f37505
improve configure checks for qhull and curl libs
John W. Eaton <jwe@octave.org>
parents:
9515
diff
changeset
|
1335 { false, "QHULL_LDFLAGS", OCTAVE_CONF_QHULL_LDFLAGS }, |
9514 | 1336 { false, "QHULL_LIBS", OCTAVE_CONF_QHULL_LIBS }, |
9570
1ab56c73ec7c
use OCTAVE_CHECK_LIBRARY to check for qrupdate library
John W. Eaton <jwe@octave.org>
parents:
9568
diff
changeset
|
1337 { false, "QRUPDATE_CPPFLAGS", OCTAVE_CONF_QRUPDATE_CPPFLAGS }, |
1ab56c73ec7c
use OCTAVE_CHECK_LIBRARY to check for qrupdate library
John W. Eaton <jwe@octave.org>
parents:
9568
diff
changeset
|
1338 { false, "QRUPDATE_LDFLAGS", OCTAVE_CONF_QRUPDATE_LDFLAGS }, |
9514 | 1339 { false, "QRUPDATE_LIBS", OCTAVE_CONF_QRUPDATE_LIBS }, |
15596
5f031158c693
Use pkg-config to discover Qt (pkg-config is already a requirement anyway).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15467
diff
changeset
|
1340 { false, "QT_CPPFLAGS", OCTAVE_CONF_QT_CPPFLAGS }, |
5f031158c693
Use pkg-config to discover Qt (pkg-config is already a requirement anyway).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15467
diff
changeset
|
1341 { false, "QT_LDFLAGS", OCTAVE_CONF_QT_LDFLAGS }, |
5f031158c693
Use pkg-config to discover Qt (pkg-config is already a requirement anyway).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
15467
diff
changeset
|
1342 { false, "QT_LIBS", OCTAVE_CONF_QT_LIBS }, |
6274 | 1343 { false, "RANLIB", OCTAVE_CONF_RANLIB }, |
1344 { false, "RDYNAMIC_FLAG", OCTAVE_CONF_RDYNAMIC_FLAG }, | |
9515 | 1345 { false, "READLINE_LIBS", OCTAVE_CONF_READLINE_LIBS }, |
9514 | 1346 { false, "REGEX_LIBS", OCTAVE_CONF_REGEX_LIBS }, |
6274 | 1347 { false, "SED", OCTAVE_CONF_SED }, |
1348 { false, "SHARED_LIBS", OCTAVE_CONF_SHARED_LIBS }, | |
1349 { false, "SHLEXT", OCTAVE_CONF_SHLEXT }, | |
1350 { false, "SHLEXT_VER", OCTAVE_CONF_SHLEXT_VER }, | |
1351 { false, "SH_LD", OCTAVE_CONF_SH_LD }, | |
1352 { false, "SH_LDFLAGS", OCTAVE_CONF_SH_LDFLAGS }, | |
1353 { false, "SONAME_FLAGS", OCTAVE_CONF_SONAME_FLAGS }, | |
1354 { false, "STATIC_LIBS", OCTAVE_CONF_STATIC_LIBS }, | |
9515 | 1355 { false, "TERM_LIBS", OCTAVE_CONF_TERM_LIBS }, |
9572
ab8a163f2052
use OCTAVE_CHECK_LIB to check for UMFPACK
John W. Eaton <jwe@octave.org>
parents:
9570
diff
changeset
|
1356 { false, "UMFPACK_CPPFLAGS", OCTAVE_CONF_UMFPACK_CPPFLAGS }, |
ab8a163f2052
use OCTAVE_CHECK_LIB to check for UMFPACK
John W. Eaton <jwe@octave.org>
parents:
9570
diff
changeset
|
1357 { false, "UMFPACK_LDFLAGS", OCTAVE_CONF_UMFPACK_LDFLAGS }, |
9514 | 1358 { false, "UMFPACK_LIBS", OCTAVE_CONF_UMFPACK_LIBS }, |
6274 | 1359 { false, "USE_64_BIT_IDX_T", OCTAVE_CONF_USE_64_BIT_IDX_T }, |
15424
cabe2fa4566c
build: Add and organize octave_config_info variables.
Rik <rik@octave.org>
parents:
15307
diff
changeset
|
1360 { false, "WARN_CFLAGS", OCTAVE_CONF_WARN_CFLAGS }, |
cabe2fa4566c
build: Add and organize octave_config_info variables.
Rik <rik@octave.org>
parents:
15307
diff
changeset
|
1361 { false, "WARN_CXXFLAGS", OCTAVE_CONF_WARN_CXXFLAGS }, |
8772
aeedc045cfe3
toplev.cc (Foctave_config_info): add CARBON_LIBS, X11_INCFLAGS, and X11_LIBS to the struct
John W. Eaton <jwe@octave.org>
parents:
8735
diff
changeset
|
1362 { false, "X11_INCFLAGS", OCTAVE_CONF_X11_INCFLAGS }, |
aeedc045cfe3
toplev.cc (Foctave_config_info): add CARBON_LIBS, X11_INCFLAGS, and X11_LIBS to the struct
John W. Eaton <jwe@octave.org>
parents:
8735
diff
changeset
|
1363 { false, "X11_LIBS", OCTAVE_CONF_X11_LIBS }, |
6274 | 1364 { false, "XTRA_CFLAGS", OCTAVE_CONF_XTRA_CFLAGS }, |
1365 { false, "XTRA_CXXFLAGS", OCTAVE_CONF_XTRA_CXXFLAGS }, | |
1366 { false, "YACC", OCTAVE_CONF_YACC }, | |
1367 { false, "YFLAGS", OCTAVE_CONF_YFLAGS }, | |
9538
d0239bddf621
use OCTAVE_CHECK_LIB to check for zlib
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
1368 { false, "Z_CPPFLAGS", OCTAVE_CONF_Z_CPPFLAGS }, |
d0239bddf621
use OCTAVE_CHECK_LIB to check for zlib
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
1369 { false, "Z_LDFLAGS", OCTAVE_CONF_Z_LDFLAGS }, |
d0239bddf621
use OCTAVE_CHECK_LIB to check for zlib
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
1370 { false, "Z_LIBS", OCTAVE_CONF_Z_LIBS }, |
6274 | 1371 { false, "api_version", OCTAVE_API_VERSION }, |
1372 { true, "archlibdir", OCTAVE_ARCHLIBDIR }, | |
1373 { true, "bindir", OCTAVE_BINDIR }, | |
1374 { false, "canonical_host_type", OCTAVE_CANONICAL_HOST_TYPE }, | |
1375 { false, "config_opts", OCTAVE_CONF_config_opts }, | |
1376 { true, "datadir", OCTAVE_DATADIR }, | |
1377 { true, "datarootdir", OCTAVE_DATAROOTDIR }, | |
6276 | 1378 { true, "exec_prefix", OCTAVE_EXEC_PREFIX }, |
6274 | 1379 { true, "fcnfiledir", OCTAVE_FCNFILEDIR }, |
1380 { true, "imagedir", OCTAVE_IMAGEDIR }, | |
1381 { true, "includedir", OCTAVE_INCLUDEDIR }, | |
1382 { true, "infodir", OCTAVE_INFODIR }, | |
6276 | 1383 { true, "infofile", OCTAVE_INFOFILE }, |
6274 | 1384 { true, "libdir", OCTAVE_LIBDIR }, |
1385 { true, "libexecdir", OCTAVE_LIBEXECDIR }, | |
6311 | 1386 { true, "localapiarchlibdir", OCTAVE_LOCALAPIARCHLIBDIR }, |
6274 | 1387 { true, "localapifcnfiledir", OCTAVE_LOCALAPIFCNFILEDIR }, |
1388 { true, "localapioctfiledir", OCTAVE_LOCALAPIOCTFILEDIR }, | |
1389 { true, "localarchlibdir", OCTAVE_LOCALARCHLIBDIR }, | |
1390 { true, "localfcnfiledir", OCTAVE_LOCALFCNFILEDIR }, | |
1391 { true, "localoctfiledir", OCTAVE_LOCALOCTFILEDIR }, | |
1392 { true, "localstartupfiledir", OCTAVE_LOCALSTARTUPFILEDIR }, | |
1393 { true, "localverarchlibdir", OCTAVE_LOCALVERARCHLIBDIR }, | |
1394 { true, "localverfcnfiledir", OCTAVE_LOCALVERFCNFILEDIR }, | |
1395 { true, "localveroctfiledir", OCTAVE_LOCALVEROCTFILEDIR }, | |
1396 { true, "man1dir", OCTAVE_MAN1DIR }, | |
1397 { false, "man1ext", OCTAVE_MAN1EXT }, | |
1398 { true, "mandir", OCTAVE_MANDIR }, | |
1399 { true, "octfiledir", OCTAVE_OCTFILEDIR }, | |
8719
679c270b7584
install DOC and NEWS in $octetcdir
John W. Eaton <jwe@octave.org>
parents:
8704
diff
changeset
|
1400 { true, "octetcdir", OCTAVE_OCTETCDIR }, |
6274 | 1401 { true, "octincludedir", OCTAVE_OCTINCLUDEDIR }, |
1402 { true, "octlibdir", OCTAVE_OCTLIBDIR }, | |
16019
5b2126a8c84f
install tests and functions to run them
John W. Eaton <jwe@octave.org>
parents:
15756
diff
changeset
|
1403 { true, "octtestsdir", OCTAVE_OCTTESTSDIR }, |
6276 | 1404 { true, "prefix", OCTAVE_PREFIX }, |
6274 | 1405 { true, "startupfiledir", OCTAVE_STARTUPFILEDIR }, |
1406 { false, "version", OCTAVE_VERSION }, | |
1407 { false, 0, 0 } | |
4357 | 1408 }; |
1409 | |
1410 if (! initialized) | |
1411 { | |
4675 | 1412 m.assign ("dld", octave_value (octave_supports_dynamic_linking)); |
4357 | 1413 |
4697 | 1414 oct_mach_info::float_format ff = oct_mach_info::native_float_format (); |
1415 m.assign ("float_format", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1416 octave_value (oct_mach_info::float_format_as_string (ff))); |
4697 | 1417 |
1418 m.assign ("words_big_endian", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1419 octave_value (oct_mach_info::words_big_endian ())); |
4697 | 1420 |
1421 m.assign ("words_little_endian", | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1422 octave_value (oct_mach_info::words_little_endian ())); |
4697 | 1423 |
16170
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
16164
diff
changeset
|
1424 m.assign ("features", octave_value (octave_config_features ())); |
2a4f83826024
new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents:
16164
diff
changeset
|
1425 |
4357 | 1426 int i = 0; |
4440 | 1427 |
1428 while (true) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1429 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1430 const conf_info_struct& elt = conf_info[i++]; |
6274 | 1431 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1432 const char *key = elt.key; |
4357 | 1433 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1434 if (key) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1435 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1436 if (elt.subst_home) |
11066
e678346a47d9
toplev.cc, sighandlers.cc, utils.cc, octave.cc, pt-eval.cc pt-idx.cc: Octave_map to octave_map and octave_scalar_map conversion
John W. Eaton <jwe@octave.org>
parents:
11023
diff
changeset
|
1437 m.assign (key, subst_octave_home (elt.val)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1438 else |
11066
e678346a47d9
toplev.cc, sighandlers.cc, utils.cc, octave.cc, pt-eval.cc pt-idx.cc: Octave_map to octave_map and octave_scalar_map conversion
John W. Eaton <jwe@octave.org>
parents:
11023
diff
changeset
|
1439 m.assign (key, elt.val); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1440 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1441 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1442 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1443 } |
4357 | 1444 |
4691 | 1445 bool unix_system = true; |
7013 | 1446 bool mac_system = false; |
4691 | 1447 bool windows_system = false; |
1448 | |
1449 #if defined (WIN32) | |
1450 windows_system = true; | |
1451 #if !defined (__CYGWIN__) | |
1452 unix_system = false; | |
1453 #endif | |
1454 #endif | |
1455 | |
8574
83b8c739d626
toplev.cc: check OCTAVE_USE_OS_X_API instead of __APPLE__ && __MACH__
John W. Eaton <jwe@octave.org>
parents:
8377
diff
changeset
|
1456 #if defined (OCTAVE_USE_OS_X_API) |
7010 | 1457 mac_system = true; |
1458 #endif | |
1459 | |
4691 | 1460 m.assign ("unix", octave_value (unix_system)); |
7010 | 1461 m.assign ("mac", octave_value (mac_system)); |
4691 | 1462 m.assign ("windows", octave_value (windows_system)); |
1463 | |
4357 | 1464 initialized = true; |
1465 } | |
2162 | 1466 |
2689 | 1467 int nargin = args.length (); |
1468 | |
1469 if (nargin == 1) | |
1470 { | |
3523 | 1471 std::string arg = args(0).string_value (); |
2689 | 1472 |
1473 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1474 { |
15307
b516da00c5e4
don't insert unknonwn parameters in internal octave_config_info struct
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
1475 if (m.isfield (arg)) |
b516da00c5e4
don't insert unknonwn parameters in internal octave_config_info struct
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
1476 { |
b516da00c5e4
don't insert unknonwn parameters in internal octave_config_info struct
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
1477 Cell c = m.contents (arg); |
5199 | 1478 |
15307
b516da00c5e4
don't insert unknonwn parameters in internal octave_config_info struct
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
1479 if (c.is_empty ()) |
15467
049e8bbff782
maint: periodic merge of stable to default
John W. Eaton <jwe@octave.org>
diff
changeset
|
1480 error ("octave_config_info: no info for '%s'", arg.c_str ()); |
15307
b516da00c5e4
don't insert unknonwn parameters in internal octave_config_info struct
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
1481 else |
b516da00c5e4
don't insert unknonwn parameters in internal octave_config_info struct
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
1482 retval = c(0); |
b516da00c5e4
don't insert unknonwn parameters in internal octave_config_info struct
John W. Eaton <jwe@octave.org>
parents:
15271
diff
changeset
|
1483 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1484 else |
15467
049e8bbff782
maint: periodic merge of stable to default
John W. Eaton <jwe@octave.org>
diff
changeset
|
1485 error ("octave_config_info: invalid parameter '%s'", arg.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10212
diff
changeset
|
1486 } |
2689 | 1487 } |
1488 else if (nargin == 0) | |
4233 | 1489 retval = m; |
2689 | 1490 else |
5823 | 1491 print_usage (); |
2689 | 1492 |
1493 return retval; | |
2162 | 1494 } |
1495 | |
12846
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1496 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14156
diff
changeset
|
1497 %!assert (ischar (octave_config_info ("version"))) |
12846
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1498 %!test |
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1499 %! x = octave_config_info (); |
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1500 %! assert (isstruct (x)); |
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1501 %! assert (! isempty (x)); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14156
diff
changeset
|
1502 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14156
diff
changeset
|
1503 %!error octave_config_info (1, 2) |
12846
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1504 */ |
9ce9e1e2d2c8
codesprint: new tests for toplev.cc
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1505 |
1683 | 1506 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE) |
2806 | 1507 |
1683 | 1508 int debug_new_delete = 0; |
1509 | |
1510 typedef void (*vfp)(void); | |
1511 extern vfp __new_handler; | |
1512 | |
1513 void * | |
1514 __builtin_new (size_t sz) | |
1515 { | |
1516 void *p; | |
1517 | |
1518 /* malloc (0) is unpredictable; avoid it. */ | |
1519 if (sz == 0) | |
1520 sz = 1; | |
15451
219479b461b8
build: Add missing tests and gnulib modules suggested by autoscan.
Rik <rik@octave.org>
parents:
15424
diff
changeset
|
1521 p = gnulib::malloc (sz); |
1683 | 1522 while (p == 0) |
1523 { | |
1524 (*__new_handler) (); | |
15451
219479b461b8
build: Add missing tests and gnulib modules suggested by autoscan.
Rik <rik@octave.org>
parents:
15424
diff
changeset
|
1525 p = gnulib::malloc (sz); |
1683 | 1526 } |
1527 | |
1528 if (debug_new_delete) | |
5629 | 1529 std::cerr << "__builtin_new: " << p << std::endl; |
1683 | 1530 |
1531 return p; | |
1532 } | |
1533 | |
1534 void | |
1535 __builtin_delete (void *ptr) | |
1536 { | |
1537 if (debug_new_delete) | |
5629 | 1538 std::cerr << "__builtin_delete: " << ptr << std::endl; |
1683 | 1539 |
1540 if (ptr) | |
1541 free (ptr); | |
1542 } | |
2806 | 1543 |
1683 | 1544 #endif |