* elf/Makefile (subdir_lib): Change this target to lib-noranlib.
[glibc.git] / stdio / linewrap.h
blob7ba337fad29a3800f1d9e6d17767f0c2e9d1e36c
1 /* Word-wrapping and line-truncating streams.
2 Copyright (C) 1996 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
18 Cambridge, MA 02139, USA. */
20 #ifndef __LINEWRAP_H__
21 #define __LINEWRAP_H__
23 #include <stdio.h>
24 #include <ctype.h>
25 #include <string.h>
27 #include <features.h>
29 #include <string.h> /* Need size_t. */
31 __BEGIN_DECLS
33 /* We keep this data for each line-wrapping stream. */
34 struct line_wrap_data
36 size_t lmargin, rmargin; /* Left and right margins. */
37 size_t wmargin; /* Margin to wrap to, or -1 to truncate. */
38 size_t point; /* Current column of last chars flushed. */
40 /* Original cookie and hooks from the stream. */
41 void *cookie;
42 void (*output) (FILE *, int);
43 __io_close_fn *close;
44 __io_fileno_fn *fileno;
45 __io_seek_fn *seek;
48 /* Modify STREAM so that it prefixes lines written on it with LMARGIN spaces
49 and limits them to RMARGIN columns total. If WMARGIN >= 0, words that
50 extend past RMARGIN are wrapped by replacing the whitespace before them
51 with a newline and WMARGIN spaces. Otherwise, chars beyond RMARGIN are
52 simply dropped until a newline. Returns STREAM after modifying it, or
53 NULL if there was an error. */
54 FILE *line_wrap_stream (FILE *stream,
55 size_t lmargin, size_t rmargin, size_t wmargin);
57 /* Remove the hooks placed in STREAM by `line_wrap_stream'. */
58 void line_unwrap_stream (FILE *stream);
60 /* Returns true if STREAM is line wrapped. */
61 extern inline int line_wrapped (FILE *stream);
63 /* If STREAM is not line-wrapped return -1, else return its left margin. */
64 extern size_t line_wrap_lmargin (FILE *stream);
66 /* If STREAM is not line-wrapped return -1, else set its left margin to
67 LMARGIN and return the old value. */
68 extern size_t line_wrap_set_lmargin (FILE *stream, size_t lmargin);
70 /* If STREAM is not line-wrapped return -1, else return its left margin. */
71 extern size_t line_wrap_rmargin (FILE *stream);
73 /* If STREAM is not line-wrapped return -1, else set its right margin to
74 RMARGIN and return the old value. */
75 extern size_t line_wrap_set_rmargin (FILE *stream, size_t rmargin);
77 /* If STREAM is not line-wrapped return -1, else return its wrap margin. */
78 extern size_t line_wrap_wmargin (FILE *stream);
80 /* If STREAM is not line-wrapped return -1, else set its left margin to
81 WMARGIN and return the old value. */
82 extern size_t line_wrap_set_wmargin (FILE *stream, size_t wmargin);
84 /* If STREAM is not line-wrapped return -1, else return the column number of
85 the current output point. */
86 extern size_t line_wrap_point (FILE *stream);
89 #ifdef __OPTIMIZE__
91 extern void __line_wrap_output (FILE *, int); /* private */
93 /* Returns true if STREAM is line wrapped. */
94 extern inline int
95 line_wrapped (FILE *stream)
97 return (stream->__room_funcs.__output == &__line_wrap_output);
100 /* If STREAM is not line-wrapped return -1, else return its left margin. */
101 extern inline size_t
102 line_wrap_lmargin (FILE *stream)
104 if (! line_wrapped (stream))
105 return -1;
106 return ((struct line_wrap_data *)stream->__cookie)->lmargin;
109 /* If STREAM is not line-wrapped return -1, else set its left margin to
110 LMARGIN and return the old value. */
111 extern inline size_t
112 line_wrap_set_lmargin (FILE *stream, size_t lmargin)
114 if (! line_wrapped (stream))
115 return -1;
116 else
118 struct line_wrap_data *d = stream->__cookie;
119 size_t old = d->lmargin;
120 d->lmargin = lmargin;
121 return old;
125 /* If STREAM is not line-wrapped return -1, else return its left margin. */
126 extern inline size_t
127 line_wrap_rmargin (FILE *stream)
129 if (! line_wrapped (stream))
130 return -1;
131 return ((struct line_wrap_data *)stream->__cookie)->rmargin;
134 /* If STREAM is not line-wrapped return -1, else set its right margin to
135 RMARGIN and return the old value. */
136 extern inline size_t
137 line_wrap_set_rmargin (FILE *stream, size_t rmargin)
139 if (! line_wrapped (stream))
140 return -1;
141 else
143 struct line_wrap_data *d = stream->__cookie;
144 size_t old = d->rmargin;
145 d->rmargin = rmargin;
146 return old;
150 /* If STREAM is not line-wrapped return -1, else return its wrap margin. */
151 extern inline size_t
152 line_wrap_wmargin (FILE *stream)
154 if (! line_wrapped (stream))
155 return -1;
156 return ((struct line_wrap_data *)stream->__cookie)->wmargin;
159 /* If STREAM is not line-wrapped return -1, else set its left margin to
160 WMARGIN and return the old value. */
161 extern inline size_t
162 line_wrap_set_wmargin (FILE *stream, size_t wmargin)
164 if (! line_wrapped (stream))
165 return -1;
166 else
168 struct line_wrap_data *d = stream->__cookie;
169 size_t old = d->wmargin;
170 d->wmargin = wmargin;
171 return old;
175 /* If STREAM is not line-wrapped return -1, else return the column number of
176 the current output point. */
177 extern inline size_t
178 line_wrap_point (FILE *stream)
180 if (! line_wrapped (stream))
181 return -1;
182 return ((struct line_wrap_data *)stream->__cookie)->point;
185 #endif /* Optimizing. */
187 __END_DECLS
189 #endif /* __LINEWRAP_H__ */