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 |
|
27 #include "defun-int.h" |
|
28 #include "ov.h" |
|
29 #include "ov-builtin.h" |
|
30 #include "ov-mapper.h" |
|
31 #include "symtab.h" |
|
32 #include "variables.h" |
|
33 |
|
34 // Install variables and functions in the symbol tables. |
|
35 |
|
36 void |
|
37 install_builtin_mapper (void *mf_arg) |
|
38 { |
|
39 octave_mapper *mf = static_cast<octave_mapper *> (mf_arg); |
|
40 |
|
41 symbol_record *sym_rec = global_sym_tab->lookup (mf->name (), true); |
|
42 |
|
43 unsigned int t |
3010
|
44 = symbol_record::BUILTIN_FUNCTION | symbol_record::MAPPER_FUNCTION; |
2974
|
45 |
|
46 sym_rec->unprotect (); |
|
47 sym_rec->define (mf, t); |
|
48 sym_rec->document (mf->doc_string ()); |
|
49 sym_rec->make_eternal (); |
|
50 sym_rec->protect (); |
|
51 } |
|
52 |
|
53 void |
|
54 install_builtin_function (void *f_arg, const string& name, |
|
55 const string& doc, bool is_text_fcn) |
|
56 { |
|
57 octave_builtin::fcn f = static_cast<octave_builtin::fcn> (f_arg); |
|
58 |
|
59 symbol_record *sym_rec = global_sym_tab->lookup (name, true); |
|
60 |
3010
|
61 unsigned int t = symbol_record::BUILTIN_FUNCTION; |
2974
|
62 |
|
63 if (is_text_fcn) |
3010
|
64 t |= symbol_record::TEXT_FUNCTION; |
2974
|
65 |
|
66 sym_rec->unprotect (); |
|
67 sym_rec->define (new octave_builtin (f, name, doc), t); |
|
68 sym_rec->document (doc); |
|
69 sym_rec->make_eternal (); |
|
70 sym_rec->protect (); |
|
71 } |
|
72 |
|
73 static void |
|
74 install_builtin_variable_as_function (const string& name, |
|
75 const octave_value& val, |
|
76 bool protect, bool eternal, |
|
77 const string& help) |
|
78 { |
|
79 symbol_record *sym_rec = global_sym_tab->lookup (name, true); |
|
80 sym_rec->unprotect (); |
|
81 |
|
82 string tmp_help = help.empty () ? sym_rec->help () : help; |
|
83 |
|
84 sym_rec->define_as_fcn (val); |
|
85 |
|
86 sym_rec->document (tmp_help); |
|
87 |
|
88 if (protect) |
|
89 sym_rec->protect (); |
|
90 |
|
91 if (eternal) |
|
92 sym_rec->make_eternal (); |
|
93 } |
|
94 |
|
95 void |
|
96 install_builtin_variable (const string& name, const octave_value& value, |
|
97 bool install_as_function, bool protect, |
3005
|
98 bool eternal, void *chg_fcn_arg, |
2974
|
99 const string& help_string) |
|
100 { |
3005
|
101 symbol_record::change_function chg_fcn |
|
102 = static_cast<symbol_record::change_function> (chg_fcn_arg); |
2974
|
103 |
|
104 if (install_as_function) |
|
105 install_builtin_variable_as_function (name, value, protect, |
|
106 eternal, help_string); |
|
107 else |
|
108 bind_builtin_variable (name, value, protect, eternal, |
3005
|
109 chg_fcn, help_string); |
2974
|
110 } |
|
111 |
|
112 void |
|
113 alias_builtin (const string& alias, const string& name) |
|
114 { |
|
115 symbol_record *sr_name = global_sym_tab->lookup (name); |
|
116 |
|
117 if (! sr_name) |
|
118 panic ("can't alias to undefined name!"); |
|
119 |
|
120 symbol_record *sr_alias = global_sym_tab->lookup (alias, true); |
|
121 |
|
122 if (sr_alias) |
|
123 sr_alias->alias (sr_name); |
|
124 else |
|
125 panic ("can't find symbol record for builtin function `%s'", |
|
126 alias.c_str ()); |
|
127 } |
|
128 |
|
129 /* |
|
130 ;;; Local Variables: *** |
|
131 ;;; mode: C++ *** |
|
132 ;;; End: *** |
|
133 */ |