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