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