argp-fmtstream.h revision 2
2N/A/* Word-wrapping and line-truncating streams. 2N/A Copyright (C) 1997, 2006-2010 Free Software Foundation, Inc. 2N/A This file is part of the GNU C Library. 2N/A Written by Miles Bader <miles@gnu.ai.mit.edu>. 2N/A This program is free software: you can redistribute it and/or modify 2N/A it under the terms of the GNU General Public License as published by 2N/A the Free Software Foundation; either version 3 of the License, or 2N/A (at your option) any later version. 2N/A This program is distributed in the hope that it will be useful, 2N/A but WITHOUT ANY WARRANTY; without even the implied warranty of 2N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2N/A GNU General Public License for more details. 2N/A You should have received a copy of the GNU General Public License 2N/A/* This package emulates glibc `line_wrap_stream' semantics for systems that 2N/A don't have that. If the system does have it, it is just a wrapper for 2N/A that. This header file is only used internally while compiling argp, and 2N/A shouldn't be installed. */ 2N/A/* The __attribute__ feature is available in gcc versions 2.5 and later. 2N/A The __-protected variants of the attributes 'format' and 'printf' are 2N/A accepted by gcc versions 2.6.4 (effectively 2.7) and later. 2N/A We enable __attribute__ only if these are supported too, because 2N/A gnulib and libintl do '#define printf __printf__' when they override 2N/A the 'printf' function. */ 2N/A/* line_wrap_stream is available, so use that. */ 2N/A/* Just be a simple wrapper for line_wrap_stream; the semantics are 2N/A *slightly* different, as line_wrap_stream doesn't actually make a new 2N/A object, it just modifies the given stream (reversibly) to do 2N/A line-wrapping. Since we control who uses this code, it doesn't matter. */ 2N/A#
else /* !ARGP_FMTSTREAM_USE_LINEWRAP */ 2N/A/* Guess we have to define our own version. */ 2N/A /* Point in buffer to which we've processed for wrapping, but not output. */ 2N/A /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */ 2N/A char *
buf;
/* Output buffer. */ 2N/A char *p;
/* Current end of text in BUF. */ 2N/A char *
end;
/* Absolute end of BUF. */ 2N/A/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines 2N/A written on it with LMARGIN spaces and limits them to RMARGIN columns 2N/A total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by 2N/A replacing the whitespace before them with a newline and WMARGIN spaces. 2N/A Otherwise, chars beyond RMARGIN are simply dropped until a newline. 2N/A Returns NULL if there was an error. */ 2N/A/* Flush __FS to its stream, and free it (but don't close the stream). */ 2N/A/* Access macros for various bits of state. */ 2N/A/* Set __FS's left margin to LMARGIN and return the old value. */ 2N/A/* Set __FS's right margin to __RMARGIN and return the old value. */ 2N/A/* Set __FS's wrap margin to __WMARGIN and return the old value. */ 2N/A/* Return the column number of the current output point in __FS. */ 2N/A/* Internal routines. */ 2N/A/* Inline versions of above routines. */ 2N/A /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 2N/A inline semantics, unless -fgnu89-inline is used. It defines a macro 2N/A __GNUC_STDC_INLINE__ to indicate this situation or a macro 2N/A __GNUC_GNU_INLINE__ to indicate the opposite situation. 2N/A GCC 4.2 with -std=c99 or -std=gnu99 implements the GNU C inline 2N/A semantics but warns, unless -fgnu89-inline is used: 2N/A warning: C99 inline functions are not supported; using GNU89 2N/A warning: to disable this warning use -fgnu89-inline or the gnu_inline function attribute 2N/A It defines a macro __GNUC_GNU_INLINE__ to indicate this situation. 2N/A Whereas Apple GCC 4.0.1 build 5479 without -std=c99 or -std=gnu99 2N/A implements the GNU C inline semantics and defines the macro 2N/A __GNUC_GNU_INLINE__, but it does not warn and does not support 2N/A __attribute__ ((__gnu_inline__)). 2N/A All in all, these are the possible combinations. For every compiler, 2N/A we need to choose ARGP_FS_EI so that the corresponding table cell 2N/A \ ARGP_FS_EI inline extern extern 2N/A gcc 4.3.0 error ok ok 2N/A gcc 4.3.0 -std=gnu99 -fgnu89-inline error ok ok 2N/A gcc 4.3.0 -std=gnu99 ok error ok 2N/A gcc 4.2.2 error ok ok 2N/A gcc 4.2.2 -std=gnu99 -fgnu89-inline error ok ok 2N/A gcc 4.2.2 -std=gnu99 error warning ok 2N/A gcc 4.1.2 error ok warning 2N/A gcc 4.1.2 -std=gnu99 error ok warning 2N/A Apple gcc 4.0.1 error ok warning 2N/A Apple gcc 4.0.1 -std=gnu99 ok error warning 2N/A /* With other compilers, assume the ISO C99 meaning of 'inline', if 2N/A the compiler supports 'inline' at all. */ 2N/A/* Set __FS's left margin to __LMARGIN and return the old value. */ 2N/A/* Set __FS's right margin to __RMARGIN and return the old value. */ 2N/A/* Set FS's wrap margin to __WMARGIN and return the old value. */ 2N/A/* Return the column number of the current output point in __FS. */ 2N/A#
endif /* __OPTIMIZE__ */ 2N/A#
endif /* ARGP_FMTSTREAM_USE_LINEWRAP */