Mercurial > octave
comparison src/help.cc @ 1295:34295bf6aac6
[project @ 1995-05-01 18:24:48 by jwe]
author | jwe |
---|---|
date | Mon, 01 May 1995 18:24:48 +0000 |
parents | 4acabfbdd381 |
children | 611d403c7f3d |
comparison
equal
deleted
inserted
replaced
1294:549b0a461fd8 | 1295:34295bf6aac6 |
---|---|
23 | 23 |
24 #ifdef HAVE_CONFIG_H | 24 #ifdef HAVE_CONFIG_H |
25 #include <config.h> | 25 #include <config.h> |
26 #endif | 26 #endif |
27 | 27 |
28 #include <sys/types.h> | |
29 #ifdef HAVE_UNISTD_H | |
30 #include <unistd.h> | |
31 #endif | |
28 #include <signal.h> | 32 #include <signal.h> |
29 #include <stdlib.h> | 33 #include <stdlib.h> |
34 #include <string.h> | |
30 #include <iostream.h> | 35 #include <iostream.h> |
31 #include <strstream.h> | 36 #include <strstream.h> |
32 | 37 |
33 #include "tree-expr.h" | 38 #include "tree-expr.h" |
34 #include "tree-const.h" | 39 #include "tree-const.h" |
44 #include "error.h" | 49 #include "error.h" |
45 #include "utils.h" | 50 #include "utils.h" |
46 #include "help.h" | 51 #include "help.h" |
47 #include "defun.h" | 52 #include "defun.h" |
48 | 53 |
49 #ifdef USE_GNU_INFO | |
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 (); | |
61 } | |
62 #endif | |
63 | |
64 extern "C" | 54 extern "C" |
65 { | 55 { |
66 // XXX FIXME XXX | 56 // XXX FIXME XXX |
67 #undef __FUNCTION_DEF | 57 #undef __FUNCTION_DEF |
68 #include <readline/tilde.h> | 58 #include <readline/tilde.h> |
519 maybe_page_output (output_buf); | 509 maybe_page_output (output_buf); |
520 } | 510 } |
521 | 511 |
522 #ifdef USE_GNU_INFO | 512 #ifdef USE_GNU_INFO |
523 static int | 513 static int |
524 try_info (const char *string, int force = 0) | 514 try_info (const char *string) |
525 { | 515 { |
526 int status = 0; | 516 int status = 0; |
527 | 517 |
518 static char *cmd_str = 0; | |
519 | |
520 delete [] cmd_str; | |
521 cmd_str = 0; | |
522 | |
523 ostrstream cmd_buf; | |
524 | |
525 cmd_buf << "info --file " << user_pref.info_file; | |
526 | |
528 char *directory_name = strsave (user_pref.info_file); | 527 char *directory_name = strsave (user_pref.info_file); |
529 char *temp = filename_non_directory (directory_name); | 528 char *file = strrchr (directory_name, '/'); |
530 | 529 if (file) |
531 if (temp != directory_name) | 530 { |
532 { | 531 file++; |
533 *temp = 0; | 532 *file = 0; |
534 info_add_path (directory_name, INFOPATH_PREPEND); | 533 cmd_buf << " --directory " << directory_name; |
535 } | 534 } |
536 | |
537 delete [] directory_name; | 535 delete [] directory_name; |
538 | 536 |
539 NODE *initial_node = info_get_node (user_pref.info_file, 0); | 537 if (string) |
540 | 538 cmd_buf << " --index-search " << string; |
541 if (! initial_node) | 539 |
542 { | 540 cmd_buf << ends; |
543 warning ("can't find info file!\n"); | 541 |
544 status = -1; | 542 cmd_str = cmd_buf.str (); |
545 } | 543 |
544 volatile sig_handler *old_sigint_handler; | |
545 old_sigint_handler = signal (SIGINT, SIG_IGN); | |
546 | |
547 status = system (cmd_str); | |
548 | |
549 signal (SIGINT, old_sigint_handler); | |
550 | |
551 if ((status & 0xff) == 0) | |
552 status = (signed char) ((status & 0xff00) >> 8); | |
546 else | 553 else |
547 { | 554 status = 127; |
548 status = initialize_info_session (initial_node, 0); | |
549 | |
550 if (status == 0 && (force || index_entry_exists (windows, string))) | |
551 { | |
552 terminal_clear_screen (); | |
553 | |
554 terminal_prep_terminal (); | |
555 | |
556 display_update_display (windows); | |
557 | |
558 info_last_executed_command = 0; | |
559 | |
560 if (! force) | |
561 do_info_index_search (windows, 0, string); | |
562 | |
563 char *format = replace_in_documentation | |
564 ("Type \"\\[quit]\" to quit, \"\\[get-help-window]\" for help."); | |
565 | |
566 window_message_in_echo_area (format); | |
567 | |
568 info_read_and_dispatch (); | |
569 | |
570 terminal_goto_xy (0, screenheight - 1); | |
571 | |
572 terminal_clear_to_eol (); | |
573 | |
574 terminal_unprep_terminal (); | |
575 | |
576 status = 1; | |
577 } | |
578 | |
579 finish_info_session (initial_node, 0); | |
580 } | |
581 | 555 |
582 return status; | 556 return status; |
583 } | 557 } |
584 #endif | 558 #endif |
585 | 559 |
586 static void | 560 static void |
587 help_from_info (int argc, char **argv) | 561 help_from_info (int argc, char **argv) |
588 { | 562 { |
589 #ifdef USE_GNU_INFO | 563 #ifdef USE_GNU_INFO |
590 if (argc == 1) | 564 if (argc == 1) |
591 { | 565 try_info (0); |
592 volatile sig_handler *old_sigint_handler; | |
593 old_sigint_handler = signal (SIGINT, SIG_IGN); | |
594 | |
595 try_info (0, 1); | |
596 | |
597 signal (SIGINT, old_sigint_handler); | |
598 } | |
599 else | 566 else |
600 { | 567 { |
601 while (--argc > 0) | 568 while (--argc > 0) |
602 { | 569 { |
603 argv++; | 570 argv++; |
604 | 571 |
605 if (! *argv || ! **argv) | 572 if (! *argv || ! **argv) |
606 continue; | 573 continue; |
607 | 574 |
608 volatile sig_handler *old_sigint_handler; | 575 int status = try_info (*argv); |
609 old_sigint_handler = signal (SIGINT, SIG_IGN); | 576 |
610 | 577 if (status) |
611 if (! try_info (*argv)) | |
612 { | 578 { |
613 message ("help", "sorry, `%s' is not indexed in the manual", | 579 if (status < 0) |
614 *argv); | 580 { |
615 sleep (2); | 581 message ("help", |
582 "sorry, `%s' is not indexed in the manual", | |
583 *argv); | |
584 sleep (2); | |
585 } | |
586 else | |
587 { | |
588 error ("help: unable to find info!"); | |
589 break; | |
590 } | |
616 } | 591 } |
617 | |
618 signal (SIGINT, old_sigint_handler); | |
619 } | 592 } |
620 } | 593 } |
621 #else | 594 #else |
622 message (0, "sorry, help -i is not available in this version of Octave"); | 595 message (0, "sorry, help -i is not available in this version of Octave"); |
623 #endif | 596 #endif |