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 |
2974
|
29 #include "defun-int.h" |
3014
|
30 #include "error.h" |
|
31 #include "help.h" |
2974
|
32 #include "ov.h" |
|
33 #include "ov-builtin.h" |
|
34 #include "ov-mapper.h" |
3014
|
35 #include "pager.h" |
2974
|
36 #include "symtab.h" |
|
37 #include "variables.h" |
|
38 |
3014
|
39 void |
|
40 print_usage (const string& nm, bool just_usage) |
|
41 { |
|
42 symbol_record *sym_rec = global_sym_tab->lookup (nm); |
|
43 |
|
44 if (sym_rec) |
|
45 { |
|
46 string h = sym_rec->help (); |
|
47 |
|
48 if (h.length () > 0) |
|
49 { |
|
50 octave_stdout << "\n*** " << nm << ":\n\n" |
|
51 << h << "\n"; |
|
52 |
|
53 if (! just_usage) |
|
54 additional_help_message (octave_stdout); |
|
55 } |
|
56 } |
|
57 else |
|
58 warning ("no usage message found for `%s'", nm.c_str ()); |
|
59 } |
|
60 |
3015
|
61 void |
|
62 check_version (const string& version, const string& fcn) |
|
63 { |
|
64 if (version != OCTAVE_VERSION) |
|
65 warning ("incompatible version %s found in function `%s'", |
|
66 version.c_str (), fcn.c_str ()); |
|
67 } |
|
68 |
2974
|
69 // Install variables and functions in the symbol tables. |
|
70 |
|
71 void |
3145
|
72 install_builtin_mapper (octave_mapper *mf) |
2974
|
73 { |
|
74 symbol_record *sym_rec = global_sym_tab->lookup (mf->name (), true); |
|
75 |
|
76 unsigned int t |
3010
|
77 = symbol_record::BUILTIN_FUNCTION | symbol_record::MAPPER_FUNCTION; |
2974
|
78 |
|
79 sym_rec->unprotect (); |
|
80 sym_rec->define (mf, t); |
|
81 sym_rec->document (mf->doc_string ()); |
|
82 sym_rec->make_eternal (); |
|
83 sym_rec->protect (); |
|
84 } |
|
85 |
|
86 void |
3145
|
87 install_builtin_function (octave_builtin::fcn f, const string& name, |
2974
|
88 const string& doc, bool is_text_fcn) |
|
89 { |
|
90 symbol_record *sym_rec = global_sym_tab->lookup (name, true); |
|
91 |
3010
|
92 unsigned int t = symbol_record::BUILTIN_FUNCTION; |
2974
|
93 |
|
94 if (is_text_fcn) |
3010
|
95 t |= symbol_record::TEXT_FUNCTION; |
2974
|
96 |
|
97 sym_rec->unprotect (); |
|
98 sym_rec->define (new octave_builtin (f, name, doc), t); |
|
99 sym_rec->document (doc); |
|
100 sym_rec->make_eternal (); |
|
101 sym_rec->protect (); |
|
102 } |
|
103 |
3258
|
104 void |
|
105 install_builtin_constant (const string& name, const octave_value& val, |
|
106 bool protect, const string& help) |
2974
|
107 { |
|
108 symbol_record *sym_rec = global_sym_tab->lookup (name, true); |
|
109 sym_rec->unprotect (); |
|
110 |
|
111 string tmp_help = help.empty () ? sym_rec->help () : help; |
|
112 |
3258
|
113 sym_rec->define_builtin_const (val); |
2974
|
114 |
|
115 sym_rec->document (tmp_help); |
|
116 |
|
117 if (protect) |
|
118 sym_rec->protect (); |
|
119 |
3258
|
120 // XXX FIXME XXX -- shouldn't constants be eternal? |
|
121 // if (eternal) |
|
122 // sym_rec->make_eternal (); |
2974
|
123 } |
|
124 |
|
125 void |
|
126 install_builtin_variable (const string& name, const octave_value& value, |
3145
|
127 bool protect, bool eternal, |
|
128 symbol_record::change_function chg_fcn, |
3258
|
129 const string& doc) |
2974
|
130 { |
3258
|
131 bind_builtin_variable (name, value, protect, eternal, chg_fcn, doc); |
2974
|
132 } |
|
133 |
|
134 void |
|
135 alias_builtin (const string& alias, const string& name) |
|
136 { |
|
137 symbol_record *sr_name = global_sym_tab->lookup (name); |
|
138 |
|
139 if (! sr_name) |
|
140 panic ("can't alias to undefined name!"); |
|
141 |
|
142 symbol_record *sr_alias = global_sym_tab->lookup (alias, true); |
|
143 |
|
144 if (sr_alias) |
|
145 sr_alias->alias (sr_name); |
|
146 else |
|
147 panic ("can't find symbol record for builtin function `%s'", |
|
148 alias.c_str ()); |
|
149 } |
|
150 |
|
151 /* |
|
152 ;;; Local Variables: *** |
|
153 ;;; mode: C++ *** |
|
154 ;;; End: *** |
|
155 */ |