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