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 |
5800
|
66 display_usage_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 |
5800
|
80 DEFUN (print_usage, args, , |
|
81 "-*- texinfo -*-\n\ |
|
82 @deftypefn {Loadable Function} {} print_usage (@var{fname})\n\ |
|
83 Print the usage message for the function named @var{fname}. The\n\ |
|
84 @code{print_usage} function is only intended to work inside the\n\ |
|
85 named function.\n\ |
|
86 @seealso{help}\n\ |
|
87 @end deftypefn") |
|
88 { |
|
89 octave_value retval; |
|
90 |
|
91 if (args.length () == 1) |
|
92 { |
|
93 std::string fname = args(0).string_value (); |
|
94 |
|
95 if (! error_state) |
|
96 print_usage (fname); |
|
97 else |
|
98 error ("print_usage: expecting character string"); |
|
99 } |
|
100 else |
|
101 print_usage ("print_usage"); |
|
102 |
|
103 return retval; |
|
104 } |
|
105 |
3015
|
106 void |
3523
|
107 check_version (const std::string& version, const std::string& fcn) |
3015
|
108 { |
4448
|
109 if (version != OCTAVE_API_VERSION) |
3986
|
110 { |
4448
|
111 error ("API version %s found in .oct file function `%s'\n" |
|
112 " does not match the running Octave (API version %s)\n" |
|
113 " this can lead to incorrect results or other failures\n" |
|
114 " you can fix this problem by recompiling this .oct file", |
|
115 version.c_str (), fcn.c_str (), OCTAVE_API_VERSION); |
3986
|
116 } |
3015
|
117 } |
|
118 |
2974
|
119 // Install variables and functions in the symbol tables. |
|
120 |
|
121 void |
3145
|
122 install_builtin_mapper (octave_mapper *mf) |
2974
|
123 { |
4009
|
124 symbol_record *sym_rec = fbi_sym_tab->lookup (mf->name (), true); |
2974
|
125 |
|
126 unsigned int t |
3010
|
127 = symbol_record::BUILTIN_FUNCTION | symbol_record::MAPPER_FUNCTION; |
2974
|
128 |
|
129 sym_rec->unprotect (); |
|
130 sym_rec->define (mf, t); |
|
131 sym_rec->document (mf->doc_string ()); |
|
132 sym_rec->make_eternal (); |
|
133 sym_rec->protect (); |
|
134 } |
|
135 |
|
136 void |
3523
|
137 install_builtin_function (octave_builtin::fcn f, const std::string& name, |
4234
|
138 const std::string& doc, bool is_text_fcn, |
|
139 bool /* can_hide_function -- not yet implemented */) |
2974
|
140 { |
4009
|
141 symbol_record *sym_rec = fbi_sym_tab->lookup (name, true); |
2974
|
142 |
3010
|
143 unsigned int t = symbol_record::BUILTIN_FUNCTION; |
2974
|
144 |
|
145 if (is_text_fcn) |
4208
|
146 t |= symbol_record::COMMAND; |
2974
|
147 |
|
148 sym_rec->unprotect (); |
|
149 sym_rec->define (new octave_builtin (f, name, doc), t); |
|
150 sym_rec->document (doc); |
|
151 sym_rec->make_eternal (); |
|
152 sym_rec->protect (); |
|
153 } |
|
154 |
3258
|
155 void |
3523
|
156 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
3325
|
157 const octave_shlib& shl, |
3523
|
158 const std::string& doc, bool is_text_fcn) |
3325
|
159 { |
4009
|
160 symbol_record *sym_rec = fbi_sym_tab->lookup (name, true); |
3325
|
161 |
|
162 unsigned int t = symbol_record::DLD_FUNCTION; |
|
163 |
|
164 if (is_text_fcn) |
4208
|
165 t |= symbol_record::COMMAND; |
3325
|
166 |
|
167 sym_rec->unprotect (); |
|
168 sym_rec->define (new octave_dld_function (f, shl, name, doc), t); |
|
169 sym_rec->document (doc); |
5397
|
170 |
|
171 // Also insert the full name in the symbol table. This way, we can |
5814
|
172 // properly cope with changes to LOAD_PATH. |
5397
|
173 |
|
174 symbol_record *full_sr = fbi_sym_tab->lookup (shl.file_name (), true); |
|
175 |
|
176 full_sr->alias (sym_rec, true); |
|
177 full_sr->hide (); |
3325
|
178 } |
|
179 |
|
180 void |
3523
|
181 alias_builtin (const std::string& alias, const std::string& name) |
2974
|
182 { |
4009
|
183 symbol_record *sr_name = fbi_sym_tab->lookup (name); |
2974
|
184 |
|
185 if (! sr_name) |
|
186 panic ("can't alias to undefined name!"); |
|
187 |
4009
|
188 symbol_record *sr_alias = fbi_sym_tab->lookup (alias, true); |
2974
|
189 |
|
190 if (sr_alias) |
|
191 sr_alias->alias (sr_name); |
|
192 else |
|
193 panic ("can't find symbol record for builtin function `%s'", |
|
194 alias.c_str ()); |
|
195 } |
|
196 |
3606
|
197 #if 0 |
|
198 // This is insufficient to really make it possible to define an alias |
|
199 // for function. There are a number of subtle problems related to |
|
200 // automatically reloading functions. |
|
201 DEFUN (alias, args, , |
|
202 "alias (alias, name)") |
|
203 { |
|
204 octave_value retval; |
|
205 |
|
206 int nargin = args.length (); |
|
207 |
|
208 if (nargin == 2) |
|
209 { |
|
210 string alias = args(0).string_value (); |
|
211 string name = args(1).string_value (); |
|
212 |
|
213 if (! error_state) |
|
214 { |
|
215 symbol_record *sr_name = lookup_by_name (name, false); |
|
216 |
|
217 if (sr_name && sr_name->is_function ()) |
|
218 { |
4009
|
219 symbol_record *sr_alias = fbi_sym_tab->lookup (alias, true); |
3606
|
220 |
|
221 if (sr_alias) |
|
222 sr_alias->alias (sr_name); |
|
223 else |
|
224 error ("alias: unable to insert `%s' in symbol table", |
|
225 alias.c_str ()); |
|
226 } |
|
227 else |
|
228 error ("alias: function `%s' does not exist", name.c_str ()); |
|
229 } |
|
230 } |
|
231 else |
|
232 print_usage ("alias"); |
|
233 |
|
234 return retval; |
|
235 } |
|
236 #endif |
|
237 |
2974
|
238 /* |
|
239 ;;; Local Variables: *** |
|
240 ;;; mode: C++ *** |
|
241 ;;; End: *** |
|
242 */ |