26#if defined (HAVE_CONFIG_H)
49#include "builtin-defun-decls.h"
75#include "default-defs.h"
79const static char *
const operators[] =
130looks_like_html (
const std::string& msg)
132 const std::size_t p1 = msg.find (
'\n');
133 std::string t = msg.substr (0, p1);
135 const std::size_t p2 = t.find (
"<html");
137 return (p2 != std::string::npos);
141looks_like_texinfo (
const std::string& msg, std::size_t& p1)
143 p1 = msg.find (
'\n');
145 std::string t = msg.substr (0, p1);
147 if (p1 == std::string::npos)
150 std::size_t p2 = t.find (
"-*- texinfo -*-");
152 return (p2 != std::string::npos);
160 "built_in_docstrings_file",
false);
167 "doc_cache_file",
false);
181 "info_program",
false);
188 "makeinfo_program",
false);
196 nargout,
"suppress_verbose_help_message");
203 "texi_macros_file",
false);
215 found = raw_help_from_symbol_table (nm, h, w, symbol_found);
218 found = raw_help_from_file (nm, h,
f, symbol_found);
220 bool external_doc = h.compare (0, 12,
"external-doc") == 0;
222 if (! found || external_doc)
224 std::string tmp_nm = nm;
226 if (external_doc && h.length () > 12 && h[12] ==
':')
227 tmp_nm = h.substr (13);
229 raw_help_from_docstrings_file (tmp_nm, h, symbol_found);
236help_system::get_which_info_from_fcn (
const std::string& name,
const octave_value& ov_fcn, std::string& file, std::string& type)
const
255 type =
"class constructor";
257 type =
"class method";
259 type =
"classdef meta object";
270 type =
"command-line function";
274 type =
"built-in function";
303 std::string& type)
const
314 size_t pos = name.find (
'.');
316 if (pos == std::string::npos)
323 if (get_which_info_from_fcn (name, ov_fcn, file, type))
354 type =
"classdef class";
372 pos = name.rfind (
'.');
373 std::string prefix = name.substr (0, pos);
374 std::string nm = name.substr (pos+1);
386 if (get_which_info_from_fcn (nm, ov_meth, file, type))
396 type =
"class property";
410 if (get_which_info_from_fcn (nm, ov_fcn, file, type))
419 if (name.size () > 1 && name[name.size () - 1] ==
'.')
420 file = lp.
find_file (name.substr (0, name.size () - 1));
424 file = sys::env::make_absolute (file);
437 return which (name, type);
446 const static int key_len = keywords.
numel ();
451 const int bif_len = bif.
numel ();
454 const int cfl_len = cfl.
numel ();
457 const int lcl_len = lcl.
numel ();
462 const int ffl_len = ffl.
numel ();
465 const int afl_len = afl.
numel ();
468 const int lfl_len = lfl.
numel ();
471 = key_len + bif_len + cfl_len + lcl_len + ffl_len + afl_len + lfl_len;
480 for (i = 0; i < key_len; i++)
481 list[j++] = keywords[i];
483 for (i = 0; i < bif_len; i++)
486 for (i = 0; i < cfl_len; i++)
489 for (i = 0; i < lcl_len; i++)
492 for (i = 0; i < ffl_len; i++)
495 for (i = 0; i < afl_len; i++)
498 for (i = 0; i < lfl_len; i++)
506 std::string&
format)
const
508 bool symbol_found =
false;
509 text =
raw_help (name, symbol_found);
514 std::size_t idx = -1;
517 format =
"Not documented";
519 else if (looks_like_texinfo (text, idx))
524 else if (looks_like_html (text))
538 std::string&
format)
const
540 bool symbol_found =
false;
544 raw_help_from_file (fname, text,
f, symbol_found);
549 std::size_t idx = -1;
552 format =
"Not documented";
554 else if (looks_like_texinfo (text, idx))
559 else if (looks_like_html (text))
571help_system::init_built_in_docstrings_file ()
573 std::string df = sys::env::getenv (
"OCTAVE_BUILT_IN_DOCSTRINGS_FILE");
575 std::string dir_sep = sys::file_ops::dir_sep_str ();
578 df = config::oct_etc_dir () + dir_sep +
"built-in-docstrings";
584help_system::init_doc_cache_file ()
586 std::string def_file = config::prepend_octave_home (OCTAVE_DOC_CACHE_FILE);
588 std::string env_file = sys::env::getenv (
"OCTAVE_DOC_CACHE_FILE");
590 return (env_file.empty () ? def_file : env_file);
594help_system::init_info_file ()
596 std::string std_info_file = config::prepend_octave_home (OCTAVE_INFOFILE);
598 std::string oct_info_file = sys::env::getenv (
"OCTAVE_INFO_FILE");
600 return (oct_info_file.empty () ? std_info_file : oct_info_file);
604help_system::init_info_program ()
606 std::string info_prog = sys::env::getenv (
"OCTAVE_INFO_PROGRAM");
608 if (info_prog.empty ())
615help_system::init_texi_macros_file ()
618 = config::prepend_octave_home (OCTAVE_TEXI_MACROS_FILE);
620 std::string env_file = sys::env::getenv (
"OCTAVE_TEXI_MACROS_FILE");
622 return (env_file.empty () ? def_file : env_file);
628help_system::local_functions ()
const
652 std::size_t sz = names.size ();
657 for (
const auto& nm : names)
664get_help_from_fcn (
const std::string& fcn_nm,
const octave_value& ov_fcn, std::string& help, std::string& what,
bool& symbol_found)
666 symbol_found =
false;
683 help =
"undocumented constructor: ";
685 help =
"undocumented method: ";
687 help =
"undocumented function: ";
693 what = fcn->
is_user_function () ?
"command-line function" :
"built-in function";
702help_system::raw_help_for_class (
const cdef_class& cls,
703 const std::string& name,
704 std::string& help, std::string& what,
705 bool& symbol_found)
const
721 std::size_t pos = name.rfind (
'.');
723 if (pos != std::string::npos)
725 std::string nm = name.substr (pos+1);
729 if (get_help_from_fcn (nm, ov_meth, help, what, symbol_found))
731 what =
"constructor";
741 if (get_help_from_fcn (name, ov_meth, help, what, symbol_found))
743 what =
"constructor";
751 help =
"default constructor: obj = " + name +
" ()";
752 what =
"constructor";
764help_system::raw_help_from_symbol_table (
const std::string& name, std::string& help, std::string& what,
bool& symbol_found)
const
768 size_t pos = name.find (
'.');
770 if (pos == std::string::npos)
782 && get_help_from_fcn (name, ov_fcn, help, what, symbol_found))
810 if (raw_help_for_class (cls, name, help, what, symbol_found))
817 help =
"package " + name;
826 pos = name.rfind (
'.');
827 std::string prefix = name.substr (0, pos);
828 std::string nm = name.substr (pos+1);
834 bool found_class = cls.
ok ();
842 if (get_help_from_fcn (nm, ov_meth, help, what, symbol_found))
844 what =
"class method";
853 help =
"default constructor: obj = " + nm +
" ()";
854 what =
"constructor";
869 what =
"class property";
884 if (get_help_from_fcn (nm, ov_fcn, help, what, symbol_found))
888 if (nm ==
"m" && raw_help_for_class (cls, prefix, help, what, symbol_found))
895help_system::raw_help_from_file (
const std::string& nm,
896 std::string& h, std::string& file,
897 bool& symbol_found)
const
910help_system::raw_help_from_docstrings_file (
const std::string& nm,
912 bool& symbol_found)
const
914 typedef std::pair<std::streampos, std::streamoff> txt_limits_type;
915 typedef std::map<std::string, txt_limits_type> help_txt_map_type;
917 static help_txt_map_type help_txt_map;
918 static bool initialized =
false;
921 symbol_found =
false;
929 std::ifstream file = sys::ifstream (m_built_in_docstrings_file.c_str (),
930 std::ios::in | std::ios::binary);
933 error (
"failed to open docstrings file: %s",
934 m_built_in_docstrings_file.c_str ());
937 file.ignore (std::numeric_limits<std::streamsize>::max(), 0x1d);
940 error (
"invalid built-in-docstrings file!");
943 std::size_t bufsize = 1000;
946 while (! file.eof ())
952 && (c = file.get ()) != std::istream::traits_type::eof ())
954 if (c ==
'\n' || c ==
'\r')
968 && (c = file.get ()) != std::istream::traits_type::eof ()
969 && c !=
'\n' && c !=
'\r')
974 && (c = file.get ()) != std::istream::traits_type::eof ()
975 && (c ==
'\n' || c ==
'\r'))
981 std::streampos beg = file.tellg ();
984 file.ignore (std::numeric_limits<std::streamsize>::max(), 0x1d);
990 len = file.tellg () - beg - 1;
993 file.seekg (0, file.end);
994 len = file.tellg () - beg - 1;
995 file.setstate (file.eofbit);
998 help_txt_map[name] = txt_limits_type (beg,
len);
1004 help_txt_map_type::const_iterator it = help_txt_map.find (nm);
1006 if (it != help_txt_map.end ())
1008 txt_limits_type txt_limits = it->second;
1010 std::streampos beg = txt_limits.first;
1011 std::streamoff
len = txt_limits.second;
1013 std::ifstream file = sys::ifstream (m_built_in_docstrings_file.c_str (),
1014 std::ios::in | std::ios::binary);
1017 error (
"failed to open docstrings file: %s",
1018 m_built_in_docstrings_file.c_str ());
1022 std::size_t txt_len =
len;
1025 file.read (buf, txt_len);
1027 buf[txt_len] =
'\0';
1031 symbol_found =
true;
1034 return symbol_found;
1047DEFMETHOD (get_help_text, interp, args, ,
1058 if (args.length () != 1)
1061 const std::string name = args(0).xstring_value (
"get_help_text: NAME must be a string");
1063 help_system& help_sys = interp.get_help_system ();
1065 std::string text,
format;
1072DEFMETHOD (get_help_text_from_file, interp, args, ,
1083 if (args.length () != 1)
1086 const std::string fname = args(0).xstring_value (
"get_help_text_from_file: NAME must be a string");
1088 help_system& help_sys = interp.get_help_system ();
1090 std::string text,
format;
1099DEFUN (__operators__, , ,
1105 return ovl (
Cell (operator_names));
1129DEFMETHOD (localfunctions, interp, args, ,
1145 if (args.length () != 0)
1155 return ovl (retval);
1191 help_system& help_sys = interp.get_help_system ();
1195 int nargin = argv.
numel ();
1199 Cell names (1, nargin);
1200 Cell files (1, nargin);
1201 Cell types (1, nargin);
1203 for (
int i = 0; i < nargin; i++)
1205 std::string name = argv[i];
1209 std::string file = help_sys.
which (name, type);
1216 m.assign (
"name", names);
1217 m.assign (
"file", files);
1218 m.assign (
"type", types);
1227DEFMETHOD (__list_functions__, interp, args, ,
1240 load_path& lp = interp.get_load_path ();
1242 if (args.length () == 0)
1252 std::string dir = args(0).xstring_value (
"__list_functions__: DIRECTORY argument must be a string");
1266DEFMETHOD (built_in_docstrings_file, interp, args, nargout,
1286 help_system& help_sys = interp.get_help_system ();
1291DEFMETHOD (doc_cache_file, interp, args, nargout,
1315 help_system& help_sys = interp.get_help_system ();
1320DEFMETHOD (info_file, interp, args, nargout,
1341 help_system& help_sys = interp.get_help_system ();
1343 return help_sys.
info_file (args, nargout);
1346DEFMETHOD (info_program, interp, args, nargout,
1364 help_system& help_sys = interp.get_help_system ();
1369DEFMETHOD (makeinfo_program, interp, args, nargout,
1386 help_system& help_sys = interp.get_help_system ();
1391DEFMETHOD (suppress_verbose_help_message, interp, args, nargout,
1405 help_system& help_sys = interp.get_help_system ();
1410DEFMETHOD (texi_macros_file, interp, args, nargout,
1433 help_system& help_sys = interp.get_help_system ();
1438OCTAVE_END_NAMESPACE(octave)
octave_value get_method(const std::string &nm) const
std::string get_name() const
void file_name(const std::string &nm)
cdef_property find_property(const std::string &nm)
cdef_package find_package(const std::string &name, bool error_if_not_found=true, bool load_if_not_found=true)
cdef_class find_class(const std::string &name, bool error_if_not_found=true, bool load_if_not_found=true)
octave_value find(const std::string &nm)
std::string get_name() const
Vector representing the dimensions (size) of an Array.
string_vector make_name_list() const
std::string texi_macros_file() const
void get_help_text_from_file(const std::string &fname, std::string &text, std::string &format) const
void get_help_text(const std::string &name, std::string &text, std::string &format) const
octave_value built_in_docstrings_file(const octave_value_list &args, int nargout)
std::string raw_help(const std::string &, bool &) const
std::string info_file() const
std::string info_program() const
bool suppress_verbose_help_message() const
std::string which(const std::string &name) const
octave_value info_file(const octave_value_list &args, int nargout)
octave_value info_program(const octave_value_list &args, int nargout)
std::string built_in_docstrings_file() const
octave_value suppress_verbose_help_message(const octave_value_list &args, int nargout)
std::string doc_cache_file() const
octave_value doc_cache_file(const octave_value_list &args, int nargout)
std::string makeinfo_program() const
octave_value makeinfo_program(const octave_value_list &args, int nargout)
octave_value texi_macros_file(const octave_value_list &args, int nargout)
cdef_manager & get_cdef_manager()
std::list< std::string > autoloaded_functions() const
std::list< std::string > variable_names()
load_path & get_load_path()
tree_evaluator & get_evaluator()
symbol_table & get_symbol_table()
string_vector files(const std::string &dir, bool omit_exts=false) const
string_vector fcn_names() const
std::string find_file(const std::string &file) const
std::string find_fcn_file(const std::string &fcn, const std::string &pack_name="")
virtual bool is_classdef_meta() const
virtual bool is_user_function() const
virtual bool is_subfunction() const
virtual std::list< std::string > subfunction_names() const
virtual octave::symbol_scope parent_fcn_scope() const
virtual std::string doc_string(const std::string &="") const
virtual std::string src_file_name() const
virtual std::string fcn_file_name() const
octave::symbol_scope scope()
bool is_classdef_constructor(const std::string &cname="") const
bool is_classdef_method(const std::string &cname="") const
std::string signature() const
octave_function * function_value(bool silent=false) const
bool is_classdef_meta() const
bool is_user_script() const
bool is_user_function() const
octave_user_function * user_function_value(bool silent=false) const
string_vector & append(const std::string &s)
string_vector & sort(bool make_uniq=false)
void resize(octave_idx_type n, const std::string &rfv="")
octave_idx_type numel() const
std::list< octave_value > localfunctions() const
octave_user_code * user_code() const
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope::invalid())
std::list< std::string > cmdline_function_names()
std::list< std::string > built_in_function_names()
octave_user_code * current_user_code() const
octave_user_code * debug_user_code() const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
#define DEFALIAS(alias, name)
Macro to define an alias for another existing function name.
void error(const char *fmt,...)
string_vector make_name_list()
help_system & __get_help_system__()
bool iskeyword(const std::string &s)
octave_value_list Fiskeyword(const octave_value_list &args, int)
F77_RET_T const F77_DBLE const F77_DBLE * f
std::complex< double > w(std::complex< double > z, double relerr=0)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
std::string get_help_from_file(const std::string &nm, bool &symbol_found, std::string &full_file)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
std::size_t format(std::ostream &os, const char *fmt,...)
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)