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