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