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