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