Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #include <sstream>
00028 #include <iostream>
00029 #include <string>
00030
00031 #include "defun.h"
00032 #include "dynamic-ld.h"
00033 #include "error.h"
00034 #include "help.h"
00035 #include "ov.h"
00036 #include "ov-builtin.h"
00037 #include "ov-dld-fcn.h"
00038 #include "ov-fcn.h"
00039 #include "ov-mex-fcn.h"
00040 #include "ov-usr-fcn.h"
00041 #include "oct-obj.h"
00042 #include "oct-lvalue.h"
00043 #include "pager.h"
00044 #include "symtab.h"
00045 #include "toplev.h"
00046 #include "variables.h"
00047 #include "parse.h"
00048
00049
00050 void
00051 print_usage (void)
00052 {
00053 const octave_function *cur = octave_call_stack::current ();
00054 if (cur)
00055 print_usage (cur->name ());
00056 else
00057 error ("print_usage: invalid function");
00058 }
00059
00060 void
00061 print_usage (const std::string& name)
00062 {
00063 feval ("print_usage", octave_value (name), 0);
00064 }
00065
00066 void
00067 check_version (const std::string& version, const std::string& fcn)
00068 {
00069 if (version != OCTAVE_API_VERSION)
00070 {
00071 error ("API version %s found in .oct file function '%s'\n"
00072 " does not match the running Octave (API version %s)\n"
00073 " this can lead to incorrect results or other failures\n"
00074 " you can fix this problem by recompiling this .oct file",
00075 version.c_str (), fcn.c_str (), OCTAVE_API_VERSION);
00076 }
00077 }
00078
00079
00080
00081 void
00082 install_builtin_function (octave_builtin::fcn f, const std::string& name,
00083 const std::string& doc,
00084 bool )
00085 {
00086 octave_value fcn (new octave_builtin (f, name, doc));
00087
00088 symbol_table::install_built_in_function (name, fcn);
00089 }
00090
00091 void
00092 install_dld_function (octave_dld_function::fcn f, const std::string& name,
00093 const octave_shlib& shl, const std::string& doc,
00094 bool relative)
00095 {
00096 octave_dld_function *fcn = new octave_dld_function (f, shl, name, doc);
00097
00098 if (relative)
00099 fcn->mark_relative ();
00100
00101 octave_value fval (fcn);
00102
00103 symbol_table::install_built_in_function (name, fval);
00104 }
00105
00106 void
00107 install_mex_function (void *fptr, bool fmex, const std::string& name,
00108 const octave_shlib& shl, bool relative)
00109 {
00110 octave_mex_function *fcn = new octave_mex_function (fptr, fmex, shl, name);
00111
00112 if (relative)
00113 fcn->mark_relative ();
00114
00115 octave_value fval (fcn);
00116
00117 symbol_table::install_built_in_function (name, fval);
00118 }
00119
00120 void
00121 alias_builtin (const std::string& alias, const std::string& name)
00122 {
00123 symbol_table::alias_built_in_function (alias, name);
00124 }
00125
00126 octave_shlib
00127 get_current_shlib (void)
00128 {
00129 octave_shlib retval;
00130
00131 octave_function *curr_fcn = octave_call_stack::current ();
00132 if (curr_fcn)
00133 {
00134 if (curr_fcn->is_dld_function ())
00135 {
00136 octave_dld_function *dld = dynamic_cast<octave_dld_function *> (curr_fcn);
00137 retval = dld->get_shlib ();
00138 }
00139 else if (curr_fcn->is_mex_function ())
00140 {
00141 octave_mex_function *mex = dynamic_cast<octave_mex_function *> (curr_fcn);
00142 retval = mex->get_shlib ();
00143 }
00144 }
00145
00146 return retval;
00147 }
00148
00149 bool defun_isargout (int nargout, int iout)
00150 {
00151 const std::list<octave_lvalue> *lvalue_list = octave_builtin::curr_lvalue_list;
00152 if (iout >= std::max (nargout, 1))
00153 return false;
00154 else if (lvalue_list)
00155 {
00156 int k = 0;
00157 for (std::list<octave_lvalue>::const_iterator p = lvalue_list->begin ();
00158 p != lvalue_list->end (); p++)
00159 {
00160 if (k == iout)
00161 return ! p->is_black_hole ();
00162 k += p->numel ();
00163 if (k > iout)
00164 break;
00165 }
00166
00167 return true;
00168 }
00169 else
00170 return true;
00171 }
00172
00173 void defun_isargout (int nargout, int nout, bool *isargout)
00174 {
00175 const std::list<octave_lvalue> *lvalue_list = octave_builtin::curr_lvalue_list;
00176 if (lvalue_list)
00177 {
00178 int k = 0;
00179 for (std::list<octave_lvalue>::const_iterator p = lvalue_list->begin ();
00180 p != lvalue_list->end () && k < nout; p++)
00181 {
00182 if (p->is_black_hole ())
00183 isargout[k++] = false;
00184 else
00185 {
00186 int l = std::min (k + p->numel (),
00187 static_cast<octave_idx_type> (nout));
00188 while (k < l)
00189 isargout[k++] = true;
00190 }
00191 }
00192 }
00193 else
00194 for (int i = 0; i < nout; i++)
00195 isargout[i] = true;
00196
00197 for (int i = std::max(nargout, 1); i < nout; i++)
00198 isargout[i] = false;
00199 }
00200