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