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