1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
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 the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 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, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
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" |
2926
|
46 #include "oct-env.h" |
1755
|
47 #include "str-vec.h" |
|
48 |
2492
|
49 #include <defaults.h> |
1352
|
50 #include "defun.h" |
|
51 #include "dirfns.h" |
|
52 #include "error.h" |
2202
|
53 #include "gripes.h" |
1352
|
54 #include "help.h" |
2177
|
55 #include "input.h" |
5832
|
56 #include "load-path.h" |
1755
|
57 #include "oct-obj.h" |
2976
|
58 #include "ov-usr-fcn.h" |
1352
|
59 #include "pager.h" |
3018
|
60 #include "parse.h" |
1466
|
61 #include "pathsearch.h" |
3295
|
62 #include "procstream.h" |
529
|
63 #include "sighandlers.h" |
|
64 #include "symtab.h" |
2694
|
65 #include "syswait.h" |
1755
|
66 #include "toplev.h" |
242
|
67 #include "utils.h" |
1352
|
68 #include "variables.h" |
3301
|
69 #include "version.h" |
5447
|
70 #include "quit.h" |
529
|
71 |
2202
|
72 // Name of the info file specified on command line. |
|
73 // (--info-file file) |
3523
|
74 std::string Vinfo_file; |
2202
|
75 |
|
76 // Name of the info reader we'd like to use. |
|
77 // (--info-program program) |
5794
|
78 std::string Vinfo_program; |
2202
|
79 |
3686
|
80 // Name of the makeinfo program to run. |
5794
|
81 static std::string Vmakeinfo_program = "makeinfo"; |
3686
|
82 |
2189
|
83 // If TRUE, don't print additional help message in help and usage |
|
84 // functions. |
5794
|
85 static bool Vsuppress_verbose_help_message = false; |
2189
|
86 |
5775
|
87 // FIXME -- maybe this should use string instead of char*. |
3016
|
88 |
|
89 struct help_list |
|
90 { |
|
91 const char *name; |
|
92 const char *help; |
|
93 }; |
|
94 |
1
|
95 static help_list operators[] = |
|
96 { |
|
97 { "!", |
|
98 "Logical not operator. See also `~'.\n", }, |
|
99 |
|
100 { "!=", |
|
101 "Logical not equals operator. See also `~' and `<>'.\n", }, |
|
102 |
|
103 { "\"", |
|
104 "String delimiter.\n", }, |
|
105 |
|
106 { "#", |
928
|
107 "Begin comment character. See also `%'.", }, |
1
|
108 |
|
109 { "%", |
928
|
110 "Begin comment charcter. See also `#'.", }, |
1
|
111 |
|
112 { "&", |
928
|
113 "Logical and operator. See also `&&'.", }, |
1
|
114 |
|
115 { "&&", |
928
|
116 "Logical and operator. See also `&'.", }, |
1
|
117 |
|
118 { "'", |
|
119 "Matrix transpose operator. For complex matrices, computes the\n\ |
|
120 complex conjugate (Hermitian) transpose. See also `.''\n\ |
|
121 \n\ |
|
122 The single quote character may also be used to delimit strings, but\n\ |
|
123 it is better to use the double quote character, since that is never\n\ |
928
|
124 ambiguous", }, |
1
|
125 |
|
126 { "(", |
928
|
127 "Array index or function argument delimiter.", }, |
1
|
128 |
|
129 { ")", |
928
|
130 "Array index or function argument delimiter.", }, |
1
|
131 |
|
132 { "*", |
928
|
133 "Multiplication operator. See also `.*'", }, |
1
|
134 |
|
135 { "**", |
928
|
136 "Power operator. See also `^', `.**', and `.^'", }, |
1
|
137 |
|
138 { "+", |
928
|
139 "Addition operator.", }, |
1
|
140 |
|
141 { "++", |
5339
|
142 "Increment operator. As in C, may be applied as a prefix or postfix\n\ |
|
143 operator.", }, |
1
|
144 |
|
145 { ",", |
928
|
146 "Array index, function argument, or command separator.", }, |
1
|
147 |
|
148 { "-", |
928
|
149 "Subtraction or unary negation operator.", }, |
1
|
150 |
|
151 { "--", |
5339
|
152 "Decrement operator. As in C, may be applied as a prefix or postfix\n\ |
|
153 operator.", }, |
1
|
154 |
|
155 { ".'", |
|
156 "Matrix transpose operator. For complex matrices, computes the\n\ |
928
|
157 transpose, *not* the complex conjugate transpose. See also `''.", }, |
1
|
158 |
|
159 { ".*", |
928
|
160 "Element by element multiplication operator. See also `*'.", }, |
1
|
161 |
|
162 { ".**", |
928
|
163 "Element by element power operator. See also `**', `^', and `.^'.", }, |
1
|
164 |
|
165 { "./", |
928
|
166 "Element by element division operator. See also `/' and `\\'.", }, |
1
|
167 |
|
168 { ".^", |
928
|
169 "Element by element power operator. See also `**', `^', and `.^'.", }, |
1
|
170 |
|
171 { "/", |
928
|
172 "Right division. See also `\\' and `./'.", }, |
1
|
173 |
|
174 { ":", |
928
|
175 "Select entire rows or columns of matrices.", }, |
1
|
176 |
|
177 { ";", |
928
|
178 "Array row or command separator. See also `,'.", }, |
1
|
179 |
|
180 { "<", |
928
|
181 "Less than operator.", }, |
1
|
182 |
|
183 { "<=", |
928
|
184 "Less than or equals operator.", }, |
1
|
185 |
|
186 { "<>", |
928
|
187 "Logical not equals operator. See also `!=' and `~='.", }, |
1
|
188 |
|
189 { "=", |
928
|
190 "Assignment operator.", }, |
1
|
191 |
|
192 { "==", |
928
|
193 "Equality test operator.", }, |
1
|
194 |
|
195 { ">", |
928
|
196 "Greater than operator.", }, |
1
|
197 |
|
198 { ">=", |
928
|
199 "Greater than or equals operator.", }, |
1
|
200 |
|
201 { "[", |
928
|
202 "Return list delimiter. See also `]'.", }, |
1
|
203 |
|
204 { "\\", |
928
|
205 "Left division operator. See also `/' and `./'.", }, |
1
|
206 |
|
207 { "]", |
928
|
208 "Return list delimiter. See also `['.", }, |
1
|
209 |
|
210 { "^", |
928
|
211 "Power operator. See also `**', `.^', and `.**.'", }, |
1
|
212 |
|
213 { "|", |
928
|
214 "Logical or operator. See also `||'.", }, |
1
|
215 |
|
216 { "||", |
928
|
217 "Logical or operator. See also `|'.", }, |
1
|
218 |
|
219 { "~", |
928
|
220 "Logical not operator. See also `!' and `~'.", }, |
1
|
221 |
|
222 { "~=", |
928
|
223 "Logical not equals operator. See also `<>' and `!='.", }, |
1
|
224 |
529
|
225 { 0, 0, }, |
1
|
226 }; |
|
227 |
|
228 static help_list keywords[] = |
|
229 { |
|
230 { "break", |
5818
|
231 "-*- texinfo -*-\n\ |
|
232 @deffn Keyword break\n\ |
|
233 Exit the innermost enclosing do, while or for loop.\n\ |
|
234 @seealso{do, while, for, continue}\n\ |
|
235 @end deffn", }, |
5040
|
236 |
|
237 { "case", |
5818
|
238 "-*- texinfo -*-\n\ |
|
239 @deffn Keyword case @{@var{value}@}\n\ |
|
240 A case statement in an switch. Octave cases are exclusive and do not\n\ |
5040
|
241 fall-through as do C-language cases. A switch statement must have at least\n\ |
5818
|
242 one case. See @code{switch} for an example.\n\ |
|
243 @seealso{switch}\n\ |
|
244 @end deffn", }, |
1
|
245 |
1489
|
246 { "catch", |
5818
|
247 "-*- texinfo -*-\n\ |
|
248 @deffn Keyword catch\n\ |
|
249 Begin the cleanup part of a try-catch block.\n\ |
|
250 @seealso{try}\n\ |
|
251 @end deffn", }, |
1489
|
252 |
1
|
253 { "continue", |
5818
|
254 "-*- texinfo -*-\n\ |
|
255 @deffn Keyword continue\n\ |
|
256 Jump to the end of the innermost enclosing do, while or for loop.\n\ |
|
257 @seealso{do, while, for, break}\n\ |
|
258 @end deffn", }, |
5040
|
259 |
|
260 { "do", |
5818
|
261 "-*- texinfo -*-\n\ |
|
262 @deffn Keyword do\n\ |
|
263 Begin a do-until loop. This differs from a do-while loop in that the\n\ |
|
264 body of the loop is executed at least once.\n\ |
|
265 @seealso{while}\n\ |
|
266 @end deffn", }, |
1
|
267 |
|
268 { "else", |
5818
|
269 "-*- texinfo -*-\n\ |
|
270 @deffn Keyword else\n\ |
|
271 Alternate action for an if block. See @code{if} for an example.\n\ |
|
272 @seealso{if}\n\ |
|
273 @end deffn", }, |
1
|
274 |
|
275 { "elseif", |
5818
|
276 "-*- texinfo -*-\n\ |
|
277 @deffn Keyword elseif (@var{condition})\n\ |
|
278 Alternate conditional test for an if block. See @code{if} for an example.\n\ |
|
279 @seealso{if}\n\ |
|
280 @end deffn", }, |
1
|
281 |
|
282 { "end", |
5818
|
283 "-*- texinfo -*-\n\ |
|
284 @deffn Keyword end\n\ |
|
285 Mark the end of any @code{for}, @code{if}, @code{do}, @code{while}, or @code{function} block.\n\ |
|
286 @seealso{for, if, do, while, function}\n\ |
|
287 @end deffn", }, |
928
|
288 |
1489
|
289 { "end_try_catch", |
5818
|
290 "-*- texinfo -*-\n\ |
|
291 @deffn Keyword end_try_catch\n\ |
|
292 Mark the end of an @code{try-catch} block.\n\ |
|
293 @seealso{try, catch}\n\ |
|
294 @end deffn", }, |
1489
|
295 |
928
|
296 { "end_unwind_protect", |
5818
|
297 "-*- texinfo -*-\n\ |
|
298 @deffn Keyword end_unwind_protect\n\ |
|
299 Mark the end of an unwind_protect block.\n\ |
|
300 @seealso{unwind_protect}\n\ |
|
301 @end deffn", }, |
1
|
302 |
|
303 { "endfor", |
5818
|
304 "-*- texinfo -*-\n\ |
|
305 @deffn Keyword endfor\n\ |
|
306 Mark the end of a for loop. See @code{for} for an example.\n\ |
|
307 @seealso{for}\n\ |
|
308 @end deffn", }, |
1
|
309 |
|
310 { "endfunction", |
5818
|
311 "-*- texinfo -*-\n\ |
|
312 @deffn Keyword endfunction\n\ |
|
313 Mark the end of a function.\n\ |
|
314 @seealso{function}\n\ |
|
315 @end deffn", }, |
1
|
316 |
|
317 { "endif", |
5818
|
318 "-*- texinfo -*-\n\ |
|
319 @deffn Keyword endif\n\ |
|
320 Mark the end of an if block. See @code{if} for an example.\n\ |
|
321 @seealso{if}\n\ |
|
322 @end deffn", }, |
1
|
323 |
5122
|
324 { "endswitch", |
5818
|
325 "-*- texinfo -*-\n\ |
|
326 @deffn Keyword endswitch\n\ |
|
327 Mark the end of a switch block. See @code{switch} for an example.\n\ |
|
328 @seealso{switch}\n\ |
|
329 @end deffn", }, |
5122
|
330 |
1
|
331 { "endwhile", |
5818
|
332 "-*- texinfo -*-\n\ |
|
333 @deffn Keyword endwhile\n\ |
|
334 Mark the end of a while loop. See @code{while} for an example.\n\ |
|
335 @seealso{do, while}\n\ |
|
336 @end deffn", }, |
1
|
337 |
|
338 { "for", |
5818
|
339 "-*- texinfo -*-\n\ |
|
340 @deffn Keyword for @var{i} = @var{range}\n\ |
|
341 Begin a for loop.\n\ |
|
342 @example\n\ |
|
343 for i = 1:10\n\ |
|
344 i\n\ |
|
345 endfor\n\ |
|
346 @end example\n\ |
|
347 @seealso{do, while}\n\ |
|
348 @end deffn", }, |
1
|
349 |
|
350 { "function", |
5818
|
351 "-*- texinfo -*-\n\ |
|
352 @deffn Keyword function @var{outputs} = function (@var{input}, ...)\n\ |
|
353 @deffnx Keyword function {} function (@var{input}, ...)\n\ |
|
354 @deffnx Keyword function @var{outputs} = function\n\ |
|
355 Begin a function body with @var{outputs} as results and @var{inputs} as\n\ |
|
356 parameters.\n\ |
|
357 @seealso{return}\n\ |
|
358 @end deffn", }, |
1
|
359 |
|
360 { "global", |
5818
|
361 "-*- texinfo -*-\n\ |
|
362 @deffn Keyword global\n\ |
|
363 Declare variables to have global scope.\n\ |
|
364 @example\n\ |
|
365 global @var{x};\n\ |
|
366 if isempty (@var{x})\n\ |
|
367 x = 1;\n\ |
|
368 endif\n\ |
|
369 @end example\n\ |
|
370 @seealso{persistent}\n\ |
|
371 @end deffn", }, |
1
|
372 |
|
373 { "if", |
5393
|
374 "-*- texinfo -*-\n\ |
|
375 @deffn Keyword if (@var{cond}) @dots{} endif\n\ |
|
376 @deffnx Keyword if (@var{cond}) @dots{} else @dots{} endif\n\ |
|
377 @deffnx Keyword if (@var{cond}) @dots{} elseif (@var{cond}) @dots{} endif\n\ |
|
378 @deffnx Keyword if (@var{cond}) @dots{} elseif (@var{cond}) @dots{} else @dots{} endif\n\ |
|
379 Begin an if block.\n\ |
5818
|
380 @example\n\ |
|
381 x = 1;\n\ |
|
382 if (x == 1)\n\ |
|
383 disp (\"one\");\n\ |
|
384 elseif (x == 2)\n\ |
|
385 disp (\"two\");\n\ |
|
386 else\n\ |
|
387 disp (\"not one or two\");\n\ |
|
388 endif\n\ |
|
389 @end example\n\ |
5646
|
390 @seealso{switch}\n\ |
|
391 @end deffn", }, |
1
|
392 |
5040
|
393 { "otherwise", |
5818
|
394 "-*- texinfo -*-\n\ |
|
395 @deffn Keyword otherwise\n\ |
|
396 The default statement in a switch block (similar to else in an if block).\n\ |
|
397 @seealso{switch}\n\ |
|
398 @end deffn", }, |
5040
|
399 |
4686
|
400 { "persistent", |
5818
|
401 "-*- texinfo -*-\n\ |
|
402 @deffn Keyword persistent @var{var}\n\ |
|
403 Declare variables as persistent. A variable that has been declared\n\ |
5623
|
404 persistent within a function will retain its contents in memory between\n\ |
|
405 subsequent calls to the same function. The difference between persistent\n\ |
5818
|
406 variables and global variables is that persistent variables are local in \n\ |
|
407 scope to a particular function and are not visible elsewhere.\n\ |
|
408 @seealso{global}\n\ |
|
409 @end deffn", }, |
4686
|
410 |
5040
|
411 { "replot", |
5818
|
412 "-*- texinfo -*-\n\ |
|
413 @deffn Keyword replot\n\ |
|
414 Replot a graphic.\n\ |
|
415 @seealso{plot}\n\ |
|
416 @end deffn", }, |
5040
|
417 |
1
|
418 { "return", |
5818
|
419 "-*- texinfo -*-\n\ |
|
420 @deffn Keyword return\n\ |
|
421 Return from a function.\n\ |
|
422 @seealso{function}\n\ |
|
423 @end deffn", }, |
928
|
424 |
5040
|
425 { "static", |
5818
|
426 "-*- texinfo -*-\n\ |
|
427 @deffn Keyword static\n\ |
|
428 This function has been deprecated in favor of persistent.\n\ |
|
429 @seealso{persistent}\n\ |
|
430 @end deffn", }, |
5040
|
431 |
|
432 { "switch", |
5818
|
433 "-*- texinfo -*-\n\ |
|
434 @deffn Keyword switch @var{statement}\n\ |
|
435 Begin a switch block.\n\ |
|
436 @example\n\ |
|
437 yesno = \"yes\"\n\ |
|
438 \n\ |
|
439 switch yesno\n\ |
5832
|
440 case @{\"Yes\" \"yes\" \"YES\" \"y\" \"Y\"@}\n\ |
5818
|
441 value = 1;\n\ |
5832
|
442 case @{\"No\" \"no\" \"NO\" \"n\" \"N\"@}\n\ |
5818
|
443 value = 0;\n\ |
|
444 otherwise\n\ |
|
445 error (\"invalid value\");\n\ |
|
446 endswitch\n\ |
|
447 @end example\n\ |
|
448 @seealso{if, case, otherwise}\n\ |
|
449 @end deffn", }, |
5040
|
450 |
1489
|
451 { "try", |
5818
|
452 "-*- texinfo -*-\n\ |
|
453 @deffn Keyword try\n\ |
|
454 Begin a try-catch block.\n\ |
|
455 @seealso{catch}\n\ |
|
456 @end deffn", }, |
1489
|
457 |
5040
|
458 { "until", |
5818
|
459 "-*- texinfo -*-\n\ |
|
460 @deffn Keyword until\n\ |
|
461 End a do-until loop.\n\ |
|
462 @seealso{do}\n\ |
|
463 @end deffn", }, |
5040
|
464 |
928
|
465 { "unwind_protect", |
5818
|
466 "-*- texinfo -*-\n\ |
|
467 @deffn Keyword unwind_protect\n\ |
|
468 Begin an unwind_protect block.\n\ |
|
469 @seealso{unwind_protect_cleanup}\n\ |
|
470 @end deffn", }, |
928
|
471 |
|
472 { "unwind_protect_cleanup", |
5818
|
473 "-*- texinfo -*-\n\ |
|
474 @deffn Keyword unwind_protect_cleanup\n\ |
|
475 Begin the cleanup section of an unwind_protect block.\n\ |
|
476 @seealso{unwind_protect}\n\ |
|
477 @end deffn", }, |
1
|
478 |
5040
|
479 { "varargin", |
5818
|
480 "-*- texinfo -*-\n\ |
|
481 @deffn Keyword varargin\n\ |
|
482 Pass an arbitrary number of arguments into a function.\n\ |
|
483 @seealso{varargout, nargin, nargout}\n\ |
|
484 @end deffn", }, |
5040
|
485 |
|
486 { "varargout", |
5818
|
487 "-*- texinfo -*-\n\ |
|
488 @deffn Keyword varargout\n\ |
|
489 Pass an arbitrary number of arguments out of a function.\n\ |
|
490 @seealso{varargin, nargin, nargout}\n\ |
|
491 @end deffn", }, |
5040
|
492 |
1
|
493 { "while", |
5818
|
494 "-*- texinfo -*-\n\ |
|
495 @deffn Keyword while\n\ |
|
496 Begin a while loop.\n\ |
|
497 @seealso{do}\n\ |
|
498 @end deffn", }, |
1
|
499 |
529
|
500 { 0, 0, }, |
1
|
501 }; |
|
502 |
581
|
503 // Return a copy of the operator or keyword names. |
|
504 |
3016
|
505 static string_vector |
3355
|
506 names (help_list *lst) |
1
|
507 { |
1755
|
508 string_vector retval; |
|
509 |
3355
|
510 int count = 0; |
1
|
511 help_list *ptr = lst; |
529
|
512 while (ptr->name) |
1
|
513 { |
|
514 count++; |
|
515 ptr++; |
|
516 } |
|
517 |
1755
|
518 if (count > 0) |
|
519 { |
|
520 retval.resize (count); |
1
|
521 |
1755
|
522 ptr = lst; |
|
523 for (int i = 0; i < count; i++) |
|
524 { |
|
525 retval[i] = ptr->name; |
|
526 ptr++; |
|
527 } |
1
|
528 } |
|
529 |
1755
|
530 return retval; |
1
|
531 } |
|
532 |
3014
|
533 static help_list * |
1
|
534 operator_help (void) |
|
535 { |
|
536 return operators; |
|
537 } |
|
538 |
3016
|
539 static help_list * |
1
|
540 keyword_help (void) |
|
541 { |
|
542 return keywords; |
|
543 } |
|
544 |
5775
|
545 // It's not likely that this does the right thing now. FIXME |
3016
|
546 |
|
547 string_vector |
|
548 make_name_list (void) |
|
549 { |
3355
|
550 string_vector key = names (keyword_help ()); |
|
551 int key_len = key.length (); |
3016
|
552 |
4009
|
553 string_vector fbi = fbi_sym_tab->name_list (); |
|
554 int fbi_len = fbi.length (); |
|
555 |
3355
|
556 string_vector glb = global_sym_tab->name_list (); |
|
557 int glb_len = glb.length (); |
3016
|
558 |
3355
|
559 string_vector top = top_level_sym_tab->name_list (); |
|
560 int top_len = top.length (); |
3016
|
561 |
3355
|
562 string_vector lcl; |
3016
|
563 if (top_level_sym_tab != curr_sym_tab) |
3355
|
564 lcl = curr_sym_tab->name_list (); |
|
565 int lcl_len = lcl.length (); |
3016
|
566 |
5832
|
567 string_vector ffl = load_path::fcn_names (); |
3016
|
568 int ffl_len = ffl.length (); |
|
569 |
5592
|
570 string_vector afl = autoloaded_functions (); |
|
571 int afl_len = afl.length (); |
|
572 |
|
573 int total_len = key_len + fbi_len + glb_len + top_len + lcl_len + ffl_len + afl_len; |
3016
|
574 |
|
575 string_vector list (total_len); |
|
576 |
|
577 // Put all the symbols in one big list. |
|
578 |
|
579 int j = 0; |
|
580 int i = 0; |
|
581 for (i = 0; i < key_len; i++) |
|
582 list[j++] = key[i]; |
|
583 |
4009
|
584 for (i = 0; i < fbi_len; i++) |
|
585 list[j++] = fbi[i]; |
|
586 |
3016
|
587 for (i = 0; i < glb_len; i++) |
|
588 list[j++] = glb[i]; |
|
589 |
|
590 for (i = 0; i < top_len; i++) |
|
591 list[j++] = top[i]; |
|
592 |
|
593 for (i = 0; i < lcl_len; i++) |
|
594 list[j++] = lcl[i]; |
|
595 |
|
596 for (i = 0; i < ffl_len; i++) |
|
597 list[j++] = ffl[i]; |
|
598 |
5592
|
599 for (i = 0; i < afl_len; i++) |
|
600 list[j++] = afl[i]; |
|
601 |
3016
|
602 return list; |
|
603 } |
|
604 |
3014
|
605 void |
3523
|
606 additional_help_message (std::ostream& os) |
2470
|
607 { |
|
608 if (! Vsuppress_verbose_help_message) |
5641
|
609 os << "\ |
5794
|
610 Additional help for built-in functions and operators is\n\ |
|
611 available in the on-line version of the manual. Use the command\n\ |
5672
|
612 `doc <topic>' to search the manual index.\n\ |
3295
|
613 \n\ |
3160
|
614 Help and information about Octave is also available on the WWW\n\ |
5041
|
615 at http://www.octave.org and via the help@octave.org\n\ |
3917
|
616 mailing list.\n"; |
3160
|
617 } |
|
618 |
5775
|
619 // FIXME -- this needs a major overhaul to cope with new |
2976
|
620 // symbol table stuff. |
|
621 |
529
|
622 static void |
3523
|
623 display_names_from_help_list (std::ostream& os, help_list *list, |
542
|
624 const char *desc) |
529
|
625 { |
3355
|
626 string_vector symbols = names (list); |
3259
|
627 |
1808
|
628 if (! symbols.empty ()) |
|
629 { |
2095
|
630 os << "\n*** " << desc << ":\n\n"; |
3259
|
631 |
|
632 symbols.qsort (); |
|
633 |
2095
|
634 symbols.list_in_columns (os); |
1808
|
635 } |
529
|
636 } |
|
637 |
|
638 static void |
3523
|
639 display_symtab_names (std::ostream& os, const string_vector& names, |
|
640 const std::string& desc) |
542
|
641 { |
1808
|
642 if (! names.empty ()) |
|
643 { |
2095
|
644 os << "\n*** " << desc << ":\n\n"; |
|
645 names.list_in_columns (os); |
1808
|
646 } |
542
|
647 } |
|
648 |
|
649 #ifdef LIST_SYMBOLS |
|
650 #undef LIST_SYMBOLS |
|
651 #endif |
|
652 #define LIST_SYMBOLS(type, msg) \ |
|
653 do \ |
|
654 { \ |
3259
|
655 string_vector names \ |
4009
|
656 = fbi_sym_tab->name_list (string_vector (), true, type); \ |
3355
|
657 display_symtab_names (octave_stdout, names, msg); \ |
542
|
658 } \ |
|
659 while (0) |
529
|
660 |
3014
|
661 static void |
|
662 simple_help (void) |
|
663 { |
3160
|
664 octave_stdout << "Help is available for the topics listed below.\n"; |
|
665 |
|
666 additional_help_message (octave_stdout); |
|
667 |
3014
|
668 display_names_from_help_list (octave_stdout, operator_help (), |
|
669 "operators"); |
|
670 |
|
671 display_names_from_help_list (octave_stdout, keyword_help (), |
|
672 "reserved words"); |
|
673 |
5775
|
674 // FIXME -- is this distinction needed? |
1358
|
675 |
4208
|
676 LIST_SYMBOLS (symbol_record::COMMAND, "commands"); |
529
|
677 |
3010
|
678 LIST_SYMBOLS (symbol_record::MAPPER_FUNCTION, "mapper functions"); |
542
|
679 |
3010
|
680 LIST_SYMBOLS (symbol_record::BUILTIN_FUNCTION, "general functions"); |
542
|
681 |
1358
|
682 // Also need to list variables and currently compiled functions from |
|
683 // the symbol table, if there are any. |
529
|
684 |
1358
|
685 // Also need to search octave_path for script files. |
529
|
686 |
5832
|
687 load_path::display (octave_stdout); |
5592
|
688 |
|
689 string_vector autoloaded = autoloaded_functions (); |
|
690 |
|
691 if (! autoloaded.empty ()) |
|
692 { |
|
693 octave_stdout << "\n*** autoloaded functions:\n\n"; |
|
694 |
|
695 autoloaded.qsort (); |
|
696 |
|
697 autoloaded.list_in_columns (octave_stdout); |
|
698 } |
529
|
699 } |
|
700 |
|
701 static int |
3523
|
702 try_info (const std::string& nm) |
529
|
703 { |
5672
|
704 int retval = -1; |
1295
|
705 |
5672
|
706 warning ("please use `doc' instead of `help -i'"); |
529
|
707 |
5672
|
708 octave_value_list args; |
|
709 args(0) = nm; |
|
710 octave_value_list result = feval ("doc", args, 1); |
4051
|
711 |
5672
|
712 if (result.length () > 0) |
|
713 retval = result(0).int_value (); |
529
|
714 |
5672
|
715 return retval; |
529
|
716 } |
1140
|
717 |
|
718 static void |
1755
|
719 help_from_info (const string_vector& argv, int idx, int argc) |
1140
|
720 { |
1755
|
721 if (idx == argc) |
3523
|
722 try_info (std::string ()); |
1140
|
723 else |
|
724 { |
1755
|
725 for (int i = idx; i < argc; i++) |
1140
|
726 { |
1755
|
727 int status = try_info (argv[i]); |
1140
|
728 |
5672
|
729 if (status == 127) |
|
730 break; |
|
731 else if (status != 0) |
|
732 message ("help", "`%s' is not indexed in the manual", |
|
733 argv[i].c_str ()); |
1140
|
734 } |
|
735 } |
2470
|
736 } |
3014
|
737 |
|
738 static bool |
3523
|
739 looks_like_texinfo (const std::string& msg, size_t& p1) |
3295
|
740 { |
|
741 p1 = msg.find ('\n'); |
|
742 |
3523
|
743 std::string t = msg.substr (0, p1); |
3295
|
744 |
|
745 if (p1 == NPOS) |
|
746 p1 = 0; |
|
747 |
|
748 size_t p2 = t.find ("-*- texinfo -*-"); |
|
749 |
|
750 return (p2 != NPOS); |
|
751 } |
|
752 |
3330
|
753 void |
3523
|
754 display_help_text (std::ostream& os, const std::string& msg) |
3295
|
755 { |
|
756 // Look for "-*- texinfo -*-" in first line of help message. If it |
|
757 // is present, use makeinfo to format the rest of the message before |
|
758 // sending it to the output stream. Otherwise, just print the |
|
759 // message. |
|
760 |
|
761 size_t pos; |
|
762 |
|
763 if (looks_like_texinfo (msg, pos)) |
|
764 { |
5594
|
765 os.flush (); |
|
766 |
3523
|
767 std::string tmp_file_name = file_ops::tempnam ("", ""); |
3295
|
768 |
|
769 int cols = command_editor::terminal_cols (); |
|
770 |
|
771 if (cols > 16) |
|
772 cols--; |
|
773 |
|
774 if (cols > 64) |
|
775 cols -= 7; |
|
776 |
|
777 if (cols > 80) |
|
778 cols = 72; |
|
779 |
5765
|
780 std::ostringstream buf; |
4051
|
781 |
6099
|
782 // Use double quotes to quote the sed patterns for Windows. |
|
783 |
|
784 buf << "sed -e \"s/^[#%][#%]* *//\" -e \"s/^ *@/@/\" | " |
5794
|
785 << "\"" << Vmakeinfo_program << "\"" |
3303
|
786 << " -D \"VERSION " << OCTAVE_VERSION << "\"" |
|
787 << " -D \"OCTAVEHOME " << OCTAVE_PREFIX << "\"" |
3584
|
788 << " -D \"TARGETHOSTTYPE " << OCTAVE_CANONICAL_HOST_TYPE << "\"" |
3301
|
789 << " --fill-column " << cols |
|
790 << " --no-warn" |
|
791 << " --no-validate" |
|
792 << " --no-headers" |
|
793 << " --force" |
5765
|
794 << " --output \"" << tmp_file_name << "\""; |
3295
|
795 |
5765
|
796 oprocstream filter (buf.str ()); |
3295
|
797 |
3686
|
798 if (filter && filter.is_open ()) |
3295
|
799 { |
3405
|
800 filter << "@macro seealso {args}\n" |
5644
|
801 << "@sp 1\n" |
3408
|
802 << "@noindent\n" |
3405
|
803 << "See also: \\args\\.\n" |
|
804 << "@end macro\n"; |
|
805 |
3769
|
806 filter << msg.substr (pos+1) << std::endl; |
3295
|
807 |
3686
|
808 int status = filter.close (); |
3295
|
809 |
3523
|
810 std::ifstream tmp_file (tmp_file_name.c_str ()); |
3295
|
811 |
3686
|
812 if (WIFEXITED (status) && WEXITSTATUS (status) == 0) |
|
813 { |
|
814 int c; |
|
815 while ((c = tmp_file.get ()) != EOF) |
|
816 os << (char) c; |
3295
|
817 |
3686
|
818 tmp_file.close (); |
|
819 } |
|
820 else |
|
821 { |
|
822 warning ("help: Texinfo formatting filter exited abnormally"); |
|
823 warning ("help: raw Texinfo source of help text follows..."); |
5594
|
824 warning ("help:\n\n%s\n\n", msg.c_str ()); |
3686
|
825 } |
3295
|
826 |
|
827 file_ops::unlink (tmp_file_name); |
|
828 } |
|
829 else |
|
830 os << msg; |
|
831 } |
|
832 else |
|
833 os << msg; |
|
834 } |
|
835 |
5800
|
836 void |
|
837 display_usage_text (std::ostream& os, const std::string& msg) |
|
838 { |
|
839 std::string filtered_msg = msg; |
|
840 |
|
841 size_t pos; |
|
842 |
|
843 if (looks_like_texinfo (msg, pos)) |
|
844 { |
|
845 std::ostringstream buf; |
|
846 |
|
847 buf << "-*- texinfo -*-\n"; |
|
848 |
|
849 bool found_def = false; |
|
850 |
|
851 size_t msg_len = msg.length (); |
|
852 |
|
853 while (pos < msg_len) |
|
854 { |
|
855 size_t new_pos = msg.find_first_of ('\n', pos); |
|
856 |
|
857 if (new_pos == NPOS) |
|
858 new_pos = msg_len-1; |
|
859 |
|
860 std::string line = msg.substr (pos, new_pos-pos+1); |
|
861 |
|
862 if (line.substr (0, 4) == "@def" |
|
863 || line.substr (0, 8) == "@end def") |
|
864 { |
|
865 found_def = true; |
|
866 buf << line; |
|
867 } |
|
868 |
|
869 pos = new_pos + 1; |
|
870 } |
|
871 |
|
872 if (found_def) |
|
873 filtered_msg = buf.str (); |
|
874 } |
|
875 |
|
876 display_help_text (os, filtered_msg); |
|
877 } |
|
878 |
3295
|
879 static bool |
3523
|
880 help_from_list (std::ostream& os, const help_list *list, |
5399
|
881 const std::string& nm, int usage, bool& symbol_found) |
542
|
882 { |
5399
|
883 bool retval = false; |
|
884 |
2804
|
885 const char *name; |
3014
|
886 |
542
|
887 while ((name = list->name) != 0) |
|
888 { |
1755
|
889 if (strcmp (name, nm.c_str ()) == 0) |
542
|
890 { |
5399
|
891 symbol_found = true; |
|
892 |
|
893 std::string h = list->help; |
|
894 |
|
895 if (h.length () > 0) |
542
|
896 { |
5399
|
897 if (usage) |
|
898 os << "\nusage: "; |
|
899 else |
|
900 os << "\n*** " << nm << ":\n\n"; |
|
901 |
|
902 display_help_text (os, h); |
|
903 |
|
904 os << "\n"; |
|
905 |
|
906 retval = true; |
542
|
907 } |
5399
|
908 break; |
542
|
909 } |
|
910 list++; |
|
911 } |
3014
|
912 |
5399
|
913 return retval;; |
|
914 } |
|
915 |
|
916 std::string |
|
917 extract_help_from_dispatch (const std::string& nm) |
|
918 { |
|
919 std::string retval; |
|
920 |
|
921 symbol_record *builtin = fbi_sym_tab->lookup ("builtin:" + nm, 0); |
|
922 |
|
923 if (builtin) |
|
924 { |
|
925 // Check that builtin is up to date. |
|
926 |
|
927 // Don't try to fight octave's function name handling |
|
928 // mechanism. Instead, move dispatch record out of the way, |
|
929 // and restore the builtin to its original name. |
|
930 symbol_record *dispatch = fbi_sym_tab->lookup (nm, 0); |
|
931 |
|
932 if (dispatch) |
|
933 { |
|
934 dispatch->unprotect (); |
|
935 |
|
936 fbi_sym_tab->rename (nm, "dispatch:" + nm); |
|
937 fbi_sym_tab->rename ("builtin:" + nm, nm); |
|
938 |
|
939 // Check for updates to builtin function; ignore errors |
|
940 // that appear (they interfere with renaming), and remove |
5775
|
941 // the updated name from the current symbol table. FIXME -- |
|
942 // check that updating a function updates it in all |
|
943 // contexts. It may be that it is updated only in the |
5399
|
944 // current symbol table, and not the caller. I believe this |
|
945 // won't be a problem because the caller will go through the |
|
946 // same logic and end up with the newer version. |
|
947 |
|
948 octave_function *f = is_valid_function (nm); |
|
949 |
|
950 if (f) |
|
951 retval = builtin->help (); |
|
952 |
|
953 curr_sym_tab->clear_function (nm); |
|
954 |
|
955 // Move the builtin function out of the way and restore the |
5775
|
956 // dispatch fuction. FIXME what if builtin wants to |
5399
|
957 // protect itself? |
|
958 |
|
959 fbi_sym_tab->rename (nm, "builtin:" + nm); |
|
960 fbi_sym_tab->rename ("dispatch:" + nm, nm); |
|
961 |
|
962 dispatch->protect (); |
|
963 } |
|
964 else |
|
965 error ("failed to find dispatch record for `builtin:%s'", nm.c_str ()); |
|
966 } |
|
967 |
|
968 return retval; |
542
|
969 } |
|
970 |
3355
|
971 static bool |
5399
|
972 help_from_symbol_table (std::ostream& os, const std::string& nm, |
|
973 bool& symbol_found) |
3355
|
974 { |
|
975 bool retval = false; |
|
976 |
|
977 symbol_record *sym_rec = lookup_by_name (nm, 0); |
|
978 |
|
979 if (sym_rec && sym_rec->is_defined ()) |
|
980 { |
5399
|
981 symbol_found = true; |
|
982 |
3523
|
983 std::string h = sym_rec->help (); |
3355
|
984 |
|
985 if (h.length () > 0) |
|
986 { |
5399
|
987 h = extract_help_from_dispatch (nm) + h; |
3355
|
988 display_help_text (os, h); |
5641
|
989 if (! Vsuppress_verbose_help_message) |
|
990 { |
|
991 sym_rec->which (os); |
|
992 os << "\n"; |
|
993 } |
3355
|
994 os << "\n"; |
|
995 retval = true; |
|
996 } |
|
997 } |
|
998 |
|
999 return retval; |
|
1000 } |
|
1001 |
|
1002 static bool |
5399
|
1003 help_from_file (std::ostream& os, const std::string& nm, bool& symbol_found) |
3355
|
1004 { |
|
1005 bool retval = false; |
|
1006 |
5931
|
1007 std::string file; |
|
1008 |
|
1009 std::string h = get_help_from_file (nm, symbol_found, file); |
3355
|
1010 |
5484
|
1011 if (h.length () > 0) |
|
1012 { |
5931
|
1013 os << nm << " is the file " << file << "\n\n"; |
5484
|
1014 display_help_text (os, h); |
|
1015 os << "\n"; |
|
1016 retval = true; |
3355
|
1017 } |
|
1018 |
|
1019 return retval; |
|
1020 } |
|
1021 |
1140
|
1022 static void |
1755
|
1023 builtin_help (int argc, const string_vector& argv) |
1140
|
1024 { |
|
1025 help_list *op_help_list = operator_help (); |
|
1026 help_list *kw_help_list = keyword_help (); |
|
1027 |
1755
|
1028 for (int i = 1; i < argc; i++) |
1140
|
1029 { |
5399
|
1030 bool symbol_found = false; |
|
1031 |
|
1032 if (help_from_list (octave_stdout, op_help_list, argv[i], 0, |
|
1033 symbol_found)) |
1140
|
1034 continue; |
|
1035 |
5399
|
1036 if (help_from_list (octave_stdout, kw_help_list, argv[i], 0, |
|
1037 symbol_found)) |
1140
|
1038 continue; |
|
1039 |
5399
|
1040 if (help_from_symbol_table (octave_stdout, argv[i], symbol_found)) |
|
1041 continue; |
|
1042 |
|
1043 if (help_from_file (octave_stdout, argv[i], symbol_found)) |
3355
|
1044 continue; |
1755
|
1045 |
5399
|
1046 if (symbol_found) |
|
1047 octave_stdout << "\nhelp: `" << argv[i] |
|
1048 << "' is not documented\n"; |
|
1049 else |
|
1050 octave_stdout << "\nhelp: `" << argv[i] |
|
1051 << "' not found\n"; |
1140
|
1052 } |
|
1053 |
2095
|
1054 additional_help_message (octave_stdout); |
1140
|
1055 } |
|
1056 |
4208
|
1057 DEFCMD (help, args, , |
3332
|
1058 "-*- texinfo -*-\n\ |
|
1059 @deffn {Command} help\n\ |
|
1060 Octave's @code{help} command can be used to print brief usage-style\n\ |
|
1061 messages, or to display information directly from an on-line version of\n\ |
|
1062 the printed manual, using the GNU Info browser. If invoked without any\n\ |
5794
|
1063 arguments, @code{help} prints a list of all the available operators\n\ |
|
1064 and functions. If the first argument is @code{-i}, the @code{help}\n\ |
|
1065 command searches the index of the on-line version of this manual for\n\ |
|
1066 the given topics.\n\ |
3168
|
1067 \n\ |
3332
|
1068 For example, the command @kbd{help help} prints a short message\n\ |
|
1069 describing the @code{help} command, and @kbd{help -i help} starts the\n\ |
|
1070 GNU Info browser at this node in the on-line version of the manual.\n\ |
|
1071 \n\ |
|
1072 Once the GNU Info browser is running, help for using it is available\n\ |
|
1073 using the command @kbd{C-h}.\n\ |
5672
|
1074 @seealso{doc, which, lookfor}\n\ |
3333
|
1075 @end deffn") |
529
|
1076 { |
2086
|
1077 octave_value_list retval; |
529
|
1078 |
1755
|
1079 int argc = args.length () + 1; |
|
1080 |
1968
|
1081 string_vector argv = args.make_argv ("help"); |
1755
|
1082 |
|
1083 if (error_state) |
|
1084 return retval; |
529
|
1085 |
|
1086 if (argc == 1) |
3014
|
1087 simple_help (); |
529
|
1088 else |
|
1089 { |
1755
|
1090 if (argv[1] == "-i") |
3014
|
1091 help_from_info (argv, 2, argc); |
529
|
1092 else |
3014
|
1093 builtin_help (argc, argv); |
529
|
1094 } |
|
1095 |
|
1096 return retval; |
|
1097 } |
|
1098 |
3355
|
1099 static void |
3523
|
1100 do_type (std::ostream& os, const std::string& name, bool pr_type_info, |
3355
|
1101 bool quiet, bool pr_orig_txt) |
|
1102 { |
|
1103 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1104 |
|
1105 if (sym_rec && sym_rec->is_defined ()) |
3356
|
1106 sym_rec->type (os, pr_type_info, quiet, pr_orig_txt); |
3355
|
1107 else |
|
1108 { |
3523
|
1109 std::string ff = fcn_file_in_path (name); |
3355
|
1110 |
|
1111 if (! ff.empty ()) |
|
1112 { |
3538
|
1113 std::ifstream fs (ff.c_str (), std::ios::in); |
3355
|
1114 |
|
1115 if (fs) |
|
1116 { |
|
1117 if (pr_type_info && ! quiet) |
|
1118 os << name << " is the script file: " << ff << "\n\n"; |
|
1119 |
|
1120 char ch; |
|
1121 |
|
1122 while (fs.get (ch)) |
|
1123 os << ch; |
|
1124 } |
|
1125 else |
|
1126 os << "unable to open `" << ff << "' for reading!\n"; |
|
1127 } |
|
1128 else |
|
1129 error ("type: `%s' undefined", name.c_str ()); |
|
1130 } |
|
1131 } |
|
1132 |
4208
|
1133 DEFCMD (type, args, nargout, |
3361
|
1134 "-*- texinfo -*-\n\ |
|
1135 \n\ |
|
1136 @deffn {Command} type options name @dots{}\n\ |
|
1137 Display the definition of each @var{name} that refers to a function.\n\ |
|
1138 \n\ |
|
1139 Normally also displays if each @var{name} is user-defined or builtin;\n\ |
|
1140 the @code{-q} option suppresses this behaviour.\n\ |
581
|
1141 \n\ |
3361
|
1142 Currently, Octave can only display functions that can be compiled\n\ |
|
1143 cleanly, because it uses its internal representation of the function to\n\ |
|
1144 recreate the program text.\n\ |
|
1145 \n\ |
|
1146 Comments are not displayed because Octave's parser currently discards\n\ |
|
1147 them as it converts the text of a function file to its internal\n\ |
|
1148 representation. This problem may be fixed in a future release.\n\ |
|
1149 @end deffn") |
581
|
1150 { |
3584
|
1151 octave_value retval; |
1588
|
1152 |
1755
|
1153 int argc = args.length () + 1; |
|
1154 |
1968
|
1155 string_vector argv = args.make_argv ("type"); |
1755
|
1156 |
3355
|
1157 if (! error_state) |
581
|
1158 { |
3355
|
1159 if (argc > 1) |
|
1160 { |
5775
|
1161 // FIXME -- we should really use getopt () |
2532
|
1162 |
3355
|
1163 bool quiet = false; |
|
1164 bool pr_orig_txt = true; |
2532
|
1165 |
3355
|
1166 int idx; |
581
|
1167 |
3355
|
1168 for (idx = 1; idx < argc; idx++) |
1281
|
1169 { |
3355
|
1170 if (argv[idx] == "-q" || argv[idx] == "-quiet") |
|
1171 quiet = true; |
|
1172 else if (argv[idx] == "-t" || argv[idx] == "-transformed") |
|
1173 pr_orig_txt = false; |
|
1174 else |
|
1175 break; |
1281
|
1176 } |
|
1177 |
3355
|
1178 if (idx < argc) |
|
1179 { |
5765
|
1180 std::ostringstream output_buf; |
581
|
1181 |
3355
|
1182 for (int i = idx; i < argc; i++) |
581
|
1183 { |
3523
|
1184 std::string id = argv[i]; |
2534
|
1185 |
3355
|
1186 if (nargout == 0) |
|
1187 do_type (octave_stdout, id, true, quiet, pr_orig_txt); |
|
1188 else |
|
1189 do_type (output_buf, id, false, quiet, pr_orig_txt); |
581
|
1190 |
3355
|
1191 if (error_state) |
|
1192 goto abort; |
581
|
1193 } |
|
1194 |
3584
|
1195 if (nargout != 0) |
5765
|
1196 retval = output_buf.str (); |
581
|
1197 } |
|
1198 else |
5823
|
1199 print_usage (); |
3355
|
1200 } |
|
1201 else |
5823
|
1202 print_usage (); |
3355
|
1203 } |
3141
|
1204 |
3355
|
1205 abort: |
581
|
1206 |
|
1207 return retval; |
|
1208 } |
|
1209 |
3536
|
1210 static std::string |
3523
|
1211 do_which (const std::string& name) |
3355
|
1212 { |
3523
|
1213 std::string retval; |
3355
|
1214 |
|
1215 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1216 |
|
1217 if (sym_rec && sym_rec->is_defined ()) |
|
1218 retval = sym_rec->which (); |
|
1219 else |
|
1220 { |
3523
|
1221 std::string path = fcn_file_in_path (name); |
3355
|
1222 |
|
1223 if (! path.empty ()) |
|
1224 retval = path; |
|
1225 else |
|
1226 retval = "undefined"; |
|
1227 } |
|
1228 |
|
1229 return retval; |
|
1230 } |
|
1231 |
|
1232 static void |
3523
|
1233 do_which (std::ostream& os, const std::string& name) |
3355
|
1234 { |
|
1235 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1236 |
|
1237 if (sym_rec && sym_rec->is_defined ()) |
|
1238 sym_rec->which (os); |
|
1239 else |
|
1240 { |
3523
|
1241 std::string path = fcn_file_in_path (name); |
3355
|
1242 |
|
1243 if (! path.empty ()) |
|
1244 os << "which: `" << name << "' is the script file\n" |
|
1245 << path << "\n"; |
|
1246 else |
|
1247 os << "which: `" << name << "' is undefined\n"; |
|
1248 } |
|
1249 } |
|
1250 |
4208
|
1251 DEFCMD (which, args, nargout, |
3361
|
1252 "-*- texinfo -*-\n\ |
|
1253 @deffn {Command} which name @dots{}\n\ |
|
1254 Display the type of each @var{name}. If @var{name} is defined from a\n\ |
|
1255 function file, the full name of the file is also displayed.\n\ |
5667
|
1256 @seealso{help, lookfor}\n\ |
3361
|
1257 @end deffn") |
581
|
1258 { |
2086
|
1259 octave_value_list retval; |
581
|
1260 |
1968
|
1261 string_vector argv = args.make_argv ("which"); |
1755
|
1262 |
3355
|
1263 if (! error_state) |
|
1264 { |
|
1265 int argc = argv.length (); |
581
|
1266 |
|
1267 if (nargout > 0) |
|
1268 retval.resize (argc-1, Matrix ()); |
|
1269 |
3355
|
1270 if (argc > 1) |
581
|
1271 { |
3355
|
1272 for (int i = 1; i < argc; i++) |
581
|
1273 { |
3523
|
1274 std::string id = argv[i]; |
3141
|
1275 |
3355
|
1276 if (nargout == 0) |
|
1277 do_which (octave_stdout, id); |
581
|
1278 else |
3355
|
1279 retval(i-1) = do_which (id); |
581
|
1280 } |
|
1281 } |
3355
|
1282 else |
5823
|
1283 print_usage (); |
581
|
1284 } |
|
1285 |
|
1286 return retval; |
|
1287 } |
|
1288 |
5775
|
1289 // FIXME |
5447
|
1290 // This function attempts to find the first sentence of a help string, though |
|
1291 // given that the user can create the help in an arbitrary format, your |
|
1292 // success might vary.. it works much better with help string formated in |
|
1293 // texinfo. Using regex might make this function much simpler. |
|
1294 |
|
1295 std::string |
|
1296 first_help_sentence (const std::string& h, bool short_sentence = true) |
|
1297 { |
5738
|
1298 std::string retval; |
|
1299 |
5447
|
1300 size_t pos = 0; |
|
1301 |
|
1302 if (looks_like_texinfo (h, pos)) |
5592
|
1303 { |
|
1304 // Get the parsed help string. |
5447
|
1305 pos = 0; |
5765
|
1306 std::ostringstream os; |
5447
|
1307 display_help_text (os, h); |
|
1308 std::string h2 = os.str (); |
|
1309 |
|
1310 while (1) |
|
1311 { |
|
1312 // Skip leading whitespace and get new line |
|
1313 pos = h2.find_first_not_of ("\n\t ", pos); |
|
1314 |
|
1315 if (pos == NPOS) |
|
1316 break; |
|
1317 |
|
1318 size_t new_pos = h2.find_first_of ('\n', pos); |
|
1319 std::string line = h2.substr (pos, new_pos-pos); |
|
1320 |
|
1321 // Skip lines starting in "-" |
|
1322 if (line.find_first_of ('-') == 0) |
|
1323 { |
|
1324 pos = new_pos + 1; |
|
1325 continue; |
|
1326 } |
|
1327 |
|
1328 break; |
|
1329 } |
|
1330 |
|
1331 if (pos == NPOS) |
5738
|
1332 return retval; |
5447
|
1333 |
|
1334 // At start of real text. Get first line with the sentence |
|
1335 size_t new_pos = h2.find_first_of ('\n', pos); |
|
1336 std::string line = h2.substr (pos, new_pos-pos); |
|
1337 size_t dot_pos; |
|
1338 |
|
1339 while ((dot_pos = line.find_first_of ('.')) == NPOS) |
|
1340 { |
|
1341 // Trim trailing blanks on line |
|
1342 line.substr (0, line.find_last_not_of ("\n\t ") + 1); |
|
1343 |
|
1344 // Append next line |
|
1345 size_t tmp_pos = h2.find_first_not_of ("\n\t ", new_pos + 1); |
|
1346 if (tmp_pos == NPOS || h2.substr (tmp_pos, 1) == "\n") |
|
1347 break; |
|
1348 |
|
1349 new_pos = h2.find_first_of ('\n', tmp_pos); |
|
1350 std::string next = h2.substr (tmp_pos, new_pos-tmp_pos); |
|
1351 |
|
1352 if (short_sentence) |
|
1353 { |
|
1354 if ((tmp_pos = next.find_first_of ('.')) != NPOS) |
|
1355 { |
|
1356 line = line + " " + next; |
|
1357 dot_pos = line.find_first_of ('.'); |
|
1358 } |
|
1359 break; |
|
1360 } |
|
1361 else |
|
1362 line = line + " " + next; |
|
1363 } |
|
1364 |
|
1365 if (dot_pos == NPOS) |
5738
|
1366 retval = line; |
5447
|
1367 else |
5738
|
1368 retval = line.substr (0, dot_pos + 1); |
5447
|
1369 } |
|
1370 else |
|
1371 { |
|
1372 std::string _upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
1373 std::string _lower = "abcdefghijklmnopqrstuvwxyz"; |
|
1374 std::string _alpha = _upper + _lower + "_"; |
|
1375 std::string _alphanum = _alpha + "1234567890"; |
|
1376 pos = 0; |
|
1377 |
|
1378 while (1) |
|
1379 { |
|
1380 // Skip leading whitespace and get new line |
|
1381 pos = h.find_first_not_of ("\n\t ", pos); |
|
1382 |
|
1383 if (pos == NPOS) |
|
1384 break; |
|
1385 |
|
1386 size_t new_pos = h.find_first_of ('\n', pos); |
|
1387 std::string line = h.substr (pos, new_pos-pos); |
|
1388 |
|
1389 // Make a lower case copy to simplify some tests |
|
1390 std::string lower = line; |
5768
|
1391 std::transform (lower.begin (), lower.end (), lower.begin (), tolower); |
5447
|
1392 |
|
1393 // Skip lines starting in "-" or "Usage" |
|
1394 if (lower.find_first_of ('-') == 0 |
|
1395 || lower.substr (0, 5) == "usage") |
|
1396 { |
5592
|
1397 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1398 continue; |
|
1399 } |
|
1400 |
|
1401 size_t line_pos = 0; |
|
1402 size_t tmp_pos = 0; |
|
1403 |
|
1404 // chop " blah : " |
|
1405 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1406 (_alphanum, line_pos)); |
|
1407 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == ":") |
|
1408 line_pos = line.find_first_not_of ("\t ", tmp_pos + 1); |
|
1409 |
|
1410 if (line_pos == NPOS) |
|
1411 { |
5592
|
1412 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1413 continue; |
|
1414 } |
|
1415 |
|
1416 // chop " function " |
|
1417 if (lower.substr (line_pos, 8) == "function") |
|
1418 line_pos = line.find_first_not_of ("\t ", line_pos + 8); |
|
1419 |
|
1420 if (line_pos == NPOS) |
|
1421 { |
5592
|
1422 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1423 continue; |
|
1424 } |
|
1425 |
|
1426 // chop " [a,b] = " |
|
1427 if (line.substr (line_pos, 1) == "[") |
|
1428 { |
|
1429 tmp_pos = line.find_first_not_of |
|
1430 ("\t ", line.find_first_of ("]", line_pos) + 1); |
|
1431 |
|
1432 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "=") |
|
1433 line_pos = line.find_first_not_of ("\t ",tmp_pos + 1); |
|
1434 } |
|
1435 |
|
1436 if (line_pos == NPOS) |
|
1437 { |
5592
|
1438 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1439 continue; |
|
1440 } |
|
1441 |
|
1442 // chop " a = " |
|
1443 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1444 { |
|
1445 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1446 (_alphanum, line_pos)); |
|
1447 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "=") |
|
1448 line_pos = line.find_first_not_of ("\t ", tmp_pos + 1); |
|
1449 } |
|
1450 |
|
1451 if (line_pos == NPOS) |
|
1452 { |
|
1453 pos = new_pos + 1; |
|
1454 continue; |
|
1455 } |
|
1456 |
|
1457 // chop " f(x) " |
|
1458 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1459 { |
|
1460 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1461 (_alphanum, line_pos)); |
|
1462 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "(") |
|
1463 line_pos = line.find_first_not_of ("\t ", line.find_first_of |
|
1464 (")", tmp_pos) + 1); |
|
1465 } |
|
1466 |
|
1467 if (line_pos == NPOS) |
|
1468 { |
5592
|
1469 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1470 continue; |
|
1471 } |
|
1472 |
|
1473 // chop " ; " |
|
1474 if (line.substr (line_pos, 1) == ":" |
|
1475 || line.substr (line_pos, 1) == ";") |
|
1476 line_pos = line.find_first_not_of ("\t ", line_pos + 1); |
|
1477 |
|
1478 if (line_pos == NPOS) |
|
1479 { |
5592
|
1480 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1481 continue; |
|
1482 } |
|
1483 |
|
1484 // chop " BLAH " |
|
1485 if (line.length () > line_pos + 2 |
|
1486 && line.find_first_of (_upper, line_pos) == line_pos |
|
1487 && line.find_first_of (_upper, line_pos+1) == line_pos + 1) |
|
1488 line_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1489 (_upper + "0123456789_", line_pos)); |
|
1490 |
|
1491 if (line_pos == NPOS) |
|
1492 { |
5592
|
1493 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1494 continue; |
|
1495 } |
|
1496 |
|
1497 // chop " blah --- " |
|
1498 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1499 (_alphanum, line_pos)); |
|
1500 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "-") |
|
1501 { |
|
1502 tmp_pos = line.find_first_not_of ("-", tmp_pos); |
|
1503 if (line.substr (tmp_pos, 1) == " " |
|
1504 || line.substr (tmp_pos, 1) == "\t") |
|
1505 line_pos = line.find_first_not_of ("\t ", tmp_pos); |
|
1506 } |
|
1507 |
|
1508 if (line_pos == NPOS) |
|
1509 { |
5592
|
1510 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1511 continue; |
|
1512 } |
|
1513 |
|
1514 // chop " blah <TAB> " |
|
1515 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1516 { |
|
1517 tmp_pos = line.find_first_not_of (" ", line.find_first_not_of |
|
1518 (_alphanum, line_pos)); |
|
1519 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "\t") |
|
1520 line_pos = line.find_first_not_of ("\t ", line.find_first_of |
|
1521 (")", tmp_pos) + 1); |
|
1522 } |
|
1523 |
|
1524 if (line_pos == NPOS) |
|
1525 { |
5592
|
1526 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1527 continue; |
|
1528 } |
|
1529 |
|
1530 // chop " blah " |
|
1531 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1532 { |
|
1533 tmp_pos = line.find_first_not_of (_alphanum, line_pos); |
|
1534 |
|
1535 if (tmp_pos != NPOS |
|
1536 && (line.substr (tmp_pos, 2) == "\t\t" |
|
1537 || line.substr (tmp_pos, 2) == "\t " |
|
1538 || line.substr (tmp_pos, 2) == " \t" |
|
1539 || line.substr (tmp_pos, 2) == " ")) |
|
1540 line_pos = line.find_first_not_of ("\t ", tmp_pos); |
|
1541 } |
|
1542 |
|
1543 if (line_pos == NPOS) |
|
1544 { |
5592
|
1545 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1546 continue; |
|
1547 } |
|
1548 |
|
1549 // skip blah \n or \n blah |
|
1550 // skip blank line |
|
1551 // skip "# !/usr/bin/octave" |
|
1552 if ((line.substr (line_pos , 2) == "or" |
|
1553 && line.find_first_not_of ("\n\t ", line_pos + 2) == NPOS) |
|
1554 || line.find_first_not_of ("\n\t ", line_pos) == NPOS |
|
1555 || line.substr (line_pos, 2) == "!/") |
|
1556 { |
5592
|
1557 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1558 continue; |
|
1559 } |
|
1560 |
|
1561 // Got the start of first sentence, break. |
|
1562 pos = pos + line_pos; |
|
1563 break; |
|
1564 } |
|
1565 |
|
1566 if (pos == NPOS) |
5738
|
1567 return retval; |
5447
|
1568 |
|
1569 // At start of real text. Get first line with the sentence |
|
1570 size_t new_pos = h.find_first_of ('\n', pos); |
|
1571 std::string line = h.substr (pos, new_pos-pos); |
|
1572 size_t dot_pos; |
|
1573 |
|
1574 while ((dot_pos = line.find_first_of ('.')) == NPOS) |
|
1575 { |
|
1576 // Trim trailing blanks on line |
|
1577 line = line.substr (0, line.find_last_not_of ("\n\t ") + 1); |
|
1578 |
|
1579 // Append next line |
|
1580 size_t tmp_pos = h.find_first_not_of ("\t ", new_pos + 1); |
|
1581 if (tmp_pos == NPOS || h.substr (tmp_pos, 1) == "\n") |
|
1582 break; |
|
1583 |
|
1584 new_pos = h.find_first_of ('\n', tmp_pos); |
|
1585 std::string next = h.substr (tmp_pos, new_pos-tmp_pos); |
|
1586 |
|
1587 if (short_sentence) |
|
1588 { |
|
1589 // Only add the next line if it terminates the sentence, then break |
|
1590 if ((tmp_pos = next.find_first_of ('.')) != NPOS) |
|
1591 { |
|
1592 line = line + " " + next; |
|
1593 dot_pos = line.find_first_of ('.'); |
|
1594 } |
|
1595 break; |
|
1596 } |
|
1597 else |
|
1598 line = line + " " + next; |
|
1599 } |
|
1600 |
|
1601 if (dot_pos == NPOS) |
5738
|
1602 retval = line; |
5447
|
1603 else |
5738
|
1604 retval = line.substr (0, dot_pos + 1); |
5447
|
1605 } |
5738
|
1606 |
|
1607 return retval; |
5447
|
1608 } |
|
1609 |
|
1610 static void |
|
1611 print_lookfor (const std::string& name, const std::string& line) |
|
1612 { |
|
1613 const size_t deflen = 20; |
|
1614 |
|
1615 size_t max_width = command_editor::terminal_cols () - deflen; |
|
1616 if (max_width < deflen) |
|
1617 max_width = deflen; |
|
1618 |
|
1619 size_t name_len = name.length (); |
|
1620 |
|
1621 size_t width = max_width; |
|
1622 if (name_len > deflen) |
|
1623 { |
|
1624 width = command_editor::terminal_cols () - name_len; |
|
1625 if (width < deflen) |
|
1626 width = deflen; |
|
1627 } |
|
1628 |
|
1629 size_t pad_len = deflen > name_len ? deflen - name_len + 1 : 1; |
|
1630 octave_stdout << name << std::string (pad_len, ' '); |
|
1631 |
|
1632 size_t pos = 0; |
|
1633 |
|
1634 while (1) |
|
1635 { |
|
1636 size_t new_pos = line.find_first_of ("\n\t ", pos); |
|
1637 size_t end_pos = new_pos; |
|
1638 |
|
1639 if (line.length () - pos < width) |
|
1640 new_pos = end_pos = NPOS; |
|
1641 else |
|
1642 while (new_pos != NPOS && new_pos - pos < width) |
|
1643 { |
|
1644 end_pos = new_pos; |
|
1645 new_pos = line.find_first_of ("\n\t ", new_pos + 1); |
|
1646 } |
|
1647 |
|
1648 octave_stdout << line.substr (pos, end_pos-pos) << std::endl; |
|
1649 |
|
1650 if (end_pos == NPOS) |
|
1651 break; |
|
1652 |
|
1653 pos = end_pos + 1; |
|
1654 width = max_width; |
|
1655 octave_stdout << std::string (deflen + 1, ' '); |
|
1656 } |
|
1657 } |
|
1658 |
|
1659 DEFCMD (lookfor, args, nargout, |
|
1660 "-*- texinfo -*-\n\ |
|
1661 @deffn {Command} lookfor @var{str}\n\ |
|
1662 @deffnx {Command} lookfor -all @var{str}\n\ |
|
1663 @deffnx {Function} {[@var{fun}, @var{helpstring}] = } lookfor (@var{str})\n\ |
|
1664 @deffnx {Function} {[@var{fun}, @var{helpstring}] = } lookfor ('-all', @var{str})\n\ |
5814
|
1665 Search for the string @var{str} in all of the functions found in the\n\ |
|
1666 function search path. By default @code{lookfor} searchs for @var{str}\n\ |
|
1667 in the first sentence of the help string of each function found. The entire\n\ |
|
1668 help string of each function found in the path can be search if\n\ |
5447
|
1669 the '-all' argument is supplied. All searches are case insensitive.\n\ |
|
1670 \n\ |
|
1671 Called with no output arguments, @code{lookfor} prints the list of matching\n\ |
|
1672 functions to the terminal. Otherwise the output arguments @var{fun} and\n\ |
|
1673 @var{helpstring} define the matching functions and the first sentence of\n\ |
|
1674 each of their help strings.\n\ |
|
1675 \n\ |
|
1676 Note that the ability of @code{lookfor} to correctly identify the first\n\ |
|
1677 sentence of the help of the functions is dependent on the format of the\n\ |
|
1678 functions help. All of the functions in octave itself will correctly\n\ |
|
1679 find the first sentence, but the same can not be guaranteed for other\n\ |
|
1680 functions. Therefore the use of the '-all' argument might be necessary\n\ |
|
1681 to find related functions that are not part of octave.\n\ |
5667
|
1682 @seealso{help, which}\n\ |
5642
|
1683 @end deffn") |
5447
|
1684 { |
|
1685 octave_value_list retval; |
|
1686 int nargin = args.length (); |
|
1687 bool first_sentence_only = true; |
|
1688 |
|
1689 if (nargin != 1 && nargin != 2) |
|
1690 { |
|
1691 usage ("lookfor"); |
|
1692 return retval; |
|
1693 } |
|
1694 |
|
1695 string_vector ret[2]; |
|
1696 |
|
1697 std::string txt; |
|
1698 |
|
1699 if (args(0).is_string ()) |
|
1700 { |
|
1701 txt = args(0).string_value (); |
|
1702 |
|
1703 if (nargin == 2) |
|
1704 { |
|
1705 if (args(1).is_string ()) |
|
1706 { |
|
1707 std::string tmp = args(1).string_value (); |
|
1708 |
|
1709 if (txt.substr(0,1) == "-") |
|
1710 { |
|
1711 txt = tmp; |
|
1712 tmp = args(0).string_value (); |
|
1713 } |
|
1714 |
|
1715 if (tmp == "-all") |
|
1716 first_sentence_only = false; |
|
1717 else |
|
1718 error ("lookfor: unrecognized option argument"); |
|
1719 } |
|
1720 else |
|
1721 error ("lookfor: arguments must be a string"); |
|
1722 } |
|
1723 } |
|
1724 else |
|
1725 error ("lookfor: argument must be a string"); |
|
1726 |
|
1727 if (!error_state) |
|
1728 { |
|
1729 // All tests in lower case |
5768
|
1730 std::transform (txt.begin (), txt.end (), txt.begin (), tolower); |
5447
|
1731 |
|
1732 help_list *ptr = keyword_help (); |
|
1733 while (ptr->name) |
|
1734 { |
|
1735 std::string name = ptr->name; |
|
1736 std::string h = ptr->help; |
|
1737 |
5592
|
1738 if (name.find (txt) != NPOS) |
5447
|
1739 { |
|
1740 if (nargout) |
|
1741 { |
|
1742 ret[0].append (name); |
|
1743 ret[1].append (first_help_sentence (h)); |
|
1744 } |
|
1745 else |
|
1746 print_lookfor (name, first_help_sentence (h)); |
|
1747 } |
5592
|
1748 else |
|
1749 { |
|
1750 std::string s; |
|
1751 |
|
1752 if (first_sentence_only) |
|
1753 s = first_help_sentence (h); |
|
1754 else |
|
1755 s = h; |
|
1756 |
5768
|
1757 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1758 |
|
1759 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1760 { |
|
1761 if (nargout) |
|
1762 { |
|
1763 ret[0].append (name); |
|
1764 ret[1].append (first_help_sentence (h)); |
|
1765 } |
|
1766 else |
|
1767 print_lookfor (name, first_help_sentence (h)); |
|
1768 } |
|
1769 } |
5447
|
1770 |
|
1771 OCTAVE_QUIT; |
|
1772 |
|
1773 ptr++; |
|
1774 } |
|
1775 |
|
1776 ptr = operator_help (); |
|
1777 while (ptr->name) |
|
1778 { |
|
1779 std::string name = ptr->name; |
|
1780 std::string h = ptr->help; |
|
1781 |
5592
|
1782 if (name.find (txt) != NPOS) |
5447
|
1783 { |
|
1784 if (nargout) |
|
1785 { |
|
1786 ret[0].append (name); |
|
1787 ret[1].append (first_help_sentence (h)); |
|
1788 } |
|
1789 else |
|
1790 print_lookfor (name, first_help_sentence (h)); |
|
1791 } |
5592
|
1792 else |
|
1793 { |
|
1794 std::string s; |
|
1795 if (first_sentence_only) |
|
1796 s = first_help_sentence (h); |
|
1797 else |
|
1798 s = h; |
|
1799 |
5768
|
1800 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1801 |
|
1802 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1803 { |
|
1804 if (nargout) |
|
1805 { |
|
1806 ret[0].append (name); |
|
1807 ret[1].append (first_help_sentence (h)); |
|
1808 } |
|
1809 else |
|
1810 print_lookfor (name, first_help_sentence (h)); |
|
1811 } |
|
1812 } |
5447
|
1813 |
|
1814 OCTAVE_QUIT; |
|
1815 |
|
1816 ptr++; |
|
1817 } |
|
1818 |
|
1819 // Check the symbol record table |
|
1820 string_vector names |
|
1821 = fbi_sym_tab->name_list (string_vector (), true); |
|
1822 |
|
1823 for (octave_idx_type i = 0; i < names.length (); i++) |
|
1824 { |
|
1825 std::string name = names (i); |
|
1826 |
|
1827 OCTAVE_QUIT; |
|
1828 |
|
1829 symbol_record *sr = lookup_by_name (name, 0); |
5738
|
1830 if (sr && sr->is_defined () |
|
1831 && sr->type_name () != "overloaded function") |
5447
|
1832 { |
|
1833 std::string h = sr->help (); |
|
1834 |
5592
|
1835 if (name.find (txt) != NPOS) |
5447
|
1836 { |
|
1837 if (nargout) |
|
1838 { |
|
1839 ret[0].append (name); |
|
1840 ret[1].append (first_help_sentence (h)); |
|
1841 } |
|
1842 else |
|
1843 print_lookfor (name, first_help_sentence (h)); |
|
1844 } |
5592
|
1845 else |
|
1846 { |
|
1847 std::string s; |
|
1848 |
|
1849 if (first_sentence_only) |
|
1850 s = first_help_sentence (h); |
|
1851 else |
|
1852 s = h; |
|
1853 |
5768
|
1854 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1855 |
|
1856 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1857 { |
|
1858 if (nargout) |
|
1859 { |
|
1860 ret[0].append (name); |
|
1861 ret[1].append (first_help_sentence (h)); |
|
1862 } |
|
1863 else |
|
1864 print_lookfor (name, first_help_sentence (h)); |
|
1865 } |
|
1866 } |
5447
|
1867 } |
|
1868 } |
|
1869 |
5832
|
1870 string_vector dirs = load_path::dirs (); |
5447
|
1871 |
|
1872 int len = dirs.length (); |
|
1873 |
|
1874 for (int i = 0; i < len; i++) |
|
1875 { |
5832
|
1876 names = load_path::files (dirs[i]); |
5447
|
1877 |
|
1878 if (! names.empty ()) |
|
1879 { |
|
1880 for (int j = 0; j < names.length (); j++) |
|
1881 { |
|
1882 std::string name = names (j); |
|
1883 |
|
1884 OCTAVE_QUIT; |
|
1885 |
|
1886 // Strip extension |
|
1887 size_t l = name.length (); |
|
1888 if (l > 4 && name.substr (l-4) == ".oct") |
|
1889 name = name.substr (0, l - 4); |
|
1890 else if (l > 2 && name.substr (l-2) == ".m") |
|
1891 name = name.substr (0, l - 2); |
|
1892 else |
|
1893 continue; |
|
1894 |
|
1895 // Check if already in symbol table |
|
1896 symbol_record *sr = fbi_sym_tab->lookup (name); |
|
1897 |
|
1898 if (!sr) |
|
1899 { |
|
1900 // Check if this version is first in the path |
|
1901 |
5832
|
1902 std::string file_name = load_path::find_fcn (name); |
|
1903 |
|
1904 std::string dir = dirs[i] + file_ops::dir_sep_str; |
|
1905 |
|
1906 if (file_name == dir + name + ".oct" |
|
1907 || file_name == dir + name + ".m") |
5447
|
1908 { |
5484
|
1909 bool symbol_found; |
|
1910 |
5592
|
1911 std::string h; |
5832
|
1912 if (file_name == dir + name + ".oct") |
5592
|
1913 { |
|
1914 // oct-file. Must load to get help |
|
1915 sr = lookup_by_name (name, false); |
5447
|
1916 |
5592
|
1917 if (sr && sr->is_defined ()) |
|
1918 h = sr->help (); |
|
1919 } |
5447
|
1920 else |
5592
|
1921 h = get_help_from_file (file_name, symbol_found); |
5447
|
1922 |
5592
|
1923 if (name.find (txt) != NPOS) |
5447
|
1924 { |
|
1925 if (nargout) |
|
1926 { |
|
1927 ret[0].append (name); |
|
1928 ret[1].append (first_help_sentence (h)); |
|
1929 } |
|
1930 else |
|
1931 print_lookfor (name, first_help_sentence (h)); |
|
1932 } |
5592
|
1933 else |
|
1934 { |
|
1935 std::string s; |
|
1936 if (first_sentence_only) |
|
1937 s = first_help_sentence (h); |
|
1938 else |
|
1939 s = h; |
|
1940 |
5768
|
1941 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1942 |
|
1943 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1944 { |
|
1945 if (nargout) |
|
1946 { |
|
1947 ret[0].append (name); |
|
1948 ret[1].append (first_help_sentence (h)); |
|
1949 } |
|
1950 else |
|
1951 print_lookfor (name, first_help_sentence (h)); |
|
1952 } |
|
1953 } |
|
1954 } |
|
1955 } |
|
1956 |
|
1957 // Check if this function has autoloaded functions attached to it |
5832
|
1958 std::string file_name = load_path::find_fcn (name); |
|
1959 |
5592
|
1960 string_vector autoload_fcns = reverse_lookup_autoload (file_name); |
|
1961 |
|
1962 if (! autoload_fcns.empty ()) |
|
1963 { |
|
1964 for (int k = 0; k < autoload_fcns.length (); k++) |
|
1965 { |
|
1966 std::string aname = autoload_fcns (k); |
|
1967 |
|
1968 // Check if already in symbol table |
|
1969 sr = fbi_sym_tab->lookup (aname); |
|
1970 |
|
1971 if (!sr) |
|
1972 { |
|
1973 // Must load to get help |
5738
|
1974 sr = lookup_by_name (aname, false); |
5592
|
1975 |
|
1976 std::string h; |
|
1977 if (sr && sr->is_defined ()) |
|
1978 h = sr->help (); |
|
1979 |
|
1980 if (aname.find (txt) != NPOS) |
|
1981 { |
|
1982 if (nargout) |
|
1983 { |
|
1984 ret[0].append (aname); |
|
1985 ret[1].append (first_help_sentence (h)); |
|
1986 } |
|
1987 else |
|
1988 print_lookfor (aname, first_help_sentence (h)); |
|
1989 } |
|
1990 else |
|
1991 { |
|
1992 std::string s; |
|
1993 if (first_sentence_only) |
|
1994 s = first_help_sentence (h); |
|
1995 else |
|
1996 s = h; |
|
1997 |
5768
|
1998 std::transform (s.begin (), s.end (), s.begin (), |
5592
|
1999 tolower); |
|
2000 |
|
2001 if (s.length () > 0 && s.find (txt) != NPOS) |
|
2002 { |
|
2003 if (nargout) |
|
2004 { |
|
2005 ret[0].append (aname); |
|
2006 ret[1].append (first_help_sentence (h)); |
|
2007 } |
|
2008 else |
|
2009 print_lookfor (aname, first_help_sentence (h)); |
|
2010 } |
|
2011 } |
|
2012 } |
5447
|
2013 } |
|
2014 } |
|
2015 } |
|
2016 } |
|
2017 } |
|
2018 |
|
2019 if (nargout != 0) |
|
2020 { |
|
2021 retval (1) = ret[1]; |
|
2022 retval (0) = ret[0]; |
|
2023 } |
|
2024 } |
|
2025 else |
|
2026 { |
|
2027 error ("lookfor: argument must be a string"); |
|
2028 } |
|
2029 |
|
2030 return retval; |
|
2031 } |
|
2032 |
5794
|
2033 DEFUN (info_file, args, nargout, |
|
2034 "-*- texinfo -*-\n\ |
|
2035 @deftypefn {Built-in Function} {@var{val} =} info_file ()\n\ |
|
2036 @deftypefnx {Built-in Function} {@var{old_val} =} info_file (@var{new_val})\n\ |
|
2037 Query or set the internal variable that specifies the name of the\n\ |
|
2038 Octave info file. The default value is\n\ |
|
2039 @code{\"@var{octave-home}/info/octave.info\"}, in\n\ |
|
2040 which @var{octave-home} is the directory where all of Octave is installed.\n\ |
|
2041 @seealso{info_program, doc, help, makeinfo_program}\n\ |
|
2042 @end deftypefn") |
2202
|
2043 { |
5794
|
2044 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_file); |
2202
|
2045 } |
|
2046 |
5794
|
2047 DEFUN (info_program, args, nargout, |
|
2048 "-*- texinfo -*-\n\ |
|
2049 @deftypefn {Built-in Function} {@var{val} =} info_program ()\n\ |
|
2050 @deftypefnx {Built-in Function} {@var{old_val} =} info_program (@var{new_val})\n\ |
|
2051 Query or set the internal variable that specifies the name of the\n\ |
|
2052 info program to run. The default initial value is\n\ |
3686
|
2053 @code{\"@var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}/info\"}\n\ |
|
2054 in which @var{octave-home} is the directory where all of Octave is\n\ |
|
2055 installed, @var{version} is the Octave version number, and @var{arch}\n\ |
|
2056 is the system type (for example, @code{i686-pc-linux-gnu}). The\n\ |
|
2057 default initial value may be overridden by the environment variable\n\ |
|
2058 @code{OCTAVE_INFO_PROGRAM}, or the command line argument\n\ |
5794
|
2059 @code{--info-program NAME}.\n\ |
|
2060 @seealso{info_file, doc, help, makeinfo_program}\n\ |
|
2061 @end deftypefn") |
|
2062 { |
|
2063 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_program); |
|
2064 } |
3686
|
2065 |
5794
|
2066 DEFUN (makeinfo_program, args, nargout, |
|
2067 "-*- texinfo -*-\n\ |
|
2068 @deftypefn {Built-in Function} {@var{val} =} makeinfo_program ()\n\ |
|
2069 @deftypefnx {Built-in Function} {@var{old_val} =} makeinfo_program (@var{new_val})\n\ |
|
2070 Query or set the internal variable that specifies the name of the\n\ |
|
2071 makeinfo program that Octave runs to format help text containing\n\ |
|
2072 Texinfo markup commands. The default initial value is @code{\"makeinfo\"}.\n\ |
|
2073 @seealso{info_file, info_program, doc, help}\n\ |
|
2074 @end deftypefn") |
|
2075 { |
|
2076 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (makeinfo_program); |
|
2077 } |
2202
|
2078 |
5794
|
2079 DEFUN (suppress_verbose_help_message, args, nargout, |
|
2080 "-*- texinfo -*-\n\ |
|
2081 @deftypefn {Built-in Function} {@var{val} =} suppress_verbose_help_message ()\n\ |
|
2082 @deftypefnx {Built-in Function} {@var{old_val} =} suppress_verbose_help_message (@var{new_val})\n\ |
|
2083 Query or set the internal vaiable that controls whether Octave\n\ |
|
2084 will add additional help information to the end of the output from\n\ |
3332
|
2085 the @code{help} command and usage messages for built-in commands.\n\ |
5794
|
2086 @end deftypefn") |
|
2087 { |
|
2088 return SET_INTERNAL_VARIABLE (suppress_verbose_help_message); |
2189
|
2089 } |
|
2090 |
1
|
2091 /* |
|
2092 ;;; Local Variables: *** |
|
2093 ;;; mode: C++ *** |
|
2094 ;;; End: *** |
|
2095 */ |