maint: update copyright
[gnulib.git] / lib / argp-fmtstream.h
index 73157e0..257dc7f 100644 (file)
@@ -1,5 +1,5 @@
 /* Word-wrapping and line-truncating streams.
-   Copyright (C) 1997, 2006-2008 Free Software Foundation, Inc.
+   Copyright (C) 1997, 2006-2014 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <miles@gnu.ai.mit.edu>.
 
@@ -16,7 +16,7 @@
    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
+/* 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.  */
 #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)
-#  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
+/* 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 _GL_ATTRIBUTE_FORMAT 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 _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+#else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
 #endif
 
 #if    (_LIBC - 0 && !defined (USE_IN_LIBIO)) \
@@ -91,19 +90,19 @@ typedef FILE *argp_fmtstream_t;
 \f
 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;
@@ -115,26 +114,26 @@ 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, ...)
-     __attribute__ ((__format__ (printf, 2, 3)));
+                                        const char *__fmt, ...)
+     _GL_ATTRIBUTE_FORMAT ((printf, 2, 3));
 extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs,
-                                     const char *__fmt, ...)
-     __attribute__ ((__format__ (printf, 2, 3)));
+                                      const char *__fmt, ...)
+     _GL_ATTRIBUTE_FORMAT ((printf, 2, 3));
 
-#if _LIBC || !defined __OPTIMIZE__
+#if _LIBC
 extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
 extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
 
@@ -142,9 +141,9 @@ 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
 \f
 /* Access macros for various bits of state.  */
@@ -155,24 +154,24 @@ 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__
+#if _LIBC
 /* 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);
@@ -185,7 +184,7 @@ extern void __argp_fmtstream_update (argp_fmtstream_t __fs);
 extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
 extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
 \f
-#ifdef __OPTIMIZE__
+#if !_LIBC || defined __OPTIMIZE__
 /* Inline versions of above routines.  */
 
 #if !_LIBC
@@ -198,6 +197,13 @@ extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
 #define __argp_fmtstream_point argp_fmtstream_point
 #define __argp_fmtstream_update _argp_fmtstream_update
 #define __argp_fmtstream_ensure _argp_fmtstream_ensure
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef ARGP_FS_EI
+# define ARGP_FS_EI _GL_INLINE
+#endif
 #endif
 
 #ifndef ARGP_FS_EI
@@ -257,7 +263,7 @@ extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
 
 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))
     {
@@ -346,9 +352,10 @@ __argp_fmtstream_point (argp_fmtstream_t __fs)
 #undef __argp_fmtstream_point
 #undef __argp_fmtstream_update
 #undef __argp_fmtstream_ensure
+_GL_INLINE_HEADER_END
 #endif
 
-#endif /* __OPTIMIZE__ */
+#endif /* !_LIBC || __OPTIMIZE__ */
 
 #endif /* ARGP_FMTSTREAM_USE_LINEWRAP */