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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
1
|
25 #endif |
|
26 |
1343
|
27 #include <cstdlib> |
|
28 #include <cstring> |
|
29 |
3503
|
30 #include <iostream> |
|
31 #include <fstream> |
1755
|
32 #include <string> |
|
33 |
1350
|
34 #ifdef HAVE_UNISTD_H |
2442
|
35 #ifdef HAVE_SYS_TYPES_H |
1295
|
36 #include <sys/types.h> |
2442
|
37 #endif |
1295
|
38 #include <unistd.h> |
|
39 #endif |
1343
|
40 |
3295
|
41 #include "cmd-edit.h" |
|
42 #include "file-ops.h" |
4051
|
43 #include "lo-sstream.h" |
2926
|
44 #include "oct-env.h" |
1755
|
45 #include "str-vec.h" |
|
46 |
2492
|
47 #include <defaults.h> |
1352
|
48 #include "defun.h" |
|
49 #include "dirfns.h" |
|
50 #include "error.h" |
2233
|
51 #include "fn-cache.h" |
2202
|
52 #include "gripes.h" |
1352
|
53 #include "help.h" |
2177
|
54 #include "input.h" |
1755
|
55 #include "oct-obj.h" |
2976
|
56 #include "ov-usr-fcn.h" |
1352
|
57 #include "pager.h" |
3018
|
58 #include "parse.h" |
1466
|
59 #include "pathsearch.h" |
3295
|
60 #include "procstream.h" |
529
|
61 #include "sighandlers.h" |
|
62 #include "symtab.h" |
2694
|
63 #include "syswait.h" |
1755
|
64 #include "toplev.h" |
242
|
65 #include "utils.h" |
1352
|
66 #include "variables.h" |
3301
|
67 #include "version.h" |
529
|
68 |
2202
|
69 // Name of the info file specified on command line. |
|
70 // (--info-file file) |
3523
|
71 std::string Vinfo_file; |
2202
|
72 |
|
73 // Name of the info reader we'd like to use. |
|
74 // (--info-program program) |
3523
|
75 std::string Vinfo_prog; |
2202
|
76 |
3686
|
77 // Name of the makeinfo program to run. |
|
78 static std::string Vmakeinfo_prog = "makeinfo"; |
|
79 |
2189
|
80 // If TRUE, don't print additional help message in help and usage |
|
81 // functions. |
|
82 static bool Vsuppress_verbose_help_message; |
|
83 |
3016
|
84 // XXX FIXME XXX -- maybe this should use string instead of char*. |
|
85 |
|
86 struct help_list |
|
87 { |
|
88 const char *name; |
|
89 const char *help; |
|
90 }; |
|
91 |
1
|
92 static help_list operators[] = |
|
93 { |
|
94 { "!", |
|
95 "Logical not operator. See also `~'.\n", }, |
|
96 |
|
97 { "!=", |
|
98 "Logical not equals operator. See also `~' and `<>'.\n", }, |
|
99 |
|
100 { "\"", |
|
101 "String delimiter.\n", }, |
|
102 |
|
103 { "#", |
928
|
104 "Begin comment character. See also `%'.", }, |
1
|
105 |
|
106 { "%", |
928
|
107 "Begin comment charcter. See also `#'.", }, |
1
|
108 |
|
109 { "&", |
928
|
110 "Logical and operator. See also `&&'.", }, |
1
|
111 |
|
112 { "&&", |
928
|
113 "Logical and operator. See also `&'.", }, |
1
|
114 |
|
115 { "'", |
|
116 "Matrix transpose operator. For complex matrices, computes the\n\ |
|
117 complex conjugate (Hermitian) transpose. See also `.''\n\ |
|
118 \n\ |
|
119 The single quote character may also be used to delimit strings, but\n\ |
|
120 it is better to use the double quote character, since that is never\n\ |
928
|
121 ambiguous", }, |
1
|
122 |
|
123 { "(", |
928
|
124 "Array index or function argument delimiter.", }, |
1
|
125 |
|
126 { ")", |
928
|
127 "Array index or function argument delimiter.", }, |
1
|
128 |
|
129 { "*", |
928
|
130 "Multiplication operator. See also `.*'", }, |
1
|
131 |
|
132 { "**", |
928
|
133 "Power operator. See also `^', `.**', and `.^'", }, |
1
|
134 |
|
135 { "+", |
928
|
136 "Addition operator.", }, |
1
|
137 |
|
138 { "++", |
928
|
139 "Increment operator. As in C, may be applied as a prefix or postfix operator.", }, |
1
|
140 |
|
141 { ",", |
928
|
142 "Array index, function argument, or command separator.", }, |
1
|
143 |
|
144 { "-", |
928
|
145 "Subtraction or unary negation operator.", }, |
1
|
146 |
|
147 { "--", |
928
|
148 "Decrement operator. As in C, may be applied as a prefix or postfix operator.", }, |
1
|
149 |
|
150 { ".'", |
|
151 "Matrix transpose operator. For complex matrices, computes the\n\ |
928
|
152 transpose, *not* the complex conjugate transpose. See also `''.", }, |
1
|
153 |
|
154 { ".*", |
928
|
155 "Element by element multiplication operator. See also `*'.", }, |
1
|
156 |
|
157 { ".**", |
928
|
158 "Element by element power operator. See also `**', `^', and `.^'.", }, |
1
|
159 |
|
160 { "./", |
928
|
161 "Element by element division operator. See also `/' and `\\'.", }, |
1
|
162 |
|
163 { ".^", |
928
|
164 "Element by element power operator. See also `**', `^', and `.^'.", }, |
1
|
165 |
|
166 { "/", |
928
|
167 "Right division. See also `\\' and `./'.", }, |
1
|
168 |
|
169 { ":", |
928
|
170 "Select entire rows or columns of matrices.", }, |
1
|
171 |
|
172 { ";", |
928
|
173 "Array row or command separator. See also `,'.", }, |
1
|
174 |
|
175 { "<", |
928
|
176 "Less than operator.", }, |
1
|
177 |
|
178 { "<=", |
928
|
179 "Less than or equals operator.", }, |
1
|
180 |
|
181 { "<>", |
928
|
182 "Logical not equals operator. See also `!=' and `~='.", }, |
1
|
183 |
|
184 { "=", |
928
|
185 "Assignment operator.", }, |
1
|
186 |
|
187 { "==", |
928
|
188 "Equality test operator.", }, |
1
|
189 |
|
190 { ">", |
928
|
191 "Greater than operator.", }, |
1
|
192 |
|
193 { ">=", |
928
|
194 "Greater than or equals operator.", }, |
1
|
195 |
|
196 { "[", |
928
|
197 "Return list delimiter. See also `]'.", }, |
1
|
198 |
|
199 { "\\", |
928
|
200 "Left division operator. See also `/' and `./'.", }, |
1
|
201 |
|
202 { "]", |
928
|
203 "Return list delimiter. See also `['.", }, |
1
|
204 |
|
205 { "^", |
928
|
206 "Power operator. See also `**', `.^', and `.**.'", }, |
1
|
207 |
|
208 { "|", |
928
|
209 "Logical or operator. See also `||'.", }, |
1
|
210 |
|
211 { "||", |
928
|
212 "Logical or operator. See also `|'.", }, |
1
|
213 |
|
214 { "~", |
928
|
215 "Logical not operator. See also `!' and `~'.", }, |
1
|
216 |
|
217 { "~=", |
928
|
218 "Logical not equals operator. See also `<>' and `!='.", }, |
1
|
219 |
529
|
220 { 0, 0, }, |
1
|
221 }; |
|
222 |
|
223 static help_list keywords[] = |
|
224 { |
928
|
225 { "all_va_args", |
|
226 "Pass all unnamed arguments to another function call.", }, |
|
227 |
1
|
228 { "break", |
5040
|
229 "Exit the innermost enclosing do, while or for loop.", }, |
|
230 |
|
231 { "case", |
|
232 "A case statement in an switch. Octave cases are exclusive and do not\n\ |
|
233 fall-through as do C-language cases. A switch statement must have at least\n\ |
|
234 one case.",}, |
1
|
235 |
1489
|
236 { "catch", |
|
237 "begin the cleanup part of a try-catch block", }, |
|
238 |
1
|
239 { "continue", |
5040
|
240 "Jump to the end of the innermost enclosing do, while or for loop.", }, |
|
241 |
|
242 { "do", |
|
243 "Begin a do-until loop. This differs from a do-while loop in that the\n\ |
|
244 body of the loop is executed at least once.",}, |
1
|
245 |
|
246 { "else", |
928
|
247 "Alternate action for an if block.", }, |
1
|
248 |
|
249 { "elseif", |
928
|
250 "Alternate conditional test for an if block.", }, |
1
|
251 |
|
252 { "end", |
5040
|
253 "Mark the end of any for, if, do, while, or function block.", }, |
928
|
254 |
1489
|
255 { "end_try_catch", |
|
256 "Mark the end of an try-catch block.", }, |
|
257 |
928
|
258 { "end_unwind_protect", |
|
259 "Mark the end of an unwind_protect block.", }, |
1
|
260 |
|
261 { "endfor", |
928
|
262 "Mark the end of a for loop.", }, |
1
|
263 |
|
264 { "endfunction", |
928
|
265 "Mark the end of a function.", }, |
1
|
266 |
|
267 { "endif", |
928
|
268 "Mark the end of an if block.", }, |
1
|
269 |
|
270 { "endwhile", |
928
|
271 "Mark the end of a while loop.", }, |
1
|
272 |
|
273 { "for", |
928
|
274 "Begin a for loop.", }, |
1
|
275 |
|
276 { "function", |
928
|
277 "Begin a function body.", }, |
1
|
278 |
|
279 { "global", |
928
|
280 "Declare variables to have global scope.", }, |
1
|
281 |
|
282 { "gplot", |
928
|
283 "Produce 2-D plots using gnuplot-like command syntax.", }, |
1
|
284 |
|
285 { "gsplot", |
928
|
286 "Produce 3-D plots using gnuplot-like command syntax.", }, |
1
|
287 |
|
288 { "if", |
928
|
289 "Begin an if block.", }, |
1
|
290 |
5040
|
291 { "otherwise", |
|
292 "The default statement in a switch block.", }, |
|
293 |
4686
|
294 { "persistent", |
|
295 "Declare variables as persistent.", }, |
|
296 |
5040
|
297 { "replot", |
|
298 "Replot a graphic.", }, |
|
299 |
1
|
300 { "return", |
928
|
301 "Return from a function.", }, |
|
302 |
5040
|
303 { "static", |
|
304 "Declare variables as persistent.", }, |
|
305 |
|
306 { "switch", |
|
307 "Begin a switch statement.",}, |
|
308 |
1489
|
309 { "try", |
|
310 "Begin a try-catch block.", }, |
|
311 |
5040
|
312 { "until", |
|
313 "End a do-until loop.",}, |
|
314 |
928
|
315 { "unwind_protect", |
|
316 "Begin an unwind_protect block.", }, |
|
317 |
|
318 { "unwind_protect_cleanup", |
|
319 "Begin the cleanup section of an unwind_protect block.", }, |
1
|
320 |
5040
|
321 { "varargin", |
|
322 "Pass an arbitrary number of arguments into a function.",}, |
|
323 |
|
324 { "varargout", |
|
325 "Pass an arbitrary number of arguments out of a function.",}, |
|
326 |
1
|
327 { "while", |
928
|
328 "Begin a while loop.", }, |
1
|
329 |
529
|
330 { 0, 0, }, |
1
|
331 }; |
|
332 |
581
|
333 // Return a copy of the operator or keyword names. |
|
334 |
3016
|
335 static string_vector |
3355
|
336 names (help_list *lst) |
1
|
337 { |
1755
|
338 string_vector retval; |
|
339 |
3355
|
340 int count = 0; |
1
|
341 help_list *ptr = lst; |
529
|
342 while (ptr->name) |
1
|
343 { |
|
344 count++; |
|
345 ptr++; |
|
346 } |
|
347 |
1755
|
348 if (count > 0) |
|
349 { |
|
350 retval.resize (count); |
1
|
351 |
1755
|
352 ptr = lst; |
|
353 for (int i = 0; i < count; i++) |
|
354 { |
|
355 retval[i] = ptr->name; |
|
356 ptr++; |
|
357 } |
1
|
358 } |
|
359 |
1755
|
360 return retval; |
1
|
361 } |
|
362 |
3014
|
363 static help_list * |
1
|
364 operator_help (void) |
|
365 { |
|
366 return operators; |
|
367 } |
|
368 |
3016
|
369 static help_list * |
1
|
370 keyword_help (void) |
|
371 { |
|
372 return keywords; |
|
373 } |
|
374 |
3016
|
375 // It's not likely that this does the right thing now. XXX FIXME XXX |
|
376 |
|
377 string_vector |
|
378 make_name_list (void) |
|
379 { |
3355
|
380 string_vector key = names (keyword_help ()); |
|
381 int key_len = key.length (); |
3016
|
382 |
4009
|
383 string_vector fbi = fbi_sym_tab->name_list (); |
|
384 int fbi_len = fbi.length (); |
|
385 |
3355
|
386 string_vector glb = global_sym_tab->name_list (); |
|
387 int glb_len = glb.length (); |
3016
|
388 |
3355
|
389 string_vector top = top_level_sym_tab->name_list (); |
|
390 int top_len = top.length (); |
3016
|
391 |
3355
|
392 string_vector lcl; |
3016
|
393 if (top_level_sym_tab != curr_sym_tab) |
3355
|
394 lcl = curr_sym_tab->name_list (); |
|
395 int lcl_len = lcl.length (); |
3016
|
396 |
3355
|
397 string_vector ffl = octave_fcn_file_name_cache::list_no_suffix (); |
3016
|
398 int ffl_len = ffl.length (); |
|
399 |
4009
|
400 int total_len = key_len + fbi_len + glb_len + top_len + lcl_len + ffl_len; |
3016
|
401 |
|
402 string_vector list (total_len); |
|
403 |
|
404 // Put all the symbols in one big list. |
|
405 |
|
406 int j = 0; |
|
407 int i = 0; |
|
408 for (i = 0; i < key_len; i++) |
|
409 list[j++] = key[i]; |
|
410 |
4009
|
411 for (i = 0; i < fbi_len; i++) |
|
412 list[j++] = fbi[i]; |
|
413 |
3016
|
414 for (i = 0; i < glb_len; i++) |
|
415 list[j++] = glb[i]; |
|
416 |
|
417 for (i = 0; i < top_len; i++) |
|
418 list[j++] = top[i]; |
|
419 |
|
420 for (i = 0; i < lcl_len; i++) |
|
421 list[j++] = lcl[i]; |
|
422 |
|
423 for (i = 0; i < ffl_len; i++) |
|
424 list[j++] = ffl[i]; |
|
425 |
|
426 return list; |
|
427 } |
|
428 |
3014
|
429 void |
3523
|
430 additional_help_message (std::ostream& os) |
2470
|
431 { |
|
432 if (! Vsuppress_verbose_help_message) |
|
433 os << "\n\ |
3259
|
434 Additional help for built-in functions, operators, and variables\n\ |
3160
|
435 is available in the on-line version of the manual. Use the command\n\ |
3295
|
436 `help -i <topic>' to search the manual index.\n\ |
|
437 \n\ |
3160
|
438 Help and information about Octave is also available on the WWW\n\ |
5041
|
439 at http://www.octave.org and via the help@octave.org\n\ |
3917
|
440 mailing list.\n"; |
3160
|
441 } |
|
442 |
2976
|
443 // XXX FIXME XXX -- this needs a major overhaul to cope with new |
|
444 // symbol table stuff. |
|
445 |
529
|
446 static void |
3523
|
447 display_names_from_help_list (std::ostream& os, help_list *list, |
542
|
448 const char *desc) |
529
|
449 { |
3355
|
450 string_vector symbols = names (list); |
3259
|
451 |
1808
|
452 if (! symbols.empty ()) |
|
453 { |
2095
|
454 os << "\n*** " << desc << ":\n\n"; |
3259
|
455 |
|
456 symbols.qsort (); |
|
457 |
2095
|
458 symbols.list_in_columns (os); |
1808
|
459 } |
529
|
460 } |
|
461 |
|
462 static void |
3523
|
463 display_symtab_names (std::ostream& os, const string_vector& names, |
|
464 const std::string& desc) |
542
|
465 { |
1808
|
466 if (! names.empty ()) |
|
467 { |
2095
|
468 os << "\n*** " << desc << ":\n\n"; |
|
469 names.list_in_columns (os); |
1808
|
470 } |
542
|
471 } |
|
472 |
|
473 #ifdef LIST_SYMBOLS |
|
474 #undef LIST_SYMBOLS |
|
475 #endif |
|
476 #define LIST_SYMBOLS(type, msg) \ |
|
477 do \ |
|
478 { \ |
3259
|
479 string_vector names \ |
4009
|
480 = fbi_sym_tab->name_list (string_vector (), true, type); \ |
3355
|
481 display_symtab_names (octave_stdout, names, msg); \ |
542
|
482 } \ |
|
483 while (0) |
529
|
484 |
3014
|
485 static void |
|
486 simple_help (void) |
|
487 { |
3160
|
488 octave_stdout << "Help is available for the topics listed below.\n"; |
|
489 |
|
490 additional_help_message (octave_stdout); |
|
491 |
3014
|
492 display_names_from_help_list (octave_stdout, operator_help (), |
|
493 "operators"); |
|
494 |
|
495 display_names_from_help_list (octave_stdout, keyword_help (), |
|
496 "reserved words"); |
|
497 |
1358
|
498 // XXX FIXME XXX -- is this distinction needed? |
|
499 |
3259
|
500 LIST_SYMBOLS (symbol_record::BUILTIN_CONSTANT, "built-in constants"); |
|
501 |
|
502 LIST_SYMBOLS (symbol_record::BUILTIN_VARIABLE, "built-in variables"); |
|
503 |
4208
|
504 LIST_SYMBOLS (symbol_record::COMMAND, "commands"); |
529
|
505 |
3010
|
506 LIST_SYMBOLS (symbol_record::MAPPER_FUNCTION, "mapper functions"); |
542
|
507 |
3010
|
508 LIST_SYMBOLS (symbol_record::BUILTIN_FUNCTION, "general functions"); |
542
|
509 |
1358
|
510 // Also need to list variables and currently compiled functions from |
|
511 // the symbol table, if there are any. |
529
|
512 |
1358
|
513 // Also need to search octave_path for script files. |
529
|
514 |
3195
|
515 string_vector dirs = Vload_path_dir_path.all_directories (); |
679
|
516 |
1787
|
517 int len = dirs.length (); |
679
|
518 |
1787
|
519 for (int i = 0; i < len; i++) |
|
520 { |
2233
|
521 string_vector names = octave_fcn_file_name_cache::list (dirs[i]); |
679
|
522 |
1787
|
523 if (! names.empty ()) |
|
524 { |
3523
|
525 std::string dir |
2926
|
526 = octave_env::make_absolute (dirs[i], octave_env::getcwd ()); |
|
527 |
|
528 octave_stdout << "\n*** function files in " << dir << ":\n\n"; |
679
|
529 |
3259
|
530 names.qsort (); |
|
531 |
2095
|
532 names.list_in_columns (octave_stdout); |
529
|
533 } |
|
534 } |
|
535 } |
|
536 |
|
537 static int |
3523
|
538 try_info (const std::string& nm) |
529
|
539 { |
|
540 int status = 0; |
|
541 |
4051
|
542 OSSTREAM cmd_buf; |
1295
|
543 |
4469
|
544 cmd_buf << "\"" << Vinfo_prog << "\" --file \"" << Vinfo_file << "\""; |
1295
|
545 |
3523
|
546 std::string directory_name = Vinfo_file; |
1755
|
547 size_t pos = directory_name.rfind ('/'); |
|
548 |
|
549 if (pos != NPOS) |
529
|
550 { |
1755
|
551 directory_name.resize (pos + 1); |
4469
|
552 cmd_buf << " --directory \"" << directory_name << "\""; |
529
|
553 } |
|
554 |
1755
|
555 if (nm.length () > 0) |
|
556 cmd_buf << " --index-search " << nm; |
529
|
557 |
4051
|
558 cmd_buf << OSSTREAM_ENDS; |
529
|
559 |
2705
|
560 volatile octave_interrupt_handler old_interrupt_handler |
2554
|
561 = octave_ignore_interrupts (); |
529
|
562 |
4051
|
563 status = system (OSSTREAM_C_STR (cmd_buf)); |
|
564 |
|
565 OSSTREAM_FREEZE (cmd_buf); |
529
|
566 |
2554
|
567 octave_set_interrupt_handler (old_interrupt_handler); |
529
|
568 |
2694
|
569 if (WIFEXITED (status)) |
|
570 status = WEXITSTATUS (status); |
1295
|
571 else |
|
572 status = 127; |
529
|
573 |
|
574 return status; |
|
575 } |
1140
|
576 |
|
577 static void |
1755
|
578 help_from_info (const string_vector& argv, int idx, int argc) |
1140
|
579 { |
1755
|
580 if (idx == argc) |
3523
|
581 try_info (std::string ()); |
1140
|
582 else |
|
583 { |
1755
|
584 for (int i = idx; i < argc; i++) |
1140
|
585 { |
1755
|
586 int status = try_info (argv[i]); |
1140
|
587 |
1295
|
588 if (status) |
1140
|
589 { |
3295
|
590 if (status == 127) |
1295
|
591 { |
3185
|
592 error ("help: unable to find info"); |
|
593 error ("help: you need info 2.18 or later (texinfo 3.12)"); |
1295
|
594 break; |
|
595 } |
3295
|
596 else |
|
597 { |
|
598 message ("help", "sorry, `%s' is not indexed in the manual", |
|
599 argv[i].c_str ()); |
|
600 } |
1140
|
601 } |
|
602 } |
|
603 } |
2470
|
604 } |
3014
|
605 |
|
606 static bool |
3523
|
607 looks_like_texinfo (const std::string& msg, size_t& p1) |
3295
|
608 { |
|
609 p1 = msg.find ('\n'); |
|
610 |
3523
|
611 std::string t = msg.substr (0, p1); |
3295
|
612 |
|
613 if (p1 == NPOS) |
|
614 p1 = 0; |
|
615 |
|
616 size_t p2 = t.find ("-*- texinfo -*-"); |
|
617 |
|
618 return (p2 != NPOS); |
|
619 } |
|
620 |
3330
|
621 void |
3523
|
622 display_help_text (std::ostream& os, const std::string& msg) |
3295
|
623 { |
|
624 // Look for "-*- texinfo -*-" in first line of help message. If it |
|
625 // is present, use makeinfo to format the rest of the message before |
|
626 // sending it to the output stream. Otherwise, just print the |
|
627 // message. |
|
628 |
|
629 size_t pos; |
|
630 |
|
631 if (looks_like_texinfo (msg, pos)) |
|
632 { |
3523
|
633 std::string tmp_file_name = file_ops::tempnam ("", ""); |
3295
|
634 |
|
635 int cols = command_editor::terminal_cols (); |
|
636 |
|
637 if (cols > 16) |
|
638 cols--; |
|
639 |
|
640 if (cols > 64) |
|
641 cols -= 7; |
|
642 |
|
643 if (cols > 80) |
|
644 cols = 72; |
|
645 |
4051
|
646 OSSTREAM buf; |
|
647 |
4115
|
648 buf << "sed -e 's/^[#%][#%]* *//' -e 's/^ *@/@/' | " |
4469
|
649 << "\"" << Vmakeinfo_prog << "\"" |
3303
|
650 << " -D \"VERSION " << OCTAVE_VERSION << "\"" |
|
651 << " -D \"OCTAVEHOME " << OCTAVE_PREFIX << "\"" |
3584
|
652 << " -D \"TARGETHOSTTYPE " << OCTAVE_CANONICAL_HOST_TYPE << "\"" |
3301
|
653 << " --fill-column " << cols |
|
654 << " --no-warn" |
|
655 << " --no-validate" |
|
656 << " --no-headers" |
|
657 << " --force" |
4108
|
658 << " --output \"" << tmp_file_name << "\"" |
3303
|
659 << " > /dev/null 2>&1" |
4051
|
660 << OSSTREAM_ENDS; |
3295
|
661 |
4051
|
662 oprocstream filter (OSSTREAM_STR (buf)); |
3295
|
663 |
4051
|
664 OSSTREAM_FREEZE (buf); |
3295
|
665 |
3686
|
666 if (filter && filter.is_open ()) |
3295
|
667 { |
3405
|
668 filter << "@macro seealso {args}\n" |
3408
|
669 << "\n" |
|
670 << "@noindent\n" |
3405
|
671 << "See also: \\args\\.\n" |
|
672 << "@end macro\n"; |
|
673 |
3769
|
674 filter << msg.substr (pos+1) << std::endl; |
3295
|
675 |
3686
|
676 int status = filter.close (); |
3295
|
677 |
3523
|
678 std::ifstream tmp_file (tmp_file_name.c_str ()); |
3295
|
679 |
3686
|
680 if (WIFEXITED (status) && WEXITSTATUS (status) == 0) |
|
681 { |
|
682 int c; |
|
683 while ((c = tmp_file.get ()) != EOF) |
|
684 os << (char) c; |
3295
|
685 |
3686
|
686 tmp_file.close (); |
|
687 } |
|
688 else |
|
689 { |
|
690 warning ("help: Texinfo formatting filter exited abnormally"); |
|
691 warning ("help: raw Texinfo source of help text follows..."); |
|
692 |
|
693 os << "\n" << msg; |
|
694 } |
3295
|
695 |
|
696 file_ops::unlink (tmp_file_name); |
|
697 } |
|
698 else |
|
699 os << msg; |
|
700 } |
|
701 else |
|
702 os << msg; |
|
703 } |
|
704 |
|
705 static bool |
3523
|
706 help_from_list (std::ostream& os, const help_list *list, |
|
707 const std::string& nm, int usage) |
542
|
708 { |
2804
|
709 const char *name; |
3014
|
710 |
542
|
711 while ((name = list->name) != 0) |
|
712 { |
1755
|
713 if (strcmp (name, nm.c_str ()) == 0) |
542
|
714 { |
|
715 if (usage) |
2095
|
716 os << "\nusage: "; |
542
|
717 else |
|
718 { |
2095
|
719 os << "\n*** " << nm << ":\n\n"; |
542
|
720 } |
|
721 |
3295
|
722 display_help_text (os, list->help); |
|
723 |
|
724 os << "\n"; |
542
|
725 |
3014
|
726 return true; |
542
|
727 } |
|
728 list++; |
|
729 } |
3014
|
730 |
|
731 return false; |
542
|
732 } |
|
733 |
3355
|
734 static bool |
3523
|
735 help_from_symbol_table (std::ostream& os, const std::string& nm) |
3355
|
736 { |
|
737 bool retval = false; |
|
738 |
|
739 symbol_record *sym_rec = lookup_by_name (nm, 0); |
|
740 |
|
741 if (sym_rec && sym_rec->is_defined ()) |
|
742 { |
3523
|
743 std::string h = sym_rec->help (); |
3355
|
744 |
|
745 if (h.length () > 0) |
|
746 { |
|
747 sym_rec->which (os); |
|
748 os << "\n"; |
|
749 display_help_text (os, h); |
|
750 os << "\n"; |
|
751 retval = true; |
|
752 } |
|
753 } |
|
754 |
|
755 return retval; |
|
756 } |
|
757 |
|
758 static bool |
3523
|
759 help_from_file (std::ostream& os, const std::string& nm) |
3355
|
760 { |
|
761 bool retval = false; |
|
762 |
3523
|
763 std::string path = fcn_file_in_path (nm); |
3355
|
764 |
3523
|
765 std::string h = get_help_from_file (path); |
3355
|
766 |
|
767 if (! h.empty ()) |
|
768 { |
|
769 os << nm << " is the file: " << path << "\n\n"; |
|
770 display_help_text (os, h); |
|
771 os << "\n"; |
|
772 retval = true; |
|
773 } |
|
774 |
|
775 return retval; |
|
776 } |
|
777 |
1140
|
778 static void |
1755
|
779 builtin_help (int argc, const string_vector& argv) |
1140
|
780 { |
|
781 help_list *op_help_list = operator_help (); |
|
782 help_list *kw_help_list = keyword_help (); |
|
783 |
1755
|
784 for (int i = 1; i < argc; i++) |
1140
|
785 { |
2095
|
786 if (help_from_list (octave_stdout, op_help_list, argv[i], 0)) |
1140
|
787 continue; |
|
788 |
2095
|
789 if (help_from_list (octave_stdout, kw_help_list, argv[i], 0)) |
1140
|
790 continue; |
|
791 |
3355
|
792 if (help_from_symbol_table (octave_stdout, argv[i])) |
|
793 continue; |
1755
|
794 |
3355
|
795 if (help_from_file (octave_stdout, argv[i])) |
|
796 continue; |
1140
|
797 |
2095
|
798 octave_stdout << "\nhelp: sorry, `" << argv[i] |
|
799 << "' is not documented\n"; |
1140
|
800 } |
|
801 |
2095
|
802 additional_help_message (octave_stdout); |
1140
|
803 } |
|
804 |
4208
|
805 DEFCMD (help, args, , |
3332
|
806 "-*- texinfo -*-\n\ |
|
807 @deffn {Command} help\n\ |
|
808 Octave's @code{help} command can be used to print brief usage-style\n\ |
|
809 messages, or to display information directly from an on-line version of\n\ |
|
810 the printed manual, using the GNU Info browser. If invoked without any\n\ |
|
811 arguments, @code{help} prints a list of all the available operators,\n\ |
|
812 functions, and built-in variables. If the first argument is @code{-i},\n\ |
|
813 the @code{help} command searches the index of the on-line version of\n\ |
|
814 this manual for the given topics.\n\ |
3168
|
815 \n\ |
3332
|
816 For example, the command @kbd{help help} prints a short message\n\ |
|
817 describing the @code{help} command, and @kbd{help -i help} starts the\n\ |
|
818 GNU Info browser at this node in the on-line version of the manual.\n\ |
|
819 \n\ |
|
820 Once the GNU Info browser is running, help for using it is available\n\ |
|
821 using the command @kbd{C-h}.\n\ |
3333
|
822 @end deffn") |
529
|
823 { |
2086
|
824 octave_value_list retval; |
529
|
825 |
1755
|
826 int argc = args.length () + 1; |
|
827 |
1968
|
828 string_vector argv = args.make_argv ("help"); |
1755
|
829 |
|
830 if (error_state) |
|
831 return retval; |
529
|
832 |
|
833 if (argc == 1) |
3014
|
834 simple_help (); |
529
|
835 else |
|
836 { |
1755
|
837 if (argv[1] == "-i") |
3014
|
838 help_from_info (argv, 2, argc); |
529
|
839 else |
3014
|
840 builtin_help (argc, argv); |
529
|
841 } |
|
842 |
|
843 return retval; |
|
844 } |
|
845 |
3355
|
846 static void |
3523
|
847 do_type (std::ostream& os, const std::string& name, bool pr_type_info, |
3355
|
848 bool quiet, bool pr_orig_txt) |
|
849 { |
|
850 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
851 |
|
852 if (sym_rec && sym_rec->is_defined ()) |
3356
|
853 sym_rec->type (os, pr_type_info, quiet, pr_orig_txt); |
3355
|
854 else |
|
855 { |
3523
|
856 std::string ff = fcn_file_in_path (name); |
3355
|
857 |
|
858 if (! ff.empty ()) |
|
859 { |
3538
|
860 std::ifstream fs (ff.c_str (), std::ios::in); |
3355
|
861 |
|
862 if (fs) |
|
863 { |
|
864 if (pr_type_info && ! quiet) |
|
865 os << name << " is the script file: " << ff << "\n\n"; |
|
866 |
|
867 char ch; |
|
868 |
|
869 while (fs.get (ch)) |
|
870 os << ch; |
|
871 } |
|
872 else |
|
873 os << "unable to open `" << ff << "' for reading!\n"; |
|
874 } |
|
875 else |
|
876 error ("type: `%s' undefined", name.c_str ()); |
|
877 } |
|
878 } |
|
879 |
4208
|
880 DEFCMD (type, args, nargout, |
3361
|
881 "-*- texinfo -*-\n\ |
|
882 \n\ |
|
883 @deffn {Command} type options name @dots{}\n\ |
|
884 Display the definition of each @var{name} that refers to a function.\n\ |
|
885 \n\ |
|
886 Normally also displays if each @var{name} is user-defined or builtin;\n\ |
|
887 the @code{-q} option suppresses this behaviour.\n\ |
581
|
888 \n\ |
3361
|
889 Currently, Octave can only display functions that can be compiled\n\ |
|
890 cleanly, because it uses its internal representation of the function to\n\ |
|
891 recreate the program text.\n\ |
|
892 \n\ |
|
893 Comments are not displayed because Octave's parser currently discards\n\ |
|
894 them as it converts the text of a function file to its internal\n\ |
|
895 representation. This problem may be fixed in a future release.\n\ |
|
896 @end deffn") |
581
|
897 { |
3584
|
898 octave_value retval; |
1588
|
899 |
1755
|
900 int argc = args.length () + 1; |
|
901 |
1968
|
902 string_vector argv = args.make_argv ("type"); |
1755
|
903 |
3355
|
904 if (! error_state) |
581
|
905 { |
3355
|
906 if (argc > 1) |
|
907 { |
|
908 // XXX FIXME XXX -- we should really use getopt () |
2532
|
909 |
3355
|
910 bool quiet = false; |
|
911 bool pr_orig_txt = true; |
2532
|
912 |
3355
|
913 int idx; |
581
|
914 |
3355
|
915 for (idx = 1; idx < argc; idx++) |
1281
|
916 { |
3355
|
917 if (argv[idx] == "-q" || argv[idx] == "-quiet") |
|
918 quiet = true; |
|
919 else if (argv[idx] == "-t" || argv[idx] == "-transformed") |
|
920 pr_orig_txt = false; |
|
921 else |
|
922 break; |
1281
|
923 } |
|
924 |
3355
|
925 if (idx < argc) |
|
926 { |
4051
|
927 OSSTREAM output_buf; |
581
|
928 |
3355
|
929 for (int i = idx; i < argc; i++) |
581
|
930 { |
3523
|
931 std::string id = argv[i]; |
2534
|
932 |
3355
|
933 if (nargout == 0) |
|
934 do_type (octave_stdout, id, true, quiet, pr_orig_txt); |
|
935 else |
|
936 do_type (output_buf, id, false, quiet, pr_orig_txt); |
581
|
937 |
3355
|
938 if (error_state) |
|
939 goto abort; |
581
|
940 } |
|
941 |
3584
|
942 if (nargout != 0) |
625
|
943 { |
4051
|
944 output_buf << OSSTREAM_ENDS; |
3164
|
945 |
4051
|
946 retval = OSSTREAM_STR (output_buf); |
3164
|
947 |
4051
|
948 OSSTREAM_FREEZE (output_buf); |
625
|
949 } |
581
|
950 } |
|
951 else |
3355
|
952 print_usage ("type"); |
|
953 } |
|
954 else |
|
955 print_usage ("type"); |
|
956 } |
3141
|
957 |
3355
|
958 abort: |
581
|
959 |
|
960 return retval; |
|
961 } |
|
962 |
3536
|
963 static std::string |
3523
|
964 do_which (const std::string& name) |
3355
|
965 { |
3523
|
966 std::string retval; |
3355
|
967 |
|
968 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
969 |
|
970 if (sym_rec && sym_rec->is_defined ()) |
|
971 retval = sym_rec->which (); |
|
972 else |
|
973 { |
3523
|
974 std::string path = fcn_file_in_path (name); |
3355
|
975 |
|
976 if (! path.empty ()) |
|
977 retval = path; |
|
978 else |
|
979 retval = "undefined"; |
|
980 } |
|
981 |
|
982 return retval; |
|
983 } |
|
984 |
|
985 static void |
3523
|
986 do_which (std::ostream& os, const std::string& name) |
3355
|
987 { |
|
988 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
989 |
|
990 if (sym_rec && sym_rec->is_defined ()) |
|
991 sym_rec->which (os); |
|
992 else |
|
993 { |
3523
|
994 std::string path = fcn_file_in_path (name); |
3355
|
995 |
|
996 if (! path.empty ()) |
|
997 os << "which: `" << name << "' is the script file\n" |
|
998 << path << "\n"; |
|
999 else |
|
1000 os << "which: `" << name << "' is undefined\n"; |
|
1001 } |
|
1002 } |
|
1003 |
4208
|
1004 DEFCMD (which, args, nargout, |
3361
|
1005 "-*- texinfo -*-\n\ |
|
1006 @deffn {Command} which name @dots{}\n\ |
|
1007 Display the type of each @var{name}. If @var{name} is defined from a\n\ |
|
1008 function file, the full name of the file is also displayed.\n\ |
|
1009 @end deffn") |
581
|
1010 { |
2086
|
1011 octave_value_list retval; |
581
|
1012 |
1968
|
1013 string_vector argv = args.make_argv ("which"); |
1755
|
1014 |
3355
|
1015 if (! error_state) |
|
1016 { |
|
1017 int argc = argv.length (); |
581
|
1018 |
|
1019 if (nargout > 0) |
|
1020 retval.resize (argc-1, Matrix ()); |
|
1021 |
3355
|
1022 if (argc > 1) |
581
|
1023 { |
3355
|
1024 for (int i = 1; i < argc; i++) |
581
|
1025 { |
3523
|
1026 std::string id = argv[i]; |
3141
|
1027 |
3355
|
1028 if (nargout == 0) |
|
1029 do_which (octave_stdout, id); |
581
|
1030 else |
3355
|
1031 retval(i-1) = do_which (id); |
581
|
1032 } |
|
1033 } |
3355
|
1034 else |
|
1035 print_usage (argv[0]); |
581
|
1036 } |
|
1037 |
|
1038 return retval; |
|
1039 } |
|
1040 |
2189
|
1041 static int |
2202
|
1042 info_file (void) |
|
1043 { |
|
1044 int status = 0; |
|
1045 |
3523
|
1046 std::string s = builtin_string_variable ("INFO_FILE"); |
2202
|
1047 |
|
1048 if (s.empty ()) |
|
1049 { |
|
1050 gripe_invalid_value_specified ("INFO_FILE"); |
|
1051 status = -1; |
|
1052 } |
|
1053 else |
|
1054 Vinfo_file = s; |
|
1055 |
|
1056 return status; |
|
1057 } |
|
1058 |
|
1059 static int |
|
1060 info_prog (void) |
|
1061 { |
|
1062 int status = 0; |
|
1063 |
3523
|
1064 std::string s = builtin_string_variable ("INFO_PROGRAM"); |
2202
|
1065 |
|
1066 if (s.empty ()) |
|
1067 { |
|
1068 gripe_invalid_value_specified ("INFO_PROGRAM"); |
|
1069 status = -1; |
|
1070 } |
|
1071 else |
|
1072 Vinfo_prog = s; |
|
1073 |
|
1074 return status; |
|
1075 } |
|
1076 |
3014
|
1077 static int |
3686
|
1078 makeinfo_prog (void) |
|
1079 { |
|
1080 int status = 0; |
|
1081 |
|
1082 std::string s = builtin_string_variable ("MAKEINFO_PROGRAM"); |
|
1083 |
|
1084 if (s.empty ()) |
|
1085 { |
|
1086 gripe_invalid_value_specified ("MAKEINFO_PROGRAM"); |
|
1087 status = -1; |
|
1088 } |
|
1089 else |
|
1090 Vmakeinfo_prog = s; |
|
1091 |
|
1092 return status; |
|
1093 } |
|
1094 |
|
1095 static int |
3014
|
1096 suppress_verbose_help_message (void) |
|
1097 { |
|
1098 Vsuppress_verbose_help_message |
|
1099 = check_preference ("suppress_verbose_help_message"); |
|
1100 |
|
1101 return 0; |
|
1102 } |
|
1103 |
2189
|
1104 void |
|
1105 symbols_of_help (void) |
|
1106 { |
3258
|
1107 DEFVAR (INFO_FILE, Vinfo_file, info_file, |
3332
|
1108 "-*- texinfo -*-\n\ |
|
1109 @defvr {Built-in Variable} INFO_FILE\n\ |
|
1110 The variable @code{INFO_FILE} names the location of the Octave info file.\n\ |
3686
|
1111 The default value is @code{\"@var{octave-home}/info/octave.info\"}, in\n\ |
|
1112 which @var{octave-home} is the directory where all of Octave is installed.\n\ |
3333
|
1113 @end defvr"); |
2202
|
1114 |
3258
|
1115 DEFVAR (INFO_PROGRAM, Vinfo_prog, info_prog, |
3332
|
1116 "-*- texinfo -*-\n\ |
3686
|
1117 @defvr {Built-in Variable} INFO_PROGRAM\n\ |
|
1118 The variable @code{INFO_PROGRAM} names the info program to run. Its\n\ |
|
1119 default initial value is\n\ |
|
1120 @code{\"@var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}/info\"}\n\ |
|
1121 in which @var{octave-home} is the directory where all of Octave is\n\ |
|
1122 installed, @var{version} is the Octave version number, and @var{arch}\n\ |
|
1123 is the system type (for example, @code{i686-pc-linux-gnu}). The\n\ |
|
1124 default initial value may be overridden by the environment variable\n\ |
|
1125 @code{OCTAVE_INFO_PROGRAM}, or the command line argument\n\ |
|
1126 @code{--info-program NAME}, or by setting the value of\n\ |
|
1127 @code{INFO_PROGRAM} in a startup script\n\ |
|
1128 @end defvr"); |
|
1129 |
|
1130 DEFVAR (MAKEINFO_PROGRAM, Vmakeinfo_prog, makeinfo_prog, |
|
1131 "-*- texinfo -*-\n\ |
|
1132 @defvr {Built-in Variable} MAKEINFO_PROGRAM\n\ |
|
1133 The variable @code{MAKEINFO_PROGRAM} names the makeinfo program that\n\ |
|
1134 Octave runs to format help text that contains Texinfo markup commands.\n\ |
|
1135 Its default initial value is @code{\"makeinfo\"}.\n\ |
3333
|
1136 @end defvr"); |
2202
|
1137 |
4233
|
1138 DEFVAR (suppress_verbose_help_message, false, suppress_verbose_help_message, |
3332
|
1139 "-*- texinfo -*-\n\ |
|
1140 @defvr {Built-in Variable} suppress_verbose_help_message\n\ |
|
1141 If the value of @code{suppress_verbose_help_message} is nonzero, Octave\n\ |
|
1142 will not add additional help information to the end of the output from\n\ |
|
1143 the @code{help} command and usage messages for built-in commands.\n\ |
3333
|
1144 @end defvr"); |
2189
|
1145 } |
|
1146 |
1
|
1147 /* |
|
1148 ;;; Local Variables: *** |
|
1149 ;;; mode: C++ *** |
|
1150 ;;; End: *** |
|
1151 */ |