comparison src/octave.cc @ 15139:bfc220d1de67 gui

include gui in default Octave binary * Makefile.am (GUIDIR): New variable. (SUBDIRS): Use it in the list instead of @GUIDIR@. List $(GUIDIR) before src. * gui/src/Makefile.am (bin_PROGRAMS): Delete. (octlib_LTLIBRARIES): New variable. (liboctgui_la_SOURCES): Rename from octave_gui_SOURCES. (liboctgui_la_CPPFLAGS): Rename from octave_gui_CPPFLAGS. (liboctgui_la_LIBADD): Rename from octave_gui_LDADD. Don't include Octave libraries in the list. Do include Qt libraries in the list. (liboctgui_la_LDFLAGS): Rename from octave_gui_LDFLAGS. Only include -L@QT_LIBDIR@ option in the list. (moc_%.cpp): Use $(liboctgui_la_CPPFLAGS) in rules, not $(octave_gui_CPPFLAGS). * octave-gui.h: New file. * octave-gui.cc: Include it. (dissociate_terminal): In parent, wait for child process and exit with exit status of child. (octave_start_gui): Rename from main. * run-octave.in: Start with GUI by default. Rename -gui option -cli to allow running octave-cli binary. * main.cc, main-cli.cc: New files. * main.c: Delete. * src/Makefile (bin_PROGRAMS): Include octave-cli in the list. (OCTAVE_CORE_LIBS): New variable. (octave_cli_SOURCES, octave_cli_LDADD, octave_cli_LDFLAGS): New variables. (octave_SOURCES): Define to main.cc, not main.c. (octave_CPPFLAGS): New variable. (octave_LDFLAGS): Include -DENABLE_GUI=1 in the list. (octave_LDADD): Use $(OCTAVE_CORE_LIBS) and link with GUI lib. * octave.cc (force_gui_option, no_gui_option): New static variables. (octave_starting_gui): New function. (usage_string): Update for new options. (FORCE_GUI_OPTION, NO_GUI_OPTION): New macros. (long_opts): Include "force-gui" and "no-gui" options in the list. (octave_main): Handle FORCE_GUI_OPTION and NO_GUI_OPTION cases. Error if both --force-gui and --no-gui are used. * octave.h (octave_starting_gui): Provide decl.
author John W. Eaton <jwe@octave.org>
date Fri, 10 Aug 2012 10:27:32 -0400
parents 16a6b0a6855d
children 973296940c89
comparison
equal deleted inserted replaced
15138:089b98bdaebf 15139:bfc220d1de67
54 #include "file-io.h" 54 #include "file-io.h"
55 #include "input.h" 55 #include "input.h"
56 #include "lex.h" 56 #include "lex.h"
57 #include "load-path.h" 57 #include "load-path.h"
58 #include "octave.h" 58 #include "octave.h"
59 #include "oct-conf.h"
59 #include "oct-hist.h" 60 #include "oct-hist.h"
60 #include "oct-map.h" 61 #include "oct-map.h"
61 #include "oct-mutex.h" 62 #include "oct-mutex.h"
62 #include "oct-obj.h" 63 #include "oct-obj.h"
63 #include "ops.h" 64 #include "ops.h"
117 118
118 // If TRUE, print verbose info in some cases. 119 // If TRUE, print verbose info in some cases.
119 // (--verbose; -V) 120 // (--verbose; -V)
120 static bool verbose_flag = false; 121 static bool verbose_flag = false;
121 122
123 // If TRUE, force the GUI to start.
124 // (--force-gui)
125 static bool force_gui_option = false;
126
127 // If TRUE don't start the GUI.
128 // (--no-gui)
129 static bool no_gui_option = false;
130
122 // Usage message 131 // Usage message
123 static const char *usage_string = 132 static const char *usage_string =
124 "octave [-HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE]\n\ 133 "octave [-HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE]\n\
125 [--exec-path path] [--help] [--image-path path] [--info-file file]\n\ 134 [--exec-path path] [--force-gui] [--help] [--image-path path]\n\
126 [--info-program prog] [--interactive] [--line-editing]\n\ 135 [--info-file file] [--info-program prog] [--interactive]\n\
127 [--no-history] [--no-init-file] [--no-init-path] [--no-line-editing]\n\ 136 [--line-editing] [--no-gui] [--no-history] [--no-init-file]\n\
128 [--no-site-file] [--no-window-system] [-p path] [--path path]\n\ 137 [--no-init-path] [--no-line-editing] [--no-site-file]\n\
129 [--silent] [--traditional] [--verbose] [--version] [file]"; 138 [--no-window-system] [-p path] [--path path] [--silent]\n\
139 [--traditional] [--verbose] [--version] [file]";
130 140
131 // This is here so that it's more likely that the usage message and 141 // This is here so that it's more likely that the usage message and
132 // the real set of options will agree. Note: the `+' must come first 142 // the real set of options will agree. Note: the `+' must come first
133 // to prevent getopt from permuting arguments! 143 // to prevent getopt from permuting arguments!
134 static const char *short_opts = "+HVdfhip:qvx"; 144 static const char *short_opts = "+HVdfhip:qvx";
142 // Long options. See the comments in getopt.h for the meanings of the 152 // Long options. See the comments in getopt.h for the meanings of the
143 // fields in this structure. 153 // fields in this structure.
144 #define DOC_CACHE_FILE_OPTION 1 154 #define DOC_CACHE_FILE_OPTION 1
145 #define EVAL_OPTION 2 155 #define EVAL_OPTION 2
146 #define EXEC_PATH_OPTION 3 156 #define EXEC_PATH_OPTION 3
147 #define IMAGE_PATH_OPTION 4 157 #define FORCE_GUI_OPTION 4
148 #define INFO_FILE_OPTION 5 158 #define IMAGE_PATH_OPTION 5
149 #define INFO_PROG_OPTION 6 159 #define INFO_FILE_OPTION 6
150 #define LINE_EDITING_OPTION 7 160 #define INFO_PROG_OPTION 7
151 #define NO_INIT_FILE_OPTION 8 161 #define LINE_EDITING_OPTION 8
152 #define NO_INIT_PATH_OPTION 9 162 #define NO_GUI_OPTION 9
153 #define NO_LINE_EDITING_OPTION 10 163 #define NO_INIT_FILE_OPTION 10
154 #define NO_SITE_FILE_OPTION 11 164 #define NO_INIT_PATH_OPTION 11
155 #define NO_WINDOW_SYSTEM_OPTION 12 165 #define NO_LINE_EDITING_OPTION 12
156 #define PERSIST_OPTION 13 166 #define NO_SITE_FILE_OPTION 13
157 #define TEXI_MACROS_FILE_OPTION 14 167 #define NO_WINDOW_SYSTEM_OPTION 14
158 #define TRADITIONAL_OPTION 15 168 #define PERSIST_OPTION 15
169 #define TEXI_MACROS_FILE_OPTION 16
170 #define TRADITIONAL_OPTION 17
159 struct option long_opts[] = 171 struct option long_opts[] =
160 { 172 {
161 { "braindead", no_argument, 0, TRADITIONAL_OPTION }, 173 { "braindead", no_argument, 0, TRADITIONAL_OPTION },
162 { "debug", no_argument, 0, 'd' }, 174 { "debug", no_argument, 0, 'd' },
163 { "doc-cache-file", required_argument, 0, DOC_CACHE_FILE_OPTION }, 175 { "doc-cache-file", required_argument, 0, DOC_CACHE_FILE_OPTION },
164 { "echo-commands", no_argument, 0, 'x' }, 176 { "echo-commands", no_argument, 0, 'x' },
165 { "eval", required_argument, 0, EVAL_OPTION }, 177 { "eval", required_argument, 0, EVAL_OPTION },
166 { "exec-path", required_argument, 0, EXEC_PATH_OPTION }, 178 { "exec-path", required_argument, 0, EXEC_PATH_OPTION },
179 { "force-gui", no_argument, 0, FORCE_GUI_OPTION },
167 { "help", no_argument, 0, 'h' }, 180 { "help", no_argument, 0, 'h' },
168 { "image-path", required_argument, 0, IMAGE_PATH_OPTION }, 181 { "image-path", required_argument, 0, IMAGE_PATH_OPTION },
169 { "info-file", required_argument, 0, INFO_FILE_OPTION }, 182 { "info-file", required_argument, 0, INFO_FILE_OPTION },
170 { "info-program", required_argument, 0, INFO_PROG_OPTION }, 183 { "info-program", required_argument, 0, INFO_PROG_OPTION },
171 { "interactive", no_argument, 0, 'i' }, 184 { "interactive", no_argument, 0, 'i' },
172 { "line-editing", no_argument, 0, LINE_EDITING_OPTION }, 185 { "line-editing", no_argument, 0, LINE_EDITING_OPTION },
186 { "no-gui", no_argument, 0, NO_GUI_OPTION },
173 { "no-history", no_argument, 0, 'H' }, 187 { "no-history", no_argument, 0, 'H' },
174 { "no-init-file", no_argument, 0, NO_INIT_FILE_OPTION }, 188 { "no-init-file", no_argument, 0, NO_INIT_FILE_OPTION },
175 { "no-init-path", no_argument, 0, NO_INIT_PATH_OPTION }, 189 { "no-init-path", no_argument, 0, NO_INIT_PATH_OPTION },
176 { "no-line-editing", no_argument, 0, NO_LINE_EDITING_OPTION }, 190 { "no-line-editing", no_argument, 0, NO_LINE_EDITING_OPTION },
177 { "no-site-file", no_argument, 0, NO_SITE_FILE_OPTION }, 191 { "no-site-file", no_argument, 0, NO_SITE_FILE_OPTION },
630 disable_warning ("Octave:function-name-clash"); 644 disable_warning ("Octave:function-name-clash");
631 disable_warning ("Octave:load-file-in-path"); 645 disable_warning ("Octave:load-file-in-path");
632 disable_warning ("Octave:possible-matlab-short-circuit-operator"); 646 disable_warning ("Octave:possible-matlab-short-circuit-operator");
633 } 647 }
634 648
635 // You guessed it. 649 // EMBEDDED is declared int instead of bool because this function is
650 // declared extern "C".
636 651
637 int 652 int
638 octave_main (int argc, char **argv, int embedded) 653 octave_main (int argc, char **argv, int embedded)
639 { 654 {
640 octave_initialize_interpreter (argc, argv, embedded); 655 octave_initialize_interpreter (argc, argv, embedded);
641 656
642 return octave_execute_interpreter (); 657 return octave_execute_interpreter ();
643 } 658 }
659
660 // EMBEDDED is declared int instead of bool because this function is
661 // declared extern "C".
644 662
645 void 663 void
646 octave_initialize_interpreter (int argc, char **argv, int embedded) 664 octave_initialize_interpreter (int argc, char **argv, int embedded)
647 { 665 {
648 octave_cmdline_argc = argc; 666 octave_cmdline_argc = argc;
785 case EXEC_PATH_OPTION: 803 case EXEC_PATH_OPTION:
786 if (optarg) 804 if (optarg)
787 set_exec_path (optarg); 805 set_exec_path (optarg);
788 break; 806 break;
789 807
808 case FORCE_GUI_OPTION:
809 force_gui_option = true;
810 break;
811
790 case IMAGE_PATH_OPTION: 812 case IMAGE_PATH_OPTION:
791 if (optarg) 813 if (optarg)
792 set_image_path (optarg); 814 set_image_path (optarg);
793 break; 815 break;
794 816
806 forced_line_editing = true; 828 forced_line_editing = true;
807 break; 829 break;
808 830
809 case NO_INIT_FILE_OPTION: 831 case NO_INIT_FILE_OPTION:
810 read_init_files = false; 832 read_init_files = false;
833 break;
834
835 case NO_GUI_OPTION:
836 no_gui_option = true;
811 break; 837 break;
812 838
813 case NO_INIT_PATH_OPTION: 839 case NO_INIT_PATH_OPTION:
814 set_initial_path = false; 840 set_initial_path = false;
815 break; 841 break;
847 panic_impossible (); 873 panic_impossible ();
848 break; 874 break;
849 } 875 }
850 } 876 }
851 877
878 if (force_gui_option && no_gui_option)
879 {
880 error ("error: only one of --force-gui and --no-gui may be used");
881 usage ();
882 }
883
852 // Make sure we clean up when we exit. Also allow users to register 884 // Make sure we clean up when we exit. Also allow users to register
853 // functions. If we don't have atexit or on_exit, we're going to 885 // functions. If we don't have atexit or on_exit, we're going to
854 // leave some junk files around if we exit abnormally. 886 // leave some junk files around if we exit abnormally.
855 887
856 atexit (do_octave_atexit); 888 atexit (do_octave_atexit);
978 quitting_gracefully = true; 1010 quitting_gracefully = true;
979 1011
980 clean_up_and_exit (retval); 1012 clean_up_and_exit (retval);
981 1013
982 return 0; 1014 return 0;
1015 }
1016
1017 // Return int instead of bool because this function is declared
1018 // extern "C".
1019
1020 int
1021 octave_starting_gui (void)
1022 {
1023 if (force_gui_option)
1024 return true;
1025
1026 if (no_gui_option)
1027 return false;
1028
1029 if (persist)
1030 return true;
1031
1032 if (! (interactive || forced_interactive))
1033 return false;
1034
1035 // If we have code to eval or execute from a file, and we are going to
1036 // exit immediately after executing it, don't start the gui.
1037
1038 int last_arg_idx = optind;
1039 int remaining_args = octave_cmdline_argc - last_arg_idx;
1040
1041 if (! code_to_eval.empty () || remaining_args > 0)
1042 return false;
1043
1044 return true;
983 } 1045 }
984 1046
985 DEFUN (argv, args, , 1047 DEFUN (argv, args, ,
986 "-*- texinfo -*-\n\ 1048 "-*- texinfo -*-\n\
987 @deftypefn {Built-in Function} {} argv ()\n\ 1049 @deftypefn {Built-in Function} {} argv ()\n\