diff options
| author | Tim J. Robbins <tjr@FreeBSD.org> | 2004-08-12 05:37:46 +0000 |
|---|---|---|
| committer | Tim J. Robbins <tjr@FreeBSD.org> | 2004-08-12 05:37:46 +0000 |
| commit | 9da8305ad3af4a0ea6ad4baa57338649cde515fb (patch) | |
| tree | 620b3c07b0df596abf6d4b574472fb8ac785ecfa /contrib/gnu-sort/lib | |
| parent | 90a99868445f36779d2e9038c6d4d9cf457deafd (diff) | |
Notes
Diffstat (limited to 'contrib/gnu-sort/lib')
23 files changed, 451 insertions, 180 deletions
diff --git a/contrib/gnu-sort/lib/argmatch.c b/contrib/gnu-sort/lib/argmatch.c index 210689ba3f5f..1a8ec2f54ba4 100644 --- a/contrib/gnu-sort/lib/argmatch.c +++ b/contrib/gnu-sort/lib/argmatch.c @@ -27,6 +27,7 @@ /* Specification. */ #include "argmatch.h" +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -79,14 +80,14 @@ argmatch_exit_fn argmatch_die = __argmatch_die; "no", "nope" -> 1 "y" is a valid argument, for `0', and "n" for `1'. */ -int +ptrdiff_t argmatch (const char *arg, const char *const *arglist, const char *vallist, size_t valsize) { - int i; /* Temporary index in ARGLIST. */ + size_t i; /* Temporary index in ARGLIST. */ size_t arglen; /* Length of ARG. */ - int matchind = -1; /* Index of first nonexact match. */ - int ambiguous = 0; /* If nonzero, multiple nonexact match(es). */ + ptrdiff_t matchind = -1; /* Index of first nonexact match. */ + bool ambiguous = false; /* If true, multiple nonexact match(es). */ arglen = strlen (arg); @@ -110,7 +111,7 @@ argmatch (const char *arg, const char *const *arglist, { /* There is a real ambiguity, or we could not disambiguate. */ - ambiguous = 1; + ambiguous = true; } } } @@ -127,7 +128,7 @@ argmatch (const char *arg, const char *const *arglist, PROBLEM is the return value from argmatch. */ void -argmatch_invalid (const char *context, const char *value, int problem) +argmatch_invalid (const char *context, const char *value, ptrdiff_t problem) { char const *format = (problem == -1 ? _("invalid argument %s for %s") @@ -145,7 +146,7 @@ void argmatch_valid (const char *const *arglist, const char *vallist, size_t valsize) { - int i; + size_t i; const char *last_val = NULL; /* We try to put synonyms on the same line. The assumption is that @@ -171,13 +172,13 @@ argmatch_valid (const char *const *arglist, "--version-control", or "$VERSION_CONTROL" etc.). Upon failure, calls the (supposed never to return) function EXIT_FN. */ -int +ptrdiff_t __xargmatch_internal (const char *context, const char *arg, const char *const *arglist, const char *vallist, size_t valsize, argmatch_exit_fn exit_fn) { - int res = argmatch (arg, arglist, vallist, valsize); + ptrdiff_t res = argmatch (arg, arglist, vallist, valsize); if (res >= 0) /* Success. */ return res; @@ -197,7 +198,7 @@ argmatch_to_argument (const char *value, const char *const *arglist, const char *vallist, size_t valsize) { - int i; + size_t i; for (i = 0; arglist[i]; i++) if (!memcmp (value, vallist + valsize * i, valsize)) diff --git a/contrib/gnu-sort/lib/argmatch.h b/contrib/gnu-sort/lib/argmatch.h index e8bb23c667ba..8952394fdac7 100644 --- a/contrib/gnu-sort/lib/argmatch.h +++ b/contrib/gnu-sort/lib/argmatch.h @@ -49,8 +49,8 @@ false ambiguities (i.e., different matches of ARG but corresponding to the same values in VALLIST). */ -int argmatch (char const *arg, char const *const *arglist, - char const *vallist, size_t valsize); +ptrdiff_t argmatch (char const *arg, char const *const *arglist, + char const *vallist, size_t valsize); # define ARGMATCH(Arg, Arglist, Vallist) \ argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist)) @@ -63,7 +63,8 @@ extern argmatch_exit_fn argmatch_die; /* Report on stderr why argmatch failed. Report correct values. */ -void argmatch_invalid (char const *context, char const *value, int problem); +void argmatch_invalid (char const *context, char const *value, + ptrdiff_t problem); /* Left for compatibility with the old name invalid_arg */ @@ -85,10 +86,10 @@ void argmatch_valid (char const *const *arglist, /* Same as argmatch, but upon failure, reports a explanation on the failure, and exits using the function EXIT_FN. */ -int __xargmatch_internal (char const *context, - char const *arg, char const *const *arglist, - char const *vallist, size_t valsize, - argmatch_exit_fn exit_fn); +ptrdiff_t __xargmatch_internal (char const *context, + char const *arg, char const *const *arglist, + char const *vallist, size_t valsize, + argmatch_exit_fn exit_fn); /* Programmer friendly interface to __xargmatch_internal. */ diff --git a/contrib/gnu-sort/lib/closeout.c b/contrib/gnu-sort/lib/closeout.c index a551d1ae8be6..3c7bed9c3d55 100644 --- a/contrib/gnu-sort/lib/closeout.c +++ b/contrib/gnu-sort/lib/closeout.c @@ -1,5 +1,7 @@ /* closeout.c - close standard output - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + + Copyright (C) 1998, 1999, 2000, 2001, 2002, 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 @@ -22,11 +24,7 @@ #include "closeout.h" #include <stdio.h> - #include <errno.h> -#ifndef errno -extern int errno; -#endif #include "gettext.h" #define _(msgid) gettext (msgid) diff --git a/contrib/gnu-sort/lib/closeout.h b/contrib/gnu-sort/lib/closeout.h index d27d7601eb7b..1b715ee30369 100644 --- a/contrib/gnu-sort/lib/closeout.h +++ b/contrib/gnu-sort/lib/closeout.h @@ -1,6 +1,6 @@ /* Close standard output. - Copyright (C) 1998, 2000, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 2000, 2003, 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 @@ -19,7 +19,15 @@ #ifndef CLOSEOUT_H # define CLOSEOUT_H 1 +# ifdef __cplusplus +extern "C" { +# endif + void close_stdout_set_file_name (const char *file); void close_stdout (void); +# ifdef __cplusplus +} +# endif + #endif diff --git a/contrib/gnu-sort/lib/dup-safer.c b/contrib/gnu-sort/lib/dup-safer.c index f72fd845f397..408a1bda7602 100644 --- a/contrib/gnu-sort/lib/dup-safer.c +++ b/contrib/gnu-sort/lib/dup-safer.c @@ -1,5 +1,5 @@ /* Invoke dup, but avoid some glitches. - Copyright (C) 2001 Free Software Foundation, Inc. + Copyright (C) 2001, 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 @@ -22,9 +22,6 @@ #endif #include <errno.h> -#ifndef errno -extern int errno; -#endif #if HAVE_FCNTL_H # include <fcntl.h> diff --git a/contrib/gnu-sort/lib/error.c b/contrib/gnu-sort/lib/error.c index 1149235a101e..5a5e126b0dfb 100644 --- a/contrib/gnu-sort/lib/error.c +++ b/contrib/gnu-sort/lib/error.c @@ -1,5 +1,5 @@ /* Error handler for noninteractive utilities - Copyright (C) 1990-1998, 2000-2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1990-1998, 2000-2002, 2003, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. This program is free software; you can redistribute it and/or modify @@ -106,7 +106,7 @@ extern char *program_name; static void print_errno_message (int errnum) { - char const *s; + char const *s = NULL; #if defined HAVE_STRERROR_R || _LIBC char errbuf[1024]; @@ -115,15 +115,11 @@ print_errno_message (int errnum) # else if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0) s = errbuf; - else - s = 0; # endif -#else - s = strerror (errnum); #endif #if !_LIBC - if (! s) + if (! s && ! (s = strerror (errnum))) s = _("Unknown system error"); #endif diff --git a/contrib/gnu-sort/lib/fopen-safer.c b/contrib/gnu-sort/lib/fopen-safer.c index 6825f9b9f21b..c5c97c8a19ab 100644 --- a/contrib/gnu-sort/lib/fopen-safer.c +++ b/contrib/gnu-sort/lib/fopen-safer.c @@ -1,5 +1,5 @@ /* Invoke fopen, but avoid some glitches. - Copyright (C) 2001 Free Software Foundation, Inc. + Copyright (C) 2001, 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 @@ -31,10 +31,6 @@ #endif #include <errno.h> -#ifndef errno -extern int errno; -#endif - #include <stdio.h> #include <stdio-safer.h> diff --git a/contrib/gnu-sort/lib/hard-locale.c b/contrib/gnu-sort/lib/hard-locale.c index 8c0ee8c7778f..67a4144a6fec 100644 --- a/contrib/gnu-sort/lib/hard-locale.c +++ b/contrib/gnu-sort/lib/hard-locale.c @@ -1,6 +1,7 @@ /* hard-locale.c -- Determine whether a locale is hard. - Copyright (C) 1997, 1998, 1999, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 1999, 2002, 2003, 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 @@ -29,23 +30,23 @@ #include <stdlib.h> #include <string.h> -/* Return nonzero if the current CATEGORY locale is hard, i.e. if you +/* Return true if the current CATEGORY locale is hard, i.e. if you can't get away with assuming traditional C or POSIX behavior. */ -int +bool hard_locale (int category) { #if ! HAVE_SETLOCALE - return 0; + return false; #else - int hard = 1; - char const *p = setlocale (category, 0); + bool hard = true; + char const *p = setlocale (category, NULL); if (p) { # if defined __GLIBC__ && 2 <= __GLIBC__ if (strcmp (p, "C") == 0 || strcmp (p, "POSIX") == 0) - hard = 0; + hard = false; # else char *locale = malloc (strlen (p) + 1); if (locale) @@ -59,7 +60,7 @@ hard_locale (int category) && strcmp (p, locale) == 0) || ((p = setlocale (category, "POSIX")) && strcmp (p, locale) == 0)) - hard = 0; + hard = false; /* Restore the caller's locale. */ setlocale (category, locale); diff --git a/contrib/gnu-sort/lib/hard-locale.h b/contrib/gnu-sort/lib/hard-locale.h index ddc15d019dbc..010cb27682b2 100644 --- a/contrib/gnu-sort/lib/hard-locale.h +++ b/contrib/gnu-sort/lib/hard-locale.h @@ -1,6 +1,6 @@ /* Determine whether a locale is hard. - Copyright (C) 1999, 2003 Free Software Foundation, Inc. + Copyright (C) 1999, 2003, 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 @@ -19,6 +19,8 @@ #ifndef HARD_LOCALE_H_ # define HARD_LOCALE_H_ 1 -int hard_locale (int); +# include <stdbool.h> + +bool hard_locale (int); #endif /* HARD_LOCALE_H_ */ diff --git a/contrib/gnu-sort/lib/human.c b/contrib/gnu-sort/lib/human.c index 36cfd7348876..f024c73ea079 100644 --- a/contrib/gnu-sort/lib/human.c +++ b/contrib/gnu-sort/lib/human.c @@ -1,7 +1,7 @@ /* human.c -- print human readable file size - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free - Software Foundation, Inc. + Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 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 @@ -300,8 +300,8 @@ human_readable (uintmax_t n, char *buf, int opts, { do { - unsigned r10 = (amt % base) * 10 + tenths; - unsigned r2 = (r10 % base) * 2 + (rounding >> 1); + unsigned int r10 = (amt % base) * 10 + tenths; + unsigned int r2 = (r10 % base) * 2 + (rounding >> 1); amt /= base; tenths = r10 / base; rounding = (r2 < base @@ -428,7 +428,9 @@ humblock (char const *spec, uintmax_t *block_size, int *options) int i; int opts = 0; - if (! spec && ! (spec = getenv ("BLOCK_SIZE"))) + if (! spec + && ! (spec = getenv ("BLOCK_SIZE")) + && ! (spec = getenv ("BLOCKSIZE"))) *block_size = default_block_size (); else { diff --git a/contrib/gnu-sort/lib/human.h b/contrib/gnu-sort/lib/human.h index 604fec1ba7f7..b67ba4e9ae0c 100644 --- a/contrib/gnu-sort/lib/human.h +++ b/contrib/gnu-sort/lib/human.h @@ -1,7 +1,7 @@ /* human.h -- print human readable file size - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free - Software Foundation, Inc. + Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 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 @@ -29,12 +29,11 @@ # include <limits.h> # include <stdbool.h> -# if HAVE_INTTYPES_H -# include <inttypes.h> -# else -# if HAVE_STDINT_H -# include <stdint.h> -# endif +# if HAVE_STDINT_H +# include <stdint.h> +# endif +# if HAVE_UNISTD_H +# include <unistd.h> # endif /* A conservative bound on the maximum length of a human-readable string. diff --git a/contrib/gnu-sort/lib/inttostr.h b/contrib/gnu-sort/lib/inttostr.h index de2b164f6b1a..6f2416b53faf 100644 --- a/contrib/gnu-sort/lib/inttostr.h +++ b/contrib/gnu-sort/lib/inttostr.h @@ -1,6 +1,6 @@ /* inttostr.h -- convert integers to printable strings - Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 2001, 2002, 2003, 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 @@ -25,14 +25,12 @@ #if HAVE_INTTYPES_H # include <inttypes.h> #endif - -#if HAVE_LIMITS_H -# include <limits.h> -#endif -#ifndef CHAR_BIT -# define CHAR_BIT 8 +#if HAVE_STDINT_H +# include <stdint.h> #endif +#include <limits.h> + #if HAVE_SYS_TYPES_H # include <sys/types.h> #endif diff --git a/contrib/gnu-sort/lib/memcoll.c b/contrib/gnu-sort/lib/memcoll.c index 34ae767dbdbb..e777e6a5bc7f 100644 --- a/contrib/gnu-sort/lib/memcoll.c +++ b/contrib/gnu-sort/lib/memcoll.c @@ -1,5 +1,5 @@ /* Locale-specific memory comparison. - Copyright (C) 1999, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2003, 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 @@ -24,10 +24,6 @@ #include "memcoll.h" #include <errno.h> -#ifndef errno -extern int errno; -#endif - #include <string.h> /* Compare S1 (with length S1LEN) and S2 (with length S2LEN) according diff --git a/contrib/gnu-sort/lib/quotearg.c b/contrib/gnu-sort/lib/quotearg.c index c695646f13ec..64fa67635455 100644 --- a/contrib/gnu-sort/lib/quotearg.c +++ b/contrib/gnu-sort/lib/quotearg.c @@ -1,5 +1,7 @@ /* quotearg.c - quote arguments for output - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. + + Copyright (C) 1998, 1999, 2000, 2001, 2002, 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 @@ -28,6 +30,7 @@ #include <ctype.h> #include <errno.h> #include <limits.h> +#include <stdbool.h> #include <stdlib.h> #include <string.h> @@ -174,7 +177,7 @@ gettext_quote (char const *msgid, enum quoting_style s) size of the output, not counting the terminating null. If BUFFERSIZE is too small to store the output string, return the 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 SIZE_MAX, use the string length of the argument for ARGSIZE. This function acts like quotearg_buffer (BUFFER, BUFFERSIZE, ARG, ARGSIZE, O), except it uses QUOTING_STYLE instead of the quoting @@ -190,8 +193,8 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, size_t len = 0; char const *quote_string = 0; size_t quote_string_len = 0; - int backslash_escapes = 0; - int unibyte_locale = MB_CUR_MAX == 1; + bool backslash_escapes = false; + bool unibyte_locale = MB_CUR_MAX == 1; #define STORE(c) \ do \ @@ -206,13 +209,13 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, { case c_quoting_style: STORE ('"'); - backslash_escapes = 1; + backslash_escapes = true; quote_string = "\""; quote_string_len = 1; break; case escape_quoting_style: - backslash_escapes = 1; + backslash_escapes = true; break; case locale_quoting_style: @@ -237,7 +240,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, char const *right = gettext_quote (N_("'"), quoting_style); for (quote_string = left; *quote_string; quote_string++) STORE (*quote_string); - backslash_escapes = 1; + backslash_escapes = true; quote_string = right; quote_string_len = strlen (quote_string); } @@ -326,6 +329,10 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, } break; + case '{': case '}': /* sometimes special if isolated */ + if (! (argsize == SIZE_MAX ? arg[1] == '\0' : argsize == 1)) + break; + /* Fall through. */ case '#': case '~': if (i != 0) break; @@ -334,7 +341,9 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, case '!': /* special in bash */ case '"': case '$': case '&': case '(': case ')': case '*': case ';': - case '<': case '>': case '[': + case '<': + case '=': /* sometimes special in 0th or (with "set -k") later args */ + case '>': case '[': case '^': /* special in old /bin/sh, e.g. SunOS 4.1.4 */ case '`': case '|': /* A shell special character. In theory, '$' and '`' could @@ -364,7 +373,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, case '%': case '+': case ',': case '-': case '.': case '/': case '0': case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': case ':': case '=': + case '6': case '7': case '8': case '9': case ':': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': @@ -374,7 +383,6 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': - case '{': case '}': /* These characters don't cause problems, no matter what the quoting style is. They cannot start multibyte sequences. */ break; @@ -389,12 +397,12 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, /* Length of multibyte sequence found so far. */ size_t m; - int printable; + bool printable; if (unibyte_locale) { m = 1; - printable = isprint (c); + printable = isprint (c) != 0; } else { @@ -402,7 +410,7 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, memset (&mbstate, 0, sizeof mbstate); m = 0; - printable = 1; + printable = true; if (argsize == SIZE_MAX) argsize = strlen (arg); @@ -415,20 +423,36 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, break; else if (bytes == (size_t) -1) { - printable = 0; + printable = false; break; } else if (bytes == (size_t) -2) { - printable = 0; + printable = false; while (i + m < argsize && arg[i + m]) m++; break; } else { + /* Work around a bug with older shells that "see" a '\' + that is really the 2nd byte of a multibyte character. + In practice the problem is limited to ASCII + chars >= '@' that are shell special chars. */ + if ('[' == 0x5b && quoting_style == shell_quoting_style) + { + size_t j; + for (j = 1; j < bytes; j++) + switch (arg[i + m + j]) + { + case '[': case '\\': case '^': + case '`': case '|': + goto use_shell_always_quoting_style; + } + } + if (! iswprint (w)) - printable = 0; + printable = false; m += bytes; } } @@ -472,6 +496,9 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, STORE (c); } + if (i == 0 && quoting_style == shell_quoting_style) + goto use_shell_always_quoting_style; + if (quote_string) for (; *quote_string; quote_string++) STORE (*quote_string); @@ -492,7 +519,8 @@ quotearg_buffer_restyled (char *buffer, size_t buffersize, size of the output, not counting the terminating null. If BUFFERSIZE is too small to store the output string, return the 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 SIZE_MAX, use the string length of the argument for + ARGSIZE. */ size_t quotearg_buffer (char *buffer, size_t buffersize, char const *arg, size_t argsize, @@ -506,8 +534,23 @@ quotearg_buffer (char *buffer, size_t buffersize, return r; } +/* Like quotearg_buffer (..., ARG, ARGSIZE, O), except return newly + allocated storage containing the quoted string. */ +char * +quotearg_alloc (char const *arg, size_t argsize, + struct quoting_options const *o) +{ + int e = errno; + size_t bufsize = quotearg_buffer (0, 0, arg, argsize, o) + 1; + char *buf = xmalloc (bufsize); + quotearg_buffer (buf, bufsize, arg, argsize, o); + errno = e; + return buf; +} + /* Use storage slot N to return a quoted version of argument ARG. - ARG is of size ARGSIZE, but if that is -1, ARG is a null-terminated string. + ARG is of size ARGSIZE, but if that is SIZE_MAX, ARG is a + null-terminated string. OPTIONS specifies the quoting options. The returned value points to static storage that can be reused by the next call to this function with the same value of N. diff --git a/contrib/gnu-sort/lib/quotearg.h b/contrib/gnu-sort/lib/quotearg.h index efc933173dcb..14dc316d74bd 100644 --- a/contrib/gnu-sort/lib/quotearg.h +++ b/contrib/gnu-sort/lib/quotearg.h @@ -1,6 +1,6 @@ /* quotearg.h - quote arguments for output - Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software + Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -27,13 +27,31 @@ /* Basic quoting styles. */ enum quoting_style { - literal_quoting_style, /* --quoting-style=literal */ - shell_quoting_style, /* --quoting-style=shell */ - shell_always_quoting_style, /* --quoting-style=shell-always */ - c_quoting_style, /* --quoting-style=c */ - escape_quoting_style, /* --quoting-style=escape */ - locale_quoting_style, /* --quoting-style=locale */ - clocale_quoting_style /* --quoting-style=clocale */ + /* Output names as-is (ls --quoting-style=literal). */ + literal_quoting_style, + + /* Quote names for the shell if they contain shell metacharacters + or would cause ambiguous output (ls --quoting-style=shell). */ + shell_quoting_style, + + /* Quote names for the shell, even if they would normally not + require quoting (ls --quoting-style=shell-always). */ + shell_always_quoting_style, + + /* Quote names as for a C language string (ls --quoting-style=c). */ + c_quoting_style, + + /* Like c_quoting_style except omit the surrounding double-quote + characters (ls --quoting-style=escape). */ + escape_quoting_style, + + /* Like clocale_quoting_style, but quote `like this' instead of + "like this" in the default C locale (ls --quoting-style=locale). */ + locale_quoting_style, + + /* Like c_quoting_style except use quotation marks appropriate for + the locale (ls --quoting-style=clocale). */ + clocale_quoting_style }; /* For now, --quoting-style=literal is the default, but this may change. */ @@ -81,6 +99,11 @@ size_t quotearg_buffer (char *buffer, size_t buffersize, char const *arg, size_t argsize, struct quoting_options const *o); +/* Like quotearg_buffer, except return the result in a newly allocated + buffer. It is the caller's responsibility to free the result. */ +char *quotearg_alloc (char const *arg, size_t argsize, + struct quoting_options const *o); + /* Use storage slot N to return a quoted version of the string ARG. Use the default quoting options. The returned value points to static storage that can be diff --git a/contrib/gnu-sort/lib/stat-macros.h b/contrib/gnu-sort/lib/stat-macros.h new file mode 100644 index 000000000000..facbabbc3c87 --- /dev/null +++ b/contrib/gnu-sort/lib/stat-macros.h @@ -0,0 +1,255 @@ +/* stat-related macros + + Copyright (C) 1993, 1994, 2001, 2002, 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 + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* Written by Paul Eggert and Jim Meyering. */ + +#ifndef STAT_MACROS_H +# define STAT_MACROS_H 1 + +# if ! defined S_ISREG && ! defined S_IFREG +# error "you must include <sys/stat.h> before including this file" +# endif + +# ifndef S_IFMT +# define S_IFMT 0170000 +# endif + +# if STAT_MACROS_BROKEN +# undef S_ISBLK +# undef S_ISCHR +# undef S_ISDIR +# undef S_ISDOOR +# undef S_ISFIFO +# undef S_ISLNK +# undef S_ISNAM +# undef S_ISMPB +# undef S_ISMPC +# undef S_ISNWK +# undef S_ISREG +# undef S_ISSOCK +# endif + + +# ifndef S_ISBLK +# ifdef S_IFBLK +# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) +# else +# define S_ISBLK(m) 0 +# endif +# endif + +# ifndef S_ISCHR +# ifdef S_IFCHR +# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +# else +# define S_ISCHR(m) 0 +# endif +# endif + +# ifndef S_ISDIR +# ifdef S_IFDIR +# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +# else +# define S_ISDIR(m) 0 +# endif +# endif + +# ifndef S_ISDOOR /* Solaris 2.5 and up */ +# ifdef S_IFDOOR +# define S_ISDOOR(m) (((m) & S_IFMT) == S_IFDOOR) +# else +# define S_ISDOOR(m) 0 +# endif +# endif + +# ifndef S_ISFIFO +# ifdef S_IFIFO +# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +# else +# define S_ISFIFO(m) 0 +# endif +# endif + +# ifndef S_ISLNK +# ifdef S_IFLNK +# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +# else +# define S_ISLNK(m) 0 +# endif +# endif + +# ifndef S_ISMPB /* V7 */ +# ifdef S_IFMPB +# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB) +# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC) +# else +# define S_ISMPB(m) 0 +# define S_ISMPC(m) 0 +# endif +# endif + +# ifndef S_ISNAM /* Xenix */ +# ifdef S_IFNAM +# define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM) +# else +# define S_ISNAM(m) 0 +# endif +# endif + +# ifndef S_ISNWK /* HP/UX */ +# ifdef S_IFNWK +# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) +# else +# define S_ISNWK(m) 0 +# endif +# endif + +# ifndef S_ISREG +# ifdef S_IFREG +# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +# else +# define S_ISREG(m) 0 +# endif +# endif + +# ifndef S_ISSOCK +# ifdef S_IFSOCK +# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) +# else +# define S_ISSOCK(m) 0 +# endif +# endif + + +# ifndef S_TYPEISMQ +# define S_TYPEISMQ(p) 0 +# endif + +# ifndef S_TYPEISTMO +# define S_TYPEISTMO(p) 0 +# endif + + +# ifndef S_TYPEISSEM +# ifdef S_INSEM +# define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM) +# else +# define S_TYPEISSEM(p) 0 +# endif +# endif + +# ifndef S_TYPEISSHM +# ifdef S_INSHD +# define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD) +# else +# define S_TYPEISSHM(p) 0 +# endif +# endif + +/* contiguous */ +# ifndef S_ISCTG +# define S_ISCTG(p) 0 +# endif + +/* Cray DMF (data migration facility): off line, with data */ +# ifndef S_ISOFD +# define S_ISOFD(p) 0 +# endif + +/* Cray DMF (data migration facility): off line, with no data */ +# ifndef S_ISOFL +# define S_ISOFL(p) 0 +# endif + +/* If any of the following are undefined, + define them to their de facto standard values. */ +# if !S_ISUID +# define S_ISUID 04000 +# endif +# if !S_ISGID +# define S_ISGID 02000 +# endif + +/* S_ISVTX is a common extension to POSIX. */ +# ifndef S_ISVTX +# define S_ISVTX 01000 +# endif + +# if !S_IRUSR && S_IREAD +# define S_IRUSR S_IREAD +# endif +# if !S_IRUSR +# define S_IRUSR 00400 +# endif +# if !S_IRGRP +# define S_IRGRP (S_IRUSR >> 3) +# endif +# if !S_IROTH +# define S_IROTH (S_IRUSR >> 6) +# endif + +# if !S_IWUSR && S_IWRITE +# define S_IWUSR S_IWRITE +# endif +# if !S_IWUSR +# define S_IWUSR 00200 +# endif +# if !S_IWGRP +# define S_IWGRP (S_IWUSR >> 3) +# endif +# if !S_IWOTH +# define S_IWOTH (S_IWUSR >> 6) +# endif + +# if !S_IXUSR && S_IEXEC +# define S_IXUSR S_IEXEC +# endif +# if !S_IXUSR +# define S_IXUSR 00100 +# endif +# if !S_IXGRP +# define S_IXGRP (S_IXUSR >> 3) +# endif +# if !S_IXOTH +# define S_IXOTH (S_IXUSR >> 6) +# endif + +# if !S_IRWXU +# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR) +# endif +# if !S_IRWXG +# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP) +# endif +# if !S_IRWXO +# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH) +# endif + +/* S_IXUGO is a common extension to POSIX. */ +# if !S_IXUGO +# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH) +# endif + +# ifndef S_IRWXUGO +# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO) +# endif + +/* All the mode bits that can be affected by chmod. */ +# define CHMOD_MODE_BITS \ + (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) + +#endif /* STAT_MACROS_H */ diff --git a/contrib/gnu-sort/lib/version-etc.c b/contrib/gnu-sort/lib/version-etc.c index 7523b087b237..fd71eff93f5d 100644 --- a/contrib/gnu-sort/lib/version-etc.c +++ b/contrib/gnu-sort/lib/version-etc.c @@ -46,7 +46,7 @@ version_etc_va (FILE *stream, const char *command_name, const char *package, const char *version, va_list authors) { - unsigned int n_authors; + size_t n_authors; /* Count the number of authors. */ { diff --git a/contrib/gnu-sort/lib/xalloc.h b/contrib/gnu-sort/lib/xalloc.h index 4b6585811bbc..d81f2a676488 100644 --- a/contrib/gnu-sort/lib/xalloc.h +++ b/contrib/gnu-sort/lib/xalloc.h @@ -1,7 +1,7 @@ /* xalloc.h -- malloc with out-of-memory checking Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2003 Free Software Foundation, Inc. + 1999, 2000, 2003, 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 @@ -22,6 +22,12 @@ # include <stddef.h> + +# ifdef __cplusplus +extern "C" { +# endif + + # ifndef __attribute__ # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ # define __attribute__(x) @@ -32,18 +38,9 @@ # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) # endif -/* If this pointer is non-zero, run the specified function upon each - allocation failure. It is initialized to zero. */ -extern void (*xalloc_fail_func) (void); - -/* If XALLOC_FAIL_FUNC is undefined or a function that returns, this - message is output. It is translated via gettext. - Its value is "memory exhausted". */ -extern char const xalloc_msg_memory_exhausted[]; - -/* This function is always triggered when memory is exhausted. It is - in charge of honoring the two previous items. It exits with status - exit_failure (defined in exitfail.h). This is the +/* This function is always triggered when memory is exhausted. + It must be defined by the application, either explicitly + or by using gnulib's xalloc-die module. This is the function to call when one wants the program to die because of a memory allocation failure. */ extern void xalloc_die (void) ATTRIBUTE_NORETURN; @@ -84,4 +81,10 @@ char *xstrdup (const char *str); # define XREALLOC(p, type, n) xnrealloc (p, n, sizeof (type)) # define XFREE(p) free (p) + +# ifdef __cplusplus +} +# endif + + #endif /* !XALLOC_H_ */ diff --git a/contrib/gnu-sort/lib/xmalloc.c b/contrib/gnu-sort/lib/xmalloc.c index 181006b43dbc..9b7a948c2f18 100644 --- a/contrib/gnu-sort/lib/xmalloc.c +++ b/contrib/gnu-sort/lib/xmalloc.c @@ -1,7 +1,7 @@ /* xmalloc.c -- malloc with out of memory checking - Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2003, - 1999, 2000, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, + 1999, 2000, 2002, 2003, 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 @@ -26,44 +26,10 @@ #include <stdlib.h> #include <string.h> -#include "gettext.h" -#define _(msgid) gettext (msgid) -#define N_(msgid) msgid - -#include "error.h" -#include "exitfail.h" - #ifndef SIZE_MAX # define SIZE_MAX ((size_t) -1) #endif -#ifndef HAVE_MALLOC -"you must run the autoconf test for a GNU libc compatible malloc" -#endif - -#ifndef HAVE_REALLOC -"you must run the autoconf test for a GNU libc compatible realloc" -#endif - -/* If non NULL, call this function when memory is exhausted. */ -void (*xalloc_fail_func) (void) = 0; - -/* If XALLOC_FAIL_FUNC is NULL, or does return, display this message - before exiting when memory is exhausted. Goes through gettext. */ -char const xalloc_msg_memory_exhausted[] = N_("memory exhausted"); - -void -xalloc_die (void) -{ - if (xalloc_fail_func) - (*xalloc_fail_func) (); - error (exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted)); - /* The `noreturn' cannot be given to error, since it may return if - its first argument is 0. To help compilers understand the - xalloc_die does terminate, call abort. */ - abort (); -} - /* Allocate an array of N objects, each with S bytes of memory, dynamically, with error checking. S must be nonzero. */ @@ -71,7 +37,7 @@ static inline void * xnmalloc_inline (size_t n, size_t s) { void *p; - if (xalloc_oversized (n, s) || ! (p = malloc (n * s))) + if (xalloc_oversized (n, s) || (! (p = malloc (n * s)) && n != 0)) xalloc_die (); return p; } @@ -96,7 +62,7 @@ xmalloc (size_t n) static inline void * xnrealloc_inline (void *p, size_t n, size_t s) { - if (xalloc_oversized (n, s) || ! (p = realloc (p, n * s))) + if (xalloc_oversized (n, s) || (! (p = realloc (p, n * s)) && n != 0)) xalloc_die (); return p; } @@ -239,7 +205,7 @@ xcalloc (size_t n, size_t s) void *p; /* Test for overflow, since some calloc implementations don't have proper overflow checks. */ - if (xalloc_oversized (n, s) || ! (p = calloc (n, s))) + if (xalloc_oversized (n, s) || (! (p = calloc (n, s)) && n != 0)) xalloc_die (); return p; } diff --git a/contrib/gnu-sort/lib/xmemcoll.c b/contrib/gnu-sort/lib/xmemcoll.c index 0e30aef15067..433d67f9c49e 100644 --- a/contrib/gnu-sort/lib/xmemcoll.c +++ b/contrib/gnu-sort/lib/xmemcoll.c @@ -1,5 +1,5 @@ /* Locale-specific memory comparison. - Copyright (C) 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 2002, 2003, 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 @@ -22,10 +22,6 @@ #endif #include <errno.h> -#ifndef errno -extern int errno; -#endif - #include <stdlib.h> #include "gettext.h" diff --git a/contrib/gnu-sort/lib/xstrtol.c b/contrib/gnu-sort/lib/xstrtol.c index d0aa0a968688..906e4a1cc1e9 100644 --- a/contrib/gnu-sort/lib/xstrtol.c +++ b/contrib/gnu-sort/lib/xstrtol.c @@ -1,6 +1,6 @@ /* A more useful interface to strtol. - Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2003 Free + Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -37,15 +37,10 @@ #include <assert.h> #include <ctype.h> -#include <stdlib.h> -#include <string.h> - #include <errno.h> -#ifndef errno -extern int errno; -#endif - #include <limits.h> +#include <stdlib.h> +#include <string.h> /* The extra casts work around common compiler bugs. */ #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) @@ -121,9 +116,10 @@ __xstrtol (const char *s, char **ptr, int strtol_base, if (! TYPE_SIGNED (__strtol_t)) { const char *q = s; - while (ISSPACE ((unsigned char) *q)) - ++q; - if (*q == '-') + unsigned char ch = *q; + while (ISSPACE (ch)) + ch = *++q; + if (ch == '-') return LONGINT_INVALID; } diff --git a/contrib/gnu-sort/lib/xstrtol.h b/contrib/gnu-sort/lib/xstrtol.h index 5765c88e239b..0d6b98482eff 100644 --- a/contrib/gnu-sort/lib/xstrtol.h +++ b/contrib/gnu-sort/lib/xstrtol.h @@ -22,13 +22,11 @@ # include "exitfail.h" -/* Get uintmax_t. */ # if HAVE_INTTYPES_H # include <inttypes.h> -# else -# if HAVE_STDINT_H -# include <stdint.h> -# endif +# endif +# if HAVE_STDINT_H +# include <stdint.h> # endif # ifndef _STRTOL_ERROR diff --git a/contrib/gnu-sort/lib/xstrtoumax.c b/contrib/gnu-sort/lib/xstrtoumax.c index a8858bf6d75e..8518ef077277 100644 --- a/contrib/gnu-sort/lib/xstrtoumax.c +++ b/contrib/gnu-sort/lib/xstrtoumax.c @@ -1,5 +1,5 @@ /* xstrtoumax.c -- A more useful interface to strtoumax. - Copyright (C) 1999, 2003 Free Software Foundation, Inc. + Copyright (C) 1999, 2003, 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 @@ -21,11 +21,7 @@ # include <config.h> #endif -#if HAVE_INTTYPES_H -# include <inttypes.h> -#elif HAVE_STDINT_H -# include <stdint.h> -#endif +#include "xstrtol.h" #define __strtol strtoumax #define __strtol_t uintmax_t |
