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", |
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\ |
3333
|
932 @end deffn") |
529
|
933 { |
2086
|
934 octave_value_list retval; |
529
|
935 |
1755
|
936 int argc = args.length () + 1; |
|
937 |
1968
|
938 string_vector argv = args.make_argv ("help"); |
1755
|
939 |
|
940 if (error_state) |
|
941 return retval; |
529
|
942 |
|
943 if (argc == 1) |
3014
|
944 simple_help (); |
529
|
945 else |
|
946 { |
1755
|
947 if (argv[1] == "-i") |
3014
|
948 help_from_info (argv, 2, argc); |
529
|
949 else |
3014
|
950 builtin_help (argc, argv); |
529
|
951 } |
|
952 |
|
953 return retval; |
|
954 } |
|
955 |
3355
|
956 static void |
3523
|
957 do_type (std::ostream& os, const std::string& name, bool pr_type_info, |
3355
|
958 bool quiet, bool pr_orig_txt) |
|
959 { |
|
960 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
961 |
|
962 if (sym_rec && sym_rec->is_defined ()) |
3356
|
963 sym_rec->type (os, pr_type_info, quiet, pr_orig_txt); |
3355
|
964 else |
|
965 { |
3523
|
966 std::string ff = fcn_file_in_path (name); |
3355
|
967 |
|
968 if (! ff.empty ()) |
|
969 { |
3538
|
970 std::ifstream fs (ff.c_str (), std::ios::in); |
3355
|
971 |
|
972 if (fs) |
|
973 { |
|
974 if (pr_type_info && ! quiet) |
|
975 os << name << " is the script file: " << ff << "\n\n"; |
|
976 |
|
977 char ch; |
|
978 |
|
979 while (fs.get (ch)) |
|
980 os << ch; |
|
981 } |
|
982 else |
|
983 os << "unable to open `" << ff << "' for reading!\n"; |
|
984 } |
|
985 else |
|
986 error ("type: `%s' undefined", name.c_str ()); |
|
987 } |
|
988 } |
|
989 |
4208
|
990 DEFCMD (type, args, nargout, |
3361
|
991 "-*- texinfo -*-\n\ |
|
992 \n\ |
|
993 @deffn {Command} type options name @dots{}\n\ |
|
994 Display the definition of each @var{name} that refers to a function.\n\ |
|
995 \n\ |
|
996 Normally also displays if each @var{name} is user-defined or builtin;\n\ |
|
997 the @code{-q} option suppresses this behaviour.\n\ |
581
|
998 \n\ |
3361
|
999 Currently, Octave can only display functions that can be compiled\n\ |
|
1000 cleanly, because it uses its internal representation of the function to\n\ |
|
1001 recreate the program text.\n\ |
|
1002 \n\ |
|
1003 Comments are not displayed because Octave's parser currently discards\n\ |
|
1004 them as it converts the text of a function file to its internal\n\ |
|
1005 representation. This problem may be fixed in a future release.\n\ |
|
1006 @end deffn") |
581
|
1007 { |
3584
|
1008 octave_value retval; |
1588
|
1009 |
1755
|
1010 int argc = args.length () + 1; |
|
1011 |
1968
|
1012 string_vector argv = args.make_argv ("type"); |
1755
|
1013 |
3355
|
1014 if (! error_state) |
581
|
1015 { |
3355
|
1016 if (argc > 1) |
|
1017 { |
|
1018 // XXX FIXME XXX -- we should really use getopt () |
2532
|
1019 |
3355
|
1020 bool quiet = false; |
|
1021 bool pr_orig_txt = true; |
2532
|
1022 |
3355
|
1023 int idx; |
581
|
1024 |
3355
|
1025 for (idx = 1; idx < argc; idx++) |
1281
|
1026 { |
3355
|
1027 if (argv[idx] == "-q" || argv[idx] == "-quiet") |
|
1028 quiet = true; |
|
1029 else if (argv[idx] == "-t" || argv[idx] == "-transformed") |
|
1030 pr_orig_txt = false; |
|
1031 else |
|
1032 break; |
1281
|
1033 } |
|
1034 |
3355
|
1035 if (idx < argc) |
|
1036 { |
4051
|
1037 OSSTREAM output_buf; |
581
|
1038 |
3355
|
1039 for (int i = idx; i < argc; i++) |
581
|
1040 { |
3523
|
1041 std::string id = argv[i]; |
2534
|
1042 |
3355
|
1043 if (nargout == 0) |
|
1044 do_type (octave_stdout, id, true, quiet, pr_orig_txt); |
|
1045 else |
|
1046 do_type (output_buf, id, false, quiet, pr_orig_txt); |
581
|
1047 |
3355
|
1048 if (error_state) |
|
1049 goto abort; |
581
|
1050 } |
|
1051 |
3584
|
1052 if (nargout != 0) |
625
|
1053 { |
4051
|
1054 output_buf << OSSTREAM_ENDS; |
3164
|
1055 |
4051
|
1056 retval = OSSTREAM_STR (output_buf); |
3164
|
1057 |
4051
|
1058 OSSTREAM_FREEZE (output_buf); |
625
|
1059 } |
581
|
1060 } |
|
1061 else |
3355
|
1062 print_usage ("type"); |
|
1063 } |
|
1064 else |
|
1065 print_usage ("type"); |
|
1066 } |
3141
|
1067 |
3355
|
1068 abort: |
581
|
1069 |
|
1070 return retval; |
|
1071 } |
|
1072 |
3536
|
1073 static std::string |
3523
|
1074 do_which (const std::string& name) |
3355
|
1075 { |
3523
|
1076 std::string retval; |
3355
|
1077 |
|
1078 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1079 |
|
1080 if (sym_rec && sym_rec->is_defined ()) |
|
1081 retval = sym_rec->which (); |
|
1082 else |
|
1083 { |
3523
|
1084 std::string path = fcn_file_in_path (name); |
3355
|
1085 |
|
1086 if (! path.empty ()) |
|
1087 retval = path; |
|
1088 else |
|
1089 retval = "undefined"; |
|
1090 } |
|
1091 |
|
1092 return retval; |
|
1093 } |
|
1094 |
|
1095 static void |
3523
|
1096 do_which (std::ostream& os, const std::string& name) |
3355
|
1097 { |
|
1098 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
1099 |
|
1100 if (sym_rec && sym_rec->is_defined ()) |
|
1101 sym_rec->which (os); |
|
1102 else |
|
1103 { |
3523
|
1104 std::string path = fcn_file_in_path (name); |
3355
|
1105 |
|
1106 if (! path.empty ()) |
|
1107 os << "which: `" << name << "' is the script file\n" |
|
1108 << path << "\n"; |
|
1109 else |
|
1110 os << "which: `" << name << "' is undefined\n"; |
|
1111 } |
|
1112 } |
|
1113 |
4208
|
1114 DEFCMD (which, args, nargout, |
3361
|
1115 "-*- texinfo -*-\n\ |
|
1116 @deffn {Command} which name @dots{}\n\ |
|
1117 Display the type of each @var{name}. If @var{name} is defined from a\n\ |
|
1118 function file, the full name of the file is also displayed.\n\ |
|
1119 @end deffn") |
581
|
1120 { |
2086
|
1121 octave_value_list retval; |
581
|
1122 |
1968
|
1123 string_vector argv = args.make_argv ("which"); |
1755
|
1124 |
3355
|
1125 if (! error_state) |
|
1126 { |
|
1127 int argc = argv.length (); |
581
|
1128 |
|
1129 if (nargout > 0) |
|
1130 retval.resize (argc-1, Matrix ()); |
|
1131 |
3355
|
1132 if (argc > 1) |
581
|
1133 { |
3355
|
1134 for (int i = 1; i < argc; i++) |
581
|
1135 { |
3523
|
1136 std::string id = argv[i]; |
3141
|
1137 |
3355
|
1138 if (nargout == 0) |
|
1139 do_which (octave_stdout, id); |
581
|
1140 else |
3355
|
1141 retval(i-1) = do_which (id); |
581
|
1142 } |
|
1143 } |
3355
|
1144 else |
|
1145 print_usage (argv[0]); |
581
|
1146 } |
|
1147 |
|
1148 return retval; |
|
1149 } |
|
1150 |
5447
|
1151 // XXX FIXME XXX |
|
1152 // This function attempts to find the first sentence of a help string, though |
|
1153 // given that the user can create the help in an arbitrary format, your |
|
1154 // success might vary.. it works much better with help string formated in |
|
1155 // texinfo. Using regex might make this function much simpler. |
|
1156 |
|
1157 std::string |
|
1158 first_help_sentence (const std::string& h, bool short_sentence = true) |
|
1159 { |
|
1160 size_t pos = 0; |
|
1161 |
|
1162 if (looks_like_texinfo (h, pos)) |
5592
|
1163 { |
|
1164 // Get the parsed help string. |
5447
|
1165 pos = 0; |
|
1166 OSSTREAM os; |
|
1167 display_help_text (os, h); |
|
1168 std::string h2 = os.str (); |
|
1169 |
|
1170 while (1) |
|
1171 { |
|
1172 // Skip leading whitespace and get new line |
|
1173 pos = h2.find_first_not_of ("\n\t ", pos); |
|
1174 |
|
1175 if (pos == NPOS) |
|
1176 break; |
|
1177 |
|
1178 size_t new_pos = h2.find_first_of ('\n', pos); |
|
1179 std::string line = h2.substr (pos, new_pos-pos); |
|
1180 |
|
1181 // Skip lines starting in "-" |
|
1182 if (line.find_first_of ('-') == 0) |
|
1183 { |
|
1184 pos = new_pos + 1; |
|
1185 continue; |
|
1186 } |
|
1187 |
|
1188 break; |
|
1189 } |
|
1190 |
|
1191 if (pos == NPOS) |
|
1192 return std::string (); |
|
1193 |
|
1194 // At start of real text. Get first line with the sentence |
|
1195 size_t new_pos = h2.find_first_of ('\n', pos); |
|
1196 std::string line = h2.substr (pos, new_pos-pos); |
|
1197 size_t dot_pos; |
|
1198 |
|
1199 while ((dot_pos = line.find_first_of ('.')) == NPOS) |
|
1200 { |
|
1201 // Trim trailing blanks on line |
|
1202 line.substr (0, line.find_last_not_of ("\n\t ") + 1); |
|
1203 |
|
1204 // Append next line |
|
1205 size_t tmp_pos = h2.find_first_not_of ("\n\t ", new_pos + 1); |
|
1206 if (tmp_pos == NPOS || h2.substr (tmp_pos, 1) == "\n") |
|
1207 break; |
|
1208 |
|
1209 new_pos = h2.find_first_of ('\n', tmp_pos); |
|
1210 std::string next = h2.substr (tmp_pos, new_pos-tmp_pos); |
|
1211 |
|
1212 if (short_sentence) |
|
1213 { |
|
1214 if ((tmp_pos = next.find_first_of ('.')) != NPOS) |
|
1215 { |
|
1216 line = line + " " + next; |
|
1217 dot_pos = line.find_first_of ('.'); |
|
1218 } |
|
1219 break; |
|
1220 } |
|
1221 else |
|
1222 line = line + " " + next; |
|
1223 } |
|
1224 |
|
1225 if (dot_pos == NPOS) |
|
1226 return line; |
|
1227 else |
|
1228 return line.substr (0, dot_pos + 1); |
|
1229 } |
|
1230 else |
|
1231 { |
|
1232 std::string _upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
|
1233 std::string _lower = "abcdefghijklmnopqrstuvwxyz"; |
|
1234 std::string _alpha = _upper + _lower + "_"; |
|
1235 std::string _alphanum = _alpha + "1234567890"; |
|
1236 pos = 0; |
|
1237 |
|
1238 while (1) |
|
1239 { |
|
1240 // Skip leading whitespace and get new line |
|
1241 pos = h.find_first_not_of ("\n\t ", pos); |
|
1242 |
|
1243 if (pos == NPOS) |
|
1244 break; |
|
1245 |
|
1246 size_t new_pos = h.find_first_of ('\n', pos); |
|
1247 std::string line = h.substr (pos, new_pos-pos); |
|
1248 |
|
1249 // Make a lower case copy to simplify some tests |
|
1250 std::string lower = line; |
|
1251 transform (lower.begin (), lower.end (), lower.begin (), tolower); |
|
1252 |
|
1253 // Skip lines starting in "-" or "Usage" |
|
1254 if (lower.find_first_of ('-') == 0 |
|
1255 || lower.substr (0, 5) == "usage") |
|
1256 { |
5592
|
1257 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1258 continue; |
|
1259 } |
|
1260 |
|
1261 size_t line_pos = 0; |
|
1262 size_t tmp_pos = 0; |
|
1263 |
|
1264 // chop " blah : " |
|
1265 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1266 (_alphanum, line_pos)); |
|
1267 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == ":") |
|
1268 line_pos = line.find_first_not_of ("\t ", tmp_pos + 1); |
|
1269 |
|
1270 if (line_pos == NPOS) |
|
1271 { |
5592
|
1272 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1273 continue; |
|
1274 } |
|
1275 |
|
1276 // chop " function " |
|
1277 if (lower.substr (line_pos, 8) == "function") |
|
1278 line_pos = line.find_first_not_of ("\t ", line_pos + 8); |
|
1279 |
|
1280 if (line_pos == NPOS) |
|
1281 { |
5592
|
1282 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1283 continue; |
|
1284 } |
|
1285 |
|
1286 // chop " [a,b] = " |
|
1287 if (line.substr (line_pos, 1) == "[") |
|
1288 { |
|
1289 tmp_pos = line.find_first_not_of |
|
1290 ("\t ", line.find_first_of ("]", line_pos) + 1); |
|
1291 |
|
1292 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "=") |
|
1293 line_pos = line.find_first_not_of ("\t ",tmp_pos + 1); |
|
1294 } |
|
1295 |
|
1296 if (line_pos == NPOS) |
|
1297 { |
5592
|
1298 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1299 continue; |
|
1300 } |
|
1301 |
|
1302 // chop " a = " |
|
1303 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1304 { |
|
1305 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1306 (_alphanum, line_pos)); |
|
1307 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "=") |
|
1308 line_pos = line.find_first_not_of ("\t ", tmp_pos + 1); |
|
1309 } |
|
1310 |
|
1311 if (line_pos == NPOS) |
|
1312 { |
|
1313 pos = new_pos + 1; |
|
1314 continue; |
|
1315 } |
|
1316 |
|
1317 // chop " f(x) " |
|
1318 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1319 { |
|
1320 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1321 (_alphanum, line_pos)); |
|
1322 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "(") |
|
1323 line_pos = line.find_first_not_of ("\t ", line.find_first_of |
|
1324 (")", tmp_pos) + 1); |
|
1325 } |
|
1326 |
|
1327 if (line_pos == NPOS) |
|
1328 { |
5592
|
1329 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1330 continue; |
|
1331 } |
|
1332 |
|
1333 // chop " ; " |
|
1334 if (line.substr (line_pos, 1) == ":" |
|
1335 || line.substr (line_pos, 1) == ";") |
|
1336 line_pos = line.find_first_not_of ("\t ", line_pos + 1); |
|
1337 |
|
1338 if (line_pos == NPOS) |
|
1339 { |
5592
|
1340 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1341 continue; |
|
1342 } |
|
1343 |
|
1344 // chop " BLAH " |
|
1345 if (line.length () > line_pos + 2 |
|
1346 && line.find_first_of (_upper, line_pos) == line_pos |
|
1347 && line.find_first_of (_upper, line_pos+1) == line_pos + 1) |
|
1348 line_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1349 (_upper + "0123456789_", line_pos)); |
|
1350 |
|
1351 if (line_pos == NPOS) |
|
1352 { |
5592
|
1353 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1354 continue; |
|
1355 } |
|
1356 |
|
1357 // chop " blah --- " |
|
1358 tmp_pos = line.find_first_not_of ("\t ", line.find_first_not_of |
|
1359 (_alphanum, line_pos)); |
|
1360 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "-") |
|
1361 { |
|
1362 tmp_pos = line.find_first_not_of ("-", tmp_pos); |
|
1363 if (line.substr (tmp_pos, 1) == " " |
|
1364 || line.substr (tmp_pos, 1) == "\t") |
|
1365 line_pos = line.find_first_not_of ("\t ", tmp_pos); |
|
1366 } |
|
1367 |
|
1368 if (line_pos == NPOS) |
|
1369 { |
5592
|
1370 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1371 continue; |
|
1372 } |
|
1373 |
|
1374 // chop " blah <TAB> " |
|
1375 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1376 { |
|
1377 tmp_pos = line.find_first_not_of (" ", line.find_first_not_of |
|
1378 (_alphanum, line_pos)); |
|
1379 if (tmp_pos != NPOS && line.substr (tmp_pos, 1) == "\t") |
|
1380 line_pos = line.find_first_not_of ("\t ", line.find_first_of |
|
1381 (")", tmp_pos) + 1); |
|
1382 } |
|
1383 |
|
1384 if (line_pos == NPOS) |
|
1385 { |
5592
|
1386 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1387 continue; |
|
1388 } |
|
1389 |
|
1390 // chop " blah " |
|
1391 if (line.find_first_not_of (_alpha, line_pos) != line_pos) |
|
1392 { |
|
1393 tmp_pos = line.find_first_not_of (_alphanum, line_pos); |
|
1394 |
|
1395 if (tmp_pos != NPOS |
|
1396 && (line.substr (tmp_pos, 2) == "\t\t" |
|
1397 || line.substr (tmp_pos, 2) == "\t " |
|
1398 || line.substr (tmp_pos, 2) == " \t" |
|
1399 || line.substr (tmp_pos, 2) == " ")) |
|
1400 line_pos = line.find_first_not_of ("\t ", tmp_pos); |
|
1401 } |
|
1402 |
|
1403 if (line_pos == NPOS) |
|
1404 { |
5592
|
1405 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1406 continue; |
|
1407 } |
|
1408 |
|
1409 // skip blah \n or \n blah |
|
1410 // skip blank line |
|
1411 // skip "# !/usr/bin/octave" |
|
1412 if ((line.substr (line_pos , 2) == "or" |
|
1413 && line.find_first_not_of ("\n\t ", line_pos + 2) == NPOS) |
|
1414 || line.find_first_not_of ("\n\t ", line_pos) == NPOS |
|
1415 || line.substr (line_pos, 2) == "!/") |
|
1416 { |
5592
|
1417 pos = (new_pos == NPOS ? NPOS : new_pos + 1); |
5447
|
1418 continue; |
|
1419 } |
|
1420 |
|
1421 // Got the start of first sentence, break. |
|
1422 pos = pos + line_pos; |
|
1423 break; |
|
1424 } |
|
1425 |
|
1426 if (pos == NPOS) |
|
1427 return std::string (); |
|
1428 |
|
1429 // At start of real text. Get first line with the sentence |
|
1430 size_t new_pos = h.find_first_of ('\n', pos); |
|
1431 std::string line = h.substr (pos, new_pos-pos); |
|
1432 size_t dot_pos; |
|
1433 |
|
1434 while ((dot_pos = line.find_first_of ('.')) == NPOS) |
|
1435 { |
|
1436 // Trim trailing blanks on line |
|
1437 line = line.substr (0, line.find_last_not_of ("\n\t ") + 1); |
|
1438 |
|
1439 // Append next line |
|
1440 size_t tmp_pos = h.find_first_not_of ("\t ", new_pos + 1); |
|
1441 if (tmp_pos == NPOS || h.substr (tmp_pos, 1) == "\n") |
|
1442 break; |
|
1443 |
|
1444 new_pos = h.find_first_of ('\n', tmp_pos); |
|
1445 std::string next = h.substr (tmp_pos, new_pos-tmp_pos); |
|
1446 |
|
1447 if (short_sentence) |
|
1448 { |
|
1449 // Only add the next line if it terminates the sentence, then break |
|
1450 if ((tmp_pos = next.find_first_of ('.')) != NPOS) |
|
1451 { |
|
1452 line = line + " " + next; |
|
1453 dot_pos = line.find_first_of ('.'); |
|
1454 } |
|
1455 break; |
|
1456 } |
|
1457 else |
|
1458 line = line + " " + next; |
|
1459 } |
|
1460 |
|
1461 if (dot_pos == NPOS) |
|
1462 return line; |
|
1463 else |
|
1464 return line.substr (0, dot_pos + 1); |
|
1465 } |
|
1466 } |
|
1467 |
|
1468 static void |
|
1469 print_lookfor (const std::string& name, const std::string& line) |
|
1470 { |
|
1471 const size_t deflen = 20; |
|
1472 |
|
1473 size_t max_width = command_editor::terminal_cols () - deflen; |
|
1474 if (max_width < deflen) |
|
1475 max_width = deflen; |
|
1476 |
|
1477 size_t name_len = name.length (); |
|
1478 |
|
1479 size_t width = max_width; |
|
1480 if (name_len > deflen) |
|
1481 { |
|
1482 width = command_editor::terminal_cols () - name_len; |
|
1483 if (width < deflen) |
|
1484 width = deflen; |
|
1485 } |
|
1486 |
|
1487 size_t pad_len = deflen > name_len ? deflen - name_len + 1 : 1; |
|
1488 octave_stdout << name << std::string (pad_len, ' '); |
|
1489 |
|
1490 size_t pos = 0; |
|
1491 |
|
1492 while (1) |
|
1493 { |
|
1494 size_t new_pos = line.find_first_of ("\n\t ", pos); |
|
1495 size_t end_pos = new_pos; |
|
1496 |
|
1497 if (line.length () - pos < width) |
|
1498 new_pos = end_pos = NPOS; |
|
1499 else |
|
1500 while (new_pos != NPOS && new_pos - pos < width) |
|
1501 { |
|
1502 end_pos = new_pos; |
|
1503 new_pos = line.find_first_of ("\n\t ", new_pos + 1); |
|
1504 } |
|
1505 |
|
1506 octave_stdout << line.substr (pos, end_pos-pos) << std::endl; |
|
1507 |
|
1508 if (end_pos == NPOS) |
|
1509 break; |
|
1510 |
|
1511 pos = end_pos + 1; |
|
1512 width = max_width; |
|
1513 octave_stdout << std::string (deflen + 1, ' '); |
|
1514 } |
|
1515 } |
|
1516 |
|
1517 DEFCMD (lookfor, args, nargout, |
|
1518 "-*- texinfo -*-\n\ |
|
1519 @deffn {Command} lookfor @var{str}\n\ |
|
1520 @deffnx {Command} lookfor -all @var{str}\n\ |
|
1521 @deffnx {Function} {[@var{fun}, @var{helpstring}] = } lookfor (@var{str})\n\ |
|
1522 @deffnx {Function} {[@var{fun}, @var{helpstring}] = } lookfor ('-all', @var{str})\n\ |
|
1523 Search for the string @var{str} in all of the functions found in\n\ |
|
1524 @var{LOADPATH}. By default @code{lookfor} searchs for @var{str} in the\n\ |
|
1525 first sentence of the help string of each function found. The entire\n\ |
|
1526 help string of each function found of @var{LOADPATH} can be search if\n\ |
|
1527 the '-all' argument is supplied. All searches are case insensitive.\n\ |
|
1528 \n\ |
|
1529 Called with no output arguments, @code{lookfor} prints the list of matching\n\ |
|
1530 functions to the terminal. Otherwise the output arguments @var{fun} and\n\ |
|
1531 @var{helpstring} define the matching functions and the first sentence of\n\ |
|
1532 each of their help strings.\n\ |
|
1533 \n\ |
|
1534 Note that the ability of @code{lookfor} to correctly identify the first\n\ |
|
1535 sentence of the help of the functions is dependent on the format of the\n\ |
|
1536 functions help. All of the functions in octave itself will correctly\n\ |
|
1537 find the first sentence, but the same can not be guaranteed for other\n\ |
|
1538 functions. Therefore the use of the '-all' argument might be necessary\n\ |
|
1539 to find related functions that are not part of octave.\n\ |
5642
|
1540 @seealso{which, help}\n\ |
|
1541 @end deffn") |
5447
|
1542 { |
|
1543 octave_value_list retval; |
|
1544 int nargin = args.length (); |
|
1545 bool first_sentence_only = true; |
|
1546 |
|
1547 if (nargin != 1 && nargin != 2) |
|
1548 { |
|
1549 usage ("lookfor"); |
|
1550 return retval; |
|
1551 } |
|
1552 |
|
1553 string_vector ret[2]; |
|
1554 |
|
1555 std::string txt; |
|
1556 |
|
1557 if (args(0).is_string ()) |
|
1558 { |
|
1559 txt = args(0).string_value (); |
|
1560 |
|
1561 if (nargin == 2) |
|
1562 { |
|
1563 if (args(1).is_string ()) |
|
1564 { |
|
1565 std::string tmp = args(1).string_value (); |
|
1566 |
|
1567 if (txt.substr(0,1) == "-") |
|
1568 { |
|
1569 txt = tmp; |
|
1570 tmp = args(0).string_value (); |
|
1571 } |
|
1572 |
|
1573 if (tmp == "-all") |
|
1574 first_sentence_only = false; |
|
1575 else |
|
1576 error ("lookfor: unrecognized option argument"); |
|
1577 } |
|
1578 else |
|
1579 error ("lookfor: arguments must be a string"); |
|
1580 } |
|
1581 } |
|
1582 else |
|
1583 error ("lookfor: argument must be a string"); |
|
1584 |
|
1585 if (!error_state) |
|
1586 { |
|
1587 // All tests in lower case |
|
1588 transform (txt.begin (), txt.end (), txt.begin (), tolower); |
|
1589 |
|
1590 help_list *ptr = keyword_help (); |
|
1591 while (ptr->name) |
|
1592 { |
|
1593 std::string name = ptr->name; |
|
1594 std::string h = ptr->help; |
|
1595 |
5592
|
1596 if (name.find (txt) != NPOS) |
5447
|
1597 { |
|
1598 if (nargout) |
|
1599 { |
|
1600 ret[0].append (name); |
|
1601 ret[1].append (first_help_sentence (h)); |
|
1602 } |
|
1603 else |
|
1604 print_lookfor (name, first_help_sentence (h)); |
|
1605 } |
5592
|
1606 else |
|
1607 { |
|
1608 std::string s; |
|
1609 |
|
1610 if (first_sentence_only) |
|
1611 s = first_help_sentence (h); |
|
1612 else |
|
1613 s = h; |
|
1614 |
|
1615 transform (s.begin (), s.end (), s.begin (), tolower); |
|
1616 |
|
1617 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1618 { |
|
1619 if (nargout) |
|
1620 { |
|
1621 ret[0].append (name); |
|
1622 ret[1].append (first_help_sentence (h)); |
|
1623 } |
|
1624 else |
|
1625 print_lookfor (name, first_help_sentence (h)); |
|
1626 } |
|
1627 } |
5447
|
1628 |
|
1629 OCTAVE_QUIT; |
|
1630 |
|
1631 ptr++; |
|
1632 } |
|
1633 |
|
1634 ptr = operator_help (); |
|
1635 while (ptr->name) |
|
1636 { |
|
1637 std::string name = ptr->name; |
|
1638 std::string h = ptr->help; |
|
1639 |
5592
|
1640 if (name.find (txt) != NPOS) |
5447
|
1641 { |
|
1642 if (nargout) |
|
1643 { |
|
1644 ret[0].append (name); |
|
1645 ret[1].append (first_help_sentence (h)); |
|
1646 } |
|
1647 else |
|
1648 print_lookfor (name, first_help_sentence (h)); |
|
1649 } |
5592
|
1650 else |
|
1651 { |
|
1652 std::string s; |
|
1653 if (first_sentence_only) |
|
1654 s = first_help_sentence (h); |
|
1655 else |
|
1656 s = h; |
|
1657 |
|
1658 transform (s.begin (), s.end (), s.begin (), tolower); |
|
1659 |
|
1660 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1661 { |
|
1662 if (nargout) |
|
1663 { |
|
1664 ret[0].append (name); |
|
1665 ret[1].append (first_help_sentence (h)); |
|
1666 } |
|
1667 else |
|
1668 print_lookfor (name, first_help_sentence (h)); |
|
1669 } |
|
1670 } |
5447
|
1671 |
|
1672 OCTAVE_QUIT; |
|
1673 |
|
1674 ptr++; |
|
1675 } |
|
1676 |
|
1677 // Check the symbol record table |
|
1678 string_vector names |
|
1679 = fbi_sym_tab->name_list (string_vector (), true); |
|
1680 |
|
1681 for (octave_idx_type i = 0; i < names.length (); i++) |
|
1682 { |
|
1683 std::string name = names (i); |
|
1684 |
|
1685 OCTAVE_QUIT; |
|
1686 |
|
1687 symbol_record *sr = lookup_by_name (name, 0); |
|
1688 if (sr && sr->is_defined ()) |
|
1689 { |
|
1690 std::string h = sr->help (); |
|
1691 |
5592
|
1692 if (name.find (txt) != NPOS) |
5447
|
1693 { |
|
1694 if (nargout) |
|
1695 { |
|
1696 ret[0].append (name); |
|
1697 ret[1].append (first_help_sentence (h)); |
|
1698 } |
|
1699 else |
|
1700 print_lookfor (name, first_help_sentence (h)); |
|
1701 } |
5592
|
1702 else |
|
1703 { |
|
1704 std::string s; |
|
1705 |
|
1706 if (first_sentence_only) |
|
1707 s = first_help_sentence (h); |
|
1708 else |
|
1709 s = h; |
|
1710 |
|
1711 transform (s.begin (), s.end (), s.begin (), tolower); |
|
1712 |
|
1713 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1714 { |
|
1715 if (nargout) |
|
1716 { |
|
1717 ret[0].append (name); |
|
1718 ret[1].append (first_help_sentence (h)); |
|
1719 } |
|
1720 else |
|
1721 print_lookfor (name, first_help_sentence (h)); |
|
1722 } |
|
1723 } |
5447
|
1724 } |
|
1725 } |
|
1726 |
|
1727 string_vector dirs = Vload_path_dir_path.all_directories (); |
|
1728 |
|
1729 int len = dirs.length (); |
|
1730 |
|
1731 for (int i = 0; i < len; i++) |
|
1732 { |
|
1733 names = octave_fcn_file_name_cache::list (dirs[i]); |
|
1734 |
|
1735 if (! names.empty ()) |
|
1736 { |
|
1737 for (int j = 0; j < names.length (); j++) |
|
1738 { |
|
1739 std::string name = names (j); |
|
1740 |
|
1741 OCTAVE_QUIT; |
|
1742 |
|
1743 // Strip extension |
|
1744 size_t l = name.length (); |
|
1745 if (l > 4 && name.substr (l-4) == ".oct") |
|
1746 name = name.substr (0, l - 4); |
|
1747 else if (l > 2 && name.substr (l-2) == ".m") |
|
1748 name = name.substr (0, l - 2); |
|
1749 else |
|
1750 continue; |
|
1751 |
|
1752 // Check if already in symbol table |
|
1753 symbol_record *sr = fbi_sym_tab->lookup (name); |
|
1754 |
|
1755 if (!sr) |
|
1756 { |
|
1757 // Check if this version is first in the path |
|
1758 string_vector tmp (2); |
|
1759 tmp(0) = name + ".oct"; |
|
1760 tmp(1) = name + ".m"; |
|
1761 std::string file_name = |
|
1762 Vload_path_dir_path.find_first_of (tmp); |
|
1763 |
|
1764 if (file_name == dirs[i] + tmp(0) |
|
1765 || file_name == dirs[i] + tmp(1)) |
|
1766 { |
5484
|
1767 bool symbol_found; |
|
1768 |
5592
|
1769 std::string h; |
|
1770 if (file_name == dirs[i] + tmp(0)) |
|
1771 { |
|
1772 // oct-file. Must load to get help |
|
1773 sr = lookup_by_name (name, false); |
5447
|
1774 |
5592
|
1775 if (sr && sr->is_defined ()) |
|
1776 h = sr->help (); |
|
1777 } |
5447
|
1778 else |
5592
|
1779 h = get_help_from_file (file_name, symbol_found); |
5447
|
1780 |
5592
|
1781 if (name.find (txt) != NPOS) |
5447
|
1782 { |
|
1783 if (nargout) |
|
1784 { |
|
1785 ret[0].append (name); |
|
1786 ret[1].append (first_help_sentence (h)); |
|
1787 } |
|
1788 else |
|
1789 print_lookfor (name, first_help_sentence (h)); |
|
1790 } |
5592
|
1791 else |
|
1792 { |
|
1793 std::string s; |
|
1794 if (first_sentence_only) |
|
1795 s = first_help_sentence (h); |
|
1796 else |
|
1797 s = h; |
|
1798 |
|
1799 transform (s.begin (), s.end (), s.begin (), tolower); |
|
1800 |
|
1801 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1802 { |
|
1803 if (nargout) |
|
1804 { |
|
1805 ret[0].append (name); |
|
1806 ret[1].append (first_help_sentence (h)); |
|
1807 } |
|
1808 else |
|
1809 print_lookfor (name, first_help_sentence (h)); |
|
1810 } |
|
1811 } |
|
1812 } |
|
1813 } |
|
1814 |
|
1815 // Check if this function has autoloaded functions attached to it |
|
1816 std::string file_name = Vload_path_dir_path.find_first_of (names(j)); |
|
1817 string_vector autoload_fcns = reverse_lookup_autoload (file_name); |
|
1818 |
|
1819 if (! autoload_fcns.empty ()) |
|
1820 { |
|
1821 for (int k = 0; k < autoload_fcns.length (); k++) |
|
1822 { |
|
1823 std::string aname = autoload_fcns (k); |
|
1824 |
|
1825 // Check if already in symbol table |
|
1826 sr = fbi_sym_tab->lookup (aname); |
|
1827 |
|
1828 if (!sr) |
|
1829 { |
|
1830 // Must load to get help |
|
1831 sr = lookup_by_name (name, false); |
|
1832 |
|
1833 std::string h; |
|
1834 if (sr && sr->is_defined ()) |
|
1835 h = sr->help (); |
|
1836 |
|
1837 if (aname.find (txt) != NPOS) |
|
1838 { |
|
1839 if (nargout) |
|
1840 { |
|
1841 ret[0].append (aname); |
|
1842 ret[1].append (first_help_sentence (h)); |
|
1843 } |
|
1844 else |
|
1845 print_lookfor (aname, first_help_sentence (h)); |
|
1846 } |
|
1847 else |
|
1848 { |
|
1849 std::string s; |
|
1850 if (first_sentence_only) |
|
1851 s = first_help_sentence (h); |
|
1852 else |
|
1853 s = h; |
|
1854 |
|
1855 transform (s.begin (), s.end (), s.begin (), |
|
1856 tolower); |
|
1857 |
|
1858 if (s.length () > 0 && s.find (txt) != NPOS) |
|
1859 { |
|
1860 if (nargout) |
|
1861 { |
|
1862 ret[0].append (aname); |
|
1863 ret[1].append (first_help_sentence (h)); |
|
1864 } |
|
1865 else |
|
1866 print_lookfor (aname, first_help_sentence (h)); |
|
1867 } |
|
1868 } |
|
1869 } |
5447
|
1870 } |
|
1871 } |
|
1872 } |
|
1873 } |
|
1874 } |
|
1875 |
|
1876 if (nargout != 0) |
|
1877 { |
|
1878 retval (1) = ret[1]; |
|
1879 retval (0) = ret[0]; |
|
1880 } |
|
1881 } |
|
1882 else |
|
1883 { |
|
1884 error ("lookfor: argument must be a string"); |
|
1885 } |
|
1886 |
|
1887 return retval; |
|
1888 } |
|
1889 |
2189
|
1890 static int |
2202
|
1891 info_file (void) |
|
1892 { |
|
1893 int status = 0; |
|
1894 |
3523
|
1895 std::string s = builtin_string_variable ("INFO_FILE"); |
2202
|
1896 |
|
1897 if (s.empty ()) |
|
1898 { |
|
1899 gripe_invalid_value_specified ("INFO_FILE"); |
|
1900 status = -1; |
|
1901 } |
|
1902 else |
|
1903 Vinfo_file = s; |
|
1904 |
|
1905 return status; |
|
1906 } |
|
1907 |
|
1908 static int |
|
1909 info_prog (void) |
|
1910 { |
|
1911 int status = 0; |
|
1912 |
3523
|
1913 std::string s = builtin_string_variable ("INFO_PROGRAM"); |
2202
|
1914 |
|
1915 if (s.empty ()) |
|
1916 { |
|
1917 gripe_invalid_value_specified ("INFO_PROGRAM"); |
|
1918 status = -1; |
|
1919 } |
|
1920 else |
|
1921 Vinfo_prog = s; |
|
1922 |
|
1923 return status; |
|
1924 } |
|
1925 |
3014
|
1926 static int |
3686
|
1927 makeinfo_prog (void) |
|
1928 { |
|
1929 int status = 0; |
|
1930 |
|
1931 std::string s = builtin_string_variable ("MAKEINFO_PROGRAM"); |
|
1932 |
|
1933 if (s.empty ()) |
|
1934 { |
|
1935 gripe_invalid_value_specified ("MAKEINFO_PROGRAM"); |
|
1936 status = -1; |
|
1937 } |
|
1938 else |
|
1939 Vmakeinfo_prog = s; |
|
1940 |
|
1941 return status; |
|
1942 } |
|
1943 |
|
1944 static int |
3014
|
1945 suppress_verbose_help_message (void) |
|
1946 { |
|
1947 Vsuppress_verbose_help_message |
|
1948 = check_preference ("suppress_verbose_help_message"); |
|
1949 |
|
1950 return 0; |
|
1951 } |
|
1952 |
2189
|
1953 void |
|
1954 symbols_of_help (void) |
|
1955 { |
3258
|
1956 DEFVAR (INFO_FILE, Vinfo_file, info_file, |
3332
|
1957 "-*- texinfo -*-\n\ |
|
1958 @defvr {Built-in Variable} INFO_FILE\n\ |
|
1959 The variable @code{INFO_FILE} names the location of the Octave info file.\n\ |
3686
|
1960 The default value is @code{\"@var{octave-home}/info/octave.info\"}, in\n\ |
|
1961 which @var{octave-home} is the directory where all of Octave is installed.\n\ |
3333
|
1962 @end defvr"); |
2202
|
1963 |
3258
|
1964 DEFVAR (INFO_PROGRAM, Vinfo_prog, info_prog, |
3332
|
1965 "-*- texinfo -*-\n\ |
3686
|
1966 @defvr {Built-in Variable} INFO_PROGRAM\n\ |
|
1967 The variable @code{INFO_PROGRAM} names the info program to run. Its\n\ |
|
1968 default initial value is\n\ |
|
1969 @code{\"@var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}/info\"}\n\ |
|
1970 in which @var{octave-home} is the directory where all of Octave is\n\ |
|
1971 installed, @var{version} is the Octave version number, and @var{arch}\n\ |
|
1972 is the system type (for example, @code{i686-pc-linux-gnu}). The\n\ |
|
1973 default initial value may be overridden by the environment variable\n\ |
|
1974 @code{OCTAVE_INFO_PROGRAM}, or the command line argument\n\ |
|
1975 @code{--info-program NAME}, or by setting the value of\n\ |
|
1976 @code{INFO_PROGRAM} in a startup script\n\ |
|
1977 @end defvr"); |
|
1978 |
|
1979 DEFVAR (MAKEINFO_PROGRAM, Vmakeinfo_prog, makeinfo_prog, |
|
1980 "-*- texinfo -*-\n\ |
|
1981 @defvr {Built-in Variable} MAKEINFO_PROGRAM\n\ |
|
1982 The variable @code{MAKEINFO_PROGRAM} names the makeinfo program that\n\ |
|
1983 Octave runs to format help text that contains Texinfo markup commands.\n\ |
|
1984 Its default initial value is @code{\"makeinfo\"}.\n\ |
3333
|
1985 @end defvr"); |
2202
|
1986 |
4233
|
1987 DEFVAR (suppress_verbose_help_message, false, suppress_verbose_help_message, |
3332
|
1988 "-*- texinfo -*-\n\ |
|
1989 @defvr {Built-in Variable} suppress_verbose_help_message\n\ |
|
1990 If the value of @code{suppress_verbose_help_message} is nonzero, Octave\n\ |
|
1991 will not add additional help information to the end of the output from\n\ |
|
1992 the @code{help} command and usage messages for built-in commands.\n\ |
3333
|
1993 @end defvr"); |
2189
|
1994 } |
|
1995 |
1
|
1996 /* |
|
1997 ;;; Local Variables: *** |
|
1998 ;;; mode: C++ *** |
|
1999 ;;; End: *** |
|
2000 */ |