? skey/testskey
Index: terminal-screen.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-screen.c,v
retrieving revision 1.106
diff -u -p -r1.106 terminal-screen.c
--- terminal-screen.c	20 Nov 2005 15:06:33 -0000	1.106
+++ terminal-screen.c	23 Nov 2005 08:31:03 -0000
@@ -69,6 +69,7 @@ struct _TerminalScreenPrivate
   guint gconf_connection_id;
   GtkWidget *hbox;
   GtkWidget *scrollbar;
+  char **environ;
 };
 
 static GList* used_ids = NULL;
@@ -265,6 +266,7 @@ terminal_screen_init (TerminalScreen *sc
   if (screen->priv->working_dir == NULL) /* shouldn't ever happen */
     screen->priv->working_dir = g_strdup (g_get_home_dir ());
   screen->priv->child_pid = -1;
+  screen->priv->environ = NULL;
 
   screen->priv->recheck_working_dir_idle = 0;
   
@@ -450,6 +452,7 @@ terminal_screen_finalize (GObject *objec
   g_free (screen->priv->matched_string);
   g_strfreev (screen->priv->override_command);
   g_free (screen->priv->working_dir);
+  g_strfreev (screen->priv->environ);
   
   g_free (screen->priv);
   
@@ -1100,18 +1103,24 @@ get_child_environment (GtkWidget      *t
   char **p;
   int i;
   char **retval;
+  char **env;
 #define EXTRA_ENV_VARS 7
   
   profile = screen->priv->profile;
+  /* if screen->priv->environ is defined, we should use that instead */
+  if (screen->priv->environ)
+	  env = screen->priv->environ;
+  else
+	  env = environ;
 
   /* count env vars that are set */
-  for (p = environ; *p; p++)
+  for (p = env; *p; p++)
     ;
   
-  i = p - environ;
+  i = p - env;
   retval = g_new (char *, i + 1 + EXTRA_ENV_VARS);
 
-  for (i = 0, p = environ; *p; p++)
+  for (i = 0, p = env; *p; p++)
     {
       /* Strip all these out, we'll replace some of them */
       if ((strncmp (*p, "COLUMNS=", 8) == 0) ||
@@ -1224,7 +1233,7 @@ new_window_callback (GtkWidget      *men
                              NULL,
                              FALSE, FALSE, FALSE,
                              NULL, NULL, NULL, dir, NULL, 1.0,
-                             NULL, name, -1);
+                             NULL, name, -1, NULL);
 
   g_free (name);
 }
@@ -1243,7 +1252,7 @@ new_tab_callback (GtkWidget      *menu_i
                              NULL,
                              FALSE, FALSE, FALSE,
                              NULL, NULL, NULL, dir, NULL, 1.0,
-                             NULL, NULL, -1);
+                             NULL, NULL, -1, NULL);
 }
 
 static void
@@ -1836,6 +1845,16 @@ terminal_screen_set_working_dir (Termina
 
   g_free (screen->priv->working_dir);
   screen->priv->working_dir = g_strdup (dirname);
+}
+
+void
+terminal_screen_set_environ (TerminalScreen *screen,
+                             char          **env)
+{
+  g_return_if_fail (TERMINAL_IS_SCREEN (screen));
+
+  g_free (screen->priv->environ);
+  screen->priv->environ = g_strdupv (env);
 }
 
 const char*
Index: terminal-screen.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-screen.h,v
retrieving revision 1.10
diff -u -p -r1.10 terminal-screen.h
--- terminal-screen.h	20 Nov 2005 15:06:34 -0000	1.10
+++ terminal-screen.h	23 Nov 2005 08:31:03 -0000
@@ -106,6 +106,8 @@ const char *terminal_screen_get_dynamic_
 
 void        terminal_screen_set_working_dir   (TerminalScreen *screen,
                                                const char     *dirname);
+void        terminal_screen_set_environ       (TerminalScreen *screen,
+                                               char          **env);
 const char *terminal_screen_get_working_dir   (TerminalScreen *screen);
 
 void        terminal_screen_set_font_scale    (TerminalScreen *screen,
Index: terminal-window.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-window.c,v
retrieving revision 1.111
diff -u -p -r1.111 terminal-window.c
--- terminal-window.c	20 Nov 2005 15:06:34 -0000	1.111
+++ terminal-window.c	23 Nov 2005 08:31:12 -0000
@@ -2212,7 +2212,7 @@ new_window (TerminalWindow *window,
                              screen,
                              FALSE, FALSE, FALSE,
                              NULL, NULL, NULL, dir, NULL, 1.0,
-                             NULL, name, -1);
+                             NULL, name, -1, NULL);
 }
 
 static void
@@ -2238,7 +2238,7 @@ new_tab_callback (GtkWidget      *menuit
                                  NULL,
                                  FALSE, FALSE, FALSE,
                                  NULL, NULL, NULL, dir, NULL, 1.0,
-                                 NULL, NULL, -1);
+                                 NULL, NULL, -1, NULL);
     }
 }
 
Index: terminal.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal.c,v
retrieving revision 1.85
diff -u -p -r1.85 terminal.c
--- terminal.c	20 Nov 2005 15:06:34 -0000	1.85
+++ terminal.c	23 Nov 2005 08:31:19 -0000
@@ -44,7 +44,6 @@
 #include <time.h>
 #include <gdk/gdkx.h>
 
-
 /* Settings storage works as follows:
  *   /apps/gnome-terminal/global/
  *   /apps/gnome-terminal/profiles/Foo/
@@ -1382,7 +1381,8 @@ option_parsing_results_apply_directory_d
 }
 
 static int
-new_terminal_with_options (OptionParsingResults *results)
+new_terminal_with_options_and_environ (OptionParsingResults *results,
+                                       char                 **env)
 {
   GList *tmp;
   
@@ -1446,7 +1446,8 @@ new_terminal_with_options (OptionParsing
                                          it->zoom : 1.0,
                                          results->startup_id,
                                          results->display_name,
-                                         results->screen_number);
+                                         results->screen_number,
+					 env);
 
               current_window = g_list_last (app->windows)->data;
             }
@@ -1465,7 +1466,8 @@ new_terminal_with_options (OptionParsing
                                          NULL,
                                          it->zoom_set ?
                                          it->zoom : 1.0,
-                                         NULL, NULL, -1);
+                                         NULL, NULL, -1,
+					 env);
             }
           
           if (it->active)
@@ -1489,6 +1491,12 @@ new_terminal_with_options (OptionParsing
   return 0;
 }
 
+static inline int
+new_terminal_with_options (OptionParsingResults *results)
+{
+	return new_terminal_with_options_and_environ (results, NULL);
+}
+
 /* This assumes that argv already has room for the args,
  * and inserts them just after argv[0]
  */
@@ -1899,7 +1907,8 @@ terminal_app_new_terminal (TerminalApp  
                            double           zoom,
                            const char      *startup_id,
                            const char      *display_name,
-                           int              screen_number)
+                           int              screen_number,
+			   char           **env)
 {
   gboolean window_created;
   gboolean screen_created;
@@ -1958,6 +1967,9 @@ terminal_app_new_terminal (TerminalApp  
       
       if (override_command)    
         terminal_screen_set_override_command (screen, override_command);
+
+      if (env)
+        terminal_screen_set_environ (screen, env);
     
       terminal_screen_set_font_scale (screen, zoom);
     
@@ -3664,11 +3676,13 @@ typedef struct
 {
   int argc;
   char **argv;
+  char **environ;
 } NewTerminalEvent;
 
 static void
 handle_new_terminal_event (int          argc,
-                           char       **argv)
+                           char       **argv,
+			   char       **env)
 {
   int nextopt;
   poptContext ctx;
@@ -3676,7 +3690,7 @@ handle_new_terminal_event (int          
   OptionParsingResults *results;
 
   g_assert (initialization_complete);
-  
+
   results = option_parsing_results_init (&argc, argv);
   
   /* Find and parse --display */
@@ -3709,7 +3723,7 @@ handle_new_terminal_event (int          
 
   option_parsing_results_apply_directory_defaults (results);
 
-  new_terminal_with_options (results);
+  new_terminal_with_options_and_environ (results, env);
 
   option_parsing_results_free (results);
 }
@@ -3722,15 +3736,18 @@ handle_new_terminal_events (void)
       GSList *next = pending_new_terminal_events->next;
       NewTerminalEvent *event = pending_new_terminal_events->data;
 
-      handle_new_terminal_event (event->argc, event->argv);
+      handle_new_terminal_event (event->argc, event->argv, event->environ);
 
       g_strfreev (event->argv);
+      g_strfreev (event->environ);
       g_free (event);
       g_slist_free_1 (pending_new_terminal_events);
       pending_new_terminal_events = next;
     }
 }
 
+#define END_ENVIRON "END-ENVIRON"
+
 /*
  *   Invoked remotely to instantiate a terminal with the
  * given arguments.
@@ -3743,8 +3760,11 @@ terminal_new_event (BonoboListener    *l
 		    gpointer           user_data)
 {
   CORBA_sequence_CORBA_string *args;
+  char **tmp_strv;
   char **tmp_argv;
+  char **tmp_environ;
   int tmp_argc;
+  int tmp_lenviron;
   int i;
   NewTerminalEvent *event;
   
@@ -3757,19 +3777,60 @@ terminal_new_event (BonoboListener    *l
 
   args = any->_value;
   
-  tmp_argv = g_new0 (char*, args->_length + 1);
+  /* the buffer contains [environ] END_ENVIRON [argv] */
+  tmp_strv = g_new0 (char*, args->_length);
   i = 0;
+  tmp_lenviron = 0;
   while (i < args->_length)
     {
-      tmp_argv[i] = g_strdup (((const char**)args->_buffer)[i]);
+      tmp_strv[i] = g_strdup (((const char**)args->_buffer)[i]);
+      if (i == tmp_lenviron && strcmp (END_ENVIRON, tmp_strv[i]))
+	      tmp_lenviron++;
       ++i;
     }
-  tmp_argv[i] = NULL;
-  tmp_argc = i;
 
+  /* copy argv */
+  tmp_argc = i - tmp_lenviron - 1;
+  tmp_argv = g_new0 (char*, tmp_argc + 1);
+#if 0
+  g_print ("Got %d argv entries\n", tmp_argc);
+#endif
+  for (i = tmp_lenviron + 1; i < args->_length; i++)
+  {
+#if 0
+      g_print ("accessing argv[%d] and strv[%d] (= %s)\n",
+                      i - tmp_lenviron - 1, i, tmp_strv[i]);
+#endif
+      tmp_argv[i - tmp_lenviron - 1] = tmp_strv[i];
+  }
+  tmp_argv[tmp_argc+1] = NULL;
+#if 0
+  g_print ("---- dumping argv ----\n");
+  for (i = 0; i < tmp_argc; i++)
+      g_print ("%s\n", tmp_argv [i]);
+  g_print ("---- done ----\n");
+#endif
+  
+  /* copy environ */
+  tmp_environ = g_new0 (char*, tmp_lenviron + 1);
+  for (i = 0; i < tmp_lenviron; i++)
+  {
+      tmp_environ[i] = tmp_strv[i];
+  }
+#if 0
+  g_print ("---- dumping environ ----\n");
+  for (i = 0; i < tmp_lenviron; i++)
+      g_print ("%s\n", tmp_environ [i]);
+  g_print ("---- done ----\n");
+#endif
+
+  /* We don't free the strings, just the array */
+  g_free (tmp_strv);
+  
   event = g_new0 (NewTerminalEvent, 1);
   event->argc = tmp_argc;
   event->argv = tmp_argv;
+  event->environ = tmp_environ;
 
   pending_new_terminal_events = g_slist_append (pending_new_terminal_events,
                                                 event);
@@ -3829,7 +3890,9 @@ terminal_invoke_factory (int argc, char 
 
   if (listener != CORBA_OBJECT_NIL)
     {
+      extern char **environ;
       int i;
+      int lenviron;
       CORBA_any any;
       CORBA_sequence_CORBA_string args;
       CORBA_Environment ev;
@@ -3839,12 +3902,26 @@ terminal_invoke_factory (int argc, char 
       any._type = TC_CORBA_sequence_CORBA_string;
       any._value = &args;
 
-      args._length = argc;
+      lenviron = g_strv_length (environ);
+      /* we are packing [environ] END [argv] */
+      args._length = lenviron + argc + 1;
       args._buffer = g_newa (CORBA_char *, args._length);
 
+      /* copy environ into the buffer */
+      for (i = 0; i < lenviron; i++)
+        args._buffer[i] = environ[i];
+      args._buffer [lenviron] = END_ENVIRON;
+      /* copy argv into the buffer */
+      for (i = lenviron + 1; i < args._length; i++)
+        args._buffer [i] = argv [i - lenviron - 1];
+
+#if 0
+      g_print ("---- dumping array ----\n");
       for (i = 0; i < args._length; i++)
-        args._buffer [i] = argv [i];
-      
+	      g_print ("%s\n", args._buffer [i]);
+      g_print ("---- done ----\n");
+#endif
+		      
       Bonobo_Listener_event (listener, "new_terminal", &any, &ev);
       CORBA_Object_release (listener, &ev);
       if (!BONOBO_EX (&ev))
Index: terminal.h
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal.h,v
retrieving revision 1.19
diff -u -p -r1.19 terminal.h
--- terminal.h	20 Nov 2005 15:06:34 -0000	1.19
+++ terminal.h	23 Nov 2005 08:31:19 -0000
@@ -54,7 +54,8 @@ void terminal_app_new_terminal (Terminal
                                 double           zoom,
                                 const char      *startup_id,
                                 const char      *display_name,
-                                int              screen_number);
+                                int              screen_number,
+				char           **env);
 
 void terminal_app_manage_profiles (TerminalApp     *app,
                                    GtkWindow       *transient_parent);
