Mercurial > hg > octave-lyh
annotate src/defun.cc @ 8283:54c25dc5b17d
parse.y: fix comment
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Oct 2008 13:04:32 -0400 |
parents | c3d21b9b94b6 |
children | f134925a1cfa |
rev | line source |
---|---|
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" |
5864 | 40 #include "ov-mex-fcn.h" |
5823 | 41 #include "ov-usr-fcn.h" |
3606 | 42 #include "oct-obj.h" |
3014 | 43 #include "pager.h" |
2974 | 44 #include "symtab.h" |
5823 | 45 #include "toplev.h" |
2974 | 46 #include "variables.h" |
47 | |
5823 | 48 // Print the usage part of the doc string of FCN (user-defined or DEFUN). |
5399 | 49 |
5823 | 50 static void |
51 print_usage (octave_function *fcn) | |
3014 | 52 { |
5823 | 53 if (fcn) |
3014 | 54 { |
5823 | 55 std::string nm = fcn->name (); |
3014 | 56 |
5823 | 57 std::string doc = fcn->doc_string (); |
58 | |
59 if (doc.length () > 0) | |
3014 | 60 { |
5765 | 61 std::ostringstream buf; |
4732 | 62 |
5750 | 63 buf << "\nInvalid call to " << nm << ". Correct usage is:\n\n"; |
3330 | 64 |
5823 | 65 display_usage_text (buf, doc); |
3330 | 66 |
5823 | 67 buf << "\n"; |
3014 | 68 |
5823 | 69 additional_help_message (buf); |
4732 | 70 |
5765 | 71 defun_usage_message (buf.str ()); |
3014 | 72 } |
5823 | 73 else |
74 error ("no usage message found for `%s'", nm.c_str ()); | |
3014 | 75 } |
76 else | |
5823 | 77 error ("print_usage: invalid function"); |
78 } | |
79 | |
80 // Print the usage part of the doc string of the current function | |
81 // (user-defined or DEFUN). | |
82 | |
83 void | |
84 print_usage (void) | |
85 { | |
86 print_usage (octave_call_stack::current ()); | |
87 } | |
88 | |
89 // Deprecated. | |
90 void | |
91 print_usage (const std::string&) | |
92 { | |
93 print_usage (); | |
3014 | 94 } |
95 | |
5800 | 96 DEFUN (print_usage, args, , |
97 "-*- texinfo -*-\n\ | |
5823 | 98 @deftypefn {Loadable Function} {} print_usage ()\n\ |
99 Print the usage message for the currently executing function. The\n\ | |
100 @code{print_usage} function is only intended to work inside a\n\ | |
101 user-defined function.\n\ | |
5800 | 102 @seealso{help}\n\ |
103 @end deftypefn") | |
104 { | |
105 octave_value retval; | |
106 | |
5823 | 107 if (args.length () == 0) |
7923
c3d21b9b94b6
eliminate octave_call_stack member functions caller_user_script and caller_user_function, and unused difference_type args
John W. Eaton <jwe@octave.org>
parents:
7503
diff
changeset
|
108 print_usage (octave_call_stack::caller_user_code ()); |
5800 | 109 else |
5823 | 110 print_usage (); |
5800 | 111 |
112 return retval; | |
113 } | |
114 | |
3015 | 115 void |
3523 | 116 check_version (const std::string& version, const std::string& fcn) |
3015 | 117 { |
4448 | 118 if (version != OCTAVE_API_VERSION) |
3986 | 119 { |
4448 | 120 error ("API version %s found in .oct file function `%s'\n" |
121 " does not match the running Octave (API version %s)\n" | |
122 " this can lead to incorrect results or other failures\n" | |
123 " you can fix this problem by recompiling this .oct file", | |
124 version.c_str (), fcn.c_str (), OCTAVE_API_VERSION); | |
3986 | 125 } |
3015 | 126 } |
127 | |
2974 | 128 // Install variables and functions in the symbol tables. |
129 | |
130 void | |
3523 | 131 install_builtin_function (octave_builtin::fcn f, const std::string& name, |
4234 | 132 const std::string& doc, bool is_text_fcn, |
133 bool /* can_hide_function -- not yet implemented */) | |
2974 | 134 { |
7336 | 135 octave_value fcn (new octave_builtin (f, name, doc)); |
2974 | 136 |
7336 | 137 symbol_table::install_built_in_function (name, fcn); |
2974 | 138 |
139 if (is_text_fcn) | |
7336 | 140 mark_as_command (name); |
2974 | 141 } |
142 | |
3258 | 143 void |
3523 | 144 install_dld_function (octave_dld_function::fcn f, const std::string& name, |
3325 | 145 const octave_shlib& shl, |
6323 | 146 const std::string& doc, bool is_text_fcn, |
147 bool relative) | |
3325 | 148 { |
7336 | 149 octave_dld_function *fcn = new octave_dld_function (f, shl, name, doc); |
6323 | 150 |
151 if (relative) | |
7336 | 152 fcn->mark_relative (); |
6323 | 153 |
7336 | 154 octave_value fval (fcn); |
5397 | 155 |
7336 | 156 symbol_table::install_built_in_function (name, fval); |
5397 | 157 |
7336 | 158 if (is_text_fcn) |
159 mark_as_command (name); | |
3325 | 160 } |
161 | |
162 void | |
5864 | 163 install_mex_function (void *fptr, bool fmex, const std::string& name, |
6323 | 164 const octave_shlib& shl, bool is_text_fcn, |
165 bool relative) | |
5864 | 166 { |
7336 | 167 octave_mex_function *fcn = new octave_mex_function (fptr, fmex, shl, name); |
6323 | 168 |
169 if (relative) | |
7336 | 170 fcn->mark_relative (); |
6323 | 171 |
7336 | 172 octave_value fval (fcn); |
5864 | 173 |
7336 | 174 symbol_table::install_built_in_function (name, fval); |
5864 | 175 |
7336 | 176 if (is_text_fcn) |
177 mark_as_command (name); | |
5864 | 178 } |
179 | |
180 void | |
3523 | 181 alias_builtin (const std::string& alias, const std::string& name) |
2974 | 182 { |
7336 | 183 symbol_table::alias_built_in_function (alias, name); |
2974 | 184 } |
185 | |
186 /* | |
187 ;;; Local Variables: *** | |
188 ;;; mode: C++ *** | |
189 ;;; End: *** | |
190 */ |