diff options
author | Miles Bader <miles@gnu.org> | 1996-07-07 16:54:03 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1996-07-07 16:54:03 +0000 |
commit | 99ed3e3909cc9be0a853f2e1de83e70fa9c1ff46 (patch) | |
tree | 2023c8a6ad35482188de05014c757f3e5346c764 /stdio | |
parent | dd411cc7bc2ffdd07364c2abf0a4ea13cd26d79d (diff) | |
download | glibc-99ed3e3909cc9be0a853f2e1de83e70fa9c1ff46.tar.gz |
Sun Jun 2 22:28:43 1996 Miles Bader <miles@gnu.ai.mit.edu>
* linewrap.c (lwupdate): Update D->point_offs when done.
Use memmove instead of memcpy where overlap is possible (not
necessary using current implementation of memcpy, but...).
(__line_wrap_update): Don't update D->point_offs (lwupdate does it).
Fri May 31 11:48:46 1996 Miles Bader <miles@gnu.ai.mit.edu>
* linewrap.c (lwupdate): New function, mostly was __line_wrap_update.
Use POINT_COL field instead of POINT.
(__line_wrap_output): Use lwupdate.
(__line_wrap_update): New function.
(ensure_unwrapped, ensure_wrapped): New functions.
(line_wrap_set_lmargin, line_wrap_set_rmargin,
line_wrap_set_wmargin, line_wrap_point): Use __line_wrap_update.
* linewrap.h (struct line_wrap_data): Rename POINT field to POINT_COL.
Add POINT_OFFS field.
(__line_wrap_update): New decl.
(line_wrap_set_lmargin, line_wrap_set_rmargin,
line_wrap_set_wmargin, line_wrap_point): Use __line_wrap_update.
Diffstat (limited to 'stdio')
-rw-r--r-- | stdio/linewrap.h | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/stdio/linewrap.h b/stdio/linewrap.h index 7ba337fad2..c569238803 100644 --- a/stdio/linewrap.h +++ b/stdio/linewrap.h @@ -35,7 +35,12 @@ struct line_wrap_data { size_t lmargin, rmargin; /* Left and right margins. */ size_t wmargin; /* Margin to wrap to, or -1 to truncate. */ - size_t point; /* Current column of last chars flushed. */ + + /* Point in stdio buffer to which we've processed for wrapping, but + not output. */ + size_t point_offs; + /* Output column at POINT_OFFS. */ + size_t point_col; /* Original cookie and hooks from the stream. */ void *cookie; @@ -85,11 +90,18 @@ extern size_t line_wrap_set_wmargin (FILE *stream, size_t wmargin); the current output point. */ extern size_t line_wrap_point (FILE *stream); - #ifdef __OPTIMIZE__ extern void __line_wrap_output (FILE *, int); /* private */ +/* If STREAM is not line-wrapped, return 0. Otherwise all pending text + buffered text in STREAM so that the POINT_OFFS field refers to the last + position in the stdio buffer, and return the line wrap state object for + STREAM. Since all text has been processed, this means that (1) the + POINT_COL field refers to the column at which any new text would be added, + and (2) any changes to the margin parameters will only affect new text. */ +extern struct line_wrap_data *__line_wrap_update (FILE *stream); /* private */ + /* Returns true if STREAM is line wrapped. */ extern inline int line_wrapped (FILE *stream) @@ -111,15 +123,15 @@ line_wrap_lmargin (FILE *stream) extern inline size_t line_wrap_set_lmargin (FILE *stream, size_t lmargin) { - if (! line_wrapped (stream)) - return -1; - else + struct line_wrap_data *d = __line_wrap_update (stream); + if (d) { - struct line_wrap_data *d = stream->__cookie; size_t old = d->lmargin; d->lmargin = lmargin; return old; } + else + return -1; } /* If STREAM is not line-wrapped return -1, else return its left margin. */ @@ -136,15 +148,15 @@ line_wrap_rmargin (FILE *stream) extern inline size_t line_wrap_set_rmargin (FILE *stream, size_t rmargin) { - if (! line_wrapped (stream)) - return -1; - else + struct line_wrap_data *d = __line_wrap_update (stream); + if (d) { - struct line_wrap_data *d = stream->__cookie; size_t old = d->rmargin; d->rmargin = rmargin; return old; } + else + return -1; } /* If STREAM is not line-wrapped return -1, else return its wrap margin. */ @@ -161,15 +173,15 @@ line_wrap_wmargin (FILE *stream) extern inline size_t line_wrap_set_wmargin (FILE *stream, size_t wmargin) { - if (! line_wrapped (stream)) - return -1; - else + struct line_wrap_data *d = __line_wrap_update (stream); + if (d) { - struct line_wrap_data *d = stream->__cookie; size_t old = d->wmargin; d->wmargin = wmargin; return old; } + else + return -1; } /* If STREAM is not line-wrapped return -1, else return the column number of @@ -177,9 +189,8 @@ line_wrap_set_wmargin (FILE *stream, size_t wmargin) extern inline size_t line_wrap_point (FILE *stream) { - if (! line_wrapped (stream)) - return -1; - return ((struct line_wrap_data *)stream->__cookie)->point; + struct line_wrap_data *d = __line_wrap_update (stream); + return d ? d->point_col : -1; } #endif /* Optimizing. */ |