octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

integrating octave-gui and octave main programs (was: Re: Last commit ma


From: John W. Eaton
Subject: integrating octave-gui and octave main programs (was: Re: Last commit may break your builds)
Date: Sun, 5 Aug 2012 17:01:09 -0400

On  5-Aug-2012, Michael Goffioul wrote:

| With the change 
| 
| http://hg.savannah.gnu.org/hgweb/octave/rev/3d7a7ae53bbf
| 
| building the GUI should be pretty well integrated with the octave build 
system.
| It adds support for resource files compilation and for the "dist" target.

Thanks.  I checked in a few more improvements here:

  http://hg.savannah.gnu.org/hgweb/octave/rev/3735a0e783cb

Now we don't try run qmake or look for moc, uic, or rcc unless qmake
is available.  Running make from the top-level directory will also
build the GUI, so you don't have to cd to the gui directory and run
make separately.  I also defined a HAVE_QT flag in config.h, but it's
not used yet.

Note that if you don't have Octave installed, Octave will not know
where to find the core .m files.  It will be searching for them in
the installation directory tree, not the source tree.  To fix that, we
need a "run-octave" script for the GUI.  But before doing that, I
think we should decide how we want to integrate the "octave-gui" main
program and the current "octave" main program.  I started working on
the attached changes to do that, so that if we are building the GUI,
then the "octave-gui" main program can be THE Octave program.  It's
not finished yet, as we need an option for "--disable-gui" and there
are some things I'm not sure about, like what should happen for things
like

  octave --eval "foo"

Without the --persist option, should a command like this start the GUI
and execute the command in the terminal window, then immediately close
the GUI?  Or should it skip starting the GUI?  With --persist, it
seems obvious that it should start the GUI and evaluate the command in
the GUI terminal window.  What if the commands to be evaluated perform
some operation that requires the GUI environment?  Should we have a
--force-gui option for that case?

jwe

# HG changeset patch
# User John W. Eaton <address@hidden>
# Date 1344197758 14400
# Branch gui
# Node ID 5e28b7cdfb75eca8cd857283daf51940464d3604
# Parent  3735a0e783cb30c2cffc2ba884e18f427de965f5
imported patch gui-main

diff --git a/gui/src/octave-adapter/octave-main-thread.cc 
b/gui/src/octave-adapter/octave-main-thread.cc
--- a/gui/src/octave-adapter/octave-main-thread.cc
+++ b/gui/src/octave-adapter/octave-main-thread.cc
@@ -27,8 +27,6 @@
 octave_main_thread::run ()
 {
   setlocale (LC_ALL, "en_US.UTF-8");
-  int argc = 1;
-  const char *argv[] = { "octave" };
   emit ready ();
-  octave_main (argc, const_cast<char**>(argv), 0);
+  octave_execute_interpreter ();
 }
diff --git a/gui/src/octave-gui.cc b/gui/src/octave-gui.cc
--- a/gui/src/octave-gui.cc
+++ b/gui/src/octave-gui.cc
@@ -22,36 +22,41 @@
 #include "resource-manager.h"
 #include "main-window.h"
 
+// Dissociate from the controlling terminal, if any.
+
+static void
+dissociate_terminal (void)
+{
+  pid_t pid = fork ();
+
+  if (pid < 0)
+    {
+      std::cerr << "fork failed!" << std::endl;;
+      exit (1);
+    }
+  else if (pid == 0)
+    {
+      // Child.
+
+      if (setsid () < 0)
+        {
+          std::cerr << "setsid error" << std::endl;
+          exit (1);
+        }
+    }
+  else
+    exit (0);
+}
+
 int
 main (int argc, char *argv[])
 {
-  /* dissociate from the controlling terminal, if any */
+  octave_initialize_interpreter (argc, argv, 0);
 
-  pid_t pid = fork ();
-  if (pid < 0)
-    {
-      //fprintf (stderr, "fork failed\n");
-      return 1;
-    }
-  else if (pid == 0)
-    {
-      /* child */
-      //fprintf (stderr, "in child, calling setsid ()\n");
-
-      if (setsid () < 0)
-        {
-          //fprintf (stderr, "setsid error\n");
-          return 1;
-        }
-    }
-  else
-    {
-      /* parent */
-      //fprintf (stderr, "in parent, exiting\n");
-      exit (0);
-    }
+  dissociate_terminal ();
 
   QApplication application (argc, argv);
+
   while (true)
     {
       if (resource_manager::instance ()->is_first_run ())
diff --git a/src/octave.cc b/src/octave.cc
--- a/src/octave.cc
+++ b/src/octave.cc
@@ -81,6 +81,10 @@
 
 extern void install_builtins (void);
 
+int octave_cmdline_argc;
+char **octave_cmdline_argv;
+int octave_embedded;
+
 // The command-line options.
 static string_vector octave_argv;
 
@@ -633,6 +637,18 @@
 int
 octave_main (int argc, char **argv, int embedded)
 {
+  octave_initialize_interpreter (argc, argv, embedded);
+
+  return octave_execute_interpreter ();
+}
+
+void
+octave_initialize_interpreter (int argc, char **argv, int embedded)
+{
+  octave_cmdline_argc = argc;
+  octave_cmdline_argv = argv;
+  octave_embedded = embedded;
+
   octave_env::set_program_name (argv[0]);
 
   octave_program_invocation_name = octave_env::get_program_invocation_name ();
@@ -862,9 +878,6 @@
   if (line_editing)
     initialize_command_input ();
 
-  if (! inhibit_startup_message)
-    std::cout << OCTAVE_STARTUP_MESSAGE "\n" << std::endl;
-
   if (traditional)
     maximum_braindamage ();
 
@@ -880,6 +893,13 @@
   load_path::initialize (set_initial_path);
 
   initialize_history (read_history_file);
+}
+
+int
+octave_execute_interpreter (void)
+{
+  if (! inhibit_startup_message)
+    std::cout << OCTAVE_STARTUP_MESSAGE "\n" << std::endl;
 
   execute_startup_files ();
 
@@ -892,7 +912,7 @@
 
   int last_arg_idx = optind;
 
-  int remaining_args = argc - last_arg_idx;
+  int remaining_args = octave_cmdline_argc - last_arg_idx;
 
   if (! code_to_eval.empty ())
     {
@@ -907,9 +927,9 @@
       // If we are running an executable script (#! /bin/octave) then
       // we should only see the args passed to the script.
 
-      intern_argv (remaining_args, argv+last_arg_idx);
+      intern_argv (remaining_args, octave_cmdline_argv+last_arg_idx);
 
-      execute_command_line_file (argv[last_arg_idx]);
+      execute_command_line_file (octave_cmdline_argv[last_arg_idx]);
 
       if (! persist)
         {
@@ -924,9 +944,9 @@
   command_editor::reset_current_command_number (1);
 
   // Now argv should have the full set of args.
-  intern_argv (argc, argv);
+  intern_argv (octave_cmdline_argc, octave_cmdline_argv);
 
-  if (! embedded)
+  if (! octave_embedded)
     switch_to_buffer (create_buffer (get_input_from_stdin ()));
 
   // Force input to be echoed if not really interactive, but the user
@@ -941,7 +961,7 @@
       bind_internal_variable ("echo_executing_commands", ECHO_CMD_LINE);
     }
 
-  if (embedded)
+  if (octave_embedded)
     {
       // FIXME -- do we need to do any cleanup here before
       // returning?  If we don't, what will happen to Octave functions
diff --git a/src/octave.h b/src/octave.h
--- a/src/octave.h
+++ b/src/octave.h
@@ -29,6 +29,15 @@
 
 extern OCTINTERP_API int octave_main (int argc, char **argv, int embedded);
 
+extern OCTINTERP_API void
+octave_initialize_interpreter (int argc, char **argv, int embedded);
+
+extern OCTINTERP_API int octave_execute_interpreter (void);
+
+extern OCTINTERP_API int octave_cmdline_argc;
+extern OCTINTERP_API char **octave_cmdline_argv;
+extern OCTINTERP_API int octave_embedded;
+
 #ifdef  __cplusplus
 }
 #endif

reply via email to

[Prev in Thread] Current Thread [Next in Thread]