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 |
|
345 static void |
542
|
346 display_symtab_names (ostrstream& output_buf, char **names, |
|
347 int count, const char *desc) |
|
348 { |
|
349 output_buf << "\n*** " << desc << ":\n\n"; |
|
350 if (names && count > 0) |
|
351 list_in_columns (output_buf, names); |
|
352 } |
|
353 |
|
354 static void |
529
|
355 simple_help (void) |
|
356 { |
|
357 ostrstream output_buf; |
|
358 |
542
|
359 display_names_from_help_list (output_buf, operator_help (), |
|
360 "operators"); |
529
|
361 |
542
|
362 display_names_from_help_list (output_buf, keyword_help (), |
|
363 "reserved words"); |
529
|
364 |
542
|
365 #ifdef LIST_SYMBOLS |
|
366 #undef LIST_SYMBOLS |
|
367 #endif |
|
368 #define LIST_SYMBOLS(type, msg) \ |
|
369 do \ |
|
370 { \ |
|
371 int count; \ |
|
372 char **names = global_sym_tab->list (count, 1, type); \ |
|
373 display_symtab_names (output_buf, names, count, msg); \ |
|
374 char **ptr = names; \ |
|
375 while (*ptr) \ |
|
376 delete [] *ptr++; \ |
|
377 delete [] names; \ |
|
378 } \ |
|
379 while (0) |
529
|
380 |
542
|
381 // XXX FIXME XXX -- is this distinction needed? |
|
382 LIST_SYMBOLS (symbol_def::TEXT_FUNCTION, |
|
383 "text functions (these names are also reserved)"); |
529
|
384 |
542
|
385 LIST_SYMBOLS (symbol_def::MAPPER_FUNCTION, "mapper functions"); |
|
386 |
|
387 LIST_SYMBOLS (symbol_def::BUILTIN_FUNCTION, "general functions"); |
|
388 |
|
389 LIST_SYMBOLS (symbol_def::BUILTIN_VARIABLE, "builtin variables"); |
|
390 |
529
|
391 // Also need to list variables and currently compiled functions from |
|
392 // the symbol table, if there are any. |
|
393 |
|
394 // Also need to search octave_path for script files. |
|
395 |
679
|
396 char *path_elt = kpse_path_element (user_pref.loadpath); |
529
|
397 |
679
|
398 while (path_elt) |
529
|
399 { |
679
|
400 str_llist_type *elt_dirs = kpse_element_dirs (path_elt); |
|
401 |
|
402 str_llist_elt_type *dir; |
|
403 for (dir = *elt_dirs; dir; dir = STR_LLIST_NEXT (*dir)) |
529
|
404 { |
679
|
405 char *elt_dir = STR_LLIST (*dir); |
|
406 |
|
407 if (elt_dir) |
|
408 { |
|
409 int count; |
|
410 char **names = get_fcn_file_names (count, elt_dir, 0); |
|
411 |
|
412 output_buf << "\n*** function files in " |
|
413 << make_absolute (elt_dir, the_current_working_directory) |
|
414 << ":\n\n"; |
|
415 |
|
416 if (names && count > 0) |
|
417 list_in_columns (output_buf, names); |
|
418 |
|
419 delete [] names; |
|
420 } |
529
|
421 } |
679
|
422 path_elt = kpse_path_element (0); |
529
|
423 } |
|
424 |
|
425 additional_help_message (output_buf); |
|
426 output_buf << ends; |
|
427 maybe_page_output (output_buf); |
|
428 } |
|
429 |
|
430 static int |
|
431 try_info (const char *string, int force = 0) |
|
432 { |
|
433 int status = 0; |
|
434 |
|
435 char *directory_name = strsave (user_pref.info_file); |
|
436 char *temp = filename_non_directory (directory_name); |
|
437 |
|
438 if (temp != directory_name) |
|
439 { |
|
440 *temp = 0; |
|
441 info_add_path (directory_name, INFOPATH_PREPEND); |
|
442 } |
|
443 |
|
444 delete [] directory_name; |
|
445 |
|
446 NODE *initial_node = info_get_node (user_pref.info_file, 0); |
|
447 |
|
448 if (! initial_node) |
|
449 { |
|
450 warning ("can't find info file!\n"); |
|
451 status = -1; |
|
452 } |
|
453 else |
|
454 { |
|
455 status = initialize_info_session (initial_node, 0); |
|
456 |
|
457 if (status == 0 && (force || index_entry_exists (windows, string))) |
|
458 { |
|
459 terminal_clear_screen (); |
|
460 |
|
461 terminal_prep_terminal (); |
|
462 |
|
463 display_update_display (windows); |
|
464 |
|
465 info_last_executed_command = 0; |
|
466 |
|
467 if (! force) |
|
468 do_info_index_search (windows, 0, string); |
|
469 |
|
470 char *format = replace_in_documentation |
|
471 ("Type \"\\[quit]\" to quit, \"\\[get-help-window]\" for help."); |
|
472 |
|
473 window_message_in_echo_area (format); |
|
474 |
|
475 info_read_and_dispatch (); |
|
476 |
|
477 terminal_goto_xy (0, screenheight - 1); |
|
478 |
|
479 terminal_clear_to_eol (); |
|
480 |
|
481 terminal_unprep_terminal (); |
|
482 |
|
483 status = 1; |
|
484 } |
|
485 |
|
486 finish_info_session (initial_node, 0); |
|
487 } |
|
488 |
|
489 return status; |
|
490 } |
|
491 |
542
|
492 int |
|
493 help_from_list (ostrstream& output_buf, const help_list *list, |
|
494 const char *string, int usage) |
|
495 { |
|
496 char *name; |
|
497 while ((name = list->name) != 0) |
|
498 { |
|
499 if (strcmp (name, string) == 0) |
|
500 { |
|
501 if (usage) |
|
502 output_buf << "\nusage: "; |
|
503 else |
|
504 { |
|
505 output_buf << "\n*** " << string << ":\n\n"; |
|
506 } |
|
507 |
|
508 output_buf << list->help << "\n"; |
|
509 |
|
510 return 1; |
|
511 } |
|
512 list++; |
|
513 } |
|
514 return 0; |
|
515 } |
|
516 |
529
|
517 DEFUN_TEXT ("help", Fhelp, Shelp, -1, 1, |
|
518 "help [-i] [topic ...]\n\ |
|
519 \n\ |
|
520 print cryptic yet witty messages") |
|
521 { |
|
522 Octave_object retval; |
|
523 |
|
524 DEFINE_ARGV("help"); |
|
525 |
|
526 if (argc == 1) |
|
527 { |
|
528 simple_help (); |
|
529 } |
|
530 else |
|
531 { |
|
532 if (argv[1] && strcmp (argv[1], "-i") == 0) |
|
533 { |
|
534 argc--; |
|
535 argv++; |
|
536 |
|
537 if (argc == 1) |
|
538 { |
|
539 volatile sig_handler *old_sigint_handler; |
654
|
540 old_sigint_handler = signal (SIGINT, SIG_IGN); |
529
|
541 |
|
542 try_info (0, 1); |
|
543 |
|
544 signal (SIGINT, old_sigint_handler); |
|
545 } |
|
546 else |
|
547 { |
|
548 while (--argc > 0) |
|
549 { |
|
550 argv++; |
|
551 |
|
552 if (! *argv || ! **argv) |
|
553 continue; |
|
554 |
|
555 volatile sig_handler *old_sigint_handler; |
|
556 old_sigint_handler = signal (SIGINT, SIG_IGN); |
|
557 |
|
558 if (! try_info (*argv)) |
|
559 { |
|
560 message ("help", |
|
561 "sorry, `%s' is not indexed in the manual", |
|
562 *argv); |
|
563 sleep (2); |
|
564 } |
|
565 |
|
566 signal (SIGINT, old_sigint_handler); |
|
567 } |
|
568 } |
|
569 } |
|
570 else |
|
571 { |
|
572 ostrstream output_buf; |
|
573 |
|
574 help_list *op_help_list = operator_help (); |
|
575 help_list *kw_help_list = keyword_help (); |
|
576 |
|
577 while (--argc > 0) |
|
578 { |
|
579 argv++; |
|
580 |
|
581 if (! *argv || ! **argv) |
|
582 continue; |
|
583 |
|
584 if (help_from_list (output_buf, op_help_list, *argv, 0)) |
|
585 continue; |
|
586 |
|
587 if (help_from_list (output_buf, kw_help_list, *argv, 0)) |
|
588 continue; |
|
589 |
581
|
590 symbol_record *sym_rec = lookup_by_name (*argv); |
|
591 |
529
|
592 if (sym_rec) |
|
593 { |
|
594 char *h = sym_rec->help (); |
|
595 if (h && *h) |
|
596 { |
|
597 output_buf << "\n*** " << *argv << ":\n\n" |
|
598 << h << "\n"; |
|
599 continue; |
|
600 } |
|
601 } |
|
602 |
|
603 output_buf << "\nhelp: sorry, `" << *argv |
581
|
604 << "' is not documented\n"; |
529
|
605 } |
|
606 |
|
607 additional_help_message (output_buf); |
|
608 output_buf << ends; |
|
609 maybe_page_output (output_buf); |
|
610 } |
|
611 } |
|
612 |
|
613 DELETE_ARGV; |
|
614 |
|
615 return retval; |
|
616 } |
|
617 |
581
|
618 DEFUN_TEXT ("type", Ftype, Stype, -1, 1, |
|
619 "type NAME ...]\n\ |
|
620 \n\ |
|
621 display the definition of each NAME that refers to a function") |
|
622 { |
|
623 Octave_object retval; |
|
624 |
|
625 DEFINE_ARGV("type"); |
|
626 |
|
627 if (argc > 1) |
|
628 { |
|
629 // XXX FIXME XXX -- we should really use getopt () |
|
630 int quiet = 0; |
|
631 if (argv[1] && strcmp (argv[1], "-q") == 0) |
|
632 { |
|
633 quiet = 1; |
|
634 argc--; |
|
635 argv++; |
|
636 } |
|
637 |
|
638 ostrstream output_buf; |
|
639 |
|
640 while (--argc > 0) |
|
641 { |
|
642 argv++; |
|
643 |
|
644 if (! *argv || ! **argv) |
|
645 continue; |
|
646 |
|
647 symbol_record *sym_rec = lookup_by_name (*argv); |
|
648 |
|
649 if (sym_rec) |
|
650 { |
|
651 if (sym_rec->is_user_function ()) |
|
652 { |
|
653 tree_fvc *defn = sym_rec->def (); |
|
654 |
|
655 if (nargout == 0 && ! quiet) |
|
656 output_buf << *argv << " is a user-defined function\n"; |
|
657 |
|
658 defn->print_code (output_buf); |
|
659 } |
|
660 |
|
661 // XXX FIXME XXX -- this code should be shared with Fwhich |
|
662 |
|
663 else if (sym_rec->is_text_function ()) |
|
664 output_buf << *argv << " is a builtin text-function\n"; |
|
665 else if (sym_rec->is_builtin_function ()) |
|
666 output_buf << *argv << " is a builtin function\n"; |
|
667 else if (sym_rec->is_user_variable ()) |
625
|
668 { |
|
669 tree_fvc *defn = sym_rec->def (); |
|
670 |
|
671 if (nargout == 0 && ! quiet) |
|
672 output_buf << *argv << " is a user-defined variable\n"; |
|
673 |
|
674 defn->print_code (output_buf); |
|
675 |
|
676 if (nargout == 0) |
|
677 output_buf << "\n"; |
|
678 } |
581
|
679 else if (sym_rec->is_builtin_variable ()) |
625
|
680 { |
|
681 tree_fvc *defn = sym_rec->def (); |
|
682 |
|
683 if (nargout == 0 && ! quiet) |
|
684 output_buf << *argv << " is a builtin variable\n"; |
|
685 |
|
686 defn->print_code (output_buf); |
|
687 |
|
688 if (nargout == 0) |
|
689 output_buf << "\n"; |
|
690 } |
581
|
691 else |
|
692 output_buf << "type: `" << *argv << "' has unknown type!\n"; |
|
693 } |
|
694 else |
|
695 output_buf << "type: `" << *argv << "' undefined\n"; |
|
696 } |
|
697 |
|
698 output_buf << ends; |
|
699 |
|
700 if (nargout == 0) |
|
701 maybe_page_output (output_buf); |
|
702 else |
|
703 { |
|
704 char *s = output_buf.str (); |
|
705 retval = s; |
|
706 delete s; |
|
707 } |
|
708 } |
|
709 else |
|
710 print_usage ("type"); |
|
711 |
|
712 DELETE_ARGV; |
|
713 |
|
714 return retval; |
|
715 } |
|
716 |
|
717 DEFUN_TEXT ("which", Fwhich, Swhich, -1, 1, |
|
718 "which NAME ...]\n\ |
|
719 \n\ |
|
720 display the type of each NAME. If NAME is defined from an function\n\ |
|
721 file, print the full name of the file.") |
|
722 { |
|
723 Octave_object retval; |
|
724 |
|
725 DEFINE_ARGV("which"); |
|
726 |
|
727 if (argc > 1) |
|
728 { |
|
729 if (nargout > 0) |
|
730 retval.resize (argc-1, Matrix ()); |
|
731 |
|
732 ostrstream output_buf; |
|
733 |
|
734 for (int i = 0; i < argc-1; i++) |
|
735 { |
|
736 argv++; |
|
737 |
|
738 if (! *argv || ! **argv) |
|
739 continue; |
|
740 |
|
741 symbol_record *sym_rec = lookup_by_name (*argv); |
|
742 |
|
743 if (sym_rec) |
|
744 { |
|
745 if (sym_rec->is_user_function ()) |
|
746 { |
|
747 tree_fvc *defn = sym_rec->def (); |
|
748 char *fn = defn->fcn_file_name (); |
|
749 if (fn) |
|
750 { |
|
751 char *ff = fcn_file_in_path (fn); |
|
752 ff = ff ? ff : fn; |
|
753 |
|
754 if (nargout == 0) |
|
755 output_buf << *argv |
|
756 << " is the function defined from:\n" |
|
757 << ff << "\n"; |
|
758 else |
|
759 retval(i) = ff; |
|
760 } |
|
761 else |
|
762 { |
|
763 if (nargout == 0) |
|
764 output_buf << *argv << " is a user-defined function\n"; |
|
765 else |
|
766 retval(i) = "user-defined function"; |
|
767 } |
|
768 } |
|
769 else if (sym_rec->is_text_function ()) |
|
770 { |
|
771 if (nargout == 0) |
|
772 output_buf << *argv << " is a builtin text-function\n"; |
|
773 else |
|
774 retval(i) = "builtin text-function"; |
|
775 } |
|
776 else if (sym_rec->is_builtin_function ()) |
|
777 { |
|
778 if (nargout == 0) |
|
779 output_buf << *argv << " is a builtin function\n"; |
|
780 else |
|
781 retval(i) = "builtin function"; |
|
782 } |
|
783 else if (sym_rec->is_user_variable ()) |
|
784 { |
|
785 if (nargout == 0) |
|
786 output_buf << *argv << " is a user-defined variable\n"; |
|
787 else |
|
788 retval(i) = "user-defined variable"; |
|
789 } |
|
790 else if (sym_rec->is_builtin_variable ()) |
|
791 { |
|
792 if (nargout == 0) |
|
793 output_buf << *argv << " is a builtin variable\n"; |
|
794 else |
|
795 retval(i) = "builtin variable"; |
|
796 } |
|
797 else |
|
798 { |
|
799 if (nargout == 0) |
|
800 output_buf << "which: `" << *argv |
|
801 << "' has unknown type\n"; |
|
802 else |
|
803 retval(i) = "unknown type"; |
|
804 } |
|
805 } |
|
806 else |
|
807 { |
|
808 if (nargout == 0) |
|
809 output_buf << "which: `" << *argv << "' is undefined\n"; |
|
810 else |
|
811 retval(i) = "undefined"; |
|
812 } |
|
813 } |
|
814 output_buf << ends; |
|
815 maybe_page_output (output_buf); |
|
816 } |
|
817 else |
|
818 print_usage ("which"); |
|
819 |
|
820 DELETE_ARGV; |
|
821 |
|
822 return retval; |
|
823 } |
|
824 |
1
|
825 /* |
|
826 ;;; Local Variables: *** |
|
827 ;;; mode: C++ *** |
|
828 ;;; page-delimiter: "^/\\*" *** |
|
829 ;;; End: *** |
|
830 */ |