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