glib/gspawn-win32.c Implement G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce
authorTor Lillqvist <tml@iki.fi>
Wed, 10 Mar 2004 22:59:14 +0000 (22:59 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Wed, 10 Mar 2004 22:59:14 +0000 (22:59 +0000)
2004-03-10  Tor Lillqvist  <tml@iki.fi>

* glib/gspawn-win32.c
* glib/gspawn-win32-helper.c: Implement
G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler)

* tests/spawn-test.c
* tests/spawn-test-win32-gui.c: Test it.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gspawn-win32-helper.c
glib/gspawn-win32.c
tests/spawn-test-win32-gui.c
tests/spawn-test.c

index 9d8f58a..9c3e305 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2004-03-10  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gspawn-win32.c
+       * glib/gspawn-win32-helper.c: Implement
+       G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler)
+
+       * tests/spawn-test.c
+       * tests/spawn-test-win32-gui.c: Test it.
+
 Tue Mar  9 09:16:11 2004  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.6 ===
index 9d8f58a..9c3e305 100644 (file)
@@ -1,3 +1,12 @@
+2004-03-10  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gspawn-win32.c
+       * glib/gspawn-win32-helper.c: Implement
+       G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler)
+
+       * tests/spawn-test.c
+       * tests/spawn-test-win32-gui.c: Test it.
+
 Tue Mar  9 09:16:11 2004  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.6 ===
index 9d8f58a..9c3e305 100644 (file)
@@ -1,3 +1,12 @@
+2004-03-10  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gspawn-win32.c
+       * glib/gspawn-win32-helper.c: Implement
+       G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler)
+
+       * tests/spawn-test.c
+       * tests/spawn-test-win32-gui.c: Test it.
+
 Tue Mar  9 09:16:11 2004  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.6 ===
index 9d8f58a..9c3e305 100644 (file)
@@ -1,3 +1,12 @@
+2004-03-10  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gspawn-win32.c
+       * glib/gspawn-win32-helper.c: Implement
+       G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler)
+
+       * tests/spawn-test.c
+       * tests/spawn-test-win32-gui.c: Test it.
+
 Tue Mar  9 09:16:11 2004  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.6 ===
index 9d8f58a..9c3e305 100644 (file)
@@ -1,3 +1,12 @@
+2004-03-10  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gspawn-win32.c
+       * glib/gspawn-win32-helper.c: Implement
+       G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler)
+
+       * tests/spawn-test.c
+       * tests/spawn-test-win32-gui.c: Test it.
+
 Tue Mar  9 09:16:11 2004  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.6 ===
index 9d8f58a..9c3e305 100644 (file)
@@ -1,3 +1,12 @@
+2004-03-10  Tor Lillqvist  <tml@iki.fi>
+
+       * glib/gspawn-win32.c
+       * glib/gspawn-win32-helper.c: Implement
+       G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler)
+
+       * tests/spawn-test.c
+       * tests/spawn-test-win32-gui.c: Test it.
+
 Tue Mar  9 09:16:11 2004  Owen Taylor  <otaylor@redhat.com>
 
        * === Released 2.3.6 ===
index 0679031..5a2c910 100644 (file)
@@ -76,6 +76,7 @@ WinMain (struct HINSTANCE__ *hInstance,
   int handle;
   int no_error = CHILD_NO_ERROR;
   int zero = 0;
+  gint file_and_argv_zero = 0;
   gchar **new_argv;
 
   SETUP_DEBUG();
@@ -105,6 +106,10 @@ WinMain (struct HINSTANCE__ *hInstance,
    */
   child_err_report_fd = atoi (__argv[ARG_CHILD_ERR_REPORT]);
 
+  /* Hack to implement G_SPAWN_FILE_AND_ARGV_ZERO */
+  if (__argv[ARG_CHILD_ERR_REPORT][strlen (__argv[ARG_CHILD_ERR_REPORT]) - 1] == '#')
+    file_and_argv_zero = 1;
+
   /* argv[ARG_STDIN..ARG_STDERR] are the file descriptors that should
    * be dup2'd to stdin, stdout and stderr, '-' if the corresponding
    * std* should be let alone, and 'z' if it should be connected to
@@ -220,7 +225,7 @@ WinMain (struct HINSTANCE__ *hInstance,
                                        __argv[ARG_PROGRAM],
                                        (mode == P_WAIT ?
                                         "P_WAIT" : "P_NOWAIT")));
-      i = ARG_PROGRAM+1;
+      i = ARG_PROGRAM + 1 + file_and_argv_zero;
       while (new_argv[i])
        {
          g_string_append (debugstring, new_argv[i++]);
@@ -231,9 +236,9 @@ WinMain (struct HINSTANCE__ *hInstance,
     }
 
   if (new_argv[ARG_USE_PATH][0] == 'y')
-    handle = spawnvp (mode, __argv[ARG_PROGRAM], new_argv+ARG_PROGRAM);
+    handle = spawnvp (mode, __argv[ARG_PROGRAM], new_argv + ARG_PROGRAM + file_and_argv_zero);
   else
-    handle = spawnv (mode, __argv[ARG_PROGRAM], new_argv+ARG_PROGRAM);
+    handle = spawnv (mode, __argv[ARG_PROGRAM], new_argv + ARG_PROGRAM + file_and_argv_zero);
 
   if (debug)
     {
index 5ca783a..3c2a944 100644 (file)
@@ -39,8 +39,6 @@
  * The structure of the source code in this file is a mess, I know.
  */
 
-/* FIXME: Actually implement G_SPAWN_FILE_AND_ARGV_ZERO */
-
 /* Define this to get some logging all the time */
 /* #define G_SPAWN_WIN32_DEBUG */
 
@@ -670,9 +668,9 @@ do_spawn (gboolean              dont_wait,
        g_print ("doing without gspawn-win32-helper\n");
 
       if (search_path)
-       rc = spawnvp (mode, argv[0], protected_argv);
+       rc = spawnvp (mode, argv[0], file_and_argv_zero ? protected_argv + 1 : protected_argv);
       else
-       rc = spawnv (mode, argv[0], protected_argv);
+       rc = spawnv (mode, argv[0], file_and_argv_zero ? protected_argv + 1 : protected_argv);
 
       for (i = 0; i < argc; i++)
        g_free (protected_argv[i]);
@@ -695,6 +693,14 @@ do_spawn (gboolean              dont_wait,
   _g_sprintf (args[ARG_CHILD_ERR_REPORT], "%d", child_err_report_fd);
   new_argv[ARG_CHILD_ERR_REPORT] = args[ARG_CHILD_ERR_REPORT];
 
+  if (file_and_argv_zero)
+    {
+      /* Overload ARG_CHILD_ERR_REPORT to also encode the
+       * G_SPAWN_FILE_AND_ARGV_ZERO functionality.
+       */
+      strcat (args[ARG_CHILD_ERR_REPORT], "#");
+    }
+
   if (stdin_fd >= 0)
     {
       _g_sprintf (args[ARG_STDIN], "%d", stdin_fd);
index 8622d44..aade3e7 100644 (file)
@@ -10,7 +10,14 @@ WinMain (struct HINSTANCE__ *hInstance,
        char *lpszCmdLine,
        int   nCmdShow)
 {
-  if (__argc <= 2)
+  char buf[100];
+
+  if (__argc >= 2 && strcmp (__argv[1], "nop") == 0)
+    {
+      sprintf (buf, "spawn-test-win32-gui: argv[0]=\"%s\"", __argv[0]);
+      MessageBox (NULL, buf, lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
+    }
+  else if (__argc <= 2)
     {
       MessageBox (NULL, "spawn-test-win32-gui: Will write to stdout",
                  lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
@@ -29,7 +36,6 @@ WinMain (struct HINSTANCE__ *hInstance,
       int infd = atoi (__argv[2]);
       int outfd = atoi (__argv[3]);
       int k, n;
-      char buf[100];
 
       if (infd < 0 || outfd < 0)
        {
@@ -87,9 +93,6 @@ WinMain (struct HINSTANCE__ *hInstance,
        }
     }
 
-  MessageBox (NULL, "spawn-test-win32-gui: Sleeping a bit.",
-             lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
-  
   Sleep (2000);
   
   MessageBox (NULL, "spawn-test-win32-gui: Done, exiting.",
index cfd4e0e..efe9afe 100644 (file)
@@ -131,8 +131,9 @@ run_tests (void)
       erroutput = NULL;
     }
 
-  printf ("Starting spawn-test-win32-gui asynchronously (without wait).\n"
-         "Click on the OK buttons.\n");
+  printf ("Running spawn-test-win32-gui in various ways. Click on the OK buttons.\n");
+
+  printf ("First asynchronously (without wait).\n");
 
   if (!g_spawn_command_line_async ("'.\\spawn-test-win32-gui.exe' 1", &err))
     {
@@ -141,8 +142,7 @@ run_tests (void)
       exit (1);
     }
 
-  printf ("Running spawn-test-win32-gui synchronously,\n"
-         "collecting its output. Click on the OK buttons.\n");
+  printf ("Now synchronously, collecting its output.\n");
   if (!g_spawn_command_line_sync ("'.\\spawn-test-win32-gui.exe' 2",
                                  &output, &erroutput, NULL,
                                  &err))
@@ -174,8 +174,26 @@ run_tests (void)
       g_free (erroutput);
     }
 
-  printf ("Running spawn-test-win32-gui asynchronously again.\n"
-         "This time talking to it through pipes. Click on the OK buttons.\n");
+  printf ("Now with G_SPAWN_FILE_AND_ARGV_ZERO.\n");
+
+  if (!g_shell_parse_argv ("'.\\spawn-test-win32-gui.exe' this-should-be-argv-zero nop", NULL, &argv, &err))
+    {
+      fprintf (stderr, "Error parsing command line? %s\n", err->message);
+      g_error_free (err);
+      exit (1);
+    }
+
+  if (!g_spawn_async (NULL, argv, NULL,
+                     G_SPAWN_FILE_AND_ARGV_ZERO,
+                     NULL, NULL, NULL,
+                     &err))
+    {
+      fprintf (stderr, "Error: %s\n", err->message);
+      g_error_free (err);
+      exit (1);
+    }
+
+  printf ("Now talking to it through pipes.\n");
 
   if (pipe (pipedown) < 0 ||
       pipe (pipeup) < 0)