35 #if defined (HAVE_CONFIG_H)
51 #if ! defined (OCTAVE_VERSION)
52 # define OCTAVE_VERSION %OCTAVE_VERSION%
55 #if ! defined (OCTAVE_ARCHLIBDIR)
56 # define OCTAVE_ARCHLIBDIR %OCTAVE_ARCHLIBDIR%
59 #if ! defined (OCTAVE_BINDIR)
60 # define OCTAVE_BINDIR %OCTAVE_BINDIR%
63 #if ! defined (OCTAVE_PREFIX)
64 # define OCTAVE_PREFIX %OCTAVE_PREFIX%
67 #if ! defined (OCTAVE_EXEC_PREFIX)
68 # define OCTAVE_EXEC_PREFIX %OCTAVE_EXEC_PREFIX%
74 #if defined (HAVE_OCTAVE_QT_GUI) && ! defined (OCTAVE_USE_WINDOWS_API)
78 static pid_t gui_pid = 0;
80 static int caught_signal = -1;
83 gui_driver_sig_handler (
int sig)
90 gui_driver_set_signal_handler (
const char *signame,
103 gui_driver_set_signal_handler (
"SIGINT", gui_driver_sig_handler);
104 gui_driver_set_signal_handler (
"SIGBREAK", gui_driver_sig_handler);
105 gui_driver_set_signal_handler (
"SIGABRT", gui_driver_sig_handler);
106 gui_driver_set_signal_handler (
"SIGALRM", gui_driver_sig_handler);
107 gui_driver_set_signal_handler (
"SIGBUS", gui_driver_sig_handler);
113 gui_driver_set_signal_handler (
"SIGEMT", gui_driver_sig_handler);
114 gui_driver_set_signal_handler (
"SIGFPE", gui_driver_sig_handler);
115 gui_driver_set_signal_handler (
"SIGHUP", gui_driver_sig_handler);
116 gui_driver_set_signal_handler (
"SIGILL", gui_driver_sig_handler);
121 gui_driver_set_signal_handler (
"SIGIOT", gui_driver_sig_handler);
122 gui_driver_set_signal_handler (
"SIGLOST", gui_driver_sig_handler);
123 gui_driver_set_signal_handler (
"SIGPIPE", gui_driver_sig_handler);
124 gui_driver_set_signal_handler (
"SIGPOLL", gui_driver_sig_handler);
129 gui_driver_set_signal_handler (
"SIGQUIT", gui_driver_sig_handler);
130 gui_driver_set_signal_handler (
"SIGSEGV", gui_driver_sig_handler);
134 gui_driver_set_signal_handler (
"SIGSYS", gui_driver_sig_handler);
135 gui_driver_set_signal_handler (
"SIGTERM", gui_driver_sig_handler);
136 gui_driver_set_signal_handler (
"SIGTRAP", gui_driver_sig_handler);
143 gui_driver_set_signal_handler (
"SIGUSR1", gui_driver_sig_handler);
144 gui_driver_set_signal_handler (
"SIGUSR2", gui_driver_sig_handler);
145 gui_driver_set_signal_handler (
"SIGVTALRM", gui_driver_sig_handler);
146 gui_driver_set_signal_handler (
"SIGIO", gui_driver_sig_handler);
150 gui_driver_set_signal_handler (
"SIGXCPU", gui_driver_sig_handler);
151 gui_driver_set_signal_handler (
"SIGXFSZ", gui_driver_sig_handler);
189 std::cerr << argv[0] <<
": failed to exec '" << file <<
"'" << std::endl;
201 char *tmp =
new char [
len+1];
202 tmp = strcpy (tmp, s);
212 bool start_gui =
false;
213 bool gui_libs =
true;
215 bool eval_code =
false;
216 bool persist_octave =
false;
222 std::string octave_cli
224 std::string octave_gui = octave_archlibdir +
dir_sep_char +
"octave-gui";
226 #if defined (HAVE_OCTAVE_QT_GUI)
231 std::string file = octave_gui;
233 std::string file = octave_cli;
238 static char **new_argv =
new char * [argc + 2];
242 bool warn_display =
true;
243 bool no_display =
false;
245 for (
int i = 1; i < argc; i++)
247 if (!
strcmp (argv[i],
"--no-gui-libs"))
258 else if (!
strcmp (argv[i],
"--no-gui"))
267 new_argv[k++] = argv[i];
269 else if (!
strcmp (argv[i],
"--gui") || !
strcmp (argv[i],
"--force-gui"))
280 else if (!
strcmp (argv[i],
"--persist"))
287 persist_octave =
true;
288 new_argv[k++] = argv[i];
290 else if (!
strcmp (argv[i],
"--eval") ||
291 (
strlen (argv[i]) > 0 && argv[i][0] !=
'-'))
294 new_argv[k++] = argv[i];
296 else if (!
strcmp (argv[i],
"--silent") || !
strcmp (argv[i],
"--quiet"))
298 warn_display =
false;
299 new_argv[k++] = argv[i];
301 else if (!
strcmp (argv[i],
"--no-window-system"))
304 new_argv[k++] = argv[i];
306 else if (
strlen (argv[i]) > 1 && argv[i][0] ==
'-' && argv[i][1] !=
'-')
313 for (
size_t j = 1; j <
len; j++)
320 warn_display =
false;
326 new_argv[k++] = argv[i];
329 new_argv[k++] = argv[i];
332 if (start_gui && eval_code && ! persist_octave)
344 std::cerr <<
"octave: conflicting options: --no-gui-libs and --gui"
349 #if ! defined (HAVE_OCTAVE_QT_GUI)
350 std::cerr <<
"octave: GUI features missing or disabled in this build"
357 for (
int j = k; j > 1; j--)
358 new_argv[j] = new_argv[j-1];
360 new_argv[1] = argv[idx_gui];
364 new_argv[k] =
nullptr;
373 else if (gui_libs || start_gui)
388 if (! display_check_err_msg)
389 display_check_err_msg =
"graphical display unavailable";
391 std::cerr <<
"octave: " << display_check_err_msg << std::endl;
392 std::cerr <<
"octave: disabling GUI features" << std::endl;
397 #if defined (OCTAVE_USE_WINDOWS_API)
401 new_argv[0] =
strsave (file.c_str ());
414 #if defined (HAVE_OCTAVE_QT_GUI) && ! defined (OCTAVE_USE_WINDOWS_API)
416 if (gui_libs && start_gui)
432 std::cerr <<
"octave: fork failed!" << std::endl;
436 else if (gui_pid == 0)
442 std::cerr <<
"octave: error calling setsid!" << std::endl;
464 if (caught_signal > 0)
466 int sig = caught_signal;
479 std::cerr <<
"octave exited with signal "
491 std::cerr << argv[0] <<
": " << std::strerror (errno) << std::endl;
499 std::cerr << argv[0] <<
": " << std::strerror (errno) << std::endl;
const char * display_available(int *dpy_avail)
#define OCTAVE_ARCHLIBDIR
static char * strsave(const char *s)
static std::string get_octave_archlibdir(void)
int main(int argc, char **argv)
static int octave_exec(const std::string &file, char **argv)
static std::string get_octave_bindir(void)
bool strcmp(const T &str_a, const T &str_b)
True if strings are the same.
void install_signal_handlers(void)
T::size_type strlen(const typename T::value_type *str)
octave_value::octave_value(const Array< char > &chm, char type) return retval
static void set_octave_home(void)
static std::string prepend_octave_exec_home(const std::string &s)
static const char dir_sep_char
static std::string octave_getenv(const std::string &name)
void octave_block_signal_by_name(const char *signame)
void octave_unblock_signal_by_name(const char *signame)
int octave_kill_wrapper(pid_t pid, int signum)
void octave_unblock_async_signals(void)
void octave_block_async_signals(void)
octave_sig_handler * octave_set_signal_handler_by_name(const char *signame, octave_sig_handler *handler, bool restart_syscalls)
void octave_sig_handler(int)
pid_t octave_setsid_wrapper(void)
pid_t octave_fork_wrapper(void)
int octave_execv_wrapper(const char *file, char *const *argv)
pid_t octave_waitpid_wrapper(pid_t pid, int *statusp, int options)
bool octave_wifsignaled_wrapper(int status)
int octave_wexitstatus_wrapper(int status)
bool octave_wifexited_wrapper(int status)
int octave_wtermsig_wrapper(int status)