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 |
3014
|
27 #include <string> |
|
28 |
3325
|
29 #include <iostream.h> |
|
30 |
2974
|
31 #include "defun-int.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" |
3014
|
39 #include "pager.h" |
2974
|
40 #include "symtab.h" |
|
41 #include "variables.h" |
|
42 |
3014
|
43 void |
|
44 print_usage (const string& nm, bool just_usage) |
|
45 { |
|
46 symbol_record *sym_rec = global_sym_tab->lookup (nm); |
|
47 |
|
48 if (sym_rec) |
|
49 { |
|
50 string h = sym_rec->help (); |
|
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 |
|
69 check_version (const string& version, const string& fcn) |
|
70 { |
|
71 if (version != OCTAVE_VERSION) |
|
72 warning ("incompatible version %s found in function `%s'", |
|
73 version.c_str (), fcn.c_str ()); |
|
74 } |
|
75 |
2974
|
76 // Install variables and functions in the symbol tables. |
|
77 |
|
78 void |
3145
|
79 install_builtin_mapper (octave_mapper *mf) |
2974
|
80 { |
|
81 symbol_record *sym_rec = global_sym_tab->lookup (mf->name (), true); |
|
82 |
|
83 unsigned int t |
3010
|
84 = symbol_record::BUILTIN_FUNCTION | symbol_record::MAPPER_FUNCTION; |
2974
|
85 |
|
86 sym_rec->unprotect (); |
|
87 sym_rec->define (mf, t); |
|
88 sym_rec->document (mf->doc_string ()); |
|
89 sym_rec->make_eternal (); |
|
90 sym_rec->protect (); |
|
91 } |
|
92 |
|
93 void |
3145
|
94 install_builtin_function (octave_builtin::fcn f, const string& name, |
2974
|
95 const string& doc, bool is_text_fcn) |
|
96 { |
|
97 symbol_record *sym_rec = global_sym_tab->lookup (name, true); |
|
98 |
3010
|
99 unsigned int t = symbol_record::BUILTIN_FUNCTION; |
2974
|
100 |
|
101 if (is_text_fcn) |
3010
|
102 t |= symbol_record::TEXT_FUNCTION; |
2974
|
103 |
|
104 sym_rec->unprotect (); |
|
105 sym_rec->define (new octave_builtin (f, name, doc), t); |
|
106 sym_rec->document (doc); |
|
107 sym_rec->make_eternal (); |
|
108 sym_rec->protect (); |
|
109 } |
|
110 |
3258
|
111 void |
|
112 install_builtin_constant (const string& name, const octave_value& val, |
|
113 bool protect, const string& help) |
2974
|
114 { |
3259
|
115 bind_builtin_constant (name, val, protect, false, help); |
2974
|
116 } |
|
117 |
|
118 void |
|
119 install_builtin_variable (const string& name, const octave_value& value, |
3145
|
120 bool protect, bool eternal, |
|
121 symbol_record::change_function chg_fcn, |
3258
|
122 const string& doc) |
2974
|
123 { |
3258
|
124 bind_builtin_variable (name, value, protect, eternal, chg_fcn, doc); |
2974
|
125 } |
|
126 |
|
127 void |
3325
|
128 install_dld_function (octave_dld_function::fcn f, const string& name, |
|
129 const octave_shlib& shl, |
|
130 const string& doc, bool is_text_fcn) |
|
131 { |
|
132 symbol_record *sym_rec = global_sym_tab->lookup (name, true); |
|
133 |
|
134 unsigned int t = symbol_record::DLD_FUNCTION; |
|
135 |
|
136 if (is_text_fcn) |
|
137 t |= symbol_record::TEXT_FUNCTION; |
|
138 |
|
139 sym_rec->unprotect (); |
|
140 sym_rec->define (new octave_dld_function (f, shl, name, doc), t); |
|
141 sym_rec->document (doc); |
|
142 sym_rec->make_eternal (); |
|
143 sym_rec->protect (); |
|
144 } |
|
145 |
|
146 void |
2974
|
147 alias_builtin (const string& alias, const string& name) |
|
148 { |
|
149 symbol_record *sr_name = global_sym_tab->lookup (name); |
|
150 |
|
151 if (! sr_name) |
|
152 panic ("can't alias to undefined name!"); |
|
153 |
|
154 symbol_record *sr_alias = global_sym_tab->lookup (alias, true); |
|
155 |
|
156 if (sr_alias) |
|
157 sr_alias->alias (sr_name); |
|
158 else |
|
159 panic ("can't find symbol record for builtin function `%s'", |
|
160 alias.c_str ()); |
|
161 } |
|
162 |
|
163 /* |
|
164 ;;; Local Variables: *** |
|
165 ;;; mode: C++ *** |
|
166 ;;; End: *** |
|
167 */ |