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