2974
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, |
|
4 2006, 2007 John W. Eaton |
2974
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
2974
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
2974
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
5765
|
28 #include <sstream> |
3503
|
29 #include <iostream> |
3014
|
30 #include <string> |
|
31 |
3606
|
32 #include "defun.h" |
3325
|
33 #include "dynamic-ld.h" |
3014
|
34 #include "error.h" |
|
35 #include "help.h" |
2974
|
36 #include "ov.h" |
|
37 #include "ov-builtin.h" |
3325
|
38 #include "ov-dld-fcn.h" |
5823
|
39 #include "ov-fcn.h" |
2974
|
40 #include "ov-mapper.h" |
5864
|
41 #include "ov-mex-fcn.h" |
5823
|
42 #include "ov-usr-fcn.h" |
3606
|
43 #include "oct-obj.h" |
3014
|
44 #include "pager.h" |
2974
|
45 #include "symtab.h" |
5823
|
46 #include "toplev.h" |
2974
|
47 #include "variables.h" |
|
48 |
5823
|
49 // Print the usage part of the doc string of FCN (user-defined or DEFUN). |
5399
|
50 |
5823
|
51 static void |
|
52 print_usage (octave_function *fcn) |
3014
|
53 { |
5823
|
54 if (fcn) |
3014
|
55 { |
5823
|
56 std::string nm = fcn->name (); |
3014
|
57 |
5823
|
58 std::string doc = fcn->doc_string (); |
|
59 |
|
60 if (doc.length () > 0) |
3014
|
61 { |
5765
|
62 std::ostringstream buf; |
4732
|
63 |
5750
|
64 buf << "\nInvalid call to " << nm << ". Correct usage is:\n\n"; |
3330
|
65 |
5823
|
66 display_usage_text (buf, doc); |
3330
|
67 |
5823
|
68 buf << "\n"; |
3014
|
69 |
5823
|
70 additional_help_message (buf); |
4732
|
71 |
5765
|
72 defun_usage_message (buf.str ()); |
3014
|
73 } |
5823
|
74 else |
|
75 error ("no usage message found for `%s'", nm.c_str ()); |
3014
|
76 } |
|
77 else |
5823
|
78 error ("print_usage: invalid function"); |
|
79 } |
|
80 |
|
81 // Print the usage part of the doc string of the current function |
|
82 // (user-defined or DEFUN). |
|
83 |
|
84 void |
|
85 print_usage (void) |
|
86 { |
|
87 print_usage (octave_call_stack::current ()); |
|
88 } |
|
89 |
|
90 // Deprecated. |
|
91 void |
|
92 print_usage (const std::string&) |
|
93 { |
|
94 print_usage (); |
3014
|
95 } |
|
96 |
5800
|
97 DEFUN (print_usage, args, , |
|
98 "-*- texinfo -*-\n\ |
5823
|
99 @deftypefn {Loadable Function} {} print_usage ()\n\ |
|
100 Print the usage message for the currently executing function. The\n\ |
|
101 @code{print_usage} function is only intended to work inside a\n\ |
|
102 user-defined function.\n\ |
5800
|
103 @seealso{help}\n\ |
|
104 @end deftypefn") |
|
105 { |
|
106 octave_value retval; |
|
107 |
5823
|
108 if (args.length () == 0) |
|
109 print_usage (octave_call_stack::caller_user_function ()); |
5800
|
110 else |
5823
|
111 print_usage (); |
5800
|
112 |
|
113 return retval; |
|
114 } |
|
115 |
3015
|
116 void |
3523
|
117 check_version (const std::string& version, const std::string& fcn) |
3015
|
118 { |
4448
|
119 if (version != OCTAVE_API_VERSION) |
3986
|
120 { |
4448
|
121 error ("API version %s found in .oct file function `%s'\n" |
|
122 " does not match the running Octave (API version %s)\n" |
|
123 " this can lead to incorrect results or other failures\n" |
|
124 " you can fix this problem by recompiling this .oct file", |
|
125 version.c_str (), fcn.c_str (), OCTAVE_API_VERSION); |
3986
|
126 } |
3015
|
127 } |
|
128 |
2974
|
129 // Install variables and functions in the symbol tables. |
|
130 |
|
131 void |
7336
|
132 install_builtin_mapper (octave_mapper *mf, const std::string& name) |
2974
|
133 { |
7336
|
134 symbol_table::install_built_in_function (name, octave_value (mf)); |
2974
|
135 } |
|
136 |
|
137 void |
3523
|
138 install_builtin_function (octave_builtin::fcn f, const std::string& name, |
4234
|
139 const std::string& doc, bool is_text_fcn, |
|
140 bool /* can_hide_function -- not yet implemented */) |
2974
|
141 { |
7336
|
142 octave_value fcn (new octave_builtin (f, name, doc)); |
2974
|
143 |
7336
|
144 symbol_table::install_built_in_function (name, fcn); |
2974
|
145 |
|
146 if (is_text_fcn) |
7336
|
147 mark_as_command (name); |
2974
|
148 } |
|
149 |
3258
|
150 void |
3523
|
151 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
3325
|
152 const octave_shlib& shl, |
6323
|
153 const std::string& doc, bool is_text_fcn, |
|
154 bool relative) |
3325
|
155 { |
7336
|
156 octave_dld_function *fcn = new octave_dld_function (f, shl, name, doc); |
6323
|
157 |
|
158 if (relative) |
7336
|
159 fcn->mark_relative (); |
6323
|
160 |
7336
|
161 octave_value fval (fcn); |
5397
|
162 |
7336
|
163 symbol_table::install_built_in_function (name, fval); |
5397
|
164 |
7336
|
165 if (is_text_fcn) |
|
166 mark_as_command (name); |
3325
|
167 } |
|
168 |
|
169 void |
5864
|
170 install_mex_function (void *fptr, bool fmex, const std::string& name, |
6323
|
171 const octave_shlib& shl, bool is_text_fcn, |
|
172 bool relative) |
5864
|
173 { |
7336
|
174 octave_mex_function *fcn = new octave_mex_function (fptr, fmex, shl, name); |
6323
|
175 |
|
176 if (relative) |
7336
|
177 fcn->mark_relative (); |
6323
|
178 |
7336
|
179 octave_value fval (fcn); |
5864
|
180 |
7336
|
181 symbol_table::install_built_in_function (name, fval); |
5864
|
182 |
7336
|
183 if (is_text_fcn) |
|
184 mark_as_command (name); |
5864
|
185 } |
|
186 |
|
187 void |
3523
|
188 alias_builtin (const std::string& alias, const std::string& name) |
2974
|
189 { |
7336
|
190 symbol_table::alias_built_in_function (alias, name); |
2974
|
191 } |
|
192 |
|
193 /* |
|
194 ;;; Local Variables: *** |
|
195 ;;; mode: C++ *** |
|
196 ;;; End: *** |
|
197 */ |