summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2002-09-12 10:51:46 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2002-09-12 10:51:46 +0000
commit520e86d2f64b08c059bfe088b117346c436c6e20 (patch)
tree893ad41a360819fedd2b16ce4aee9d9d793c9b8b /lib
parentd64d942ce5fa35d4d968bd93375645a638a6281e (diff)
downloadmailutils-520e86d2f64b08c059bfe088b117346c436c6e20.tar.gz
mailutils-520e86d2f64b08c059bfe088b117346c436c6e20.tar.bz2
Moved to mailbox
Diffstat (limited to 'lib')
-rw-r--r--lib/argp-fmtstream.h292
-rw-r--r--lib/argp-namefrob.h88
2 files changed, 0 insertions, 380 deletions
diff --git a/lib/argp-fmtstream.h b/lib/argp-fmtstream.h
deleted file mode 100644
index 914d8373c..000000000
--- a/lib/argp-fmtstream.h
+++ /dev/null
@@ -1,292 +0,0 @@
1/* Word-wrapping and line-truncating streams.
2 Copyright (C) 1997, 2001 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Written by Miles Bader <miles@gnu.ai.mit.edu>.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21/* This package emulates glibc `line_wrap_stream' semantics for systems that
22 don't have that. If the system does have it, it is just a wrapper for
23 that. This header file is only used internally while compiling argp, and
24 shouldn't be installed. */
25
26#ifndef _ARGP_FMTSTREAM_H
27#define _ARGP_FMTSTREAM_H
28
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32
33#include <stdio.h>
34#include <string.h>
35#include <unistd.h>
36
37#if (_LIBC - 0 && !defined (USE_IN_LIBIO)) \
38 || (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H))
39/* line_wrap_stream is available, so use that. */
40#define ARGP_FMTSTREAM_USE_LINEWRAP
41#endif
42
43#ifdef ARGP_FMTSTREAM_USE_LINEWRAP
44/* Just be a simple wrapper for line_wrap_stream; the semantics are
45 *slightly* different, as line_wrap_stream doesn't actually make a new
46 object, it just modifies the given stream (reversibly) to do
47 line-wrapping. Since we control who uses this code, it doesn't matter. */
48
49#include <linewrap.h>
50
51typedef FILE *argp_fmtstream_t;
52
53#define argp_make_fmtstream line_wrap_stream
54#define __argp_make_fmtstream line_wrap_stream
55#define argp_fmtstream_free line_unwrap_stream
56#define __argp_fmtstream_free line_unwrap_stream
57
58#define __argp_fmtstream_putc(fs,ch) putc(ch,fs)
59#define argp_fmtstream_putc(fs,ch) putc(ch,fs)
60#define __argp_fmtstream_puts(fs,str) fputs(str,fs)
61#define argp_fmtstream_puts(fs,str) fputs(str,fs)
62#define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
63#define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
64#define __argp_fmtstream_printf fprintf
65#define argp_fmtstream_printf fprintf
66
67#define __argp_fmtstream_lmargin line_wrap_lmargin
68#define argp_fmtstream_lmargin line_wrap_lmargin
69#define __argp_fmtstream_set_lmargin line_wrap_set_lmargin
70#define argp_fmtstream_set_lmargin line_wrap_set_lmargin
71#define __argp_fmtstream_rmargin line_wrap_rmargin
72#define argp_fmtstream_rmargin line_wrap_rmargin
73#define __argp_fmtstream_set_rmargin line_wrap_set_rmargin
74#define argp_fmtstream_set_rmargin line_wrap_set_rmargin
75#define __argp_fmtstream_wmargin line_wrap_wmargin
76#define argp_fmtstream_wmargin line_wrap_wmargin
77#define __argp_fmtstream_set_wmargin line_wrap_set_wmargin
78#define argp_fmtstream_set_wmargin line_wrap_set_wmargin
79#define __argp_fmtstream_point line_wrap_point
80#define argp_fmtstream_point line_wrap_point
81
82#else /* !ARGP_FMTSTREAM_USE_LINEWRAP */
83/* Guess we have to define our own version. */
84
85
86struct argp_fmtstream
87{
88 FILE *stream; /* The stream we're outputting to. */
89
90 size_t lmargin, rmargin; /* Left and right margins. */
91 ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */
92
93 /* Point in buffer to which we've processed for wrapping, but not output. */
94 size_t point_offs;
95 /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */
96 ssize_t point_col;
97
98 char *buf; /* Output buffer. */
99 char *p; /* Current end of text in BUF. */
100 char *end; /* Absolute end of BUF. */
101};
102
103typedef struct argp_fmtstream *argp_fmtstream_t;
104
105/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
106 written on it with LMARGIN spaces and limits them to RMARGIN columns
107 total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
108 replacing the whitespace before them with a newline and WMARGIN spaces.
109 Otherwise, chars beyond RMARGIN are simply dropped until a newline.
110 Returns NULL if there was an error. */
111extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream,
112 size_t __lmargin,
113 size_t __rmargin,
114 ssize_t __wmargin);
115extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream,
116 size_t __lmargin,
117 size_t __rmargin,
118 ssize_t __wmargin);
119
120/* Flush __FS to its stream, and free it (but don't close the stream). */
121extern void __argp_fmtstream_free (argp_fmtstream_t __fs);
122extern void argp_fmtstream_free (argp_fmtstream_t __fs);
123
124extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs,
125 const char *__fmt, ...);
126extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs,
127 const char *__fmt, ...);
128
129extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
130extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
131
132extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str);
133extern int argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str);
134
135extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs,
136 const char *__str, size_t __len);
137extern size_t argp_fmtstream_write (argp_fmtstream_t __fs,
138 const char *__str, size_t __len);
139
140/* Access macros for various bits of state. */
141#define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin)
142#define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin)
143#define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin)
144#define __argp_fmtstream_lmargin argp_fmtstream_lmargin
145#define __argp_fmtstream_rmargin argp_fmtstream_rmargin
146#define __argp_fmtstream_wmargin argp_fmtstream_wmargin
147
148/* Set __FS's left margin to LMARGIN and return the old value. */
149extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
150 size_t __lmargin);
151extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
152 size_t __lmargin);
153
154/* Set __FS's right margin to __RMARGIN and return the old value. */
155extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
156 size_t __rmargin);
157extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
158 size_t __rmargin);
159
160/* Set __FS's wrap margin to __WMARGIN and return the old value. */
161extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
162 size_t __wmargin);
163extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
164 size_t __wmargin);
165
166/* Return the column number of the current output point in __FS. */
167extern size_t argp_fmtstream_point (argp_fmtstream_t __fs);
168extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs);
169
170/* Internal routines. */
171extern void _argp_fmtstream_update (argp_fmtstream_t __fs);
172extern void __argp_fmtstream_update (argp_fmtstream_t __fs);
173extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
174extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
175
176#ifdef __OPTIMIZE__
177/* Inline versions of above routines. */
178
179#if !_LIBC
180#define __argp_fmtstream_putc argp_fmtstream_putc
181#define __argp_fmtstream_puts argp_fmtstream_puts
182#define __argp_fmtstream_write argp_fmtstream_write
183#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
184#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
185#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
186#define __argp_fmtstream_point argp_fmtstream_point
187#define __argp_fmtstream_update _argp_fmtstream_update
188#define __argp_fmtstream_ensure _argp_fmtstream_ensure
189#endif
190
191#ifndef ARGP_FS_EI
192#define ARGP_FS_EI extern inline
193#endif
194
195ARGP_FS_EI size_t
196__argp_fmtstream_write (argp_fmtstream_t __fs,
197 const char *__str, size_t __len)
198{
199 if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len))
200 {
201 memcpy (__fs->p, __str, __len);
202 __fs->p += __len;
203 return __len;
204 }
205 else
206 return 0;
207}
208
209ARGP_FS_EI int
210__argp_fmtstream_puts (argp_fmtstream_t __fs, const char *__str)
211{
212 size_t __len = strlen (__str);
213 if (__len)
214 {
215 size_t __wrote = __argp_fmtstream_write (__fs, __str, __len);
216 return __wrote == __len ? 0 : -1;
217 }
218 else
219 return 0;
220} </