Mercurial > octave
comparison src/help.cc @ 1140:26d986865487
[project @ 1995-02-26 03:23:43 by jwe]
author | jwe |
---|---|
date | Sun, 26 Feb 1995 03:23:43 +0000 |
parents | 4d364429af83 |
children | 22741d6ed818 |
comparison
equal
deleted
inserted
replaced
1139:80973a849607 | 1140:26d986865487 |
---|---|
44 #include "error.h" | 44 #include "error.h" |
45 #include "utils.h" | 45 #include "utils.h" |
46 #include "help.h" | 46 #include "help.h" |
47 #include "defun.h" | 47 #include "defun.h" |
48 | 48 |
49 #ifdef USE_GNU_INFO | |
49 extern "C" | 50 extern "C" |
50 { | 51 { |
51 #include "info/info.h" | 52 #include "info/info.h" |
52 #include "info/dribble.h" | 53 #include "info/dribble.h" |
53 #include "info/terminal.h" | 54 #include "info/terminal.h" |
55 extern int initialize_info_session (); | 56 extern int initialize_info_session (); |
56 extern int index_entry_exists (); | 57 extern int index_entry_exists (); |
57 extern int do_info_index_search (); | 58 extern int do_info_index_search (); |
58 extern void finish_info_session (); | 59 extern void finish_info_session (); |
59 extern char *replace_in_documentation (); | 60 extern char *replace_in_documentation (); |
60 | 61 } |
62 #endif | |
63 | |
64 extern "C" | |
65 { | |
61 // XXX FIXME XXX | 66 // XXX FIXME XXX |
62 #undef __FUNCTION_DEF | 67 #undef __FUNCTION_DEF |
63 #include <readline/tilde.h> | 68 #include <readline/tilde.h> |
64 | 69 } |
70 | |
71 extern "C" | |
72 { | |
65 #define boolean kpathsea_boolean | 73 #define boolean kpathsea_boolean |
66 #define false kpathsea_false | 74 #define false kpathsea_false |
67 #define true kpathsea_true | 75 #define true kpathsea_true |
68 #include <kpathsea/pathsearch.h> | 76 #include <kpathsea/pathsearch.h> |
69 } | 77 } |
317 Use the command `help -i <topic>' to search the manual index.\n" | 325 Use the command `help -i <topic>' to search the manual index.\n" |
318 | 326 |
319 static void | 327 static void |
320 additional_help_message (ostrstream& output_buf) | 328 additional_help_message (ostrstream& output_buf) |
321 { | 329 { |
330 #ifdef USE_GNU_INFO | |
322 if (! user_pref.suppress_verbose_help_message) | 331 if (! user_pref.suppress_verbose_help_message) |
323 output_buf << VERBOSE_HELP_MESSAGE; | 332 output_buf << VERBOSE_HELP_MESSAGE; |
333 #endif | |
324 } | 334 } |
325 | 335 |
326 void | 336 void |
327 print_usage (const char *string, int just_usage) | 337 print_usage (const char *string, int just_usage) |
328 { | 338 { |
512 additional_help_message (output_buf); | 522 additional_help_message (output_buf); |
513 output_buf << ends; | 523 output_buf << ends; |
514 maybe_page_output (output_buf); | 524 maybe_page_output (output_buf); |
515 } | 525 } |
516 | 526 |
527 #ifdef USE_GNU_INFO | |
517 static int | 528 static int |
518 try_info (const char *string, int force = 0) | 529 try_info (const char *string, int force = 0) |
519 { | 530 { |
520 int status = 0; | 531 int status = 0; |
521 | 532 |
572 | 583 |
573 finish_info_session (initial_node, 0); | 584 finish_info_session (initial_node, 0); |
574 } | 585 } |
575 | 586 |
576 return status; | 587 return status; |
588 } | |
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 | |
577 } | 629 } |
578 | 630 |
579 int | 631 int |
580 help_from_list (ostrstream& output_buf, const help_list *list, | 632 help_from_list (ostrstream& output_buf, const help_list *list, |
581 const char *string, int usage) | 633 const char *string, int usage) |
599 list++; | 651 list++; |
600 } | 652 } |
601 return 0; | 653 return 0; |
602 } | 654 } |
603 | 655 |
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 | |
604 DEFUN_TEXT ("help", Fhelp, Shelp, -1, 1, | 711 DEFUN_TEXT ("help", Fhelp, Shelp, -1, 1, |
605 "help [-i] [topic ...]\n\ | 712 "help [-i] [topic ...]\n\ |
606 \n\ | 713 \n\ |
607 print cryptic yet witty messages") | 714 print cryptic yet witty messages") |
715 #else | |
716 DEFUN_TEXT ("help", Fhelp, Shelp, -1, 1, | |
717 "help [topic ...]\n\ | |
718 \n\ | |
719 print cryptic yet witty messages") | |
720 #endif | |
608 { | 721 { |
609 Octave_object retval; | 722 Octave_object retval; |
610 | 723 |
611 DEFINE_ARGV("help"); | 724 DEFINE_ARGV("help"); |
612 | 725 |
619 if (argv[1] && strcmp (argv[1], "-i") == 0) | 732 if (argv[1] && strcmp (argv[1], "-i") == 0) |
620 { | 733 { |
621 argc--; | 734 argc--; |
622 argv++; | 735 argv++; |
623 | 736 |
624 if (argc == 1) | 737 help_from_info (argc, argv); |
625 { | |
626 volatile sig_handler *old_sigint_handler; | |
627 old_sigint_handler = signal (SIGINT, SIG_IGN); | |
628 | |
629 try_info (0, 1); | |
630 | |
631 signal (SIGINT, old_sigint_handler); | |
632 } | |
633 else | |
634 { | |
635 while (--argc > 0) | |
636 { | |
637 argv++; | |
638 | |
639 if (! *argv || ! **argv) | |
640 continue; | |
641 | |
642 volatile sig_handler *old_sigint_handler; | |
643 old_sigint_handler = signal (SIGINT, SIG_IGN); | |
644 | |
645 if (! try_info (*argv)) | |
646 { | |
647 message ("help", | |
648 "sorry, `%s' is not indexed in the manual", | |
649 *argv); | |
650 sleep (2); | |
651 } | |
652 | |
653 signal (SIGINT, old_sigint_handler); | |
654 } | |
655 } | |
656 } | 738 } |
657 else | 739 else |
658 { | 740 { |
659 ostrstream output_buf; | 741 builtin_help (argc, argv); |
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 | |
703 << "' is not documented\n"; | |
704 } | |
705 | |
706 additional_help_message (output_buf); | |
707 output_buf << ends; | |
708 maybe_page_output (output_buf); | |
709 } | 742 } |
710 } | 743 } |
711 | 744 |
712 DELETE_ARGV; | 745 DELETE_ARGV; |
713 | 746 |