26 #if defined (HAVE_CONFIG_H)
79 const static char *
const operators[] =
130 looks_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);
141 looks_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);
236 help_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;
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))
571 help_system::init_built_in_docstrings_file ()
573 std::string df = sys::env::getenv (
"OCTAVE_BUILT_IN_DOCSTRINGS_FILE");
584 help_system::init_doc_cache_file ()
588 std::string env_file = sys::env::getenv (
"OCTAVE_DOC_CACHE_FILE");
590 return (env_file.empty () ? def_file : env_file);
594 help_system::init_info_file ()
598 std::string oct_info_file = sys::env::getenv (
"OCTAVE_INFO_FILE");
600 return (oct_info_file.empty () ? std_info_file : oct_info_file);
604 help_system::init_info_program ()
606 std::string info_prog = sys::env::getenv (
"OCTAVE_INFO_PROGRAM");
608 if (info_prog.empty ())
615 help_system::init_texi_macros_file ()
620 std::string env_file = sys::env::getenv (
"OCTAVE_TEXI_MACROS_FILE");
622 return (env_file.empty () ? def_file : env_file);
628 help_system::local_functions ()
const
652 std::size_t sz = names.size ();
657 for (
const auto& nm : names)
664 get_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;
679 what = fcn->
is_user_function () ?
"command-line function" :
"built-in function";
688 help_system::raw_help_for_class (
const cdef_class& cls,
689 const std::string& name,
690 std::string& help, std::string& what,
691 bool& symbol_found)
const
707 std::size_t pos = name.rfind (
'.');
709 if (pos != std::string::npos)
711 std::string nm = name.substr (pos+1);
715 if (get_help_from_fcn (nm, ov_meth, help, what, symbol_found))
717 what =
"constructor";
724 help = name +
" is an undocumented class";
737 help_system::raw_help_from_symbol_table (
const std::string& name, std::string& help, std::string& what,
bool& symbol_found)
const
741 size_t pos = name.find (
'.');
743 if (pos == std::string::npos)
755 && get_help_from_fcn (name, ov_fcn, help, what, symbol_found))
783 if (raw_help_for_class (cls, name, help, what, symbol_found))
790 help =
"package " + name;
799 pos = name.rfind (
'.');
800 std::string prefix = name.substr (0, pos);
801 std::string nm = name.substr (pos+1);
807 bool found_class = cls.
ok ();
815 if (get_help_from_fcn (nm, ov_meth, help, what, symbol_found))
828 what =
"class property";
843 if (get_help_from_fcn (nm, ov_fcn, help, what, symbol_found))
847 if (nm ==
"m" && raw_help_for_class (cls, prefix, help, what, symbol_found))
854 help_system::raw_help_from_file (
const std::string& nm,
855 std::string& h, std::string& file,
856 bool& symbol_found)
const
869 help_system::raw_help_from_docstrings_file (
const std::string& nm,
871 bool& symbol_found)
const
873 typedef std::pair<std::streampos, std::streamoff> txt_limits_type;
874 typedef std::map<std::string, txt_limits_type> help_txt_map_type;
876 static help_txt_map_type help_txt_map;
877 static bool initialized =
false;
880 symbol_found =
false;
889 std::ios::in | std::ios::binary);
892 error (
"failed to open docstrings file: %s",
893 m_built_in_docstrings_file.c_str ());
899 error (
"invalid built-in-docstrings file!");
902 std::size_t bufsize = 1000;
905 while (! file.eof ())
911 && (c = file.get ()) != std::istream::traits_type::eof ())
913 if (c ==
'\n' || c ==
'\r')
927 && (c = file.get ()) != std::istream::traits_type::eof ()
928 && c !=
'\n' && c !=
'\r')
933 && (c = file.get ()) != std::istream::traits_type::eof ()
934 && (c ==
'\n' || c ==
'\r'))
940 std::streampos beg = file.tellg ();
949 len = file.tellg () - beg - 1;
952 file.seekg (0, file.end);
953 len = file.tellg () - beg - 1;
954 file.setstate (file.eofbit);
957 help_txt_map[name] = txt_limits_type (beg,
len);
963 help_txt_map_type::const_iterator it = help_txt_map.find (nm);
965 if (it != help_txt_map.end ())
967 txt_limits_type txt_limits = it->second;
969 std::streampos beg = txt_limits.first;
970 std::streamoff
len = txt_limits.second;
973 std::ios::in | std::ios::binary);
976 error (
"failed to open docstrings file: %s",
977 m_built_in_docstrings_file.c_str ());
981 std::size_t txt_len =
len;
984 file.read (buf, txt_len);
1006 DEFMETHOD (get_help_text, interp, args, ,
1017 if (args.length () != 1)
1020 const std::string name = args(0).xstring_value (
"get_help_text: NAME must be a string");
1022 help_system& help_sys = interp.get_help_system ();
1031 DEFMETHOD (get_help_text_from_file, interp, args, ,
1042 if (args.length () != 1)
1045 const std::string fname = args(0).xstring_value (
"get_help_text_from_file: NAME must be a string");
1047 help_system& help_sys = interp.get_help_system ();
1058 DEFUN (__operators__, , ,
1064 return ovl (
Cell (operator_names));
1088 DEFMETHOD (localfunctions, interp, args, ,
1104 if (args.length () != 0)
1114 return ovl (retval);
1150 help_system& help_sys = interp.get_help_system ();
1154 int nargin = argv.
numel ();
1158 Cell names (1, nargin);
1159 Cell files (1, nargin);
1160 Cell types (1, nargin);
1162 for (
int i = 0; i < nargin; i++)
1164 std::string name = argv[i];
1168 std::string file = help_sys.
which (name, type);
1175 m.assign (
"name", names);
1176 m.assign (
"file", files);
1177 m.assign (
"type", types);
1186 DEFMETHOD (__list_functions__, interp, args, ,
1199 load_path& lp = interp.get_load_path ();
1201 if (args.length () == 0)
1211 std::string dir = args(0).xstring_value (
"__list_functions__: DIRECTORY argument must be a string");
1225 DEFMETHOD (built_in_docstrings_file, interp, args, nargout,
1245 help_system& help_sys = interp.get_help_system ();
1250 DEFMETHOD (doc_cache_file, interp, args, nargout,
1274 help_system& help_sys = interp.get_help_system ();
1279 DEFMETHOD (info_file, interp, args, nargout,
1300 help_system& help_sys = interp.get_help_system ();
1302 return help_sys.
info_file (args, nargout);
1305 DEFMETHOD (info_program, interp, args, nargout,
1323 help_system& help_sys = interp.get_help_system ();
1328 DEFMETHOD (makeinfo_program, interp, args, nargout,
1345 help_system& help_sys = interp.get_help_system ();
1350 DEFMETHOD (suppress_verbose_help_message, interp, args, nargout,
1364 help_system& help_sys = interp.get_help_system ();
1369 DEFMETHOD (texi_macros_file, interp, args, nargout,
1392 help_system& help_sys = interp.get_help_system ();
1397 OCTAVE_END_NAMESPACE(
octave)
octave_value_list Fiskeyword(const octave_value_list &=octave_value_list(), int=0)
charNDArray max(char d, const charNDArray &m)
octave_value get_method(const std::string &nm) 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)
std::list< std::string > autoloaded_functions() const
std::list< std::string > variable_names()
cdef_manager & get_cdef_manager()
symbol_table & get_symbol_table()
tree_evaluator & get_evaluator()
load_path & get_load_path()
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 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
virtual std::list< std::string > subfunction_names() const
octave::symbol_scope scope()
bool is_classdef_meta() const
bool is_user_script() const
octave_function * 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
octave_user_code * user_code() const
std::list< octave_value > localfunctions() 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 OCTAVE_TEXI_MACROS_FILE
#define OCTAVE_DOC_CACHE_FILE
std::string prepend_octave_home(const std::string &s)
std::string oct_etc_dir()
#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,...)
std::string dir_sep_str()
string_vector make_name_list()
help_system & __get_help_system__()
bool iskeyword(const std::string &s)
F77_RET_T const F77_DBLE const F77_DBLE * f
std::ifstream ifstream(const std::string &filename, const std::ios::openmode mode)
std::complex< double > w(std::complex< double > z, double relerr=0)
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)
std::string get_help_from_file(const std::string &nm, bool &symbol_found, std::string &full_file)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
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,...)