Sync with gnulib.

This commit is contained in:
Paul Eggert
2002-11-23 07:25:41 +00:00
parent 69e16b4c5e
commit f6cf0f6e5f
5 changed files with 62 additions and 118 deletions

View File

@@ -1,5 +1,5 @@
/* Determine the number of screen columns needed for a string. /* Determine the number of screen columns needed for a string.
Copyright (C) 2000-2001 Free Software Foundation, Inc. Copyright (C) 2000-2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@@ -87,9 +87,7 @@ int wcwidth ();
With flags = MBSW_REJECT_INVALID | MBSW_REJECT_UNPRINTABLE, this is With flags = MBSW_REJECT_INVALID | MBSW_REJECT_UNPRINTABLE, this is
the multibyte analogon of the wcswidth function. */ the multibyte analogon of the wcswidth function. */
int int
mbswidth (string, flags) mbswidth (const char *string, int flags)
const char *string;
int flags;
{ {
return mbsnwidth (string, strlen (string), flags); return mbsnwidth (string, strlen (string), flags);
} }
@@ -99,10 +97,7 @@ mbswidth (string, flags)
non-printable character occurs, and MBSW_REJECT_UNPRINTABLE is non-printable character occurs, and MBSW_REJECT_UNPRINTABLE is
specified, -1 is returned. */ specified, -1 is returned. */
int int
mbsnwidth (string, nbytes, flags) mbsnwidth (const char *string, size_t nbytes, int flags)
const char *string;
size_t nbytes;
int flags;
{ {
const char *p = string; const char *p = string;
const char *plimit = p + nbytes; const char *plimit = p + nbytes;

View File

@@ -1,5 +1,5 @@
/* Determine the number of screen columns needed for a string. /* Determine the number of screen columns needed for a string.
Copyright (C) 2000-2001 Free Software Foundation, Inc. Copyright (C) 2000-2002 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@@ -17,14 +17,6 @@
#include <stddef.h> #include <stddef.h>
#ifndef PARAMS
# if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
# define PARAMS(Args) Args
# else
# define PARAMS(Args) ()
# endif
#endif
/* Optional flags to influence mbswidth/mbsnwidth behavior. */ /* Optional flags to influence mbswidth/mbsnwidth behavior. */
/* If this bit is set, return -1 upon finding an invalid or incomplete /* If this bit is set, return -1 upon finding an invalid or incomplete
@@ -38,8 +30,8 @@
/* Returns the number of screen columns needed for STRING. */ /* Returns the number of screen columns needed for STRING. */
#define mbswidth gnu_mbswidth /* avoid clash with UnixWare 7.1.1 function */ #define mbswidth gnu_mbswidth /* avoid clash with UnixWare 7.1.1 function */
extern int mbswidth PARAMS ((const char *string, int flags)); extern int mbswidth (const char *string, int flags);
/* Returns the number of screen columns needed for the NBYTES bytes /* Returns the number of screen columns needed for the NBYTES bytes
starting at BUF. */ starting at BUF. */
extern int mbsnwidth PARAMS ((const char *buf, size_t nbytes, int flags)); extern int mbsnwidth (const char *buf, size_t nbytes, int flags);

View File

@@ -21,52 +21,19 @@
# include <config.h> # include <config.h>
#endif #endif
#if HAVE_STDDEF_H
# include <stddef.h> /* For the definition of size_t on windows w/MSVC. */
#endif
#include <sys/types.h>
#include "quotearg.h" #include "quotearg.h"
#include "xalloc.h" #include "xalloc.h"
#include <ctype.h> #include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#if ENABLE_NLS #include "gettext.h"
# include <libintl.h> #define _(msgid) gettext (msgid)
# define _(text) gettext (text) #define N_(msgid) msgid
#else
# define _(text) text
#endif
#define N_(text) text
#if HAVE_LIMITS_H
# include <limits.h>
#endif
#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
#ifndef UCHAR_MAX
# define UCHAR_MAX ((unsigned char) -1)
#endif
#ifndef UINT_MAX
# define UINT_MAX ((unsigned int) -1)
#endif
#if HAVE_C_BACKSLASH_A
# define ALERT_CHAR '\a'
#else
# define ALERT_CHAR '\7'
#endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if HAVE_STRING_H
# include <string.h>
#endif
#if HAVE_WCHAR_H #if HAVE_WCHAR_H
@@ -84,7 +51,7 @@
# undef MB_CUR_MAX # undef MB_CUR_MAX
# define MB_CUR_MAX 1 # define MB_CUR_MAX 1
# define mbrtowc(pwc, s, n, ps) ((*(pwc) = *(s)) != 0) # define mbrtowc(pwc, s, n, ps) ((*(pwc) = *(s)) != 0)
# define iswprint(wc) ISPRINT ((unsigned char) (wc)) # define iswprint(wc) isprint ((unsigned char) (wc))
# undef HAVE_MBSINIT # undef HAVE_MBSINIT
#endif #endif
@@ -101,17 +68,11 @@
# endif # endif
#endif #endif
#define INT_BITS (sizeof (int) * CHAR_BIT) #ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
# define IN_CTYPE_DOMAIN(c) 1
#else
# define IN_CTYPE_DOMAIN(c) isascii(c)
#endif #endif
/* Undefine to protect against the definition in wctype.h of solaris2.6. */ #define INT_BITS (sizeof (int) * CHAR_BIT)
#undef ISPRINT
#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
struct quoting_options struct quoting_options
{ {
@@ -157,9 +118,10 @@ static struct quoting_options default_quoting_options;
struct quoting_options * struct quoting_options *
clone_quoting_options (struct quoting_options *o) clone_quoting_options (struct quoting_options *o)
{ {
struct quoting_options *p int e = errno;
= (struct quoting_options *) xmalloc (sizeof (struct quoting_options)); struct quoting_options *p = xmalloc (sizeof *p);
*p = *(o ? o : &default_quoting_options); *p = *(o ? o : &default_quoting_options);
errno = e;
return p; return p;
} }
@@ -291,7 +253,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
break; break;
} }
for (i = 0; ! (argsize == (size_t) -1 ? arg[i] == '\0' : i == argsize); i++) for (i = 0; ! (argsize == SIZE_MAX ? arg[i] == '\0' : i == argsize); i++)
{ {
unsigned char c; unsigned char c;
unsigned char esc; unsigned char esc;
@@ -344,7 +306,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
} }
break; break;
case ALERT_CHAR: esc = 'a'; goto c_escape; case '\a': esc = 'a'; goto c_escape;
case '\b': esc = 'b'; goto c_escape; case '\b': esc = 'b'; goto c_escape;
case '\f': esc = 'f'; goto c_escape; case '\f': esc = 'f'; goto c_escape;
case '\n': esc = 'n'; goto c_and_shell_escape; case '\n': esc = 'n'; goto c_and_shell_escape;
@@ -432,7 +394,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
if (unibyte_locale) if (unibyte_locale)
{ {
m = 1; m = 1;
printable = ISPRINT (c); printable = isprint (c);
} }
else else
{ {
@@ -441,7 +403,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize,
m = 0; m = 0;
printable = 1; printable = 1;
if (argsize == (size_t) -1) if (argsize == SIZE_MAX)
argsize = strlen (arg); argsize = strlen (arg);
do do
@@ -537,8 +499,11 @@ quotearg_buffer (char *buffer, size_t buffersize,
struct quoting_options const *o) struct quoting_options const *o)
{ {
struct quoting_options const *p = o ? o : &default_quoting_options; struct quoting_options const *p = o ? o : &default_quoting_options;
return quotearg_buffer_restyled (buffer, buffersize, arg, argsize, int e = errno;
p->style, p); size_t r = quotearg_buffer_restyled (buffer, buffersize, arg, argsize,
p->style, p);
errno = e;
return r;
} }
/* Use storage slot N to return a quoted version of argument ARG. /* Use storage slot N to return a quoted version of argument ARG.
@@ -552,6 +517,8 @@ static char *
quotearg_n_options (int n, char const *arg, size_t argsize, quotearg_n_options (int n, char const *arg, size_t argsize,
struct quoting_options const *options) struct quoting_options const *options)
{ {
int e = errno;
/* Preallocate a slot 0 buffer, so that the caller can always quote /* Preallocate a slot 0 buffer, so that the caller can always quote
one small component of a "memory exhausted" message in slot 0. */ one small component of a "memory exhausted" message in slot 0. */
static char slot0[256]; static char slot0[256];
@@ -579,10 +546,10 @@ quotearg_n_options (int n, char const *arg, size_t argsize,
if (slotvec == &slotvec0) if (slotvec == &slotvec0)
{ {
slotvec = (struct slotvec *) xmalloc (sizeof *slotvec); slotvec = xmalloc (sizeof *slotvec);
*slotvec = slotvec0; *slotvec = slotvec0;
} }
slotvec = (struct slotvec *) xrealloc (slotvec, s); slotvec = xrealloc (slotvec, s);
memset (slotvec + nslots, 0, (n1 - nslots) * sizeof *slotvec); memset (slotvec + nslots, 0, (n1 - nslots) * sizeof *slotvec);
nslots = n1; nslots = n1;
} }
@@ -599,6 +566,7 @@ quotearg_n_options (int n, char const *arg, size_t argsize,
quotearg_buffer (val, size, arg, argsize, options); quotearg_buffer (val, size, arg, argsize, options);
} }
errno = e;
return val; return val;
} }
} }
@@ -606,7 +574,7 @@ quotearg_n_options (int n, char const *arg, size_t argsize,
char * char *
quotearg_n (int n, char const *arg) quotearg_n (int n, char const *arg)
{ {
return quotearg_n_options (n, arg, (size_t) -1, &default_quoting_options); return quotearg_n_options (n, arg, SIZE_MAX, &default_quoting_options);
} }
char * char *
@@ -629,7 +597,7 @@ char *
quotearg_n_style (int n, enum quoting_style s, char const *arg) quotearg_n_style (int n, enum quoting_style s, char const *arg)
{ {
struct quoting_options const o = quoting_options_from_style (s); struct quoting_options const o = quoting_options_from_style (s);
return quotearg_n_options (n, arg, (size_t) -1, &o); return quotearg_n_options (n, arg, SIZE_MAX, &o);
} }
char * char *
@@ -652,7 +620,7 @@ quotearg_char (char const *arg, char ch)
struct quoting_options options; struct quoting_options options;
options = default_quoting_options; options = default_quoting_options;
set_char_quoting (&options, ch, 1); set_char_quoting (&options, ch, 1);
return quotearg_n_options (0, arg, (size_t) -1, &options); return quotearg_n_options (0, arg, SIZE_MAX, &options);
} }
char * char *

View File

@@ -22,6 +22,8 @@
#ifndef QUOTEARG_H_ #ifndef QUOTEARG_H_
# define QUOTEARG_H_ 1 # define QUOTEARG_H_ 1
# include <stddef.h>
/* Basic quoting styles. */ /* Basic quoting styles. */
enum quoting_style enum quoting_style
{ {
@@ -45,37 +47,27 @@ extern enum quoting_style const quoting_style_vals[];
struct quoting_options; struct quoting_options;
# ifndef PARAMS
# if defined PROTOTYPES || defined __STDC__
# define PARAMS(Args) Args
# else
# define PARAMS(Args) ()
# endif
# endif
/* The functions listed below set and use a hidden variable /* The functions listed below set and use a hidden variable
that contains the default quoting style options. */ that contains the default quoting style options. */
/* Allocate a new set of quoting options, with contents initially identical /* Allocate a new set of quoting options, with contents initially identical
to O if O is not null, or to the default if O is null. to O if O is not null, or to the default if O is null.
It is the caller's responsibility to free the result. */ It is the caller's responsibility to free the result. */
struct quoting_options *clone_quoting_options struct quoting_options *clone_quoting_options (struct quoting_options *o);
PARAMS ((struct quoting_options *o));
/* Get the value of O's quoting style. If O is null, use the default. */ /* Get the value of O's quoting style. If O is null, use the default. */
enum quoting_style get_quoting_style PARAMS ((struct quoting_options *o)); enum quoting_style get_quoting_style (struct quoting_options *o);
/* In O (or in the default if O is null), /* In O (or in the default if O is null),
set the value of the quoting style to S. */ set the value of the quoting style to S. */
void set_quoting_style PARAMS ((struct quoting_options *o, void set_quoting_style (struct quoting_options *o, enum quoting_style s);
enum quoting_style s));
/* In O (or in the default if O is null), /* In O (or in the default if O is null),
set the value of the quoting options for character C to I. set the value of the quoting options for character C to I.
Return the old value. Currently, the only values defined for I are Return the old value. Currently, the only values defined for I are
0 (the default) and 1 (which means to quote the character even if 0 (the default) and 1 (which means to quote the character even if
it would not otherwise be quoted). */ it would not otherwise be quoted). */
int set_char_quoting PARAMS ((struct quoting_options *o, char c, int i)); int set_char_quoting (struct quoting_options *o, char c, int i);
/* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of /* Place into buffer BUFFER (of size BUFFERSIZE) a quoted version of
argument ARG (of size ARGSIZE), using O to control quoting. argument ARG (of size ARGSIZE), using O to control quoting.
@@ -85,38 +77,38 @@ int set_char_quoting PARAMS ((struct quoting_options *o, char c, int i));
If BUFFERSIZE is too small to store the output string, return the If BUFFERSIZE is too small to store the output string, return the
value that would have been returned had BUFFERSIZE been large enough. value that would have been returned had BUFFERSIZE been large enough.
If ARGSIZE is -1, use the string length of the argument for ARGSIZE. */ If ARGSIZE is -1, use the string length of the argument for ARGSIZE. */
size_t quotearg_buffer PARAMS ((char *buffer, size_t buffersize, size_t quotearg_buffer (char *buffer, size_t buffersize,
char const *arg, size_t argsize, char const *arg, size_t argsize,
struct quoting_options const *o)); struct quoting_options const *o);
/* Use storage slot N to return a quoted version of the string ARG. /* Use storage slot N to return a quoted version of the string ARG.
Use the default quoting options. Use the default quoting options.
The returned value points to static storage that can be The returned value points to static storage that can be
reused by the next call to this function with the same value of N. reused by the next call to this function with the same value of N.
N must be nonnegative. */ N must be nonnegative. */
char *quotearg_n PARAMS ((int n, char const *arg)); char *quotearg_n (int n, char const *arg);
/* Equivalent to quotearg_n (0, ARG). */ /* Equivalent to quotearg_n (0, ARG). */
char *quotearg PARAMS ((char const *arg)); char *quotearg (char const *arg);
/* Use style S and storage slot N to return a quoted version of the string ARG. /* Use style S and storage slot N to return a quoted version of the string ARG.
This is like quotearg_n (N, ARG), except that it uses S with no other This is like quotearg_n (N, ARG), except that it uses S with no other
options to specify the quoting method. */ options to specify the quoting method. */
char *quotearg_n_style PARAMS ((int n, enum quoting_style s, char const *arg)); char *quotearg_n_style (int n, enum quoting_style s, char const *arg);
/* Use style S and storage slot N to return a quoted version of the /* Use style S and storage slot N to return a quoted version of the
argument ARG of size ARGSIZE. This is like quotearg_n_style argument ARG of size ARGSIZE. This is like quotearg_n_style
(N, S, ARG), except it can quote null bytes. */ (N, S, ARG), except it can quote null bytes. */
char *quotearg_n_style_mem PARAMS ((int n, enum quoting_style s, char *quotearg_n_style_mem (int n, enum quoting_style s,
char const *arg, size_t argsize)); char const *arg, size_t argsize);
/* Equivalent to quotearg_n_style (0, S, ARG). */ /* Equivalent to quotearg_n_style (0, S, ARG). */
char *quotearg_style PARAMS ((enum quoting_style s, char const *arg)); char *quotearg_style (enum quoting_style s, char const *arg);
/* Like quotearg (ARG), except also quote any instances of CH. */ /* Like quotearg (ARG), except also quote any instances of CH. */
char *quotearg_char PARAMS ((char const *arg, char ch)); char *quotearg_char (char const *arg, char ch);
/* Equivalent to quotearg_char (ARG, ':'). */ /* Equivalent to quotearg_char (ARG, ':'). */
char *quotearg_colon PARAMS ((char const *arg)); char *quotearg_colon (char const *arg);
#endif /* !QUOTEARG_H_ */ #endif /* !QUOTEARG_H_ */

View File

@@ -30,14 +30,9 @@ void *realloc ();
void free (); void free ();
#endif #endif
#if ENABLE_NLS #include "gettext.h"
# include <libintl.h> #define _(msgid) gettext (msgid)
# define _(Text) gettext (Text) #define N_(msgid) msgid
#else
# define textdomain(Domain)
# define _(Text) Text
#endif
#define N_(Text) Text
#include "error.h" #include "error.h"
#include "xalloc.h" #include "xalloc.h"
@@ -46,12 +41,14 @@ void free ();
# define EXIT_FAILURE 1 # define EXIT_FAILURE 1
#endif #endif
/* The following tests require AC_PREREQ(2.54). */
#ifndef HAVE_MALLOC #ifndef HAVE_MALLOC
"you must run the autoconf test for a properly working malloc" "you must run the autoconf test for a GNU libc compatible malloc"
#endif #endif
#ifndef HAVE_REALLOC #ifndef HAVE_REALLOC
"you must run the autoconf test for a properly working realloc" "you must run the autoconf test for a GNU libc compatible realloc"
#endif #endif
/* Exit value when the requested amount of memory is not available. /* Exit value when the requested amount of memory is not available.