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