Mercurial > octave
comparison libinterp/octave.cc @ 15224:a44e4a08fc55
perform fewer actions before starting GUI
* octave.cc (forced_line_editing, read_history_file,
command_line_path, echo_executing_commands, doc_cache_file, exec_path,
image_path, info_file, info_program, no_window_system,
texi_macros_file): New file-scope static variables.
(octave_process_command_line): New function.
Process command line and set octave_cmdline_argc, octave_cmdline_argv,
forced_line_editing, and read_history_file here, not in
octave_initialize_interpreter.
(octave_initialize_interpreter): Perform actions for command line
options here instead of in command option processing loop in
octave_process_command_line.
(octave_main): Call octave_process_command_line.
* octave.h (octave_process_command_line): Provide decl.
* main.cc, main-cli.cc (main): Call octave_process_command_line.
* main.cc (main): If not starting GUI, call
octave_initialize_interpreter before calling
octave_execute_interpreter.
* main-cli.cc (main): Call octave_initialize_interpreter before
calling octave_execute_interpreter.
* octave-main-thread.cc (octave_main_thread::run): Likewise.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 Aug 2012 17:53:42 -0400 |
parents | 6ec6ddebb1a6 |
children | 2d337a9869e9 |
comparison
equal
deleted
inserted
replaced
15223:6ec6ddebb1a6 | 15224:a44e4a08fc55 |
---|---|
125 static bool force_gui_option = false; | 125 static bool force_gui_option = false; |
126 | 126 |
127 // If TRUE don't start the GUI. | 127 // If TRUE don't start the GUI. |
128 // (--no-gui) | 128 // (--no-gui) |
129 static bool no_gui_option = false; | 129 static bool no_gui_option = false; |
130 | |
131 // If TRUE, force readline command line editing. | |
132 // (--line-editing) | |
133 static bool forced_line_editing = false; | |
134 | |
135 // If TRUE, initialize history list from saved history file. | |
136 // (--no-history; -H) | |
137 static bool read_history_file = true; | |
138 | |
139 // The value of "path" specified on the command line. | |
140 // (--path; -p) | |
141 static std::string command_line_path; | |
142 | |
143 // Flags used to determine what commands should be echoed when they are | |
144 // parsed and executed. | |
145 // (--echo-commands; -x) | |
146 static int echo_executing_commands = 0; | |
147 | |
148 // The file used for the doc string cache. | |
149 // (--doc-cache-file) | |
150 static std::string doc_cache_file; | |
151 | |
152 // The value for "EXEC_PATH" specified on the command line. | |
153 // (--exec-path) | |
154 static std::string exec_path; | |
155 | |
156 // The value for "IMAGE_PATH" specified on the command line. | |
157 // (--image-path) | |
158 static std::string image_path; | |
159 | |
160 // The value for "info_file" specified on the command line. | |
161 // (--info-file) | |
162 static std::string info_file; | |
163 | |
164 // The value for "info_program" specified on the command line. | |
165 // (--info-program) | |
166 static std::string info_program; | |
167 | |
168 // If TRUE, ignore the window system even if it is available. | |
169 // (--no-window-system) | |
170 static bool no_window_system = false; | |
171 | |
172 // The value for "texi_macros_file" specified on the command line. | |
173 // (--texi-macros-file) | |
174 static std::string texi_macros_file; | |
130 | 175 |
131 // Usage message | 176 // Usage message |
132 static const char *usage_string = | 177 static const char *usage_string = |
133 "octave [-HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE]\n\ | 178 "octave [-HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE]\n\ |
134 [--exec-path path] [--force-gui] [--help] [--image-path path]\n\ | 179 [--exec-path path] [--force-gui] [--help] [--image-path path]\n\ |
652 // declared extern "C". | 697 // declared extern "C". |
653 | 698 |
654 int | 699 int |
655 octave_main (int argc, char **argv, int embedded) | 700 octave_main (int argc, char **argv, int embedded) |
656 { | 701 { |
702 octave_process_command_line (argc, argv); | |
703 | |
657 octave_initialize_interpreter (argc, argv, embedded); | 704 octave_initialize_interpreter (argc, argv, embedded); |
658 | 705 |
659 return octave_execute_interpreter (); | 706 return octave_execute_interpreter (); |
660 } | 707 } |
661 | 708 |
662 // EMBEDDED is declared int instead of bool because this function is | |
663 // declared extern "C". | |
664 | |
665 void | 709 void |
666 octave_initialize_interpreter (int argc, char **argv, int embedded) | 710 octave_process_command_line (int argc, char **argv) |
667 { | 711 { |
668 octave_cmdline_argc = argc; | 712 octave_cmdline_argc = argc; |
669 octave_cmdline_argv = argv; | 713 octave_cmdline_argv = argv; |
670 octave_embedded = embedded; | |
671 | |
672 octave_env::set_program_name (argv[0]); | |
673 | |
674 octave_program_invocation_name = octave_env::get_program_invocation_name (); | |
675 octave_program_name = octave_env::get_program_name (); | |
676 | |
677 octave_thread::init (); | |
678 | |
679 // The order of these calls is important. The call to | |
680 // install_defaults must come before install_builtins because | |
681 // default variable values must be available for the variables to be | |
682 // installed, and the call to install_builtins must come before the | |
683 // options are processed because some command line options override | |
684 // defaults by calling bind_internal_variable. | |
685 | |
686 init_signals (); | |
687 | |
688 sysdep_init (); | |
689 | |
690 octave_ieee_init (); | |
691 | |
692 // The idea here is to force xerbla to be referenced so that we will | |
693 // link to our own version instead of the one provided by the BLAS | |
694 // library. But octave_NaN should never be -1, so we should never | |
695 // actually call xerbla. | |
696 | |
697 if (octave_NaN == -1) | |
698 F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6)); | |
699 | |
700 initialize_error_handlers (); | |
701 | |
702 initialize_default_warning_state (); | |
703 | |
704 install_defaults (); | |
705 | |
706 initialize_pathsearch (); | |
707 | |
708 if (! embedded) | |
709 install_signal_handlers (); | |
710 else | |
711 quit_allowed = false; | |
712 | |
713 initialize_file_io (); | |
714 | |
715 install_types (); | |
716 | |
717 install_ops (); | |
718 | |
719 install_builtins (); | |
720 | |
721 bool forced_line_editing = false; | |
722 | |
723 bool read_history_file = true; | |
724 | 714 |
725 while (true) | 715 while (true) |
726 { | 716 { |
727 int long_idx; | 717 int long_idx; |
728 | 718 |
740 usage (); | 730 usage (); |
741 break; | 731 break; |
742 | 732 |
743 case 'H': | 733 case 'H': |
744 read_history_file = false; | 734 read_history_file = false; |
745 bind_internal_variable ("saving_history", false); | |
746 break; | 735 break; |
747 | 736 |
748 case 'V': | 737 case 'V': |
749 verbose_flag = true; | 738 verbose_flag = true; |
750 break; | 739 break; |
767 forced_interactive = true; | 756 forced_interactive = true; |
768 break; | 757 break; |
769 | 758 |
770 case 'p': | 759 case 'p': |
771 if (optarg) | 760 if (optarg) |
772 load_path::set_command_line_path (optarg); | 761 command_line_path = optarg; |
773 break; | 762 break; |
774 | 763 |
775 case 'q': | 764 case 'q': |
776 inhibit_startup_message = true; | 765 inhibit_startup_message = true; |
777 break; | 766 break; |
778 | 767 |
779 case 'x': | 768 case 'x': |
780 { | 769 echo_executing_commands |
781 double tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_CMD_LINE); | 770 = (ECHO_SCRIPTS | ECHO_FUNCTIONS | ECHO_CMD_LINE); |
782 bind_internal_variable ("echo_executing_commands", tmp); | |
783 } | |
784 break; | 771 break; |
785 | 772 |
786 case 'v': | 773 case 'v': |
787 print_version_and_exit (); | 774 print_version_and_exit (); |
788 break; | 775 break; |
789 | 776 |
790 case DOC_CACHE_FILE_OPTION: | 777 case DOC_CACHE_FILE_OPTION: |
791 if (optarg) | 778 if (optarg) |
792 bind_internal_variable ("doc_cache_file", optarg); | 779 doc_cache_file = optarg; |
793 break; | 780 break; |
794 | 781 |
795 case EVAL_OPTION: | 782 case EVAL_OPTION: |
796 if (optarg) | 783 if (optarg) |
797 { | 784 { |
802 } | 789 } |
803 break; | 790 break; |
804 | 791 |
805 case EXEC_PATH_OPTION: | 792 case EXEC_PATH_OPTION: |
806 if (optarg) | 793 if (optarg) |
807 set_exec_path (optarg); | 794 exec_path = optarg; |
808 break; | 795 break; |
809 | 796 |
810 case FORCE_GUI_OPTION: | 797 case FORCE_GUI_OPTION: |
811 force_gui_option = true; | 798 force_gui_option = true; |
812 break; | 799 break; |
813 | 800 |
814 case IMAGE_PATH_OPTION: | 801 case IMAGE_PATH_OPTION: |
815 if (optarg) | 802 if (optarg) |
816 set_image_path (optarg); | 803 image_path = optarg; |
817 break; | 804 break; |
818 | 805 |
819 case INFO_FILE_OPTION: | 806 case INFO_FILE_OPTION: |
820 if (optarg) | 807 if (optarg) |
821 bind_internal_variable ("info_file", optarg); | 808 info_file = optarg; |
822 break; | 809 break; |
823 | 810 |
824 case INFO_PROG_OPTION: | 811 case INFO_PROG_OPTION: |
825 if (optarg) | 812 if (optarg) |
826 bind_internal_variable ("info_program", optarg); | 813 info_program = optarg; |
827 break; | 814 break; |
828 | 815 |
829 case LINE_EDITING_OPTION: | 816 case LINE_EDITING_OPTION: |
830 forced_line_editing = true; | 817 forced_line_editing = true; |
831 break; | 818 break; |
849 case NO_SITE_FILE_OPTION: | 836 case NO_SITE_FILE_OPTION: |
850 read_site_files = 0; | 837 read_site_files = 0; |
851 break; | 838 break; |
852 | 839 |
853 case NO_WINDOW_SYSTEM_OPTION: | 840 case NO_WINDOW_SYSTEM_OPTION: |
854 display_info::no_window_system (); | 841 no_window_system = true; |
855 break; | 842 break; |
856 | 843 |
857 case PERSIST_OPTION: | 844 case PERSIST_OPTION: |
858 persist = true; | 845 persist = true; |
859 break; | 846 break; |
860 | 847 |
861 case TEXI_MACROS_FILE_OPTION: | 848 case TEXI_MACROS_FILE_OPTION: |
862 if (optarg) | 849 if (optarg) |
863 bind_internal_variable ("texi_macros_file", optarg); | 850 texi_macros_file = optarg; |
864 break; | 851 break; |
865 | 852 |
866 case TRADITIONAL_OPTION: | 853 case TRADITIONAL_OPTION: |
867 traditional = true; | 854 traditional = true; |
868 break; | 855 break; |
880 if (force_gui_option && no_gui_option) | 867 if (force_gui_option && no_gui_option) |
881 { | 868 { |
882 error ("error: only one of --force-gui and --no-gui may be used"); | 869 error ("error: only one of --force-gui and --no-gui may be used"); |
883 usage (); | 870 usage (); |
884 } | 871 } |
872 } | |
873 | |
874 // EMBEDDED is declared int instead of bool because this function is | |
875 // declared extern "C". | |
876 | |
877 void | |
878 octave_initialize_interpreter (int argc, char **argv, int embedded) | |
879 { | |
880 octave_embedded = embedded; | |
881 | |
882 octave_env::set_program_name (argv[0]); | |
883 | |
884 octave_program_invocation_name = octave_env::get_program_invocation_name (); | |
885 octave_program_name = octave_env::get_program_name (); | |
886 | |
887 octave_thread::init (); | |
888 | |
889 // The order of these calls is important. The call to | |
890 // install_defaults must come before install_builtins because | |
891 // default variable values must be available for the variables to be | |
892 // installed, and the call to install_builtins must come before the | |
893 // options are processed because some command line options override | |
894 // defaults by calling bind_internal_variable. | |
895 | |
896 init_signals (); | |
897 | |
898 sysdep_init (); | |
899 | |
900 octave_ieee_init (); | |
901 | |
902 // The idea here is to force xerbla to be referenced so that we will | |
903 // link to our own version instead of the one provided by the BLAS | |
904 // library. But octave_NaN should never be -1, so we should never | |
905 // actually call xerbla. | |
906 | |
907 if (octave_NaN == -1) | |
908 F77_FUNC (xerbla, XERBLA) ("octave", 13 F77_CHAR_ARG_LEN (6)); | |
909 | |
910 initialize_error_handlers (); | |
911 | |
912 initialize_default_warning_state (); | |
913 | |
914 install_defaults (); | |
915 | |
916 initialize_pathsearch (); | |
917 | |
918 if (! embedded) | |
919 install_signal_handlers (); | |
920 else | |
921 quit_allowed = false; | |
922 | |
923 initialize_file_io (); | |
924 | |
925 install_types (); | |
926 | |
927 install_ops (); | |
928 | |
929 install_builtins (); | |
930 | |
931 if (! read_history_file) | |
932 bind_internal_variable ("saving_history", false); | |
933 | |
934 if (! command_line_path.empty ()) | |
935 load_path::set_command_line_path (command_line_path); | |
936 | |
937 if (echo_executing_commands) | |
938 bind_internal_variable ("echo_executing_commands", | |
939 echo_executing_commands); | |
940 | |
941 if (! doc_cache_file.empty ()) | |
942 bind_internal_variable ("doc_cache_file", doc_cache_file); | |
943 | |
944 if (! exec_path.empty ()) | |
945 set_exec_path (exec_path); | |
946 | |
947 if (! image_path.empty ()) | |
948 set_exec_path (image_path); | |
949 | |
950 if (! info_file.empty ()) | |
951 bind_internal_variable ("info_file", info_file); | |
952 | |
953 if (! info_program.empty ()) | |
954 bind_internal_variable ("info_program", info_program); | |
955 | |
956 if (no_window_system) | |
957 display_info::no_window_system (); | |
958 | |
959 if (! texi_macros_file.empty ()) | |
960 bind_internal_variable ("texi_macros_file", texi_macros_file); | |
885 | 961 |
886 // Make sure we clean up when we exit. Also allow users to register | 962 // Make sure we clean up when we exit. Also allow users to register |
887 // functions. If we don't have atexit or on_exit, we're going to | 963 // functions. If we don't have atexit or on_exit, we're going to |
888 // leave some junk files around if we exit abnormally. | 964 // leave some junk files around if we exit abnormally. |
889 | 965 |
1032 return false; | 1108 return false; |
1033 | 1109 |
1034 if (persist) | 1110 if (persist) |
1035 return true; | 1111 return true; |
1036 | 1112 |
1037 if (! (interactive || forced_interactive)) | 1113 // If stdin is not a tty, then assume we are reading commands from a |
1114 // pipe or a redirected file and the GUI should not start. If this is | |
1115 // not the case (for example, starting from a desktop "launcher" with | |
1116 // no terminal) and you want to start the GUI, you may use the | |
1117 // --force-gui option to start the GUI. | |
1118 | |
1119 if (! gnulib::isatty (fileno (stdin))) | |
1038 return false; | 1120 return false; |
1039 | 1121 |
1040 // If we have code to eval or execute from a file, and we are going to | 1122 // If we have code to eval or execute from a file, and we are going to |
1041 // exit immediately after executing it, don't start the gui. | 1123 // exit immediately after executing it, don't start the gui. |
1042 | 1124 |