GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
help.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1993-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <cstdlib>
31 #include <cstring>
32 
33 #include <algorithm>
34 #include <fstream>
35 #include <istream>
36 #include <map>
37 #include <sstream>
38 #include <string>
39 
40 #include "cmd-edit.h"
41 #include "file-ops.h"
42 #include "file-stat.h"
43 #include "lo-sysdep.h"
44 #include "oct-env.h"
45 #include "oct-locbuf.h"
46 #include "str-vec.h"
47 
48 #include "Cell.h"
49 #include "builtin-defun-decls.h"
50 #include "defaults.h"
51 #include "defun.h"
52 #include "error.h"
53 #include "errwarn.h"
54 #include "help.h"
55 #include "input.h"
56 #include "interpreter-private.h"
57 #include "interpreter.h"
58 #include "load-path.h"
59 #include "ov-fcn-handle.h"
60 #include "ov-usr-fcn.h"
61 #include "ovl.h"
62 #include "pager.h"
63 #include "parse.h"
64 #include "pathsearch.h"
65 #include "procstream.h"
66 #include "quit.h"
67 #include "sighandlers.h"
68 #include "symtab.h"
69 #include "unwind-prot.h"
70 #include "utils.h"
71 #include "variables.h"
72 #include "version.h"
73 
74 #include "default-defs.h"
75 
76 namespace octave
77 {
78  const static char * const operators[] =
79  {
80  "!",
81  "~",
82  "!=",
83  "~=",
84  R"(")",
85  "#",
86  "%",
87  "#{",
88  "%{",
89  "#}",
90  "%}",
91  "...",
92  "&",
93  "&&",
94  "'",
95  "(",
96  ")",
97  "*",
98  "**",
99  "^",
100  "+",
101  "++",
102  ",",
103  "-",
104  "--",
105  ".'",
106  ".*",
107  ".**",
108  ".^",
109  "./",
110  "/",
111  R"(.\)",
112  R"(\)",
113  ":",
114  ";",
115  "<",
116  "<=",
117  "=",
118  "==",
119  ">",
120  ">=",
121  "[",
122  "]",
123  "|",
124  "||",
125  nullptr
126  };
127 
128  const static string_vector operator_names (operators);
129 
130  static bool
131  looks_like_html (const std::string& msg)
132  {
133  const size_t p1 = msg.find ('\n');
134  std::string t = msg.substr (0, p1);
135  // FIXME: this comparison should be case-insensitive
136  const size_t p2 = t.find ("<html");
137 
138  return (p2 != std::string::npos);
139  }
140 
141  static bool
142  looks_like_texinfo (const std::string& msg, size_t& p1)
143  {
144  p1 = msg.find ('\n');
145 
146  std::string t = msg.substr (0, p1);
147 
148  if (p1 == std::string::npos)
149  p1 = 0;
150 
151  size_t p2 = t.find ("-*- texinfo -*-");
152 
153  return (p2 != std::string::npos);
154  }
155 
158  int nargout)
159  {
160  return set_internal_variable (m_built_in_docstrings_file, args, nargout,
161  "built_in_docstrings_file", false);
162  }
163 
165  help_system::doc_cache_file (const octave_value_list& args, int nargout)
166  {
167  return set_internal_variable (m_doc_cache_file, args, nargout,
168  "doc_cache_file", false);
169  }
170 
172  help_system::info_file (const octave_value_list& args, int nargout)
173  {
174  return set_internal_variable (m_info_file, args, nargout,
175  "info_file", false);
176  }
177 
179  help_system::info_program (const octave_value_list& args, int nargout)
180  {
181  return set_internal_variable (m_info_program, args, nargout,
182  "info_program", false);
183  }
184 
186  help_system::makeinfo_program (const octave_value_list& args, int nargout)
187  {
188  return set_internal_variable (m_makeinfo_program, args, nargout,
189  "makeinfo_program", false);
190  }
191 
194  int nargout)
195  {
197  nargout, "suppress_verbose_help_message");
198  }
199 
201  help_system::texi_macros_file (const octave_value_list& args, int nargout)
202  {
203  return set_internal_variable (m_texi_macros_file, args, nargout,
204  "texi_macros_file", false);
205  }
206 
207  std::string
208  help_system::raw_help (const std::string& nm, bool& symbol_found) const
209  {
210  std::string h;
211  std::string w;
212  std::string f;
213 
214  bool found;
215 
216  found = raw_help_from_symbol_table (nm, h, w, symbol_found);
217 
218  if (! found)
219  found = raw_help_from_file (nm, h, f, symbol_found);
220 
221  bool external_doc = h.compare (0, 12, "external-doc") == 0;
222 
223  if (! found || external_doc)
224  {
225  std::string tmp_nm = nm;
226 
227  if (external_doc && h.length () > 12 && h[12] == ':')
228  tmp_nm = h.substr (13);
229 
230  raw_help_from_docstrings_file (tmp_nm, h, symbol_found);
231  }
232 
233  return h;
234  }
235 
236  std::string help_system::which (const std::string& name,
237  std::string& type) const
238  {
239  std::string file;
240 
241  if (name.empty ())
242  return file;
243 
244  type = "";
245 
246  if (name.find_first_of ('.') == std::string::npos)
247  {
248  symbol_table& symtab = m_interpreter.get_symbol_table ();
249 
250  octave_value val = symtab.find_function (name);
251 
252  if (val.is_defined ())
253  {
254  octave_function *fcn = val.function_value ();
255 
256  if (fcn)
257  {
258  file = fcn->fcn_file_name ();
259 
260  if (file.empty ())
261  {
262  if (fcn->is_user_function ())
263  type = "command-line function";
264  else
265  {
266  file = fcn->src_file_name ();
267  type = "built-in function";
268  }
269  }
270  else
271  type = val.is_user_script () ? "script" : "function";
272  }
273  }
274  else
275  {
276  // We might find a file that contains only a doc string.
277 
278  load_path& lp = m_interpreter.get_load_path ();
279 
280  file = lp.find_fcn_file (name);
281  }
282  }
283  else
284  {
285  // File query.
286 
287  load_path& lp = m_interpreter.get_load_path ();
288 
289  // For compatibility: "file." queries "file".
290  if (name.size () > 1 && name[name.size () - 1] == '.')
291  file = lp.find_file (name.substr (0, name.size () - 1));
292  else
293  file = lp.find_file (name);
294 
295  file = sys::env::make_absolute (file);
296  }
297 
298  return file;
299  }
300 
301  std::string help_system::which (const std::string& name) const
302  {
303  std::string type;
304 
305  return which (name, type);
306  }
307 
309  {
310  const static string_vector keywords
311  = Fiskeyword ()(0).string_vector_value ();
312 
313  const static int key_len = keywords.numel ();
314 
315  symbol_table& symtab = m_interpreter.get_symbol_table ();
316 
317  const string_vector bif = symtab.built_in_function_names ();
318  const int bif_len = bif.numel ();
319 
320  const string_vector cfl = symtab.cmdline_function_names ();
321  const int cfl_len = cfl.numel ();
322 
324  const int lcl_len = lcl.numel ();
325 
326  load_path& lp = m_interpreter.get_load_path ();
327 
328  const string_vector ffl = lp.fcn_names ();
329  const int ffl_len = ffl.numel ();
330 
332  const int afl_len = afl.numel ();
333 
334  const string_vector lfl = local_functions ();
335  const int lfl_len = lfl.numel ();
336 
337  const int total_len
338  = key_len + bif_len + cfl_len + lcl_len + ffl_len + afl_len + lfl_len;
339 
340  string_vector list (total_len);
341 
342  // Put all the symbols in one big list.
343 
344  int j = 0;
345  int i = 0;
346 
347  for (i = 0; i < key_len; i++)
348  list[j++] = keywords[i];
349 
350  for (i = 0; i < bif_len; i++)
351  list[j++] = bif[i];
352 
353  for (i = 0; i < cfl_len; i++)
354  list[j++] = cfl[i];
355 
356  for (i = 0; i < lcl_len; i++)
357  list[j++] = lcl[i];
358 
359  for (i = 0; i < ffl_len; i++)
360  list[j++] = ffl[i];
361 
362  for (i = 0; i < afl_len; i++)
363  list[j++] = afl[i];
364 
365  for (i = 0; i < lfl_len; i++)
366  list[j++] = lfl[i];
367 
368  return list;
369  }
370 
371  void help_system::get_help_text (const std::string& name, std::string& text,
372  std::string& format) const
373  {
374  bool symbol_found = false;
375  text = raw_help (name, symbol_found);
376 
377  format = "Not found";
378  if (symbol_found)
379  {
380  size_t idx = -1;
381  if (text.empty ())
382  {
383  format = "Not documented";
384  }
385  else if (looks_like_texinfo (text, idx))
386  {
387  format = "texinfo";
388  text.erase (0, idx);
389  }
390  else if (looks_like_html (text))
391  {
392  format = "html";
393  }
394  else
395  {
396  format = "plain text";
397  }
398  }
399  }
400 
401  void help_system::get_help_text_from_file (const std::string& fname,
402  std::string& text,
403  std::string& format) const
404  {
405  bool symbol_found = false;
406 
407  std::string f;
408 
409  raw_help_from_file (fname, text, f, symbol_found);
410 
411  format = "Not found";
412  if (symbol_found)
413  {
414  size_t idx = -1;
415  if (text.empty ())
416  {
417  format = "Not documented";
418  }
419  else if (looks_like_texinfo (text, idx))
420  {
421  format = "texinfo";
422  text.erase (0, idx);
423  }
424  else if (looks_like_html (text))
425  {
426  format = "html";
427  }
428  else
429  {
430  format = "plain text";
431  }
432  }
433  }
434 
436  {
437  std::string df = sys::env::getenv ("OCTAVE_BUILT_IN_DOCSTRINGS_FILE");
438 
439  std::string dir_sep = sys::file_ops::dir_sep_str ();
440 
441  if (df.empty ())
442  df = config::oct_etc_dir () + dir_sep + "built-in-docstrings";
443 
444  return df;
445  }
446 
447  std::string help_system::init_doc_cache_file (void)
448  {
449  std::string def_file = config::prepend_octave_home (OCTAVE_DOC_CACHE_FILE);
450 
451  std::string env_file = sys::env::getenv ("OCTAVE_DOC_CACHE_FILE");
452 
453  return (env_file.empty () ? def_file : env_file);
454  }
455 
456  std::string help_system::init_info_file (void)
457  {
458  std::string std_info_file = config::prepend_octave_home (OCTAVE_INFOFILE);
459 
460  std::string oct_info_file = sys::env::getenv ("OCTAVE_INFO_FILE");
461 
462  return (oct_info_file.empty () ? std_info_file : oct_info_file);
463  }
464 
465  std::string help_system::init_info_program (void)
466  {
467  std::string info_prog = sys::env::getenv ("OCTAVE_INFO_PROGRAM");
468 
469  if (info_prog.empty ())
470  info_prog = "info";
471 
472  return info_prog;
473  }
474 
475  std::string help_system::init_texi_macros_file (void)
476  {
477  std::string def_file
479 
480  std::string env_file = sys::env::getenv ("OCTAVE_TEXI_MACROS_FILE");
481 
482  return (env_file.empty () ? def_file : env_file);
483  }
484 
485  // Return a vector of all functions from this file,
486  // for use in command line auto-completion.
488  {
490 
491  tree_evaluator& tw = m_interpreter.get_evaluator ();
492 
493  octave_user_code *curr_fcn = tw.current_user_code ();
494 
495  if (! curr_fcn)
496  return retval;
497 
498  // All subfunctions are listed in the top-level function of this file.
499  // If curr_fcn is a subfunction, then there must be a parent and
500  // curr_fcn will always be valid in and after executing this loop.
501 
502  while (curr_fcn->is_subfunction ())
503  {
504  symbol_scope pscope = curr_fcn->parent_fcn_scope ();
505  curr_fcn = pscope.user_code ();
506  }
507 
508  // Get subfunctions.
509  const std::list<std::string> names = curr_fcn->subfunction_names ();
510 
511  size_t sz = names.size ();
512  retval.resize (sz);
513 
514  // Loop over them.
515  size_t i = 0;
516  for (const auto& nm : names)
517  retval(i++) = nm;
518 
519  return retval;
520  }
521 
522  bool help_system::raw_help_from_symbol_table (const std::string& nm,
523  std::string& h, std::string& w,
524  bool& symbol_found) const
525  {
526  std::string meth_nm;
527 
528  symbol_table& symtab = m_interpreter.get_symbol_table ();
529 
530  octave_value val = symtab.find_function (nm);
531 
532  if (! val.is_defined ())
533  {
534  size_t pos = nm.rfind ('.');
535 
536  if (pos != std::string::npos)
537  {
538  meth_nm = nm.substr (pos+1);
539 
540  val = symtab.find_function (nm.substr (0, pos));
541  }
542  }
543 
544  if (val.is_defined ())
545  {
546  octave_function *fcn = val.function_value ();
547 
548  if (fcn)
549  {
550  // FCN may actually be a classdef_meta object.
551 
552  symbol_found = true;
553 
554  h = fcn->doc_string (meth_nm);
555 
556  w = fcn->fcn_file_name ();
557 
558  if (w.empty ())
559  w = fcn->is_user_function () ? "command-line function"
560  : "built-in function";
561 
562  return true;
563  }
564  }
565 
566  return false;
567  }
568 
569  bool help_system::raw_help_from_file (const std::string& nm,
570  std::string& h, std::string& file,
571  bool& symbol_found) const
572  {
573  bool retval = false;
574 
575  h = get_help_from_file (nm, symbol_found, file);
576 
577  if (h.length () > 0)
578  retval = true;
579 
580  return retval;
581  }
582 
583  bool
584  help_system::raw_help_from_docstrings_file (const std::string& nm,
585  std::string& h,
586  bool& symbol_found) const
587  {
588  typedef std::pair<std::streampos, std::streamoff> txt_limits_type;
589  typedef std::map<std::string, txt_limits_type> help_txt_map_type;
590 
591  static help_txt_map_type help_txt_map;
592  static bool initialized = false;
593 
594  h = "";
595  symbol_found = false;
596 
597  // FIXME: Should we cache the timestamp of the file and reload the
598  // offsets if it changes? Or just warn about that? Or just ignore
599  // it, and assume it won't change?
600 
601  if (! initialized)
602  {
604  std::ios::in | std::ios::binary);
605 
606  if (! file)
607  error ("failed to open docstrings file: %s",
608  m_built_in_docstrings_file.c_str ());
609 
610  // Ignore header;
611  file.ignore (std::numeric_limits<std::streamsize>::max(), 0x1d);
612 
613  if (file.eof ())
614  error ("invalid built-in-docstrings file!");
615 
616  // FIXME: eliminate fixed buffer size.
617  size_t bufsize = 1000;
618  OCTAVE_LOCAL_BUFFER (char, buf, bufsize);
619 
620  while (! file.eof ())
621  {
622  std::string name;
623  int i = 0;
624  int c;
625  while (file && (c = file.get ()) != std::istream::traits_type::eof ())
626  {
627  if (c == '\n' || c == '\r')
628  {
629  buf[i] = '\0';
630  name = buf;
631  break;
632  }
633  else
634  buf[i++] = c;
635  }
636 
637  // Skip @c FILENAME which is part of current DOCSTRINGS
638  // syntax. This may disappear if a specific format for
639  // docstring files is developed.
640  while (file
641  && (c = file.get ()) != std::istream::traits_type::eof ()
642  && c != '\n' && c != '\r')
643  ; // skip text
644 
645  // skip newline characters
646  while (file
647  && (c = file.get ()) != std::istream::traits_type::eof ()
648  && (c == '\n' || c == '\r'))
649  ; // skip text
650 
651  file.unget ();
652 
653  // Position of beginning of help text.
654  std::streampos beg = file.tellg ();
655 
656  // Skip help text.
657  file.ignore (std::numeric_limits<std::streamsize>::max(), 0x1d);
658 
659  // Position of end of help text.
660  std::streamoff len;
661 
662  if (! file.eof ())
663  len = file.tellg () - beg - 1;
664  else
665  {
666  file.seekg (0, file.end);
667  len = file.tellg () - beg - 1;
668  file.setstate (file.eofbit); // reset eof flag
669  }
670 
671  help_txt_map[name] = txt_limits_type (beg, len);
672  }
673 
674  initialized = true;
675  }
676 
677  help_txt_map_type::const_iterator it = help_txt_map.find (nm);
678 
679  if (it != help_txt_map.end ())
680  {
681  txt_limits_type txt_limits = it->second;
682 
683  std::streampos beg = txt_limits.first;
684  std::streamoff len = txt_limits.second;
685 
687  std::ios::in | std::ios::binary);
688 
689  if (! file)
690  error ("failed to open docstrings file: %s",
691  m_built_in_docstrings_file.c_str ());
692 
693  file.seekg (beg);
694 
695  size_t txt_len = len;
696  OCTAVE_LOCAL_BUFFER (char, buf, txt_len + 1);
697 
698  file.read (buf, txt_len);
699 
700  buf[txt_len] = '\0';
701 
702  h = buf;
703 
704  symbol_found = true;
705  }
706 
707  return symbol_found;
708  }
709 
710  // FIXME: It's not likely that this does the right thing now.
711 
713  {
714  help_system& help_sys = __get_help_system__ ("make_name_list");
715 
716  return help_sys.make_name_list ();
717  }
718 }
719 
720 DEFMETHOD (get_help_text, interp, args, ,
721  doc: /* -*- texinfo -*-
722 @deftypefn {} {[@var{text}, @var{format}] =} get_help_text (@var{name})
723 Return the raw help text of function @var{name}.
724 
725 The raw help text is returned in @var{text} and the format in @var{format}.
726 The format is a string which is one of @qcode{"texinfo"}, @qcode{"html"}, or
727 @w{@qcode{"plain text"}}.
728 @seealso{get_help_text_from_file}
729 @end deftypefn */)
730 {
731  if (args.length () != 1)
732  print_usage ();
733 
734  const std::string name = args(0).xstring_value ("get_help_text: NAME must be a string");
735 
736  octave::help_system& help_sys = interp.get_help_system ();
737 
738  std::string text, format;
739 
740  help_sys.get_help_text (name, text, format);
741 
742  return ovl (text, format);
743 }
744 
745 DEFMETHOD (get_help_text_from_file, interp, args, ,
746  doc: /* -*- texinfo -*-
747 @deftypefn {} {[@var{text}, @var{format}] =} get_help_text_from_file (@var{fname})
748 Return the raw help text from the file @var{fname}.
749 
750 The raw help text is returned in @var{text} and the format in @var{format}.
751 The format is a string which is one of @qcode{"texinfo"}, @qcode{"html"}, or
752 @w{@qcode{"plain text"}}.
753 @seealso{get_help_text}
754 @end deftypefn */)
755 {
756  if (args.length () != 1)
757  print_usage ();
758 
759  const std::string fname = args(0).xstring_value ("get_help_text_from_file: NAME must be a string");
760 
761  octave::help_system& help_sys = interp.get_help_system ();
762 
763  std::string text, format;
764 
765  help_sys.get_help_text_from_file (fname, text, format);
766 
767  return ovl (text, format);
768 }
769 
770 // Return a cell array of strings containing the names of all operators.
771 
772 DEFUN (__operators__, , ,
773  doc: /* -*- texinfo -*-
774 @deftypefn {} {} __operators__ ()
775 Undocumented internal function.
776 @end deftypefn */)
777 {
778  return ovl (Cell (octave::operator_names));
779 }
780 
781 // Return a cell array of strings containing the names of all keywords.
782 // iskeyword() function is located in lex.ll and is based on what the parser
783 // thinks is a keyword.
784 
785 DEFALIAS (__keywords__, iskeyword)
786 
787 // Return a cell array of strings with the names of all builtin functions.
788 
789 DEFMETHOD (__builtins__, interp, , ,
790  doc: /* -*- texinfo -*-
791 @deftypefn {} {} __builtins__ ()
792 Undocumented internal function.
793 @end deftypefn */)
794 {
795  octave::symbol_table& symtab = interp.get_symbol_table ();
796 
797  const string_vector bif = symtab.built_in_function_names ();
798 
799  return ovl (Cell (bif));
800 }
801 
802 DEFMETHOD (localfunctions, interp, args, ,
803  doc: /* -*- texinfo -*-
804 @deftypefn {} {} localfunctions ()
805 Return a list of all local functions, i.e., subfunctions, within the current
806 file.
807 
808 The return value is a column cell array of function handles to all local
809 functions accessible from the function from which @code{localfunctions} is
810 called. Nested functions are @emph{not} included in the list.
811 
812 If the call is from the command line, an anonymous function, or a script,
813 the return value is an empty cell array.
814 
815 @seealso{functions}
816 @end deftypefn */)
817 {
818  if (args.length () != 0)
819  print_usage ();
820 
821  Cell retval;
822 
823  // Find the main function we are in.
824  octave::tree_evaluator& tw = interp.get_evaluator ();
825  octave_user_code *caller = tw.debug_user_code ();
826 
827  if (! caller)
828  return ovl (retval);
829 
830  octave::symbol_scope scope = caller->scope ();
831 
832  return ovl (Cell (scope.localfunctions ()));
833 }
834 
835 /*
836 %!test
837 %! f = tempname (tempdir (), "oct_");
838 %! [~, fcn_name] = fileparts (f);
839 %! f = [f ".m"];
840 %! save_path = path ();
841 %! unwind_protect
842 %! addpath (tempdir ());
843 %! fid = fopen (f, "w+");
844 %! fprintf (fid, "function z = %s\n z = localfunctions; end\n", fcn_name);
845 %! fprintf (fid, "function z = b(x)\n z = x+1; end\n");
846 %! fprintf (fid, "function z = c(x)\n z = 2*x; end\n");
847 %! fclose (fid);
848 %! d = eval (fcn_name);
849 %! assert (size (d), [2, 1]);
850 %! assert (d{1} (3), 4);
851 %! assert (d{2} (3), 6);
852 %! unwind_protect_cleanup
853 %! unlink (f);
854 %! path (save_path);
855 %! end_unwind_protect
856 */
857 
858 DEFMETHOD (__which__, interp, args, ,
859  doc: /* -*- texinfo -*-
860 @deftypefn {} {} __which__ (@var{name}, @dots{})
861 Undocumented internal function.
862 @end deftypefn */)
863 {
864  octave::help_system& help_sys = interp.get_help_system ();
865 
866  string_vector argv = args.make_argv ();
867 
868  int nargin = argv.numel ();
869 
870  octave_map m (dim_vector (1, nargin));
871 
872  Cell names (1, nargin);
873  Cell files (1, nargin);
874  Cell types (1, nargin);
875 
876  for (int i = 0; i < nargin; i++)
877  {
878  std::string name = argv[i];
879 
880  std::string type;
881 
882  std::string file = help_sys.which (name, type);
883 
884  names(i) = name;
885  files(i) = file;
886  types(i) = type;
887  }
888 
889  m.assign ("name", names);
890  m.assign ("file", files);
891  m.assign ("type", types);
892 
893  return ovl (m);
894 }
895 
896 // Return a cell array of strings containing the names of all
897 // functions available in DIRECTORY. If no directory is given, search
898 // the current path.
899 
900 DEFMETHOD (__list_functions__, interp, args, ,
901  doc: /* -*- texinfo -*-
902 @deftypefn {} {@var{retval} =} __list_functions__ ()
903 @deftypefnx {} {@var{retval} =} __list_functions__ (@var{directory})
904 Return a list of all functions (.m and .oct functions) in the load path.
905 
906 If the optional argument @var{directory} is given then list only the functions
907 in that directory.
908 @seealso{path}
909 @end deftypefn */)
910 {
912 
913  octave::load_path& lp = interp.get_load_path ();
914 
915  if (args.length () == 0)
916  {
917  // Get list of all functions
918  string_vector ffl = lp.fcn_names ();
919  string_vector afl = interp.autoloaded_functions ();
920 
921  retval = Cell (ffl.append (afl));
922  }
923  else
924  {
925  std::string dir = args(0).xstring_value ("__list_functions__: DIRECTORY argument must be a string");
926 
927  string_vector fl = lp.files (dir, true);
928 
929  // Return a sorted list with unique entries (in case of .m and .oct
930  // versions of the same function in a given directory, for example).
931  fl.sort (true);
932 
933  retval = Cell (fl);
934  }
935 
936  return retval;
937 }
938 
939 DEFMETHOD (built_in_docstrings_file, interp, args, nargout,
940  doc: /* -*- texinfo -*-
941 @deftypefn {} {@var{val} =} built_in_docstrings_file ()
942 @deftypefnx {} {@var{old_val} =} built_in_docstrings_file (@var{new_val})
943 @deftypefnx {} {} built_in_docstrings_file (@var{new_val}, "local")
944 Query or set the internal variable that specifies the name of the
945 file containing docstrings for built-in Octave functions.
946 
947 The default value is
948 @file{@var{octave-home}/share/octave/@var{version}/etc/built-in-docstrings},
949 in which @var{octave-home} is the root directory of the Octave installation,
950 and @var{version} is the Octave version number. The default value may be
951 overridden by the environment variable
952 @w{@env{OCTAVE_BUILT_IN_DOCSTRINGS_FILE}}, or the command line argument
953 @option{--built-in-docstrings-file FNAME}.
954 
955 Note: This variable is only used when Octave is initializing itself.
956 Modifying it during a running session of Octave will have no effect.
957 @end deftypefn */)
958 {
959  octave::help_system& help_sys = interp.get_help_system ();
960 
961  return help_sys.built_in_docstrings_file (args, nargout);
962 }
963 
964 DEFMETHOD (doc_cache_file, interp, args, nargout,
965  doc: /* -*- texinfo -*-
966 @deftypefn {} {@var{val} =} doc_cache_file ()
967 @deftypefnx {} {@var{old_val} =} doc_cache_file (@var{new_val})
968 @deftypefnx {} {} doc_cache_file (@var{new_val}, "local")
969 Query or set the internal variable that specifies the name of the
970 Octave documentation cache file.
971 
972 A cache file significantly improves the performance of the @code{lookfor}
973 command. The default value is
974 @file{@var{octave-home}/share/octave/@var{version}/etc/doc-cache},
975 in which @var{octave-home} is the root directory of the Octave installation,
976 and @var{version} is the Octave version number.
977 The default value may be overridden by the environment variable
978 @w{@env{OCTAVE_DOC_CACHE_FILE}}, or the command line argument
979 @option{--doc-cache-file FNAME}.
980 
981 When called from inside a function with the @qcode{"local"} option, the
982 variable is changed locally for the function and any subroutines it calls.
983 The original variable value is restored when exiting the function.
984 @seealso{doc_cache_create, lookfor, info_program, doc, help, makeinfo_program}
985 @seealso{lookfor}
986 @end deftypefn */)
987 {
988  octave::help_system& help_sys = interp.get_help_system ();
989 
990  return help_sys.doc_cache_file (args, nargout);
991 }
992 
993 DEFMETHOD (info_file, interp, args, nargout,
994  doc: /* -*- texinfo -*-
995 @deftypefn {} {@var{val} =} info_file ()
996 @deftypefnx {} {@var{old_val} =} info_file (@var{new_val})
997 @deftypefnx {} {} info_file (@var{new_val}, "local")
998 Query or set the internal variable that specifies the name of the
999 Octave info file.
1000 
1001 The default value is
1002 @file{@var{octave-home}/share/info/octave.info}, in
1003 which @var{octave-home} is the root directory of the Octave installation.
1004 The default value may be overridden by the environment variable
1005 @w{@env{OCTAVE_INFO_FILE}}, or the command line argument
1006 @option{--info-file FNAME}.
1007 
1008 When called from inside a function with the @qcode{"local"} option, the
1009 variable is changed locally for the function and any subroutines it calls.
1010 The original variable value is restored when exiting the function.
1011 @seealso{info_program, doc, help, makeinfo_program}
1012 @end deftypefn */)
1013 {
1014  octave::help_system& help_sys = interp.get_help_system ();
1015 
1016  return help_sys.info_file (args, nargout);
1017 }
1018 
1019 DEFMETHOD (info_program, interp, args, nargout,
1020  doc: /* -*- texinfo -*-
1021 @deftypefn {} {@var{val} =} info_program ()
1022 @deftypefnx {} {@var{old_val} =} info_program (@var{new_val})
1023 @deftypefnx {} {} info_program (@var{new_val}, "local")
1024 Query or set the internal variable that specifies the name of the
1025 info program to run.
1026 
1027 The default value is "@file{info}". The default value may be overridden by the
1028 environment variable @w{@env{OCTAVE_INFO_PROGRAM}}, or the command line
1029 argument @option{--info-program NAME}.
1030 
1031 When called from inside a function with the @qcode{"local"} option, the
1032 variable is changed locally for the function and any subroutines it calls.
1033 The original variable value is restored when exiting the function.
1034 @seealso{info_file, doc, help, makeinfo_program}
1035 @end deftypefn */)
1036 {
1037  octave::help_system& help_sys = interp.get_help_system ();
1038 
1039  return help_sys.info_program (args, nargout);
1040 }
1041 
1042 DEFMETHOD (makeinfo_program, interp, args, nargout,
1043  doc: /* -*- texinfo -*-
1044 @deftypefn {} {@var{val} =} makeinfo_program ()
1045 @deftypefnx {} {@var{old_val} =} makeinfo_program (@var{new_val})
1046 @deftypefnx {} {} makeinfo_program (@var{new_val}, "local")
1047 Query or set the internal variable that specifies the name of the
1048 program that Octave runs to format help text containing
1049 Texinfo markup commands.
1050 
1051 The default value is @code{makeinfo}.
1052 
1053 When called from inside a function with the @qcode{"local"} option, the
1054 variable is changed locally for the function and any subroutines it calls.
1055 The original variable value is restored when exiting the function.
1056 @seealso{texi_macros_file, info_file, info_program, doc, help}
1057 @end deftypefn */)
1058 {
1059  octave::help_system& help_sys = interp.get_help_system ();
1060 
1061  return help_sys.makeinfo_program (args, nargout);
1062 }
1063 
1064 DEFMETHOD (suppress_verbose_help_message, interp, args, nargout,
1065  doc: /* -*- texinfo -*-
1066 @deftypefn {} {@var{val} =} suppress_verbose_help_message ()
1067 @deftypefnx {} {@var{old_val} =} suppress_verbose_help_message (@var{new_val})
1068 @deftypefnx {} {} suppress_verbose_help_message (@var{new_val}, "local")
1069 Query or set the internal variable that controls whether Octave
1070 will add additional help information to the end of the output from
1071 the @code{help} command and usage messages for built-in commands.
1072 
1073 When called from inside a function with the @qcode{"local"} option, the
1074 variable is changed locally for the function and any subroutines it calls.
1075 The original variable value is restored when exiting the function.
1076 @end deftypefn */)
1077 {
1078  octave::help_system& help_sys = interp.get_help_system ();
1079 
1080  return help_sys.suppress_verbose_help_message (args, nargout);
1081 }
1082 
1083 DEFMETHOD (texi_macros_file, interp, args, nargout,
1084  doc: /* -*- texinfo -*-
1085 @deftypefn {} {@var{val} =} texi_macros_file ()
1086 @deftypefnx {} {@var{old_val} =} texi_macros_file (@var{new_val})
1087 @deftypefnx {} {} texi_macros_file (@var{new_val}, "local")
1088 Query or set the internal variable that specifies the name of the
1089 file containing Texinfo macros that are prepended to documentation strings
1090 before they are passed to makeinfo.
1091 
1092 The default value is
1093 @file{@var{octave-home}/share/octave/@var{version}/etc/macros.texi},
1094 in which @var{octave-home} is the root directory of the Octave installation,
1095 and @var{version} is the Octave version number.
1096 The default value may be overridden by the environment variable
1097 @w{@env{OCTAVE_TEXI_MACROS_FILE}}, or the command line argument
1098 @option{--texi-macros-file FNAME}.
1099 
1100 When called from inside a function with the @qcode{"local"} option, the
1101 variable is changed locally for the function and any subroutines it calls.
1102 The original variable value is restored when exiting the function.
1103 @seealso{makeinfo_program}
1104 @end deftypefn */)
1105 {
1106  octave::help_system& help_sys = interp.get_help_system ();
1107 
1108  return help_sys.texi_macros_file (args, nargout);
1109 }
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:230
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Definition: Array.cc:1011
Definition: Cell.h:43
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
std::string raw_help(const std::string &, bool &) const
octave_value info_program(const octave_value_list &args, int nargout)
octave_value info_file(const octave_value_list &args, int nargout)
static std::string init_doc_cache_file(void)
std::string m_doc_cache_file
Definition: help.h:150
std::string makeinfo_program(void) const
Definition: help.h:98
octave_value texi_macros_file(const octave_value_list &args, int nargout)
bool suppress_verbose_help_message(void) const
Definition: help.h:108
std::string doc_cache_file(void) const
Definition: help.h:71
bool raw_help_from_symbol_table(const std::string &nm, std::string &h, std::string &w, bool &symbol_found) const
interpreter & m_interpreter
Definition: help.h:142
bool m_suppress_verbose_help_message
Definition: help.h:165
std::string built_in_docstrings_file(void) const
Definition: help.h:62
string_vector make_name_list(void) const
std::string info_program(void) const
Definition: help.h:89
std::string m_built_in_docstrings_file
Definition: help.h:146
bool raw_help_from_file(const std::string &nm, std::string &h, std::string &file, bool &symbol_found) const
octave_value suppress_verbose_help_message(const octave_value_list &args, int nargout)
string_vector local_functions(void) const
bool raw_help_from_docstrings_file(const std::string &nm, std::string &h, bool &symbol_found) const
std::string m_texi_macros_file
Definition: help.h:170
octave_value makeinfo_program(const octave_value_list &args, int nargout)
std::string info_file(void) const
Definition: help.h:80
octave_value built_in_docstrings_file(const octave_value_list &args, int nargout)
static std::string init_info_file(void)
static std::string init_texi_macros_file(void)
std::string m_info_file
Definition: help.h:154
std::string texi_macros_file(void) const
Definition: help.h:120
std::string m_info_program
Definition: help.h:158
std::string m_makeinfo_program
Definition: help.h:161
std::string which(const std::string &name) const
void get_help_text_from_file(const std::string &fname, std::string &text, std::string &format) const
static std::string init_info_program(void)
void get_help_text(const std::string &name, std::string &text, std::string &format) const
octave_value doc_cache_file(const octave_value_list &args, int nargout)
static std::string init_built_in_docstrings_file(void)
std::list< std::string > variable_names(void)
std::list< std::string > autoloaded_functions(void) const
load_path & get_load_path(void)
Definition: interpreter.h:243
symbol_table & get_symbol_table(void)
Definition: interpreter.h:258
tree_evaluator & get_evaluator(void)
std::string find_fcn_file(const std::string &fcn, const std::string &pack_name="")
Definition: load-path.h:131
string_vector files(const std::string &dir, bool omit_exts=false) const
Definition: load-path.cc:858
string_vector fcn_names(void) const
Definition: load-path.cc:886
std::string find_file(const std::string &file) const
Definition: load-path.cc:538
std::list< octave_value > localfunctions(void) const
Definition: symscope.cc:327
std::list< std::string > built_in_function_names(void)
Definition: symtab.cc:597
static std::string getenv(const std::string &name)
Definition: oct-env.cc:271
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
Definition: oct-env.cc:133
octave_user_code * debug_user_code(void) const
Definition: pt-eval.cc:1902
virtual bool is_user_function(void) const
Definition: ov-base.h:471
virtual std::string fcn_file_name(void) const
Definition: ov-fcn.h:78
virtual std::string doc_string(const std::string &="") const
Definition: ov-fcn.h:227
virtual std::list< std::string > subfunction_names(void) const
Definition: ov-fcn.h:205
virtual std::string src_file_name(void) const
Definition: ov-fcn.h:80
virtual bool is_subfunction(void) const
Definition: ov-fcn.h:111
virtual octave::symbol_scope parent_fcn_scope(void) const
Definition: ov-fcn.h:87
octave::symbol_scope scope(void)
Definition: ov-usr-fcn.h:98
bool is_defined(void) const
Definition: ov.h:551
bool is_user_script(void) const
Definition: ov.h:733
octave_function * function_value(bool silent=false) const
string_vector & append(const std::string &s)
Definition: str-vec.cc:110
string_vector & sort(bool make_uniq=false)
Definition: str-vec.cc:77
octave_idx_type numel(void) const
Definition: str-vec.h:100
#define OCTAVE_TEXI_MACROS_FILE
#define OCTAVE_INFOFILE
#define OCTAVE_DOC_CACHE_FILE
OCTINTERP_API void print_usage(void)
Definition: defun.cc:53
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
Definition: defun.h:138
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
#define DEFALIAS(alias, name)
Macro to define an alias for another existing function name.
Definition: defun.h:214
void error(const char *fmt,...)
Definition: error.cc:968
QString name
OCTAVE_EXPORT octave_value_list Fiskeyword(const octave_value_list &args, int)
Definition: lex.cc:4971
T octave_idx_type m
Definition: mx-inlines.cc:773
std::complex< double > w(std::complex< double > z, double relerr=0)
std::string prepend_octave_home(const std::string &s)
Definition: defaults.cc:125
std::string oct_etc_dir(void)
Definition: defaults.cc:339
std::string dir_sep_str(void)
Definition: file-ops.cc:243
std::ifstream ifstream(const std::string &filename, const std::ios::openmode mode)
Definition: lo-sysdep.cc:381
help_system & __get_help_system__(const std::string &who)
string_vector make_name_list(void)
static double f(double k, double l_nu, double c_pm)
Definition: randpoisson.cc:118
bool iskeyword(const std::string &s)
Definition: lex.cc:1283
size_t format(std::ostream &os, const char *fmt,...)
Definition: utils.cc:1329
std::string get_help_from_file(const std::string &nm, bool &symbol_found, std::string &full_file)
Definition: oct-parse.cc:9268
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:44
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)
Definition: variables.cc:608
F77_RET_T len
Definition: xerbla.cc:61