26 #if defined (HAVE_CONFIG_H)
49 #include "builtin-defun-decls.h"
75 #include "default-defs.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);
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);
236 std::string& type)
const
263 type =
"class constructor";
265 type =
"class method";
267 type =
"classdef meta object";
279 type =
"command-line function";
283 type =
"built-in function";
305 if (name.size () > 1 && name[name.size () - 1] ==
'.')
306 file = lp.
find_file (name.substr (0, name.size () - 1));
320 return which (name, type);
328 const static int key_len = keywords.
numel ();
333 const int bif_len = bif.
numel ();
336 const int cfl_len = cfl.
numel ();
339 const int lcl_len = lcl.
numel ();
344 const int ffl_len = ffl.
numel ();
347 const int afl_len = afl.
numel ();
350 const int lfl_len = lfl.
numel ();
353 = key_len + bif_len + cfl_len + lcl_len + ffl_len + afl_len + lfl_len;
362 for (i = 0; i < key_len; i++)
363 list[j++] = keywords[i];
365 for (i = 0; i < bif_len; i++)
368 for (i = 0; i < cfl_len; i++)
371 for (i = 0; i < lcl_len; i++)
374 for (i = 0; i < ffl_len; i++)
377 for (i = 0; i < afl_len; i++)
380 for (i = 0; i < lfl_len; i++)
387 std::string&
format)
const
389 bool symbol_found =
false;
390 text =
raw_help (name, symbol_found);
395 std::size_t idx = -1;
398 format =
"Not documented";
400 else if (looks_like_texinfo (text, idx))
405 else if (looks_like_html (text))
418 std::string&
format)
const
420 bool symbol_found =
false;
429 std::size_t idx = -1;
432 format =
"Not documented";
434 else if (looks_like_texinfo (text, idx))
439 else if (looks_like_html (text))
452 std::string df = sys::env::getenv (
"OCTAVE_BUILT_IN_DOCSTRINGS_FILE");
466 std::string env_file = sys::env::getenv (
"OCTAVE_DOC_CACHE_FILE");
468 return (env_file.empty () ? def_file : env_file);
475 std::string oct_info_file = sys::env::getenv (
"OCTAVE_INFO_FILE");
477 return (oct_info_file.empty () ? std_info_file : oct_info_file);
482 std::string info_prog = sys::env::getenv (
"OCTAVE_INFO_PROGRAM");
484 if (info_prog.empty ())
495 std::string env_file = sys::env::getenv (
"OCTAVE_TEXI_MACROS_FILE");
497 return (env_file.empty () ? def_file : env_file);
526 std::size_t sz = names.size ();
531 for (
const auto& nm : names)
538 std::string& h, std::string&
w,
539 bool& symbol_found)
const
549 std::size_t pos = nm.rfind (
'.');
551 if (pos != std::string::npos)
553 meth_nm = nm.substr (pos+1);
575 :
"built-in function";
585 std::string& h, std::string& file,
586 bool& symbol_found)
const
601 bool& symbol_found)
const
603 typedef std::pair<std::streampos, std::streamoff> txt_limits_type;
604 typedef std::map<std::string, txt_limits_type> help_txt_map_type;
606 static help_txt_map_type help_txt_map;
607 static bool initialized =
false;
610 symbol_found =
false;
619 std::ios::in | std::ios::binary);
622 error (
"failed to open docstrings file: %s",
629 error (
"invalid built-in-docstrings file!");
632 std::size_t bufsize = 1000;
635 while (! file.eof ())
641 && (c = file.get ()) != std::istream::traits_type::eof ())
643 if (c ==
'\n' || c ==
'\r')
657 && (c = file.get ()) != std::istream::traits_type::eof ()
658 && c !=
'\n' && c !=
'\r')
663 && (c = file.get ()) != std::istream::traits_type::eof ()
664 && (c ==
'\n' || c ==
'\r'))
670 std::streampos beg = file.tellg ();
679 len = file.tellg () - beg - 1;
682 file.seekg (0, file.end);
683 len = file.tellg () - beg - 1;
684 file.setstate (file.eofbit);
687 help_txt_map[name] = txt_limits_type (beg,
len);
693 help_txt_map_type::const_iterator it = help_txt_map.find (nm);
695 if (it != help_txt_map.end ())
697 txt_limits_type txt_limits = it->second;
699 std::streampos beg = txt_limits.first;
700 std::streamoff
len = txt_limits.second;
703 std::ios::in | std::ios::binary);
706 error (
"failed to open docstrings file: %s",
711 std::size_t txt_len =
len;
714 file.read (buf, txt_len);
735 DEFMETHOD (get_help_text, interp, args, ,
746 if (args.length () != 1)
749 const std::string name = args(0).xstring_value (
"get_help_text: NAME must be a string");
760 DEFMETHOD (get_help_text_from_file, interp, args, ,
771 if (args.length () != 1)
774 const std::string fname = args(0).xstring_value (
"get_help_text_from_file: NAME must be a string");
787 DEFUN (__operators__, , ,
793 return ovl (
Cell (operator_names));
817 DEFMETHOD (localfunctions, interp, args, ,
833 if (args.length () != 0)
883 int nargin = argv.
numel ();
887 Cell names (1, nargin);
888 Cell files (1, nargin);
889 Cell types (1, nargin);
891 for (
int i = 0; i < nargin; i++)
893 std::string name = argv[i];
897 std::string file = help_sys.
which (name, type);
904 m.assign (
"name", names);
905 m.assign (
"file", files);
906 m.assign (
"type", types);
915 DEFMETHOD (__list_functions__, interp, args, ,
930 if (args.length () == 0)
940 std::string dir = args(0).xstring_value (
"__list_functions__: DIRECTORY argument must be a string");
954 DEFMETHOD (built_in_docstrings_file, interp, args, nargout,
979 DEFMETHOD (doc_cache_file, interp, args, nargout,
1003 help_system& help_sys = interp.get_help_system ();
1008 DEFMETHOD (info_file, interp, args, nargout,
1029 help_system& help_sys = interp.get_help_system ();
1031 return help_sys.
info_file (args, nargout);
1034 DEFMETHOD (info_program, interp, args, nargout,
1052 help_system& help_sys = interp.get_help_system ();
1057 DEFMETHOD (makeinfo_program, interp, args, nargout,
1074 help_system& help_sys = interp.get_help_system ();
1079 DEFMETHOD (suppress_verbose_help_message, interp, args, nargout,
1093 help_system& help_sys = interp.get_help_system ();
1098 DEFMETHOD (texi_macros_file, interp, args, nargout,
1121 help_system& help_sys = interp.get_help_system ();
charNDArray max(char d, const charNDArray &m)
Vector representing the dimensions (size) of an Array.
std::string m_makeinfo_program
bool m_suppress_verbose_help_message
static std::string init_texi_macros_file(void)
bool raw_help_from_symbol_table(const std::string &nm, std::string &h, std::string &w, bool &symbol_found) const
void get_help_text_from_file(const std::string &fname, std::string &text, std::string &format) const
bool raw_help_from_file(const std::string &nm, std::string &h, std::string &file, bool &symbol_found) const
std::string info_program(void) const
std::string m_doc_cache_file
string_vector make_name_list(void) 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
bool raw_help_from_docstrings_file(const std::string &nm, std::string &h, bool &symbol_found) const
static std::string init_info_program(void)
std::string m_built_in_docstrings_file
interpreter & m_interpreter
std::string which(const std::string &name) const
octave_value info_file(const octave_value_list &args, int nargout)
std::string doc_cache_file(void) const
static std::string init_doc_cache_file(void)
static std::string init_built_in_docstrings_file(void)
std::string m_texi_macros_file
std::string makeinfo_program(void) const
static std::string init_info_file(void)
octave_value info_program(const octave_value_list &args, int nargout)
bool suppress_verbose_help_message(void) const
std::string texi_macros_file(void) const
std::string built_in_docstrings_file(void) const
std::string info_file(void) const
string_vector local_functions(void) const
octave_value suppress_verbose_help_message(const octave_value_list &args, int nargout)
octave_value doc_cache_file(const octave_value_list &args, int nargout)
std::string m_info_program
octave_value makeinfo_program(const octave_value_list &args, int nargout)
octave_value texi_macros_file(const octave_value_list &args, int nargout)
tree_evaluator & get_evaluator(void)
symbol_table & get_symbol_table(void)
std::list< std::string > variable_names(void)
load_path & get_load_path(void)
std::list< std::string > autoloaded_functions(void) const
string_vector files(const std::string &dir, bool omit_exts=false) const
std::string find_file(const std::string &file) const
string_vector fcn_names(void) const
std::string find_fcn_file(const std::string &fcn, const std::string &pack_name="")
virtual bool is_user_function(void) const
virtual bool is_classdef_meta(void) const
virtual std::string fcn_file_name(void) const
virtual std::string doc_string(const std::string &="") const
virtual std::list< std::string > subfunction_names(void) const
virtual std::string src_file_name(void) const
virtual bool is_subfunction(void) const
virtual octave::symbol_scope parent_fcn_scope(void) const
octave::symbol_scope scope(void)
OCTINTERP_API octave_function * function_value(bool silent=false) const
bool is_defined(void) const
bool is_user_script(void) 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(void) const
octave_user_code * user_code(void) const
std::list< octave_value > localfunctions(void) const
std::list< std::string > cmdline_function_names(void)
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope())
std::list< std::string > built_in_function_names(void)
octave_user_code * current_user_code(void) const
octave_user_code * debug_user_code(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::string oct_etc_dir(void)
OCTINTERP_API void print_usage(void)
#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(void)
string_vector make_name_list(void)
help_system & __get_help_system__(void)
bool iskeyword(const std::string &s)
OCTAVE_EXPORT octave_value_list Fiskeyword(const octave_value_list &args, int)
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)
#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.
static OCTAVE_UNUSED std::string prepend_octave_home(const std::string &s)
static string_vector make_absolute(const string_vector &sv)
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)