+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.
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
gl_FUNC_STRERROR
jm_FUNC_GLIBC_UNLOCKED_IO
gt_FUNC_ERROR_AT_LINE
+gl_QUOTEARG
gl_PATHMAX
gl_FUNC_READLINK
gl_XREADLINK
## 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
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 \
concatpath.obj \
pipe.obj \
progname.obj progreloc.obj \
+ quotearg.obj \
safe-read.obj \
safe-write.obj \
sh-quote.obj \
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
concatpath.obj, \
pipe.obj, \
progname.obj, progreloc.obj, \
+ quotearg.obj, \
safe-read.obj, \
safe-write.obj, \
sh-quote.obj, \
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
/* 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,
/* 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
/* 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. */
/* 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
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