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 |
4115
|
782 buf << "sed -e 's/^[#%][#%]* *//' -e 's/^ *@/@/' | " |
5794
|
783 << "\"" << Vmakeinfo_program << "\"" |
3303
|
784 << " -D \"VERSION " << OCTAVE_VERSION << "\"" |
|
785 << " -D \"OCTAVEHOME " << OCTAVE_PREFIX << "\"" |
3584
|
786 << " -D \"TARGETHOSTTYPE " << OCTAVE_CANONICAL_HOST_TYPE << "\"" |
3301
|
787 << " --fill-column " << cols |
|
788 << " --no-warn" |
|
789 << " --no-validate" |
|
790 << " --no-headers" |
|
791 << " --force" |
5765
|
792 << " --output \"" << tmp_file_name << "\""; |
3295
|
793 |
5765
|
794 oprocstream filter (buf.str ()); |
3295
|
795 |
3686
|
796 if (filter && filter.is_open ()) |
3295
|
797 { |
3405
|
798 filter << "@macro seealso {args}\n" |
5644
|
799 << "@sp 1\n" |
3408
|
800 << "@noindent\n" |
3405
|
801 << "See also: \\args\\.\n" |
|
802 << "@end macro\n"; |
|
803 |
3769
|
804 filter << msg.substr (pos+1) << std::endl; |
3295
|
805 |
3686
|
806 int status = filter.close (); |
3295
|
807 |
3523
|
808 std::ifstream tmp_file (tmp_file_name.c_str ()); |
3295
|
809 |
3686
|
810 if (WIFEXITED (status) && WEXITSTATUS (status) == 0) |
|
811 { |
|
812 int c; |
|
813 while ((c = tmp_file.get ()) != EOF) |
|
814 os << (char) c; |
3295
|
815 |
3686
|
816 tmp_file.close (); |
|
817 } |
|
818 else |
|
819 { |
|
820 warning ("help: Texinfo formatting filter exited abnormally"); |
|
821 warning ("help: raw Texinfo source of help text follows..."); |
5594
|
822 warning ("help:\n\n%s\n\n", msg.c_str ()); |
3686
|
823 } |
3295
|
824 |
|
825 file_ops::unlink (tmp_file_name); |
|
826 } |
|
827 else |
|
828 os << msg; |
|
829 } |
|
830 else |
|
831 os << msg; |
|
832 } |
|
833 |
5800
|
834 void |
|
835 display_usage_text (std::ostream& os, const std::string& msg) |
|
836 { |
|
837 std::string filtered_msg = msg; |
|
838 |
|
839 size_t pos; |
|
840 |
|
841 if (looks_like_texinfo (msg, pos)) |
|
842 { |
|
843 std::ostringstream buf; |
|
844 |
|
845 buf << "-*- texinfo -*-\n"; |
|
846 |
|
847 bool found_def = false; |
|
848 |
|
849 size_t msg_len = msg.length (); |
|
850 |
|
851 while (pos < msg_len) |
|
852 { |
|
853 size_t new_pos = msg.find_first_of ('\n', pos); |
|
854 |
|
855 if (new_pos == NPOS) |
|
856 new_pos = msg_len-1; |
|
857 |
|
858 std::string line = msg.substr (pos, new_pos-pos+1); |
|
859 |
|
860 if (line.substr (0, 4) == "@def" |
|
861 || line.substr (0, 8) == "@end def") |
|
862 { |
|
863 found_def = true; |
|
864 buf << line; |
|
865 } |
|
866 |
|
867 pos = new_pos + 1; |
|
868 } |
|
869 |
|
870 if (found_def) |
|
871 filtered_msg = buf.str (); |
|
872 } |
|
873 |
|
874 display_help_text (os, filtered_msg); |
|
875 } |
|
876 |
3295
|
877 static bool |
3523
|
878 help_from_list (std::ostream& os, const help_list *list, |
5399
|
879 const std::string& nm, int usage, bool& symbol_found) |
542
|
880 { |
5399
|
881 bool retval = false; |
|
882 |
2804
|
883 const char *name; |
3014
|
884 |
542
|
885 while ((name = list->name) != 0) |
|
886 { |
1755
|
887 if (strcmp (name, nm.c_str ()) == 0) |
542
|
888 { |
5399
|
889 symbol_found = true; |
|
890 |
|
891 std::string h = list->help; |
|
892 |
|
893 if (h.length () > 0) |
542
|
894 { |
5399
|
895 if (usage) |
|
896 os << "\nusage: "; |
|
897 else |
|
898 os << "\n*** " << nm << ":\n\n"; |
|
899 |
|
900 display_help_text (os, h); |
|
901 |
|
902 os << "\n"; |
|
903 |
|
904 retval = true; |
542
|
905 } |
5399
|
906 break; |
542
|
907 } |
|
908 list++; |
|
909 } |
3014
|
910 |
5399
|
911 return retval;; |
|
912 } |
|
913 |
|
914 std::string |
|
915 extract_help_from_dispatch (const std::string& nm) |
|
916 { |
|
917 std::string retval; |
|
918 |
|
919 symbol_record *builtin = fbi_sym_tab->lookup ("builtin:" + nm, 0); |
|
920 |
|
921 if (builtin) |
|
922 { |
|
923 // Check that builtin is up to date. |
|
924 |
|
925 // Don't try to fight octave's function name handling |
|
926 // mechanism. Instead, move dispatch record out of the way, |
|
927 // and restore the builtin to its original name. |
|
928 symbol_record *dispatch = fbi_sym_tab->lookup (nm, 0); |
|
929 |
|
930 if (dispatch) |
|
931 { |
|
932 dispatch->unprotect (); |
|
933 |
|
934 fbi_sym_tab->rename (nm, "dispatch:" + nm); |
|
935 fbi_sym_tab->rename ("builtin:" + nm, nm); |
|
936 |
|
937 // Check for updates to builtin function; ignore errors |
|
938 // that appear (they interfere with renaming), and remove |
5775
|
939 // the updated name from the current symbol table. FIXME -- |
|
940 // check that updating a function updates it in all |
|
941 // contexts. It may be that it is updated only in the |
5399
|
942 // current symbol table, and not the caller. I believe this |
|
943 // won't be a problem because the caller will go through the |
|
944 // same logic and end up with the newer version. |
|
945 |
|
946 octave_function *f = is_valid_function (nm); |
|
947 |
|
948 if (f) |
|
949 retval = builtin->help (); |
|
950 |
|
951 curr_sym_tab->clear_function (nm); |
|
952 |
|
953 // Move the builtin function out of the way and restore the |
5775
|
954 // dispatch fuction. FIXME what if builtin wants to |
5399
|
955 // protect itself? |
|
956 |
|
957 fbi_sym_tab->rename (nm, "builtin:" + nm); |
|
958 fbi_sym_tab->rename ("dispatch:" + nm, nm); |
|
959 |
|
960 dispatch->protect (); |
|
961 } |
|
962 else |
|
963 error ("failed to find dispatch record for `builtin:%s'", nm.c_str ()); |
|
964 } |
|
965 |
|
966 return retval; |
542
|
967 } |
|
968 |
3355
|
969 static bool |
5399
|
970 help_from_symbol_table (std::ostream& os, const std::string& nm, |
|
971 bool& symbol_found) |
3355
|
972 { |
|
973 bool retval = false; |
|
974 |
|
975 symbol_record *sym_rec = lookup_by_name (nm, 0); |
|
976 |
|
977 if (sym_rec && sym_rec->is_defined ()) |
|
978 { |
5399
|
979 symbol_found = true; |
|
980 |
3523
|
981 std::string h = sym_rec->help (); |
3355
|
982 |
|
983 if (h.length () > 0) |
|
984 { |
5399
|
985 h = extract_help_from_dispatch (nm) + h; |
3355
|
986 display_help_text (os, h); |
5641
|
987 if (! Vsuppress_verbose_help_message) |
|
988 { |
|
989 sym_rec->which (os); |
|
990 os << "\n"; |
|
991 } |
3355
|
992 os << "\n"; |
|
993 retval = true; |
|
994 } |
|
995 } |
|
996 |
|
997 return retval; |
|
998 } |
|
999 |
|
1000 static bool |
5399
|
1001 help_from_file (std::ostream& os, const std::string& nm, bool& symbol_found) |
3355
|
1002 { |
|
1003 bool retval = false; |
|
1004 |
5931
|
1005 std::string file; |
|
1006 |
|
1007 std::string h = get_help_from_file (nm, symbol_found, file); |
3355
|
1008 |
5484
|
1009 if (h.length () > 0) |
|
1010 { |
5931
|
1011 os << nm << " is the file " << file << "\n\n"; |
5484
|
1012 display_help_text (os, h); |
|
1013 os << "\n"; |
|
1014 retval = true; |
3355
|
1015 } |
|
1016 |
|
1017 return retval; |
|
1018 } |
|
1019 |
1140
|
1020 static void |
1755
|
1021 builtin_help (int argc, const string_vector& argv) |
1140
|
1022 { |
|
1023 help_list *op_help_list = operator_help (); |
|
1024 help_list *kw_help_list = keyword_help (); |
|
1025 |
1755
|
1026 for (int i = 1; i < argc; i++) |
1140
|
1027 { |
5399
|
1028 bool symbol_found = false; |
|
1029 |
|
1030 if (help_from_list (octave_stdout, op_help_list, argv[i], 0, |
|
1031 symbol_found)) |
1140
|
1032 continue; |
|
1033 |
5399
|
1034 if (help_from_list (octave_stdout, kw_help_list, argv[i], 0, |
|
1035 symbol_found)) |
1140
|
1036 continue; |
|
1037 |
5399
|
1038 if (help_from_symbol_table (octave_stdout, argv[i], symbol_found)) |
|
1039 continue; |
|
1040 |
|
1041 if (help_from_file (octave_stdout, argv[i], symbol_found)) |
3355
|
1042 continue; |
1755
|
1043 |
5399
|
1044 if (symbol_found) |
|
1045 octave_stdout << "\nhelp: `" << argv[i] |
|
1046 << "' is not documented\n"; |
|
1047 else |
|
1048 octave_stdout << "\nhelp: `" << argv[i] |
|
1049 << "' not found\n"; |
1140
|
1050 } |
|
1051 |
2095
|
1052 additional_help_message (octave_stdout); |
1140
|
1053 } |
|
1054 |
4208
|
1055 DEFCMD (help, args, , |
3332
|
1056 "-*- texinfo -*-\n\ |
|
1057 @deffn {Command} help\n\ |
|
1058 Octave's @code{help} command can be used to print brief usage-style\n\ |
|
1059 messages, or to display information directly from an on-line version of\n\ |
|
1060 the printed manual, using the GNU Info browser. If invoked without any\n\ |
5794
|
1061 arguments, @code{help} prints a list of all the available operators\n\ |
|
1062 and functions. If the first argument is @code{-i}, the @code{help}\n\ |
|
1063 command searches the index of the on-line version of this manual for\n\ |
|
1064 the given topics.\n\ |
3168
|
1065 \n\ |
3332
|
1066 For example, the command @kbd{help help} prints a short message\n\ |
|
1067 describing the @code{help} command, and @kbd{help -i help} starts the\n\ |
|
1068 GNU Info browser at this node in the on-line version of the manual.\n\ |
|
1069 \n\ |
|
1070 Once the GNU Info browser is running, help for using it is available\n\ |
|
1071 using the command @kbd{C-h}.\n\ |
5672
|
1072 @seealso{doc, which, lookfor}\n\ |
3333
|
1073 @end deffn") |
529
|
1074 { |
2086
|
1075 octave_value_list retval; |
529
|
1076 |
1755
|
1077 int argc = args.length () + 1; |
|
1078 |
1968
|
1079 string_vector argv = args.make_argv ("help"); |
1755
|
1080 |
|
1081 if (error_state) |
|
1082 return retval; |
529
|
1083 |
|
1084 if (argc == 1) |
3014
|
1085 simple_help (); |
529
|
1086 else |
|
1087 { |
1755
|
1088 if (argv[1] == "-i") |
3014
|
1089 help_from_info (argv, 2, argc); |
529
|
1090 else |
3014
|
1091 builtin_help (argc, argv); |
529
|
1092 } |
|
1093 |
|
1094 return retval; |
|
1095 } |
|
1096 |
3355
|
1097 static void |
3523
|
1098 do_type (std::ostream& os, const std::string& name, bool pr_type_info, |
3355
|
1099 bool quiet, bool pr_orig_txt) |
|
1100 { |
|
1101 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1102 |
|
1103 if (sym_rec && sym_rec->is_defined ()) |
3356
|
1104 sym_rec->type (os, pr_type_info, quiet, pr_orig_txt); |
3355
|
1105 else |
|
1106 { |
3523
|
1107 std::string ff = fcn_file_in_path (name); |
3355
|
1108 |
|
1109 if (! ff.empty ()) |
|
1110 { |
3538
|
1111 std::ifstream fs (ff.c_str (), std::ios::in); |
3355
|
1112 |
|
1113 if (fs) |
|
1114 { |
|
1115 if (pr_type_info && ! quiet) |
|
1116 os << name << " is the script file: " << ff << "\n\n"; |
|
1117 |
|
1118 char ch; |
|
1119 |
|
1120 while (fs.get (ch)) |
|
1121 os << ch; |
|
1122 } |
|
1123 else |
|
1124 os << "unable to open `" << ff << "' for reading!\n"; |
|
1125 } |
|
1126 else |
|
1127 error ("type: `%s' undefined", name.c_str ()); |
|
1128 } |
|
1129 } |
|
1130 |
4208
|
1131 DEFCMD (type, args, nargout, |
3361
|
1132 "-*- texinfo -*-\n\ |
|
1133 \n\ |
|
1134 @deffn {Command} type options name @dots{}\n\ |
|
1135 Display the definition of each @var{name} that refers to a function.\n\ |
|
1136 \n\ |
|
1137 Normally also displays if each @var{name} is user-defined or builtin;\n\ |
|
1138 the @code{-q} option suppresses this behaviour.\n\ |
581
|
1139 \n\ |
3361
|
1140 Currently, Octave can only display functions that can be compiled\n\ |
|
1141 cleanly, because it uses its internal representation of the function to\n\ |
|
1142 recreate the program text.\n\ |
|
1143 \n\ |
|
1144 Comments are not displayed because Octave's parser currently discards\n\ |
|
1145 them as it converts the text of a function file to its internal\n\ |
|
1146 representation. This problem may be fixed in a future release.\n\ |
|
1147 @end deffn") |
581
|
1148 { |
3584
|
1149 octave_value retval; |
1588
|
1150 |
1755
|
1151 int argc = args.length () + 1; |
|
1152 |
1968
|
1153 string_vector argv = args.make_argv ("type"); |
1755
|
1154 |
3355
|
1155 if (! error_state) |
581
|
1156 { |
3355
|
1157 if (argc > 1) |
|
1158 { |
5775
|
1159 // FIXME -- we should really use getopt () |
2532
|
1160 |
3355
|
1161 bool quiet = false; |
|
1162 bool pr_orig_txt = true; |
2532
|
1163 |
3355
|
1164 int idx; |
581
|
1165 |
3355
|
1166 for (idx = 1; idx < argc; idx++) |
1281
|
1167 { |
3355
|
1168 if (argv[idx] == "-q" || argv[idx] == "-quiet") |
|
1169 quiet = true; |
|
1170 else if (argv[idx] == "-t" || argv[idx] == "-transformed") |
|
1171 pr_orig_txt = false; |
|
1172 else |
|
1173 break; |
1281
|
1174 } |
|
1175 |
3355
|
1176 if (idx < argc) |
|
1177 { |
5765
|
1178 std::ostringstream output_buf; |
581
|
1179 |
3355
|
1180 for (int i = idx; i < argc; i++) |
581
|
1181 { |
3523
|
1182 std::string id = argv[i]; |
2534
|
1183 |
3355
|
1184 if (nargout == 0) |
|
1185 do_type (octave_stdout, id, true, quiet, pr_orig_txt); |
|
1186 else |
|
1187 do_type (output_buf, id, false, quiet, pr_orig_txt); |
581
|
1188 |
3355
|
1189 if (error_state) |
|
1190 goto abort; |
581
|
1191 } |
|
1192 |
3584
|
1193 if (nargout != 0) |
5765
|
1194 retval = output_buf.str (); |
581
|
1195 } |
|
1196 else |
5823
|
1197 print_usage (); |
3355
|
1198 } |
|
1199 else |
5823
|
1200 print_usage (); |
3355
|
1201 } |
3141
|
1202 |
3355
|
1203 abort: |
581
|
1204 |
|
1205 return retval; |
|
1206 } |
|
1207 |
3536
|
1208 static std::string |
3523
|
1209 do_which (const std::string& name) |
3355
|
1210 { |
3523
|
1211 std::string retval; |
3355
|
1212 |
|
1213 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1214 |
|
1215 if (sym_rec && sym_rec->is_defined ()) |
|
1216 retval = sym_rec->which (); |
|
1217 else |
|
1218 { |
3523
|
1219 std::string path = fcn_file_in_path (name); |
3355
|
1220 |
|
1221 if (! path.empty ()) |
|
1222 retval = path; |
|
1223 else |
|
1224 retval = "undefined"; |
|
1225 } |
|
1226 |
|
1227 return retval; |
|
1228 } |
|
1229 |
|
1230 static void |
3523
|
1231 do_which (std::ostream& os, const std::string& name) |
3355
|
1232 { |
|
1233 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1234 |
|
1235 if (sym_rec && sym_rec->is_defined ()) |
|
1236 sym_rec->which (os); |
|
1237 else |
|
1238 { |
3523
|
1239 std::string path = fcn_file_in_path (name); |
3355
|
1240 |
|
1241 if (! path.empty ()) |
|
1242 os << "which: `" << name << "' is the script file\n" |
|
1243 << path << "\n"; |
|
1244 else |
|
1245 os << "which: `" << name << "' is undefined\n"; |
|
1246 } |
|
1247 } |
|
1248 |
4208
|
1249 DEFCMD (which, args, nargout, |
3361
|
1250 "-*- texinfo -*-\n\ |
|
1251 @deffn {Command} which name @dots{}\n\ |
|
1252 Display the type of each @var{name}. If @var{name} is defined from a\n\ |
|
1253 function file, the full name of the file is also displayed.\n\ |
5667
|
1254 @seealso{help, lookfor}\n\ |
3361
|
1255 @end deffn") |
581
|
1256 { |
2086
|
1257 octave_value_list retval; |
581
|
1258 |
1968
|
1259 string_vector argv = args.make_argv ("which"); |
1755
|
1260 |
3355
|
1261 if (! error_state) |
|
1262 { |
|
1263 int argc = argv.length (); |
581
|
1264 |
|
1265 if (nargout > 0) |
|
1266 retval.resize (argc-1, Matrix ()); |
|
1267 |
3355
|
1268 if (argc > 1) |
581
|
1269 { |
3355
|
1270 for (int i = 1; i < argc; i++) |
581
|
1271 { |
3523
|
1272 std::string id = argv[i]; |
3141
|
1273 |
3355
|
1274 if (nargout == 0) |
|
1275 do_which (octave_stdout, id); |
581
|
1276 else |
3355
|
1277 retval(i-1) = do_which (id); |
581
|
1278 } |
|
1279 } |
3355
|
1280 else |
5823
|
1281 print_usage (); |
581
|
1282 } |
|
1283 |
|
1284 return retval; |
|
1285 } |
|
1286 |
5775
|
1287 // FIXME |
5447
|
1288 // This function attempts to find the first sentence of a help string, though |
|
1289 // given that the user can create the help in an arbitrary format, your |
|
1290 // success might vary.. it works much better with help string formated in |
|
1291 // texinfo. Using regex might make this function much simpler. |
|
1292 |
|
1293 std::string |
|
1294 first_help_sentence (const std::string& h, bool short_sentence = true) |
|
1295 { |
5738
|
1296 std::string retval; |
|
1297 |
5447
|
1298 size_t pos = 0; |
|
1299 |
|
1300 if (looks_like_texinfo (h, pos)) |
5592
|
1301 { |
|
1302 // Get the parsed help string. |
5447
|
1303 pos = 0; |
5765
|
1304 std::ostringstream os; |
5447
|
1305 display_help_text (os, h); |
|
1306 std::string h2 = os.str (); |
|
1307 |
|
1308 while (1) |
|
1309 { |
|
1310 // Skip leading whitespace and get new line |
|
1311 pos = h2.find_first_not_of ("\n\t ", pos); |
|
1312 |
|
1313 if (pos == NPOS) |
|
1314 break; |
|
1315 |
|
1316 size_t new_pos = h2.find_first_of ('\n', pos); |
|
1317 std::string line = h2.substr (pos, new_pos-pos); |
|
1318 |
|
1319 // Skip lines starting in "-" |
|
1320 if (line.find_first_of ('-') == 0) |
|
1321 { |
|
1322 pos = new_pos + 1; |
|
1323 continue; |
|
1324 } |
|
1325 |
|
1326 break; |
|
1327 } |
|
1328 |
|
1329 if (pos == NPOS) |
5738
|
1330 return retval; |
5447
|
1331 |
|
1332 // At start of real text. Get first line with the sentence |
|
1333 size_t new_pos = h2.find_first_of ('\n', pos); |
|
1334 std::string line = h2.substr (pos, new_pos-pos); |
|
1335 size_t dot_pos; |
|
1336 |
|
1337 while ((dot_pos = line.find_first_of ('.')) == NPOS) |
|
1338 { |
|
1339 // Trim trailing blanks on line |
|
1340 line.substr (0, line.find_last_not_of ("\n\t ") + 1); |
|
1341 |
|
1342 // Append next line |
|
1343 size_t tmp_pos = h2.find_first_not_of ("\n\t ", new_pos + 1); |
|
1344 if (tmp_pos == NPOS || h2.substr (tmp_pos, 1) == "\n") |
|
1345 break; |
|
1346 |
|
1347 new_pos = h2.find_first_of ('\n', tmp_pos); |
|
1348 std::string next = h2.substr (tmp_pos, new_pos-tmp_pos); |
|
1349 |
|
1350 if (short_sentence) |
|
1351 { |
|
1352 if ((tmp_pos = next.find_first_of ('.')) != NPOS) |
|
1353 { |
|
1354 line = line + " " + next; |
|
1355 dot_pos = line.find_first_of ('.'); |
|
1356 } |
|
1357 break; |
|
1358 } |
|
1359 else |
|
1360 line = line + " " + next; |
|
1361 } |
|
1362 |
|
1363 if (dot_pos == NPOS) |
5738
|
1364 retval = line; |
5447
|
1365 else |
5738
|
1366 retval = line.substr (0, dot_pos + 1); |
5447
|
1367 } |
|
1368 else |
|
1369 { |
|
1370 std::string _upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
1371 std::string _lower = "abcdefghijklmnopqrstuvwxyz"; |
|
1372 std::string _alpha = _upper + _lower + "_"; |
|
1373 std::string _alphanum = _alpha + "1234567890"; |
|
1374 pos = 0; |
|
1375 |
|
1376 while (1) |
|
1377 { |
|
1378 // Skip leading whitespace and get new line |
|
1379 pos = h.find_first_not_of ("\n\t ", pos); |
|
1380 |
|
1381 if (pos == NPOS) |
|
1382 break; |
|
1383 |
|
1384 size_t new_pos = h.find_first_of ('\n', pos); |
|
1385 std::string line = h.substr (pos, new_pos-pos); |
|
1386 |
|
1387 // Make a lower case copy to simplify some tests |
|
1388 std::string lower = line; |
5768
|
1389 std::transform (lower.begin (), lower.end (), lower.begin (), tolower); |
5447
|
1390 |
|
1391 // Skip lines starting in "-" or "Usage" |
|
1392 if (lower.find_first_of ('-') == 0 |
|
1393 || lower.substr (0, 5) == "usage") |
|
1394 { |
5592
|
1395 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1396 continue; |
|
1397 } |
|
1398 |
|
1399 size_t line_pos = 0; |
|
1400 size_t tmp_pos = 0; |
|
1401 |
|
1402 // chop " blah : " |
|
1403 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1404 (_alphanum, line_pos)); |
|
1405 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == ":") |
|
1406 line_pos = line.find_first_not_of ("\t ", tmp_pos + 1); |
|
1407 |
|
1408 if (line_pos == NPOS) |
|
1409 { |
5592
|
1410 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1411 continue; |
|
1412 } |
|
1413 |
|
1414 // chop " function " |
|
1415 if (lower.substr (line_pos, 8) == "function") |
|
1416 line_pos = line.find_first_not_of ("\t ", line_pos + 8); |
|
1417 |
|
1418 if (line_pos == NPOS) |
|
1419 { |
5592
|
1420 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1421 continue; |
|
1422 } |
|
1423 |
|
1424 // chop " [a,b] = " |
|
1425 if (line.substr (line_pos, 1) == "[") |
|
1426 { |
|
1427 tmp_pos = line.find_first_not_of |
|
1428 ("\t ", line.find_first_of ("]", line_pos) + 1); |
|
1429 |
|
1430 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "=") |
|
1431 line_pos = line.find_first_not_of ("\t ",tmp_pos + 1); |
|
1432 } |
|
1433 |
|
1434 if (line_pos == NPOS) |
|
1435 { |
5592
|
1436 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1437 continue; |
|
1438 } |
|
1439 |
|
1440 // chop " a = " |
|
1441 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1442 { |
|
1443 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1444 (_alphanum, line_pos)); |
|
1445 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "=") |
|
1446 line_pos = line.find_first_not_of ("\t ", tmp_pos + 1); |
|
1447 } |
|
1448 |
|
1449 if (line_pos == NPOS) |
|
1450 { |
|
1451 pos = new_pos + 1; |
|
1452 continue; |
|
1453 } |
|
1454 |
|
1455 // chop " f(x) " |
|
1456 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1457 { |
|
1458 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1459 (_alphanum, line_pos)); |
|
1460 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "(") |
|
1461 line_pos = line.find_first_not_of ("\t ", line.find_first_of |
|
1462 (")", tmp_pos) + 1); |
|
1463 } |
|
1464 |
|
1465 if (line_pos == NPOS) |
|
1466 { |
5592
|
1467 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1468 continue; |
|
1469 } |
|
1470 |
|
1471 // chop " ; " |
|
1472 if (line.substr (line_pos, 1) == ":" |
|
1473 || line.substr (line_pos, 1) == ";") |
|
1474 line_pos = line.find_first_not_of ("\t ", line_pos + 1); |
|
1475 |
|
1476 if (line_pos == NPOS) |
|
1477 { |
5592
|
1478 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1479 continue; |
|
1480 } |
|
1481 |
|
1482 // chop " BLAH " |
|
1483 if (line.length () > line_pos + 2 |
|
1484 && line.find_first_of (_upper, line_pos) == line_pos |
|
1485 && line.find_first_of (_upper, line_pos+1) == line_pos + 1) |
|
1486 line_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1487 (_upper + "0123456789_", line_pos)); |
|
1488 |
|
1489 if (line_pos == NPOS) |
|
1490 { |
5592
|
1491 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1492 continue; |
|
1493 } |
|
1494 |
|
1495 // chop " blah --- " |
|
1496 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1497 (_alphanum, line_pos)); |
|
1498 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "-") |
|
1499 { |
|
1500 tmp_pos = line.find_first_not_of ("-", tmp_pos); |
|
1501 if (line.substr (tmp_pos, 1) == " " |
|
1502 || line.substr (tmp_pos, 1) == "\t") |
|
1503 line_pos = line.find_first_not_of ("\t ", tmp_pos); |
|
1504 } |
|
1505 |
|
1506 if (line_pos == NPOS) |
|
1507 { |
5592
|
1508 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1509 continue; |
|
1510 } |
|
1511 |
|
1512 // chop " blah <TAB> " |
|
1513 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1514 { |
|
1515 tmp_pos = line.find_first_not_of (" ", line.find_first_not_of |
|
1516 (_alphanum, line_pos)); |
|
1517 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "\t") |
|
1518 line_pos = line.find_first_not_of ("\t ", line.find_first_of |
|
1519 (")", tmp_pos) + 1); |
|
1520 } |
|
1521 |
|
1522 if (line_pos == NPOS) |
|
1523 { |
5592
|
1524 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1525 continue; |
|
1526 } |
|
1527 |
|
1528 // chop " blah " |
|
1529 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1530 { |
|
1531 tmp_pos = line.find_first_not_of (_alphanum, line_pos); |
|
1532 |
|
1533 if (tmp_pos != NPOS |
|
1534 && (line.substr (tmp_pos, 2) == "\t\t" |
|
1535 || line.substr (tmp_pos, 2) == "\t " |
|
1536 || line.substr (tmp_pos, 2) == " \t" |
|
1537 || line.substr (tmp_pos, 2) == " ")) |
|
1538 line_pos = line.find_first_not_of ("\t ", tmp_pos); |
|
1539 } |
|
1540 |
|
1541 if (line_pos == NPOS) |
|
1542 { |
5592
|
1543 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1544 continue; |
|
1545 } |
|
1546 |
|
1547 // skip blah \n or \n blah |
|
1548 // skip blank line |
|
1549 // skip "# !/usr/bin/octave" |
|
1550 if ((line.substr (line_pos , 2) == "or" |
|
1551 && line.find_first_not_of ("\n\t ", line_pos + 2) == NPOS) |
|
1552 || line.find_first_not_of ("\n\t ", line_pos) == NPOS |
|
1553 || line.substr (line_pos, 2) == "!/") |
|
1554 { |
5592
|
1555 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1556 continue; |
|
1557 } |
|
1558 |
|
1559 // Got the start of first sentence, break. |
|
1560 pos = pos + line_pos; |
|
1561 break; |
|
1562 } |
|
1563 |
|
1564 if (pos == NPOS) |
5738
|
1565 return retval; |
5447
|
1566 |
|
1567 // At start of real text. Get first line with the sentence |
|
1568 size_t new_pos = h.find_first_of ('\n', pos); |
|
1569 std::string line = h.substr (pos, new_pos-pos); |
|
1570 size_t dot_pos; |
|
1571 |
|
1572 while ((dot_pos = line.find_first_of ('.')) == NPOS) |
|
1573 { |
|
1574 // Trim trailing blanks on line |
|
1575 line = line.substr (0, line.find_last_not_of ("\n\t ") + 1); |
|
1576 |
|
1577 // Append next line |
|
1578 size_t tmp_pos = h.find_first_not_of ("\t ", new_pos + 1); |
|
1579 if (tmp_pos == NPOS || h.substr (tmp_pos, 1) == "\n") |
|
1580 break; |
|
1581 |
|
1582 new_pos = h.find_first_of ('\n', tmp_pos); |
|
1583 std::string next = h.substr (tmp_pos, new_pos-tmp_pos); |
|
1584 |
|
1585 if (short_sentence) |
|
1586 { |
|
1587 // Only add the next line if it terminates the sentence, then break |
|
1588 if ((tmp_pos = next.find_first_of ('.')) != NPOS) |
|
1589 { |
|
1590 line = line + " " + next; |
|
1591 dot_pos = line.find_first_of ('.'); |
|
1592 } |
|
1593 break; |
|
1594 } |
|
1595 else |
|
1596 line = line + " " + next; |
|
1597 } |
|
1598 |
|
1599 if (dot_pos == NPOS) |
5738
|
1600 retval = line; |
5447
|
1601 else |
5738
|
1602 retval = line.substr (0, dot_pos + 1); |
5447
|
1603 } |
5738
|
1604 |
|
1605 return retval; |
5447
|
1606 } |
|
1607 |
|
1608 static void |
|
1609 print_lookfor (const std::string& name, const std::string& line) |
|
1610 { |
|
1611 const size_t deflen = 20; |
|
1612 |
|
1613 size_t max_width = command_editor::terminal_cols () - deflen; |
|
1614 if (max_width < deflen) |
|
1615 max_width = deflen; |
|
1616 |
|
1617 size_t name_len = name.length (); |
|
1618 |
|
1619 size_t width = max_width; |
|
1620 if (name_len > deflen) |
|
1621 { |
|
1622 width = command_editor::terminal_cols () - name_len; |
|
1623 if (width < deflen) |
|
1624 width = deflen; |
|
1625 } |
|
1626 |
|
1627 size_t pad_len = deflen > name_len ? deflen - name_len + 1 : 1; |
|
1628 octave_stdout << name << std::string (pad_len, ' '); |
|
1629 |
|
1630 size_t pos = 0; |
|
1631 |
|
1632 while (1) |
|
1633 { |
|
1634 size_t new_pos = line.find_first_of ("\n\t ", pos); |
|
1635 size_t end_pos = new_pos; |
|
1636 |
|
1637 if (line.length () - pos < width) |
|
1638 new_pos = end_pos = NPOS; |
|
1639 else |
|
1640 while (new_pos != NPOS && new_pos - pos < width) |
|
1641 { |
|
1642 end_pos = new_pos; |
|
1643 new_pos = line.find_first_of ("\n\t ", new_pos + 1); |
|
1644 } |
|
1645 |
|
1646 octave_stdout << line.substr (pos, end_pos-pos) << std::endl; |
|
1647 |
|
1648 if (end_pos == NPOS) |
|
1649 break; |
|
1650 |
|
1651 pos = end_pos + 1; |
|
1652 width = max_width; |
|
1653 octave_stdout << std::string (deflen + 1, ' '); |
|
1654 } |
|
1655 } |
|
1656 |
|
1657 DEFCMD (lookfor, args, nargout, |
|
1658 "-*- texinfo -*-\n\ |
|
1659 @deffn {Command} lookfor @var{str}\n\ |
|
1660 @deffnx {Command} lookfor -all @var{str}\n\ |
|
1661 @deffnx {Function} {[@var{fun}, @var{helpstring}] = } lookfor (@var{str})\n\ |
|
1662 @deffnx {Function} {[@var{fun}, @var{helpstring}] = } lookfor ('-all', @var{str})\n\ |
5814
|
1663 Search for the string @var{str} in all of the functions found in the\n\ |
|
1664 function search path. By default @code{lookfor} searchs for @var{str}\n\ |
|
1665 in the first sentence of the help string of each function found. The entire\n\ |
|
1666 help string of each function found in the path can be search if\n\ |
5447
|
1667 the '-all' argument is supplied. All searches are case insensitive.\n\ |
|
1668 \n\ |
|
1669 Called with no output arguments, @code{lookfor} prints the list of matching\n\ |
|
1670 functions to the terminal. Otherwise the output arguments @var{fun} and\n\ |
|
1671 @var{helpstring} define the matching functions and the first sentence of\n\ |
|
1672 each of their help strings.\n\ |
|
1673 \n\ |
|
1674 Note that the ability of @code{lookfor} to correctly identify the first\n\ |
|
1675 sentence of the help of the functions is dependent on the format of the\n\ |
|
1676 functions help. All of the functions in octave itself will correctly\n\ |
|
1677 find the first sentence, but the same can not be guaranteed for other\n\ |
|
1678 functions. Therefore the use of the '-all' argument might be necessary\n\ |
|
1679 to find related functions that are not part of octave.\n\ |
5667
|
1680 @seealso{help, which}\n\ |
5642
|
1681 @end deffn") |
5447
|
1682 { |
|
1683 octave_value_list retval; |
|
1684 int nargin = args.length (); |
|
1685 bool first_sentence_only = true; |
|
1686 |
|
1687 if (nargin != 1 && nargin != 2) |
|
1688 { |
|
1689 usage ("lookfor"); |
|
1690 return retval; |
|
1691 } |
|
1692 |
|
1693 string_vector ret[2]; |
|
1694 |
|
1695 std::string txt; |
|
1696 |
|
1697 if (args(0).is_string ()) |
|
1698 { |
|
1699 txt = args(0).string_value (); |
|
1700 |
|
1701 if (nargin == 2) |
|
1702 { |
|
1703 if (args(1).is_string ()) |
|
1704 { |
|
1705 std::string tmp = args(1).string_value (); |
|
1706 |
|
1707 if (txt.substr(0,1) == "-") |
|
1708 { |
|
1709 txt = tmp; |
|
1710 tmp = args(0).string_value (); |
|
1711 } |
|
1712 |
|
1713 if (tmp == "-all") |
|
1714 first_sentence_only = false; |
|
1715 else |
|
1716 error ("lookfor: unrecognized option argument"); |
|
1717 } |
|
1718 else |
|
1719 error ("lookfor: arguments must be a string"); |
|
1720 } |
|
1721 } |
|
1722 else |
|
1723 error ("lookfor: argument must be a string"); |
|
1724 |
|
1725 if (!error_state) |
|
1726 { |
|
1727 // All tests in lower case |
5768
|
1728 std::transform (txt.begin (), txt.end (), txt.begin (), tolower); |
5447
|
1729 |
|
1730 help_list *ptr = keyword_help (); |
|
1731 while (ptr->name) |
|
1732 { |
|
1733 std::string name = ptr->name; |
|
1734 std::string h = ptr->help; |
|
1735 |
5592
|
1736 if (name.find (txt) != NPOS) |
5447
|
1737 { |
|
1738 if (nargout) |
|
1739 { |
|
1740 ret[0].append (name); |
|
1741 ret[1].append (first_help_sentence (h)); |
|
1742 } |
|
1743 else |
|
1744 print_lookfor (name, first_help_sentence (h)); |
|
1745 } |
5592
|
1746 else |
|
1747 { |
|
1748 std::string s; |
|
1749 |
|
1750 if (first_sentence_only) |
|
1751 s = first_help_sentence (h); |
|
1752 else |
|
1753 s = h; |
|
1754 |
5768
|
1755 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1756 |
|
1757 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1758 { |
|
1759 if (nargout) |
|
1760 { |
|
1761 ret[0].append (name); |
|
1762 ret[1].append (first_help_sentence (h)); |
|
1763 } |
|
1764 else |
|
1765 print_lookfor (name, first_help_sentence (h)); |
|
1766 } |
|
1767 } |
5447
|
1768 |
|
1769 OCTAVE_QUIT; |
|
1770 |
|
1771 ptr++; |
|
1772 } |
|
1773 |
|
1774 ptr = operator_help (); |
|
1775 while (ptr->name) |
|
1776 { |
|
1777 std::string name = ptr->name; |
|
1778 std::string h = ptr->help; |
|
1779 |
5592
|
1780 if (name.find (txt) != NPOS) |
5447
|
1781 { |
|
1782 if (nargout) |
|
1783 { |
|
1784 ret[0].append (name); |
|
1785 ret[1].append (first_help_sentence (h)); |
|
1786 } |
|
1787 else |
|
1788 print_lookfor (name, first_help_sentence (h)); |
|
1789 } |
5592
|
1790 else |
|
1791 { |
|
1792 std::string s; |
|
1793 if (first_sentence_only) |
|
1794 s = first_help_sentence (h); |
|
1795 else |
|
1796 s = h; |
|
1797 |
5768
|
1798 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1799 |
|
1800 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1801 { |
|
1802 if (nargout) |
|
1803 { |
|
1804 ret[0].append (name); |
|
1805 ret[1].append (first_help_sentence (h)); |
|
1806 } |
|
1807 else |
|
1808 print_lookfor (name, first_help_sentence (h)); |
|
1809 } |
|
1810 } |
5447
|
1811 |
|
1812 OCTAVE_QUIT; |
|
1813 |
|
1814 ptr++; |
|
1815 } |
|
1816 |
|
1817 // Check the symbol record table |
|
1818 string_vector names |
|
1819 = fbi_sym_tab->name_list (string_vector (), true); |
|
1820 |
|
1821 for (octave_idx_type i = 0; i < names.length (); i++) |
|
1822 { |
|
1823 std::string name = names (i); |
|
1824 |
|
1825 OCTAVE_QUIT; |
|
1826 |
|
1827 symbol_record *sr = lookup_by_name (name, 0); |
5738
|
1828 if (sr && sr->is_defined () |
|
1829 && sr->type_name () != "overloaded function") |
5447
|
1830 { |
|
1831 std::string h = sr->help (); |
|
1832 |
5592
|
1833 if (name.find (txt) != NPOS) |
5447
|
1834 { |
|
1835 if (nargout) |
|
1836 { |
|
1837 ret[0].append (name); |
|
1838 ret[1].append (first_help_sentence (h)); |
|
1839 } |
|
1840 else |
|
1841 print_lookfor (name, first_help_sentence (h)); |
|
1842 } |
5592
|
1843 else |
|
1844 { |
|
1845 std::string s; |
|
1846 |
|
1847 if (first_sentence_only) |
|
1848 s = first_help_sentence (h); |
|
1849 else |
|
1850 s = h; |
|
1851 |
5768
|
1852 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1853 |
|
1854 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1855 { |
|
1856 if (nargout) |
|
1857 { |
|
1858 ret[0].append (name); |
|
1859 ret[1].append (first_help_sentence (h)); |
|
1860 } |
|
1861 else |
|
1862 print_lookfor (name, first_help_sentence (h)); |
|
1863 } |
|
1864 } |
5447
|
1865 } |
|
1866 } |
|
1867 |
5832
|
1868 string_vector dirs = load_path::dirs (); |
5447
|
1869 |
|
1870 int len = dirs.length (); |
|
1871 |
|
1872 for (int i = 0; i < len; i++) |
|
1873 { |
5832
|
1874 names = load_path::files (dirs[i]); |
5447
|
1875 |
|
1876 if (! names.empty ()) |
|
1877 { |
|
1878 for (int j = 0; j < names.length (); j++) |
|
1879 { |
|
1880 std::string name = names (j); |
|
1881 |
|
1882 OCTAVE_QUIT; |
|
1883 |
|
1884 // Strip extension |
|
1885 size_t l = name.length (); |
|
1886 if (l > 4 && name.substr (l-4) == ".oct") |
|
1887 name = name.substr (0, l - 4); |
|
1888 else if (l > 2 && name.substr (l-2) == ".m") |
|
1889 name = name.substr (0, l - 2); |
|
1890 else |
|
1891 continue; |
|
1892 |
|
1893 // Check if already in symbol table |
|
1894 symbol_record *sr = fbi_sym_tab->lookup (name); |
|
1895 |
|
1896 if (!sr) |
|
1897 { |
|
1898 // Check if this version is first in the path |
|
1899 |
5832
|
1900 std::string file_name = load_path::find_fcn (name); |
|
1901 |
|
1902 std::string dir = dirs[i] + file_ops::dir_sep_str; |
|
1903 |
|
1904 if (file_name == dir + name + ".oct" |
|
1905 || file_name == dir + name + ".m") |
5447
|
1906 { |
5484
|
1907 bool symbol_found; |
|
1908 |
5592
|
1909 std::string h; |
5832
|
1910 if (file_name == dir + name + ".oct") |
5592
|
1911 { |
|
1912 // oct-file. Must load to get help |
|
1913 sr = lookup_by_name (name, false); |
5447
|
1914 |
5592
|
1915 if (sr && sr->is_defined ()) |
|
1916 h = sr->help (); |
|
1917 } |
5447
|
1918 else |
5592
|
1919 h = get_help_from_file (file_name, symbol_found); |
5447
|
1920 |
5592
|
1921 if (name.find (txt) != NPOS) |
5447
|
1922 { |
|
1923 if (nargout) |
|
1924 { |
|
1925 ret[0].append (name); |
|
1926 ret[1].append (first_help_sentence (h)); |
|
1927 } |
|
1928 else |
|
1929 print_lookfor (name, first_help_sentence (h)); |
|
1930 } |
5592
|
1931 else |
|
1932 { |
|
1933 std::string s; |
|
1934 if (first_sentence_only) |
|
1935 s = first_help_sentence (h); |
|
1936 else |
|
1937 s = h; |
|
1938 |
5768
|
1939 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1940 |
|
1941 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1942 { |
|
1943 if (nargout) |
|
1944 { |
|
1945 ret[0].append (name); |
|
1946 ret[1].append (first_help_sentence (h)); |
|
1947 } |
|
1948 else |
|
1949 print_lookfor (name, first_help_sentence (h)); |
|
1950 } |
|
1951 } |
|
1952 } |
|
1953 } |
|
1954 |
|
1955 // Check if this function has autoloaded functions attached to it |
5832
|
1956 std::string file_name = load_path::find_fcn (name); |
|
1957 |
5592
|
1958 string_vector autoload_fcns = reverse_lookup_autoload (file_name); |
|
1959 |
|
1960 if (! autoload_fcns.empty ()) |
|
1961 { |
|
1962 for (int k = 0; k < autoload_fcns.length (); k++) |
|
1963 { |
|
1964 std::string aname = autoload_fcns (k); |
|
1965 |
|
1966 // Check if already in symbol table |
|
1967 sr = fbi_sym_tab->lookup (aname); |
|
1968 |
|
1969 if (!sr) |
|
1970 { |
|
1971 // Must load to get help |
5738
|
1972 sr = lookup_by_name (aname, false); |
5592
|
1973 |
|
1974 std::string h; |
|
1975 if (sr && sr->is_defined ()) |
|
1976 h = sr->help (); |
|
1977 |
|
1978 if (aname.find (txt) != NPOS) |
|
1979 { |
|
1980 if (nargout) |
|
1981 { |
|
1982 ret[0].append (aname); |
|
1983 ret[1].append (first_help_sentence (h)); |
|
1984 } |
|
1985 else |
|
1986 print_lookfor (aname, first_help_sentence (h)); |
|
1987 } |
|
1988 else |
|
1989 { |
|
1990 std::string s; |
|
1991 if (first_sentence_only) |
|
1992 s = first_help_sentence (h); |
|
1993 else |
|
1994 s = h; |
|
1995 |
5768
|
1996 std::transform (s.begin (), s.end (), s.begin (), |
5592
|
1997 tolower); |
|
1998 |
|
1999 if (s.length () > 0 && s.find (txt) != NPOS) |
|
2000 { |
|
2001 if (nargout) |
|
2002 { |
|
2003 ret[0].append (aname); |
|
2004 ret[1].append (first_help_sentence (h)); |
|
2005 } |
|
2006 else |
|
2007 print_lookfor (aname, first_help_sentence (h)); |
|
2008 } |
|
2009 } |
|
2010 } |
5447
|
2011 } |
|
2012 } |
|
2013 } |
|
2014 } |
|
2015 } |
|
2016 |
|
2017 if (nargout != 0) |
|
2018 { |
|
2019 retval (1) = ret[1]; |
|
2020 retval (0) = ret[0]; |
|
2021 } |
|
2022 } |
|
2023 else |
|
2024 { |
|
2025 error ("lookfor: argument must be a string"); |
|
2026 } |
|
2027 |
|
2028 return retval; |
|
2029 } |
|
2030 |
5794
|
2031 DEFUN (info_file, args, nargout, |
|
2032 "-*- texinfo -*-\n\ |
|
2033 @deftypefn {Built-in Function} {@var{val} =} info_file ()\n\ |
|
2034 @deftypefnx {Built-in Function} {@var{old_val} =} info_file (@var{new_val})\n\ |
|
2035 Query or set the internal variable that specifies the name of the\n\ |
|
2036 Octave info file. The default value is\n\ |
|
2037 @code{\"@var{octave-home}/info/octave.info\"}, in\n\ |
|
2038 which @var{octave-home} is the directory where all of Octave is installed.\n\ |
|
2039 @seealso{info_program, doc, help, makeinfo_program}\n\ |
|
2040 @end deftypefn") |
2202
|
2041 { |
5794
|
2042 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_file); |
2202
|
2043 } |
|
2044 |
5794
|
2045 DEFUN (info_program, args, nargout, |
|
2046 "-*- texinfo -*-\n\ |
|
2047 @deftypefn {Built-in Function} {@var{val} =} info_program ()\n\ |
|
2048 @deftypefnx {Built-in Function} {@var{old_val} =} info_program (@var{new_val})\n\ |
|
2049 Query or set the internal variable that specifies the name of the\n\ |
|
2050 info program to run. The default initial value is\n\ |
3686
|
2051 @code{\"@var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}/info\"}\n\ |
|
2052 in which @var{octave-home} is the directory where all of Octave is\n\ |
|
2053 installed, @var{version} is the Octave version number, and @var{arch}\n\ |
|
2054 is the system type (for example, @code{i686-pc-linux-gnu}). The\n\ |
|
2055 default initial value may be overridden by the environment variable\n\ |
|
2056 @code{OCTAVE_INFO_PROGRAM}, or the command line argument\n\ |
5794
|
2057 @code{--info-program NAME}.\n\ |
|
2058 @seealso{info_file, doc, help, makeinfo_program}\n\ |
|
2059 @end deftypefn") |
|
2060 { |
|
2061 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_program); |
|
2062 } |
3686
|
2063 |
5794
|
2064 DEFUN (makeinfo_program, args, nargout, |
|
2065 "-*- texinfo -*-\n\ |
|
2066 @deftypefn {Built-in Function} {@var{val} =} makeinfo_program ()\n\ |
|
2067 @deftypefnx {Built-in Function} {@var{old_val} =} makeinfo_program (@var{new_val})\n\ |
|
2068 Query or set the internal variable that specifies the name of the\n\ |
|
2069 makeinfo program that Octave runs to format help text containing\n\ |
|
2070 Texinfo markup commands. The default initial value is @code{\"makeinfo\"}.\n\ |
|
2071 @seealso{info_file, info_program, doc, help}\n\ |
|
2072 @end deftypefn") |
|
2073 { |
|
2074 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (makeinfo_program); |
|
2075 } |
2202
|
2076 |
5794
|
2077 DEFUN (suppress_verbose_help_message, args, nargout, |
|
2078 "-*- texinfo -*-\n\ |
|
2079 @deftypefn {Built-in Function} {@var{val} =} suppress_verbose_help_message ()\n\ |
|
2080 @deftypefnx {Built-in Function} {@var{old_val} =} suppress_verbose_help_message (@var{new_val})\n\ |
|
2081 Query or set the internal vaiable that controls whether Octave\n\ |
|
2082 will add additional help information to the end of the output from\n\ |
3332
|
2083 the @code{help} command and usage messages for built-in commands.\n\ |
5794
|
2084 @end deftypefn") |
|
2085 { |
|
2086 return SET_INTERNAL_VARIABLE (suppress_verbose_help_message); |
2189
|
2087 } |
|
2088 |
1
|
2089 /* |
|
2090 ;;; Local Variables: *** |
|
2091 ;;; mode: C++ *** |
|
2092 ;;; End: *** |
|
2093 */ |