1
|
1 // help.cc -*- C++ -*- |
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
529
|
28 #include <signal.h> |
|
29 #include <stdlib.h> |
1
|
30 #include <iostream.h> |
529
|
31 #include <strstream.h> |
240
|
32 |
581
|
33 #include "tree-expr.h" |
|
34 #include "tree-const.h" |
529
|
35 #include "sighandlers.h" |
|
36 #include "user-prefs.h" |
|
37 #include "tree-expr.h" |
|
38 #include "variables.h" |
|
39 #include "oct-obj.h" |
|
40 #include "symtab.h" |
|
41 #include "octave.h" |
|
42 #include "dirfns.h" |
|
43 #include "pager.h" |
|
44 #include "error.h" |
242
|
45 #include "utils.h" |
1
|
46 #include "help.h" |
529
|
47 #include "defun.h" |
|
48 |
1140
|
49 #ifdef USE_GNU_INFO |
529
|
50 extern "C" |
|
51 { |
|
52 #include "info/info.h" |
|
53 #include "info/dribble.h" |
|
54 #include "info/terminal.h" |
|
55 |
|
56 extern int initialize_info_session (); |
|
57 extern int index_entry_exists (); |
|
58 extern int do_info_index_search (); |
|
59 extern void finish_info_session (); |
|
60 extern char *replace_in_documentation (); |
1140
|
61 } |
|
62 #endif |
529
|
63 |
1140
|
64 extern "C" |
|
65 { |
529
|
66 // XXX FIXME XXX |
|
67 #undef __FUNCTION_DEF |
|
68 #include <readline/tilde.h> |
1140
|
69 } |
679
|
70 |
1140
|
71 extern "C" |
|
72 { |
679
|
73 #define boolean kpathsea_boolean |
|
74 #define false kpathsea_false |
|
75 #define true kpathsea_true |
|
76 #include <kpathsea/pathsearch.h> |
529
|
77 } |
1
|
78 |
|
79 static help_list operators[] = |
|
80 { |
|
81 { "!", |
|
82 "Logical not operator. See also `~'.\n", }, |
|
83 |
|
84 { "!=", |
|
85 "Logical not equals operator. See also `~' and `<>'.\n", }, |
|
86 |
|
87 { "\"", |
|
88 "String delimiter.\n", }, |
|
89 |
|
90 { "#", |
928
|
91 "Begin comment character. See also `%'.", }, |
1
|
92 |
|
93 { "%", |
928
|
94 "Begin comment charcter. See also `#'.", }, |
1
|
95 |
|
96 { "&", |
928
|
97 "Logical and operator. See also `&&'.", }, |
1
|
98 |
|
99 { "&&", |
928
|
100 "Logical and operator. See also `&'.", }, |
1
|
101 |
|
102 { "'", |
|
103 "Matrix transpose operator. For complex matrices, computes the\n\ |
|
104 complex conjugate (Hermitian) transpose. See also `.''\n\ |
|
105 \n\ |
|
106 The single quote character may also be used to delimit strings, but\n\ |
|
107 it is better to use the double quote character, since that is never\n\ |
928
|
108 ambiguous", }, |
1
|
109 |
|
110 { "(", |
928
|
111 "Array index or function argument delimiter.", }, |
1
|
112 |
|
113 { ")", |
928
|
114 "Array index or function argument delimiter.", }, |
1
|
115 |
|
116 { "*", |
928
|
117 "Multiplication operator. See also `.*'", }, |
1
|
118 |
|
119 { "**", |
928
|
120 "Power operator. See also `^', `.**', and `.^'", }, |
1
|
121 |
|
122 { "+", |
928
|
123 "Addition operator.", }, |
1
|
124 |
|
125 { "++", |
928
|
126 "Increment operator. As in C, may be applied as a prefix or postfix operator.", }, |
1
|
127 |
|
128 { ",", |
928
|
129 "Array index, function argument, or command separator.", }, |
1
|
130 |
|
131 { "-", |
928
|
132 "Subtraction or unary negation operator.", }, |
1
|
133 |
|
134 { "--", |
928
|
135 "Decrement operator. As in C, may be applied as a prefix or postfix operator.", }, |
1
|
136 |
|
137 { ".'", |
|
138 "Matrix transpose operator. For complex matrices, computes the\n\ |
928
|
139 transpose, *not* the complex conjugate transpose. See also `''.", }, |
1
|
140 |
|
141 { ".*", |
928
|
142 "Element by element multiplication operator. See also `*'.", }, |
1
|
143 |
|
144 { ".**", |
928
|
145 "Element by element power operator. See also `**', `^', and `.^'.", }, |
1
|
146 |
|
147 { "./", |
928
|
148 "Element by element division operator. See also `/' and `\\'.", }, |
1
|
149 |
|
150 { ".^", |
928
|
151 "Element by element power operator. See also `**', `^', and `.^'.", }, |
1
|
152 |
|
153 { "/", |
928
|
154 "Right division. See also `\\' and `./'.", }, |
1
|
155 |
|
156 { ":", |
928
|
157 "Select entire rows or columns of matrices.", }, |
1
|
158 |
|
159 { ";", |
928
|
160 "Array row or command separator. See also `,'.", }, |
1
|
161 |
|
162 { "<", |
928
|
163 "Less than operator.", }, |
1
|
164 |
|
165 { "<=", |
928
|
166 "Less than or equals operator.", }, |
1
|
167 |
|
168 { "<>", |
928
|
169 "Logical not equals operator. See also `!=' and `~='.", }, |
1
|
170 |
|
171 { "=", |
928
|
172 "Assignment operator.", }, |
1
|
173 |
|
174 { "==", |
928
|
175 "Equality test operator.", }, |
1
|
176 |
|
177 { ">", |
928
|
178 "Greater than operator.", }, |
1
|
179 |
|
180 { ">=", |
928
|
181 "Greater than or equals operator.", }, |
1
|
182 |
|
183 { "[", |
928
|
184 "Return list delimiter. See also `]'.", }, |
1
|
185 |
|
186 { "\\", |
928
|
187 "Left division operator. See also `/' and `./'.", }, |
1
|
188 |
|
189 { "]", |
928
|
190 "Return list delimiter. See also `['.", }, |
1
|
191 |
|
192 { "^", |
928
|
193 "Power operator. See also `**', `.^', and `.**.'", }, |
1
|
194 |
|
195 { "|", |
928
|
196 "Logical or operator. See also `||'.", }, |
1
|
197 |
|
198 { "||", |
928
|
199 "Logical or operator. See also `|'.", }, |
1
|
200 |
|
201 { "~", |
928
|
202 "Logical not operator. See also `!' and `~'.", }, |
1
|
203 |
|
204 { "~=", |
928
|
205 "Logical not equals operator. See also `<>' and `!='.", }, |
1
|
206 |
529
|
207 { 0, 0, }, |
1
|
208 }; |
|
209 |
|
210 static help_list keywords[] = |
|
211 { |
928
|
212 { "all_va_args", |
|
213 "Pass all unnamed arguments to another function call.", }, |
|
214 |
1
|
215 { "break", |
928
|
216 "Exit the innermost enclosing while or for loop.", }, |
1
|
217 |
|
218 { "continue", |
928
|
219 "Jump to the end of the innermost enclosing while or for loop.", }, |
1
|
220 |
|
221 { "else", |
928
|
222 "Alternate action for an if block.", }, |
1
|
223 |
|
224 { "elseif", |
928
|
225 "Alternate conditional test for an if block.", }, |
1
|
226 |
|
227 { "end", |
928
|
228 "Mark the end of any for, if, while, or function block.", }, |
|
229 |
|
230 { "end_unwind_protect", |
|
231 "Mark the end of an unwind_protect block.", }, |
1
|
232 |
|
233 { "endfor", |
928
|
234 "Mark the end of a for loop.", }, |
1
|
235 |
|
236 { "endfunction", |
928
|
237 "Mark the end of a function.", }, |
1
|
238 |
|
239 { "endif", |
928
|
240 "Mark the end of an if block.", }, |
1
|
241 |
|
242 { "endwhile", |
928
|
243 "Mark the end of a while loop.", }, |
1
|
244 |
|
245 { "for", |
928
|
246 "Begin a for loop.", }, |
1
|
247 |
|
248 { "function", |
928
|
249 "Begin a function body.", }, |
1
|
250 |
|
251 { "global", |
928
|
252 "Declare variables to have global scope.", }, |
1
|
253 |
|
254 { "gplot", |
928
|
255 "Produce 2-D plots using gnuplot-like command syntax.", }, |
1
|
256 |
|
257 { "gsplot", |
928
|
258 "Produce 3-D plots using gnuplot-like command syntax.", }, |
1
|
259 |
|
260 { "if", |
928
|
261 "Begin an if block.", }, |
1
|
262 |
|
263 { "return", |
928
|
264 "Return from a function.", }, |
|
265 |
|
266 { "unwind_protect", |
|
267 "Begin an unwind_protect block.", }, |
|
268 |
|
269 { "unwind_protect_cleanup", |
|
270 "Begin the cleanup section of an unwind_protect block.", }, |
1
|
271 |
|
272 { "while", |
928
|
273 "Begin a while loop.", }, |
1
|
274 |
529
|
275 { 0, 0, }, |
1
|
276 }; |
|
277 |
581
|
278 // Return a copy of the operator or keyword names. |
|
279 |
1
|
280 char ** |
|
281 names (help_list *lst, int& count) |
|
282 { |
|
283 count = 0; |
|
284 help_list *ptr = lst; |
529
|
285 while (ptr->name) |
1
|
286 { |
|
287 count++; |
|
288 ptr++; |
|
289 } |
|
290 |
|
291 if (count == 0) |
529
|
292 return 0; |
1
|
293 |
|
294 char **name_list = new char * [count+1]; |
|
295 |
|
296 ptr = lst; |
|
297 int i = 0; |
529
|
298 while (ptr->name) |
1
|
299 { |
242
|
300 name_list[i++] = strsave (ptr->name); |
1
|
301 ptr++; |
|
302 } |
|
303 |
529
|
304 name_list[i] = 0; |
1
|
305 return name_list; |
|
306 } |
|
307 |
|
308 help_list * |
|
309 operator_help (void) |
|
310 { |
|
311 return operators; |
|
312 } |
|
313 |
|
314 help_list * |
|
315 keyword_help (void) |
|
316 { |
|
317 return keywords; |
|
318 } |
|
319 |
1115
|
320 #define VERBOSE_HELP_MESSAGE \ |
|
321 "\n\ |
|
322 Additional help for builtin functions, operators, and variables\n\ |
|
323 is available in the on-line version of the manual.\n\ |
|
324 \n\ |
|
325 Use the command `help -i <topic>' to search the manual index.\n" |
|
326 |
|
327 static void |
1117
|
328 additional_help_message (ostrstream& output_buf) |
542
|
329 { |
1140
|
330 #ifdef USE_GNU_INFO |
1117
|
331 if (! user_pref.suppress_verbose_help_message) |
1115
|
332 output_buf << VERBOSE_HELP_MESSAGE; |
1140
|
333 #endif |
542
|
334 } |
|
335 |
|
336 void |
|
337 print_usage (const char *string, int just_usage) |
|
338 { |
|
339 ostrstream output_buf; |
|
340 |
|
341 symbol_record *sym_rec = global_sym_tab->lookup (string, 0, 0); |
|
342 if (sym_rec) |
|
343 { |
|
344 char *h = sym_rec->help (); |
|
345 if (h && *h) |
|
346 { |
|
347 output_buf << "\n*** " << string << ":\n\n" |
|
348 << h << "\n"; |
|
349 |
1117
|
350 if (! just_usage) |
1118
|
351 additional_help_message (output_buf); |
542
|
352 output_buf << ends; |
|
353 maybe_page_output (output_buf); |
|
354 } |
|
355 } |
1023
|
356 else |
|
357 warning ("no usage message found for `%s'", string); |
542
|
358 } |
|
359 |
529
|
360 static void |
542
|
361 display_names_from_help_list (ostrstream& output_buf, help_list *list, |
|
362 const char *desc) |
529
|
363 { |
|
364 int count = 0; |
|
365 char **symbols = names (list, count); |
|
366 output_buf << "\n*** " << desc << ":\n\n"; |
|
367 if (symbols && count > 0) |
|
368 list_in_columns (output_buf, symbols); |
|
369 delete [] symbols; |
|
370 } |
|
371 |
742
|
372 static char * |
|
373 print_symbol_type (ostrstream& output_buf, symbol_record *sym_rec, |
|
374 char *name, int print) |
|
375 { |
|
376 char *retval = 0; |
|
377 |
|
378 if (sym_rec->is_user_function ()) |
|
379 { |
|
380 tree_fvc *defn = sym_rec->def (); |
|
381 char *fn = defn->fcn_file_name (); |
|
382 if (fn) |
|
383 { |
|
384 char *ff = fcn_file_in_path (fn); |
|
385 ff = ff ? ff : fn; |
|
386 |
|
387 if (print) |
|
388 output_buf << name |
|
389 << " is the function defined from:\n" |
|
390 << ff << "\n"; |
|
391 else |
|
392 retval = ff; |
|
393 } |
|
394 else |
|
395 { |
|
396 if (print) |
|
397 output_buf << name << " is a user-defined function\n"; |
|
398 else |
|
399 retval = "user-defined function"; |
|
400 } |
|
401 } |
|
402 else if (sym_rec->is_text_function ()) |
|
403 { |
|
404 if (print) |
|
405 output_buf << name << " is a builtin text-function\n"; |
|
406 else |
|
407 retval = "builtin text-function"; |
|
408 } |
|
409 else if (sym_rec->is_builtin_function ()) |
|
410 { |
|
411 if (print) |
|
412 output_buf << name << " is a builtin function\n"; |
|
413 else |
|
414 retval = "builtin function"; |
|
415 } |
|
416 else if (sym_rec->is_user_variable ()) |
|
417 { |
|
418 if (print) |
|
419 output_buf << name << " is a user-defined variable\n"; |
|
420 else |
|
421 retval = "user-defined variable"; |
|
422 } |
|
423 else if (sym_rec->is_builtin_variable ()) |
|
424 { |
|
425 if (print) |
|
426 output_buf << name << " is a builtin variable\n"; |
|
427 else |
|
428 retval = "builtin variable"; |
|
429 } |
|
430 else |
|
431 { |
|
432 if (print) |
|
433 output_buf << "which: `" << name |
|
434 << "' has unknown type\n"; |
|
435 else |
|
436 retval = "unknown type"; |
|
437 } |
|
438 |
|
439 return retval; |
|
440 } |
|
441 |
529
|
442 static void |
542
|
443 display_symtab_names (ostrstream& output_buf, char **names, |
|
444 int count, const char *desc) |
|
445 { |
|
446 output_buf << "\n*** " << desc << ":\n\n"; |
|
447 if (names && count > 0) |
|
448 list_in_columns (output_buf, names); |
|
449 } |
|
450 |
|
451 static void |
529
|
452 simple_help (void) |
|
453 { |
|
454 ostrstream output_buf; |
|
455 |
542
|
456 display_names_from_help_list (output_buf, operator_help (), |
|
457 "operators"); |
529
|
458 |
542
|
459 display_names_from_help_list (output_buf, keyword_help (), |
|
460 "reserved words"); |
529
|
461 |
542
|
462 #ifdef LIST_SYMBOLS |
|
463 #undef LIST_SYMBOLS |
|
464 #endif |
|
465 #define LIST_SYMBOLS(type, msg) \ |
|
466 do \ |
|
467 { \ |
|
468 int count; \ |
867
|
469 char **names = global_sym_tab->list (count, 0, 0, 1, type); \ |
542
|
470 display_symtab_names (output_buf, names, count, msg); \ |
|
471 char **ptr = names; \ |
|
472 while (*ptr) \ |
|
473 delete [] *ptr++; \ |
|
474 delete [] names; \ |
|
475 } \ |
|
476 while (0) |
529
|
477 |
542
|
478 // XXX FIXME XXX -- is this distinction needed? |
|
479 LIST_SYMBOLS (symbol_def::TEXT_FUNCTION, |
|
480 "text functions (these names are also reserved)"); |
529
|
481 |
542
|
482 LIST_SYMBOLS (symbol_def::MAPPER_FUNCTION, "mapper functions"); |
|
483 |
|
484 LIST_SYMBOLS (symbol_def::BUILTIN_FUNCTION, "general functions"); |
|
485 |
|
486 LIST_SYMBOLS (symbol_def::BUILTIN_VARIABLE, "builtin variables"); |
|
487 |
529
|
488 // Also need to list variables and currently compiled functions from |
|
489 // the symbol table, if there are any. |
|
490 |
|
491 // Also need to search octave_path for script files. |
|
492 |
679
|
493 char *path_elt = kpse_path_element (user_pref.loadpath); |
529
|
494 |
679
|
495 while (path_elt) |
529
|
496 { |
679
|
497 str_llist_type *elt_dirs = kpse_element_dirs (path_elt); |
|
498 |
|
499 str_llist_elt_type *dir; |
|
500 for (dir = *elt_dirs; dir; dir = STR_LLIST_NEXT (*dir)) |
529
|
501 { |
679
|
502 char *elt_dir = STR_LLIST (*dir); |
|
503 |
|
504 if (elt_dir) |
|
505 { |
|
506 int count; |
|
507 char **names = get_fcn_file_names (count, elt_dir, 0); |
|
508 |
|
509 output_buf << "\n*** function files in " |
|
510 << make_absolute (elt_dir, the_current_working_directory) |
|
511 << ":\n\n"; |
|
512 |
|
513 if (names && count > 0) |
|
514 list_in_columns (output_buf, names); |
|
515 |
|
516 delete [] names; |
|
517 } |
529
|
518 } |
679
|
519 path_elt = kpse_path_element (0); |
529
|
520 } |
|
521 |
|
522 additional_help_message (output_buf); |
|
523 output_buf << ends; |
|
524 maybe_page_output (output_buf); |
|
525 } |
|
526 |
1140
|
527 #ifdef USE_GNU_INFO |
529
|
528 static int |
|
529 try_info (const char *string, int force = 0) |
|
530 { |
|
531 int status = 0; |
|
532 |
|
533 char *directory_name = strsave (user_pref.info_file); |
|
534 char *temp = filename_non_directory (directory_name); |
|
535 |
|
536 if (temp != directory_name) |
|
537 { |
|
538 *temp = 0; |
|
539 info_add_path (directory_name, INFOPATH_PREPEND); |
|
540 } |
|
541 |
|
542 delete [] directory_name; |
|
543 |
|
544 NODE *initial_node = info_get_node (user_pref.info_file, 0); |
|
545 |
|
546 if (! initial_node) |
|
547 { |
|
548 warning ("can't find info file!\n"); |
|
549 status = -1; |
|
550 } |
|
551 else |
|
552 { |
|
553 status = initialize_info_session (initial_node, 0); |
|
554 |
|
555 if (status == 0 && (force || index_entry_exists (windows, string))) |
|
556 { |
|
557 terminal_clear_screen (); |
|
558 |
|
559 terminal_prep_terminal (); |
|
560 |
|
561 display_update_display (windows); |
|
562 |
|
563 info_last_executed_command = 0; |
|
564 |
|
565 if (! force) |
|
566 do_info_index_search (windows, 0, string); |
|
567 |
|
568 char *format = replace_in_documentation |
|
569 ("Type \"\\[quit]\" to quit, \"\\[get-help-window]\" for help."); |
|
570 |
|
571 window_message_in_echo_area (format); |
|
572 |
|
573 info_read_and_dispatch (); |
|
574 |
|
575 terminal_goto_xy (0, screenheight - 1); |
|
576 |
|
577 terminal_clear_to_eol (); |
|
578 |
|
579 terminal_unprep_terminal (); |
|
580 |
|
581 status = 1; |
|
582 } |
|
583 |
|
584 finish_info_session (initial_node, 0); |
|
585 } |
|
586 |
|
587 return status; |
|
588 } |
1140
|
589 #endif |
|
590 |
|
591 static void |
|
592 help_from_info (int argc, char **argv) |
|
593 { |
|
594 #ifdef USE_GNU_INFO |
|
595 if (argc == 1) |
|
596 { |
|
597 volatile sig_handler *old_sigint_handler; |
|
598 old_sigint_handler = signal (SIGINT, SIG_IGN); |
|
599 |
|
600 try_info (0, 1); |
|
601 |
|
602 signal (SIGINT, old_sigint_handler); |
|
603 } |
|
604 else |
|
605 { |
|
606 while (--argc > 0) |
|
607 { |
|
608 argv++; |
|
609 |
|
610 if (! *argv || ! **argv) |
|
611 continue; |
|
612 |
|
613 volatile sig_handler *old_sigint_handler; |
|
614 old_sigint_handler = signal (SIGINT, SIG_IGN); |
|
615 |
|
616 if (! try_info (*argv)) |
|
617 { |
|
618 message ("help", "sorry, `%s' is not indexed in the manual", |
|
619 *argv); |
|
620 sleep (2); |
|
621 } |
|
622 |
|
623 signal (SIGINT, old_sigint_handler); |
|
624 } |
|
625 } |
|
626 #else |
|
627 message (0, "sorry, help -i is not available in this version of Octave"); |
|
628 #endif |
|
629 } |
529
|
630 |
542
|
631 int |
|
632 help_from_list (ostrstream& output_buf, const help_list *list, |
|
633 const char *string, int usage) |
|
634 { |
|
635 char *name; |
|
636 while ((name = list->name) != 0) |
|
637 { |
|
638 if (strcmp (name, string) == 0) |
|
639 { |
|
640 if (usage) |
|
641 output_buf << "\nusage: "; |
|
642 else |
|
643 { |
|
644 output_buf << "\n*** " << string << ":\n\n"; |
|
645 } |
|
646 |
|
647 output_buf << list->help << "\n"; |
|
648 |
|
649 return 1; |
|
650 } |
|
651 list++; |
|
652 } |
|
653 return 0; |
|
654 } |
|
655 |
1140
|
656 static void |
|
657 builtin_help (int argc, char **argv) |
|
658 { |
|
659 ostrstream output_buf; |
|
660 |
|
661 help_list *op_help_list = operator_help (); |
|
662 help_list *kw_help_list = keyword_help (); |
|
663 |
|
664 while (--argc > 0) |
|
665 { |
|
666 argv++; |
|
667 |
|
668 if (! *argv || ! **argv) |
|
669 continue; |
|
670 |
|
671 if (help_from_list (output_buf, op_help_list, *argv, 0)) |
|
672 continue; |
|
673 |
|
674 if (help_from_list (output_buf, kw_help_list, *argv, 0)) |
|
675 continue; |
|
676 |
|
677 symbol_record *sym_rec = lookup_by_name (*argv, 0); |
|
678 |
|
679 if (sym_rec && sym_rec->is_defined ()) |
|
680 { |
|
681 char *h = sym_rec->help (); |
|
682 if (h && *h) |
|
683 { |
|
684 print_symbol_type (output_buf, sym_rec, *argv, 1); |
|
685 output_buf << "\n" << h << "\n"; |
|
686 continue; |
|
687 } |
|
688 } |
|
689 |
|
690 char *path = fcn_file_in_path (*argv); |
|
691 char *h = get_help_from_file (path); |
|
692 if (h && *h) |
|
693 { |
|
694 output_buf << *argv << " is the file:\n" |
|
695 << path << "\n\n" << h << "\n"; |
|
696 delete [] h; |
|
697 delete [] path; |
|
698 continue; |
|
699 } |
|
700 delete [] path; |
|
701 |
|
702 output_buf << "\nhelp: sorry, `" << *argv << "' is not documented\n"; |
|
703 } |
|
704 |
|
705 additional_help_message (output_buf); |
|
706 output_buf << ends; |
|
707 maybe_page_output (output_buf); |
|
708 } |
|
709 |
|
710 #ifdef USE_GNU_INFO |
529
|
711 DEFUN_TEXT ("help", Fhelp, Shelp, -1, 1, |
|
712 "help [-i] [topic ...]\n\ |
|
713 \n\ |
|
714 print cryptic yet witty messages") |
1140
|
715 #else |
|
716 DEFUN_TEXT ("help", Fhelp, Shelp, -1, 1, |
|
717 "help [topic ...]\n\ |
|
718 \n\ |
|
719 print cryptic yet witty messages") |
|
720 #endif |
529
|
721 { |
|
722 Octave_object retval; |
|
723 |
|
724 DEFINE_ARGV("help"); |
|
725 |
|
726 if (argc == 1) |
|
727 { |
|
728 simple_help (); |
|
729 } |
|
730 else |
|
731 { |
|
732 if (argv[1] && strcmp (argv[1], "-i") == 0) |
|
733 { |
|
734 argc--; |
|
735 argv++; |
|
736 |
1140
|
737 help_from_info (argc, argv); |
529
|
738 } |
|
739 else |
|
740 { |
1140
|
741 builtin_help (argc, argv); |
529
|
742 } |
|
743 } |
|
744 |
|
745 DELETE_ARGV; |
|
746 |
|
747 return retval; |
|
748 } |
|
749 |
581
|
750 DEFUN_TEXT ("type", Ftype, Stype, -1, 1, |
|
751 "type NAME ...]\n\ |
|
752 \n\ |
|
753 display the definition of each NAME that refers to a function") |
|
754 { |
|
755 Octave_object retval; |
|
756 |
|
757 DEFINE_ARGV("type"); |
|
758 |
|
759 if (argc > 1) |
|
760 { |
|
761 // XXX FIXME XXX -- we should really use getopt () |
|
762 int quiet = 0; |
|
763 if (argv[1] && strcmp (argv[1], "-q") == 0) |
|
764 { |
|
765 quiet = 1; |
|
766 argc--; |
|
767 argv++; |
|
768 } |
|
769 |
|
770 ostrstream output_buf; |
|
771 |
|
772 while (--argc > 0) |
|
773 { |
|
774 argv++; |
|
775 |
|
776 if (! *argv || ! **argv) |
|
777 continue; |
|
778 |
962
|
779 symbol_record *sym_rec = lookup_by_name (*argv, 0); |
581
|
780 |
|
781 if (sym_rec) |
|
782 { |
|
783 if (sym_rec->is_user_function ()) |
|
784 { |
|
785 tree_fvc *defn = sym_rec->def (); |
|
786 |
|
787 if (nargout == 0 && ! quiet) |
|
788 output_buf << *argv << " is a user-defined function\n"; |
|
789 |
|
790 defn->print_code (output_buf); |
|
791 } |
|
792 |
|
793 // XXX FIXME XXX -- this code should be shared with Fwhich |
|
794 |
|
795 else if (sym_rec->is_text_function ()) |
|
796 output_buf << *argv << " is a builtin text-function\n"; |
|
797 else if (sym_rec->is_builtin_function ()) |
|
798 output_buf << *argv << " is a builtin function\n"; |
|
799 else if (sym_rec->is_user_variable ()) |
625
|
800 { |
|
801 tree_fvc *defn = sym_rec->def (); |
|
802 |
|
803 if (nargout == 0 && ! quiet) |
|
804 output_buf << *argv << " is a user-defined variable\n"; |
|
805 |
|
806 defn->print_code (output_buf); |
|
807 |
|
808 if (nargout == 0) |
|
809 output_buf << "\n"; |
|
810 } |
581
|
811 else if (sym_rec->is_builtin_variable ()) |
625
|
812 { |
|
813 tree_fvc *defn = sym_rec->def (); |
|
814 |
|
815 if (nargout == 0 && ! quiet) |
|
816 output_buf << *argv << " is a builtin variable\n"; |
|
817 |
|
818 defn->print_code (output_buf); |
|
819 |
|
820 if (nargout == 0) |
|
821 output_buf << "\n"; |
|
822 } |
581
|
823 else |
|
824 output_buf << "type: `" << *argv << "' has unknown type!\n"; |
|
825 } |
|
826 else |
|
827 output_buf << "type: `" << *argv << "' undefined\n"; |
|
828 } |
|
829 |
|
830 output_buf << ends; |
|
831 |
|
832 if (nargout == 0) |
|
833 maybe_page_output (output_buf); |
|
834 else |
|
835 { |
|
836 char *s = output_buf.str (); |
|
837 retval = s; |
|
838 delete s; |
|
839 } |
|
840 } |
|
841 else |
|
842 print_usage ("type"); |
|
843 |
|
844 DELETE_ARGV; |
|
845 |
|
846 return retval; |
|
847 } |
|
848 |
|
849 DEFUN_TEXT ("which", Fwhich, Swhich, -1, 1, |
|
850 "which NAME ...]\n\ |
|
851 \n\ |
|
852 display the type of each NAME. If NAME is defined from an function\n\ |
|
853 file, print the full name of the file.") |
|
854 { |
|
855 Octave_object retval; |
|
856 |
|
857 DEFINE_ARGV("which"); |
|
858 |
|
859 if (argc > 1) |
|
860 { |
|
861 if (nargout > 0) |
|
862 retval.resize (argc-1, Matrix ()); |
|
863 |
|
864 ostrstream output_buf; |
|
865 |
|
866 for (int i = 0; i < argc-1; i++) |
|
867 { |
|
868 argv++; |
|
869 |
|
870 if (! *argv || ! **argv) |
|
871 continue; |
|
872 |
962
|
873 symbol_record *sym_rec = lookup_by_name (*argv, 0); |
581
|
874 |
|
875 if (sym_rec) |
|
876 { |
742
|
877 int print = (nargout == 0); |
|
878 char *tmp = print_symbol_type (output_buf, sym_rec, |
|
879 *argv, print); |
|
880 if (! print) |
|
881 retval(i) = tmp; |
581
|
882 } |
|
883 else |
|
884 { |
|
885 if (nargout == 0) |
|
886 output_buf << "which: `" << *argv << "' is undefined\n"; |
|
887 else |
|
888 retval(i) = "undefined"; |
|
889 } |
|
890 } |
|
891 output_buf << ends; |
|
892 maybe_page_output (output_buf); |
|
893 } |
|
894 else |
|
895 print_usage ("which"); |
|
896 |
|
897 DELETE_ARGV; |
|
898 |
|
899 return retval; |
|
900 } |
|
901 |
1
|
902 /* |
|
903 ;;; Local Variables: *** |
|
904 ;;; mode: C++ *** |
|
905 ;;; page-delimiter: "^/\\*" *** |
|
906 ;;; End: *** |
|
907 */ |