bug-diffutils
[Top][All Lists]
Advanced

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

[bug-diffutils] [PATCH] main: port subcommands to mingw


From: Paul Eggert
Subject: [bug-diffutils] [PATCH] main: port subcommands to mingw
Date: Mon, 14 May 2012 23:35:19 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1

I pushed the following patch to diffutils, in the hope
that it solves the remaining mingw problems.  I have not
tested this on mingw; just on GNU/Linux.

----
Problem reported by Eli Zaretskii in
<http://lists.gnu.org/archive/html/bug-gnu-utils/2012-05/msg00013.html>.
Approach suggested by Bruno Haible as option (4) in
<http://lists.gnu.org/archive/html/bug-gnu-utils/2012-05/msg00036.html>.
* bootstrap.conf (gnulib_modules): Add system-quote.
* src/diff3.c, src/sdiff.c, src/util.c:
Include <system-quote.h>, not <sh-quote.h>.
* src/diff3.c (read_diff):
* src/sdiff.c (main, edit):
* src/util.c (begin_output):
Use system_quote_argv, for portability to Mingw.
* src/sdiff.c (NUM_SIGS, handler_index_of_SIGINT): Now enum
values, not macros; this is cleaner and avoids a GCC warning if
!HAVE_WORKING_VFORK.
* src/util.c (begin_output) [! HAVE_WORKING_FORK]: Do not use -f,
for consistency with the HAVE_WORKING_FORK code.
---
 bootstrap.conf |    1 +
 src/diff3.c    |   39 +++++++++------------------------------
 src/sdiff.c    |   41 +++++++++++++----------------------------
 src/util.c     |   19 ++++++++++---------
 4 files changed, 33 insertions(+), 67 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 55f0837..3954c4d 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -69,6 +69,7 @@ strftime
 strptime
 strtoumax
 sys_wait
+system-quote
 unistd
 unlocked-io
 update-copyright
diff --git a/src/diff3.c b/src/diff3.c
index 3b01071..e234401 100644
--- a/src/diff3.c
+++ b/src/diff3.c
@@ -29,7 +29,7 @@
 #include <file-type.h>
 #include <getopt.h>
 #include <progname.h>
-#include <sh-quote.h>
+#include <system-quote.h>
 #include <version-etc.h>
 #include <xalloc.h>
 #include <xfreopen.h>
@@ -1161,13 +1161,15 @@ read_diff (char const *filea,
   int fd, wstatus, status;
   int werrno = 0;
   struct stat pipestat;
-
-#if HAVE_WORKING_FORK
-
   char const *argv[9];
   char const **ap;
+#if HAVE_WORKING_FORK
   int fds[2];
   pid_t pid;
+#else
+  FILE *fpipe;
+  char *command;
+#endif
 
   ap = argv;
   *ap++ = diff_program;
@@ -1181,6 +1183,8 @@ read_diff (char const *filea,
   *ap++ = fileb;
   *ap = 0;
 
+#if HAVE_WORKING_FORK
+
   if (pipe (fds) != 0)
     perror_with_exit ("pipe");
 
@@ -1210,32 +1214,7 @@ read_diff (char const *filea,
 
 #else
 
-  FILE *fpipe;
-  char const args[] = " --horizon-lines=100 -- ";
-  char *command = xmalloc (shell_quote_length (diff_program)
-                          + sizeof "-a"
-                          + sizeof "--strip-trailing-cr"
-                          + sizeof args - 1
-                          + shell_quote_length (filea) + 1
-                          + shell_quote_length (fileb) + 1);
-  char *p = command;
-  p = shell_quote_copy (p, diff_program);
-  if (text)
-    {
-      strcpy (p, " -a");
-      p += 3;
-    }
-  if (strip_trailing_cr)
-    {
-      strcpy (p, " --strip-trailing-cr");
-      p += 20;
-    }
-  strcpy (p, args);
-  p += sizeof args - 1;
-  p = shell_quote_copy (p, filea);
-  *p++ = ' ';
-  p = shell_quote_copy (p, fileb);
-  *p = 0;
+  command = system_quote_argv (SCI_SYSTEM, (char **) argv);
   errno = 0;
   fpipe = popen (command, "r");
   if (!fpipe)
diff --git a/src/sdiff.c b/src/sdiff.c
index 63b2861..e82ec84 100644
--- a/src/sdiff.c
+++ b/src/sdiff.c
@@ -31,7 +31,7 @@
 #include <file-type.h>
 #include <getopt.h>
 #include <progname.h>
-#include <sh-quote.h>
+#include <system-quote.h>
 #include <version-etc.h>
 #include <xalloc.h>
 
@@ -66,7 +66,6 @@ static void perror_fatal (char const *) 
__attribute__((noreturn));
 static void trapsigs (void);
 static void untrapsig (int);
 
-#define NUM_SIGS (sizeof sigs / sizeof *sigs)
 static int const sigs[] = {
 #ifdef SIGHUP
        SIGHUP,
@@ -87,8 +86,12 @@ static int const sigs[] = {
        SIGPIPE,
 #endif
        SIGINT
-#define handler_index_of_SIGINT (NUM_SIGS - 1)
 };
+enum
+  {
+    NUM_SIGS = sizeof sigs / sizeof *sigs,
+    handler_index_of_SIGINT = NUM_SIGS - 1
+  };
 
 #if HAVE_SIGACTION
   /* Prefer 'sigaction' if available, since 'signal' can lose signals.  */
@@ -607,19 +610,7 @@ main (int argc, char *argv[])
 
 #if ! HAVE_WORKING_FORK
       {
-       size_t cmdsize = 1;
-       char *p, *command;
-       int i;
-
-       for (i = 0;  diffargv[i];  i++)
-         cmdsize += shell_quote_length (diffargv[i]) + 1;
-       command = p = xmalloc (cmdsize);
-       for (i = 0;  diffargv[i];  i++)
-         {
-           p = shell_quote_copy (p, diffargv[i]);
-           *p++ = ' ';
-         }
-       p[-1] = 0;
+       char *command = system_quote_argv (SCI_SYSTEM, (char **) diffargv);
        errno = 0;
        diffout = popen (command, "r");
        if (! diffout)
@@ -1020,16 +1011,17 @@ edit (struct line_filter *left, char const *lname, lin 
lline, lin llen,
            {
              int wstatus;
              int werrno = 0;
+             char const *argv[3];
+
              ignore_SIGINT = true;
              checksigs ();
+             argv[0] = editor_program;
+             argv[1] = tmpname;
+             argv[2] = 0;
 
              {
 #if ! HAVE_WORKING_FORK
-               char *command =
-                 xmalloc (shell_quote_length (editor_program)
-                          + 1 + strlen (tmpname) + 1);
-               sprintf (shell_quote_copy (command, editor_program),
-                        " %s", tmpname);
+               char *command = system_quote_argv (SCI_SYSTEM, (char **) argv);
                wstatus = system (command);
                if (wstatus == -1)
                  werrno = errno;
@@ -1040,13 +1032,6 @@ edit (struct line_filter *left, char const *lname, lin 
lline, lin llen,
                pid = fork ();
                if (pid == 0)
                  {
-                   char const *argv[3];
-                   int i = 0;
-
-                   argv[i++] = editor_program;
-                   argv[i++] = tmpname;
-                   argv[i] = 0;
-
                    execvp (editor_program, (char **) argv);
                    _exit (errno == ENOENT ? 127 : 126);
                  }
diff --git a/src/util.c b/src/util.c
index 2b0bbbf..38b33ef 100644
--- a/src/util.c
+++ b/src/util.c
@@ -21,7 +21,7 @@
 #include "diff.h"
 #include <dirname.h>
 #include <error.h>
-#include <sh-quote.h>
+#include <system-quote.h>
 #include <xalloc.h>
 
 char const pr_program[] = PR_PROGRAM;
@@ -187,9 +187,16 @@ begin_output (void)
 
   if (paginate)
     {
+      char const *argv[4];
+
       if (fflush (stdout) != 0)
        pfatal_with_name (_("write failed"));
 
+      argv[0] = pr_program;
+      argv[1] = "-h";
+      argv[2] = name;
+      argv[3] = 0;
+
       /* Make OUTFILE a pipe to a subsidiary 'pr'.  */
       {
 #if HAVE_WORKING_FORK
@@ -212,7 +219,7 @@ begin_output (void)
                close (pipes[0]);
              }
 
-           execl (pr_program, pr_program, "-h", name, (char *) 0);
+           execv (pr_program, (char **) argv);
            _exit (errno == ENOENT ? 127 : 126);
          }
        else
@@ -223,13 +230,7 @@ begin_output (void)
              pfatal_with_name ("fdopen");
          }
 #else
-       char *command = xmalloc (sizeof pr_program - 1 + 7
-                                + shell_quote_length (name) + 1);
-       char *p;
-       sprintf (command, "%s -f -h ", pr_program);
-       p = command + sizeof pr_program - 1 + 7;
-       p = shell_quote_copy (p, name);
-       *p = 0;
+       char *command = system_quote_argv (SCI_SYSTEM, (char **) argv);
        errno = 0;
        outfile = popen (command, "w");
        if (!outfile)
-- 
1.7.6.5




reply via email to

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