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 |
5122
|
270 { "endswitch", |
|
271 "Mark the end of a switch block.", }, |
|
272 |
1
|
273 { "endwhile", |
928
|
274 "Mark the end of a while loop.", }, |
1
|
275 |
|
276 { "for", |
928
|
277 "Begin a for loop.", }, |
1
|
278 |
|
279 { "function", |
928
|
280 "Begin a function body.", }, |
1
|
281 |
|
282 { "global", |
928
|
283 "Declare variables to have global scope.", }, |
1
|
284 |
|
285 { "gplot", |
928
|
286 "Produce 2-D plots using gnuplot-like command syntax.", }, |
1
|
287 |
|
288 { "gsplot", |
928
|
289 "Produce 3-D plots using gnuplot-like command syntax.", }, |
1
|
290 |
|
291 { "if", |
928
|
292 "Begin an if block.", }, |
1
|
293 |
5040
|
294 { "otherwise", |
|
295 "The default statement in a switch block.", }, |
|
296 |
4686
|
297 { "persistent", |
|
298 "Declare variables as persistent.", }, |
|
299 |
5040
|
300 { "replot", |
|
301 "Replot a graphic.", }, |
|
302 |
1
|
303 { "return", |
928
|
304 "Return from a function.", }, |
|
305 |
5040
|
306 { "static", |
|
307 "Declare variables as persistent.", }, |
|
308 |
|
309 { "switch", |
|
310 "Begin a switch statement.",}, |
|
311 |
1489
|
312 { "try", |
|
313 "Begin a try-catch block.", }, |
|
314 |
5040
|
315 { "until", |
|
316 "End a do-until loop.",}, |
|
317 |
928
|
318 { "unwind_protect", |
|
319 "Begin an unwind_protect block.", }, |
|
320 |
|
321 { "unwind_protect_cleanup", |
|
322 "Begin the cleanup section of an unwind_protect block.", }, |
1
|
323 |
5040
|
324 { "varargin", |
|
325 "Pass an arbitrary number of arguments into a function.",}, |
|
326 |
|
327 { "varargout", |
|
328 "Pass an arbitrary number of arguments out of a function.",}, |
|
329 |
1
|
330 { "while", |
928
|
331 "Begin a while loop.", }, |
1
|
332 |
529
|
333 { 0, 0, }, |
1
|
334 }; |
|
335 |
581
|
336 // Return a copy of the operator or keyword names. |
|
337 |
3016
|
338 static string_vector |
3355
|
339 names (help_list *lst) |
1
|
340 { |
1755
|
341 string_vector retval; |
|
342 |
3355
|
343 int count = 0; |
1
|
344 help_list *ptr = lst; |
529
|
345 while (ptr->name) |
1
|
346 { |
|
347 count++; |
|
348 ptr++; |
|
349 } |
|
350 |
1755
|
351 if (count > 0) |
|
352 { |
|
353 retval.resize (count); |
1
|
354 |
1755
|
355 ptr = lst; |
|
356 for (int i = 0; i < count; i++) |
|
357 { |
|
358 retval[i] = ptr->name; |
|
359 ptr++; |
|
360 } |
1
|
361 } |
|
362 |
1755
|
363 return retval; |
1
|
364 } |
|
365 |
3014
|
366 static help_list * |
1
|
367 operator_help (void) |
|
368 { |
|
369 return operators; |
|
370 } |
|
371 |
3016
|
372 static help_list * |
1
|
373 keyword_help (void) |
|
374 { |
|
375 return keywords; |
|
376 } |
|
377 |
3016
|
378 // It's not likely that this does the right thing now. XXX FIXME XXX |
|
379 |
|
380 string_vector |
|
381 make_name_list (void) |
|
382 { |
3355
|
383 string_vector key = names (keyword_help ()); |
|
384 int key_len = key.length (); |
3016
|
385 |
4009
|
386 string_vector fbi = fbi_sym_tab->name_list (); |
|
387 int fbi_len = fbi.length (); |
|
388 |
3355
|
389 string_vector glb = global_sym_tab->name_list (); |
|
390 int glb_len = glb.length (); |
3016
|
391 |
3355
|
392 string_vector top = top_level_sym_tab->name_list (); |
|
393 int top_len = top.length (); |
3016
|
394 |
3355
|
395 string_vector lcl; |
3016
|
396 if (top_level_sym_tab != curr_sym_tab) |
3355
|
397 lcl = curr_sym_tab->name_list (); |
|
398 int lcl_len = lcl.length (); |
3016
|
399 |
3355
|
400 string_vector ffl = octave_fcn_file_name_cache::list_no_suffix (); |
3016
|
401 int ffl_len = ffl.length (); |
|
402 |
4009
|
403 int total_len = key_len + fbi_len + glb_len + top_len + lcl_len + ffl_len; |
3016
|
404 |
|
405 string_vector list (total_len); |
|
406 |
|
407 // Put all the symbols in one big list. |
|
408 |
|
409 int j = 0; |
|
410 int i = 0; |
|
411 for (i = 0; i < key_len; i++) |
|
412 list[j++] = key[i]; |
|
413 |
4009
|
414 for (i = 0; i < fbi_len; i++) |
|
415 list[j++] = fbi[i]; |
|
416 |
3016
|
417 for (i = 0; i < glb_len; i++) |
|
418 list[j++] = glb[i]; |
|
419 |
|
420 for (i = 0; i < top_len; i++) |
|
421 list[j++] = top[i]; |
|
422 |
|
423 for (i = 0; i < lcl_len; i++) |
|
424 list[j++] = lcl[i]; |
|
425 |
|
426 for (i = 0; i < ffl_len; i++) |
|
427 list[j++] = ffl[i]; |
|
428 |
|
429 return list; |
|
430 } |
|
431 |
3014
|
432 void |
3523
|
433 additional_help_message (std::ostream& os) |
2470
|
434 { |
|
435 if (! Vsuppress_verbose_help_message) |
|
436 os << "\n\ |
3259
|
437 Additional help for built-in functions, operators, and variables\n\ |
3160
|
438 is available in the on-line version of the manual. Use the command\n\ |
3295
|
439 `help -i <topic>' to search the manual index.\n\ |
|
440 \n\ |
3160
|
441 Help and information about Octave is also available on the WWW\n\ |
5041
|
442 at http://www.octave.org and via the help@octave.org\n\ |
3917
|
443 mailing list.\n"; |
3160
|
444 } |
|
445 |
2976
|
446 // XXX FIXME XXX -- this needs a major overhaul to cope with new |
|
447 // symbol table stuff. |
|
448 |
529
|
449 static void |
3523
|
450 display_names_from_help_list (std::ostream& os, help_list *list, |
542
|
451 const char *desc) |
529
|
452 { |
3355
|
453 string_vector symbols = names (list); |
3259
|
454 |
1808
|
455 if (! symbols.empty ()) |
|
456 { |
2095
|
457 os << "\n*** " << desc << ":\n\n"; |
3259
|
458 |
|
459 symbols.qsort (); |
|
460 |
2095
|
461 symbols.list_in_columns (os); |
1808
|
462 } |
529
|
463 } |
|
464 |
|
465 static void |
3523
|
466 display_symtab_names (std::ostream& os, const string_vector& names, |
|
467 const std::string& desc) |
542
|
468 { |
1808
|
469 if (! names.empty ()) |
|
470 { |
2095
|
471 os << "\n*** " << desc << ":\n\n"; |
|
472 names.list_in_columns (os); |
1808
|
473 } |
542
|
474 } |
|
475 |
|
476 #ifdef LIST_SYMBOLS |
|
477 #undef LIST_SYMBOLS |
|
478 #endif |
|
479 #define LIST_SYMBOLS(type, msg) \ |
|
480 do \ |
|
481 { \ |
3259
|
482 string_vector names \ |
4009
|
483 = fbi_sym_tab->name_list (string_vector (), true, type); \ |
3355
|
484 display_symtab_names (octave_stdout, names, msg); \ |
542
|
485 } \ |
|
486 while (0) |
529
|
487 |
3014
|
488 static void |
|
489 simple_help (void) |
|
490 { |
3160
|
491 octave_stdout << "Help is available for the topics listed below.\n"; |
|
492 |
|
493 additional_help_message (octave_stdout); |
|
494 |
3014
|
495 display_names_from_help_list (octave_stdout, operator_help (), |
|
496 "operators"); |
|
497 |
|
498 display_names_from_help_list (octave_stdout, keyword_help (), |
|
499 "reserved words"); |
|
500 |
1358
|
501 // XXX FIXME XXX -- is this distinction needed? |
|
502 |
3259
|
503 LIST_SYMBOLS (symbol_record::BUILTIN_CONSTANT, "built-in constants"); |
|
504 |
|
505 LIST_SYMBOLS (symbol_record::BUILTIN_VARIABLE, "built-in variables"); |
|
506 |
4208
|
507 LIST_SYMBOLS (symbol_record::COMMAND, "commands"); |
529
|
508 |
3010
|
509 LIST_SYMBOLS (symbol_record::MAPPER_FUNCTION, "mapper functions"); |
542
|
510 |
3010
|
511 LIST_SYMBOLS (symbol_record::BUILTIN_FUNCTION, "general functions"); |
542
|
512 |
1358
|
513 // Also need to list variables and currently compiled functions from |
|
514 // the symbol table, if there are any. |
529
|
515 |
1358
|
516 // Also need to search octave_path for script files. |
529
|
517 |
3195
|
518 string_vector dirs = Vload_path_dir_path.all_directories (); |
679
|
519 |
1787
|
520 int len = dirs.length (); |
679
|
521 |
1787
|
522 for (int i = 0; i < len; i++) |
|
523 { |
2233
|
524 string_vector names = octave_fcn_file_name_cache::list (dirs[i]); |
679
|
525 |
1787
|
526 if (! names.empty ()) |
|
527 { |
3523
|
528 std::string dir |
2926
|
529 = octave_env::make_absolute (dirs[i], octave_env::getcwd ()); |
|
530 |
|
531 octave_stdout << "\n*** function files in " << dir << ":\n\n"; |
679
|
532 |
3259
|
533 names.qsort (); |
|
534 |
2095
|
535 names.list_in_columns (octave_stdout); |
529
|
536 } |
|
537 } |
|
538 } |
|
539 |
|
540 static int |
3523
|
541 try_info (const std::string& nm) |
529
|
542 { |
|
543 int status = 0; |
|
544 |
4051
|
545 OSSTREAM cmd_buf; |
1295
|
546 |
4469
|
547 cmd_buf << "\"" << Vinfo_prog << "\" --file \"" << Vinfo_file << "\""; |
1295
|
548 |
3523
|
549 std::string directory_name = Vinfo_file; |
1755
|
550 size_t pos = directory_name.rfind ('/'); |
|
551 |
|
552 if (pos != NPOS) |
529
|
553 { |
1755
|
554 directory_name.resize (pos + 1); |
4469
|
555 cmd_buf << " --directory \"" << directory_name << "\""; |
529
|
556 } |
|
557 |
1755
|
558 if (nm.length () > 0) |
|
559 cmd_buf << " --index-search " << nm; |
529
|
560 |
4051
|
561 cmd_buf << OSSTREAM_ENDS; |
529
|
562 |
2705
|
563 volatile octave_interrupt_handler old_interrupt_handler |
2554
|
564 = octave_ignore_interrupts (); |
529
|
565 |
4051
|
566 status = system (OSSTREAM_C_STR (cmd_buf)); |
|
567 |
|
568 OSSTREAM_FREEZE (cmd_buf); |
529
|
569 |
2554
|
570 octave_set_interrupt_handler (old_interrupt_handler); |
529
|
571 |
2694
|
572 if (WIFEXITED (status)) |
|
573 status = WEXITSTATUS (status); |
1295
|
574 else |
|
575 status = 127; |
529
|
576 |
|
577 return status; |
|
578 } |
1140
|
579 |
|
580 static void |
1755
|
581 help_from_info (const string_vector& argv, int idx, int argc) |
1140
|
582 { |
1755
|
583 if (idx == argc) |
3523
|
584 try_info (std::string ()); |
1140
|
585 else |
|
586 { |
1755
|
587 for (int i = idx; i < argc; i++) |
1140
|
588 { |
1755
|
589 int status = try_info (argv[i]); |
1140
|
590 |
1295
|
591 if (status) |
1140
|
592 { |
3295
|
593 if (status == 127) |
1295
|
594 { |
3185
|
595 error ("help: unable to find info"); |
|
596 error ("help: you need info 2.18 or later (texinfo 3.12)"); |
1295
|
597 break; |
|
598 } |
3295
|
599 else |
|
600 { |
|
601 message ("help", "sorry, `%s' is not indexed in the manual", |
|
602 argv[i].c_str ()); |
|
603 } |
1140
|
604 } |
|
605 } |
|
606 } |
2470
|
607 } |
3014
|
608 |
|
609 static bool |
3523
|
610 looks_like_texinfo (const std::string& msg, size_t& p1) |
3295
|
611 { |
|
612 p1 = msg.find ('\n'); |
|
613 |
3523
|
614 std::string t = msg.substr (0, p1); |
3295
|
615 |
|
616 if (p1 == NPOS) |
|
617 p1 = 0; |
|
618 |
|
619 size_t p2 = t.find ("-*- texinfo -*-"); |
|
620 |
|
621 return (p2 != NPOS); |
|
622 } |
|
623 |
3330
|
624 void |
3523
|
625 display_help_text (std::ostream& os, const std::string& msg) |
3295
|
626 { |
|
627 // Look for "-*- texinfo -*-" in first line of help message. If it |
|
628 // is present, use makeinfo to format the rest of the message before |
|
629 // sending it to the output stream. Otherwise, just print the |
|
630 // message. |
|
631 |
|
632 size_t pos; |
|
633 |
|
634 if (looks_like_texinfo (msg, pos)) |
|
635 { |
3523
|
636 std::string tmp_file_name = file_ops::tempnam ("", ""); |
3295
|
637 |
|
638 int cols = command_editor::terminal_cols (); |
|
639 |
|
640 if (cols > 16) |
|
641 cols--; |
|
642 |
|
643 if (cols > 64) |
|
644 cols -= 7; |
|
645 |
|
646 if (cols > 80) |
|
647 cols = 72; |
|
648 |
4051
|
649 OSSTREAM buf; |
|
650 |
4115
|
651 buf << "sed -e 's/^[#%][#%]* *//' -e 's/^ *@/@/' | " |
4469
|
652 << "\"" << Vmakeinfo_prog << "\"" |
3303
|
653 << " -D \"VERSION " << OCTAVE_VERSION << "\"" |
|
654 << " -D \"OCTAVEHOME " << OCTAVE_PREFIX << "\"" |
3584
|
655 << " -D \"TARGETHOSTTYPE " << OCTAVE_CANONICAL_HOST_TYPE << "\"" |
3301
|
656 << " --fill-column " << cols |
|
657 << " --no-warn" |
|
658 << " --no-validate" |
|
659 << " --no-headers" |
|
660 << " --force" |
4108
|
661 << " --output \"" << tmp_file_name << "\"" |
3303
|
662 << " > /dev/null 2>&1" |
4051
|
663 << OSSTREAM_ENDS; |
3295
|
664 |
4051
|
665 oprocstream filter (OSSTREAM_STR (buf)); |
3295
|
666 |
4051
|
667 OSSTREAM_FREEZE (buf); |
3295
|
668 |
3686
|
669 if (filter && filter.is_open ()) |
3295
|
670 { |
3405
|
671 filter << "@macro seealso {args}\n" |
3408
|
672 << "\n" |
|
673 << "@noindent\n" |
3405
|
674 << "See also: \\args\\.\n" |
|
675 << "@end macro\n"; |
|
676 |
3769
|
677 filter << msg.substr (pos+1) << std::endl; |
3295
|
678 |
3686
|
679 int status = filter.close (); |
3295
|
680 |
3523
|
681 std::ifstream tmp_file (tmp_file_name.c_str ()); |
3295
|
682 |
3686
|
683 if (WIFEXITED (status) && WEXITSTATUS (status) == 0) |
|
684 { |
|
685 int c; |
|
686 while ((c = tmp_file.get ()) != EOF) |
|
687 os << (char) c; |
3295
|
688 |
3686
|
689 tmp_file.close (); |
|
690 } |
|
691 else |
|
692 { |
|
693 warning ("help: Texinfo formatting filter exited abnormally"); |
|
694 warning ("help: raw Texinfo source of help text follows..."); |
|
695 |
|
696 os << "\n" << msg; |
|
697 } |
3295
|
698 |
|
699 file_ops::unlink (tmp_file_name); |
|
700 } |
|
701 else |
|
702 os << msg; |
|
703 } |
|
704 else |
|
705 os << msg; |
|
706 } |
|
707 |
|
708 static bool |
3523
|
709 help_from_list (std::ostream& os, const help_list *list, |
|
710 const std::string& nm, int usage) |
542
|
711 { |
2804
|
712 const char *name; |
3014
|
713 |
542
|
714 while ((name = list->name) != 0) |
|
715 { |
1755
|
716 if (strcmp (name, nm.c_str ()) == 0) |
542
|
717 { |
|
718 if (usage) |
2095
|
719 os << "\nusage: "; |
542
|
720 else |
|
721 { |
2095
|
722 os << "\n*** " << nm << ":\n\n"; |
542
|
723 } |
|
724 |
3295
|
725 display_help_text (os, list->help); |
|
726 |
|
727 os << "\n"; |
542
|
728 |
3014
|
729 return true; |
542
|
730 } |
|
731 list++; |
|
732 } |
3014
|
733 |
|
734 return false; |
542
|
735 } |
|
736 |
3355
|
737 static bool |
3523
|
738 help_from_symbol_table (std::ostream& os, const std::string& nm) |
3355
|
739 { |
|
740 bool retval = false; |
|
741 |
|
742 symbol_record *sym_rec = lookup_by_name (nm, 0); |
|
743 |
|
744 if (sym_rec && sym_rec->is_defined ()) |
|
745 { |
3523
|
746 std::string h = sym_rec->help (); |
3355
|
747 |
|
748 if (h.length () > 0) |
|
749 { |
|
750 sym_rec->which (os); |
|
751 os << "\n"; |
|
752 display_help_text (os, h); |
|
753 os << "\n"; |
|
754 retval = true; |
|
755 } |
|
756 } |
|
757 |
|
758 return retval; |
|
759 } |
|
760 |
|
761 static bool |
3523
|
762 help_from_file (std::ostream& os, const std::string& nm) |
3355
|
763 { |
|
764 bool retval = false; |
|
765 |
3523
|
766 std::string path = fcn_file_in_path (nm); |
3355
|
767 |
3523
|
768 std::string h = get_help_from_file (path); |
3355
|
769 |
|
770 if (! h.empty ()) |
|
771 { |
|
772 os << nm << " is the file: " << path << "\n\n"; |
|
773 display_help_text (os, h); |
|
774 os << "\n"; |
|
775 retval = true; |
|
776 } |
|
777 |
|
778 return retval; |
|
779 } |
|
780 |
1140
|
781 static void |
1755
|
782 builtin_help (int argc, const string_vector& argv) |
1140
|
783 { |
|
784 help_list *op_help_list = operator_help (); |
|
785 help_list *kw_help_list = keyword_help (); |
|
786 |
1755
|
787 for (int i = 1; i < argc; i++) |
1140
|
788 { |
2095
|
789 if (help_from_list (octave_stdout, op_help_list, argv[i], 0)) |
1140
|
790 continue; |
|
791 |
2095
|
792 if (help_from_list (octave_stdout, kw_help_list, argv[i], 0)) |
1140
|
793 continue; |
|
794 |
3355
|
795 if (help_from_symbol_table (octave_stdout, argv[i])) |
|
796 continue; |
1755
|
797 |
3355
|
798 if (help_from_file (octave_stdout, argv[i])) |
|
799 continue; |
1140
|
800 |
2095
|
801 octave_stdout << "\nhelp: sorry, `" << argv[i] |
|
802 << "' is not documented\n"; |
1140
|
803 } |
|
804 |
2095
|
805 additional_help_message (octave_stdout); |
1140
|
806 } |
|
807 |
4208
|
808 DEFCMD (help, args, , |
3332
|
809 "-*- texinfo -*-\n\ |
|
810 @deffn {Command} help\n\ |
|
811 Octave's @code{help} command can be used to print brief usage-style\n\ |
|
812 messages, or to display information directly from an on-line version of\n\ |
|
813 the printed manual, using the GNU Info browser. If invoked without any\n\ |
|
814 arguments, @code{help} prints a list of all the available operators,\n\ |
|
815 functions, and built-in variables. If the first argument is @code{-i},\n\ |
|
816 the @code{help} command searches the index of the on-line version of\n\ |
|
817 this manual for the given topics.\n\ |
3168
|
818 \n\ |
3332
|
819 For example, the command @kbd{help help} prints a short message\n\ |
|
820 describing the @code{help} command, and @kbd{help -i help} starts the\n\ |
|
821 GNU Info browser at this node in the on-line version of the manual.\n\ |
|
822 \n\ |
|
823 Once the GNU Info browser is running, help for using it is available\n\ |
|
824 using the command @kbd{C-h}.\n\ |
3333
|
825 @end deffn") |
529
|
826 { |
2086
|
827 octave_value_list retval; |
529
|
828 |
1755
|
829 int argc = args.length () + 1; |
|
830 |
1968
|
831 string_vector argv = args.make_argv ("help"); |
1755
|
832 |
|
833 if (error_state) |
|
834 return retval; |
529
|
835 |
|
836 if (argc == 1) |
3014
|
837 simple_help (); |
529
|
838 else |
|
839 { |
1755
|
840 if (argv[1] == "-i") |
3014
|
841 help_from_info (argv, 2, argc); |
529
|
842 else |
3014
|
843 builtin_help (argc, argv); |
529
|
844 } |
|
845 |
|
846 return retval; |
|
847 } |
|
848 |
3355
|
849 static void |
3523
|
850 do_type (std::ostream& os, const std::string& name, bool pr_type_info, |
3355
|
851 bool quiet, bool pr_orig_txt) |
|
852 { |
|
853 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
854 |
|
855 if (sym_rec && sym_rec->is_defined ()) |
3356
|
856 sym_rec->type (os, pr_type_info, quiet, pr_orig_txt); |
3355
|
857 else |
|
858 { |
3523
|
859 std::string ff = fcn_file_in_path (name); |
3355
|
860 |
|
861 if (! ff.empty ()) |
|
862 { |
3538
|
863 std::ifstream fs (ff.c_str (), std::ios::in); |
3355
|
864 |
|
865 if (fs) |
|
866 { |
|
867 if (pr_type_info && ! quiet) |
|
868 os << name << " is the script file: " << ff << "\n\n"; |
|
869 |
|
870 char ch; |
|
871 |
|
872 while (fs.get (ch)) |
|
873 os << ch; |
|
874 } |
|
875 else |
|
876 os << "unable to open `" << ff << "' for reading!\n"; |
|
877 } |
|
878 else |
|
879 error ("type: `%s' undefined", name.c_str ()); |
|
880 } |
|
881 } |
|
882 |
4208
|
883 DEFCMD (type, args, nargout, |
3361
|
884 "-*- texinfo -*-\n\ |
|
885 \n\ |
|
886 @deffn {Command} type options name @dots{}\n\ |
|
887 Display the definition of each @var{name} that refers to a function.\n\ |
|
888 \n\ |
|
889 Normally also displays if each @var{name} is user-defined or builtin;\n\ |
|
890 the @code{-q} option suppresses this behaviour.\n\ |
581
|
891 \n\ |
3361
|
892 Currently, Octave can only display functions that can be compiled\n\ |
|
893 cleanly, because it uses its internal representation of the function to\n\ |
|
894 recreate the program text.\n\ |
|
895 \n\ |
|
896 Comments are not displayed because Octave's parser currently discards\n\ |
|
897 them as it converts the text of a function file to its internal\n\ |
|
898 representation. This problem may be fixed in a future release.\n\ |
|
899 @end deffn") |
581
|
900 { |
3584
|
901 octave_value retval; |
1588
|
902 |
1755
|
903 int argc = args.length () + 1; |
|
904 |
1968
|
905 string_vector argv = args.make_argv ("type"); |
1755
|
906 |
3355
|
907 if (! error_state) |
581
|
908 { |
3355
|
909 if (argc > 1) |
|
910 { |
|
911 // XXX FIXME XXX -- we should really use getopt () |
2532
|
912 |
3355
|
913 bool quiet = false; |
|
914 bool pr_orig_txt = true; |
2532
|
915 |
3355
|
916 int idx; |
581
|
917 |
3355
|
918 for (idx = 1; idx < argc; idx++) |
1281
|
919 { |
3355
|
920 if (argv[idx] == "-q" || argv[idx] == "-quiet") |
|
921 quiet = true; |
|
922 else if (argv[idx] == "-t" || argv[idx] == "-transformed") |
|
923 pr_orig_txt = false; |
|
924 else |
|
925 break; |
1281
|
926 } |
|
927 |
3355
|
928 if (idx < argc) |
|
929 { |
4051
|
930 OSSTREAM output_buf; |
581
|
931 |
3355
|
932 for (int i = idx; i < argc; i++) |
581
|
933 { |
3523
|
934 std::string id = argv[i]; |
2534
|
935 |
3355
|
936 if (nargout == 0) |
|
937 do_type (octave_stdout, id, true, quiet, pr_orig_txt); |
|
938 else |
|
939 do_type (output_buf, id, false, quiet, pr_orig_txt); |
581
|
940 |
3355
|
941 if (error_state) |
|
942 goto abort; |
581
|
943 } |
|
944 |
3584
|
945 if (nargout != 0) |
625
|
946 { |
4051
|
947 output_buf << OSSTREAM_ENDS; |
3164
|
948 |
4051
|
949 retval = OSSTREAM_STR (output_buf); |
3164
|
950 |
4051
|
951 OSSTREAM_FREEZE (output_buf); |
625
|
952 } |
581
|
953 } |
|
954 else |
3355
|
955 print_usage ("type"); |
|
956 } |
|
957 else |
|
958 print_usage ("type"); |
|
959 } |
3141
|
960 |
3355
|
961 abort: |
581
|
962 |
|
963 return retval; |
|
964 } |
|
965 |
3536
|
966 static std::string |
3523
|
967 do_which (const std::string& name) |
3355
|
968 { |
3523
|
969 std::string retval; |
3355
|
970 |
|
971 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
972 |
|
973 if (sym_rec && sym_rec->is_defined ()) |
|
974 retval = sym_rec->which (); |
|
975 else |
|
976 { |
3523
|
977 std::string path = fcn_file_in_path (name); |
3355
|
978 |
|
979 if (! path.empty ()) |
|
980 retval = path; |
|
981 else |
|
982 retval = "undefined"; |
|
983 } |
|
984 |
|
985 return retval; |
|
986 } |
|
987 |
|
988 static void |
3523
|
989 do_which (std::ostream& os, const std::string& name) |
3355
|
990 { |
|
991 symbol_record *sym_rec = lookup_by_name (name, 0); |
|
992 |
|
993 if (sym_rec && sym_rec->is_defined ()) |
|
994 sym_rec->which (os); |
|
995 else |
|
996 { |
3523
|
997 std::string path = fcn_file_in_path (name); |
3355
|
998 |
|
999 if (! path.empty ()) |
|
1000 os << "which: `" << name << "' is the script file\n" |
|
1001 << path << "\n"; |
|
1002 else |
|
1003 os << "which: `" << name << "' is undefined\n"; |
|
1004 } |
|
1005 } |
|
1006 |
4208
|
1007 DEFCMD (which, args, nargout, |
3361
|
1008 "-*- texinfo -*-\n\ |
|
1009 @deffn {Command} which name @dots{}\n\ |
|
1010 Display the type of each @var{name}. If @var{name} is defined from a\n\ |
|
1011 function file, the full name of the file is also displayed.\n\ |
|
1012 @end deffn") |
581
|
1013 { |
2086
|
1014 octave_value_list retval; |
581
|
1015 |
1968
|
1016 string_vector argv = args.make_argv ("which"); |
1755
|
1017 |
3355
|
1018 if (! error_state) |
|
1019 { |
|
1020 int argc = argv.length (); |
581
|
1021 |
|
1022 if (nargout > 0) |
|
1023 retval.resize (argc-1, Matrix ()); |
|
1024 |
3355
|
1025 if (argc > 1) |
581
|
1026 { |
3355
|
1027 for (int i = 1; i < argc; i++) |
581
|
1028 { |
3523
|
1029 std::string id = argv[i]; |
3141
|
1030 |
3355
|
1031 if (nargout == 0) |
|
1032 do_which (octave_stdout, id); |
581
|
1033 else |
3355
|
1034 retval(i-1) = do_which (id); |
581
|
1035 } |
|
1036 } |
3355
|
1037 else |
|
1038 print_usage (argv[0]); |
581
|
1039 } |
|
1040 |
|
1041 return retval; |
|
1042 } |
|
1043 |
2189
|
1044 static int |
2202
|
1045 info_file (void) |
|
1046 { |
|
1047 int status = 0; |
|
1048 |
3523
|
1049 std::string s = builtin_string_variable ("INFO_FILE"); |
2202
|
1050 |
|
1051 if (s.empty ()) |
|
1052 { |
|
1053 gripe_invalid_value_specified ("INFO_FILE"); |
|
1054 status = -1; |
|
1055 } |
|
1056 else |
|
1057 Vinfo_file = s; |
|
1058 |
|
1059 return status; |
|
1060 } |
|
1061 |
|
1062 static int |
|
1063 info_prog (void) |
|
1064 { |
|
1065 int status = 0; |
|
1066 |
3523
|
1067 std::string s = builtin_string_variable ("INFO_PROGRAM"); |
2202
|
1068 |
|
1069 if (s.empty ()) |
|
1070 { |
|
1071 gripe_invalid_value_specified ("INFO_PROGRAM"); |
|
1072 status = -1; |
|
1073 } |
|
1074 else |
|
1075 Vinfo_prog = s; |
|
1076 |
|
1077 return status; |
|
1078 } |
|
1079 |
3014
|
1080 static int |
3686
|
1081 makeinfo_prog (void) |
|
1082 { |
|
1083 int status = 0; |
|
1084 |
|
1085 std::string s = builtin_string_variable ("MAKEINFO_PROGRAM"); |
|
1086 |
|
1087 if (s.empty ()) |
|
1088 { |
|
1089 gripe_invalid_value_specified ("MAKEINFO_PROGRAM"); |
|
1090 status = -1; |
|
1091 } |
|
1092 else |
|
1093 Vmakeinfo_prog = s; |
|
1094 |
|
1095 return status; |
|
1096 } |
|
1097 |
|
1098 static int |
3014
|
1099 suppress_verbose_help_message (void) |
|
1100 { |
|
1101 Vsuppress_verbose_help_message |
|
1102 = check_preference ("suppress_verbose_help_message"); |
|
1103 |
|
1104 return 0; |
|
1105 } |
|
1106 |
2189
|
1107 void |
|
1108 symbols_of_help (void) |
|
1109 { |
3258
|
1110 DEFVAR (INFO_FILE, Vinfo_file, info_file, |
3332
|
1111 "-*- texinfo -*-\n\ |
|
1112 @defvr {Built-in Variable} INFO_FILE\n\ |
|
1113 The variable @code{INFO_FILE} names the location of the Octave info file.\n\ |
3686
|
1114 The default value is @code{\"@var{octave-home}/info/octave.info\"}, in\n\ |
|
1115 which @var{octave-home} is the directory where all of Octave is installed.\n\ |
3333
|
1116 @end defvr"); |
2202
|
1117 |
3258
|
1118 DEFVAR (INFO_PROGRAM, Vinfo_prog, info_prog, |
3332
|
1119 "-*- texinfo -*-\n\ |
3686
|
1120 @defvr {Built-in Variable} INFO_PROGRAM\n\ |
|
1121 The variable @code{INFO_PROGRAM} names the info program to run. Its\n\ |
|
1122 default initial value is\n\ |
|
1123 @code{\"@var{octave-home}/libexec/octave/@var{version}/exec/@var{arch}/info\"}\n\ |
|
1124 in which @var{octave-home} is the directory where all of Octave is\n\ |
|
1125 installed, @var{version} is the Octave version number, and @var{arch}\n\ |
|
1126 is the system type (for example, @code{i686-pc-linux-gnu}). The\n\ |
|
1127 default initial value may be overridden by the environment variable\n\ |
|
1128 @code{OCTAVE_INFO_PROGRAM}, or the command line argument\n\ |
|
1129 @code{--info-program NAME}, or by setting the value of\n\ |
|
1130 @code{INFO_PROGRAM} in a startup script\n\ |
|
1131 @end defvr"); |
|
1132 |
|
1133 DEFVAR (MAKEINFO_PROGRAM, Vmakeinfo_prog, makeinfo_prog, |
|
1134 "-*- texinfo -*-\n\ |
|
1135 @defvr {Built-in Variable} MAKEINFO_PROGRAM\n\ |
|
1136 The variable @code{MAKEINFO_PROGRAM} names the makeinfo program that\n\ |
|
1137 Octave runs to format help text that contains Texinfo markup commands.\n\ |
|
1138 Its default initial value is @code{\"makeinfo\"}.\n\ |
3333
|
1139 @end defvr"); |
2202
|
1140 |
4233
|
1141 DEFVAR (suppress_verbose_help_message, false, suppress_verbose_help_message, |
3332
|
1142 "-*- texinfo -*-\n\ |
|
1143 @defvr {Built-in Variable} suppress_verbose_help_message\n\ |
|
1144 If the value of @code{suppress_verbose_help_message} is nonzero, Octave\n\ |
|
1145 will not add additional help information to the end of the output from\n\ |
|
1146 the @code{help} command and usage messages for built-in commands.\n\ |
3333
|
1147 @end defvr"); |
2189
|
1148 } |
|
1149 |
1
|
1150 /* |
|
1151 ;;; Local Variables: *** |
|
1152 ;;; mode: C++ *** |
|
1153 ;;; End: *** |
|
1154 */ |