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