]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Use quotearg.
authorBruno Haible <bruno@clisp.org>
Sat, 7 Feb 2004 18:03:46 +0000 (18:03 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:48 +0000 (12:11 +0200)
gettext-tools/ChangeLog
gettext-tools/configure.ac
gettext-tools/lib/Makefile.am
gettext-tools/lib/Makefile.msvc
gettext-tools/lib/Makefile.vms
gettext-tools/lib/sh-quote.c
gettext-tools/lib/sh-quote.h
gettext-tools/lib/xalloc.h

index 232ee7f00ed0505475520eb8ef0b125ee06749ed..63317205ffc790fa35ce67607a2c2243855ece84 100644 (file)
@@ -1,3 +1,7 @@
+2004-02-07  Bruno Haible  <bruno@clisp.org>
+
+       * configure.ac: Invoke gl_QUOTEARG.
+
 2004-01-29  Bruno Haible  <bruno@clisp.org>
 
        * gettext-0.14.1 released.
index 6bbebf43652d3a7dec4fc07b5bb7ed71a1239141..cc57e1906bd383dfa41cb4bb27865dab5a218a20 100644 (file)
@@ -1,5 +1,5 @@
 dnl Configuration for the gettext-tools directory of GNU gettext
-dnl Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc.
+dnl Copyright (C) 1995-1999, 2000-2004 Free Software Foundation, Inc.
 dnl
 dnl This program is free software; you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
@@ -141,6 +141,7 @@ gt_FUNC_SETENV
 gl_FUNC_STRERROR
 jm_FUNC_GLIBC_UNLOCKED_IO
 gt_FUNC_ERROR_AT_LINE
+gl_QUOTEARG
 gl_PATHMAX
 gl_FUNC_READLINK
 gl_XREADLINK
index 5f31e39d420bd92f17b2239743867bb583b810ed..128b970116ff7797a1745bf34f0e2199310248a5 100644 (file)
@@ -1,5 +1,5 @@
 ## Makefile for the gettext-tools/lib subdirectory of GNU gettext
-## Copyright (C) 1995-1998, 2000-2003 Free Software Foundation, Inc.
+## Copyright (C) 1995-1998, 2000-2004 Free Software Foundation, Inc.
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -64,6 +64,7 @@ libgettextlib_la_SOURCES = \
   pathname.h concatpath.c \
   pipe.h pipe.c w32spawn.h \
   progname.h progname.c progreloc.c \
+  quotearg.h quotearg.c \
   safe-read.h safe-read.c \
   safe-write.h safe-write.c \
   sh-quote.h sh-quote.c \
index 88387f77799ecf01c68af1347694f1c1cb8a491d..17af0dd370e1fec5758c6fb5bad5d14f26ff3fa0 100644 (file)
@@ -109,6 +109,7 @@ OBJECTS = \
   concatpath.obj \
   pipe.obj \
   progname.obj progreloc.obj \
+  quotearg.obj \
   safe-read.obj \
   safe-write.obj \
   sh-quote.obj \
@@ -231,6 +232,9 @@ progname.obj : progname.c
 progreloc.obj : progreloc.c
        $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c progreloc.c
 
+quotearg.obj : quotearg.c
+       $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c quotearg.c
+
 safe-read.obj : safe-read.c
        $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c safe-read.c
 
index 4390f69158100a6d63c24263e4def847ab3db944..04b7891221066b2728e215ed20502c2d953df964 100644 (file)
@@ -67,6 +67,7 @@ OBJECTS = \
   concatpath.obj, \
   pipe.obj, \
   progname.obj, progreloc.obj, \
+  quotearg.obj, \
   safe-read.obj, \
   safe-write.obj, \
   sh-quote.obj, \
@@ -192,6 +193,9 @@ progname.obj : progname.c
 progreloc.obj : progreloc.c
        $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) progreloc.c
 
+quotearg.obj : quotearg.c
+       $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) quotearg.c
+
 safe-read.obj : safe-read.c
        $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) safe-read.c
 
index b723c30bf11f8b91089b421c1ad76995a179d484..a549c46ef6b740ee113ac1e2afd46d6e6f082a8b 100644 (file)
@@ -1,5 +1,5 @@
 /* Shell quoting.
-   Copyright (C) 2001-2003 Free Software Foundation, Inc.
+   Copyright (C) 2001-2004 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software; you can redistribute it and/or modify
 
 #include <string.h>
 
-#include "strpbrk.h"
+#include "quotearg.h"
 #include "xalloc.h"
 
+/* Describes quoting for sh compatible shells.  */
+static struct quoting_options *sh_quoting_options;
 
-/* Must quote the program name and arguments since Unix shells interpret
-   characters like " ", "'", "<", ">", "$" etc. in a special way.  This
-   kind of quoting should work unless the string contains "\n" and we call
-   csh.  But we are lucky: only /bin/sh will be used.  */
-
-#define SHELL_SPECIAL_CHARS "\t\n !\"#$&'()*;<=>?[\\]`{|}~"
+/* Initializes the sh_quoting_options variable.  */
+static void
+init_sh_quoting_options ()
+{
+  sh_quoting_options = clone_quoting_options (NULL);
+  set_quoting_style (sh_quoting_options, shell_quoting_style);
+}
 
 /* Returns the number of bytes needed for the quoted string.  */
 size_t
 shell_quote_length (const char *string)
 {
-  if (string[0] == '\0')
-    return 2;
-  else if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL)
-    return strlen (string);
-  else
-    {
-      char qchar = '\0';       /* last quote character: none or ' or " */
-      size_t length = 0;
-
-      for (; *string != '\0'; string++)
-       {
-         char c = *string;
-         char q = (c == '\'' ? '"' : '\'');
-
-         if (qchar != q)
-           {
-             if (qchar)
-               length++;
-             qchar = q;
-             length++;
-           }
-         length++;
-       }
-      if (qchar)
-       length++;
-
-      return length;
-    }
+  if (sh_quoting_options == NULL)
+    init_sh_quoting_options ();
+  return quotearg_buffer (NULL, 0, string, strlen (string),
+                          sh_quoting_options);
 }
 
-/* Copies the quoted string to p and returns the incremented p.  */
+/* Copies the quoted string to p and returns the incremented p.
+   There must be room for shell_quote_length (string) + 1 bytes at p.  */
 char *
 shell_quote_copy (char *p, const char *string)
 {
-  if (string[0] == '\0')
-    {
-      memcpy (p, "''", 2);
-      return p + 2;
-    }
-  else if (strpbrk (string, SHELL_SPECIAL_CHARS) == NULL)
-    {
-      memcpy (p, string, strlen (string));
-      return p + strlen (string);
-    }
-  else
-    {
-      char qchar = '\0';       /* last quote character: none or ' or " */
-
-      for (; *string != '\0'; string++)
-       {
-         char c = *string;
-         char q = (c == '\'' ? '"' : '\'');
-
-         if (qchar != q)
-           {
-             if (qchar)
-               *p++ = qchar;
-             qchar = q;
-             *p++ = qchar;
-           }
-         *p++ = c;
-       }
-      if (qchar)
-       *p++ = qchar;
-
-      return p;
-    }
+  if (sh_quoting_options == NULL)
+    init_sh_quoting_options ();
+  return p + quotearg_buffer (p, (size_t)(-1), string, strlen (string),
+                             sh_quoting_options);
 }
 
 /* Returns the freshly allocated quoted string.  */
 char *
 shell_quote (const char *string)
 {
-  size_t length = shell_quote_length (string);
-  char *quoted = (char *) xmalloc (length + 1);
-  char *p = shell_quote_copy (quoted, string);
-  *p = '\0';
-  return quoted;
+  if (sh_quoting_options == NULL)
+    init_sh_quoting_options ();
+  return quotearg_alloc (string, strlen (string), sh_quoting_options);
 }
 
 /* Returns a freshly allocated string containing all argument strings, quoted,
index 76a5831039ea8ee9f16ece9ee2d1382f69329249..06895e619b35c7f17a6783eb45fe2326418b02fc 100644 (file)
@@ -1,5 +1,5 @@
 /* Shell quoting.
-   Copyright (C) 2001-2002 Free Software Foundation, Inc.
+   Copyright (C) 2001-2002, 2004 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software; you can redistribute it and/or modify
@@ -25,7 +25,8 @@
 /* Returns the number of bytes needed for the quoted string.  */
 extern size_t shell_quote_length (const char *string);
 
-/* Copies the quoted string to p and returns the incremented p.  */
+/* Copies the quoted string to p and returns the incremented p.
+   There must be room for shell_quote_length (string) + 1 bytes at p.  */
 extern char * shell_quote_copy (char *p, const char *string);
 
 /* Returns the freshly allocated quoted string.  */
index 0e7ea8487c4a2d805299f10d27bd3e1cdae3fb49..5a00f364ae34dffd130720fe00d1e54d9751a7d0 100644 (file)
@@ -1,5 +1,5 @@
 /* malloc with out of memory checking.
-   Copyright (C) 2001-2003 Free Software Foundation, Inc.
+   Copyright (C) 2001-2004 Free Software Foundation, Inc.
    Written by Bruno Haible <haible@clisp.cons.org>, 2001.
 
    This program is free software; you can redistribute it and/or modify
@@ -56,6 +56,22 @@ extern void xalloc_die (void)
 extern char *xstrdup (const char *string);
 
 
+/* Return 1 if an array of N objects, each of size S, cannot exist due
+   to size arithmetic overflow.  S must be positive and N must be
+   nonnegative.  This is a macro, not an inline function, so that it
+   works correctly even when SIZE_MAX < N.
+
+   By gnulib convention, SIZE_MAX represents overflow in size
+   calculations, so the conservative dividend to use here is
+   SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
+   However, malloc (SIZE_MAX) fails on all known hosts where
+   sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
+   exactly-SIZE_MAX allocations on such hosts; this avoids a test and
+   branch when S is known to be 1.  */
+# define xalloc_oversized(n, s) \
+    ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
+
+
 #ifdef __cplusplus
 }
 #endif