Mercurial > hg > octave-nkf
annotate src/help.cc @ 8630:540165304f00
Allow displaying 'Contents.m' files.
author | Soren Hauberg <hauberg@gmail.com> |
---|---|
date | Sun, 25 Jan 2009 17:25:15 +0100 |
parents | f134925a1cfa |
children | 52956d669506 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
4 2002, 2003, 2004, 2005, 2006, 2007 John W. Eaton | |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
240 | 24 #ifdef HAVE_CONFIG_H |
1192 | 25 #include <config.h> |
1 | 26 #endif |
27 | |
1343 | 28 #include <cstdlib> |
29 #include <cstring> | |
30 | |
5769 | 31 #include <algorithm> |
3503 | 32 #include <iostream> |
33 #include <fstream> | |
5765 | 34 #include <sstream> |
1755 | 35 #include <string> |
36 | |
1350 | 37 #ifdef HAVE_UNISTD_H |
2442 | 38 #ifdef HAVE_SYS_TYPES_H |
1295 | 39 #include <sys/types.h> |
2442 | 40 #endif |
1295 | 41 #include <unistd.h> |
42 #endif | |
1343 | 43 |
3295 | 44 #include "cmd-edit.h" |
45 #include "file-ops.h" | |
6253 | 46 #include "file-stat.h" |
2926 | 47 #include "oct-env.h" |
1755 | 48 #include "str-vec.h" |
49 | |
2492 | 50 #include <defaults.h> |
1352 | 51 #include "defun.h" |
52 #include "dirfns.h" | |
53 #include "error.h" | |
2202 | 54 #include "gripes.h" |
1352 | 55 #include "help.h" |
2177 | 56 #include "input.h" |
5832 | 57 #include "load-path.h" |
1755 | 58 #include "oct-obj.h" |
2976 | 59 #include "ov-usr-fcn.h" |
1352 | 60 #include "pager.h" |
3018 | 61 #include "parse.h" |
1466 | 62 #include "pathsearch.h" |
3295 | 63 #include "procstream.h" |
7336 | 64 #include "pt-pr-code.h" |
529 | 65 #include "sighandlers.h" |
66 #include "symtab.h" | |
2694 | 67 #include "syswait.h" |
1755 | 68 #include "toplev.h" |
242 | 69 #include "utils.h" |
1352 | 70 #include "variables.h" |
3301 | 71 #include "version.h" |
5447 | 72 #include "quit.h" |
529 | 73 |
2202 | 74 // Name of the info file specified on command line. |
75 // (--info-file file) | |
3523 | 76 std::string Vinfo_file; |
2202 | 77 |
78 // Name of the info reader we'd like to use. | |
79 // (--info-program program) | |
5794 | 80 std::string Vinfo_program; |
2202 | 81 |
3686 | 82 // Name of the makeinfo program to run. |
5794 | 83 static std::string Vmakeinfo_program = "makeinfo"; |
3686 | 84 |
2189 | 85 // If TRUE, don't print additional help message in help and usage |
86 // functions. | |
5794 | 87 static bool Vsuppress_verbose_help_message = false; |
2189 | 88 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
89 #include <map> |
3016 | 90 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
91 typedef std::map<std::string, std::string> map_type; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
92 typedef map_type::value_type pair_type; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
93 typedef map_type::const_iterator map_iter; |
3016 | 94 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
95 template<typename T, std::size_t z> |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
96 std::size_t |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
97 size (T const (&)[z]) |
1 | 98 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
99 return z; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
100 } |
1 | 101 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
102 // FIXME -- The descriptions could easily be in texinfo -- should they? |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
103 const static pair_type operators[] = |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
104 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
105 pair_type ("!", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
106 "Logical not operator. See also `~'.\n"), |
1 | 107 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
108 pair_type ("!=", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
109 "Logical not equals operator. See also `~='.\n"), |
1 | 110 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
111 pair_type ("\"", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
112 "String delimiter.\n"), |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
113 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
114 pair_type ("#", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
115 "Begin comment character. See also `%'."), |
1 | 116 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
117 pair_type ("%", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
118 "Begin comment charcter. See also `#'."), |
1 | 119 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
120 pair_type ("&", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
121 "Element by element logical and operator. See also `&&'."), |
1 | 122 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
123 pair_type ("&&", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
124 "Logical and operator (with short-circuit evaluation). See also `&'."), |
1 | 125 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
126 pair_type ("'", |
1 | 127 "Matrix transpose operator. For complex matrices, computes the\n\ |
128 complex conjugate (Hermitian) transpose. See also `.''\n\ | |
129 \n\ | |
130 The single quote character may also be used to delimit strings, but\n\ | |
131 it is better to use the double quote character, since that is never\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
132 ambiguous"), |
1 | 133 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
134 pair_type ("(", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
135 "Array index or function argument delimiter."), |
1 | 136 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
137 pair_type (")", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
138 "Array index or function argument delimiter."), |
1 | 139 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
140 pair_type ("*", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
141 "Multiplication operator. See also `.*'"), |
1 | 142 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
143 pair_type ("**", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
144 "Power operator. See also `^', `.**', and `.^'"), |
1 | 145 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
146 pair_type ("+", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
147 "Addition operator."), |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
148 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
149 pair_type ("++", |
5339 | 150 "Increment operator. As in C, may be applied as a prefix or postfix\n\ |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
151 operator."), |
1 | 152 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
153 pair_type (",", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
154 "Array index, function argument, or command separator."), |
1 | 155 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
156 pair_type ("-", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
157 "Subtraction or unary negation operator."), |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
158 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
159 pair_type ("--", |
5339 | 160 "Decrement operator. As in C, may be applied as a prefix or postfix\n\ |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
161 operator."), |
1 | 162 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
163 pair_type (".'", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
164 "Matrix transpose operator. For complex matrices, computes the\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
165 transpose, *not* the complex conjugate transpose. See also `''."), |
1 | 166 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
167 pair_type (".*", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
168 "Element by element multiplication operator. See also `*'."), |
1 | 169 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
170 pair_type (".**", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
171 "Element by element power operator. See also `**', `^', and `.^'."), |
1 | 172 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
173 pair_type ("./", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
174 "Element by element division operator. See also `/' and `\\'."), |
1 | 175 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
176 pair_type (".^", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
177 "Element by element power operator. See also `**', `^', and `.^'."), |
1 | 178 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
179 pair_type ("/", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
180 "Right division. See also `\\' and `./'."), |
1 | 181 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
182 pair_type (":", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
183 "Select entire rows or columns of matrices."), |
1 | 184 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
185 pair_type (";", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
186 "Array row or command separator. See also `,'."), |
1 | 187 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
188 pair_type ("<", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
189 "Less than operator."), |
1 | 190 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
191 pair_type ("<=", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
192 "Less than or equals operator."), |
1 | 193 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
194 pair_type ("=", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
195 "Assignment operator."), |
1 | 196 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
197 pair_type ("==", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
198 "Equality test operator."), |
1 | 199 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
200 pair_type (">", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
201 "Greater than operator."), |
1 | 202 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
203 pair_type (">=", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
204 "Greater than or equals operator."), |
1 | 205 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
206 pair_type ("[", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
207 "Return list delimiter. See also `]'."), |
1 | 208 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
209 pair_type ("\\", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
210 "Left division operator. See also `/' and `./'."), |
1 | 211 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
212 pair_type ("]", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
213 "Return list delimiter. See also `['."), |
1 | 214 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
215 pair_type ("^", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
216 "Power operator. See also `**', `.^', and `.**.'"), |
1 | 217 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
218 pair_type ("|", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
219 "Element by element logical or operator. See also `||'."), |
1 | 220 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
221 pair_type ("||", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
222 "Logical or operator (with short-circuit evaluation). See also `|'."), |
1 | 223 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
224 pair_type ("~", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
225 "Logical not operator. See also `!' and `~'."), |
1 | 226 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
227 pair_type ("~=", |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
228 "Logical not equals operator. See also `!='."), |
1 | 229 }; |
230 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
231 const static pair_type keywords[] = |
1 | 232 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
233 pair_type ("break", |
5818 | 234 "-*- texinfo -*-\n\ |
235 @deffn Keyword break\n\ | |
236 Exit the innermost enclosing do, while or for loop.\n\ | |
237 @seealso{do, while, for, continue}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
238 @end deffn"), |
5040 | 239 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
240 pair_type ("case", |
5818 | 241 "-*- texinfo -*-\n\ |
242 @deffn Keyword case @{@var{value}@}\n\ | |
243 A case statement in an switch. Octave cases are exclusive and do not\n\ | |
5040 | 244 fall-through as do C-language cases. A switch statement must have at least\n\ |
5818 | 245 one case. See @code{switch} for an example.\n\ |
246 @seealso{switch}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
247 @end deffn"), |
1 | 248 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
249 pair_type ("catch", |
5818 | 250 "-*- texinfo -*-\n\ |
251 @deffn Keyword catch\n\ | |
252 Begin the cleanup part of a try-catch block.\n\ | |
253 @seealso{try}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
254 @end deffn"), |
1489 | 255 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
256 pair_type ("continue", |
5818 | 257 "-*- texinfo -*-\n\ |
258 @deffn Keyword continue\n\ | |
259 Jump to the end of the innermost enclosing do, while or for loop.\n\ | |
260 @seealso{do, while, for, break}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
261 @end deffn"), |
5040 | 262 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
263 pair_type ("do", |
5818 | 264 "-*- texinfo -*-\n\ |
265 @deffn Keyword do\n\ | |
266 Begin a do-until loop. This differs from a do-while loop in that the\n\ | |
267 body of the loop is executed at least once.\n\ | |
268 @seealso{while}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
269 @end deffn"), |
1 | 270 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
271 pair_type ("else", |
5818 | 272 "-*- texinfo -*-\n\ |
273 @deffn Keyword else\n\ | |
274 Alternate action for an if block. See @code{if} for an example.\n\ | |
275 @seealso{if}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
276 @end deffn"), |
1 | 277 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
278 pair_type ("elseif", |
5818 | 279 "-*- texinfo -*-\n\ |
280 @deffn Keyword elseif (@var{condition})\n\ | |
281 Alternate conditional test for an if block. See @code{if} for an example.\n\ | |
282 @seealso{if}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
283 @end deffn"), |
1 | 284 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
285 pair_type ("end", |
5818 | 286 "-*- texinfo -*-\n\ |
287 @deffn Keyword end\n\ | |
288 Mark the end of any @code{for}, @code{if}, @code{do}, @code{while}, or @code{function} block.\n\ | |
289 @seealso{for, if, do, while, function}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
290 @end deffn"), |
928 | 291 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
292 pair_type ("end_try_catch", |
5818 | 293 "-*- texinfo -*-\n\ |
294 @deffn Keyword end_try_catch\n\ | |
295 Mark the end of an @code{try-catch} block.\n\ | |
296 @seealso{try, catch}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
297 @end deffn"), |
1489 | 298 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
299 pair_type ("end_unwind_protect", |
5818 | 300 "-*- texinfo -*-\n\ |
301 @deffn Keyword end_unwind_protect\n\ | |
302 Mark the end of an unwind_protect block.\n\ | |
303 @seealso{unwind_protect}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
304 @end deffn"), |
1 | 305 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
306 pair_type ("endfor", |
5818 | 307 "-*- texinfo -*-\n\ |
308 @deffn Keyword endfor\n\ | |
309 Mark the end of a for loop. See @code{for} for an example.\n\ | |
310 @seealso{for}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
311 @end deffn"), |
1 | 312 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
313 pair_type ("endfunction", |
5818 | 314 "-*- texinfo -*-\n\ |
315 @deffn Keyword endfunction\n\ | |
316 Mark the end of a function.\n\ | |
317 @seealso{function}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
318 @end deffn"), |
1 | 319 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
320 pair_type ("endif", |
5818 | 321 "-*- texinfo -*-\n\ |
322 @deffn Keyword endif\n\ | |
323 Mark the end of an if block. See @code{if} for an example.\n\ | |
324 @seealso{if}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
325 @end deffn"), |
1 | 326 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
327 pair_type ("endswitch", |
5818 | 328 "-*- texinfo -*-\n\ |
329 @deffn Keyword endswitch\n\ | |
330 Mark the end of a switch block. See @code{switch} for an example.\n\ | |
331 @seealso{switch}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
332 @end deffn"), |
5122 | 333 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
334 pair_type ("endwhile", |
5818 | 335 "-*- texinfo -*-\n\ |
336 @deffn Keyword endwhile\n\ | |
337 Mark the end of a while loop. See @code{while} for an example.\n\ | |
338 @seealso{do, while}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
339 @end deffn"), |
1 | 340 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
341 pair_type ("for", |
5818 | 342 "-*- texinfo -*-\n\ |
343 @deffn Keyword for @var{i} = @var{range}\n\ | |
344 Begin a for loop.\n\ | |
345 @example\n\ | |
346 for i = 1:10\n\ | |
347 i\n\ | |
348 endfor\n\ | |
349 @end example\n\ | |
350 @seealso{do, while}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
351 @end deffn"), |
1 | 352 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
353 pair_type ("function", |
5818 | 354 "-*- texinfo -*-\n\ |
355 @deffn Keyword function @var{outputs} = function (@var{input}, ...)\n\ | |
356 @deffnx Keyword function {} function (@var{input}, ...)\n\ | |
357 @deffnx Keyword function @var{outputs} = function\n\ | |
358 Begin a function body with @var{outputs} as results and @var{inputs} as\n\ | |
359 parameters.\n\ | |
360 @seealso{return}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
361 @end deffn"), |
1 | 362 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
363 pair_type ("global", |
5818 | 364 "-*- texinfo -*-\n\ |
365 @deffn Keyword global\n\ | |
366 Declare variables to have global scope.\n\ | |
367 @example\n\ | |
368 global @var{x};\n\ | |
369 if isempty (@var{x})\n\ | |
370 x = 1;\n\ | |
371 endif\n\ | |
372 @end example\n\ | |
373 @seealso{persistent}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
374 @end deffn"), |
1 | 375 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
376 pair_type ("if", |
5393 | 377 "-*- texinfo -*-\n\ |
378 @deffn Keyword if (@var{cond}) @dots{} endif\n\ | |
379 @deffnx Keyword if (@var{cond}) @dots{} else @dots{} endif\n\ | |
380 @deffnx Keyword if (@var{cond}) @dots{} elseif (@var{cond}) @dots{} endif\n\ | |
381 @deffnx Keyword if (@var{cond}) @dots{} elseif (@var{cond}) @dots{} else @dots{} endif\n\ | |
382 Begin an if block.\n\ | |
5818 | 383 @example\n\ |
384 x = 1;\n\ | |
385 if (x == 1)\n\ | |
386 disp (\"one\");\n\ | |
387 elseif (x == 2)\n\ | |
388 disp (\"two\");\n\ | |
389 else\n\ | |
390 disp (\"not one or two\");\n\ | |
391 endif\n\ | |
392 @end example\n\ | |
5646 | 393 @seealso{switch}\n\ |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
394 @end deffn"), |
1 | 395 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
396 pair_type ("otherwise", |
5818 | 397 "-*- texinfo -*-\n\ |
398 @deffn Keyword otherwise\n\ | |
399 The default statement in a switch block (similar to else in an if block).\n\ | |
400 @seealso{switch}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
401 @end deffn"), |
5040 | 402 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
403 pair_type ("persistent", |
5818 | 404 "-*- texinfo -*-\n\ |
405 @deffn Keyword persistent @var{var}\n\ | |
406 Declare variables as persistent. A variable that has been declared\n\ | |
5623 | 407 persistent within a function will retain its contents in memory between\n\ |
408 subsequent calls to the same function. The difference between persistent\n\ | |
5818 | 409 variables and global variables is that persistent variables are local in \n\ |
410 scope to a particular function and are not visible elsewhere.\n\ | |
411 @seealso{global}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
412 @end deffn"), |
4686 | 413 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
414 pair_type ("replot", |
5818 | 415 "-*- texinfo -*-\n\ |
416 @deffn Keyword replot\n\ | |
417 Replot a graphic.\n\ | |
418 @seealso{plot}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
419 @end deffn"), |
5040 | 420 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
421 pair_type ("return", |
5818 | 422 "-*- texinfo -*-\n\ |
423 @deffn Keyword return\n\ | |
424 Return from a function.\n\ | |
425 @seealso{function}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
426 @end deffn"), |
928 | 427 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
428 pair_type ("static", |
5818 | 429 "-*- texinfo -*-\n\ |
430 @deffn Keyword static\n\ | |
431 This function has been deprecated in favor of persistent.\n\ | |
432 @seealso{persistent}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
433 @end deffn"), |
5040 | 434 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
435 pair_type ("switch", |
5818 | 436 "-*- texinfo -*-\n\ |
437 @deffn Keyword switch @var{statement}\n\ | |
438 Begin a switch block.\n\ | |
439 @example\n\ | |
440 yesno = \"yes\"\n\ | |
441 \n\ | |
442 switch yesno\n\ | |
5832 | 443 case @{\"Yes\" \"yes\" \"YES\" \"y\" \"Y\"@}\n\ |
5818 | 444 value = 1;\n\ |
5832 | 445 case @{\"No\" \"no\" \"NO\" \"n\" \"N\"@}\n\ |
5818 | 446 value = 0;\n\ |
447 otherwise\n\ | |
448 error (\"invalid value\");\n\ | |
449 endswitch\n\ | |
450 @end example\n\ | |
451 @seealso{if, case, otherwise}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
452 @end deffn"), |
5040 | 453 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
454 pair_type ("try", |
5818 | 455 "-*- texinfo -*-\n\ |
456 @deffn Keyword try\n\ | |
457 Begin a try-catch block.\n\ | |
6138 | 458 \n\ |
459 If an error occurs within a try block, then the catch code will be run and\n\ | |
460 execution will proceed after the catch block (though it is often\n\ | |
461 recommended to use the lasterr function to re-throw the error after cleanup\n\ | |
462 is completed).\n\ | |
463 @seealso{catch,unwind_protect}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
464 @end deffn"), |
1489 | 465 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
466 pair_type ("until", |
5818 | 467 "-*- texinfo -*-\n\ |
468 @deffn Keyword until\n\ | |
469 End a do-until loop.\n\ | |
470 @seealso{do}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
471 @end deffn"), |
5040 | 472 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
473 pair_type ("unwind_protect", |
5818 | 474 "-*- texinfo -*-\n\ |
475 @deffn Keyword unwind_protect\n\ | |
476 Begin an unwind_protect block.\n\ | |
6138 | 477 \n\ |
478 If an error occurs within the first part of an unwind_protect block\n\ | |
479 the commands within the unwind_protect_cleanup block are executed before\n\ | |
480 the error is thrown. If an error is not thrown, then the\n\ | |
481 unwind_protect_cleanup block is still executed (in other words, the\n\ | |
482 unwind_protect_cleanup will be run with or without an error in the\n\ | |
483 unwind_protect block).\n\ | |
484 @seealso{unwind_protect_cleanup,try}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
485 @end deffn"), |
928 | 486 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
487 pair_type ("unwind_protect_cleanup", |
5818 | 488 "-*- texinfo -*-\n\ |
489 @deffn Keyword unwind_protect_cleanup\n\ | |
490 Begin the cleanup section of an unwind_protect block.\n\ | |
491 @seealso{unwind_protect}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
492 @end deffn"), |
1 | 493 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
494 pair_type ("varargin", |
5818 | 495 "-*- texinfo -*-\n\ |
496 @deffn Keyword varargin\n\ | |
497 Pass an arbitrary number of arguments into a function.\n\ | |
498 @seealso{varargout, nargin, nargout}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
499 @end deffn"), |
5040 | 500 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
501 pair_type ("varargout", |
5818 | 502 "-*- texinfo -*-\n\ |
503 @deffn Keyword varargout\n\ | |
504 Pass an arbitrary number of arguments out of a function.\n\ | |
505 @seealso{varargin, nargin, nargout}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
506 @end deffn"), |
5040 | 507 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
508 pair_type ("while", |
5818 | 509 "-*- texinfo -*-\n\ |
510 @deffn Keyword while\n\ | |
511 Begin a while loop.\n\ | |
512 @seealso{do}\n\ | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
513 @end deffn"), |
1 | 514 }; |
515 | |
581 | 516 // Return a copy of the operator or keyword names. |
3016 | 517 static string_vector |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
518 names (const map_type& lst) |
1 | 519 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
520 string_vector retval (lst.size ()); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
521 int j = 0; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
522 for (map_iter iter = lst.begin (); iter != lst.end (); iter ++) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
523 retval [j++] = iter->first; |
1755 | 524 return retval; |
1 | 525 } |
526 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
527 const static map_type operators_map (operators, operators + size (operators)); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
528 const static map_type keywords_map (keywords, keywords + size (keywords)); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
529 const static string_vector keyword_names = names (keywords_map); |
1 | 530 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
531 // FIXME -- It's not likely that this does the right thing now. |
3016 | 532 |
533 string_vector | |
534 make_name_list (void) | |
535 { | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
536 const int key_len = keyword_names.length (); |
3016 | 537 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
538 const string_vector bif = symbol_table::built_in_function_names (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
539 const int bif_len = bif.length (); |
4009 | 540 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7438
diff
changeset
|
541 // FIXME -- is this really necessary here? |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
542 const string_vector glb = symbol_table::global_variable_names (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
543 const int glb_len = glb.length (); |
3016 | 544 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7438
diff
changeset
|
545 // FIXME -- is this really necessary here? |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
546 const string_vector top = symbol_table::top_level_variable_names (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
547 const int top_len = top.length (); |
3016 | 548 |
3355 | 549 string_vector lcl; |
7336 | 550 if (! symbol_table::at_top_level ()) |
551 lcl = symbol_table::variable_names (); | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
552 const int lcl_len = lcl.length (); |
3016 | 553 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
554 const string_vector ffl = load_path::fcn_names (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
555 const int ffl_len = ffl.length (); |
3016 | 556 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
557 const string_vector afl = autoloaded_functions (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
558 const int afl_len = afl.length (); |
5592 | 559 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
560 const int total_len = key_len + bif_len + glb_len + top_len + lcl_len |
7336 | 561 + ffl_len + afl_len; |
3016 | 562 |
563 string_vector list (total_len); | |
564 | |
565 // Put all the symbols in one big list. | |
566 | |
567 int j = 0; | |
568 int i = 0; | |
569 for (i = 0; i < key_len; i++) | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
570 list[j++] = keyword_names[i]; |
3016 | 571 |
7336 | 572 for (i = 0; i < bif_len; i++) |
573 list[j++] = bif[i]; | |
4009 | 574 |
3016 | 575 for (i = 0; i < glb_len; i++) |
576 list[j++] = glb[i]; | |
577 | |
578 for (i = 0; i < top_len; i++) | |
579 list[j++] = top[i]; | |
580 | |
581 for (i = 0; i < lcl_len; i++) | |
582 list[j++] = lcl[i]; | |
583 | |
584 for (i = 0; i < ffl_len; i++) | |
585 list[j++] = ffl[i]; | |
586 | |
5592 | 587 for (i = 0; i < afl_len; i++) |
588 list[j++] = afl[i]; | |
589 | |
3016 | 590 return list; |
591 } | |
592 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
593 static bool |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
594 looks_like_html (const std::string& msg) |
3014 | 595 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
596 const size_t p1 = msg.find ('\n'); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
597 std::string t = msg.substr (0, p1); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
598 const size_t p2 = t.find ("<html"); // FIXME: this comparison should be case-insensitive |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
599 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
600 return (p2 != std::string::npos); |
2470 | 601 } |
3014 | 602 |
603 static bool | |
3523 | 604 looks_like_texinfo (const std::string& msg, size_t& p1) |
3295 | 605 { |
606 p1 = msg.find ('\n'); | |
607 | |
3523 | 608 std::string t = msg.substr (0, p1); |
3295 | 609 |
8021 | 610 if (p1 == std::string::npos) |
3295 | 611 p1 = 0; |
612 | |
613 size_t p2 = t.find ("-*- texinfo -*-"); | |
614 | |
8021 | 615 return (p2 != std::string::npos); |
3295 | 616 } |
617 | |
3355 | 618 static bool |
6243 | 619 raw_help_from_symbol_table (const std::string& nm, std::string& h, |
620 std::string& w, bool& symbol_found) | |
3355 | 621 { |
622 bool retval = false; | |
623 | |
7336 | 624 octave_value val = symbol_table::find_function (nm); |
3355 | 625 |
7336 | 626 if (val.is_defined ()) |
3355 | 627 { |
7336 | 628 octave_function *fcn = val.function_value (); |
629 | |
630 if (fcn) | |
631 { | |
632 symbol_found = true; | |
5399 | 633 |
7336 | 634 h = fcn->doc_string (); |
635 | |
636 if (! h.empty ()) | |
637 { | |
638 retval = true; | |
6243 | 639 |
7336 | 640 w = fcn->fcn_file_name (); |
6243 | 641 |
7336 | 642 if (w.empty ()) |
643 w = fcn->is_user_function () | |
644 ? "command-line function" : "built-in function"; | |
645 } | |
6243 | 646 } |
647 } | |
3355 | 648 |
6243 | 649 return retval; |
650 } | |
651 | |
652 static bool | |
653 raw_help_from_file (const std::string& nm, std::string& h, | |
654 std::string& file, bool& symbol_found) | |
655 { | |
656 bool retval = false; | |
657 | |
658 h = get_help_from_file (nm, symbol_found, file); | |
659 | |
660 if (h.length () > 0) | |
661 retval = true; | |
662 | |
663 return retval; | |
664 } | |
665 | |
666 static bool | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
667 raw_help_from_map (const std::string& nm, std::string& h, |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
668 const map_type& map, bool& symbol_found) |
3355 | 669 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
670 map_iter idx = map.find (nm); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
671 symbol_found = (idx != map.end ()); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
672 h = (symbol_found) ? idx->second : ""; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
673 return symbol_found; |
3355 | 674 } |
675 | |
6243 | 676 std::string |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
677 raw_help (const std::string& nm, bool& symbol_found) |
6243 | 678 { |
679 std::string h; | |
680 std::string w; | |
681 std::string f; | |
682 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
683 (raw_help_from_symbol_table (nm, h, w, symbol_found) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
684 || raw_help_from_file (nm, h, f, symbol_found) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
685 || raw_help_from_map (nm, h, operators_map, symbol_found) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
686 || raw_help_from_map (nm, h, keywords_map, symbol_found)); |
6243 | 687 |
688 return h; | |
689 } | |
690 | |
1140 | 691 static void |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
692 do_get_help_text (const std::string name, std::string& text, |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
693 std::string& format) |
1140 | 694 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
695 bool symbol_found = false; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
696 text = raw_help (name, symbol_found); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
697 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
698 format = "Not found"; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
699 if (symbol_found) |
1140 | 700 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
701 size_t idx = -1; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
702 if (looks_like_texinfo (text, idx)) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
703 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
704 format = "texinfo"; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
705 text.erase (0, idx); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
706 } |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
707 else if (looks_like_html (text)) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
708 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
709 format = "html"; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
710 } |
5399 | 711 else |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
712 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
713 format = "plain text"; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
714 } |
1140 | 715 } |
716 } | |
717 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
718 DEFUN (get_help_text, args, , "-*- texinfo -*-\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
719 @deftypefn {Loadable Function} {[@var{text}, @var{format}] =} get_help_text (@var{name})\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
720 Returns the help text of a given function.\n\ |
3168 | 721 \n\ |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
722 This function returns the raw help text @var{text} and an indication of\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
723 its format for the function @var{name}. The format indication @var{format}\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
724 is a string that can be either @t{\"texinfo\"}, @t{\"html\"}, or\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
725 @t{\"plain text\"}.\n\ |
3332 | 726 \n\ |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
727 To convert the help text to other formats, use the @code{makeinfo} function.\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
728 \n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
729 @seealso{makeinfo}\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
730 @end deftypefn\n") |
529 | 731 { |
2086 | 732 octave_value_list retval; |
529 | 733 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
734 if (args.length () == 1) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
735 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
736 const std::string name = args (0).string_value (); |
1755 | 737 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
738 if (! error_state) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
739 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
740 std::string text; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
741 std::string format; |
529 | 742 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
743 do_get_help_text (name, text, format); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
744 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
745 retval(1) = format; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
746 retval(0) = text; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
747 } |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
748 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
749 error ("get_help_text: invalid input"); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
750 } |
529 | 751 else |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
752 print_usage (); |
529 | 753 |
754 return retval; | |
755 } | |
756 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
757 DEFUN (__operators__, , , "-*- texinfo -*-\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
758 @deftypefn {Function File} __operators__ ()\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
759 Return a cell array of strings containing the names of all operators.\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
760 \n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
761 This is an internal function and should not be used directly.\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
762 @end deftypefn\n") |
3355 | 763 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
764 return octave_value (Cell (names (operators_map))); |
3355 | 765 } |
766 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
767 DEFUN (__keywords__, , , "-*- texinfo -*-\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
768 @deftypefn {Function File} __keywords__ ()\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
769 Return a cell array of strings containing the names of all keywords.\n\ |
3361 | 770 \n\ |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
771 This is an internal function and should not be used directly.\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
772 @end deftypefn\n") |
581 | 773 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
774 return octave_value (Cell (names (keywords_map))); |
581 | 775 } |
776 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
777 DEFUN (__builtins__, , , "-*- texinfo -*-\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
778 @deftypefn {Function File} __builtins__ ()\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
779 Return a cell array of strings containing the names of all builtin functions.\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
780 \n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
781 This is an internal function and should not be used directly.\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
782 @end deftypefn\n") |
3355 | 783 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
784 const string_vector bif = symbol_table::built_in_function_names (); |
3355 | 785 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
786 return octave_value (Cell (bif)); |
3355 | 787 } |
788 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
789 static std::string |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
790 do_which (const std::string& name, std::string& type) |
3355 | 791 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
792 std::string file; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
793 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
794 type = std::string (); |
3355 | 795 |
7336 | 796 octave_value val = symbol_table::find_function (name); |
797 | |
798 if (val.is_defined ()) | |
3355 | 799 { |
7336 | 800 octave_function *fcn = val.function_value (); |
801 | |
802 if (fcn) | |
803 { | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
804 file = fcn->fcn_file_name (); |
3355 | 805 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
806 if (file.empty ()) |
7336 | 807 { |
808 if (fcn->is_user_function ()) | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
809 type = "command-line function"; |
7336 | 810 else |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
811 type = "built-in function"; |
7336 | 812 } |
813 else | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
814 type = val.is_user_script () |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
815 ? std::string ("script") : std::string ("function"); |
7336 | 816 } |
817 } | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
818 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
819 return file; |
3355 | 820 } |
821 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
822 std::string |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
823 do_which (const std::string& name) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
824 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
825 std::string retval; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
826 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
827 std::string type; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
828 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
829 retval = do_which (name, type); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
830 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
831 return retval; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
832 } |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
833 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
834 DEFUN (__which__, args, , |
3361 | 835 "-*- texinfo -*-\n\ |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
836 @deftypefn {Built-in Function} {} __which__ (@var{name}, @dots{})\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
837 Undocumented internal function.\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
838 @end deftypefn") |
581 | 839 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
840 octave_value retval; |
581 | 841 |
1968 | 842 string_vector argv = args.make_argv ("which"); |
1755 | 843 |
3355 | 844 if (! error_state) |
845 { | |
846 int argc = argv.length (); | |
581 | 847 |
3355 | 848 if (argc > 1) |
581 | 849 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
850 Octave_map m (dim_vector (1, argc-1)); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
851 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
852 Cell names (1, argc-1); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
853 Cell files (1, argc-1); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
854 Cell types (1, argc-1); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
855 |
3355 | 856 for (int i = 1; i < argc; i++) |
581 | 857 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
858 std::string name = argv[i]; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
859 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
860 std::string type; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
861 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
862 std::string file = do_which (name, type); |
3141 | 863 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
864 names(i-1) = name; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
865 files(i-1) = file; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
866 types(i-1) = type; |
581 | 867 } |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
868 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
869 m.assign ("name", names); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
870 m.assign ("file", files); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
871 m.assign ("type", types); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
872 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
873 retval = m; |
581 | 874 } |
3355 | 875 else |
5823 | 876 print_usage (); |
581 | 877 } |
878 | |
879 return retval; | |
880 } | |
881 | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
882 // FIXME -- Are we sure this function always does the right thing? |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
883 inline bool |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
884 file_is_in_dir (const std::string filename, const std::string dir) |
5447 | 885 { |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
886 if (filename.find (dir) == 0) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
887 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
888 const int dir_len = dir.size (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
889 const int filename_len = filename.size (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
890 const int max_allowed_seps = file_ops::is_dir_sep (dir [dir_len-1]) ? 0 : 1; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
891 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
892 int num_seps = 0; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
893 for (int i = dir_len; i < filename_len; i++) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
894 if (file_ops::is_dir_sep (filename [i])) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
895 num_seps ++; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
896 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
897 return (num_seps <= max_allowed_seps); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
898 } |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
899 else |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
900 return false; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
901 } |
5447 | 902 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
903 DEFUN (__list_functions__, args, , "-*- texinfo -*-\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
904 @deftypefn {Function File} {@var{retval} =} __list_functions__ ()\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
905 @deftypefnx{Function File} {@var{retval} =} __list_functions__ (@var{directory})\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
906 Return the functions available in a given directory.\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
907 \n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
908 The function returns a cell array of strings containing the names of all\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
909 functions available in said directory. If no directory is given, the current\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
910 path is searched.\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
911 \n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
912 This is an internal function and should not be used directly.\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
913 @seealso{path}\n\ |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
914 @end deftypefn\n") |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
915 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
916 octave_value_list retval; |
5447 | 917 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
918 // Get list of functions |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
919 const string_vector ffl = load_path::fcn_names (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
920 const int ffl_len = ffl.length (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
921 const string_vector afl = autoloaded_functions (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
922 const int afl_len = afl.length (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
923 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
924 if (args.length () == 0) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
925 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
926 Cell C (ffl_len + afl_len, 1); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
927 int j = 0; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
928 for (int i = 0; i < ffl_len; i++) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
929 C (j++, 0) = octave_value (ffl [i]); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
930 for (int i = 0; i < afl_len; i++) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
931 C (j++, 0) = octave_value (afl [i]); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
932 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
933 retval.append (octave_value (C)); |
5447 | 934 } |
935 else | |
936 { | |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
937 // Get input |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
938 std::string dir = args (0).string_value (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
939 if (error_state) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
940 error ("__list_functions__: input must be a string"); |
5447 | 941 else |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
942 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
943 dir = file_ops::canonicalize_file_name (dir); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
944 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
945 // FIXME -- This seems very inefficient. Is there a better way? |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
946 std::list<std::string> list; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
947 for (int i = 0; i < ffl_len; i++) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
948 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
949 const std::string filename = do_which (ffl [i]); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
950 if (file_is_in_dir (filename, dir)) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
951 list.push_back (ffl [i]); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
952 } |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
953 for (int i = 0; i < afl_len; i++) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
954 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
955 const std::string filename = do_which (afl [i]); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
956 if (file_is_in_dir (filename, dir)) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
957 list.push_back (afl [i]); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
958 } |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
959 |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
960 Cell C (list.size (), 1); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
961 int j = 0; |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
962 for (std::list<std::string>::const_iterator iter = list.begin (); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
963 iter != list.end (); iter++) |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
964 { |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
965 C (j++, 0) = octave_value (*iter); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
966 } |
5447 | 967 |
8575
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
968 retval.append (octave_value (C)); |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
969 } |
f134925a1cfa
m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
8503
diff
changeset
|
970 } |
5447 | 971 |
972 return retval; | |
973 } | |
974 | |
5794 | 975 DEFUN (info_file, args, nargout, |
976 "-*- texinfo -*-\n\ | |
977 @deftypefn {Built-in Function} {@var{val} =} info_file ()\n\ | |
978 @deftypefnx {Built-in Function} {@var{old_val} =} info_file (@var{new_val})\n\ | |
979 Query or set the internal variable that specifies the name of the\n\ | |
980 Octave info file. The default value is\n\ | |
981 @code{\"@var{octave-home}/info/octave.info\"}, in\n\ | |
982 which @var{octave-home} is the directory where all of Octave is installed.\n\ | |
983 @seealso{info_program, doc, help, makeinfo_program}\n\ | |
984 @end deftypefn") | |
2202 | 985 { |
5794 | 986 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_file); |
2202 | 987 } |
988 | |
5794 | 989 DEFUN (info_program, args, nargout, |
990 "-*- texinfo -*-\n\ | |
991 @deftypefn {Built-in Function} {@var{val} =} info_program ()\n\ | |
992 @deftypefnx {Built-in Function} {@var{old_val} =} info_program (@var{new_val})\n\ | |
993 Query or set the internal variable that specifies the name of the\n\ | |
7096 | 994 info program to run. The default value is\n\ |
3686 | 995 @code{\"@var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}/info\"}\n\ |
996 in which @var{octave-home} is the directory where all of Octave is\n\ | |
997 installed, @var{version} is the Octave version number, and @var{arch}\n\ | |
998 is the system type (for example, @code{i686-pc-linux-gnu}). The\n\ | |
999 default initial value may be overridden by the environment variable\n\ | |
1000 @code{OCTAVE_INFO_PROGRAM}, or the command line argument\n\ | |
5794 | 1001 @code{--info-program NAME}.\n\ |
1002 @seealso{info_file, doc, help, makeinfo_program}\n\ | |
1003 @end deftypefn") | |
1004 { | |
1005 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_program); | |
1006 } | |
3686 | 1007 |
5794 | 1008 DEFUN (makeinfo_program, args, nargout, |
1009 "-*- texinfo -*-\n\ | |
1010 @deftypefn {Built-in Function} {@var{val} =} makeinfo_program ()\n\ | |
1011 @deftypefnx {Built-in Function} {@var{old_val} =} makeinfo_program (@var{new_val})\n\ | |
1012 Query or set the internal variable that specifies the name of the\n\ | |
1013 makeinfo program that Octave runs to format help text containing\n\ | |
1014 Texinfo markup commands. The default initial value is @code{\"makeinfo\"}.\n\ | |
1015 @seealso{info_file, info_program, doc, help}\n\ | |
1016 @end deftypefn") | |
1017 { | |
1018 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (makeinfo_program); | |
1019 } | |
2202 | 1020 |
5794 | 1021 DEFUN (suppress_verbose_help_message, args, nargout, |
1022 "-*- texinfo -*-\n\ | |
1023 @deftypefn {Built-in Function} {@var{val} =} suppress_verbose_help_message ()\n\ | |
1024 @deftypefnx {Built-in Function} {@var{old_val} =} suppress_verbose_help_message (@var{new_val})\n\ | |
7001 | 1025 Query or set the internal variable that controls whether Octave\n\ |
5794 | 1026 will add additional help information to the end of the output from\n\ |
3332 | 1027 the @code{help} command and usage messages for built-in commands.\n\ |
5794 | 1028 @end deftypefn") |
1029 { | |
1030 return SET_INTERNAL_VARIABLE (suppress_verbose_help_message); | |
2189 | 1031 } |
1032 | |
1 | 1033 /* |
1034 ;;; Local Variables: *** | |
1035 ;;; mode: C++ *** | |
1036 ;;; End: *** | |
1037 */ |