1
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
|
4 2002, 2003, 2004, 2005, 2006, 2007 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
1
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
1
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
1
|
26 #endif |
|
27 |
1343
|
28 #include <cstdlib> |
|
29 #include <cstring> |
|
30 |
5769
|
31 #include <algorithm> |
3503
|
32 #include <iostream> |
|
33 #include <fstream> |
5765
|
34 #include <sstream> |
1755
|
35 #include <string> |
|
36 |
1350
|
37 #ifdef HAVE_UNISTD_H |
2442
|
38 #ifdef HAVE_SYS_TYPES_H |
1295
|
39 #include <sys/types.h> |
2442
|
40 #endif |
1295
|
41 #include <unistd.h> |
|
42 #endif |
1343
|
43 |
3295
|
44 #include "cmd-edit.h" |
|
45 #include "file-ops.h" |
6253
|
46 #include "file-stat.h" |
2926
|
47 #include "oct-env.h" |
1755
|
48 #include "str-vec.h" |
|
49 |
2492
|
50 #include <defaults.h> |
1352
|
51 #include "defun.h" |
|
52 #include "dirfns.h" |
|
53 #include "error.h" |
2202
|
54 #include "gripes.h" |
1352
|
55 #include "help.h" |
2177
|
56 #include "input.h" |
5832
|
57 #include "load-path.h" |
1755
|
58 #include "oct-obj.h" |
2976
|
59 #include "ov-usr-fcn.h" |
1352
|
60 #include "pager.h" |
3018
|
61 #include "parse.h" |
1466
|
62 #include "pathsearch.h" |
3295
|
63 #include "procstream.h" |
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\ |
6138
|
456 \n\ |
|
457 If an error occurs within a try block, then the catch code will be run and\n\ |
|
458 execution will proceed after the catch block (though it is often\n\ |
|
459 recommended to use the lasterr function to re-throw the error after cleanup\n\ |
|
460 is completed).\n\ |
|
461 @seealso{catch,unwind_protect}\n\ |
5818
|
462 @end deffn", }, |
1489
|
463 |
5040
|
464 { "until", |
5818
|
465 "-*- texinfo -*-\n\ |
|
466 @deffn Keyword until\n\ |
|
467 End a do-until loop.\n\ |
|
468 @seealso{do}\n\ |
|
469 @end deffn", }, |
5040
|
470 |
928
|
471 { "unwind_protect", |
5818
|
472 "-*- texinfo -*-\n\ |
|
473 @deffn Keyword unwind_protect\n\ |
|
474 Begin an unwind_protect block.\n\ |
6138
|
475 \n\ |
|
476 If an error occurs within the first part of an unwind_protect block\n\ |
|
477 the commands within the unwind_protect_cleanup block are executed before\n\ |
|
478 the error is thrown. If an error is not thrown, then the\n\ |
|
479 unwind_protect_cleanup block is still executed (in other words, the\n\ |
|
480 unwind_protect_cleanup will be run with or without an error in the\n\ |
|
481 unwind_protect block).\n\ |
|
482 @seealso{unwind_protect_cleanup,try}\n\ |
5818
|
483 @end deffn", }, |
928
|
484 |
|
485 { "unwind_protect_cleanup", |
5818
|
486 "-*- texinfo -*-\n\ |
|
487 @deffn Keyword unwind_protect_cleanup\n\ |
|
488 Begin the cleanup section of an unwind_protect block.\n\ |
|
489 @seealso{unwind_protect}\n\ |
|
490 @end deffn", }, |
1
|
491 |
5040
|
492 { "varargin", |
5818
|
493 "-*- texinfo -*-\n\ |
|
494 @deffn Keyword varargin\n\ |
|
495 Pass an arbitrary number of arguments into a function.\n\ |
|
496 @seealso{varargout, nargin, nargout}\n\ |
|
497 @end deffn", }, |
5040
|
498 |
|
499 { "varargout", |
5818
|
500 "-*- texinfo -*-\n\ |
|
501 @deffn Keyword varargout\n\ |
|
502 Pass an arbitrary number of arguments out of a function.\n\ |
|
503 @seealso{varargin, nargin, nargout}\n\ |
|
504 @end deffn", }, |
5040
|
505 |
1
|
506 { "while", |
5818
|
507 "-*- texinfo -*-\n\ |
|
508 @deffn Keyword while\n\ |
|
509 Begin a while loop.\n\ |
|
510 @seealso{do}\n\ |
|
511 @end deffn", }, |
1
|
512 |
529
|
513 { 0, 0, }, |
1
|
514 }; |
|
515 |
581
|
516 // Return a copy of the operator or keyword names. |
|
517 |
3016
|
518 static string_vector |
3355
|
519 names (help_list *lst) |
1
|
520 { |
1755
|
521 string_vector retval; |
|
522 |
3355
|
523 int count = 0; |
1
|
524 help_list *ptr = lst; |
529
|
525 while (ptr->name) |
1
|
526 { |
|
527 count++; |
|
528 ptr++; |
|
529 } |
|
530 |
1755
|
531 if (count > 0) |
|
532 { |
|
533 retval.resize (count); |
1
|
534 |
1755
|
535 ptr = lst; |
|
536 for (int i = 0; i < count; i++) |
|
537 { |
|
538 retval[i] = ptr->name; |
|
539 ptr++; |
|
540 } |
1
|
541 } |
|
542 |
1755
|
543 return retval; |
1
|
544 } |
|
545 |
3014
|
546 static help_list * |
1
|
547 operator_help (void) |
|
548 { |
|
549 return operators; |
|
550 } |
|
551 |
3016
|
552 static help_list * |
1
|
553 keyword_help (void) |
|
554 { |
|
555 return keywords; |
|
556 } |
|
557 |
5775
|
558 // It's not likely that this does the right thing now. FIXME |
3016
|
559 |
|
560 string_vector |
|
561 make_name_list (void) |
|
562 { |
3355
|
563 string_vector key = names (keyword_help ()); |
|
564 int key_len = key.length (); |
3016
|
565 |
4009
|
566 string_vector fbi = fbi_sym_tab->name_list (); |
|
567 int fbi_len = fbi.length (); |
|
568 |
3355
|
569 string_vector glb = global_sym_tab->name_list (); |
|
570 int glb_len = glb.length (); |
3016
|
571 |
3355
|
572 string_vector top = top_level_sym_tab->name_list (); |
|
573 int top_len = top.length (); |
3016
|
574 |
3355
|
575 string_vector lcl; |
3016
|
576 if (top_level_sym_tab != curr_sym_tab) |
3355
|
577 lcl = curr_sym_tab->name_list (); |
|
578 int lcl_len = lcl.length (); |
3016
|
579 |
5832
|
580 string_vector ffl = load_path::fcn_names (); |
3016
|
581 int ffl_len = ffl.length (); |
|
582 |
5592
|
583 string_vector afl = autoloaded_functions (); |
|
584 int afl_len = afl.length (); |
|
585 |
|
586 int total_len = key_len + fbi_len + glb_len + top_len + lcl_len + ffl_len + afl_len; |
3016
|
587 |
|
588 string_vector list (total_len); |
|
589 |
|
590 // Put all the symbols in one big list. |
|
591 |
|
592 int j = 0; |
|
593 int i = 0; |
|
594 for (i = 0; i < key_len; i++) |
|
595 list[j++] = key[i]; |
|
596 |
4009
|
597 for (i = 0; i < fbi_len; i++) |
|
598 list[j++] = fbi[i]; |
|
599 |
3016
|
600 for (i = 0; i < glb_len; i++) |
|
601 list[j++] = glb[i]; |
|
602 |
|
603 for (i = 0; i < top_len; i++) |
|
604 list[j++] = top[i]; |
|
605 |
|
606 for (i = 0; i < lcl_len; i++) |
|
607 list[j++] = lcl[i]; |
|
608 |
|
609 for (i = 0; i < ffl_len; i++) |
|
610 list[j++] = ffl[i]; |
|
611 |
5592
|
612 for (i = 0; i < afl_len; i++) |
|
613 list[j++] = afl[i]; |
|
614 |
3016
|
615 return list; |
|
616 } |
|
617 |
3014
|
618 void |
3523
|
619 additional_help_message (std::ostream& os) |
2470
|
620 { |
|
621 if (! Vsuppress_verbose_help_message) |
5641
|
622 os << "\ |
5794
|
623 Additional help for built-in functions and operators is\n\ |
|
624 available in the on-line version of the manual. Use the command\n\ |
5672
|
625 `doc <topic>' to search the manual index.\n\ |
3295
|
626 \n\ |
3160
|
627 Help and information about Octave is also available on the WWW\n\ |
5041
|
628 at http://www.octave.org and via the help@octave.org\n\ |
3917
|
629 mailing list.\n"; |
3160
|
630 } |
|
631 |
5775
|
632 // FIXME -- this needs a major overhaul to cope with new |
2976
|
633 // symbol table stuff. |
|
634 |
529
|
635 static void |
3523
|
636 display_names_from_help_list (std::ostream& os, help_list *list, |
542
|
637 const char *desc) |
529
|
638 { |
3355
|
639 string_vector symbols = names (list); |
3259
|
640 |
1808
|
641 if (! symbols.empty ()) |
|
642 { |
2095
|
643 os << "\n*** " << desc << ":\n\n"; |
3259
|
644 |
|
645 symbols.qsort (); |
|
646 |
2095
|
647 symbols.list_in_columns (os); |
1808
|
648 } |
529
|
649 } |
|
650 |
|
651 static void |
3523
|
652 display_symtab_names (std::ostream& os, const string_vector& names, |
|
653 const std::string& desc) |
542
|
654 { |
1808
|
655 if (! names.empty ()) |
|
656 { |
2095
|
657 os << "\n*** " << desc << ":\n\n"; |
|
658 names.list_in_columns (os); |
1808
|
659 } |
542
|
660 } |
|
661 |
|
662 #ifdef LIST_SYMBOLS |
|
663 #undef LIST_SYMBOLS |
|
664 #endif |
|
665 #define LIST_SYMBOLS(type, msg) \ |
|
666 do \ |
|
667 { \ |
3259
|
668 string_vector names \ |
4009
|
669 = fbi_sym_tab->name_list (string_vector (), true, type); \ |
3355
|
670 display_symtab_names (octave_stdout, names, msg); \ |
542
|
671 } \ |
|
672 while (0) |
529
|
673 |
3014
|
674 static void |
|
675 simple_help (void) |
|
676 { |
3160
|
677 octave_stdout << "Help is available for the topics listed below.\n"; |
|
678 |
|
679 additional_help_message (octave_stdout); |
|
680 |
3014
|
681 display_names_from_help_list (octave_stdout, operator_help (), |
|
682 "operators"); |
|
683 |
|
684 display_names_from_help_list (octave_stdout, keyword_help (), |
|
685 "reserved words"); |
|
686 |
5775
|
687 // FIXME -- is this distinction needed? |
1358
|
688 |
4208
|
689 LIST_SYMBOLS (symbol_record::COMMAND, "commands"); |
529
|
690 |
3010
|
691 LIST_SYMBOLS (symbol_record::MAPPER_FUNCTION, "mapper functions"); |
542
|
692 |
3010
|
693 LIST_SYMBOLS (symbol_record::BUILTIN_FUNCTION, "general functions"); |
542
|
694 |
1358
|
695 // Also need to list variables and currently compiled functions from |
|
696 // the symbol table, if there are any. |
529
|
697 |
1358
|
698 // Also need to search octave_path for script files. |
529
|
699 |
5832
|
700 load_path::display (octave_stdout); |
5592
|
701 |
|
702 string_vector autoloaded = autoloaded_functions (); |
|
703 |
|
704 if (! autoloaded.empty ()) |
|
705 { |
|
706 octave_stdout << "\n*** autoloaded functions:\n\n"; |
|
707 |
|
708 autoloaded.qsort (); |
|
709 |
|
710 autoloaded.list_in_columns (octave_stdout); |
|
711 } |
529
|
712 } |
|
713 |
|
714 static int |
3523
|
715 try_info (const std::string& nm) |
529
|
716 { |
5672
|
717 int retval = -1; |
1295
|
718 |
5672
|
719 warning ("please use `doc' instead of `help -i'"); |
529
|
720 |
5672
|
721 octave_value_list args; |
|
722 args(0) = nm; |
|
723 octave_value_list result = feval ("doc", args, 1); |
4051
|
724 |
5672
|
725 if (result.length () > 0) |
|
726 retval = result(0).int_value (); |
529
|
727 |
5672
|
728 return retval; |
529
|
729 } |
1140
|
730 |
|
731 static void |
1755
|
732 help_from_info (const string_vector& argv, int idx, int argc) |
1140
|
733 { |
1755
|
734 if (idx == argc) |
3523
|
735 try_info (std::string ()); |
1140
|
736 else |
|
737 { |
1755
|
738 for (int i = idx; i < argc; i++) |
1140
|
739 { |
1755
|
740 int status = try_info (argv[i]); |
1140
|
741 |
5672
|
742 if (status == 127) |
|
743 break; |
|
744 else if (status != 0) |
|
745 message ("help", "`%s' is not indexed in the manual", |
|
746 argv[i].c_str ()); |
1140
|
747 } |
|
748 } |
2470
|
749 } |
3014
|
750 |
|
751 static bool |
3523
|
752 looks_like_texinfo (const std::string& msg, size_t& p1) |
3295
|
753 { |
|
754 p1 = msg.find ('\n'); |
|
755 |
3523
|
756 std::string t = msg.substr (0, p1); |
3295
|
757 |
|
758 if (p1 == NPOS) |
|
759 p1 = 0; |
|
760 |
|
761 size_t p2 = t.find ("-*- texinfo -*-"); |
|
762 |
|
763 return (p2 != NPOS); |
|
764 } |
|
765 |
3330
|
766 void |
3523
|
767 display_help_text (std::ostream& os, const std::string& msg) |
3295
|
768 { |
|
769 // Look for "-*- texinfo -*-" in first line of help message. If it |
|
770 // is present, use makeinfo to format the rest of the message before |
|
771 // sending it to the output stream. Otherwise, just print the |
|
772 // message. |
|
773 |
|
774 size_t pos; |
|
775 |
|
776 if (looks_like_texinfo (msg, pos)) |
|
777 { |
5594
|
778 os.flush (); |
|
779 |
3523
|
780 std::string tmp_file_name = file_ops::tempnam ("", ""); |
3295
|
781 |
|
782 int cols = command_editor::terminal_cols (); |
|
783 |
|
784 if (cols > 16) |
|
785 cols--; |
|
786 |
|
787 if (cols > 64) |
|
788 cols -= 7; |
|
789 |
|
790 if (cols > 80) |
|
791 cols = 72; |
|
792 |
5765
|
793 std::ostringstream buf; |
4051
|
794 |
6099
|
795 // Use double quotes to quote the sed patterns for Windows. |
|
796 |
|
797 buf << "sed -e \"s/^[#%][#%]* *//\" -e \"s/^ *@/@/\" | " |
5794
|
798 << "\"" << Vmakeinfo_program << "\"" |
3303
|
799 << " -D \"VERSION " << OCTAVE_VERSION << "\"" |
|
800 << " -D \"OCTAVEHOME " << OCTAVE_PREFIX << "\"" |
3584
|
801 << " -D \"TARGETHOSTTYPE " << OCTAVE_CANONICAL_HOST_TYPE << "\"" |
3301
|
802 << " --fill-column " << cols |
|
803 << " --no-warn" |
|
804 << " --no-validate" |
|
805 << " --no-headers" |
|
806 << " --force" |
5765
|
807 << " --output \"" << tmp_file_name << "\""; |
3295
|
808 |
5765
|
809 oprocstream filter (buf.str ()); |
3295
|
810 |
3686
|
811 if (filter && filter.is_open ()) |
3295
|
812 { |
3405
|
813 filter << "@macro seealso {args}\n" |
5644
|
814 << "@sp 1\n" |
3408
|
815 << "@noindent\n" |
3405
|
816 << "See also: \\args\\.\n" |
|
817 << "@end macro\n"; |
|
818 |
3769
|
819 filter << msg.substr (pos+1) << std::endl; |
3295
|
820 |
3686
|
821 int status = filter.close (); |
3295
|
822 |
3523
|
823 std::ifstream tmp_file (tmp_file_name.c_str ()); |
3295
|
824 |
3686
|
825 if (WIFEXITED (status) && WEXITSTATUS (status) == 0) |
|
826 { |
|
827 int c; |
|
828 while ((c = tmp_file.get ()) != EOF) |
|
829 os << (char) c; |
3295
|
830 |
3686
|
831 tmp_file.close (); |
|
832 } |
|
833 else |
|
834 { |
|
835 warning ("help: Texinfo formatting filter exited abnormally"); |
|
836 warning ("help: raw Texinfo source of help text follows..."); |
5594
|
837 warning ("help:\n\n%s\n\n", msg.c_str ()); |
3686
|
838 } |
3295
|
839 |
|
840 file_ops::unlink (tmp_file_name); |
|
841 } |
|
842 else |
|
843 os << msg; |
|
844 } |
|
845 else |
|
846 os << msg; |
|
847 } |
|
848 |
5800
|
849 void |
|
850 display_usage_text (std::ostream& os, const std::string& msg) |
|
851 { |
|
852 std::string filtered_msg = msg; |
|
853 |
|
854 size_t pos; |
|
855 |
|
856 if (looks_like_texinfo (msg, pos)) |
|
857 { |
|
858 std::ostringstream buf; |
|
859 |
|
860 buf << "-*- texinfo -*-\n"; |
|
861 |
|
862 bool found_def = false; |
|
863 |
|
864 size_t msg_len = msg.length (); |
|
865 |
|
866 while (pos < msg_len) |
|
867 { |
|
868 size_t new_pos = msg.find_first_of ('\n', pos); |
|
869 |
|
870 if (new_pos == NPOS) |
|
871 new_pos = msg_len-1; |
|
872 |
|
873 std::string line = msg.substr (pos, new_pos-pos+1); |
|
874 |
|
875 if (line.substr (0, 4) == "@def" |
|
876 || line.substr (0, 8) == "@end def") |
|
877 { |
|
878 found_def = true; |
|
879 buf << line; |
|
880 } |
|
881 |
|
882 pos = new_pos + 1; |
|
883 } |
|
884 |
|
885 if (found_def) |
|
886 filtered_msg = buf.str (); |
|
887 } |
|
888 |
|
889 display_help_text (os, filtered_msg); |
|
890 } |
|
891 |
3295
|
892 static bool |
6243
|
893 raw_help_from_list (const help_list *list, const std::string& nm, |
|
894 std::string& h, bool& symbol_found) |
542
|
895 { |
5399
|
896 bool retval = false; |
|
897 |
2804
|
898 const char *name; |
3014
|
899 |
542
|
900 while ((name = list->name) != 0) |
|
901 { |
1755
|
902 if (strcmp (name, nm.c_str ()) == 0) |
542
|
903 { |
5399
|
904 symbol_found = true; |
|
905 |
6243
|
906 h = list->help; |
5399
|
907 |
|
908 if (h.length () > 0) |
6243
|
909 retval = true; |
5399
|
910 |
|
911 break; |
542
|
912 } |
|
913 list++; |
|
914 } |
3014
|
915 |
5399
|
916 return retval;; |
|
917 } |
|
918 |
6243
|
919 static bool |
|
920 help_from_list (std::ostream& os, const help_list *list, |
|
921 const std::string& nm, int usage, bool& symbol_found) |
|
922 { |
|
923 bool retval = false; |
|
924 |
|
925 std::string h; |
|
926 |
|
927 if (raw_help_from_list (list, nm, h, symbol_found)) |
|
928 { |
|
929 if (h.length () > 0) |
|
930 { |
|
931 if (usage) |
|
932 os << "\nusage: "; |
|
933 else |
|
934 os << "\n*** " << nm << ":\n\n"; |
|
935 |
|
936 display_help_text (os, h); |
|
937 |
|
938 os << "\n"; |
|
939 |
|
940 retval = true; |
|
941 } |
|
942 } |
|
943 |
|
944 return retval; |
|
945 } |
|
946 |
5399
|
947 std::string |
|
948 extract_help_from_dispatch (const std::string& nm) |
|
949 { |
|
950 std::string retval; |
|
951 |
|
952 symbol_record *builtin = fbi_sym_tab->lookup ("builtin:" + nm, 0); |
|
953 |
|
954 if (builtin) |
|
955 { |
|
956 // Check that builtin is up to date. |
|
957 |
|
958 // Don't try to fight octave's function name handling |
|
959 // mechanism. Instead, move dispatch record out of the way, |
|
960 // and restore the builtin to its original name. |
|
961 symbol_record *dispatch = fbi_sym_tab->lookup (nm, 0); |
|
962 |
|
963 if (dispatch) |
|
964 { |
|
965 dispatch->unprotect (); |
|
966 |
|
967 fbi_sym_tab->rename (nm, "dispatch:" + nm); |
|
968 fbi_sym_tab->rename ("builtin:" + nm, nm); |
|
969 |
|
970 // Check for updates to builtin function; ignore errors |
|
971 // that appear (they interfere with renaming), and remove |
5775
|
972 // the updated name from the current symbol table. FIXME -- |
|
973 // check that updating a function updates it in all |
|
974 // contexts. It may be that it is updated only in the |
5399
|
975 // current symbol table, and not the caller. I believe this |
|
976 // won't be a problem because the caller will go through the |
|
977 // same logic and end up with the newer version. |
|
978 |
|
979 octave_function *f = is_valid_function (nm); |
|
980 |
|
981 if (f) |
|
982 retval = builtin->help (); |
|
983 |
|
984 curr_sym_tab->clear_function (nm); |
|
985 |
|
986 // Move the builtin function out of the way and restore the |
5775
|
987 // dispatch fuction. FIXME what if builtin wants to |
5399
|
988 // protect itself? |
|
989 |
|
990 fbi_sym_tab->rename (nm, "builtin:" + nm); |
|
991 fbi_sym_tab->rename ("dispatch:" + nm, nm); |
|
992 |
|
993 dispatch->protect (); |
|
994 } |
|
995 else |
|
996 error ("failed to find dispatch record for `builtin:%s'", nm.c_str ()); |
|
997 } |
|
998 |
|
999 return retval; |
542
|
1000 } |
|
1001 |
3355
|
1002 static bool |
6243
|
1003 raw_help_from_symbol_table (const std::string& nm, std::string& h, |
|
1004 std::string& w, bool& symbol_found) |
3355
|
1005 { |
|
1006 bool retval = false; |
|
1007 |
|
1008 symbol_record *sym_rec = lookup_by_name (nm, 0); |
|
1009 |
|
1010 if (sym_rec && sym_rec->is_defined ()) |
|
1011 { |
5399
|
1012 symbol_found = true; |
|
1013 |
6243
|
1014 h = sym_rec->help (); |
|
1015 |
|
1016 if (h.length () > 0) |
|
1017 { |
|
1018 w = sym_rec->which (); |
|
1019 |
|
1020 retval = true; |
|
1021 } |
|
1022 } |
3355
|
1023 |
6243
|
1024 return retval; |
|
1025 } |
|
1026 |
|
1027 static bool |
|
1028 help_from_symbol_table (std::ostream& os, const std::string& nm, |
|
1029 bool& symbol_found) |
|
1030 { |
|
1031 bool retval = false; |
|
1032 |
|
1033 std::string h; |
|
1034 std::string w; |
|
1035 |
|
1036 if (raw_help_from_symbol_table (nm, h, w, symbol_found)) |
|
1037 { |
3355
|
1038 if (h.length () > 0) |
|
1039 { |
5399
|
1040 h = extract_help_from_dispatch (nm) + h; |
6243
|
1041 |
3355
|
1042 display_help_text (os, h); |
6243
|
1043 |
|
1044 if (w.length () > 0 && ! Vsuppress_verbose_help_message) |
|
1045 os << w << "\n"; |
|
1046 |
3355
|
1047 os << "\n"; |
6243
|
1048 |
3355
|
1049 retval = true; |
|
1050 } |
|
1051 } |
|
1052 |
|
1053 return retval; |
|
1054 } |
|
1055 |
|
1056 static bool |
6243
|
1057 raw_help_from_file (const std::string& nm, std::string& h, |
|
1058 std::string& file, bool& symbol_found) |
|
1059 { |
|
1060 bool retval = false; |
|
1061 |
|
1062 h = get_help_from_file (nm, symbol_found, file); |
|
1063 |
|
1064 if (h.length () > 0) |
|
1065 retval = true; |
|
1066 |
|
1067 return retval; |
|
1068 } |
|
1069 |
|
1070 static bool |
5399
|
1071 help_from_file (std::ostream& os, const std::string& nm, bool& symbol_found) |
3355
|
1072 { |
|
1073 bool retval = false; |
|
1074 |
6243
|
1075 std::string h; |
5931
|
1076 std::string file; |
|
1077 |
6243
|
1078 if (raw_help_from_file (nm, h, file, symbol_found)) |
5484
|
1079 { |
6243
|
1080 if (h.length () > 0) |
|
1081 { |
6253
|
1082 // Strip extension |
|
1083 size_t l = file.length (); |
|
1084 if (l > 2 && file.substr (l-2) == ".m") |
|
1085 { |
|
1086 std::string tmp = file.substr (0, l - 2); |
|
1087 |
|
1088 if (file_stat (tmp + ".oct")) |
|
1089 file = tmp + ".oct"; |
|
1090 else if (file_stat (tmp + ".mex")) |
|
1091 file = tmp + ".mex"; |
|
1092 } |
|
1093 |
6243
|
1094 os << nm << " is the file " << file << "\n\n"; |
|
1095 |
|
1096 display_help_text (os, h); |
|
1097 |
|
1098 os << "\n"; |
|
1099 |
|
1100 retval = true; |
|
1101 } |
3355
|
1102 } |
|
1103 |
|
1104 return retval; |
|
1105 } |
|
1106 |
6243
|
1107 std::string |
|
1108 raw_help (const std::string& nm, bool &symbol_found) |
|
1109 { |
|
1110 std::string h; |
|
1111 std::string w; |
|
1112 std::string f; |
|
1113 |
|
1114 (raw_help_from_list (operator_help (), nm, h, symbol_found) |
|
1115 || raw_help_from_list (keyword_help (), nm, h, symbol_found) |
|
1116 || raw_help_from_symbol_table (nm, h, w, symbol_found) |
|
1117 || raw_help_from_file (nm, h, f, symbol_found)); |
|
1118 |
|
1119 return h; |
|
1120 } |
|
1121 |
1140
|
1122 static void |
1755
|
1123 builtin_help (int argc, const string_vector& argv) |
1140
|
1124 { |
|
1125 help_list *op_help_list = operator_help (); |
|
1126 help_list *kw_help_list = keyword_help (); |
|
1127 |
1755
|
1128 for (int i = 1; i < argc; i++) |
1140
|
1129 { |
5399
|
1130 bool symbol_found = false; |
|
1131 |
|
1132 if (help_from_list (octave_stdout, op_help_list, argv[i], 0, |
|
1133 symbol_found)) |
1140
|
1134 continue; |
|
1135 |
5399
|
1136 if (help_from_list (octave_stdout, kw_help_list, argv[i], 0, |
|
1137 symbol_found)) |
1140
|
1138 continue; |
|
1139 |
5399
|
1140 if (help_from_symbol_table (octave_stdout, argv[i], symbol_found)) |
|
1141 continue; |
|
1142 |
|
1143 if (help_from_file (octave_stdout, argv[i], symbol_found)) |
3355
|
1144 continue; |
1755
|
1145 |
5399
|
1146 if (symbol_found) |
|
1147 octave_stdout << "\nhelp: `" << argv[i] |
|
1148 << "' is not documented\n"; |
|
1149 else |
|
1150 octave_stdout << "\nhelp: `" << argv[i] |
|
1151 << "' not found\n"; |
1140
|
1152 } |
|
1153 |
2095
|
1154 additional_help_message (octave_stdout); |
1140
|
1155 } |
|
1156 |
4208
|
1157 DEFCMD (help, args, , |
3332
|
1158 "-*- texinfo -*-\n\ |
6615
|
1159 @deffn {Command} help @var{name}\n\ |
|
1160 Display the help text for @var{name}.\n\ |
|
1161 If invoked without any arguments, @code{help} prints a list\n\ |
|
1162 of all the available operators and functions.\n\ |
3168
|
1163 \n\ |
3332
|
1164 For example, the command @kbd{help help} prints a short message\n\ |
6615
|
1165 describing the @code{help} command.\n\ |
3332
|
1166 \n\ |
6615
|
1167 The help command can give you information about operators, but not the\n\ |
|
1168 comma and semicolons that are used as command separators. To get help\n\ |
|
1169 for those, you must type @kbd{help comma} or @kbd{help semicolon}.\n\ |
5672
|
1170 @seealso{doc, which, lookfor}\n\ |
3333
|
1171 @end deffn") |
529
|
1172 { |
2086
|
1173 octave_value_list retval; |
529
|
1174 |
1755
|
1175 int argc = args.length () + 1; |
|
1176 |
1968
|
1177 string_vector argv = args.make_argv ("help"); |
1755
|
1178 |
|
1179 if (error_state) |
|
1180 return retval; |
529
|
1181 |
|
1182 if (argc == 1) |
3014
|
1183 simple_help (); |
529
|
1184 else |
|
1185 { |
1755
|
1186 if (argv[1] == "-i") |
3014
|
1187 help_from_info (argv, 2, argc); |
529
|
1188 else |
3014
|
1189 builtin_help (argc, argv); |
529
|
1190 } |
|
1191 |
|
1192 return retval; |
|
1193 } |
|
1194 |
3355
|
1195 static void |
3523
|
1196 do_type (std::ostream& os, const std::string& name, bool pr_type_info, |
3355
|
1197 bool quiet, bool pr_orig_txt) |
|
1198 { |
|
1199 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1200 |
|
1201 if (sym_rec && sym_rec->is_defined ()) |
3356
|
1202 sym_rec->type (os, pr_type_info, quiet, pr_orig_txt); |
3355
|
1203 else |
|
1204 { |
3523
|
1205 std::string ff = fcn_file_in_path (name); |
3355
|
1206 |
|
1207 if (! ff.empty ()) |
|
1208 { |
3538
|
1209 std::ifstream fs (ff.c_str (), std::ios::in); |
3355
|
1210 |
|
1211 if (fs) |
|
1212 { |
|
1213 if (pr_type_info && ! quiet) |
|
1214 os << name << " is the script file: " << ff << "\n\n"; |
|
1215 |
|
1216 char ch; |
|
1217 |
|
1218 while (fs.get (ch)) |
|
1219 os << ch; |
|
1220 } |
|
1221 else |
|
1222 os << "unable to open `" << ff << "' for reading!\n"; |
|
1223 } |
|
1224 else |
|
1225 error ("type: `%s' undefined", name.c_str ()); |
|
1226 } |
|
1227 } |
|
1228 |
4208
|
1229 DEFCMD (type, args, nargout, |
3361
|
1230 "-*- texinfo -*-\n\ |
|
1231 \n\ |
|
1232 @deffn {Command} type options name @dots{}\n\ |
|
1233 Display the definition of each @var{name} that refers to a function.\n\ |
|
1234 \n\ |
6620
|
1235 Normally also displays whether each @var{name} is user-defined or built-in;\n\ |
3361
|
1236 the @code{-q} option suppresses this behaviour.\n\ |
|
1237 @end deffn") |
581
|
1238 { |
3584
|
1239 octave_value retval; |
1588
|
1240 |
1755
|
1241 int argc = args.length () + 1; |
|
1242 |
1968
|
1243 string_vector argv = args.make_argv ("type"); |
1755
|
1244 |
3355
|
1245 if (! error_state) |
581
|
1246 { |
3355
|
1247 if (argc > 1) |
|
1248 { |
5775
|
1249 // FIXME -- we should really use getopt () |
2532
|
1250 |
3355
|
1251 bool quiet = false; |
|
1252 bool pr_orig_txt = true; |
2532
|
1253 |
3355
|
1254 int idx; |
581
|
1255 |
3355
|
1256 for (idx = 1; idx < argc; idx++) |
1281
|
1257 { |
3355
|
1258 if (argv[idx] == "-q" || argv[idx] == "-quiet") |
|
1259 quiet = true; |
|
1260 else if (argv[idx] == "-t" || argv[idx] == "-transformed") |
|
1261 pr_orig_txt = false; |
|
1262 else |
|
1263 break; |
1281
|
1264 } |
|
1265 |
3355
|
1266 if (idx < argc) |
|
1267 { |
5765
|
1268 std::ostringstream output_buf; |
581
|
1269 |
3355
|
1270 for (int i = idx; i < argc; i++) |
581
|
1271 { |
3523
|
1272 std::string id = argv[i]; |
2534
|
1273 |
3355
|
1274 if (nargout == 0) |
|
1275 do_type (octave_stdout, id, true, quiet, pr_orig_txt); |
|
1276 else |
|
1277 do_type (output_buf, id, false, quiet, pr_orig_txt); |
581
|
1278 |
3355
|
1279 if (error_state) |
|
1280 goto abort; |
581
|
1281 } |
|
1282 |
3584
|
1283 if (nargout != 0) |
5765
|
1284 retval = output_buf.str (); |
581
|
1285 } |
|
1286 else |
5823
|
1287 print_usage (); |
3355
|
1288 } |
|
1289 else |
5823
|
1290 print_usage (); |
3355
|
1291 } |
3141
|
1292 |
3355
|
1293 abort: |
581
|
1294 |
|
1295 return retval; |
|
1296 } |
|
1297 |
3536
|
1298 static std::string |
3523
|
1299 do_which (const std::string& name) |
3355
|
1300 { |
3523
|
1301 std::string retval; |
3355
|
1302 |
|
1303 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1304 |
|
1305 if (sym_rec && sym_rec->is_defined ()) |
|
1306 retval = sym_rec->which (); |
|
1307 else |
6348
|
1308 retval = fcn_file_in_path (name); |
3355
|
1309 |
|
1310 return retval; |
|
1311 } |
|
1312 |
|
1313 static void |
3523
|
1314 do_which (std::ostream& os, const std::string& name) |
3355
|
1315 { |
|
1316 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1317 |
|
1318 if (sym_rec && sym_rec->is_defined ()) |
|
1319 sym_rec->which (os); |
|
1320 else |
|
1321 { |
3523
|
1322 std::string path = fcn_file_in_path (name); |
3355
|
1323 |
|
1324 if (! path.empty ()) |
|
1325 os << "which: `" << name << "' is the script file\n" |
|
1326 << path << "\n"; |
|
1327 else |
|
1328 os << "which: `" << name << "' is undefined\n"; |
|
1329 } |
|
1330 } |
|
1331 |
4208
|
1332 DEFCMD (which, args, nargout, |
3361
|
1333 "-*- texinfo -*-\n\ |
|
1334 @deffn {Command} which name @dots{}\n\ |
|
1335 Display the type of each @var{name}. If @var{name} is defined from a\n\ |
|
1336 function file, the full name of the file is also displayed.\n\ |
5667
|
1337 @seealso{help, lookfor}\n\ |
3361
|
1338 @end deffn") |
581
|
1339 { |
2086
|
1340 octave_value_list retval; |
581
|
1341 |
1968
|
1342 string_vector argv = args.make_argv ("which"); |
1755
|
1343 |
3355
|
1344 if (! error_state) |
|
1345 { |
|
1346 int argc = argv.length (); |
581
|
1347 |
|
1348 if (nargout > 0) |
|
1349 retval.resize (argc-1, Matrix ()); |
|
1350 |
3355
|
1351 if (argc > 1) |
581
|
1352 { |
3355
|
1353 for (int i = 1; i < argc; i++) |
581
|
1354 { |
3523
|
1355 std::string id = argv[i]; |
3141
|
1356 |
3355
|
1357 if (nargout == 0) |
|
1358 do_which (octave_stdout, id); |
581
|
1359 else |
3355
|
1360 retval(i-1) = do_which (id); |
581
|
1361 } |
|
1362 } |
3355
|
1363 else |
5823
|
1364 print_usage (); |
581
|
1365 } |
|
1366 |
|
1367 return retval; |
|
1368 } |
|
1369 |
5775
|
1370 // FIXME |
5447
|
1371 // This function attempts to find the first sentence of a help string, though |
|
1372 // given that the user can create the help in an arbitrary format, your |
|
1373 // success might vary.. it works much better with help string formated in |
|
1374 // texinfo. Using regex might make this function much simpler. |
|
1375 |
|
1376 std::string |
|
1377 first_help_sentence (const std::string& h, bool short_sentence = true) |
|
1378 { |
5738
|
1379 std::string retval; |
|
1380 |
5447
|
1381 size_t pos = 0; |
|
1382 |
|
1383 if (looks_like_texinfo (h, pos)) |
5592
|
1384 { |
|
1385 // Get the parsed help string. |
5447
|
1386 pos = 0; |
5765
|
1387 std::ostringstream os; |
5447
|
1388 display_help_text (os, h); |
|
1389 std::string h2 = os.str (); |
|
1390 |
|
1391 while (1) |
|
1392 { |
|
1393 // Skip leading whitespace and get new line |
|
1394 pos = h2.find_first_not_of ("\n\t ", pos); |
|
1395 |
|
1396 if (pos == NPOS) |
|
1397 break; |
|
1398 |
|
1399 size_t new_pos = h2.find_first_of ('\n', pos); |
|
1400 std::string line = h2.substr (pos, new_pos-pos); |
|
1401 |
|
1402 // Skip lines starting in "-" |
|
1403 if (line.find_first_of ('-') == 0) |
|
1404 { |
|
1405 pos = new_pos + 1; |
|
1406 continue; |
|
1407 } |
|
1408 |
|
1409 break; |
|
1410 } |
|
1411 |
|
1412 if (pos == NPOS) |
5738
|
1413 return retval; |
5447
|
1414 |
|
1415 // At start of real text. Get first line with the sentence |
|
1416 size_t new_pos = h2.find_first_of ('\n', pos); |
|
1417 std::string line = h2.substr (pos, new_pos-pos); |
|
1418 size_t dot_pos; |
|
1419 |
|
1420 while ((dot_pos = line.find_first_of ('.')) == NPOS) |
|
1421 { |
|
1422 // Trim trailing blanks on line |
|
1423 line.substr (0, line.find_last_not_of ("\n\t ") + 1); |
|
1424 |
|
1425 // Append next line |
|
1426 size_t tmp_pos = h2.find_first_not_of ("\n\t ", new_pos + 1); |
|
1427 if (tmp_pos == NPOS || h2.substr (tmp_pos, 1) == "\n") |
|
1428 break; |
|
1429 |
|
1430 new_pos = h2.find_first_of ('\n', tmp_pos); |
|
1431 std::string next = h2.substr (tmp_pos, new_pos-tmp_pos); |
|
1432 |
|
1433 if (short_sentence) |
|
1434 { |
|
1435 if ((tmp_pos = next.find_first_of ('.')) != NPOS) |
|
1436 { |
|
1437 line = line + " " + next; |
|
1438 dot_pos = line.find_first_of ('.'); |
|
1439 } |
|
1440 break; |
|
1441 } |
|
1442 else |
|
1443 line = line + " " + next; |
|
1444 } |
|
1445 |
|
1446 if (dot_pos == NPOS) |
5738
|
1447 retval = line; |
5447
|
1448 else |
5738
|
1449 retval = line.substr (0, dot_pos + 1); |
5447
|
1450 } |
|
1451 else |
|
1452 { |
|
1453 std::string _upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
1454 std::string _lower = "abcdefghijklmnopqrstuvwxyz"; |
|
1455 std::string _alpha = _upper + _lower + "_"; |
|
1456 std::string _alphanum = _alpha + "1234567890"; |
|
1457 pos = 0; |
|
1458 |
|
1459 while (1) |
|
1460 { |
|
1461 // Skip leading whitespace and get new line |
|
1462 pos = h.find_first_not_of ("\n\t ", pos); |
|
1463 |
|
1464 if (pos == NPOS) |
|
1465 break; |
|
1466 |
|
1467 size_t new_pos = h.find_first_of ('\n', pos); |
|
1468 std::string line = h.substr (pos, new_pos-pos); |
|
1469 |
|
1470 // Make a lower case copy to simplify some tests |
|
1471 std::string lower = line; |
5768
|
1472 std::transform (lower.begin (), lower.end (), lower.begin (), tolower); |
5447
|
1473 |
|
1474 // Skip lines starting in "-" or "Usage" |
|
1475 if (lower.find_first_of ('-') == 0 |
|
1476 || lower.substr (0, 5) == "usage") |
|
1477 { |
5592
|
1478 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1479 continue; |
|
1480 } |
|
1481 |
|
1482 size_t line_pos = 0; |
|
1483 size_t tmp_pos = 0; |
|
1484 |
|
1485 // chop " blah : " |
|
1486 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1487 (_alphanum, line_pos)); |
|
1488 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == ":") |
|
1489 line_pos = line.find_first_not_of ("\t ", tmp_pos + 1); |
|
1490 |
|
1491 if (line_pos == NPOS) |
|
1492 { |
5592
|
1493 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1494 continue; |
|
1495 } |
|
1496 |
|
1497 // chop " function " |
|
1498 if (lower.substr (line_pos, 8) == "function") |
|
1499 line_pos = line.find_first_not_of ("\t ", line_pos + 8); |
|
1500 |
|
1501 if (line_pos == NPOS) |
|
1502 { |
5592
|
1503 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1504 continue; |
|
1505 } |
|
1506 |
|
1507 // chop " [a,b] = " |
|
1508 if (line.substr (line_pos, 1) == "[") |
|
1509 { |
|
1510 tmp_pos = line.find_first_not_of |
|
1511 ("\t ", line.find_first_of ("]", line_pos) + 1); |
|
1512 |
|
1513 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "=") |
|
1514 line_pos = line.find_first_not_of ("\t ",tmp_pos + 1); |
|
1515 } |
|
1516 |
|
1517 if (line_pos == NPOS) |
|
1518 { |
5592
|
1519 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1520 continue; |
|
1521 } |
|
1522 |
|
1523 // chop " a = " |
|
1524 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1525 { |
|
1526 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1527 (_alphanum, line_pos)); |
|
1528 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "=") |
|
1529 line_pos = line.find_first_not_of ("\t ", tmp_pos + 1); |
|
1530 } |
|
1531 |
|
1532 if (line_pos == NPOS) |
|
1533 { |
|
1534 pos = new_pos + 1; |
|
1535 continue; |
|
1536 } |
|
1537 |
|
1538 // chop " f(x) " |
|
1539 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1540 { |
|
1541 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1542 (_alphanum, line_pos)); |
|
1543 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "(") |
|
1544 line_pos = line.find_first_not_of ("\t ", line.find_first_of |
|
1545 (")", tmp_pos) + 1); |
|
1546 } |
|
1547 |
|
1548 if (line_pos == NPOS) |
|
1549 { |
5592
|
1550 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1551 continue; |
|
1552 } |
|
1553 |
|
1554 // chop " ; " |
|
1555 if (line.substr (line_pos, 1) == ":" |
|
1556 || line.substr (line_pos, 1) == ";") |
|
1557 line_pos = line.find_first_not_of ("\t ", line_pos + 1); |
|
1558 |
|
1559 if (line_pos == NPOS) |
|
1560 { |
5592
|
1561 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1562 continue; |
|
1563 } |
|
1564 |
|
1565 // chop " BLAH " |
|
1566 if (line.length () > line_pos + 2 |
|
1567 && line.find_first_of (_upper, line_pos) == line_pos |
|
1568 && line.find_first_of (_upper, line_pos+1) == line_pos + 1) |
|
1569 line_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1570 (_upper + "0123456789_", line_pos)); |
|
1571 |
|
1572 if (line_pos == NPOS) |
|
1573 { |
5592
|
1574 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1575 continue; |
|
1576 } |
|
1577 |
|
1578 // chop " blah --- " |
|
1579 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1580 (_alphanum, line_pos)); |
|
1581 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "-") |
|
1582 { |
|
1583 tmp_pos = line.find_first_not_of ("-", tmp_pos); |
|
1584 if (line.substr (tmp_pos, 1) == " " |
|
1585 || line.substr (tmp_pos, 1) == "\t") |
|
1586 line_pos = line.find_first_not_of ("\t ", tmp_pos); |
|
1587 } |
|
1588 |
|
1589 if (line_pos == NPOS) |
|
1590 { |
5592
|
1591 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1592 continue; |
|
1593 } |
|
1594 |
|
1595 // chop " blah <TAB> " |
|
1596 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1597 { |
|
1598 tmp_pos = line.find_first_not_of (" ", line.find_first_not_of |
|
1599 (_alphanum, line_pos)); |
|
1600 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "\t") |
|
1601 line_pos = line.find_first_not_of ("\t ", line.find_first_of |
|
1602 (")", tmp_pos) + 1); |
|
1603 } |
|
1604 |
|
1605 if (line_pos == NPOS) |
|
1606 { |
5592
|
1607 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1608 continue; |
|
1609 } |
|
1610 |
|
1611 // chop " blah " |
|
1612 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1613 { |
|
1614 tmp_pos = line.find_first_not_of (_alphanum, line_pos); |
|
1615 |
|
1616 if (tmp_pos != NPOS |
|
1617 && (line.substr (tmp_pos, 2) == "\t\t" |
|
1618 || line.substr (tmp_pos, 2) == "\t " |
|
1619 || line.substr (tmp_pos, 2) == " \t" |
|
1620 || line.substr (tmp_pos, 2) == " ")) |
|
1621 line_pos = line.find_first_not_of ("\t ", tmp_pos); |
|
1622 } |
|
1623 |
|
1624 if (line_pos == NPOS) |
|
1625 { |
5592
|
1626 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1627 continue; |
|
1628 } |
|
1629 |
|
1630 // skip blah \n or \n blah |
|
1631 // skip blank line |
|
1632 // skip "# !/usr/bin/octave" |
|
1633 if ((line.substr (line_pos , 2) == "or" |
|
1634 && line.find_first_not_of ("\n\t ", line_pos + 2) == NPOS) |
|
1635 || line.find_first_not_of ("\n\t ", line_pos) == NPOS |
|
1636 || line.substr (line_pos, 2) == "!/") |
|
1637 { |
5592
|
1638 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1639 continue; |
|
1640 } |
|
1641 |
|
1642 // Got the start of first sentence, break. |
|
1643 pos = pos + line_pos; |
|
1644 break; |
|
1645 } |
|
1646 |
|
1647 if (pos == NPOS) |
5738
|
1648 return retval; |
5447
|
1649 |
|
1650 // At start of real text. Get first line with the sentence |
|
1651 size_t new_pos = h.find_first_of ('\n', pos); |
|
1652 std::string line = h.substr (pos, new_pos-pos); |
|
1653 size_t dot_pos; |
|
1654 |
|
1655 while ((dot_pos = line.find_first_of ('.')) == NPOS) |
|
1656 { |
|
1657 // Trim trailing blanks on line |
|
1658 line = line.substr (0, line.find_last_not_of ("\n\t ") + 1); |
|
1659 |
|
1660 // Append next line |
|
1661 size_t tmp_pos = h.find_first_not_of ("\t ", new_pos + 1); |
|
1662 if (tmp_pos == NPOS || h.substr (tmp_pos, 1) == "\n") |
|
1663 break; |
|
1664 |
|
1665 new_pos = h.find_first_of ('\n', tmp_pos); |
|
1666 std::string next = h.substr (tmp_pos, new_pos-tmp_pos); |
|
1667 |
|
1668 if (short_sentence) |
|
1669 { |
|
1670 // Only add the next line if it terminates the sentence, then break |
|
1671 if ((tmp_pos = next.find_first_of ('.')) != NPOS) |
|
1672 { |
|
1673 line = line + " " + next; |
|
1674 dot_pos = line.find_first_of ('.'); |
|
1675 } |
|
1676 break; |
|
1677 } |
|
1678 else |
|
1679 line = line + " " + next; |
|
1680 } |
|
1681 |
|
1682 if (dot_pos == NPOS) |
5738
|
1683 retval = line; |
5447
|
1684 else |
5738
|
1685 retval = line.substr (0, dot_pos + 1); |
5447
|
1686 } |
5738
|
1687 |
|
1688 return retval; |
5447
|
1689 } |
|
1690 |
|
1691 static void |
|
1692 print_lookfor (const std::string& name, const std::string& line) |
|
1693 { |
|
1694 const size_t deflen = 20; |
|
1695 |
|
1696 size_t max_width = command_editor::terminal_cols () - deflen; |
|
1697 if (max_width < deflen) |
|
1698 max_width = deflen; |
|
1699 |
|
1700 size_t name_len = name.length (); |
|
1701 |
|
1702 size_t width = max_width; |
|
1703 if (name_len > deflen) |
|
1704 { |
|
1705 width = command_editor::terminal_cols () - name_len; |
|
1706 if (width < deflen) |
|
1707 width = deflen; |
|
1708 } |
|
1709 |
|
1710 size_t pad_len = deflen > name_len ? deflen - name_len + 1 : 1; |
|
1711 octave_stdout << name << std::string (pad_len, ' '); |
|
1712 |
|
1713 size_t pos = 0; |
|
1714 |
|
1715 while (1) |
|
1716 { |
|
1717 size_t new_pos = line.find_first_of ("\n\t ", pos); |
|
1718 size_t end_pos = new_pos; |
|
1719 |
|
1720 if (line.length () - pos < width) |
|
1721 new_pos = end_pos = NPOS; |
|
1722 else |
|
1723 while (new_pos != NPOS && new_pos - pos < width) |
|
1724 { |
|
1725 end_pos = new_pos; |
|
1726 new_pos = line.find_first_of ("\n\t ", new_pos + 1); |
|
1727 } |
|
1728 |
|
1729 octave_stdout << line.substr (pos, end_pos-pos) << std::endl; |
|
1730 |
|
1731 if (end_pos == NPOS) |
|
1732 break; |
|
1733 |
|
1734 pos = end_pos + 1; |
|
1735 width = max_width; |
|
1736 octave_stdout << std::string (deflen + 1, ' '); |
|
1737 } |
|
1738 } |
|
1739 |
|
1740 DEFCMD (lookfor, args, nargout, |
|
1741 "-*- texinfo -*-\n\ |
|
1742 @deffn {Command} lookfor @var{str}\n\ |
|
1743 @deffnx {Command} lookfor -all @var{str}\n\ |
|
1744 @deffnx {Function} {[@var{fun}, @var{helpstring}] = } lookfor (@var{str})\n\ |
|
1745 @deffnx {Function} {[@var{fun}, @var{helpstring}] = } lookfor ('-all', @var{str})\n\ |
5814
|
1746 Search for the string @var{str} in all of the functions found in the\n\ |
7001
|
1747 function search path. By default @code{lookfor} searches for @var{str}\n\ |
5814
|
1748 in the first sentence of the help string of each function found. The entire\n\ |
7001
|
1749 help string of each function found in the path can be searched if\n\ |
5447
|
1750 the '-all' argument is supplied. All searches are case insensitive.\n\ |
|
1751 \n\ |
|
1752 Called with no output arguments, @code{lookfor} prints the list of matching\n\ |
|
1753 functions to the terminal. Otherwise the output arguments @var{fun} and\n\ |
|
1754 @var{helpstring} define the matching functions and the first sentence of\n\ |
|
1755 each of their help strings.\n\ |
|
1756 \n\ |
|
1757 Note that the ability of @code{lookfor} to correctly identify the first\n\ |
|
1758 sentence of the help of the functions is dependent on the format of the\n\ |
6620
|
1759 functions help. All of the functions in Octave itself will correctly\n\ |
5447
|
1760 find the first sentence, but the same can not be guaranteed for other\n\ |
|
1761 functions. Therefore the use of the '-all' argument might be necessary\n\ |
6620
|
1762 to find related functions that are not part of Octave.\n\ |
5667
|
1763 @seealso{help, which}\n\ |
5642
|
1764 @end deffn") |
5447
|
1765 { |
|
1766 octave_value_list retval; |
|
1767 int nargin = args.length (); |
|
1768 bool first_sentence_only = true; |
|
1769 |
|
1770 if (nargin != 1 && nargin != 2) |
|
1771 { |
7038
|
1772 print_usage (); |
5447
|
1773 return retval; |
|
1774 } |
|
1775 |
|
1776 string_vector ret[2]; |
|
1777 |
|
1778 std::string txt; |
|
1779 |
|
1780 if (args(0).is_string ()) |
|
1781 { |
|
1782 txt = args(0).string_value (); |
|
1783 |
|
1784 if (nargin == 2) |
|
1785 { |
|
1786 if (args(1).is_string ()) |
|
1787 { |
|
1788 std::string tmp = args(1).string_value (); |
|
1789 |
|
1790 if (txt.substr(0,1) == "-") |
|
1791 { |
|
1792 txt = tmp; |
|
1793 tmp = args(0).string_value (); |
|
1794 } |
|
1795 |
|
1796 if (tmp == "-all") |
|
1797 first_sentence_only = false; |
|
1798 else |
|
1799 error ("lookfor: unrecognized option argument"); |
|
1800 } |
|
1801 else |
|
1802 error ("lookfor: arguments must be a string"); |
|
1803 } |
|
1804 } |
|
1805 else |
|
1806 error ("lookfor: argument must be a string"); |
|
1807 |
|
1808 if (!error_state) |
|
1809 { |
|
1810 // All tests in lower case |
5768
|
1811 std::transform (txt.begin (), txt.end (), txt.begin (), tolower); |
5447
|
1812 |
|
1813 help_list *ptr = keyword_help (); |
|
1814 while (ptr->name) |
|
1815 { |
|
1816 std::string name = ptr->name; |
|
1817 std::string h = ptr->help; |
|
1818 |
5592
|
1819 if (name.find (txt) != NPOS) |
5447
|
1820 { |
|
1821 if (nargout) |
|
1822 { |
|
1823 ret[0].append (name); |
|
1824 ret[1].append (first_help_sentence (h)); |
|
1825 } |
|
1826 else |
|
1827 print_lookfor (name, first_help_sentence (h)); |
|
1828 } |
5592
|
1829 else |
|
1830 { |
|
1831 std::string s; |
|
1832 |
|
1833 if (first_sentence_only) |
|
1834 s = first_help_sentence (h); |
|
1835 else |
|
1836 s = h; |
|
1837 |
5768
|
1838 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1839 |
|
1840 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1841 { |
|
1842 if (nargout) |
|
1843 { |
|
1844 ret[0].append (name); |
|
1845 ret[1].append (first_help_sentence (h)); |
|
1846 } |
|
1847 else |
|
1848 print_lookfor (name, first_help_sentence (h)); |
|
1849 } |
|
1850 } |
5447
|
1851 |
|
1852 OCTAVE_QUIT; |
|
1853 |
|
1854 ptr++; |
|
1855 } |
|
1856 |
|
1857 ptr = operator_help (); |
|
1858 while (ptr->name) |
|
1859 { |
|
1860 std::string name = ptr->name; |
|
1861 std::string h = ptr->help; |
|
1862 |
5592
|
1863 if (name.find (txt) != NPOS) |
5447
|
1864 { |
|
1865 if (nargout) |
|
1866 { |
|
1867 ret[0].append (name); |
|
1868 ret[1].append (first_help_sentence (h)); |
|
1869 } |
|
1870 else |
|
1871 print_lookfor (name, first_help_sentence (h)); |
|
1872 } |
5592
|
1873 else |
|
1874 { |
|
1875 std::string s; |
|
1876 if (first_sentence_only) |
|
1877 s = first_help_sentence (h); |
|
1878 else |
|
1879 s = h; |
|
1880 |
5768
|
1881 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1882 |
|
1883 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1884 { |
|
1885 if (nargout) |
|
1886 { |
|
1887 ret[0].append (name); |
|
1888 ret[1].append (first_help_sentence (h)); |
|
1889 } |
|
1890 else |
|
1891 print_lookfor (name, first_help_sentence (h)); |
|
1892 } |
|
1893 } |
5447
|
1894 |
|
1895 OCTAVE_QUIT; |
|
1896 |
|
1897 ptr++; |
|
1898 } |
|
1899 |
|
1900 // Check the symbol record table |
|
1901 string_vector names |
|
1902 = fbi_sym_tab->name_list (string_vector (), true); |
|
1903 |
|
1904 for (octave_idx_type i = 0; i < names.length (); i++) |
|
1905 { |
|
1906 std::string name = names (i); |
|
1907 |
|
1908 OCTAVE_QUIT; |
|
1909 |
|
1910 symbol_record *sr = lookup_by_name (name, 0); |
5738
|
1911 if (sr && sr->is_defined () |
|
1912 && sr->type_name () != "overloaded function") |
5447
|
1913 { |
|
1914 std::string h = sr->help (); |
|
1915 |
5592
|
1916 if (name.find (txt) != NPOS) |
5447
|
1917 { |
|
1918 if (nargout) |
|
1919 { |
|
1920 ret[0].append (name); |
|
1921 ret[1].append (first_help_sentence (h)); |
|
1922 } |
|
1923 else |
|
1924 print_lookfor (name, first_help_sentence (h)); |
|
1925 } |
5592
|
1926 else |
|
1927 { |
|
1928 std::string s; |
|
1929 |
|
1930 if (first_sentence_only) |
|
1931 s = first_help_sentence (h); |
|
1932 else |
|
1933 s = h; |
|
1934 |
5768
|
1935 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1936 |
|
1937 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1938 { |
|
1939 if (nargout) |
|
1940 { |
|
1941 ret[0].append (name); |
|
1942 ret[1].append (first_help_sentence (h)); |
|
1943 } |
|
1944 else |
|
1945 print_lookfor (name, first_help_sentence (h)); |
|
1946 } |
|
1947 } |
5447
|
1948 } |
|
1949 } |
|
1950 |
5832
|
1951 string_vector dirs = load_path::dirs (); |
5447
|
1952 |
|
1953 int len = dirs.length (); |
|
1954 |
|
1955 for (int i = 0; i < len; i++) |
|
1956 { |
5832
|
1957 names = load_path::files (dirs[i]); |
5447
|
1958 |
|
1959 if (! names.empty ()) |
|
1960 { |
|
1961 for (int j = 0; j < names.length (); j++) |
|
1962 { |
|
1963 std::string name = names (j); |
|
1964 |
|
1965 OCTAVE_QUIT; |
|
1966 |
|
1967 // Strip extension |
|
1968 size_t l = name.length (); |
|
1969 if (l > 4 && name.substr (l-4) == ".oct") |
|
1970 name = name.substr (0, l - 4); |
|
1971 else if (l > 2 && name.substr (l-2) == ".m") |
|
1972 name = name.substr (0, l - 2); |
|
1973 else |
|
1974 continue; |
|
1975 |
|
1976 // Check if already in symbol table |
|
1977 symbol_record *sr = fbi_sym_tab->lookup (name); |
|
1978 |
|
1979 if (!sr) |
|
1980 { |
|
1981 // Check if this version is first in the path |
|
1982 |
5832
|
1983 std::string file_name = load_path::find_fcn (name); |
|
1984 |
|
1985 std::string dir = dirs[i] + file_ops::dir_sep_str; |
|
1986 |
|
1987 if (file_name == dir + name + ".oct" |
|
1988 || file_name == dir + name + ".m") |
5447
|
1989 { |
5484
|
1990 bool symbol_found; |
|
1991 |
5592
|
1992 std::string h; |
5832
|
1993 if (file_name == dir + name + ".oct") |
5592
|
1994 { |
|
1995 // oct-file. Must load to get help |
|
1996 sr = lookup_by_name (name, false); |
5447
|
1997 |
5592
|
1998 if (sr && sr->is_defined ()) |
|
1999 h = sr->help (); |
|
2000 } |
5447
|
2001 else |
5592
|
2002 h = get_help_from_file (file_name, symbol_found); |
5447
|
2003 |
5592
|
2004 if (name.find (txt) != NPOS) |
5447
|
2005 { |
|
2006 if (nargout) |
|
2007 { |
|
2008 ret[0].append (name); |
|
2009 ret[1].append (first_help_sentence (h)); |
|
2010 } |
|
2011 else |
|
2012 print_lookfor (name, first_help_sentence (h)); |
|
2013 } |
5592
|
2014 else |
|
2015 { |
|
2016 std::string s; |
|
2017 if (first_sentence_only) |
|
2018 s = first_help_sentence (h); |
|
2019 else |
|
2020 s = h; |
|
2021 |
5768
|
2022 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
2023 |
|
2024 if (s.length () > 0 && s.find (txt) != NPOS) |
|
2025 { |
|
2026 if (nargout) |
|
2027 { |
|
2028 ret[0].append (name); |
|
2029 ret[1].append (first_help_sentence (h)); |
|
2030 } |
|
2031 else |
|
2032 print_lookfor (name, first_help_sentence (h)); |
|
2033 } |
|
2034 } |
|
2035 } |
|
2036 } |
|
2037 |
|
2038 // Check if this function has autoloaded functions attached to it |
5832
|
2039 std::string file_name = load_path::find_fcn (name); |
|
2040 |
5592
|
2041 string_vector autoload_fcns = reverse_lookup_autoload (file_name); |
|
2042 |
|
2043 if (! autoload_fcns.empty ()) |
|
2044 { |
|
2045 for (int k = 0; k < autoload_fcns.length (); k++) |
|
2046 { |
|
2047 std::string aname = autoload_fcns (k); |
|
2048 |
|
2049 // Check if already in symbol table |
|
2050 sr = fbi_sym_tab->lookup (aname); |
|
2051 |
|
2052 if (!sr) |
|
2053 { |
|
2054 // Must load to get help |
5738
|
2055 sr = lookup_by_name (aname, false); |
5592
|
2056 |
|
2057 std::string h; |
|
2058 if (sr && sr->is_defined ()) |
|
2059 h = sr->help (); |
|
2060 |
|
2061 if (aname.find (txt) != NPOS) |
|
2062 { |
|
2063 if (nargout) |
|
2064 { |
|
2065 ret[0].append (aname); |
|
2066 ret[1].append (first_help_sentence (h)); |
|
2067 } |
|
2068 else |
|
2069 print_lookfor (aname, first_help_sentence (h)); |
|
2070 } |
|
2071 else |
|
2072 { |
|
2073 std::string s; |
|
2074 if (first_sentence_only) |
|
2075 s = first_help_sentence (h); |
|
2076 else |
|
2077 s = h; |
|
2078 |
5768
|
2079 std::transform (s.begin (), s.end (), s.begin (), |
5592
|
2080 tolower); |
|
2081 |
|
2082 if (s.length () > 0 && s.find (txt) != NPOS) |
|
2083 { |
|
2084 if (nargout) |
|
2085 { |
|
2086 ret[0].append (aname); |
|
2087 ret[1].append (first_help_sentence (h)); |
|
2088 } |
|
2089 else |
|
2090 print_lookfor (aname, first_help_sentence (h)); |
|
2091 } |
|
2092 } |
|
2093 } |
5447
|
2094 } |
|
2095 } |
|
2096 } |
|
2097 } |
|
2098 } |
|
2099 |
|
2100 if (nargout != 0) |
|
2101 { |
|
2102 retval (1) = ret[1]; |
|
2103 retval (0) = ret[0]; |
|
2104 } |
|
2105 } |
|
2106 else |
|
2107 { |
|
2108 error ("lookfor: argument must be a string"); |
|
2109 } |
|
2110 |
|
2111 return retval; |
|
2112 } |
|
2113 |
5794
|
2114 DEFUN (info_file, args, nargout, |
|
2115 "-*- texinfo -*-\n\ |
|
2116 @deftypefn {Built-in Function} {@var{val} =} info_file ()\n\ |
|
2117 @deftypefnx {Built-in Function} {@var{old_val} =} info_file (@var{new_val})\n\ |
|
2118 Query or set the internal variable that specifies the name of the\n\ |
|
2119 Octave info file. The default value is\n\ |
|
2120 @code{\"@var{octave-home}/info/octave.info\"}, in\n\ |
|
2121 which @var{octave-home} is the directory where all of Octave is installed.\n\ |
|
2122 @seealso{info_program, doc, help, makeinfo_program}\n\ |
|
2123 @end deftypefn") |
2202
|
2124 { |
5794
|
2125 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_file); |
2202
|
2126 } |
|
2127 |
5794
|
2128 DEFUN (info_program, args, nargout, |
|
2129 "-*- texinfo -*-\n\ |
|
2130 @deftypefn {Built-in Function} {@var{val} =} info_program ()\n\ |
|
2131 @deftypefnx {Built-in Function} {@var{old_val} =} info_program (@var{new_val})\n\ |
|
2132 Query or set the internal variable that specifies the name of the\n\ |
|
2133 info program to run. The default initial value is\n\ |
3686
|
2134 @code{\"@var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}/info\"}\n\ |
|
2135 in which @var{octave-home} is the directory where all of Octave is\n\ |
|
2136 installed, @var{version} is the Octave version number, and @var{arch}\n\ |
|
2137 is the system type (for example, @code{i686-pc-linux-gnu}). The\n\ |
|
2138 default initial value may be overridden by the environment variable\n\ |
|
2139 @code{OCTAVE_INFO_PROGRAM}, or the command line argument\n\ |
5794
|
2140 @code{--info-program NAME}.\n\ |
|
2141 @seealso{info_file, doc, help, makeinfo_program}\n\ |
|
2142 @end deftypefn") |
|
2143 { |
|
2144 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_program); |
|
2145 } |
3686
|
2146 |
5794
|
2147 DEFUN (makeinfo_program, args, nargout, |
|
2148 "-*- texinfo -*-\n\ |
|
2149 @deftypefn {Built-in Function} {@var{val} =} makeinfo_program ()\n\ |
|
2150 @deftypefnx {Built-in Function} {@var{old_val} =} makeinfo_program (@var{new_val})\n\ |
|
2151 Query or set the internal variable that specifies the name of the\n\ |
|
2152 makeinfo program that Octave runs to format help text containing\n\ |
|
2153 Texinfo markup commands. The default initial value is @code{\"makeinfo\"}.\n\ |
|
2154 @seealso{info_file, info_program, doc, help}\n\ |
|
2155 @end deftypefn") |
|
2156 { |
|
2157 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (makeinfo_program); |
|
2158 } |
2202
|
2159 |
5794
|
2160 DEFUN (suppress_verbose_help_message, args, nargout, |
|
2161 "-*- texinfo -*-\n\ |
|
2162 @deftypefn {Built-in Function} {@var{val} =} suppress_verbose_help_message ()\n\ |
|
2163 @deftypefnx {Built-in Function} {@var{old_val} =} suppress_verbose_help_message (@var{new_val})\n\ |
7001
|
2164 Query or set the internal variable that controls whether Octave\n\ |
5794
|
2165 will add additional help information to the end of the output from\n\ |
3332
|
2166 the @code{help} command and usage messages for built-in commands.\n\ |
5794
|
2167 @end deftypefn") |
|
2168 { |
|
2169 return SET_INTERNAL_VARIABLE (suppress_verbose_help_message); |
2189
|
2170 } |
|
2171 |
1
|
2172 /* |
|
2173 ;;; Local Variables: *** |
|
2174 ;;; mode: C++ *** |
|
2175 ;;; End: *** |
|
2176 */ |