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