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