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