2974
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
3503
|
27 #include <iostream> |
3014
|
28 #include <string> |
|
29 |
3606
|
30 #include "defun.h" |
3325
|
31 #include "dynamic-ld.h" |
3014
|
32 #include "error.h" |
|
33 #include "help.h" |
2974
|
34 #include "ov.h" |
|
35 #include "ov-builtin.h" |
3325
|
36 #include "ov-dld-fcn.h" |
2974
|
37 #include "ov-mapper.h" |
3606
|
38 #include "oct-obj.h" |
3014
|
39 #include "pager.h" |
2974
|
40 #include "symtab.h" |
|
41 #include "variables.h" |
|
42 |
3014
|
43 void |
3523
|
44 print_usage (const std::string& nm, bool just_usage) |
3014
|
45 { |
4009
|
46 symbol_record *sym_rec = fbi_sym_tab->lookup (nm); |
3014
|
47 |
|
48 if (sym_rec) |
|
49 { |
3523
|
50 std::string h = sym_rec->help (); |
3014
|
51 |
|
52 if (h.length () > 0) |
|
53 { |
3330
|
54 octave_stdout << "\n*** " << nm << ":\n\n"; |
|
55 |
|
56 display_help_text (octave_stdout, h); |
|
57 |
|
58 octave_stdout << "\n"; |
3014
|
59 |
|
60 if (! just_usage) |
|
61 additional_help_message (octave_stdout); |
|
62 } |
|
63 } |
|
64 else |
|
65 warning ("no usage message found for `%s'", nm.c_str ()); |
|
66 } |
|
67 |
3015
|
68 void |
3523
|
69 check_version (const std::string& version, const std::string& fcn) |
3015
|
70 { |
|
71 if (version != OCTAVE_VERSION) |
3986
|
72 { |
|
73 warning ("incompatible version %s found in function `%s'", |
|
74 version.c_str (), fcn.c_str ()); |
|
75 warning ("this can lead to incorrect results or other failures"); |
|
76 warning ("you can fix this problem by recmpiling this .oct file"); |
|
77 |
|
78 } |
3015
|
79 } |
|
80 |
2974
|
81 // Install variables and functions in the symbol tables. |
|
82 |
|
83 void |
3145
|
84 install_builtin_mapper (octave_mapper *mf) |
2974
|
85 { |
4009
|
86 symbol_record *sym_rec = fbi_sym_tab->lookup (mf->name (), true); |
2974
|
87 |
|
88 unsigned int t |
3010
|
89 = symbol_record::BUILTIN_FUNCTION | symbol_record::MAPPER_FUNCTION; |
2974
|
90 |
|
91 sym_rec->unprotect (); |
|
92 sym_rec->define (mf, t); |
|
93 sym_rec->document (mf->doc_string ()); |
|
94 sym_rec->make_eternal (); |
|
95 sym_rec->protect (); |
|
96 } |
|
97 |
|
98 void |
3523
|
99 install_builtin_function (octave_builtin::fcn f, const std::string& name, |
4234
|
100 const std::string& doc, bool is_text_fcn, |
|
101 bool /* can_hide_function -- not yet implemented */) |
2974
|
102 { |
4009
|
103 symbol_record *sym_rec = fbi_sym_tab->lookup (name, true); |
2974
|
104 |
3010
|
105 unsigned int t = symbol_record::BUILTIN_FUNCTION; |
2974
|
106 |
|
107 if (is_text_fcn) |
4208
|
108 t |= symbol_record::COMMAND; |
2974
|
109 |
|
110 sym_rec->unprotect (); |
|
111 sym_rec->define (new octave_builtin (f, name, doc), t); |
|
112 sym_rec->document (doc); |
|
113 sym_rec->make_eternal (); |
|
114 sym_rec->protect (); |
|
115 } |
|
116 |
3258
|
117 void |
3523
|
118 install_builtin_constant (const std::string& name, const octave_value& val, |
|
119 bool protect, const std::string& help) |
2974
|
120 { |
3259
|
121 bind_builtin_constant (name, val, protect, false, help); |
2974
|
122 } |
|
123 |
|
124 void |
3523
|
125 install_builtin_variable (const std::string& name, const octave_value& value, |
3145
|
126 bool protect, bool eternal, |
|
127 symbol_record::change_function chg_fcn, |
3523
|
128 const std::string& doc) |
2974
|
129 { |
3258
|
130 bind_builtin_variable (name, value, protect, eternal, chg_fcn, doc); |
2974
|
131 } |
|
132 |
|
133 void |
3523
|
134 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
3325
|
135 const octave_shlib& shl, |
3523
|
136 const std::string& doc, bool is_text_fcn) |
3325
|
137 { |
4009
|
138 symbol_record *sym_rec = fbi_sym_tab->lookup (name, true); |
3325
|
139 |
|
140 unsigned int t = symbol_record::DLD_FUNCTION; |
|
141 |
|
142 if (is_text_fcn) |
4208
|
143 t |= symbol_record::COMMAND; |
3325
|
144 |
|
145 sym_rec->unprotect (); |
|
146 sym_rec->define (new octave_dld_function (f, shl, name, doc), t); |
|
147 sym_rec->document (doc); |
|
148 sym_rec->make_eternal (); |
|
149 sym_rec->protect (); |
|
150 } |
|
151 |
|
152 void |
3523
|
153 alias_builtin (const std::string& alias, const std::string& name) |
2974
|
154 { |
4009
|
155 symbol_record *sr_name = fbi_sym_tab->lookup (name); |
2974
|
156 |
|
157 if (! sr_name) |
|
158 panic ("can't alias to undefined name!"); |
|
159 |
4009
|
160 symbol_record *sr_alias = fbi_sym_tab->lookup (alias, true); |
2974
|
161 |
|
162 if (sr_alias) |
|
163 sr_alias->alias (sr_name); |
|
164 else |
|
165 panic ("can't find symbol record for builtin function `%s'", |
|
166 alias.c_str ()); |
|
167 } |
|
168 |
3606
|
169 #if 0 |
|
170 // This is insufficient to really make it possible to define an alias |
|
171 // for function. There are a number of subtle problems related to |
|
172 // automatically reloading functions. |
|
173 DEFUN (alias, args, , |
|
174 "alias (alias, name)") |
|
175 { |
|
176 octave_value retval; |
|
177 |
|
178 int nargin = args.length (); |
|
179 |
|
180 if (nargin == 2) |
|
181 { |
|
182 string alias = args(0).string_value (); |
|
183 string name = args(1).string_value (); |
|
184 |
|
185 if (! error_state) |
|
186 { |
|
187 symbol_record *sr_name = lookup_by_name (name, false); |
|
188 |
|
189 if (sr_name && sr_name->is_function ()) |
|
190 { |
4009
|
191 symbol_record *sr_alias = fbi_sym_tab->lookup (alias, true); |
3606
|
192 |
|
193 if (sr_alias) |
|
194 sr_alias->alias (sr_name); |
|
195 else |
|
196 error ("alias: unable to insert `%s' in symbol table", |
|
197 alias.c_str ()); |
|
198 } |
|
199 else |
|
200 error ("alias: function `%s' does not exist", name.c_str ()); |
|
201 } |
|
202 } |
|
203 else |
|
204 print_usage ("alias"); |
|
205 |
|
206 return retval; |
|
207 } |
|
208 #endif |
|
209 |
2974
|
210 /* |
|
211 ;;; Local Variables: *** |
|
212 ;;; mode: C++ *** |
|
213 ;;; End: *** |
|
214 */ |