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" |
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\ |
|
1159 @deffn {Command} help\n\ |
|
1160 Octave's @code{help} command can be used to print brief usage-style\n\ |
|
1161 messages, or to display information directly from an on-line version of\n\ |
|
1162 the printed manual, using the GNU Info browser. If invoked without any\n\ |
5794
|
1163 arguments, @code{help} prints a list of all the available operators\n\ |
|
1164 and functions. If the first argument is @code{-i}, the @code{help}\n\ |
|
1165 command searches the index of the on-line version of this manual for\n\ |
|
1166 the given topics.\n\ |
3168
|
1167 \n\ |
3332
|
1168 For example, the command @kbd{help help} prints a short message\n\ |
|
1169 describing the @code{help} command, and @kbd{help -i help} starts the\n\ |
|
1170 GNU Info browser at this node in the on-line version of the manual.\n\ |
|
1171 \n\ |
|
1172 Once the GNU Info browser is running, help for using it is available\n\ |
|
1173 using the command @kbd{C-h}.\n\ |
5672
|
1174 @seealso{doc, which, lookfor}\n\ |
3333
|
1175 @end deffn") |
529
|
1176 { |
2086
|
1177 octave_value_list retval; |
529
|
1178 |
1755
|
1179 int argc = args.length () + 1; |
|
1180 |
1968
|
1181 string_vector argv = args.make_argv ("help"); |
1755
|
1182 |
|
1183 if (error_state) |
|
1184 return retval; |
529
|
1185 |
|
1186 if (argc == 1) |
3014
|
1187 simple_help (); |
529
|
1188 else |
|
1189 { |
1755
|
1190 if (argv[1] == "-i") |
3014
|
1191 help_from_info (argv, 2, argc); |
529
|
1192 else |
3014
|
1193 builtin_help (argc, argv); |
529
|
1194 } |
|
1195 |
|
1196 return retval; |
|
1197 } |
|
1198 |
3355
|
1199 static void |
3523
|
1200 do_type (std::ostream& os, const std::string& name, bool pr_type_info, |
3355
|
1201 bool quiet, bool pr_orig_txt) |
|
1202 { |
|
1203 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1204 |
|
1205 if (sym_rec && sym_rec->is_defined ()) |
3356
|
1206 sym_rec->type (os, pr_type_info, quiet, pr_orig_txt); |
3355
|
1207 else |
|
1208 { |
3523
|
1209 std::string ff = fcn_file_in_path (name); |
3355
|
1210 |
|
1211 if (! ff.empty ()) |
|
1212 { |
3538
|
1213 std::ifstream fs (ff.c_str (), std::ios::in); |
3355
|
1214 |
|
1215 if (fs) |
|
1216 { |
|
1217 if (pr_type_info && ! quiet) |
|
1218 os << name << " is the script file: " << ff << "\n\n"; |
|
1219 |
|
1220 char ch; |
|
1221 |
|
1222 while (fs.get (ch)) |
|
1223 os << ch; |
|
1224 } |
|
1225 else |
|
1226 os << "unable to open `" << ff << "' for reading!\n"; |
|
1227 } |
|
1228 else |
|
1229 error ("type: `%s' undefined", name.c_str ()); |
|
1230 } |
|
1231 } |
|
1232 |
4208
|
1233 DEFCMD (type, args, nargout, |
3361
|
1234 "-*- texinfo -*-\n\ |
|
1235 \n\ |
|
1236 @deffn {Command} type options name @dots{}\n\ |
|
1237 Display the definition of each @var{name} that refers to a function.\n\ |
|
1238 \n\ |
|
1239 Normally also displays if each @var{name} is user-defined or builtin;\n\ |
|
1240 the @code{-q} option suppresses this behaviour.\n\ |
581
|
1241 \n\ |
3361
|
1242 Currently, Octave can only display functions that can be compiled\n\ |
|
1243 cleanly, because it uses its internal representation of the function to\n\ |
|
1244 recreate the program text.\n\ |
|
1245 \n\ |
|
1246 Comments are not displayed because Octave's parser currently discards\n\ |
|
1247 them as it converts the text of a function file to its internal\n\ |
|
1248 representation. This problem may be fixed in a future release.\n\ |
|
1249 @end deffn") |
581
|
1250 { |
3584
|
1251 octave_value retval; |
1588
|
1252 |
1755
|
1253 int argc = args.length () + 1; |
|
1254 |
1968
|
1255 string_vector argv = args.make_argv ("type"); |
1755
|
1256 |
3355
|
1257 if (! error_state) |
581
|
1258 { |
3355
|
1259 if (argc > 1) |
|
1260 { |
5775
|
1261 // FIXME -- we should really use getopt () |
2532
|
1262 |
3355
|
1263 bool quiet = false; |
|
1264 bool pr_orig_txt = true; |
2532
|
1265 |
3355
|
1266 int idx; |
581
|
1267 |
3355
|
1268 for (idx = 1; idx < argc; idx++) |
1281
|
1269 { |
3355
|
1270 if (argv[idx] == "-q" || argv[idx] == "-quiet") |
|
1271 quiet = true; |
|
1272 else if (argv[idx] == "-t" || argv[idx] == "-transformed") |
|
1273 pr_orig_txt = false; |
|
1274 else |
|
1275 break; |
1281
|
1276 } |
|
1277 |
3355
|
1278 if (idx < argc) |
|
1279 { |
5765
|
1280 std::ostringstream output_buf; |
581
|
1281 |
3355
|
1282 for (int i = idx; i < argc; i++) |
581
|
1283 { |
3523
|
1284 std::string id = argv[i]; |
2534
|
1285 |
3355
|
1286 if (nargout == 0) |
|
1287 do_type (octave_stdout, id, true, quiet, pr_orig_txt); |
|
1288 else |
|
1289 do_type (output_buf, id, false, quiet, pr_orig_txt); |
581
|
1290 |
3355
|
1291 if (error_state) |
|
1292 goto abort; |
581
|
1293 } |
|
1294 |
3584
|
1295 if (nargout != 0) |
5765
|
1296 retval = output_buf.str (); |
581
|
1297 } |
|
1298 else |
5823
|
1299 print_usage (); |
3355
|
1300 } |
|
1301 else |
5823
|
1302 print_usage (); |
3355
|
1303 } |
3141
|
1304 |
3355
|
1305 abort: |
581
|
1306 |
|
1307 return retval; |
|
1308 } |
|
1309 |
3536
|
1310 static std::string |
3523
|
1311 do_which (const std::string& name) |
3355
|
1312 { |
3523
|
1313 std::string retval; |
3355
|
1314 |
|
1315 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1316 |
|
1317 if (sym_rec && sym_rec->is_defined ()) |
|
1318 retval = sym_rec->which (); |
|
1319 else |
6348
|
1320 retval = fcn_file_in_path (name); |
3355
|
1321 |
|
1322 return retval; |
|
1323 } |
|
1324 |
|
1325 static void |
3523
|
1326 do_which (std::ostream& os, const std::string& name) |
3355
|
1327 { |
|
1328 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1329 |
|
1330 if (sym_rec && sym_rec->is_defined ()) |
|
1331 sym_rec->which (os); |
|
1332 else |
|
1333 { |
3523
|
1334 std::string path = fcn_file_in_path (name); |
3355
|
1335 |
|
1336 if (! path.empty ()) |
|
1337 os << "which: `" << name << "' is the script file\n" |
|
1338 << path << "\n"; |
|
1339 else |
|
1340 os << "which: `" << name << "' is undefined\n"; |
|
1341 } |
|
1342 } |
|
1343 |
4208
|
1344 DEFCMD (which, args, nargout, |
3361
|
1345 "-*- texinfo -*-\n\ |
|
1346 @deffn {Command} which name @dots{}\n\ |
|
1347 Display the type of each @var{name}. If @var{name} is defined from a\n\ |
|
1348 function file, the full name of the file is also displayed.\n\ |
5667
|
1349 @seealso{help, lookfor}\n\ |
3361
|
1350 @end deffn") |
581
|
1351 { |
2086
|
1352 octave_value_list retval; |
581
|
1353 |
1968
|
1354 string_vector argv = args.make_argv ("which"); |
1755
|
1355 |
3355
|
1356 if (! error_state) |
|
1357 { |
|
1358 int argc = argv.length (); |
581
|
1359 |
|
1360 if (nargout > 0) |
|
1361 retval.resize (argc-1, Matrix ()); |
|
1362 |
3355
|
1363 if (argc > 1) |
581
|
1364 { |
3355
|
1365 for (int i = 1; i < argc; i++) |
581
|
1366 { |
3523
|
1367 std::string id = argv[i]; |
3141
|
1368 |
3355
|
1369 if (nargout == 0) |
|
1370 do_which (octave_stdout, id); |
581
|
1371 else |
3355
|
1372 retval(i-1) = do_which (id); |
581
|
1373 } |
|
1374 } |
3355
|
1375 else |
5823
|
1376 print_usage (); |
581
|
1377 } |
|
1378 |
|
1379 return retval; |
|
1380 } |
|
1381 |
5775
|
1382 // FIXME |
5447
|
1383 // This function attempts to find the first sentence of a help string, though |
|
1384 // given that the user can create the help in an arbitrary format, your |
|
1385 // success might vary.. it works much better with help string formated in |
|
1386 // texinfo. Using regex might make this function much simpler. |
|
1387 |
|
1388 std::string |
|
1389 first_help_sentence (const std::string& h, bool short_sentence = true) |
|
1390 { |
5738
|
1391 std::string retval; |
|
1392 |
5447
|
1393 size_t pos = 0; |
|
1394 |
|
1395 if (looks_like_texinfo (h, pos)) |
5592
|
1396 { |
|
1397 // Get the parsed help string. |
5447
|
1398 pos = 0; |
5765
|
1399 std::ostringstream os; |
5447
|
1400 display_help_text (os, h); |
|
1401 std::string h2 = os.str (); |
|
1402 |
|
1403 while (1) |
|
1404 { |
|
1405 // Skip leading whitespace and get new line |
|
1406 pos = h2.find_first_not_of ("\n\t ", pos); |
|
1407 |
|
1408 if (pos == NPOS) |
|
1409 break; |
|
1410 |
|
1411 size_t new_pos = h2.find_first_of ('\n', pos); |
|
1412 std::string line = h2.substr (pos, new_pos-pos); |
|
1413 |
|
1414 // Skip lines starting in "-" |
|
1415 if (line.find_first_of ('-') == 0) |
|
1416 { |
|
1417 pos = new_pos + 1; |
|
1418 continue; |
|
1419 } |
|
1420 |
|
1421 break; |
|
1422 } |
|
1423 |
|
1424 if (pos == NPOS) |
5738
|
1425 return retval; |
5447
|
1426 |
|
1427 // At start of real text. Get first line with the sentence |
|
1428 size_t new_pos = h2.find_first_of ('\n', pos); |
|
1429 std::string line = h2.substr (pos, new_pos-pos); |
|
1430 size_t dot_pos; |
|
1431 |
|
1432 while ((dot_pos = line.find_first_of ('.')) == NPOS) |
|
1433 { |
|
1434 // Trim trailing blanks on line |
|
1435 line.substr (0, line.find_last_not_of ("\n\t ") + 1); |
|
1436 |
|
1437 // Append next line |
|
1438 size_t tmp_pos = h2.find_first_not_of ("\n\t ", new_pos + 1); |
|
1439 if (tmp_pos == NPOS || h2.substr (tmp_pos, 1) == "\n") |
|
1440 break; |
|
1441 |
|
1442 new_pos = h2.find_first_of ('\n', tmp_pos); |
|
1443 std::string next = h2.substr (tmp_pos, new_pos-tmp_pos); |
|
1444 |
|
1445 if (short_sentence) |
|
1446 { |
|
1447 if ((tmp_pos = next.find_first_of ('.')) != NPOS) |
|
1448 { |
|
1449 line = line + " " + next; |
|
1450 dot_pos = line.find_first_of ('.'); |
|
1451 } |
|
1452 break; |
|
1453 } |
|
1454 else |
|
1455 line = line + " " + next; |
|
1456 } |
|
1457 |
|
1458 if (dot_pos == NPOS) |
5738
|
1459 retval = line; |
5447
|
1460 else |
5738
|
1461 retval = line.substr (0, dot_pos + 1); |
5447
|
1462 } |
|
1463 else |
|
1464 { |
|
1465 std::string _upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
1466 std::string _lower = "abcdefghijklmnopqrstuvwxyz"; |
|
1467 std::string _alpha = _upper + _lower + "_"; |
|
1468 std::string _alphanum = _alpha + "1234567890"; |
|
1469 pos = 0; |
|
1470 |
|
1471 while (1) |
|
1472 { |
|
1473 // Skip leading whitespace and get new line |
|
1474 pos = h.find_first_not_of ("\n\t ", pos); |
|
1475 |
|
1476 if (pos == NPOS) |
|
1477 break; |
|
1478 |
|
1479 size_t new_pos = h.find_first_of ('\n', pos); |
|
1480 std::string line = h.substr (pos, new_pos-pos); |
|
1481 |
|
1482 // Make a lower case copy to simplify some tests |
|
1483 std::string lower = line; |
5768
|
1484 std::transform (lower.begin (), lower.end (), lower.begin (), tolower); |
5447
|
1485 |
|
1486 // Skip lines starting in "-" or "Usage" |
|
1487 if (lower.find_first_of ('-') == 0 |
|
1488 || lower.substr (0, 5) == "usage") |
|
1489 { |
5592
|
1490 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1491 continue; |
|
1492 } |
|
1493 |
|
1494 size_t line_pos = 0; |
|
1495 size_t tmp_pos = 0; |
|
1496 |
|
1497 // chop " blah : " |
|
1498 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1499 (_alphanum, line_pos)); |
|
1500 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == ":") |
|
1501 line_pos = line.find_first_not_of ("\t ", tmp_pos + 1); |
|
1502 |
|
1503 if (line_pos == NPOS) |
|
1504 { |
5592
|
1505 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1506 continue; |
|
1507 } |
|
1508 |
|
1509 // chop " function " |
|
1510 if (lower.substr (line_pos, 8) == "function") |
|
1511 line_pos = line.find_first_not_of ("\t ", line_pos + 8); |
|
1512 |
|
1513 if (line_pos == NPOS) |
|
1514 { |
5592
|
1515 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1516 continue; |
|
1517 } |
|
1518 |
|
1519 // chop " [a,b] = " |
|
1520 if (line.substr (line_pos, 1) == "[") |
|
1521 { |
|
1522 tmp_pos = line.find_first_not_of |
|
1523 ("\t ", line.find_first_of ("]", line_pos) + 1); |
|
1524 |
|
1525 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "=") |
|
1526 line_pos = line.find_first_not_of ("\t ",tmp_pos + 1); |
|
1527 } |
|
1528 |
|
1529 if (line_pos == NPOS) |
|
1530 { |
5592
|
1531 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1532 continue; |
|
1533 } |
|
1534 |
|
1535 // chop " a = " |
|
1536 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1537 { |
|
1538 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1539 (_alphanum, line_pos)); |
|
1540 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "=") |
|
1541 line_pos = line.find_first_not_of ("\t ", tmp_pos + 1); |
|
1542 } |
|
1543 |
|
1544 if (line_pos == NPOS) |
|
1545 { |
|
1546 pos = new_pos + 1; |
|
1547 continue; |
|
1548 } |
|
1549 |
|
1550 // chop " f(x) " |
|
1551 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1552 { |
|
1553 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1554 (_alphanum, line_pos)); |
|
1555 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "(") |
|
1556 line_pos = line.find_first_not_of ("\t ", line.find_first_of |
|
1557 (")", tmp_pos) + 1); |
|
1558 } |
|
1559 |
|
1560 if (line_pos == NPOS) |
|
1561 { |
5592
|
1562 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1563 continue; |
|
1564 } |
|
1565 |
|
1566 // chop " ; " |
|
1567 if (line.substr (line_pos, 1) == ":" |
|
1568 || line.substr (line_pos, 1) == ";") |
|
1569 line_pos = line.find_first_not_of ("\t ", line_pos + 1); |
|
1570 |
|
1571 if (line_pos == NPOS) |
|
1572 { |
5592
|
1573 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1574 continue; |
|
1575 } |
|
1576 |
|
1577 // chop " BLAH " |
|
1578 if (line.length () > line_pos + 2 |
|
1579 && line.find_first_of (_upper, line_pos) == line_pos |
|
1580 && line.find_first_of (_upper, line_pos+1) == line_pos + 1) |
|
1581 line_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1582 (_upper + "0123456789_", line_pos)); |
|
1583 |
|
1584 if (line_pos == NPOS) |
|
1585 { |
5592
|
1586 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1587 continue; |
|
1588 } |
|
1589 |
|
1590 // chop " blah --- " |
|
1591 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1592 (_alphanum, line_pos)); |
|
1593 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "-") |
|
1594 { |
|
1595 tmp_pos = line.find_first_not_of ("-", tmp_pos); |
|
1596 if (line.substr (tmp_pos, 1) == " " |
|
1597 || line.substr (tmp_pos, 1) == "\t") |
|
1598 line_pos = line.find_first_not_of ("\t ", tmp_pos); |
|
1599 } |
|
1600 |
|
1601 if (line_pos == NPOS) |
|
1602 { |
5592
|
1603 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1604 continue; |
|
1605 } |
|
1606 |
|
1607 // chop " blah <TAB> " |
|
1608 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1609 { |
|
1610 tmp_pos = line.find_first_not_of (" ", line.find_first_not_of |
|
1611 (_alphanum, line_pos)); |
|
1612 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "\t") |
|
1613 line_pos = line.find_first_not_of ("\t ", line.find_first_of |
|
1614 (")", tmp_pos) + 1); |
|
1615 } |
|
1616 |
|
1617 if (line_pos == NPOS) |
|
1618 { |
5592
|
1619 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1620 continue; |
|
1621 } |
|
1622 |
|
1623 // chop " blah " |
|
1624 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1625 { |
|
1626 tmp_pos = line.find_first_not_of (_alphanum, line_pos); |
|
1627 |
|
1628 if (tmp_pos != NPOS |
|
1629 && (line.substr (tmp_pos, 2) == "\t\t" |
|
1630 || line.substr (tmp_pos, 2) == "\t " |
|
1631 || line.substr (tmp_pos, 2) == " \t" |
|
1632 || line.substr (tmp_pos, 2) == " ")) |
|
1633 line_pos = line.find_first_not_of ("\t ", tmp_pos); |
|
1634 } |
|
1635 |
|
1636 if (line_pos == NPOS) |
|
1637 { |
5592
|
1638 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1639 continue; |
|
1640 } |
|
1641 |
|
1642 // skip blah \n or \n blah |
|
1643 // skip blank line |
|
1644 // skip "# !/usr/bin/octave" |
|
1645 if ((line.substr (line_pos , 2) == "or" |
|
1646 && line.find_first_not_of ("\n\t ", line_pos + 2) == NPOS) |
|
1647 || line.find_first_not_of ("\n\t ", line_pos) == NPOS |
|
1648 || line.substr (line_pos, 2) == "!/") |
|
1649 { |
5592
|
1650 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1651 continue; |
|
1652 } |
|
1653 |
|
1654 // Got the start of first sentence, break. |
|
1655 pos = pos + line_pos; |
|
1656 break; |
|
1657 } |
|
1658 |
|
1659 if (pos == NPOS) |
5738
|
1660 return retval; |
5447
|
1661 |
|
1662 // At start of real text. Get first line with the sentence |
|
1663 size_t new_pos = h.find_first_of ('\n', pos); |
|
1664 std::string line = h.substr (pos, new_pos-pos); |
|
1665 size_t dot_pos; |
|
1666 |
|
1667 while ((dot_pos = line.find_first_of ('.')) == NPOS) |
|
1668 { |
|
1669 // Trim trailing blanks on line |
|
1670 line = line.substr (0, line.find_last_not_of ("\n\t ") + 1); |
|
1671 |
|
1672 // Append next line |
|
1673 size_t tmp_pos = h.find_first_not_of ("\t ", new_pos + 1); |
|
1674 if (tmp_pos == NPOS || h.substr (tmp_pos, 1) == "\n") |
|
1675 break; |
|
1676 |
|
1677 new_pos = h.find_first_of ('\n', tmp_pos); |
|
1678 std::string next = h.substr (tmp_pos, new_pos-tmp_pos); |
|
1679 |
|
1680 if (short_sentence) |
|
1681 { |
|
1682 // Only add the next line if it terminates the sentence, then break |
|
1683 if ((tmp_pos = next.find_first_of ('.')) != NPOS) |
|
1684 { |
|
1685 line = line + " " + next; |
|
1686 dot_pos = line.find_first_of ('.'); |
|
1687 } |
|
1688 break; |
|
1689 } |
|
1690 else |
|
1691 line = line + " " + next; |
|
1692 } |
|
1693 |
|
1694 if (dot_pos == NPOS) |
5738
|
1695 retval = line; |
5447
|
1696 else |
5738
|
1697 retval = line.substr (0, dot_pos + 1); |
5447
|
1698 } |
5738
|
1699 |
|
1700 return retval; |
5447
|
1701 } |
|
1702 |
|
1703 static void |
|
1704 print_lookfor (const std::string& name, const std::string& line) |
|
1705 { |
|
1706 const size_t deflen = 20; |
|
1707 |
|
1708 size_t max_width = command_editor::terminal_cols () - deflen; |
|
1709 if (max_width < deflen) |
|
1710 max_width = deflen; |
|
1711 |
|
1712 size_t name_len = name.length (); |
|
1713 |
|
1714 size_t width = max_width; |
|
1715 if (name_len > deflen) |
|
1716 { |
|
1717 width = command_editor::terminal_cols () - name_len; |
|
1718 if (width < deflen) |
|
1719 width = deflen; |
|
1720 } |
|
1721 |
|
1722 size_t pad_len = deflen > name_len ? deflen - name_len + 1 : 1; |
|
1723 octave_stdout << name << std::string (pad_len, ' '); |
|
1724 |
|
1725 size_t pos = 0; |
|
1726 |
|
1727 while (1) |
|
1728 { |
|
1729 size_t new_pos = line.find_first_of ("\n\t ", pos); |
|
1730 size_t end_pos = new_pos; |
|
1731 |
|
1732 if (line.length () - pos < width) |
|
1733 new_pos = end_pos = NPOS; |
|
1734 else |
|
1735 while (new_pos != NPOS && new_pos - pos < width) |
|
1736 { |
|
1737 end_pos = new_pos; |
|
1738 new_pos = line.find_first_of ("\n\t ", new_pos + 1); |
|
1739 } |
|
1740 |
|
1741 octave_stdout << line.substr (pos, end_pos-pos) << std::endl; |
|
1742 |
|
1743 if (end_pos == NPOS) |
|
1744 break; |
|
1745 |
|
1746 pos = end_pos + 1; |
|
1747 width = max_width; |
|
1748 octave_stdout << std::string (deflen + 1, ' '); |
|
1749 } |
|
1750 } |
|
1751 |
|
1752 DEFCMD (lookfor, args, nargout, |
|
1753 "-*- texinfo -*-\n\ |
|
1754 @deffn {Command} lookfor @var{str}\n\ |
|
1755 @deffnx {Command} lookfor -all @var{str}\n\ |
|
1756 @deffnx {Function} {[@var{fun}, @var{helpstring}] = } lookfor (@var{str})\n\ |
|
1757 @deffnx {Function} {[@var{fun}, @var{helpstring}] = } lookfor ('-all', @var{str})\n\ |
5814
|
1758 Search for the string @var{str} in all of the functions found in the\n\ |
|
1759 function search path. By default @code{lookfor} searchs for @var{str}\n\ |
|
1760 in the first sentence of the help string of each function found. The entire\n\ |
|
1761 help string of each function found in the path can be search if\n\ |
5447
|
1762 the '-all' argument is supplied. All searches are case insensitive.\n\ |
|
1763 \n\ |
|
1764 Called with no output arguments, @code{lookfor} prints the list of matching\n\ |
|
1765 functions to the terminal. Otherwise the output arguments @var{fun} and\n\ |
|
1766 @var{helpstring} define the matching functions and the first sentence of\n\ |
|
1767 each of their help strings.\n\ |
|
1768 \n\ |
|
1769 Note that the ability of @code{lookfor} to correctly identify the first\n\ |
|
1770 sentence of the help of the functions is dependent on the format of the\n\ |
|
1771 functions help. All of the functions in octave itself will correctly\n\ |
|
1772 find the first sentence, but the same can not be guaranteed for other\n\ |
|
1773 functions. Therefore the use of the '-all' argument might be necessary\n\ |
|
1774 to find related functions that are not part of octave.\n\ |
5667
|
1775 @seealso{help, which}\n\ |
5642
|
1776 @end deffn") |
5447
|
1777 { |
|
1778 octave_value_list retval; |
|
1779 int nargin = args.length (); |
|
1780 bool first_sentence_only = true; |
|
1781 |
|
1782 if (nargin != 1 && nargin != 2) |
|
1783 { |
|
1784 usage ("lookfor"); |
|
1785 return retval; |
|
1786 } |
|
1787 |
|
1788 string_vector ret[2]; |
|
1789 |
|
1790 std::string txt; |
|
1791 |
|
1792 if (args(0).is_string ()) |
|
1793 { |
|
1794 txt = args(0).string_value (); |
|
1795 |
|
1796 if (nargin == 2) |
|
1797 { |
|
1798 if (args(1).is_string ()) |
|
1799 { |
|
1800 std::string tmp = args(1).string_value (); |
|
1801 |
|
1802 if (txt.substr(0,1) == "-") |
|
1803 { |
|
1804 txt = tmp; |
|
1805 tmp = args(0).string_value (); |
|
1806 } |
|
1807 |
|
1808 if (tmp == "-all") |
|
1809 first_sentence_only = false; |
|
1810 else |
|
1811 error ("lookfor: unrecognized option argument"); |
|
1812 } |
|
1813 else |
|
1814 error ("lookfor: arguments must be a string"); |
|
1815 } |
|
1816 } |
|
1817 else |
|
1818 error ("lookfor: argument must be a string"); |
|
1819 |
|
1820 if (!error_state) |
|
1821 { |
|
1822 // All tests in lower case |
5768
|
1823 std::transform (txt.begin (), txt.end (), txt.begin (), tolower); |
5447
|
1824 |
|
1825 help_list *ptr = keyword_help (); |
|
1826 while (ptr->name) |
|
1827 { |
|
1828 std::string name = ptr->name; |
|
1829 std::string h = ptr->help; |
|
1830 |
5592
|
1831 if (name.find (txt) != NPOS) |
5447
|
1832 { |
|
1833 if (nargout) |
|
1834 { |
|
1835 ret[0].append (name); |
|
1836 ret[1].append (first_help_sentence (h)); |
|
1837 } |
|
1838 else |
|
1839 print_lookfor (name, first_help_sentence (h)); |
|
1840 } |
5592
|
1841 else |
|
1842 { |
|
1843 std::string s; |
|
1844 |
|
1845 if (first_sentence_only) |
|
1846 s = first_help_sentence (h); |
|
1847 else |
|
1848 s = h; |
|
1849 |
5768
|
1850 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1851 |
|
1852 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1853 { |
|
1854 if (nargout) |
|
1855 { |
|
1856 ret[0].append (name); |
|
1857 ret[1].append (first_help_sentence (h)); |
|
1858 } |
|
1859 else |
|
1860 print_lookfor (name, first_help_sentence (h)); |
|
1861 } |
|
1862 } |
5447
|
1863 |
|
1864 OCTAVE_QUIT; |
|
1865 |
|
1866 ptr++; |
|
1867 } |
|
1868 |
|
1869 ptr = operator_help (); |
|
1870 while (ptr->name) |
|
1871 { |
|
1872 std::string name = ptr->name; |
|
1873 std::string h = ptr->help; |
|
1874 |
5592
|
1875 if (name.find (txt) != NPOS) |
5447
|
1876 { |
|
1877 if (nargout) |
|
1878 { |
|
1879 ret[0].append (name); |
|
1880 ret[1].append (first_help_sentence (h)); |
|
1881 } |
|
1882 else |
|
1883 print_lookfor (name, first_help_sentence (h)); |
|
1884 } |
5592
|
1885 else |
|
1886 { |
|
1887 std::string s; |
|
1888 if (first_sentence_only) |
|
1889 s = first_help_sentence (h); |
|
1890 else |
|
1891 s = h; |
|
1892 |
5768
|
1893 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1894 |
|
1895 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1896 { |
|
1897 if (nargout) |
|
1898 { |
|
1899 ret[0].append (name); |
|
1900 ret[1].append (first_help_sentence (h)); |
|
1901 } |
|
1902 else |
|
1903 print_lookfor (name, first_help_sentence (h)); |
|
1904 } |
|
1905 } |
5447
|
1906 |
|
1907 OCTAVE_QUIT; |
|
1908 |
|
1909 ptr++; |
|
1910 } |
|
1911 |
|
1912 // Check the symbol record table |
|
1913 string_vector names |
|
1914 = fbi_sym_tab->name_list (string_vector (), true); |
|
1915 |
|
1916 for (octave_idx_type i = 0; i < names.length (); i++) |
|
1917 { |
|
1918 std::string name = names (i); |
|
1919 |
|
1920 OCTAVE_QUIT; |
|
1921 |
|
1922 symbol_record *sr = lookup_by_name (name, 0); |
5738
|
1923 if (sr && sr->is_defined () |
|
1924 && sr->type_name () != "overloaded function") |
5447
|
1925 { |
|
1926 std::string h = sr->help (); |
|
1927 |
5592
|
1928 if (name.find (txt) != NPOS) |
5447
|
1929 { |
|
1930 if (nargout) |
|
1931 { |
|
1932 ret[0].append (name); |
|
1933 ret[1].append (first_help_sentence (h)); |
|
1934 } |
|
1935 else |
|
1936 print_lookfor (name, first_help_sentence (h)); |
|
1937 } |
5592
|
1938 else |
|
1939 { |
|
1940 std::string s; |
|
1941 |
|
1942 if (first_sentence_only) |
|
1943 s = first_help_sentence (h); |
|
1944 else |
|
1945 s = h; |
|
1946 |
5768
|
1947 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
1948 |
|
1949 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1950 { |
|
1951 if (nargout) |
|
1952 { |
|
1953 ret[0].append (name); |
|
1954 ret[1].append (first_help_sentence (h)); |
|
1955 } |
|
1956 else |
|
1957 print_lookfor (name, first_help_sentence (h)); |
|
1958 } |
|
1959 } |
5447
|
1960 } |
|
1961 } |
|
1962 |
5832
|
1963 string_vector dirs = load_path::dirs (); |
5447
|
1964 |
|
1965 int len = dirs.length (); |
|
1966 |
|
1967 for (int i = 0; i < len; i++) |
|
1968 { |
5832
|
1969 names = load_path::files (dirs[i]); |
5447
|
1970 |
|
1971 if (! names.empty ()) |
|
1972 { |
|
1973 for (int j = 0; j < names.length (); j++) |
|
1974 { |
|
1975 std::string name = names (j); |
|
1976 |
|
1977 OCTAVE_QUIT; |
|
1978 |
|
1979 // Strip extension |
|
1980 size_t l = name.length (); |
|
1981 if (l > 4 && name.substr (l-4) == ".oct") |
|
1982 name = name.substr (0, l - 4); |
|
1983 else if (l > 2 && name.substr (l-2) == ".m") |
|
1984 name = name.substr (0, l - 2); |
|
1985 else |
|
1986 continue; |
|
1987 |
|
1988 // Check if already in symbol table |
|
1989 symbol_record *sr = fbi_sym_tab->lookup (name); |
|
1990 |
|
1991 if (!sr) |
|
1992 { |
|
1993 // Check if this version is first in the path |
|
1994 |
5832
|
1995 std::string file_name = load_path::find_fcn (name); |
|
1996 |
|
1997 std::string dir = dirs[i] + file_ops::dir_sep_str; |
|
1998 |
|
1999 if (file_name == dir + name + ".oct" |
|
2000 || file_name == dir + name + ".m") |
5447
|
2001 { |
5484
|
2002 bool symbol_found; |
|
2003 |
5592
|
2004 std::string h; |
5832
|
2005 if (file_name == dir + name + ".oct") |
5592
|
2006 { |
|
2007 // oct-file. Must load to get help |
|
2008 sr = lookup_by_name (name, false); |
5447
|
2009 |
5592
|
2010 if (sr && sr->is_defined ()) |
|
2011 h = sr->help (); |
|
2012 } |
5447
|
2013 else |
5592
|
2014 h = get_help_from_file (file_name, symbol_found); |
5447
|
2015 |
5592
|
2016 if (name.find (txt) != NPOS) |
5447
|
2017 { |
|
2018 if (nargout) |
|
2019 { |
|
2020 ret[0].append (name); |
|
2021 ret[1].append (first_help_sentence (h)); |
|
2022 } |
|
2023 else |
|
2024 print_lookfor (name, first_help_sentence (h)); |
|
2025 } |
5592
|
2026 else |
|
2027 { |
|
2028 std::string s; |
|
2029 if (first_sentence_only) |
|
2030 s = first_help_sentence (h); |
|
2031 else |
|
2032 s = h; |
|
2033 |
5768
|
2034 std::transform (s.begin (), s.end (), s.begin (), tolower); |
5592
|
2035 |
|
2036 if (s.length () > 0 && s.find (txt) != NPOS) |
|
2037 { |
|
2038 if (nargout) |
|
2039 { |
|
2040 ret[0].append (name); |
|
2041 ret[1].append (first_help_sentence (h)); |
|
2042 } |
|
2043 else |
|
2044 print_lookfor (name, first_help_sentence (h)); |
|
2045 } |
|
2046 } |
|
2047 } |
|
2048 } |
|
2049 |
|
2050 // Check if this function has autoloaded functions attached to it |
5832
|
2051 std::string file_name = load_path::find_fcn (name); |
|
2052 |
5592
|
2053 string_vector autoload_fcns = reverse_lookup_autoload (file_name); |
|
2054 |
|
2055 if (! autoload_fcns.empty ()) |
|
2056 { |
|
2057 for (int k = 0; k < autoload_fcns.length (); k++) |
|
2058 { |
|
2059 std::string aname = autoload_fcns (k); |
|
2060 |
|
2061 // Check if already in symbol table |
|
2062 sr = fbi_sym_tab->lookup (aname); |
|
2063 |
|
2064 if (!sr) |
|
2065 { |
|
2066 // Must load to get help |
5738
|
2067 sr = lookup_by_name (aname, false); |
5592
|
2068 |
|
2069 std::string h; |
|
2070 if (sr && sr->is_defined ()) |
|
2071 h = sr->help (); |
|
2072 |
|
2073 if (aname.find (txt) != NPOS) |
|
2074 { |
|
2075 if (nargout) |
|
2076 { |
|
2077 ret[0].append (aname); |
|
2078 ret[1].append (first_help_sentence (h)); |
|
2079 } |
|
2080 else |
|
2081 print_lookfor (aname, first_help_sentence (h)); |
|
2082 } |
|
2083 else |
|
2084 { |
|
2085 std::string s; |
|
2086 if (first_sentence_only) |
|
2087 s = first_help_sentence (h); |
|
2088 else |
|
2089 s = h; |
|
2090 |
5768
|
2091 std::transform (s.begin (), s.end (), s.begin (), |
5592
|
2092 tolower); |
|
2093 |
|
2094 if (s.length () > 0 && s.find (txt) != NPOS) |
|
2095 { |
|
2096 if (nargout) |
|
2097 { |
|
2098 ret[0].append (aname); |
|
2099 ret[1].append (first_help_sentence (h)); |
|
2100 } |
|
2101 else |
|
2102 print_lookfor (aname, first_help_sentence (h)); |
|
2103 } |
|
2104 } |
|
2105 } |
5447
|
2106 } |
|
2107 } |
|
2108 } |
|
2109 } |
|
2110 } |
|
2111 |
|
2112 if (nargout != 0) |
|
2113 { |
|
2114 retval (1) = ret[1]; |
|
2115 retval (0) = ret[0]; |
|
2116 } |
|
2117 } |
|
2118 else |
|
2119 { |
|
2120 error ("lookfor: argument must be a string"); |
|
2121 } |
|
2122 |
|
2123 return retval; |
|
2124 } |
|
2125 |
5794
|
2126 DEFUN (info_file, args, nargout, |
|
2127 "-*- texinfo -*-\n\ |
|
2128 @deftypefn {Built-in Function} {@var{val} =} info_file ()\n\ |
|
2129 @deftypefnx {Built-in Function} {@var{old_val} =} info_file (@var{new_val})\n\ |
|
2130 Query or set the internal variable that specifies the name of the\n\ |
|
2131 Octave info file. The default value is\n\ |
|
2132 @code{\"@var{octave-home}/info/octave.info\"}, in\n\ |
|
2133 which @var{octave-home} is the directory where all of Octave is installed.\n\ |
|
2134 @seealso{info_program, doc, help, makeinfo_program}\n\ |
|
2135 @end deftypefn") |
2202
|
2136 { |
5794
|
2137 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_file); |
2202
|
2138 } |
|
2139 |
5794
|
2140 DEFUN (info_program, args, nargout, |
|
2141 "-*- texinfo -*-\n\ |
|
2142 @deftypefn {Built-in Function} {@var{val} =} info_program ()\n\ |
|
2143 @deftypefnx {Built-in Function} {@var{old_val} =} info_program (@var{new_val})\n\ |
|
2144 Query or set the internal variable that specifies the name of the\n\ |
|
2145 info program to run. The default initial value is\n\ |
3686
|
2146 @code{\"@var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}/info\"}\n\ |
|
2147 in which @var{octave-home} is the directory where all of Octave is\n\ |
|
2148 installed, @var{version} is the Octave version number, and @var{arch}\n\ |
|
2149 is the system type (for example, @code{i686-pc-linux-gnu}). The\n\ |
|
2150 default initial value may be overridden by the environment variable\n\ |
|
2151 @code{OCTAVE_INFO_PROGRAM}, or the command line argument\n\ |
5794
|
2152 @code{--info-program NAME}.\n\ |
|
2153 @seealso{info_file, doc, help, makeinfo_program}\n\ |
|
2154 @end deftypefn") |
|
2155 { |
|
2156 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (info_program); |
|
2157 } |
3686
|
2158 |
5794
|
2159 DEFUN (makeinfo_program, args, nargout, |
|
2160 "-*- texinfo -*-\n\ |
|
2161 @deftypefn {Built-in Function} {@var{val} =} makeinfo_program ()\n\ |
|
2162 @deftypefnx {Built-in Function} {@var{old_val} =} makeinfo_program (@var{new_val})\n\ |
|
2163 Query or set the internal variable that specifies the name of the\n\ |
|
2164 makeinfo program that Octave runs to format help text containing\n\ |
|
2165 Texinfo markup commands. The default initial value is @code{\"makeinfo\"}.\n\ |
|
2166 @seealso{info_file, info_program, doc, help}\n\ |
|
2167 @end deftypefn") |
|
2168 { |
|
2169 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (makeinfo_program); |
|
2170 } |
2202
|
2171 |
5794
|
2172 DEFUN (suppress_verbose_help_message, args, nargout, |
|
2173 "-*- texinfo -*-\n\ |
|
2174 @deftypefn {Built-in Function} {@var{val} =} suppress_verbose_help_message ()\n\ |
|
2175 @deftypefnx {Built-in Function} {@var{old_val} =} suppress_verbose_help_message (@var{new_val})\n\ |
|
2176 Query or set the internal vaiable that controls whether Octave\n\ |
|
2177 will add additional help information to the end of the output from\n\ |
3332
|
2178 the @code{help} command and usage messages for built-in commands.\n\ |
5794
|
2179 @end deftypefn") |
|
2180 { |
|
2181 return SET_INTERNAL_VARIABLE (suppress_verbose_help_message); |
2189
|
2182 } |
|
2183 |
1
|
2184 /* |
|
2185 ;;; Local Variables: *** |
|
2186 ;;; mode: C++ *** |
|
2187 ;;; End: *** |
|
2188 */ |