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