annotate src/toplev.cc @ 10186:095a1e670e68

make dbstep work with keyboard function
author John W. Eaton <jwe@octave.org>
date Fri, 22 Jan 2010 07:30:44 -0500
parents 0522a65bcd56
children 56f7734f5448
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1 /*
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
2
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
3 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8810
diff changeset
4 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
5
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
7
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7013
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7013
diff changeset
11 option) any later version.
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
12
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
16 for more details.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
17
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7013
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7013
diff changeset
20 <http://www.gnu.org/licenses/>.
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
21
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
22 */
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
23
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
25 #include <config.h>
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
26 #endif
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
27
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
28 #include <cassert>
4489
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
29 #include <cerrno>
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
30 #include <cstdlib>
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
31 #include <cstring>
4221
a7d8e5dd87ad [project @ 2002-12-06 22:34:47 by jwe]
jwe
parents: 4217
diff changeset
32 #include <new>
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
33
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3446
diff changeset
34 #include <fstream>
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3446
diff changeset
35 #include <iostream>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5744
diff changeset
36 #include <sstream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1704
diff changeset
37 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1704
diff changeset
38
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
39 #include <sys/types.h>
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
40 #include <unistd.h>
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
41
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2910
diff changeset
42 #include "cmd-edit.h"
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2910
diff changeset
43 #include "file-ops.h"
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
44 #include "lo-error.h"
2370
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2322
diff changeset
45 #include "lo-mappers.h"
3020
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
46 #include "oct-env.h"
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
47 #include "quit.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1751
diff changeset
48 #include "str-vec.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8347
diff changeset
49 #include "oct-locbuf.h"
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
50
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2475
diff changeset
51 #include <defaults.h>
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
52 #include "defun.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
53 #include "error.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
54 #include "file-io.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
55 #include "input.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
56 #include "lex.h"
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2475
diff changeset
57 #include <oct-conf.h>
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1728
diff changeset
58 #include "oct-hist.h"
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
59 #include "oct-map.h"
2862
95e85daad148 [project @ 1997-04-15 22:00:57 by jwe]
jwe
parents: 2859
diff changeset
60 #include "oct-obj.h"
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
61 #include "pager.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
62 #include "parse.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
63 #include "pathsearch.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
64 #include "procstream.h"
2370
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2322
diff changeset
65 #include "ov.h"
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8581
diff changeset
66 #include "pt-eval.h"
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
67 #include "pt-jump.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents: 2973
diff changeset
68 #include "pt-stmt.h"
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
69 #include "sighandlers.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
70 #include "sysdep.h"
2693
f4d0604cbcc4 [project @ 1997-02-18 15:25:21 by jwe]
jwe
parents: 2692
diff changeset
71 #include "syswait.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
72 #include "toplev.h"
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
73 #include "unwind-prot.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
74 #include "utils.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
75 #include "variables.h"
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2475
diff changeset
76 #include <version.h>
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
77
9217
ee7cf4d963f3 smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents: 9187
diff changeset
78 void (*octave_exit) (int) = ::exit;
ee7cf4d963f3 smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents: 9187
diff changeset
79
9255
1c2d2c9f4a8d don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents: 9217
diff changeset
80 // 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
81 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
82
3020
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
83 // TRUE means we are exiting via the builtin exit or quit functions.
9383
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
84 bool quitting_gracefully = false;
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
85 // This stores the exit status.
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
86 int exit_status = 0;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
87
4217
301cc4cf87e9 [project @ 2002-12-05 03:33:01 by jwe]
jwe
parents: 4214
diff changeset
88 // TRUE means we are ready to interpret commands, but not everything
301cc4cf87e9 [project @ 2002-12-05 03:33:01 by jwe]
jwe
parents: 4214
diff changeset
89 // is ready for interactive use.
301cc4cf87e9 [project @ 2002-12-05 03:33:01 by jwe]
jwe
parents: 4214
diff changeset
90 bool octave_interpreter_ready = false;
301cc4cf87e9 [project @ 2002-12-05 03:33:01 by jwe]
jwe
parents: 4214
diff changeset
91
4172
2e94b2abfe6d [project @ 2002-11-12 21:14:04 by jwe]
jwe
parents: 4171
diff changeset
92 // TRUE means we've processed all the init code and we are good to go.
2e94b2abfe6d [project @ 2002-11-12 21:14:04 by jwe]
jwe
parents: 4171
diff changeset
93 bool octave_initialized = false;
2e94b2abfe6d [project @ 2002-11-12 21:14:04 by jwe]
jwe
parents: 4171
diff changeset
94
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
95 // Current command to execute.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
96 tree_statement_list *global_command = 0;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
97
5743
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5717
diff changeset
98 octave_call_stack *octave_call_stack::instance = 0;
a527e0f77aa5 [project @ 2006-04-06 08:20:21 by jwe]
jwe
parents: 5717
diff changeset
99
7734
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
100 int
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
101 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
102 {
9484
bbe033dcfe13 make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents: 9483
diff changeset
103 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
104
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
105 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
106 }
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
107
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
108 int
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
109 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
110 {
9484
bbe033dcfe13 make dbwhere work when called at keyboard prompt
John W. Eaton <jwe@octave.org>
parents: 9483
diff changeset
111 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
112
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
113 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
114 }
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
115
7877
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
116 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
117 octave_call_stack::do_caller_user_code_line (void) const
7877
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
118 {
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
119 int retval = -1;
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
120
7890
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
121 const_iterator p = cs.end ();
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
122
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
123 while (p != cs.begin ())
7877
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
124 {
7890
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
125 const call_stack_elt& elt = *(--p);
7877
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
126
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
127 octave_function *f = elt.fcn;
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
128
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
129 if (f && f->is_user_code ())
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
130 {
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
131 tree_statement *stmt = elt.stmt;
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
132
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
133 if (stmt)
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
134 {
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
135 retval = stmt->line ();
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
136 break;
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
137 }
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
138 }
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
139 }
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
140
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
141 return retval;
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
142 }
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
143
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
144 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
145 octave_call_stack::do_caller_user_code_column (void) const
7877
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
146 {
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
147 int retval = -1;
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
148
7890
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
149 const_iterator p = cs.end ();
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
150
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
151 while (p != cs.begin ())
7877
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
152 {
7890
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
153 const call_stack_elt& elt = *(--p);
7877
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
154
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
155 octave_function *f = elt.fcn;
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
156
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
157 if (f && f->is_user_code ())
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
158 {
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
159 tree_statement *stmt = elt.stmt;
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
160
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
161 if (stmt)
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
162 {
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
163 retval = stmt->column ();
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
164 break;
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
165 }
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
166 }
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
167 }
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
168
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
169 return retval;
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
170 }
59031cfe331b lasterror fixes
John W. Eaton <jwe@octave.org>
parents: 7818
diff changeset
171
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
172 size_t
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
173 octave_call_stack::do_num_user_code_frames (octave_idx_type& curr_user_frame) const
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
174 {
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
175 size_t retval = 0;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
176
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
177 curr_user_frame = 0;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
178
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
179 // Look for the caller of dbstack.
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
180 size_t frame = cs[curr_frame].prev;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
181
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
182 bool found = false;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
183
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
184 size_t k = cs.size ();
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
185
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
186 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
187 {
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
188 octave_function *f = (*p).fcn;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
189
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
190 if (--k == frame)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
191 found = true;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
192
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
193 if (f && f->is_user_code ())
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
194 {
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
195 if (! found)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
196 curr_user_frame++;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
197
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
198 retval++;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
199 }
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
200 }
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
201
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
202 // We counted how many user frames were not the one, in reverse.
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
203 // Now set curr_user_frame to be the index in the other direction.
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
204 curr_user_frame = retval - curr_user_frame - 1;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
205
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
206 return retval;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
207 }
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
208
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
209 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
210 octave_call_stack::do_caller_user_code (size_t nskip) const
5744
1c36a2e82266 [project @ 2006-04-06 19:38:34 by jwe]
jwe
parents: 5743
diff changeset
211 {
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
212 octave_user_code *retval = 0;
5744
1c36a2e82266 [project @ 2006-04-06 19:38:34 by jwe]
jwe
parents: 5743
diff changeset
213
7890
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
214 const_iterator p = cs.end ();
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
215
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
216 while (p != cs.begin ())
5744
1c36a2e82266 [project @ 2006-04-06 19:38:34 by jwe]
jwe
parents: 5743
diff changeset
217 {
7890
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
218 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
219
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
220 octave_function *f = elt.fcn;
5744
1c36a2e82266 [project @ 2006-04-06 19:38:34 by jwe]
jwe
parents: 5743
diff changeset
221
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
222 if (f && f->is_user_code ())
5744
1c36a2e82266 [project @ 2006-04-06 19:38:34 by jwe]
jwe
parents: 5743
diff changeset
223 {
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
224 if (nskip > 0)
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
225 nskip--;
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
226 else
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
227 {
c3d21b9b94b6 eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents: 7913
diff changeset
228 retval = dynamic_cast<octave_user_code *> (f);
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 break;
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
230 }
5744
1c36a2e82266 [project @ 2006-04-06 19:38:34 by jwe]
jwe
parents: 5743
diff changeset
231 }
1c36a2e82266 [project @ 2006-04-06 19:38:34 by jwe]
jwe
parents: 5743
diff changeset
232 }
1c36a2e82266 [project @ 2006-04-06 19:38:34 by jwe]
jwe
parents: 5743
diff changeset
233
1c36a2e82266 [project @ 2006-04-06 19:38:34 by jwe]
jwe
parents: 5743
diff changeset
234 return retval;
1c36a2e82266 [project @ 2006-04-06 19:38:34 by jwe]
jwe
parents: 5743
diff changeset
235 }
1c36a2e82266 [project @ 2006-04-06 19:38:34 by jwe]
jwe
parents: 5743
diff changeset
236
7734
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
237 Octave_map
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
238 octave_call_stack::do_backtrace (size_t nskip,
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
239 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
240 {
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
241 Octave_map retval;
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
242
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
243 size_t user_code_frames = do_num_user_code_frames (curr_user_frame);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
244
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
245 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
246
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
247 // Our list is reversed.
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
248 curr_user_frame = nframes - curr_user_frame - 1;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
249
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
250 Cell keys (6, 1);
7734
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
251
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
252 keys(0) = "file";
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
253 keys(1) = "name";
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
254 keys(2) = "line";
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
255 keys(3) = "column";
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
256 keys(4) = "scope";
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
257 keys(5) = "context";
7890
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
258
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
259 Cell file (nframes, 1);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
260 Cell name (nframes, 1);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
261 Cell line (nframes, 1);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
262 Cell column (nframes, 1);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
263 Cell scope (nframes, 1);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
264 Cell context (nframes, 1);
7734
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
265
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
266 if (nframes > 0)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
267 {
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
268 int k = 0;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
269
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
270 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); 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
271 {
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
272 const call_stack_elt& elt = *p;
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
273
7736
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
274 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
275
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
276 if (f && f->is_user_code ())
7736
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
277 {
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
278 if (nskip > 0)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
279 nskip--;
7736
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
280 else
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
281 {
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
282 scope(k) = elt.scope;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
283 context(k) = elt.context;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
284
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
285 file(k) = f->fcn_file_name ();
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
286 std::string parent_fcn_name = f->parent_fcn_name ();
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
287 if (parent_fcn_name == std::string ())
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
288 name(k) = f->name ();
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
289 else
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
290 name(k) = f->parent_fcn_name () + Vfilemarker + f->name ();
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
291
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
292 tree_statement *stmt = elt.stmt;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
293
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
294 if (stmt)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
295 {
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
296 line(k) = stmt->line ();
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
297 column(k) = stmt->column ();
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
298 }
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
299 else
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
300 {
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
301 line(k) = -1;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
302 column(k) = -1;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
303 }
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
304
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
305 k++;
7736
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
306 }
7734
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
307 }
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
308 }
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
309
7736
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
310 retval.assign ("file", file);
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
311 retval.assign ("name", name);
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
312 retval.assign ("line", line);
a059b5679fbb implement dbstack
John W. Eaton <jwe@octave.org>
parents: 7734
diff changeset
313 retval.assign ("column", column);
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
314 retval.assign ("scope", scope);
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
315 retval.assign ("context", context);
7734
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
316 }
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
317
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
318 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
319 }
2dee19385d32 eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents: 7733
diff changeset
320
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
321 bool
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
322 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
323 {
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
324 bool retval = false;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
325
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
326 if (n < cs.size ())
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
327 {
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
328 retval = true;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
329
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
330 curr_frame = n;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
331
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
332 const call_stack_elt& elt = cs[n];
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
333
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
334 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
335
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
336 if (verbose)
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
337 {
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
338 octave_function *f = elt.fcn;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
339 std::string nm = f ? f->name () : std::string ("<unknown>");
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
340
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
341 tree_statement *s = elt.stmt;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
342 int l = -1;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
343 int c = -1;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
344 if (s)
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
345 {
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
346 l = s->line ();
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
347 c = s->column ();
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
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
350 octave_stdout << "stopped in " << nm
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
351 << " at line " << l << " column " << c
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
352 << " (" << elt.scope << "[" << elt.context << "])"
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
353 << std::endl;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
354 }
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
355 }
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
356
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
357 return retval;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
358 }
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
359
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
360 bool
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
361 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
362 {
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
363 bool retval = false;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
364
9483
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
365 int incr = 0;
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
366
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
367 if (nskip < 0)
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
368 incr = -1;
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
369 else if (nskip > 0)
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
370 incr = 1;
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
371
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
372 // 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
373 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
374
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
375 while (true)
7890
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
376 {
9483
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
377 if ((incr < 0 && frame == 0) || (incr > 0 && frame == cs.size () - 1))
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
378 break;
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
379
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
380 frame += incr;
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
381
9483
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
382 const call_stack_elt& elt = cs[frame];
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
383
9483
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
384 octave_function *f = elt.fcn;
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
385
9990
2b008f1d3794 octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents: 9981
diff changeset
386 if (frame == 0 || (f && f->is_user_code ()))
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
387 {
9483
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
388 if (nskip > 0)
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
389 nskip--;
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
390 else if (nskip < 0)
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
391 nskip++;
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
392
9483
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
393 if (nskip == 0)
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
394 {
9483
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
395 curr_frame = frame;
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
396 cs[cs.size () - 1].prev = curr_frame;
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
397
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
398 symbol_table::set_scope_and_context (elt.scope, elt.context);
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
399
9483
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
400 if (verbose)
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
401 {
9990
2b008f1d3794 octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents: 9981
diff changeset
402 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
403
2b008f1d3794 octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents: 9981
diff changeset
404 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
405 {
2b008f1d3794 octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents: 9981
diff changeset
406 tree_statement *s = elt.stmt;
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
407
9990
2b008f1d3794 octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents: 9981
diff changeset
408 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
409 int c = s ? s->column () : -1;
2b008f1d3794 octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents: 9981
diff changeset
410
2b008f1d3794 octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents: 9981
diff changeset
411 buf << f->name () << ": " << " line " << l
2b008f1d3794 octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents: 9981
diff changeset
412 << ", column " << c << std::endl;
2b008f1d3794 octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents: 9981
diff changeset
413 }
2b008f1d3794 octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents: 9981
diff changeset
414 else
2b008f1d3794 octave_call_stack::do_goto_frame_relative: stop searching at top frame
John W. Eaton <jwe@octave.org>
parents: 9981
diff changeset
415 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
416
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
417 octave_stdout << buf.str ();
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
418 }
9483
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
419
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
420 retval = true;
25c2e92ee03c correctly skip frame assigned to keyboard function
John W. Eaton <jwe@octave.org>
parents: 9452
diff changeset
421 break;
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
422 }
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
423 }
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
424
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
425 // 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
426 // 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
427 // jump to the new "prev" frame set above.
7890
73ef513855e7 dbstack fixes
John W. Eaton <jwe@octave.org>
parents: 7877
diff changeset
428 }
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
429
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
430 return retval;
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
431 }
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7736
diff changeset
432
5744
1c36a2e82266 [project @ 2006-04-06 19:38:34 by jwe]
jwe
parents: 5743
diff changeset
433 void
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
434 octave_call_stack::do_goto_caller_frame (void)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
435 {
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
436 size_t frame = curr_frame;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
437
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
438 bool skipped = false;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
439
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
440 while (frame != 0)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
441 {
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
442 frame = cs[frame].prev;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
443
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
444 const call_stack_elt& elt = cs[frame];
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
445
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
446 octave_function *f = elt.fcn;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
447
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
448 if (frame == 0 || (f && f->is_user_code ()))
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
449 {
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
450 if (! skipped)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
451 // We found the current user code frame, so skip it.
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
452 skipped = true;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
453 else
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
454 {
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
455 // We found the caller user code frame.
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
456 call_stack_elt tmp (elt);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
457 tmp.prev = curr_frame;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
458
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
459 curr_frame = cs.size ();
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
460
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
461 cs.push_back (tmp);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
462
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
463 symbol_table::set_scope_and_context (tmp.scope, tmp.context);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
464
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
465 break;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
466 }
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
467 }
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
468 }
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
469 }
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
470
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
471 void
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
472 octave_call_stack::do_goto_base_frame (void)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
473 {
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
474 call_stack_elt tmp (cs[0]);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
475 tmp.prev = curr_frame;
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
476
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
477 curr_frame = cs.size ();
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
478
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
479 cs.push_back (tmp);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
480
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
481 symbol_table::set_scope_and_context (tmp.scope, tmp.context);
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
482 }
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
483
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7890
diff changeset
484 void
8013
b3e667f1ab4c call backtrace_error_message in eval functions, not when popping stack
John W. Eaton <jwe@octave.org>
parents: 8011
diff changeset
485 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
486 {
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
487 if (error_state > 0)
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
488 {
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
489 error_state = -1;
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
490
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
491 error ("called from:");
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
492 }
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
493
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
494 if (! cs.empty ())
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
495 {
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
496 const call_stack_elt& elt = cs.back ();
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
497
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
498 octave_function *fcn = elt.fcn;
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
499 tree_statement *stmt = elt.stmt;
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 std::string fcn_name = "?unknown?";
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 if (fcn)
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 fcn_name = fcn->fcn_file_name ();
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
506
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
507 if (fcn_name.empty ())
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
508 fcn_name = fcn->name ();
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
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
511 int line = stmt ? stmt->line () : -1;
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
512 int column = stmt ? stmt->column () : -1;
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
513
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
514 error (" %s at line %d, column %d",
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
515 fcn_name.c_str (), line, column);
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 }
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
518
3100283874d7 improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents: 7968
diff changeset
519 void
4180
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
520 recover_from_exception (void)
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
521 {
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
522 can_interrupt = true;
4182
4d1d7c51205c [project @ 2002-11-15 20:33:47 by jwe]
jwe
parents: 4181
diff changeset
523 octave_interrupt_immediately = 0;
4180
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
524 octave_interrupt_state = 0;
5142
0f9108f298ab [project @ 2005-02-12 02:29:34 by jwe]
jwe
parents: 5102
diff changeset
525 octave_signal_caught = 0;
7481
78f3811155f7 use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents: 7409
diff changeset
526 octave_exception_state = octave_no_exception;
4180
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
527 octave_restore_signal_mask ();
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
528 octave_catch_interrupts ();
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
529 }
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
530
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
531 int
5189
85b315ad5f7d [project @ 2005-03-04 02:46:08 by jwe]
jwe
parents: 5169
diff changeset
532 main_loop (void)
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
533 {
2016
6f3428b0d2c7 [project @ 1996-03-22 09:48:38 by jwe]
jwe
parents: 1996
diff changeset
534 octave_save_signal_mask ();
6f3428b0d2c7 [project @ 1996-03-22 09:48:38 by jwe]
jwe
parents: 1996
diff changeset
535
3020
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
536 can_interrupt = true;
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
537
5142
0f9108f298ab [project @ 2005-02-12 02:29:34 by jwe]
jwe
parents: 5102
diff changeset
538 octave_signal_hook = octave_signal_handler;
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9990
diff changeset
539 octave_interrupt_hook = 0;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9990
diff changeset
540 octave_bad_alloc_hook = 0;
4429
c1f6200b5f0e [project @ 2003-06-17 04:36:08 by jwe]
jwe
parents: 4399
diff changeset
541
2554
f7e3d23f0a8f [project @ 1996-11-21 01:41:57 by jwe]
jwe
parents: 2552
diff changeset
542 octave_catch_interrupts ();
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
543
4172
2e94b2abfe6d [project @ 2002-11-12 21:14:04 by jwe]
jwe
parents: 4171
diff changeset
544 octave_initialized = true;
2e94b2abfe6d [project @ 2002-11-12 21:14:04 by jwe]
jwe
parents: 4171
diff changeset
545
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
546 // The big loop.
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
547
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
548 int retval = 0;
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
549 do
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
550 {
4180
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
551 try
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
552 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9990
diff changeset
553 unwind_protect frame;
9260
9c2349a51218 properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents: 9255
diff changeset
554
4318
115bffcecfd3 [project @ 2003-02-13 05:52:16 by jwe]
jwe
parents: 4254
diff changeset
555 reset_error_handler ();
115bffcecfd3 [project @ 2003-02-13 05:52:16 by jwe]
jwe
parents: 4254
diff changeset
556
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
557 reset_parser ();
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
558
10186
095a1e670e68 make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
559 if (symbol_table::at_top_level ())
095a1e670e68 make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
560 tree_evaluator::reset_debug_state ();
095a1e670e68 make dbstep work with keyboard function
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
561
9260
9c2349a51218 properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents: 9255
diff changeset
562 // Do this with an unwind-protect cleanup function so that
9c2349a51218 properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents: 9255
diff changeset
563 // the forced variables will be unmarked in the event of an
9c2349a51218 properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents: 9255
diff changeset
564 // interrupt.
9c2349a51218 properly unmark forced variables
John W. Eaton <jwe@octave.org>
parents: 9255
diff changeset
565 symbol_table::scope_id scope = symbol_table::top_scope ();
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9990
diff changeset
566 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
567
4753
9f0ce1536368 [project @ 2004-02-13 17:55:24 by jwe]
jwe
parents: 4748
diff changeset
568 // This is the same as yyparse in parse.y.
9f0ce1536368 [project @ 2004-02-13 17:55:24 by jwe]
jwe
parents: 4748
diff changeset
569 retval = octave_parse ();
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
570
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
571 if (retval == 0)
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
572 {
7913
f46e73bcb85b toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents: 7903
diff changeset
573 if (global_command)
3804
4073be5aefa1 [project @ 2001-02-28 08:36:04 by jwe]
jwe
parents: 3726
diff changeset
574 {
8658
73c4516fae10 New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents: 8581
diff changeset
575 global_command->accept (*current_evaluator);
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
576
7913
f46e73bcb85b toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents: 7903
diff changeset
577 delete global_command;
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
578
7913
f46e73bcb85b toplev.cc (main_loop): undo previous change; input.cc (get_debug_input): don't delete global_command here
John W. Eaton <jwe@octave.org>
parents: 7903
diff changeset
579 global_command = 0;
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
580
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
581 octave_quit ();
4171
04694e5b4239 [project @ 2002-11-12 20:27:24 by jwe]
jwe
parents: 4155
diff changeset
582
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
583 if (! (interactive || forced_interactive))
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
584 {
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4199
diff changeset
585 bool quit = (tree_return_command::returning
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4199
diff changeset
586 || tree_break_command::breaking);
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
587
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4199
diff changeset
588 if (tree_return_command::returning)
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4199
diff changeset
589 tree_return_command::returning = 0;
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
590
4207
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4199
diff changeset
591 if (tree_break_command::breaking)
fa3482b34599 [project @ 2002-12-03 18:22:05 by jwe]
jwe
parents: 4199
diff changeset
592 tree_break_command::breaking--;
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
593
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
594 if (quit)
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
595 break;
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
596 }
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
597
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
598 if (error_state)
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
599 {
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
600 if (! (interactive || forced_interactive))
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
601 {
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
602 // We should exit with a non-zero status.
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
603 retval = 1;
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
604 break;
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
605 }
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
606 }
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
607 else
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
608 {
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
609 if (octave_completion_matches_called)
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
610 octave_completion_matches_called = false;
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
611 else
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
612 command_editor::increment_current_command_number ();
3883
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
613 }
69b6bd271277 [project @ 2002-04-02 21:05:10 by jwe]
jwe
parents: 3881
diff changeset
614 }
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
615 else if (parser_end_of_input)
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
616 break;
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
617 }
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
618 }
4182
4d1d7c51205c [project @ 2002-11-15 20:33:47 by jwe]
jwe
parents: 4181
diff changeset
619 catch (octave_interrupt_exception)
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4130
diff changeset
620 {
4180
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
621 recover_from_exception ();
9383
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
622 octave_stdout << "\n";
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
623 if (quitting_gracefully)
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
624 {
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
625 clean_up_and_exit (exit_status);
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
626 break; // If user has overriden the exit func.
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
627 }
4180
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
628 }
8704
236ff50db90f load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents: 8669
diff changeset
629 catch (octave_execution_exception)
236ff50db90f load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents: 8669
diff changeset
630 {
236ff50db90f load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents: 8669
diff changeset
631 recover_from_exception ();
236ff50db90f load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents: 8669
diff changeset
632 std::cerr
236ff50db90f load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents: 8669
diff changeset
633 << "error: unhandled execution exception -- trying to return to prompt"
236ff50db90f load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents: 8669
diff changeset
634 << std::endl;
236ff50db90f load-path.cc: catch execution exception in getcwd
John W. Eaton <jwe@octave.org>
parents: 8669
diff changeset
635 }
4181
dd2abf428f5d [project @ 2002-11-15 18:33:41 by jwe]
jwe
parents: 4180
diff changeset
636 catch (std::bad_alloc)
4180
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
637 {
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
638 recover_from_exception ();
84fe3ca3a246 [project @ 2002-11-15 04:47:01 by jwe]
jwe
parents: 4173
diff changeset
639 std::cerr
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
640 << "error: memory exhausted or requested size too large for range of Octave's index type -- trying to return to prompt"
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
641 << std::endl;
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
642 }
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
643 }
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
644 while (retval == 0);
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
645
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
646 return retval;
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
647 }
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
648
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
649 // Call a function with exceptions handled to avoid problems with
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
650 // errors while shutting down.
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
651
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
652 #define IGNORE_EXCEPTION(E) \
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
653 catch (E) \
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
654 { \
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
655 std::cerr << "error: ignoring " #E " while preparing to exit" << std::endl; \
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
656 recover_from_exception (); \
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
657 }
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
658
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
659 #define SAFE_CALL(F, ARGS) \
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
660 try \
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
661 { \
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
662 F ARGS; \
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
663 } \
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
664 IGNORE_EXCEPTION (octave_interrupt_exception) \
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
665 IGNORE_EXCEPTION (octave_execution_exception) \
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
666 IGNORE_EXCEPTION (std::bad_alloc)
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
667
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
668 // Fix up things before exiting.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
669
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
670 void
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3147
diff changeset
671 clean_up_and_exit (int retval)
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3147
diff changeset
672 {
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
673 do_octave_atexit ();
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
674
9981
692ab4eaf965 clean up top-level variables when exiting Octave
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
675 // Clean up symbol table.
692ab4eaf965 clean up top-level variables when exiting Octave
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
676 SAFE_CALL (symbol_table::cleanup, ());
692ab4eaf965 clean up top-level variables when exiting Octave
Jaroslav Hajek <highegg@gmail.com>
parents: 9794
diff changeset
677
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
678 SAFE_CALL (sysdep_cleanup, ())
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5398
diff changeset
679
9217
ee7cf4d963f3 smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents: 9187
diff changeset
680 if (octave_exit)
ee7cf4d963f3 smarter handling of quit()
Jaroslav Hajek <highegg@gmail.com>
parents: 9187
diff changeset
681 (*octave_exit) (retval == EOF ? 0 : retval);
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
682 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
683
3180
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
684 DEFUN (quit, args, nargout,
3332
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
685 "-*- texinfo -*-\n\
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
686 @deftypefn {Built-in Function} {} exit (@var{status})\n\
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
687 @deftypefnx {Built-in Function} {} quit (@var{status})\n\
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
688 Exit the current Octave session. If the optional integer value\n\
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
689 @var{status} is supplied, pass that value to the operating system as the\n\
6615
687ae48b2253 [project @ 2007-05-13 06:24:57 by jwe]
jwe
parents: 6556
diff changeset
690 Octave's exit status. The default value is zero.\n\
3333
15cddaacbc2d [project @ 1999-11-03 19:53:59 by jwe]
jwe
parents: 3332
diff changeset
691 @end deftypefn")
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
692 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
693 octave_value_list retval;
2068
18365b6332a8 [project @ 1996-04-17 23:37:35 by jwe]
jwe
parents: 2016
diff changeset
694
9255
1c2d2c9f4a8d don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents: 9217
diff changeset
695 if (! quit_allowed)
1c2d2c9f4a8d don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents: 9217
diff changeset
696 error ("quit: not supported in embedded mode.");
1c2d2c9f4a8d don't allow quit() in embedded mode by default, make configurable
Jaroslav Hajek <highegg@gmail.com>
parents: 9217
diff changeset
697 else if (nargout == 0)
2068
18365b6332a8 [project @ 1996-04-17 23:37:35 by jwe]
jwe
parents: 2016
diff changeset
698 {
3180
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
699 if (args.length () > 0)
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
700 {
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
701 int tmp = args(0).nint_value ();
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
702
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
703 if (! error_state)
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
704 exit_status = tmp;
3180
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
705 }
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
706
9383
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
707 if (! error_state)
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
708 {
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
709 quitting_gracefully = true;
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
710
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
711 // Simulate interrupt.
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
712
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
713 octave_interrupt_state = -1;
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
714
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
715 octave_throw_interrupt_exception ();
d57f0c56195f improve error handling
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
716 }
2068
18365b6332a8 [project @ 1996-04-17 23:37:35 by jwe]
jwe
parents: 2016
diff changeset
717 }
3180
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
718 else
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
719 error ("quit: invalid number of output arguments");
2068
18365b6332a8 [project @ 1996-04-17 23:37:35 by jwe]
jwe
parents: 2016
diff changeset
720
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
721 return retval;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
722 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
723
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
724 DEFALIAS (exit, quit);
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
725
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1907
diff changeset
726 DEFUN (warranty, , ,
3446
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3402
diff changeset
727 "-*- texinfo -*-\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3402
diff changeset
728 @deftypefn {Built-in Function} {} warranty ()\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3402
diff changeset
729 Describe the conditions for copying and distributing Octave.\n\
5ee5afb3981a [project @ 2000-01-17 09:42:43 by jwe]
jwe
parents: 3402
diff changeset
730 @end deftypefn")
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
731 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
732 octave_value_list retval;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
733
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3892
diff changeset
734 octave_stdout << "\n" \
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3892
diff changeset
735 OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3892
diff changeset
736 \n\
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
737 This program is free software; you can redistribute it and/or modify\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
738 it under the terms of the GNU General Public License as published by\n\
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7013
diff changeset
739 the Free Software Foundation; either version 3 of the License, or\n\
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
740 (at your option) any later version.\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
741 \n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
742 This program is distributed in the hope that it will be useful,\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
743 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
744 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
745 GNU General Public License for more details.\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
746 \n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
747 You should have received a copy of the GNU General Public License\n\
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7013
diff changeset
748 along with this program. If not, see <http://www.gnu.org/licenses/>.\n\
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
749 \n";
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
750
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
751 return retval;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
752 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
753
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
754 // Execute a shell command.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
755
1965
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
756 static void
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
757 cleanup_iprocstream (void *p)
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
758 {
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
759 iprocstream *cmd = static_cast<iprocstream *> (p);
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
760
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
761 octave_child_list::remove (cmd->pid ());
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
762
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
763 delete cmd;
1965
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
764 }
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
765
6316
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
766 static int
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
767 wait_for_input (int fid)
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
768 {
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
769 int retval = -1;
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
770
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
771 #if defined (HAVE_SELECT)
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
772 if (fid >= 0)
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
773 {
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
774 fd_set set;
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
775
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
776 FD_ZERO (&set);
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
777 FD_SET (fid, &set);
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
778
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
779 retval = select (FD_SETSIZE, &set, 0, 0, 0);
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
780 }
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
781 #else
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
782 retval = 1;
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
783 #endif
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
784
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
785 return retval;
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
786 }
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
787
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
788 static octave_value_list
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
789 run_command_and_return_output (const std::string& cmd_str)
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
790 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
791 octave_value_list retval;
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
792
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
793 iprocstream *cmd = new iprocstream (cmd_str.c_str ());
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
794
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
795 if (cmd)
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
796 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9990
diff changeset
797 unwind_protect frame;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9990
diff changeset
798 frame.add (cleanup_iprocstream, cmd);
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
799
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
800 if (*cmd)
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
801 {
6316
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
802 int fid = cmd->file_number ();
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 2086
diff changeset
803
6316
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
804 std::ostringstream output_buf;
4494
93ad80b6eef6 [project @ 2003-09-03 20:27:00 by jwe]
jwe
parents: 4489
diff changeset
805
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
806 char ch;
3147
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
807
4489
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
808 for (;;)
3147
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
809 {
4489
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
810 if (cmd->get (ch))
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
811 output_buf.put (ch);
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
812 else
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
813 {
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
814 if (! cmd->eof () && errno == EAGAIN)
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
815 {
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
816 cmd->clear ();
3147
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
817
6316
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
818 if (wait_for_input (fid) != 1)
a3a2580435c2 [project @ 2007-02-16 07:23:49 by jwe]
jwe
parents: 6311
diff changeset
819 break;
4489
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
820 }
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
821 else
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
822 break;
a90c3cbded0d [project @ 2003-08-28 16:08:26 by jwe]
jwe
parents: 4440
diff changeset
823 }
3147
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
824 }
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
825
3252
9c784bd18858 [project @ 1999-07-15 00:33:12 by jwe]
jwe
parents: 3234
diff changeset
826 int cmd_status = cmd->close ();
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
827
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
828 if (WIFEXITED (cmd_status))
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
829 cmd_status = WEXITSTATUS (cmd_status);
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
830 else
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
831 cmd_status = 127;
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
832
8810
c9e1db15035b eliminate unnecessary casts
John W. Eaton <jwe@octave.org>
parents: 8772
diff changeset
833 retval(0) = cmd_status;
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5744
diff changeset
834 retval(1) = output_buf.str ();
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
835 }
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
836 }
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
837 else
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
838 error ("unable to start subprocess for `%s'", cmd_str.c_str ());
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
839
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
840 return retval;
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
841 }
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
842
5285
fe5ee25a5e6c [project @ 2005-04-19 15:02:49 by jwe]
jwe
parents: 5275
diff changeset
843 enum system_exec_type { et_sync, et_async };
fe5ee25a5e6c [project @ 2005-04-19 15:02:49 by jwe]
jwe
parents: 5275
diff changeset
844
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1907
diff changeset
845 DEFUN (system, args, nargout,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
846 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
847 @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
848 Execute a shell command specified by @var{string}. The second\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
849 argument is optional. If @var{type} is @code{\"async\"}, the process\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
850 is started in the background and the process id of the child process\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
851 is returned immediately. Otherwise, the process is started, and\n\
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8013
diff changeset
852 Octave waits until it exits. If the @var{type} argument is omitted, a\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
853 value of @code{\"sync\"} is assumed.\n\
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
854 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
855 If two input arguments are given (the actual value of\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
856 @var{return_output} is irrelevant) and the subprocess is started\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
857 synchronously, or if @var{system} is called with one input argument and\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
858 one or more output arguments, the output from the command is returned.\n\
5097
69b822a4129c [project @ 2004-12-15 18:34:02 by jwe]
jwe
parents: 4975
diff changeset
859 Otherwise, if the subprocess is executed synchronously, its output is\n\
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
860 sent to the standard output. To send the output of a command executed\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
861 with @var{system} through the pager, use a command like\n\
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
862 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
863 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
864 disp (system (cmd, 1));\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
865 @end example\n\
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
866 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
867 @noindent\n\
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
868 or\n\
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
869 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
870 @example\n\
9079
4d610aba7347 Cleanup documentation for system.texi, package.texi
Rik <rdrider0-list@yahoo.com>
parents: 9035
diff changeset
871 printf (\"%s\\n\", system (cmd, 1));\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
872 @end example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
873 \n\
5659
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5655
diff changeset
874 The @code{system} function can return two values. The first is the\n\
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5655
diff changeset
875 exit status of the command and the second is any output from the\n\
960f4b9a26af [project @ 2006-03-10 15:35:20 by jwe]
jwe
parents: 5655
diff changeset
876 command that was written to the standard output stream. For example,\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
877 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
878 @example\n\
5717
34cda7d94c08 [project @ 2006-03-27 22:26:18 by jwe]
jwe
parents: 5672
diff changeset
879 [status, output] = system (\"echo foo; exit 2\");\n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
880 @end example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
881 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
882 @noindent\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
883 will set the variable @code{output} to the string @samp{foo}, and the\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
884 variable @code{status} to the integer @samp{2}.\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
885 @end deftypefn")
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
886 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
887 octave_value_list retval;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
888
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9990
diff changeset
889 unwind_protect frame;
3834
414e694c9e6a [project @ 2001-05-17 13:45:41 by jwe]
jwe
parents: 3822
diff changeset
890
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
891 int nargin = args.length ();
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
892
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
893 if (nargin > 0 && nargin < 4)
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
894 {
5672
62734ddaf17b [project @ 2006-03-15 21:27:34 by jwe]
jwe
parents: 5659
diff changeset
895 bool return_output = (nargout > 1 || nargin > 1);
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
896
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
897 std::string cmd_str = args(0).string_value ();
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
898
5285
fe5ee25a5e6c [project @ 2005-04-19 15:02:49 by jwe]
jwe
parents: 5275
diff changeset
899 system_exec_type type = et_sync;
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
900
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
901 if (! error_state)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
902 {
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
903 if (nargin > 2)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
904 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
905 std::string type_str = args(2).string_value ();
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
906
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
907 if (! error_state)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
908 {
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
909 if (type_str == "sync")
5285
fe5ee25a5e6c [project @ 2005-04-19 15:02:49 by jwe]
jwe
parents: 5275
diff changeset
910 type = et_sync;
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
911 else if (type_str == "async")
5285
fe5ee25a5e6c [project @ 2005-04-19 15:02:49 by jwe]
jwe
parents: 5275
diff changeset
912 type = et_async;
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
913 else
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
914 error ("system: third arg must be \"sync\" or \"async\"");
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
915 }
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
916 else
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
917 error ("system: third argument must be a string");
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
918 }
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
919 }
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
920 else
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
921 error ("system: expecting std::string as first argument");
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
922
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
923 if (! error_state)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
924 {
7104
b26d0cd10a42 [project @ 2007-11-06 17:18:41 by jwe]
jwe
parents: 7017
diff changeset
925 #if defined (__WIN32__) && ! defined (__CYGWIN__)
b26d0cd10a42 [project @ 2007-11-06 17:18:41 by jwe]
jwe
parents: 7017
diff changeset
926 // Work around weird double-quote handling on Windows systems.
b26d0cd10a42 [project @ 2007-11-06 17:18:41 by jwe]
jwe
parents: 7017
diff changeset
927 if (type == et_sync)
b26d0cd10a42 [project @ 2007-11-06 17:18:41 by jwe]
jwe
parents: 7017
diff changeset
928 cmd_str = "\"" + cmd_str + "\"";
b26d0cd10a42 [project @ 2007-11-06 17:18:41 by jwe]
jwe
parents: 7017
diff changeset
929 #endif
b26d0cd10a42 [project @ 2007-11-06 17:18:41 by jwe]
jwe
parents: 7017
diff changeset
930
5285
fe5ee25a5e6c [project @ 2005-04-19 15:02:49 by jwe]
jwe
parents: 5275
diff changeset
931 if (type == et_async)
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
932 {
6222
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
933 // FIXME -- maybe this should go in sysdep.cc?
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4084
diff changeset
934 #ifdef HAVE_FORK
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
935 pid_t pid = fork ();
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
936
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
937 if (pid < 0)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
938 error ("system: fork failed -- can't create child process");
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
939 else if (pid == 0)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
940 {
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
941 // FIXME -- should probably replace this
3273
eb27ea9b7ff8 [project @ 1999-10-12 02:22:25 by jwe]
jwe
parents: 3258
diff changeset
942 // call with something portable.
eb27ea9b7ff8 [project @ 1999-10-12 02:22:25 by jwe]
jwe
parents: 3258
diff changeset
943
5510
3fadccb05d5d [project @ 2005-10-26 17:50:55 by jwe]
jwe
parents: 5498
diff changeset
944 execl ("/bin/sh", "sh", "-c", cmd_str.c_str (),
3fadccb05d5d [project @ 2005-10-26 17:50:55 by jwe]
jwe
parents: 5498
diff changeset
945 static_cast<void *> (0));
3273
eb27ea9b7ff8 [project @ 1999-10-12 02:22:25 by jwe]
jwe
parents: 3258
diff changeset
946
eb27ea9b7ff8 [project @ 1999-10-12 02:22:25 by jwe]
jwe
parents: 3258
diff changeset
947 panic_impossible ();
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
948 }
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
949 else
4254
df5f2e433a11 [project @ 2002-12-31 19:43:07 by jwe]
jwe
parents: 4238
diff changeset
950 retval(0) = pid;
6222
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
951 #elif defined (__WIN32__)
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
952 STARTUPINFO si;
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
953 PROCESS_INFORMATION pi;
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
954 ZeroMemory (&si, sizeof (si));
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
955 ZeroMemory (&pi, sizeof (pi));
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
956 OCTAVE_LOCAL_BUFFER (char, xcmd_str, cmd_str.length()+1);
6676
43fdc8e8ed28 [project @ 2007-05-31 19:35:58 by jwe]
jwe
parents: 6620
diff changeset
957 strcpy (xcmd_str, cmd_str.c_str ());
6222
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
958
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
959 if (! CreateProcess (0, xcmd_str, 0, 0, FALSE, 0, 0, 0, &si, &pi))
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
960 error ("system: CreateProcess failed -- can't create child process");
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
961 else
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
962 {
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
963 retval(0) = pi.dwProcessId;
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
964 CloseHandle (pi.hProcess);
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
965 CloseHandle (pi.hThread);
07d967f75dba [project @ 2007-01-03 20:15:15 by jwe]
jwe
parents: 6124
diff changeset
966 }
4086
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4084
diff changeset
967 #else
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4084
diff changeset
968 error ("asynchronous system calls are not supported");
ddc722b38e87 [project @ 2002-10-03 19:08:45 by jwe]
jwe
parents: 4084
diff changeset
969 #endif
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
970 }
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
971 else if (return_output)
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
972 retval = run_command_and_return_output (cmd_str);
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
973 else
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
974 {
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
975 int status = system (cmd_str.c_str ());
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
976
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
977 // The value in status is as returned by waitpid. If
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
978 // the process exited normally, extract the actual exit
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
979 // status of the command. Otherwise, return 127 as a
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
980 // failure code.
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
981
2693
f4d0604cbcc4 [project @ 1997-02-18 15:25:21 by jwe]
jwe
parents: 2692
diff changeset
982 if (WIFEXITED (status))
f4d0604cbcc4 [project @ 1997-02-18 15:25:21 by jwe]
jwe
parents: 2692
diff changeset
983 status = WEXITSTATUS (status);
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
984
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4221
diff changeset
985 retval(0) = status;
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
986 }
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
987 }
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
988 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
989 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
990 print_usage ();
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
991
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
992 return retval;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
993 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
994
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
995 DEFALIAS (shell_cmd, system);
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
996
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
997 // FIXME -- this should really be static, but that causes
2614
ae47b0911863 [project @ 1997-01-21 03:57:46 by jwe]
jwe
parents: 2554
diff changeset
998 // problems on some systems.
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
999 std::list<std::string> octave_atexit_functions;
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1000
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1001 void
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1002 do_octave_atexit (void)
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1003 {
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1004 static bool deja_vu = false;
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1005
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1006 while (! octave_atexit_functions.empty ())
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1007 {
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1008 std::string fcn = octave_atexit_functions.front ();
4214
b9317f3973ec [project @ 2002-12-04 04:57:01 by jwe]
jwe
parents: 4208
diff changeset
1009
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1010 octave_atexit_functions.pop_front ();
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1011
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
1012 SAFE_CALL (reset_error_handler, ())
5237
652e8aa49fa7 [project @ 2005-03-23 21:28:45 by jwe]
jwe
parents: 5235
diff changeset
1013
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
1014 SAFE_CALL (feval, (fcn, octave_value_list (), 0))
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3202
diff changeset
1015
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
1016 SAFE_CALL (flush_octave_stdout, ())
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1017 }
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1018
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1019 if (! deja_vu)
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1020 {
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1021 deja_vu = true;
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1022
6068
c9f0839c583f [project @ 2006-10-20 16:54:30 by jwe]
jwe
parents: 6043
diff changeset
1023 // Do this explicitly so that destructors for mex file objects
c9f0839c583f [project @ 2006-10-20 16:54:30 by jwe]
jwe
parents: 6043
diff changeset
1024 // are called, so that functions registered with mexAtExit are
c9f0839c583f [project @ 2006-10-20 16:54:30 by jwe]
jwe
parents: 6043
diff changeset
1025 // called.
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
1026 SAFE_CALL (clear_mex_functions, ())
6068
c9f0839c583f [project @ 2006-10-20 16:54:30 by jwe]
jwe
parents: 6043
diff changeset
1027
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
1028 SAFE_CALL (command_editor::restore_terminal_state, ())
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1029
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5765
diff changeset
1030 // FIXME -- is this needed? Can it cause any trouble?
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
1031 SAFE_CALL (raw_mode, (0))
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1032
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
1033 SAFE_CALL (octave_history_write_timestamp, ())
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 5285
diff changeset
1034
8735
afbfd7f4fd93 toplev.cc (do_octave_atexit): only save history if Vsaving_history is true
John W. Eaton <jwe@octave.org>
parents: 8719
diff changeset
1035 if (Vsaving_history)
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
1036 SAFE_CALL (command_history::clean_up_and_save, ())
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1037
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
1038 SAFE_CALL (close_files, ())
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1039
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
1040 SAFE_CALL (cleanup_tmp_files, ())
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1041
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
1042 SAFE_CALL (flush_octave_stdout, ())
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1043
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 5285
diff changeset
1044 if (! quitting_gracefully && (interactive || forced_interactive))
5629
489a475073d7 [project @ 2006-02-20 21:47:12 by jwe]
jwe
parents: 5510
diff changeset
1045 {
489a475073d7 [project @ 2006-02-20 21:47:12 by jwe]
jwe
parents: 5510
diff changeset
1046 octave_stdout << "\n";
489a475073d7 [project @ 2006-02-20 21:47:12 by jwe]
jwe
parents: 5510
diff changeset
1047
489a475073d7 [project @ 2006-02-20 21:47:12 by jwe]
jwe
parents: 5510
diff changeset
1048 // Yes, we want this to be separate from the call to
489a475073d7 [project @ 2006-02-20 21:47:12 by jwe]
jwe
parents: 5510
diff changeset
1049 // flush_octave_stdout above.
489a475073d7 [project @ 2006-02-20 21:47:12 by jwe]
jwe
parents: 5510
diff changeset
1050
9452
deb668d53e60 toplev.cc: handle exceptions while preparing to exit
John W. Eaton <jwe@octave.org>
parents: 9396
diff changeset
1051 SAFE_CALL (flush_octave_stdout, ())
5629
489a475073d7 [project @ 2006-02-20 21:47:12 by jwe]
jwe
parents: 5510
diff changeset
1052 }
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
1053 }
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1054 }
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1055
7409
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1056 void
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1057 octave_add_atexit_function (const std::string& fname)
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1058 {
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1059 octave_atexit_functions.push_front (fname);
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1060 }
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1061
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1062 bool
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1063 octave_remove_atexit_function (const std::string& fname)
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1064 {
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1065 bool found = false;
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1066
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1067 for (std::list<std::string>::iterator p = octave_atexit_functions.begin ();
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1068 p != octave_atexit_functions.end (); p++)
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1069 {
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1070 if (*p == fname)
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1071 {
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1072 octave_atexit_functions.erase (p);
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1073 found = true;
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1074 break;
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1075 }
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1076 }
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1077
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1078 return found;
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1079 }
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1080
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1081
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1082 DEFUN (atexit, args, nargout,
3332
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
1083 "-*- texinfo -*-\n\
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
1084 @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
1085 @deftypefnx {Built-in Function} {} atexit (@var{fcn}, @var{flag})\n\
3332
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
1086 Register a function to be called when Octave exits. For example,\n\
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1087 \n\
3332
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
1088 @example\n\
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
1089 @group\n\
9035
57649dcecb55 Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
1090 function last_words ()\n\
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6615
diff changeset
1091 disp (\"Bye bye\");\n\
3332
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
1092 endfunction\n\
9035
57649dcecb55 Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
1093 atexit (\"last_words\");\n\
3332
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
1094 @end group\n\
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
1095 @end example\n\
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
1096 \n\
7c03933635c6 [project @ 1999-11-02 06:57:12 by jwe]
jwe
parents: 3325
diff changeset
1097 @noindent\n\
6620
bf4bdc21dc8d [project @ 2007-05-14 17:35:46 by jwe]
jwe
parents: 6615
diff changeset
1098 will print the message \"Bye bye\" when Octave exits.\n\
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1099 \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
1100 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
1101 @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
1102 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
1103 @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
1104 after registering the function @code{last_words} above,\n\
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1105 \n\
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1106 @example\n\
9035
57649dcecb55 Documentation cleanup of basics.texi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
1107 atexit (\"last_words\", false);\n\
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1108 @end example\n\
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1109 \n\
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1110 @noindent\n\
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1111 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
1112 @code{last_words} when it exits.\n\
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1113 \n\
7001
8b0cfeb06365 [project @ 2007-10-10 18:02:59 by jwe]
jwe
parents: 6789
diff changeset
1114 Note that @code{atexit} only removes the first occurrence of a function\n\
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1115 from the list, so if a function was placed in the list multiple\n\
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1116 times with @code{atexit}, it must also be removed from the list\n\
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1117 multiple times.\n\
3333
15cddaacbc2d [project @ 1999-11-03 19:53:59 by jwe]
jwe
parents: 3332
diff changeset
1118 @end deftypefn")
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1119 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
1120 octave_value_list retval;
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1121
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1122 int nargin = args.length ();
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1123
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1124 if (nargin == 1 || nargin == 2)
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1125 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1126 std::string arg = args(0).string_value ();
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1127
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1128 if (! error_state)
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1129 {
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1130 bool add_mode = true;
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1131
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1132 if (nargin == 2)
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1133 {
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1134 add_mode = args(1).bool_value ();
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1135
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1136 if (error_state)
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1137 error ("atexit: second argument must be a logical value");
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1138 }
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1139
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1140 if (! error_state)
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1141 {
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1142 if (add_mode)
7409
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1143 octave_add_atexit_function (arg);
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1144 else
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1145 {
7409
73036cdd855d [project @ 2008-01-22 20:31:59 by jwe]
jwe
parents: 7361
diff changeset
1146 bool found = octave_remove_atexit_function (arg);
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1147
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1148 if (nargout > 0)
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1149 retval(0) = found;
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1150 }
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1151 }
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1152 }
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1153 else
6680
cd39d4a0b671 [project @ 2007-05-31 20:23:45 by jwe]
jwe
parents: 6676
diff changeset
1154 error ("atexit: argument must be a string");
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1155 }
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1156 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
1157 print_usage ();
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1158
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1159 return retval;
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1160 }
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
1161
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1162 DEFUN (octave_config_info, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
1163 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
1164 @deftypefn {Built-in Function} {} octave_config_info (@var{option})\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
1165 Return a structure containing configuration and installation\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
1166 information for Octave.\n\
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1167 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
1168 if @var{option} is a string, return the configuration information for the\n\
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1169 specified option.\n\
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1170 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
1171 @end deftypefn")
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
1172 {
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1173 octave_value retval;
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1174
4128
919b2f6573ee [project @ 2002-10-25 20:36:14 by jwe]
jwe
parents: 4111
diff changeset
1175 #if defined (ENABLE_DYNAMIC_LINKING)
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1176 bool octave_supports_dynamic_linking = true;
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1177 #else
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1178 bool octave_supports_dynamic_linking = false;
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1179 #endif
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1180
4357
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1181 static bool initialized = false;
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1182 static Octave_map m;
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
1183
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1184 struct conf_info_struct
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1185 {
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1186 bool subst_home;
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1187 const char *key;
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1188 const char *val;
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1189 };
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1190
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1191 static const conf_info_struct conf_info[] =
4357
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1192 {
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1193 { false, "ALL_CFLAGS", OCTAVE_CONF_ALL_CFLAGS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1194 { false, "ALL_CXXFLAGS", OCTAVE_CONF_ALL_CXXFLAGS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1195 { false, "ALL_FFLAGS", OCTAVE_CONF_ALL_FFLAGS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1196 { false, "ALL_LDFLAGS", OCTAVE_CONF_ALL_LDFLAGS },
9523
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1197 { false, "AMD_CPPFLAGS", OCTAVE_CONF_AMD_CPPFLAGS },
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1198 { false, "AMD_LDFLAGS", OCTAVE_CONF_AMD_LDFLAGS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1199 { false, "AMD_LIBS", OCTAVE_CONF_AMD_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1200 { false, "AR", OCTAVE_CONF_AR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1201 { false, "ARFLAGS", OCTAVE_CONF_ARFLAGS },
9568
d3fccc4c4b9e use OCTAVE_CHECK_LIBRARY to check for ARPACK
John W. Eaton <jwe@octave.org>
parents: 9542
diff changeset
1202 { false, "ARPACK_CPPFLAGS", OCTAVE_CONF_ARPACK_CPPFLAGS },
d3fccc4c4b9e use OCTAVE_CHECK_LIBRARY to check for ARPACK
John W. Eaton <jwe@octave.org>
parents: 9542
diff changeset
1203 { false, "ARPACK_LDFLAGS", OCTAVE_CONF_ARPACK_LDFLAGS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1204 { false, "ARPACK_LIBS", OCTAVE_CONF_ARPACK_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1205 { false, "BLAS_LIBS", OCTAVE_CONF_BLAS_LIBS },
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
1206 { false, "CARBON_LIBS", OCTAVE_CONF_CARBON_LIBS },
9523
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1207 { false, "CAMD_CPPFLAGS", OCTAVE_CONF_CAMD_CPPFLAGS },
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1208 { false, "CAMD_LDFLAGS", OCTAVE_CONF_CAMD_LDFLAGS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1209 { false, "CAMD_LIBS", OCTAVE_CONF_CAMD_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1210 { false, "CC", OCTAVE_CONF_CC },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1211 { false, "CC_VERSION", OCTAVE_CONF_CC_VERSION },
9523
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1212 { false, "CCOLAMD_CPPFLAGS", OCTAVE_CONF_CCOLAMD_CPPFLAGS },
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1213 { false, "CCOLAMD_LDFLAGS", OCTAVE_CONF_CCOLAMD_LDFLAGS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1214 { false, "CCOLAMD_LIBS", OCTAVE_CONF_CCOLAMD_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1215 { false, "CFLAGS", OCTAVE_CONF_CFLAGS },
9523
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1216 { false, "CHOLMOD_CPPFLAGS", OCTAVE_CONF_CHOLMOD_CPPFLAGS },
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1217 { false, "CHOLMOD_LDFLAGS", OCTAVE_CONF_CHOLMOD_LDFLAGS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1218 { false, "CHOLMOD_LIBS", OCTAVE_CONF_CHOLMOD_LIBS },
9523
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1219 { false, "COLAMD_CPPFLAGS", OCTAVE_CONF_COLAMD_CPPFLAGS },
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1220 { false, "COLAMD_LDFLAGS", OCTAVE_CONF_COLAMD_LDFLAGS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1221 { false, "COLAMD_LIBS", OCTAVE_CONF_COLAMD_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1222 { false, "CPICFLAG", OCTAVE_CONF_CPICFLAG },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1223 { 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
1224 { 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
1225 { false, "CURL_LDFLAGS", OCTAVE_CONF_CURL_LDFLAGS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1226 { false, "CURL_LIBS", OCTAVE_CONF_CURL_LIBS },
9523
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1227 { false, "CXSPARSE_CPPFLAGS", OCTAVE_CONF_CXSPARSE_CPPFLAGS },
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1228 { false, "CXSPARSE_LDFLAGS", OCTAVE_CONF_CXSPARSE_LDFLAGS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1229 { false, "CXSPARSE_LIBS", OCTAVE_CONF_CXSPARSE_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1230 { false, "CXX", OCTAVE_CONF_CXX },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1231 { false, "CXXCPP", OCTAVE_CONF_CXXCPP },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1232 { false, "CXXFLAGS", OCTAVE_CONF_CXXFLAGS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1233 { false, "CXXPICFLAG", OCTAVE_CONF_CXXPICFLAG },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1234 { false, "CXX_VERSION", OCTAVE_CONF_CXX_VERSION },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1235 { false, "DEFAULT_PAGER", OCTAVE_DEFAULT_PAGER },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1236 { false, "DEFS", OCTAVE_CONF_DEFS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1237 { false, "DL_LD", OCTAVE_CONF_DL_LD },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1238 { false, "DL_LDFLAGS", OCTAVE_CONF_DL_LDFLAGS },
9515
eee9b3150446 more configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9514
diff changeset
1239 { false, "DL_LIBS", OCTAVE_CONF_DL_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1240 { false, "ENABLE_DYNAMIC_LINKING", OCTAVE_CONF_ENABLE_DYNAMIC_LINKING },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1241 { false, "EXEEXT", OCTAVE_CONF_EXEEXT },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1242 { false, "F77", OCTAVE_CONF_F77 },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1243 { false, "F77_FLOAT_STORE_FLAG", OCTAVE_CONF_F77_FLOAT_STORE_FLAG },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1244 { false, "FC", OCTAVE_CONF_FC },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1245 { false, "FFLAGS", OCTAVE_CONF_FFLAGS },
9523
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1246 { false, "FFTW3_CPPFLAGS", OCTAVE_CONF_FFTW3_CPPFLAGS },
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1247 { false, "FFTW3_LDFLAGS", OCTAVE_CONF_FFTW3_LDFLAGS },
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1248 { false, "FFTW3_LIBS", OCTAVE_CONF_FFTW3_LIBS },
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1249 { false, "FFTW3F_CPPFLAGS", OCTAVE_CONF_FFTW3F_CPPFLAGS },
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1250 { false, "FFTW3F_LDFLAGS", OCTAVE_CONF_FFTW3F_LDFLAGS },
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1251 { false, "FFTW3F_LIBS", OCTAVE_CONF_FFTW3F_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1252 { false, "FLIBS", OCTAVE_CONF_FLIBS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1253 { false, "FPICFLAG", OCTAVE_CONF_FPICFLAG },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1254 { false, "FT2_LIBS", OCTAVE_CONF_FT2_LIBS },
9523
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1255 { false, "GLPK_CPPFLAGS", OCTAVE_CONF_GLPK_CPPFLAGS },
0ce82753dd72 more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents: 9519
diff changeset
1256 { false, "GLPK_LDFLAGS", OCTAVE_CONF_GLPK_LDFLAGS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1257 { false, "GLPK_LIBS", OCTAVE_CONF_GLPK_LIBS },
7361
a2870fd8ac58 [project @ 2008-01-12 07:50:54 by jwe]
jwe
parents: 7336
diff changeset
1258 { false, "GNUPLOT", OCTAVE_CONF_GNUPLOT },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1259 { 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
1260 { 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
1261 { false, "HDF5_LDFLAGS", OCTAVE_CONF_HDF5_LDFLAGS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1262 { false, "HDF5_LIBS", OCTAVE_CONF_HDF5_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1263 { false, "INCFLAGS", OCTAVE_CONF_INCFLAGS },
9794
0d4613a736e9 convert build system to use automake and libtool
John W. Eaton <jwe@octave.org>
parents: 9575
diff changeset
1264 { false, "LAPACK_LIBS", OCTAVE_CONF_LAPACK_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1265 { false, "LDFLAGS", OCTAVE_CONF_LDFLAGS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1266 { false, "LD_CXX", OCTAVE_CONF_LD_CXX },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1267 { false, "LD_STATIC_FLAG", OCTAVE_CONF_LD_STATIC_FLAG },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1268 { false, "LEX", OCTAVE_CONF_LEX },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1269 { false, "LEXLIB", OCTAVE_CONF_LEXLIB },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1270 { false, "LFLAGS", OCTAVE_CONF_LFLAGS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1271 { false, "LIBCRUFT", OCTAVE_CONF_LIBCRUFT },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1272 { false, "LIBEXT", OCTAVE_CONF_LIBEXT },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1273 { false, "LIBFLAGS", OCTAVE_CONF_LIBFLAGS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1274 { false, "LIBOCTAVE", OCTAVE_CONF_LIBOCTAVE },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1275 { false, "LIBOCTINTERP", OCTAVE_CONF_LIBOCTINTERP },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1276 { false, "LIBS", OCTAVE_CONF_LIBS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1277 { 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
1278 { false, "MAGICK_CPPFLAGS", OCTAVE_CONF_MAGICK_CPPFLAGS },
55ecaefb7d0f Use pkg-config to configure GraphicsMagick++.
David Grundberg <individ@acc.umu.se>
parents: 9572
diff changeset
1279 { 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
1280 { false, "MAGICK_LIBS", OCTAVE_CONF_MAGICK_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1281 { false, "MKOCTFILE_DL_LDFLAGS", OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1282 { false, "OPENGL_LIBS", OCTAVE_CONF_OPENGL_LIBS },
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1283 { false, "PTHREAD_CFLAGS", OCTAVE_CONF_PTHREAD_CFLAGS },
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1284 { 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
1285 { 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
1286 { false, "QHULL_LDFLAGS", OCTAVE_CONF_QHULL_LDFLAGS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1287 { 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
1288 { 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
1289 { false, "QRUPDATE_LDFLAGS", OCTAVE_CONF_QRUPDATE_LDFLAGS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1290 { false, "QRUPDATE_LIBS", OCTAVE_CONF_QRUPDATE_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1291 { false, "RANLIB", OCTAVE_CONF_RANLIB },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1292 { false, "RDYNAMIC_FLAG", OCTAVE_CONF_RDYNAMIC_FLAG },
9515
eee9b3150446 more configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9514
diff changeset
1293 { false, "READLINE_LIBS", OCTAVE_CONF_READLINE_LIBS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1294 { false, "REGEX_LIBS", OCTAVE_CONF_REGEX_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1295 { false, "RLD_FLAG", OCTAVE_CONF_RLD_FLAG },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1296 { false, "SED", OCTAVE_CONF_SED },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1297 { false, "SHARED_LIBS", OCTAVE_CONF_SHARED_LIBS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1298 { false, "SHLEXT", OCTAVE_CONF_SHLEXT },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1299 { false, "SHLEXT_VER", OCTAVE_CONF_SHLEXT_VER },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1300 { false, "SH_LD", OCTAVE_CONF_SH_LD },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1301 { false, "SH_LDFLAGS", OCTAVE_CONF_SH_LDFLAGS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1302 { false, "SONAME_FLAGS", OCTAVE_CONF_SONAME_FLAGS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1303 { false, "STATIC_LIBS", OCTAVE_CONF_STATIC_LIBS },
9515
eee9b3150446 more configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9514
diff changeset
1304 { false, "TERM_LIBS", OCTAVE_CONF_TERM_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1305 { 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
1306 { 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
1307 { false, "UMFPACK_LDFLAGS", OCTAVE_CONF_UMFPACK_LDFLAGS },
9514
af86991d8d47 configure tweaks
John W. Eaton <jwe@octave.org>
parents: 9484
diff changeset
1308 { false, "UMFPACK_LIBS", OCTAVE_CONF_UMFPACK_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1309 { false, "USE_64_BIT_IDX_T", OCTAVE_CONF_USE_64_BIT_IDX_T },
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
1310 { 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
1311 { false, "X11_LIBS", OCTAVE_CONF_X11_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1312 { false, "XTRA_CFLAGS", OCTAVE_CONF_XTRA_CFLAGS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1313 { false, "XTRA_CXXFLAGS", OCTAVE_CONF_XTRA_CXXFLAGS },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1314 { false, "YACC", OCTAVE_CONF_YACC },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1315 { 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
1316 { 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
1317 { 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
1318 { false, "Z_LIBS", OCTAVE_CONF_Z_LIBS },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1319 { false, "api_version", OCTAVE_API_VERSION },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1320 { true, "archlibdir", OCTAVE_ARCHLIBDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1321 { true, "bindir", OCTAVE_BINDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1322 { false, "canonical_host_type", OCTAVE_CANONICAL_HOST_TYPE },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1323 { false, "config_opts", OCTAVE_CONF_config_opts },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1324 { true, "datadir", OCTAVE_DATADIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1325 { true, "datarootdir", OCTAVE_DATAROOTDIR },
6276
d26c558691cd [project @ 2007-02-07 09:01:24 by jwe]
jwe
parents: 6274
diff changeset
1326 { true, "exec_prefix", OCTAVE_EXEC_PREFIX },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1327 { true, "fcnfiledir", OCTAVE_FCNFILEDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1328 { true, "imagedir", OCTAVE_IMAGEDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1329 { true, "includedir", OCTAVE_INCLUDEDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1330 { true, "infodir", OCTAVE_INFODIR },
6276
d26c558691cd [project @ 2007-02-07 09:01:24 by jwe]
jwe
parents: 6274
diff changeset
1331 { true, "infofile", OCTAVE_INFOFILE },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1332 { true, "libdir", OCTAVE_LIBDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1333 { true, "libexecdir", OCTAVE_LIBEXECDIR },
6311
e2a1aca62551 [project @ 2007-02-15 21:18:34 by jwe]
jwe
parents: 6276
diff changeset
1334 { true, "localapiarchlibdir", OCTAVE_LOCALAPIARCHLIBDIR },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1335 { true, "localapifcnfiledir", OCTAVE_LOCALAPIFCNFILEDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1336 { true, "localapioctfiledir", OCTAVE_LOCALAPIOCTFILEDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1337 { true, "localarchlibdir", OCTAVE_LOCALARCHLIBDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1338 { true, "localfcnfiledir", OCTAVE_LOCALFCNFILEDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1339 { true, "localoctfiledir", OCTAVE_LOCALOCTFILEDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1340 { true, "localstartupfiledir", OCTAVE_LOCALSTARTUPFILEDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1341 { true, "localverarchlibdir", OCTAVE_LOCALVERARCHLIBDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1342 { true, "localverfcnfiledir", OCTAVE_LOCALVERFCNFILEDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1343 { true, "localveroctfiledir", OCTAVE_LOCALVEROCTFILEDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1344 { true, "man1dir", OCTAVE_MAN1DIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1345 { false, "man1ext", OCTAVE_MAN1EXT },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1346 { true, "mandir", OCTAVE_MANDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1347 { true, "octfiledir", OCTAVE_OCTFILEDIR },
8719
679c270b7584 install DOC and NEWS in $octetcdir
John W. Eaton <jwe@octave.org>
parents: 8704
diff changeset
1348 { true, "octetcdir", OCTAVE_OCTETCDIR },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1349 { true, "octincludedir", OCTAVE_OCTINCLUDEDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1350 { true, "octlibdir", OCTAVE_OCTLIBDIR },
6276
d26c558691cd [project @ 2007-02-07 09:01:24 by jwe]
jwe
parents: 6274
diff changeset
1351 { true, "prefix", OCTAVE_PREFIX },
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1352 { true, "startupfiledir", OCTAVE_STARTUPFILEDIR },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1353 { false, "version", OCTAVE_VERSION },
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1354 { false, 0, 0 }
4357
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1355 };
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1356
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1357 if (! initialized)
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1358 {
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4494
diff changeset
1359 m.assign ("dld", octave_value (octave_supports_dynamic_linking));
4357
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1360
4697
c26904f532f1 [project @ 2004-01-16 17:49:20 by jwe]
jwe
parents: 4691
diff changeset
1361 oct_mach_info::float_format ff = oct_mach_info::native_float_format ();
c26904f532f1 [project @ 2004-01-16 17:49:20 by jwe]
jwe
parents: 4691
diff changeset
1362 m.assign ("float_format",
c26904f532f1 [project @ 2004-01-16 17:49:20 by jwe]
jwe
parents: 4691
diff changeset
1363 octave_value (oct_mach_info::float_format_as_string (ff)));
c26904f532f1 [project @ 2004-01-16 17:49:20 by jwe]
jwe
parents: 4691
diff changeset
1364
c26904f532f1 [project @ 2004-01-16 17:49:20 by jwe]
jwe
parents: 4691
diff changeset
1365 m.assign ("words_big_endian",
c26904f532f1 [project @ 2004-01-16 17:49:20 by jwe]
jwe
parents: 4691
diff changeset
1366 octave_value (oct_mach_info::words_big_endian ()));
c26904f532f1 [project @ 2004-01-16 17:49:20 by jwe]
jwe
parents: 4691
diff changeset
1367
c26904f532f1 [project @ 2004-01-16 17:49:20 by jwe]
jwe
parents: 4691
diff changeset
1368 m.assign ("words_little_endian",
c26904f532f1 [project @ 2004-01-16 17:49:20 by jwe]
jwe
parents: 4691
diff changeset
1369 octave_value (oct_mach_info::words_little_endian ()));
c26904f532f1 [project @ 2004-01-16 17:49:20 by jwe]
jwe
parents: 4691
diff changeset
1370
4357
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1371 int i = 0;
4440
0bca8443db39 [project @ 2003-07-02 22:45:29 by jwe]
jwe
parents: 4429
diff changeset
1372
0bca8443db39 [project @ 2003-07-02 22:45:29 by jwe]
jwe
parents: 4429
diff changeset
1373 while (true)
4357
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1374 {
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1375 const conf_info_struct& elt = conf_info[i++];
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1376
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1377 const char *key = elt.key;
4357
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1378
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1379 if (key)
6274
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1380 {
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1381 if (elt.subst_home)
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1382 m.assign (key, octave_value (subst_octave_home (elt.val)));
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1383 else
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1384 m.assign (key, octave_value (elt.val));
d42abdfcb8e9 [project @ 2007-02-07 07:22:02 by jwe]
jwe
parents: 6222
diff changeset
1385 }
4357
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1386 else
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1387 break;
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1388 }
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1389
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1390 bool unix_system = true;
7013
f943e9635115 [project @ 2007-10-11 19:39:02 by jwe]
jwe
parents: 7010
diff changeset
1391 bool mac_system = false;
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1392 bool windows_system = false;
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1393
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1394 #if defined (WIN32)
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1395 windows_system = true;
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1396 #if !defined (__CYGWIN__)
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1397 unix_system = false;
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1398 #endif
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1399 #endif
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1400
8574
83b8c739d626 toplev.cc: check OCTAVE_USE_OS_X_API instead of __APPLE__ && __MACH__
John W. Eaton <jwe@octave.org>
parents: 8377
diff changeset
1401 #if defined (OCTAVE_USE_OS_X_API)
7010
f7d2f54008f5 [project @ 2007-10-11 17:50:34 by jwe]
jwe
parents: 7001
diff changeset
1402 mac_system = true;
f7d2f54008f5 [project @ 2007-10-11 17:50:34 by jwe]
jwe
parents: 7001
diff changeset
1403 #endif
f7d2f54008f5 [project @ 2007-10-11 17:50:34 by jwe]
jwe
parents: 7001
diff changeset
1404
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1405 m.assign ("unix", octave_value (unix_system));
7010
f7d2f54008f5 [project @ 2007-10-11 17:50:34 by jwe]
jwe
parents: 7001
diff changeset
1406 m.assign ("mac", octave_value (mac_system));
4691
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1407 m.assign ("windows", octave_value (windows_system));
bdc51b369a78 [project @ 2004-01-10 18:16:02 by jwe]
jwe
parents: 4675
diff changeset
1408
4357
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1409 initialized = true;
d700cfed902a [project @ 2003-02-22 18:48:18 by jwe]
jwe
parents: 4356
diff changeset
1410 }
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
1411
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1412 int nargin = args.length ();
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1413
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1414 if (nargin == 1)
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1415 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
1416 std::string arg = args(0).string_value ();
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1417
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1418 if (! error_state)
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4494
diff changeset
1419 {
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4494
diff changeset
1420 Cell c = m.contents (arg.c_str ());
5199
16a6247730d9 [project @ 2005-03-10 20:24:45 by jwe]
jwe
parents: 5189
diff changeset
1421
16a6247730d9 [project @ 2005-03-10 20:24:45 by jwe]
jwe
parents: 5189
diff changeset
1422 if (c.is_empty ())
16a6247730d9 [project @ 2005-03-10 20:24:45 by jwe]
jwe
parents: 5189
diff changeset
1423 error ("octave_config_info: no info for `%s'", arg.c_str ());
16a6247730d9 [project @ 2005-03-10 20:24:45 by jwe]
jwe
parents: 5189
diff changeset
1424 else
16a6247730d9 [project @ 2005-03-10 20:24:45 by jwe]
jwe
parents: 5189
diff changeset
1425 retval = c(0);
4675
f6d6335c08f6 [project @ 2003-12-16 05:11:26 by jwe]
jwe
parents: 4494
diff changeset
1426 }
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1427 }
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1428 else if (nargin == 0)
4233
ccfdb55c8156 [project @ 2002-12-20 22:43:54 by jwe]
jwe
parents: 4221
diff changeset
1429 retval = m;
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1430 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5814
diff changeset
1431 print_usage ();
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1432
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
1433 return retval;
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
1434 }
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
1435
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1436 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE)
2806
187d5321cfa3 [project @ 1997-03-11 05:13:15 by jwe]
jwe
parents: 2802
diff changeset
1437
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1438 int debug_new_delete = 0;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1439
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1440 typedef void (*vfp)(void);
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1441 extern vfp __new_handler;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1442
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1443 void *
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1444 __builtin_new (size_t sz)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1445 {
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1446 void *p;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1447
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1448 /* malloc (0) is unpredictable; avoid it. */
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1449 if (sz == 0)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1450 sz = 1;
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2796
diff changeset
1451 p = malloc (sz);
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1452 while (p == 0)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1453 {
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1454 (*__new_handler) ();
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2796
diff changeset
1455 p = malloc (sz);
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1456 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1457
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1458 if (debug_new_delete)
5629
489a475073d7 [project @ 2006-02-20 21:47:12 by jwe]
jwe
parents: 5510
diff changeset
1459 std::cerr << "__builtin_new: " << p << std::endl;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1460
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1461 return p;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1462 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1463
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1464 void
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1465 __builtin_delete (void *ptr)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1466 {
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1467 if (debug_new_delete)
5629
489a475073d7 [project @ 2006-02-20 21:47:12 by jwe]
jwe
parents: 5510
diff changeset
1468 std::cerr << "__builtin_delete: " << ptr << std::endl;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1469
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1470 if (ptr)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1471 free (ptr);
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1472 }
2806
187d5321cfa3 [project @ 1997-03-11 05:13:15 by jwe]
jwe
parents: 2802
diff changeset
1473
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
1474 #endif