annotate src/toplev.cc @ 3325:2efa28a91e7a

[project @ 1999-10-29 21:39:20 by jwe]
author jwe
date Fri, 29 Oct 1999 21:39:31 +0000
parents 7ae1928ca623
children 7c03933635c6
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
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 2831
diff changeset
3 Copyright (C) 1996, 1997 John W. Eaton
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
4
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
6
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
7 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
8 under the terms of the GNU General Public License as published by the
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
10 later version.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
11
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
12 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
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
14 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
15 for more details.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
16
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
20
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 #ifdef HAVE_CONFIG_H
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
25 #endif
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
26
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
27 #include <cassert>
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
28 #include <csetjmp>
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
29 #include <csignal>
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>
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
32
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1704
diff changeset
33 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1704
diff changeset
34
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
35 #include <fstream.h>
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
36 #include <iostream.h>
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
37 #include <strstream.h>
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
38
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
39 #ifdef HAVE_UNISTD_H
2442
f667d7ec08b9 [project @ 1996-10-30 18:46:22 by jwe]
jwe
parents: 2439
diff changeset
40 #ifdef HAVE_SYS_TYPES_H
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
41 #include <sys/types.h>
2442
f667d7ec08b9 [project @ 1996-10-30 18:46:22 by jwe]
jwe
parents: 2439
diff changeset
42 #endif
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
43 #include <unistd.h>
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
44 #endif
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
45
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2910
diff changeset
46 #include "cmd-edit.h"
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2910
diff changeset
47 #include "file-ops.h"
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
48 #include "lo-error.h"
2370
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2322
diff changeset
49 #include "lo-mappers.h"
3020
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
50 #include "oct-env.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1751
diff changeset
51 #include "str-vec.h"
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
52
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2475
diff changeset
53 #include <defaults.h>
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
54 #include "defun.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
55 #include "error.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
56 #include "file-io.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
57 #include "input.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
58 #include "lex.h"
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2475
diff changeset
59 #include <oct-conf.h>
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1728
diff changeset
60 #include "oct-hist.h"
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
61 #include "oct-map.h"
2862
95e85daad148 [project @ 1997-04-15 22:00:57 by jwe]
jwe
parents: 2859
diff changeset
62 #include "oct-obj.h"
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
63 #include "pager.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
64 #include "parse.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
65 #include "pathsearch.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
66 #include "procstream.h"
2370
a45c7d64b5e3 [project @ 1996-10-11 23:51:15 by jwe]
jwe
parents: 2322
diff changeset
67 #include "ov.h"
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
68 #include "pt-jump.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
69 #include "pt-plot.h"
2982
20f5cec4f11c [project @ 1997-05-16 03:29:26 by jwe]
jwe
parents: 2973
diff changeset
70 #include "pt-stmt.h"
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
71 #include "sighandlers.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
72 #include "sysdep.h"
2693
f4d0604cbcc4 [project @ 1997-02-18 15:25:21 by jwe]
jwe
parents: 2692
diff changeset
73 #include "syswait.h"
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
74 #include "toplev.h"
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
75 #include "unwind-prot.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
76 #include "utils.h"
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
77 #include "variables.h"
2492
06595bc7f2d0 [project @ 1996-11-09 00:13:50 by jwe]
jwe
parents: 2475
diff changeset
78 #include <version.h>
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
79
3020
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
80 // TRUE means we are exiting via the builtin exit or quit functions.
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
81 static bool quitting_gracefully = false;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
82
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
83 // Current command to execute.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
84 tree_statement_list *global_command = 0;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
85
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
86 // Pointer to function that is currently being evaluated.
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2862
diff changeset
87 octave_user_function *curr_function = 0;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
88
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
89 // Top level context (?)
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
90 jmp_buf toplevel;
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
91
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
92 int
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
93 main_loop (void)
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
94 {
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
95 // Allow the user to interrupt us without exiting.
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
96
2016
6f3428b0d2c7 [project @ 1996-03-22 09:48:38 by jwe]
jwe
parents: 1996
diff changeset
97 octave_save_signal_mask ();
6f3428b0d2c7 [project @ 1996-03-22 09:48:38 by jwe]
jwe
parents: 1996
diff changeset
98
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
99 if (setjmp (toplevel) != 0)
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
100 {
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
101 raw_mode (0);
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
102
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
103 cout << "\n";
2016
6f3428b0d2c7 [project @ 1996-03-22 09:48:38 by jwe]
jwe
parents: 1996
diff changeset
104
6f3428b0d2c7 [project @ 1996-03-22 09:48:38 by jwe]
jwe
parents: 1996
diff changeset
105 octave_restore_signal_mask ();
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
106 }
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
107
3020
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
108 can_interrupt = true;
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
109
2554
f7e3d23f0a8f [project @ 1996-11-21 01:41:57 by jwe]
jwe
parents: 2552
diff changeset
110 octave_catch_interrupts ();
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
111
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
112 // The big loop.
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
113
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
114 int retval;
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
115 do
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
116 {
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
117 curr_sym_tab = top_level_sym_tab;
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
118
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
119 reset_parser ();
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
120
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
121 retval = yyparse ();
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
122
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
123 if (retval == 0 && global_command)
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
124 {
2898
8303749672be [project @ 1997-04-28 20:50:36 by jwe]
jwe
parents: 2891
diff changeset
125 global_command->eval ();
2299
f296bbc757a1 [project @ 1996-06-23 03:45:44 by jwe]
jwe
parents: 2204
diff changeset
126
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
127 delete global_command;
2299
f296bbc757a1 [project @ 1996-06-23 03:45:44 by jwe]
jwe
parents: 2204
diff changeset
128
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
129 global_command = 0;
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
130
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
131 if (! (interactive || forced_interactive))
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
132 {
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
133 bool quit = (tree_return_command::returning
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
134 || tree_break_command::breaking);
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
135
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
136 if (tree_return_command::returning)
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
137 tree_return_command::returning = 0;
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
138
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
139 if (tree_break_command::breaking)
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2982
diff changeset
140 tree_break_command::breaking--;
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
141
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
142 if (quit)
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
143 break;
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
144 }
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
145
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
146 if (error_state)
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
147 {
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
148 if (! (interactive || forced_interactive))
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
149 break;
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
150 }
2299
f296bbc757a1 [project @ 1996-06-23 03:45:44 by jwe]
jwe
parents: 2204
diff changeset
151 else
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
152 {
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
153 if (octave_completion_matches_called)
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
154 octave_completion_matches_called = false;
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
155 else
2973
ef3379196bcf [project @ 1997-05-15 19:27:38 by jwe]
jwe
parents: 2942
diff changeset
156 command_editor::increment_current_command_number ();
2620
5c773d4745d6 [project @ 1997-01-23 16:26:25 by jwe]
jwe
parents: 2614
diff changeset
157 }
1907
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
158 }
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
159 }
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
160 while (retval == 0);
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
161
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
162 return retval;
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
163 }
8c6cea97eb80 [project @ 1996-02-10 01:12:46 by jwe]
jwe
parents: 1884
diff changeset
164
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
165 // Fix up things before exiting.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
166
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
167 void
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3147
diff changeset
168 clean_up_and_exit (int retval)
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3147
diff changeset
169 {
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
170 do_octave_atexit ();
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
171
3162
7c96e85c76db [project @ 1998-04-08 18:19:35 by jwe]
jwe
parents: 3147
diff changeset
172 exit (retval == EOF ? 0 : retval);
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
173 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
174
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1907
diff changeset
175 DEFUN_TEXT (casesen, args, ,
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
176 "casesen [on|off]")
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
177 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
178 octave_value_list retval;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
179
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1751
diff changeset
180 int argc = args.length () + 1;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1751
diff changeset
181
1965
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
182 string_vector argv = args.make_argv ("casesen");
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
183
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1751
diff changeset
184 if (error_state)
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1751
diff changeset
185 return retval;
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1751
diff changeset
186
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1751
diff changeset
187 if (argc == 1 || (argc > 1 && argv[1] == "off"))
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
188 warning ("casesen: sorry, Octave is always case sensitive");
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1751
diff changeset
189 else if (argc > 1 && argv[1] == "on")
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
190 ; // ok.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
191 else
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
192 print_usage ("casesen");
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
193
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
194 return retval;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
195 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
196
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1907
diff changeset
197 DEFUN (computer, args, nargout,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
198 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
199 @deftypefn {Built-in Function} {} computer ()\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
200 Print or return a string of the form @var{cpu}-@var{vendor}-@var{os}\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
201 that identifies the kind of computer Octave is running on. If invoked\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
202 with an output argument, the value is returned instead of printed. For\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
203 example,\n\
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
204 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
205 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
206 @group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
207 computer ()\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
208 @print{} i586-pc-linux-gnu\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
209 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
210 x = computer ()\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
211 @result{} x = \"i586-pc-linux-gnu\"\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
212 @end group\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
213 @end example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
214 @end deftypefn")
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
215 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
216 octave_value_list retval;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
217
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
218 int nargin = args.length ();
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
219
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
220 if (nargin != 0)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
221 warning ("computer: ignoring extra arguments");
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
222
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 2086
diff changeset
223 string msg;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
224
3234
be8e0ba13644 [project @ 1999-01-29 03:52:30 by jwe]
jwe
parents: 3216
diff changeset
225 if (strcmp (CANONICAL_HOST_TYPE, "unknown") == 0)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 2086
diff changeset
226 msg = "Hi Dave, I'm a HAL-9000";
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
227 else
3234
be8e0ba13644 [project @ 1999-01-29 03:52:30 by jwe]
jwe
parents: 3216
diff changeset
228 msg = CANONICAL_HOST_TYPE;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
229
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
230 if (nargout == 0)
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 2086
diff changeset
231 octave_stdout << msg << "\n";
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
232 else
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 2086
diff changeset
233 retval = msg;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
234
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
235 return retval;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
236 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
237
3180
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
238 DEFUN (quit, args, nargout,
2068
18365b6332a8 [project @ 1996-04-17 23:37:35 by jwe]
jwe
parents: 2016
diff changeset
239 "quit (STATUS): exit Octave gracefully, returning STATUS to the system.\n\
18365b6332a8 [project @ 1996-04-17 23:37:35 by jwe]
jwe
parents: 2016
diff changeset
240 \n\
18365b6332a8 [project @ 1996-04-17 23:37:35 by jwe]
jwe
parents: 2016
diff changeset
241 STATUS should be an integer value. If STATUS is missing, 0 is assumed.")
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
242 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
243 octave_value_list retval;
2068
18365b6332a8 [project @ 1996-04-17 23:37:35 by jwe]
jwe
parents: 2016
diff changeset
244
3180
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
245 if (nargout == 0)
2068
18365b6332a8 [project @ 1996-04-17 23:37:35 by jwe]
jwe
parents: 2016
diff changeset
246 {
3180
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
247 int exit_status = 0;
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
248
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
249 quitting_gracefully = true;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
250
3180
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
251 if (args.length () > 0)
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
252 {
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
253 int tmp = args(0).nint_value ();
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
254
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
255 if (! error_state)
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3180
diff changeset
256 exit_status = tmp;
3180
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
257 }
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
258
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
259 clean_up_and_exit (exit_status);
2068
18365b6332a8 [project @ 1996-04-17 23:37:35 by jwe]
jwe
parents: 2016
diff changeset
260 }
3180
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
261 else
c17387059fd3 [project @ 1998-09-24 18:59:11 by jwe]
jwe
parents: 3162
diff changeset
262 error ("quit: invalid number of output arguments");
2068
18365b6332a8 [project @ 1996-04-17 23:37:35 by jwe]
jwe
parents: 2016
diff changeset
263
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
264 return retval;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
265 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
266
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
267 DEFALIAS (exit, quit);
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
268
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1907
diff changeset
269 DEFUN (warranty, , ,
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
270 "warranty (): describe copying conditions")
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
271 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
272 octave_value_list retval;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
273
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 2086
diff changeset
274 octave_stdout << "\n" OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\n\
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
275 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
276 it under the terms of the GNU General Public License as published by\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
277 the Free Software Foundation; either version 2 of the License, or\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
278 (at your option) any later version.\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
279 \n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
280 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
281 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
282 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
283 GNU General Public License for more details.\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
284 \n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
285 You should have received a copy of the GNU General Public License\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
286 along with this program. If not, write to the Free Software\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
287 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n\
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
288 \n";
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
289
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
290 return retval;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
291 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
292
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
293 // Execute a shell command.
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
294
1965
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
295 static void
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
296 cleanup_iprocstream (void *p)
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
297 {
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
298 iprocstream *cmd = static_cast<iprocstream *> (p);
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
299
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
300 octave_child_list::remove (cmd->pid ());
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
301
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
302 delete cmd;
1965
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
303 }
01e3ed56c415 [project @ 1996-02-17 02:02:50 by jwe]
jwe
parents: 1957
diff changeset
304
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
305 static octave_value_list
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
306 run_command_and_return_output (const string& cmd_str)
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
307 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
308 octave_value_list retval;
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
309
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
310 iprocstream *cmd = new iprocstream (cmd_str.c_str ());
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
311
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
312 if (cmd)
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
313 {
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
314 unwind_protect::add (cleanup_iprocstream, cmd);
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
315
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
316 if (*cmd)
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
317 {
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
318 ostrstream output_buf;
2095
36903d507b0e [project @ 1996-04-28 09:00:07 by jwe]
jwe
parents: 2086
diff changeset
319
3147
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
320 // XXX FIXME XXX -- sometimes, the subprocess hasn't written
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
321 // anything before we try to read from the procstream. The
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
322 // kluge below (simply waiting and trying again) is ugly,
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
323 // but it seems to work, at least most of the time. It
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
324 // could probably still fail if the subprocess hasn't
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
325 // started writing after the snooze. Isn't there a better
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
326 // way? If there is, you should also fix the code for the
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
327 // ls function in dirfns.cc.
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
328
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
329 char ch;
3147
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
330
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
331 if (cmd->get (ch))
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
332 output_buf.put (ch);
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
333 else
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
334 {
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
335 cmd->clear ();
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
336
3308
7ae1928ca623 [project @ 1999-10-21 08:57:11 by jwe]
jwe
parents: 3301
diff changeset
337 octave_usleep (100);
3147
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
338 }
894d516b4a00 [project @ 1998-02-06 06:00:08 by jwe]
jwe
parents: 3141
diff changeset
339
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
340 while (cmd->get (ch))
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
341 output_buf.put (ch);
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
342
3252
9c784bd18858 [project @ 1999-07-15 00:33:12 by jwe]
jwe
parents: 3234
diff changeset
343 int cmd_status = cmd->close ();
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
344
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
345 if (WIFEXITED (cmd_status))
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
346 cmd_status = WEXITSTATUS (cmd_status);
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
347 else
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
348 cmd_status = 127;
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
349
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
350 output_buf << ends;
2145
4d13a9fafd44 [project @ 1996-05-13 05:55:25 by jwe]
jwe
parents: 2095
diff changeset
351
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
352 char *msg = output_buf.str ();
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
353
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
354 retval(1) = (double) cmd_status;
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
355 retval(0) = msg;
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
356
3060
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
357 delete [] msg;
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
358 }
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
359
9c6cd52f3f5a [project @ 1997-06-25 18:30:40 by jwe]
jwe
parents: 3020
diff changeset
360 unwind_protect::run ();
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
361 }
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
362 else
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
363 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
364
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
365 return retval;
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
366 }
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
367
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1907
diff changeset
368 DEFUN (system, args, nargout,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
369 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
370 @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
371 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
372 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
373 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
374 is returned immediately. Otherwise, the process is started, and\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
375 Octave waits until it exits. If @var{type} argument is omitted, a\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
376 value of @code{\"sync\"} is assumed.\n\
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
377 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
378 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
379 @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
380 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
381 one or more output arguments, the output from the command is returned.\n\
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
382 Otherwise, if the subprocess is executed synchronously, it's output is\n\
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
383 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
384 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
385 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
386 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
387 disp (system (cmd, 1));\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
388 @end example\n\
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
389 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
390 @noindent\n\
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
391 or\n\
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
392 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
393 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
394 printf (\"%s\n\", system (cmd, 1));\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
395 @end example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
396 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
397 The @code{system} function can return two values. The first is any\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
398 output from the command that was written to the standard output stream,\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
399 and the second is the output status of the command. For example,\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
400 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
401 @example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
402 [output, status] = system (\"echo foo; exit 2\");\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
403 @end example\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
404 \n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
405 @noindent\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
406 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
407 variable @code{status} to the integer @samp{2}.\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
408 @end deftypefn")
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
409 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
410 octave_value_list retval;
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
411
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
412 int nargin = args.length ();
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
413
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
414 if (nargin > 0 && nargin < 4)
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
415 {
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
416 bool return_output = (nargout > 0 || nargin > 1);
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
417
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
418 string cmd_str = args(0).string_value ();
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
419
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
420 enum exec_type { sync, async };
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
421
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
422 exec_type type = sync;
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
423
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
424 if (! error_state)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
425 {
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
426 if (nargin > 2)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
427 {
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
428 string type_str = args(2).string_value ();
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
429
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
430 if (! error_state)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
431 {
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
432 if (type_str == "sync")
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
433 type = sync;
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
434 else if (type_str == "async")
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
435 type = async;
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
436 else
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
437 error ("system: third arg must be \"sync\" or \"async\"");
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
438 }
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
439 else
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
440 error ("system: third argument must be a string");
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
441 }
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
442 }
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
443 else
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
444 error ("system: expecting string as first argument");
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
445
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
446 if (! error_state)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
447 {
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
448 if (type == async)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
449 {
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
450 pid_t pid = fork ();
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
451
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
452 if (pid < 0)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
453 error ("system: fork failed -- can't create child process");
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
454 else if (pid == 0)
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
455 {
3273
eb27ea9b7ff8 [project @ 1999-10-12 02:22:25 by jwe]
jwe
parents: 3258
diff changeset
456 // XXX FIXME XXX -- should probably replace this
eb27ea9b7ff8 [project @ 1999-10-12 02:22:25 by jwe]
jwe
parents: 3258
diff changeset
457 // call with something portable.
eb27ea9b7ff8 [project @ 1999-10-12 02:22:25 by jwe]
jwe
parents: 3258
diff changeset
458
eb27ea9b7ff8 [project @ 1999-10-12 02:22:25 by jwe]
jwe
parents: 3258
diff changeset
459 execl ("/bin/sh", "sh", "-c", cmd_str.c_str (), 0);
eb27ea9b7ff8 [project @ 1999-10-12 02:22:25 by jwe]
jwe
parents: 3258
diff changeset
460
eb27ea9b7ff8 [project @ 1999-10-12 02:22:25 by jwe]
jwe
parents: 3258
diff changeset
461 panic_impossible ();
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
462 }
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
463 else
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2796
diff changeset
464 retval(0) = static_cast<double> (pid);
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
465 }
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
466 else if (return_output)
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
467 retval = run_command_and_return_output (cmd_str);
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
468 else
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
469 {
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
470 int status = system (cmd_str.c_str ());
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
471
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
472 // 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
473 // the process exited normally, extract the actual exit
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
474 // status of the command. Otherwise, return 127 as a
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
475 // failure code.
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
476
2693
f4d0604cbcc4 [project @ 1997-02-18 15:25:21 by jwe]
jwe
parents: 2692
diff changeset
477 if (WIFEXITED (status))
f4d0604cbcc4 [project @ 1997-02-18 15:25:21 by jwe]
jwe
parents: 2692
diff changeset
478 status = WEXITSTATUS (status);
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
479
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2796
diff changeset
480 retval = static_cast<double> (status);
2321
dac9933079e6 [project @ 1996-07-15 21:08:05 by jwe]
jwe
parents: 2299
diff changeset
481 }
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
482 }
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
483 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
484 else
2083
679d7262a525 [project @ 1996-04-25 04:29:27 by jwe]
jwe
parents: 2078
diff changeset
485 print_usage ("system");
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
486
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
487 return retval;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
488 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
489
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
490 DEFALIAS (shell_cmd, system);
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
491
2614
ae47b0911863 [project @ 1997-01-21 03:57:46 by jwe]
jwe
parents: 2554
diff changeset
492 // XXX FIXME XXX -- this should really be static, but that causes
ae47b0911863 [project @ 1997-01-21 03:57:46 by jwe]
jwe
parents: 2554
diff changeset
493 // problems on some systems.
ae47b0911863 [project @ 1997-01-21 03:57:46 by jwe]
jwe
parents: 2554
diff changeset
494 SLStack<string> octave_atexit_functions;
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
495
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
496 void
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
497 do_octave_atexit (void)
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
498 {
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
499 static bool deja_vu = false;
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
500
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
501 while (! octave_atexit_functions.empty ())
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
502 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
503 octave_value_list fcn = octave_atexit_functions.pop ();
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
504
2942
026f342c2019 [project @ 1997-05-08 02:20:57 by jwe]
jwe
parents: 2926
diff changeset
505 feval (fcn, 0);
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3202
diff changeset
506
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3202
diff changeset
507 flush_octave_stdout ();
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
508 }
3216
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
509
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
510 if (! deja_vu)
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
511 {
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
512 deja_vu = true;
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
513
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
514 command_editor::restore_terminal_state ();
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
515
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
516 // XXX FIXME XXX -- is this needed? Can it cause any trouble?
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
517 raw_mode (0);
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
518
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
519 command_history::clean_up_and_save ();
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
520
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
521 close_plot_stream ();
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
522
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
523 close_files ();
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
524
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
525 cleanup_tmp_files ();
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
526
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
527 flush_octave_stdout ();
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
528
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
529 if (!quitting_gracefully && (interactive || forced_interactive))
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
530 cout << "\n";
60a89a69a70a [project @ 1998-11-11 20:47:03 by jwe]
jwe
parents: 3215
diff changeset
531 }
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
532 }
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
533
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
534 DEFUN (atexit, args, ,
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
535 "atexit (NAME): register NAME as a function to call when Octave exits\n\
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
536 \n\
2802
bca5fbab2e52 [project @ 1997-03-09 11:02:27 by jwe]
jwe
parents: 2800
diff changeset
537 Functions are called with no arguments in the reverse of the order in\n\
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
538 which they were registered with atexit()")
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
539 {
2086
bfb775fb6fe8 [project @ 1996-04-25 05:55:19 by jwe]
jwe
parents: 2084
diff changeset
540 octave_value_list retval;
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
541
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
542 int nargin = args.length ();
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
543
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
544 if (nargin == 1)
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
545 {
2475
1d7925d6bede [project @ 1996-11-07 04:36:00 by jwe]
jwe
parents: 2442
diff changeset
546 #if defined (HAVE_ATEXIT) || defined (HAVE_ON_EXIT)
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
547 string arg = args(0).string_value ();
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
548
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
549 if (! error_state)
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
550 octave_atexit_functions.push (arg);
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
551 else
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
552 error ("atexit: argument must be a string");
2475
1d7925d6bede [project @ 1996-11-07 04:36:00 by jwe]
jwe
parents: 2442
diff changeset
553 #else
1d7925d6bede [project @ 1996-11-07 04:36:00 by jwe]
jwe
parents: 2442
diff changeset
554 gripe_not_supported ("atexit");
1d7925d6bede [project @ 1996-11-07 04:36:00 by jwe]
jwe
parents: 2442
diff changeset
555 #endif
2077
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
556 }
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
557 else
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
558 print_usage ("atexit");
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
559
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
560 return retval;
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
561 }
2d03b8eb891d [project @ 1996-04-24 00:21:21 by jwe]
jwe
parents: 2068
diff changeset
562
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
563 DEFUN (octave_config_info, args, ,
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
564 "-*- texinfo -*-\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
565 @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
566 Return a structure containing configuration and installation\n\
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
567 information for Octave.\n\
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
568 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
569 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
570 specified option.\n\
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
571 \n\
3301
02866242d3ae [project @ 1999-10-20 04:10:46 by jwe]
jwe
parents: 3273
diff changeset
572 @end deftypefn")
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
573 {
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
574 octave_value retval;
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
575
2696
eb2ade3c6609 [project @ 1997-02-18 17:00:34 by jwe]
jwe
parents: 2693
diff changeset
576 #if defined (WITH_DYNAMIC_LINKING) && (defined (WITH_DL) || defined (WITH_SHL))
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
577 bool octave_supports_dynamic_linking = true;
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
578 #else
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
579 bool octave_supports_dynamic_linking = false;
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
580 #endif
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
581
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
582 Octave_map m;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
583
3141
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 3136
diff changeset
584 // XXX FIXME XXX -- should we perform OCTAVE_HOME substitution on these?
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 3136
diff changeset
585
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
586 m ["default_pager"] = DEFAULT_PAGER;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
587 m ["prefix"] = OCTAVE_PREFIX;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
588 m ["exec_prefix"] = OCTAVE_EXEC_PREFIX;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
589 m ["datadir"] = OCTAVE_DATADIR;
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2796
diff changeset
590 m ["dld"] = static_cast<double> (octave_supports_dynamic_linking);
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
591 m ["libdir"] = OCTAVE_LIBDIR;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
592 m ["bindir"] = OCTAVE_BINDIR;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
593 m ["infodir"] = OCTAVE_INFODIR;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
594 m ["fcnfiledir"] = OCTAVE_FCNFILEDIR;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
595 m ["localfcnfiledir"] = OCTAVE_LOCALFCNFILEDIR;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
596 m ["localstartupfiledir"] = OCTAVE_LOCALSTARTUPFILEDIR;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
597 m ["startupfiledir"] = OCTAVE_STARTUPFILEDIR;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
598 m ["localfcnfilepath"] = OCTAVE_LOCALFCNFILEPATH;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
599 m ["archlibdir"] = OCTAVE_ARCHLIBDIR;
2439
dc870b8b229f [project @ 1996-10-30 07:57:31 by jwe]
jwe
parents: 2370
diff changeset
600 m ["localarchlibdir"] = OCTAVE_LOCALARCHLIBDIR;
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
601 m ["octfiledir"] = OCTAVE_OCTFILEDIR;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
602 m ["localoctfilepath"] = OCTAVE_LOCALOCTFILEPATH;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
603 m ["fcnfilepath"] = OCTAVE_FCNFILEPATH;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
604 m ["imagepath"] = OCTAVE_IMAGEPATH;
3234
be8e0ba13644 [project @ 1999-01-29 03:52:30 by jwe]
jwe
parents: 3216
diff changeset
605 m ["canonical_host_type"] = CANONICAL_HOST_TYPE;
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
606 m ["configure_options"] = config_opts;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
607 m ["F77"] = F77;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
608 m ["FFLAGS"] = FFLAGS;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
609 m ["FPICFLAG"] = FPICFLAG;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
610 m ["F2C"] = F2C;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
611 m ["F2CFLAGS"] = F2CFLAGS;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
612 m ["FLIBS"] = FLIBS;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
613 m ["CPPFLAGS"] = CPPFLAGS;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
614 m ["INCFLAGS"] = INCFLAGS;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
615 m ["CC"] = CC " " CC_VERSION;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
616 m ["CFLAGS"] = CFLAGS;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
617 m ["CPICFLAG"] = CPICFLAG;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
618 m ["CXX"] = CXX " " CXX_VERSION;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
619 m ["CXXFLAGS"] = CXXFLAGS;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
620 m ["CXXPICFLAG"] = CXXPICFLAG;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
621 m ["LDFLAGS"] = LDFLAGS;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
622 m ["LIBFLAGS"] = LIBFLAGS;
2675
5b13fb88db90 [project @ 1997-02-13 22:34:18 by jwe]
jwe
parents: 2630
diff changeset
623 m ["RLD_FLAG"] = RLD_FLAG;
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
624 m ["TERMLIBS"] = TERMLIBS;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
625 m ["LIBS"] = LIBS;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
626 m ["LEXLIB"] = LEXLIB;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
627 m ["LIBPLPLOT"] = LIBPLPLOT;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
628 m ["LIBDLFCN"] = LIBDLFCN;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
629 m ["DEFS"] = DEFS;
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
630
2689
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
631 int nargin = args.length ();
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
632
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
633 if (nargin == 1)
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
634 {
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
635 string arg = args(0).string_value ();
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
636
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
637 if (! error_state)
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
638 retval = octave_value (m [arg.c_str ()]);
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
639 }
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
640 else if (nargin == 0)
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
641 retval = octave_value (m);
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
642 else
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
643 print_usage ("octave_config_info");
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
644
8c7955a8d49f [project @ 1997-02-18 09:06:10 by jwe]
jwe
parents: 2675
diff changeset
645 return retval;
2162
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
646 }
a940dcdfe9de [project @ 1996-05-13 10:31:51 by jwe]
jwe
parents: 2145
diff changeset
647
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
648 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE)
2806
187d5321cfa3 [project @ 1997-03-11 05:13:15 by jwe]
jwe
parents: 2802
diff changeset
649
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
650 int debug_new_delete = 0;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
651
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
652 typedef void (*vfp)(void);
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
653 extern vfp __new_handler;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
654
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
655 void *
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
656 __builtin_new (size_t sz)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
657 {
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
658 void *p;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
659
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
660 /* malloc (0) is unpredictable; avoid it. */
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
661 if (sz == 0)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
662 sz = 1;
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2796
diff changeset
663 p = malloc (sz);
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
664 while (p == 0)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
665 {
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
666 (*__new_handler) ();
2800
9aeba8e006a4 [project @ 1997-03-09 09:50:20 by jwe]
jwe
parents: 2796
diff changeset
667 p = malloc (sz);
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
668 }
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 if (debug_new_delete)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
671 cout << "__builtin_new: " << p << endl;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
672
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
673 return p;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
674 }
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
675
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
676 void
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
677 __builtin_delete (void *ptr)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
678 {
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
679 if (debug_new_delete)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
680 cout << "__builtin_delete: " << ptr << endl;
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
681
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
682 if (ptr)
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
683 free (ptr);
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
684 }
2806
187d5321cfa3 [project @ 1997-03-11 05:13:15 by jwe]
jwe
parents: 2802
diff changeset
685
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
686 #endif
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
687
2806
187d5321cfa3 [project @ 1997-03-11 05:13:15 by jwe]
jwe
parents: 2802
diff changeset
688 void
187d5321cfa3 [project @ 1997-03-11 05:13:15 by jwe]
jwe
parents: 2802
diff changeset
689 symbols_of_toplev (void)
187d5321cfa3 [project @ 1997-03-11 05:13:15 by jwe]
jwe
parents: 2802
diff changeset
690 {
3141
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 3136
diff changeset
691 DEFCONST (argv, ,
3020
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
692 "the command line arguments this program was invoked with");
2806
187d5321cfa3 [project @ 1997-03-11 05:13:15 by jwe]
jwe
parents: 2802
diff changeset
693
3020
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
694 DEFCONST (program_invocation_name,
3141
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 3136
diff changeset
695 octave_env::get_program_invocation_name (),
3020
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
696 "the full name of the current program or script, including the\n\
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
697 directory specification");
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
698
3141
292ff0bf484b [project @ 1998-02-03 08:11:07 by jwe]
jwe
parents: 3136
diff changeset
699 DEFCONST (program_name, octave_env::get_program_name (),
3020
f491f232cb09 [project @ 1997-06-03 22:15:08 by jwe]
jwe
parents: 3014
diff changeset
700 "the name of the current program or script");
2806
187d5321cfa3 [project @ 1997-03-11 05:13:15 by jwe]
jwe
parents: 2802
diff changeset
701 }
187d5321cfa3 [project @ 1997-03-11 05:13:15 by jwe]
jwe
parents: 2802
diff changeset
702
1683
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
703 /*
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
704 ;;; Local Variables: ***
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
705 ;;; mode: C++ ***
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
706 ;;; End: ***
5282f171363d [project @ 1995-12-30 03:46:07 by jwe]
jwe
parents:
diff changeset
707 */