123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- #ifndef _ARGP_FMTSTREAM_H
- #define _ARGP_FMTSTREAM_H
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #ifndef __attribute__
- # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || defined(__STRICT_ANSI__)
- # define __attribute__(Spec)
- # endif
- # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || defined(__STRICT_ANSI__)
- # define __format__ format
- # define __printf__ printf
- # endif
- #endif
- #if 0
- #if (_LIBC - 0 && !defined (USE_IN_LIBIO)) \
- || (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H))
- #define ARGP_FMTSTREAM_USE_LINEWRAP
- #endif
- #else
- # undef ARGP_FMTSTREAM_USE_LINEWRAP
- #endif
- #ifdef ARGP_FMTSTREAM_USE_LINEWRAP
- #include <linewrap.h>
- typedef FILE *argp_fmtstream_t;
- #define argp_make_fmtstream line_wrap_stream
- #define __argp_make_fmtstream line_wrap_stream
- #define argp_fmtstream_free line_unwrap_stream
- #define __argp_fmtstream_free line_unwrap_stream
- #define __argp_fmtstream_putc(fs,ch) putc(ch,fs)
- #define argp_fmtstream_putc(fs,ch) putc(ch,fs)
- #define __argp_fmtstream_puts(fs,str) fputs(str,fs)
- #define argp_fmtstream_puts(fs,str) fputs(str,fs)
- #define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
- #define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
- #define __argp_fmtstream_printf fprintf
- #define argp_fmtstream_printf fprintf
- #define __argp_fmtstream_lmargin line_wrap_lmargin
- #define argp_fmtstream_lmargin line_wrap_lmargin
- #define __argp_fmtstream_set_lmargin line_wrap_set_lmargin
- #define argp_fmtstream_set_lmargin line_wrap_set_lmargin
- #define __argp_fmtstream_rmargin line_wrap_rmargin
- #define argp_fmtstream_rmargin line_wrap_rmargin
- #define __argp_fmtstream_set_rmargin line_wrap_set_rmargin
- #define argp_fmtstream_set_rmargin line_wrap_set_rmargin
- #define __argp_fmtstream_wmargin line_wrap_wmargin
- #define argp_fmtstream_wmargin line_wrap_wmargin
- #define __argp_fmtstream_set_wmargin line_wrap_set_wmargin
- #define argp_fmtstream_set_wmargin line_wrap_set_wmargin
- #define __argp_fmtstream_point line_wrap_point
- #define argp_fmtstream_point line_wrap_point
- #else
- #ifndef __const
- #define __const const
- #endif
- struct argp_fmtstream
- {
- FILE *stream;
- size_t lmargin, rmargin;
- ssize_t wmargin;
-
- size_t point_offs;
-
- ssize_t point_col;
- char *buf;
- char *p;
- char *end;
- };
- typedef struct argp_fmtstream *argp_fmtstream_t;
- extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream,
- 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);
- 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)));
- extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs,
- __const char *__fmt, ...)
- __attribute__ ((__format__ (printf, 2, 3)));
- 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 size_t __argp_fmtstream_write (argp_fmtstream_t __fs,
- __const char *__str, size_t __len);
- extern size_t argp_fmtstream_write (argp_fmtstream_t __fs,
- __const char *__str, size_t __len);
- #define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin)
- #define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin)
- #define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin)
- #define __argp_fmtstream_lmargin argp_fmtstream_lmargin
- #define __argp_fmtstream_rmargin argp_fmtstream_rmargin
- #define __argp_fmtstream_wmargin argp_fmtstream_wmargin
- extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
- size_t __lmargin);
- extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
- size_t __lmargin);
- extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
- size_t __rmargin);
- extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
- size_t __rmargin);
- extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
- size_t __wmargin);
- extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
- size_t __wmargin);
- extern size_t argp_fmtstream_point (argp_fmtstream_t __fs);
- extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs);
- extern void _argp_fmtstream_update (argp_fmtstream_t __fs);
- 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);
- #ifdef __OPTIMIZE__
- #if !_LIBC
- #define __argp_fmtstream_putc argp_fmtstream_putc
- #define __argp_fmtstream_puts argp_fmtstream_puts
- #define __argp_fmtstream_write argp_fmtstream_write
- #define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
- #define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
- #define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
- #define __argp_fmtstream_point argp_fmtstream_point
- #define __argp_fmtstream_update _argp_fmtstream_update
- #define __argp_fmtstream_ensure _argp_fmtstream_ensure
- #endif
- #ifndef ARGP_FS_EI
- #define ARGP_FS_EI __extern_inline
- #endif
- ARGP_FS_EI size_t
- __argp_fmtstream_write (argp_fmtstream_t __fs,
- __const char *__str, size_t __len)
- {
- if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len))
- {
- memcpy (__fs->p, __str, __len);
- __fs->p += __len;
- return __len;
- }
- else
- return 0;
- }
- ARGP_FS_EI int
- __argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str)
- {
- size_t __len = strlen (__str);
- if (__len)
- {
- size_t __wrote = __argp_fmtstream_write (__fs, __str, __len);
- return __wrote == __len ? 0 : -1;
- }
- else
- return 0;
- }
- ARGP_FS_EI int
- __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch)
- {
- if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1))
- return *__fs->p++ = __ch;
- else
- return EOF;
- }
- ARGP_FS_EI size_t
- __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
- {
- size_t __old;
- if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
- __argp_fmtstream_update (__fs);
- __old = __fs->lmargin;
- __fs->lmargin = __lmargin;
- return __old;
- }
- ARGP_FS_EI size_t
- __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
- {
- size_t __old;
- if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
- __argp_fmtstream_update (__fs);
- __old = __fs->rmargin;
- __fs->rmargin = __rmargin;
- return __old;
- }
- ARGP_FS_EI size_t
- __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
- {
- size_t __old;
- if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
- __argp_fmtstream_update (__fs);
- __old = __fs->wmargin;
- __fs->wmargin = __wmargin;
- return __old;
- }
- ARGP_FS_EI size_t
- __argp_fmtstream_point (argp_fmtstream_t __fs)
- {
- if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
- __argp_fmtstream_update (__fs);
- return __fs->point_col >= 0 ? __fs->point_col : 0;
- }
- #if !_LIBC
- #undef __argp_fmtstream_putc
- #undef __argp_fmtstream_puts
- #undef __argp_fmtstream_write
- #undef __argp_fmtstream_set_lmargin
- #undef __argp_fmtstream_set_rmargin
- #undef __argp_fmtstream_set_wmargin
- #undef __argp_fmtstream_point
- #undef __argp_fmtstream_update
- #undef __argp_fmtstream_ensure
- #endif
- #endif
- #endif
- #endif
|