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