X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fargp-fmtstream.h;h=b913d1b254bb324b8a97c9e4004ca206460144c8;hb=217ec874c8e4610ce407f0204c4e3fe30b7c76ec;hp=15914a7e83f57be1da59d1a9cbdb59d367fe4490;hpb=267a39bafd249d7eb9c37df06dc6defcf41cb343;p=gnulib.git diff --git a/lib/argp-fmtstream.h b/lib/argp-fmtstream.h index 15914a7e8..b913d1b25 100644 --- a/lib/argp-fmtstream.h +++ b/lib/argp-fmtstream.h @@ -1,21 +1,20 @@ /* Word-wrapping and line-truncating streams. - Copyright (C) 1997 Free Software Foundation, Inc. + Copyright (C) 1997, 2006-2010 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Miles Bader . - 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 - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ /* This package emulates glibc `line_wrap_stream' semantics for systems that don't have that. If the system does have it, it is just a wrapper for @@ -25,24 +24,19 @@ #ifndef _ARGP_FMTSTREAM_H #define _ARGP_FMTSTREAM_H -#ifdef HAVE_CONFIG_H -#include -#endif - #include #include #include #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 +/* The __attribute__ feature is available in gcc versions 2.5 and later. + The __-protected variants of the attributes 'format' and 'printf' are + accepted by gcc versions 2.6.4 (effectively 2.7) and later. + We enable __attribute__ only if these are supported too, because + gnulib and libintl do '#define printf __printf__' when they override + the 'printf' function. */ +# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) +# define __attribute__(Spec) /* empty */ # endif #endif @@ -93,26 +87,22 @@ typedef FILE *argp_fmtstream_t; #else /* !ARGP_FMTSTREAM_USE_LINEWRAP */ /* Guess we have to define our own version. */ - -#ifndef __const -#define __const const -#endif struct argp_fmtstream { - FILE *stream; /* The stream we're outputting to. */ + FILE *stream; /* The stream we're outputting to. */ - size_t lmargin, rmargin; /* Left and right margins. */ - ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */ + size_t lmargin, rmargin; /* Left and right margins. */ + ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */ /* Point in buffer to which we've processed for wrapping, but not output. */ size_t point_offs; /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */ ssize_t point_col; - char *buf; /* Output buffer. */ - char *p; /* Current end of text in BUF. */ - char *end; /* Absolute end of BUF. */ + char *buf; /* Output buffer. */ + char *p; /* Current end of text in BUF. */ + char *end; /* Absolute end of BUF. */ }; typedef struct argp_fmtstream *argp_fmtstream_t; @@ -124,35 +114,37 @@ typedef struct argp_fmtstream *argp_fmtstream_t; Otherwise, chars beyond RMARGIN are simply dropped until a newline. Returns NULL if there was an error. */ extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream, - size_t __lmargin, - size_t __rmargin, - ssize_t __wmargin); + size_t __lmargin, + size_t __rmargin, + ssize_t __wmargin); extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream, - size_t __lmargin, - size_t __rmargin, - ssize_t __wmargin); + size_t __lmargin, + size_t __rmargin, + ssize_t __wmargin); /* Flush __FS to its stream, and free it (but don't close the stream). */ extern void __argp_fmtstream_free (argp_fmtstream_t __fs); extern void argp_fmtstream_free (argp_fmtstream_t __fs); extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs, - __const char *__fmt, ...) + const char *__fmt, ...) __attribute__ ((__format__ (printf, 2, 3))); extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs, - __const char *__fmt, ...) + const char *__fmt, ...) __attribute__ ((__format__ (printf, 2, 3))); +#if _LIBC || !defined __OPTIMIZE__ extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch); extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch); -extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str); -extern int argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str); +extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str); +extern int argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str); extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs, - __const char *__str, size_t __len); + const char *__str, size_t __len); extern size_t argp_fmtstream_write (argp_fmtstream_t __fs, - __const char *__str, size_t __len); + const char *__str, size_t __len); +#endif /* Access macros for various bits of state. */ #define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin) @@ -162,27 +154,29 @@ extern size_t argp_fmtstream_write (argp_fmtstream_t __fs, #define __argp_fmtstream_rmargin argp_fmtstream_rmargin #define __argp_fmtstream_wmargin argp_fmtstream_wmargin +#if _LIBC || !defined __OPTIMIZE__ /* Set __FS's left margin to LMARGIN and return the old value. */ extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, - size_t __lmargin); + size_t __lmargin); extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, - size_t __lmargin); + size_t __lmargin); /* Set __FS's right margin to __RMARGIN and return the old value. */ extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, - size_t __rmargin); + size_t __rmargin); extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, - size_t __rmargin); + size_t __rmargin); /* Set __FS's wrap margin to __WMARGIN and return the old value. */ extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, - size_t __wmargin); + size_t __wmargin); extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, - size_t __wmargin); + size_t __wmargin); /* Return the column number of the current output point in __FS. */ extern size_t argp_fmtstream_point (argp_fmtstream_t __fs); extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs); +#endif /* Internal routines. */ extern void _argp_fmtstream_update (argp_fmtstream_t __fs); @@ -206,12 +200,63 @@ extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount); #endif #ifndef ARGP_FS_EI -#define ARGP_FS_EI extern inline +# ifdef __GNUC__ + /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 + inline semantics, unless -fgnu89-inline is used. It defines a macro + __GNUC_STDC_INLINE__ to indicate this situation or a macro + __GNUC_GNU_INLINE__ to indicate the opposite situation. + + GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline + semantics but warns, unless -fgnu89-inline is used: + warning: C99 inline functions are not supported; using GNU89 + warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute + It defines a macro __GNUC_GNU_INLINE__ to indicate this situation. + + Whereas Apple GCC 4.0.1 build 5479 without -std=c99 or -std=gnu99 + implements the GNU C inline semantics and defines the macro + __GNUC_GNU_INLINE__, but it does not warn and does not support + __attribute__ ((__gnu_inline__)). + + All in all, these are the possible combinations. For every compiler, + we need to choose ARGP_FS_EI so that the corresponding table cell + contains an "ok". + + \ ARGP_FS_EI inline extern extern + \ inline inline + CC \ __attribute__ + ((gnu_inline)) + + gcc 4.3.0 error ok ok + gcc 4.3.0 -std=gnu99 -fgnu89-inline error ok ok + gcc 4.3.0 -std=gnu99 ok error ok + + gcc 4.2.2 error ok ok + gcc 4.2.2 -std=gnu99 -fgnu89-inline error ok ok + gcc 4.2.2 -std=gnu99 error warning ok + + gcc 4.1.2 error ok warning + gcc 4.1.2 -std=gnu99 error ok warning + + Apple gcc 4.0.1 error ok warning + Apple gcc 4.0.1 -std=gnu99 ok error warning + */ +# if defined __GNUC_STDC_INLINE__ +# define ARGP_FS_EI inline +# elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2) +# define ARGP_FS_EI extern inline __attribute__ ((__gnu_inline__)) +# else +# define ARGP_FS_EI extern inline +# endif +# else + /* With other compilers, assume the ISO C99 meaning of 'inline', if + the compiler supports 'inline' at all. */ +# define ARGP_FS_EI inline +# endif #endif ARGP_FS_EI size_t __argp_fmtstream_write (argp_fmtstream_t __fs, - __const char *__str, size_t __len) + const char *__str, size_t __len) { if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len)) { @@ -224,7 +269,7 @@ __argp_fmtstream_write (argp_fmtstream_t __fs, } ARGP_FS_EI int -__argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str) +__argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str) { size_t __len = strlen (__str); if (__len)