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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2974
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
3503
|
28 #include <iostream> |
3014
|
29 #include <string> |
|
30 |
3606
|
31 #include "defun.h" |
3325
|
32 #include "dynamic-ld.h" |
3014
|
33 #include "error.h" |
|
34 #include "help.h" |
2974
|
35 #include "ov.h" |
|
36 #include "ov-builtin.h" |
3325
|
37 #include "ov-dld-fcn.h" |
2974
|
38 #include "ov-mapper.h" |
3606
|
39 #include "oct-obj.h" |
3014
|
40 #include "pager.h" |
2974
|
41 #include "symtab.h" |
|
42 #include "variables.h" |
|
43 |
5399
|
44 // XXX FIXME XXX -- this function could probably share some code with |
|
45 // the help functions. |
|
46 |
3014
|
47 void |
3523
|
48 print_usage (const std::string& nm, bool just_usage) |
3014
|
49 { |
4009
|
50 symbol_record *sym_rec = fbi_sym_tab->lookup (nm); |
3014
|
51 |
|
52 if (sym_rec) |
|
53 { |
3523
|
54 std::string h = sym_rec->help (); |
3014
|
55 |
|
56 if (h.length () > 0) |
|
57 { |
4732
|
58 OSSTREAM buf; |
|
59 |
|
60 buf << "\n*** " << nm << ":\n\n"; |
3330
|
61 |
5399
|
62 h = extract_help_from_dispatch (nm) + h; |
|
63 |
4732
|
64 display_help_text (buf, h); |
3330
|
65 |
4732
|
66 buf << "\n"; |
3014
|
67 |
|
68 if (! just_usage) |
4732
|
69 additional_help_message (buf); |
|
70 |
|
71 buf << OSSTREAM_ENDS; |
|
72 |
|
73 defun_usage_message (OSSTREAM_STR (buf)); |
|
74 |
|
75 OSSTREAM_FREEZE (buf); |
3014
|
76 } |
|
77 } |
|
78 else |
|
79 warning ("no usage message found for `%s'", nm.c_str ()); |
|
80 } |
|
81 |
3015
|
82 void |
3523
|
83 check_version (const std::string& version, const std::string& fcn) |
3015
|
84 { |
4448
|
85 if (version != OCTAVE_API_VERSION) |
3986
|
86 { |
4448
|
87 error ("API version %s found in .oct file function `%s'\n" |
|
88 " does not match the running Octave (API version %s)\n" |
|
89 " this can lead to incorrect results or other failures\n" |
|
90 " you can fix this problem by recompiling this .oct file", |
|
91 version.c_str (), fcn.c_str (), OCTAVE_API_VERSION); |
3986
|
92 } |
3015
|
93 } |
|
94 |
2974
|
95 // Install variables and functions in the symbol tables. |
|
96 |
|
97 void |
3145
|
98 install_builtin_mapper (octave_mapper *mf) |
2974
|
99 { |
4009
|
100 symbol_record *sym_rec = fbi_sym_tab->lookup (mf->name (), true); |
2974
|
101 |
|
102 unsigned int t |
3010
|
103 = symbol_record::BUILTIN_FUNCTION | symbol_record::MAPPER_FUNCTION; |
2974
|
104 |
|
105 sym_rec->unprotect (); |
|
106 sym_rec->define (mf, t); |
|
107 sym_rec->document (mf->doc_string ()); |
|
108 sym_rec->make_eternal (); |
|
109 sym_rec->protect (); |
|
110 } |
|
111 |
|
112 void |
3523
|
113 install_builtin_function (octave_builtin::fcn f, const std::string& name, |
4234
|
114 const std::string& doc, bool is_text_fcn, |
|
115 bool /* can_hide_function -- not yet implemented */) |
2974
|
116 { |
4009
|
117 symbol_record *sym_rec = fbi_sym_tab->lookup (name, true); |
2974
|
118 |
3010
|
119 unsigned int t = symbol_record::BUILTIN_FUNCTION; |
2974
|
120 |
|
121 if (is_text_fcn) |
4208
|
122 t |= symbol_record::COMMAND; |
2974
|
123 |
|
124 sym_rec->unprotect (); |
|
125 sym_rec->define (new octave_builtin (f, name, doc), t); |
|
126 sym_rec->document (doc); |
|
127 sym_rec->make_eternal (); |
|
128 sym_rec->protect (); |
|
129 } |
|
130 |
3258
|
131 void |
3523
|
132 install_builtin_constant (const std::string& name, const octave_value& val, |
|
133 bool protect, const std::string& help) |
2974
|
134 { |
3259
|
135 bind_builtin_constant (name, val, protect, false, help); |
2974
|
136 } |
|
137 |
|
138 void |
3523
|
139 install_builtin_variable (const std::string& name, const octave_value& value, |
3145
|
140 bool protect, bool eternal, |
|
141 symbol_record::change_function chg_fcn, |
3523
|
142 const std::string& doc) |
2974
|
143 { |
3258
|
144 bind_builtin_variable (name, value, protect, eternal, chg_fcn, doc); |
2974
|
145 } |
|
146 |
|
147 void |
3523
|
148 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
3325
|
149 const octave_shlib& shl, |
3523
|
150 const std::string& doc, bool is_text_fcn) |
3325
|
151 { |
4009
|
152 symbol_record *sym_rec = fbi_sym_tab->lookup (name, true); |
3325
|
153 |
|
154 unsigned int t = symbol_record::DLD_FUNCTION; |
|
155 |
|
156 if (is_text_fcn) |
4208
|
157 t |= symbol_record::COMMAND; |
3325
|
158 |
|
159 sym_rec->unprotect (); |
|
160 sym_rec->define (new octave_dld_function (f, shl, name, doc), t); |
|
161 sym_rec->document (doc); |
5397
|
162 |
|
163 // Also insert the full name in the symbol table. This way, we can |
|
164 // properly cope with changes to LOADPATH. |
|
165 |
|
166 symbol_record *full_sr = fbi_sym_tab->lookup (shl.file_name (), true); |
|
167 |
|
168 full_sr->alias (sym_rec, true); |
|
169 full_sr->hide (); |
3325
|
170 } |
|
171 |
|
172 void |
3523
|
173 alias_builtin (const std::string& alias, const std::string& name) |
2974
|
174 { |
4009
|
175 symbol_record *sr_name = fbi_sym_tab->lookup (name); |
2974
|
176 |
|
177 if (! sr_name) |
|
178 panic ("can't alias to undefined name!"); |
|
179 |
4009
|
180 symbol_record *sr_alias = fbi_sym_tab->lookup (alias, true); |
2974
|
181 |
|
182 if (sr_alias) |
|
183 sr_alias->alias (sr_name); |
|
184 else |
|
185 panic ("can't find symbol record for builtin function `%s'", |
|
186 alias.c_str ()); |
|
187 } |
|
188 |
3606
|
189 #if 0 |
|
190 // This is insufficient to really make it possible to define an alias |
|
191 // for function. There are a number of subtle problems related to |
|
192 // automatically reloading functions. |
|
193 DEFUN (alias, args, , |
|
194 "alias (alias, name)") |
|
195 { |
|
196 octave_value retval; |
|
197 |
|
198 int nargin = args.length (); |
|
199 |
|
200 if (nargin == 2) |
|
201 { |
|
202 string alias = args(0).string_value (); |
|
203 string name = args(1).string_value (); |
|
204 |
|
205 if (! error_state) |
|
206 { |
|
207 symbol_record *sr_name = lookup_by_name (name, false); |
|
208 |
|
209 if (sr_name && sr_name->is_function ()) |
|
210 { |
4009
|
211 symbol_record *sr_alias = fbi_sym_tab->lookup (alias, true); |
3606
|
212 |
|
213 if (sr_alias) |
|
214 sr_alias->alias (sr_name); |
|
215 else |
|
216 error ("alias: unable to insert `%s' in symbol table", |
|
217 alias.c_str ()); |
|
218 } |
|
219 else |
|
220 error ("alias: function `%s' does not exist", name.c_str ()); |
|
221 } |
|
222 } |
|
223 else |
|
224 print_usage ("alias"); |
|
225 |
|
226 return retval; |
|
227 } |
|
228 #endif |
|
229 |
2974
|
230 /* |
|
231 ;;; Local Variables: *** |
|
232 ;;; mode: C++ *** |
|
233 ;;; End: *** |
|
234 */ |