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