/* Word-wrapping and line-truncating streams.
Copyright (C) 1997, 2006-2010 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Written by Miles Bader <miles@gnu.ai.mit.edu>.
it under the terms of the GNU General Public License as published by
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, see <http://www.gnu.org/licenses/>. */
/* 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
that. This header file is only used internally while compiling argp, and
shouldn't be installed. */
#ifndef _ARGP_FMTSTREAM_H
#define _ARGP_FMTSTREAM_H
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#ifndef __attribute__
/* 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. */
# endif
#endif
#if (_LIBC - 0 && !defined (USE_IN_LIBIO)) \
|| (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H))
/* line_wrap_stream is available, so use that. */
#define ARGP_FMTSTREAM_USE_LINEWRAP
#endif
#ifdef ARGP_FMTSTREAM_USE_LINEWRAP
/* Just be a simple wrapper for line_wrap_stream; the semantics are
*slightly* different, as line_wrap_stream doesn't actually make a new
object, it just modifies the given stream (reversibly) to do
line-wrapping. Since we control who uses this code, it doesn't matter. */
#include <linewrap.h>
#else /* !ARGP_FMTSTREAM_USE_LINEWRAP */
/* Guess we have to define our own version. */
struct argp_fmtstream
{
/* Point in buffer to which we've processed for wrapping, but not output. */
/* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */
char *p; /* Current end of text in BUF. */
};
/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
written on it with LMARGIN spaces and limits them to RMARGIN columns
total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
replacing the whitespace before them with a newline and WMARGIN spaces.
Otherwise, chars beyond RMARGIN are simply dropped until a newline.
Returns NULL if there was an error. */
/* Flush __FS to its stream, and free it (but don't close the stream). */
const char *__fmt, ...)
const char *__fmt, ...)
#if _LIBC || !defined __OPTIMIZE__
#endif
/* Access macros for various bits of state. */
#if _LIBC || !defined __OPTIMIZE__
/* Set __FS's left margin to LMARGIN and return the old value. */
/* Set __FS's right margin to __RMARGIN and return the old value. */
/* Set __FS's wrap margin to __WMARGIN and return the old value. */
/* Return the column number of the current output point in __FS. */
#endif
/* Internal routines. */
#ifdef __OPTIMIZE__
/* Inline versions of above routines. */
#if !_LIBC
#endif
#ifndef ARGP_FS_EI
# 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
# 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
{
{
return __len;
}
else
return 0;
}
ARGP_FS_EI int
{
if (__len)
{
}
else
return 0;
}
ARGP_FS_EI int
{
else
return EOF;
}
/* Set __FS's left margin to __LMARGIN and return the old value. */
{
return __old;
}
/* Set __FS's right margin to __RMARGIN and return the old value. */
{
return __old;
}
/* Set FS's wrap margin to __WMARGIN and return the old value. */
{
return __old;
}
/* Return the column number of the current output point in __FS. */
{
}
#if !_LIBC
#endif
#endif /* __OPTIMIZE__ */
#endif /* ARGP_FMTSTREAM_USE_LINEWRAP */
#endif /* argp-fmtstream.h */