35 #if defined (HAVE_CONFIG_H)
46 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
62 #if ! defined (OCTAVE_VERSION)
63 # define OCTAVE_VERSION %OCTAVE_VERSION%
66 #if ! defined (OCTAVE_ARCHLIBDIR)
67 # define OCTAVE_ARCHLIBDIR %OCTAVE_ARCHLIBDIR%
70 #if ! defined (OCTAVE_BINDIR)
71 # define OCTAVE_BINDIR %OCTAVE_BINDIR%
74 #if ! defined (OCTAVE_PREFIX)
75 # define OCTAVE_PREFIX %OCTAVE_PREFIX%
78 #if ! defined (OCTAVE_EXEC_PREFIX)
79 # define OCTAVE_EXEC_PREFIX %OCTAVE_EXEC_PREFIX%
86 #if defined (HAVE_OCTAVE_QT_GUI) && ! defined (OCTAVE_USE_WINDOWS_API)
87 static bool fork_and_exec =
true;
89 static bool fork_and_exec =
false;
95 static pid_t gui_pid = 0;
97 static int caught_signal = -1;
100 gui_driver_sig_handler (
int sig)
107 gui_driver_set_signal_handler (
const char *signame,
114 install_signal_handlers ()
120 gui_driver_set_signal_handler (
"SIGINT", gui_driver_sig_handler);
121 gui_driver_set_signal_handler (
"SIGBREAK", gui_driver_sig_handler);
122 gui_driver_set_signal_handler (
"SIGABRT", gui_driver_sig_handler);
123 gui_driver_set_signal_handler (
"SIGALRM", gui_driver_sig_handler);
124 gui_driver_set_signal_handler (
"SIGBUS", gui_driver_sig_handler);
130 gui_driver_set_signal_handler (
"SIGEMT", gui_driver_sig_handler);
131 gui_driver_set_signal_handler (
"SIGFPE", gui_driver_sig_handler);
132 gui_driver_set_signal_handler (
"SIGHUP", gui_driver_sig_handler);
133 gui_driver_set_signal_handler (
"SIGILL", gui_driver_sig_handler);
138 gui_driver_set_signal_handler (
"SIGIOT", gui_driver_sig_handler);
139 gui_driver_set_signal_handler (
"SIGLOST", gui_driver_sig_handler);
140 gui_driver_set_signal_handler (
"SIGPIPE", gui_driver_sig_handler);
141 gui_driver_set_signal_handler (
"SIGPOLL", gui_driver_sig_handler);
146 gui_driver_set_signal_handler (
"SIGQUIT", gui_driver_sig_handler);
147 gui_driver_set_signal_handler (
"SIGSEGV", gui_driver_sig_handler);
151 gui_driver_set_signal_handler (
"SIGSYS", gui_driver_sig_handler);
152 gui_driver_set_signal_handler (
"SIGTERM", gui_driver_sig_handler);
153 gui_driver_set_signal_handler (
"SIGTRAP", gui_driver_sig_handler);
160 gui_driver_set_signal_handler (
"SIGUSR1", gui_driver_sig_handler);
161 gui_driver_set_signal_handler (
"SIGUSR2", gui_driver_sig_handler);
162 gui_driver_set_signal_handler (
"SIGVTALRM", gui_driver_sig_handler);
163 gui_driver_set_signal_handler (
"SIGIO", gui_driver_sig_handler);
167 gui_driver_set_signal_handler (
"SIGXCPU", gui_driver_sig_handler);
168 gui_driver_set_signal_handler (
"SIGXFSZ", gui_driver_sig_handler);
179 std::string obd = octave_getenv (
"OCTAVE_BINDIR");
186 get_octave_archlibdir ()
193 std::string dir = octave_getenv (
"OCTAVE_ARCHLIBDIR");
200 octave_exec (
const std::string& file,
char **argv)
204 #if defined (OCTAVE_USE_WINDOWS_API)
208 std::cerr << argv[0] <<
": failed to exec '" << file <<
"'" << std::endl;
214 strsave (
const char *s)
220 char *tmp =
new char [
len+1];
221 tmp = strcpy (tmp, s);
225 #if defined (OCTAVE_USE_WINDOWS_API) && defined (_UNICODE)
228 wmain (
int argc,
wchar_t **wargv)
230 static char **argv =
new char * [argc + 1];
231 std::vector<std::string> argv_str;
234 std::wstring_convert<std::codecvt_utf8<wchar_t>,
wchar_t> wchar_conv;
235 for (
int i_arg = 0; i_arg < argc; i_arg++)
236 argv_str.push_back (wchar_conv.to_bytes (wargv[i_arg]));
239 for (
int i_arg = 0; i_arg < argc; i_arg++)
240 argv[i_arg] = &argv_str[i_arg][0];
241 argv[argc] =
nullptr;
252 bool start_gui =
false;
253 bool gui_libs =
true;
255 bool eval_code =
false;
256 bool persist_octave =
false;
260 std::string octave_bindir = get_octave_bindir ();
261 std::string octave_archlibdir = get_octave_archlibdir ();
262 std::string octave_cli
264 std::string octave_gui = octave_archlibdir +
dir_sep_char +
"octave-gui";
266 #if defined (HAVE_OCTAVE_QT_GUI)
271 std::string file = octave_gui;
273 std::string file = octave_cli;
278 static char **new_argv =
new char * [argc + 2];
283 bool warn_display =
true;
284 bool no_display =
false;
299 int old_optind = next_optind;
324 new_argv[k++] = argv[old_optind];
334 idx_gui = old_optind;
339 fork_and_exec =
false;
340 new_argv[k++] = argv[old_optind];
348 persist_octave =
true;
349 new_argv[k++] = argv[old_optind];
354 new_argv[k++] = argv[old_optind];
359 for (
int i = old_optind; i < next_optind; i++)
360 new_argv[k++] = argv[i];
365 warn_display =
false;
366 new_argv[k++] = argv[old_optind];
372 new_argv[k++] = argv[old_optind];
376 for (
int i = old_optind; i < next_optind; i++)
377 new_argv[k++] = argv[i];
383 if (next_optind < argc)
386 for (
int i = next_optind; i < argc; i++)
387 new_argv[k++] = argv[i];
390 if (start_gui && eval_code && ! persist_octave)
402 std::cerr <<
"octave: conflicting options: --no-gui-libs and --gui"
409 std::cerr <<
"octave: conflicting options: --server and --gui"
414 #if ! defined (HAVE_OCTAVE_QT_GUI)
415 std::cerr <<
"octave: GUI features missing or disabled in this build"
422 for (
int j = k; j > 1; j--)
423 new_argv[j] = new_argv[j-1];
425 new_argv[1] = argv[idx_gui];
429 new_argv[k] =
nullptr;
438 else if (gui_libs || start_gui)
453 if (! display_check_err_msg)
454 display_check_err_msg =
"graphical display unavailable";
456 std::cerr <<
"octave: " << display_check_err_msg << std::endl;
457 std::cerr <<
"octave: disabling GUI features" << std::endl;
462 #if defined (OCTAVE_USE_WINDOWS_API)
466 new_argv[0] = strsave (file.c_str ());
479 if (fork_and_exec && gui_libs && start_gui)
495 std::cerr <<
"octave: fork failed!" << std::endl;
499 else if (gui_pid == 0)
505 std::cerr <<
"octave: error calling setsid!" << std::endl;
510 retval = octave_exec (file, new_argv);
516 install_signal_handlers ();
527 if (caught_signal > 0)
529 int sig = caught_signal;
542 std::cerr <<
"octave exited with signal "
551 retval = octave_exec (file, new_argv);
554 std::cerr << argv[0] <<
": " << std::strerror (errno) << std::endl;
void octave_unblock_async_signals()
void octave_block_async_signals()
std::string prepend_octave_exec_home(const std::string &s)
const char * display_available(int *dpy_avail)
int octave_getopt_long_wrapper(int argc, char **argv, const char *shortopts, const struct octave_getopt_options *longopts, int *longind)
int octave_optind_wrapper(void)
int octave_set_opterr_wrapper(int val)
#define OCTAVE_ARCHLIBDIR
int main(int argc, char **argv)
T::size_type strlen(const typename T::value_type *str)
#define NO_GUI_LIBS_OPTION
#define EXPERIMENTAL_TERMINAL_WIDGET_OPTION
struct octave_getopt_options long_opts[]
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)
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)