Mercurial > hg > octave-lojdl > gnulib-hg
changeset 4767:0a9cf348c2ec
argp update from libc
author | Karl Berry <karl@freefriends.org> |
---|---|
date | Sat, 04 Oct 2003 12:28:06 +0000 |
parents | cc75be2f0981 |
children | 3027c8485825 |
files | lib/ChangeLog lib/argp-fmtstream.h lib/argp-help.c lib/argp-namefrob.h lib/argp-parse.c lib/argp-xinl.c lib/argp.h |
diffstat | 7 files changed, 170 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,7 @@ +2003-10-04 Karl Berry <karl@gnu.org> + + * argp*: update from libc. + 2003-10-01 Larry Jones <lawrence.jones@eds.com> * getpass.c (getpass): Use a no-op fseek when switching from input to
--- a/lib/argp-fmtstream.h +++ b/lib/argp-fmtstream.h @@ -33,6 +33,19 @@ #include <string.h> #include <unistd.h> +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ +# define __attribute__(Spec) /* empty */ +# endif +/* The __-protected variants of `format' and `printf' attributes + are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || __STRICT_ANSI__ +# define __format__ format +# define __printf__ printf +# endif +#endif + #if (_LIBC - 0 && !defined (USE_IN_LIBIO)) \ || (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H)) /* line_wrap_stream is available, so use that. */
--- a/lib/argp-help.c +++ b/lib/argp-help.c @@ -49,7 +49,6 @@ #include <string.h> #include <assert.h> #include <stdarg.h> -#include <malloc.h> #include <ctype.h> #ifdef USE_IN_LIBIO # include <wchar.h> @@ -69,13 +68,25 @@ # endif #endif +#ifndef _LIBC +# if HAVE_STRERROR_R +# if !HAVE_DECL_STRERROR_R +char *strerror_r (int errnum, char *buf, size_t buflen); +# endif +# else +# if !HAVE_DECL_STRERROR +char *strerror (int errnum); +# endif +# endif +#endif + #include "argp.h" #include "argp-fmtstream.h" #include "argp-namefrob.h" #ifndef SIZE_MAX # define SIZE_MAX ((size_t) -1) -#endif +#endif /* User-selectable (using an environment variable) formatting parameters. @@ -551,7 +562,7 @@ } static inline int -__attribute ((always_inline)) +__attribute__ ((always_inline)) hol_entry_long_iterate (const struct hol_entry *entry, int (*func)(const struct argp_option *opt, const struct argp_option *real, @@ -1537,7 +1548,9 @@ if (! stream) return; +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) __flockfile (stream); +#endif if (! uparams.valid) fill_in_uparams (state); @@ -1545,7 +1558,9 @@ fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0); if (! fs) { +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) __funlockfile (stream); +#endif return; } @@ -1653,7 +1668,9 @@ anything = 1; } +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) __funlockfile (stream); +#endif if (hol) hol_free (hol); @@ -1672,6 +1689,32 @@ weak_alias (__argp_help, argp_help) #endif +#ifndef _LIBC +char *__argp_basename (char *name) +{ + char *short_name = strrchr (name, '/'); + return short_name ? short_name + 1 : name; +} + +char * +__argp_short_program_name (void) +{ +# if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME + return program_invocation_short_name; +# elif HAVE_DECL_PROGRAM_INVOCATION_NAME + return __argp_basename (program_invocation_name); +# else + /* FIXME: What now? Miles suggests that it is better to use NULL, + but currently the value is passed on directly to fputs_unlocked, + so that requires more changes. */ +# if __GNUC__ +# warning No reasonable value to return +# endif /* __GNUC__ */ + return ""; +# endif +} +#endif + /* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are from the set ARGP_HELP_*. */ void @@ -1683,7 +1726,7 @@ flags |= ARGP_HELP_LONG_ONLY; _help (state ? state->root_argp : 0, state, stream, flags, - state ? state->name : program_invocation_short_name); + state ? state->name : __argp_short_program_name ()); if (!state || ! (state->flags & ARGP_NO_EXIT)) { @@ -1712,7 +1755,9 @@ { va_list ap; +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) __flockfile (stream); +#endif va_start (ap, fmt); @@ -1724,7 +1769,7 @@ __asprintf (&buf, fmt, ap); __fwprintf (stream, L"%s: %s\n", - state ? state->name : program_invocation_short_name, + state ? state->name : __argp_short_program_name (), buf); free (buf); @@ -1733,7 +1778,7 @@ #endif { fputs_unlocked (state - ? state->name : program_invocation_short_name, + ? state->name : __argp_short_program_name (), stream); putc_unlocked (':', stream); putc_unlocked (' ', stream); @@ -1747,7 +1792,9 @@ va_end (ap); +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) __funlockfile (stream); +#endif } } } @@ -1773,16 +1820,18 @@ if (stream) { +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) __flockfile (stream); +#endif #ifdef USE_IN_LIBIO if (_IO_fwide (stream, 0) > 0) __fwprintf (stream, L"%s", - state ? state->name : program_invocation_short_name); + state ? state->name : __argp_short_program_name ()); else #endif fputs_unlocked (state - ? state->name : program_invocation_short_name, + ? state->name : __argp_short_program_name (), stream); if (fmt) @@ -1826,7 +1875,11 @@ { putc_unlocked (':', stream); putc_unlocked (' ', stream); +#if defined _LIBC || defined HAVE_STRERROR_R fputs (__strerror_r (errnum, buf, sizeof (buf)), stream); +#else + fputs (strerror (errnum), stream); +#endif } } @@ -1837,7 +1890,9 @@ #endif putc_unlocked ('\n', stream); +#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE) __funlockfile (stream); +#endif if (status && (!state || !(state->flags & ARGP_NO_EXIT))) exit (status);
--- a/lib/argp-namefrob.h +++ b/lib/argp-namefrob.h @@ -1,5 +1,5 @@ /* Name frobnication for compiling argp outside of glibc - Copyright (C) 1997 Free Software Foundation, Inc. + Copyright (C) 1997, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Miles Bader <miles@gnu.ai.mit.edu>. @@ -77,15 +77,75 @@ #define __argp_fmtstream_wmargin argp_fmtstream_wmargin /* normal libc functions we call */ +#undef __flockfile +#define __flockfile flockfile +#undef __funlockfile +#define __funlockfile funlockfile +#undef __mempcpy +#define __mempcpy mempcpy #undef __sleep #define __sleep sleep #undef __strcasecmp #define __strcasecmp strcasecmp +#undef __strchrnul +#define __strchrnul strchrnul +#undef __strerror_r +#define __strerror_r strerror_r +#undef __strndup +#define __strndup strndup #undef __vsnprintf #define __vsnprintf vsnprintf +#if defined(HAVE_DECL_CLEARERR_UNLOCKED) && !HAVE_DECL_CLEARERR_UNLOCKED +# define clearerr_unlocked(x) clearerr (x) +#endif +#if defined(HAVE_DECL_FEOF_UNLOCKED) && !HAVE_DECL_FEOF_UNLOCKED +# define feof_unlocked(x) feof (x) +# endif +#if defined(HAVE_DECL_FERROR_UNLOCKED) && !HAVE_DECL_FERROR_UNLOCKED +# define ferror_unlocked(x) ferror (x) +# endif +#if defined(HAVE_DECL_FFLUSH_UNLOCKED) && !HAVE_DECL_FFLUSH_UNLOCKED +# define fflush_unlocked(x) fflush (x) +# endif +#if defined(HAVE_DECL_FGETS_UNLOCKED) && !HAVE_DECL_FGETS_UNLOCKED +# define fgets_unlocked(x,y,z) fgets (x,y,z) +# endif +#if defined(HAVE_DECL_FPUTC_UNLOCKED) && !HAVE_DECL_FPUTC_UNLOCKED +# define fputc_unlocked(x,y) fputc (x,y) +# endif +#if defined(HAVE_DECL_FPUTS_UNLOCKED) && !HAVE_DECL_FPUTS_UNLOCKED +# define fputs_unlocked(x,y) fputs (x,y) +# endif +#if defined(HAVE_DECL_FREAD_UNLOCKED) && !HAVE_DECL_FREAD_UNLOCKED +# define fread_unlocked(w,x,y,z) fread (w,x,y,z) +# endif +#if defined(HAVE_DECL_FWRITE_UNLOCKED) && !HAVE_DECL_FWRITE_UNLOCKED +# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z) +# endif +#if defined(HAVE_DECL_GETC_UNLOCKED) && !HAVE_DECL_GETC_UNLOCKED +# define getc_unlocked(x) getc (x) +# endif +#if defined(HAVE_DECL_GETCHAR_UNLOCKED) && !HAVE_DECL_GETCHAR_UNLOCKED +# define getchar_unlocked() getchar () +# endif +#if defined(HAVE_DECL_PUTC_UNLOCKED) && !HAVE_DECL_PUTC_UNLOCKED +# define putc_unlocked(x,y) putc (x,y) +# endif +#if defined(HAVE_DECL_PUTCHAR_UNLOCKED) && !HAVE_DECL_PUTCHAR_UNLOCKED +# define putchar_unlocked(x) putchar (x) +# endif + +extern char *__argp_basename (char *name); + #endif /* !_LIBC */ #ifndef __set_errno #define __set_errno(e) (errno = (e)) #endif + +#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME +# define __argp_short_program_name() (program_invocation_short_name) +#else +extern char *__argp_short_program_name (void); +#endif
--- a/lib/argp-parse.c +++ b/lib/argp-parse.c @@ -118,24 +118,28 @@ break; case OPT_PROGNAME: /* Set the program name. */ +#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_NAME program_invocation_name = arg; - +#endif /* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined to be that, so we have to be a bit careful here.] */ - arg = strrchr (arg, '/'); - if (arg) - program_invocation_short_name = arg + 1; - else - program_invocation_short_name = program_invocation_name; /* Update what we use for messages. */ - state->name = program_invocation_short_name; + state->name = strrchr (arg, '/'); + if (state->name) + state->name++; + else + state->name = arg; + +#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME + program_invocation_short_name = state->name; +#endif if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS)) == ARGP_PARSE_ARGV0) /* Update what getopt uses too. */ - state->argv[0] = program_invocation_name; + state->argv[0] = arg; break; @@ -598,7 +602,7 @@ parser->state.name = short_name ? short_name + 1 : argv[0]; } else - parser->state.name = program_invocation_short_name; + parser->state.name = __argp_short_program_name (); return 0; }
--- a/lib/argp-xinl.c +++ b/lib/argp-xinl.c @@ -21,7 +21,9 @@ #include <config.h> #endif -#include <features.h> +#if defined _LIBC || defined HAVE_FEATURES_H +# include <features.h> +#endif #ifndef __USE_EXTERN_INLINES # define __USE_EXTERN_INLINES 1
--- a/lib/argp.h +++ b/lib/argp.h @@ -35,6 +35,19 @@ # define __THROW #endif +#ifndef __attribute__ +/* This feature is available in gcc versions 2.5 and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ +# define __attribute__(Spec) /* empty */ +# endif +/* The __-protected variants of `format' and `printf' attributes + are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || __STRICT_ANSI__ +# define __format__ format +# define __printf__ printf +# endif +#endif + #ifndef __error_t_defined typedef int error_t; # define __error_t_defined