Lines Matching +full:input +full:- +full:style

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
8 * Edward Sze-Tyan Wang.
55 static void r_reg(FILE *, const char *, enum STYLE, off_t, struct stat *);
58 * reverse -- display input in reverse order by line.
60 * There are six separate cases for this -- regular and non-regular
65 * NOREG cyclically read characters into a wrap-around buffer
69 * NOREG cyclically read lines into a wrap-around array of buffers
73 * NOREG cyclically read input into a linked list of buffers
76 reverse(FILE *fp, const char *fn, enum STYLE style, off_t off, struct stat *sbp) in reverse() argument
78 if (style != REVERSE && off == 0) in reverse()
81 if (S_ISREG(sbp->st_mode)) in reverse()
82 r_reg(fp, fn, style, off, sbp); in reverse()
84 switch(style) { in reverse()
102 * r_reg -- display a regular file in reverse order by line.
105 r_reg(FILE *fp, const char *fn, enum STYLE style, off_t off, struct stat *sbp) in r_reg() argument
111 if (!(size = sbp->st_size)) in r_reg()
121 * size == 0 is dealt with above, and size == 1 sets curoff to -1. in r_reg()
123 curoff = size - 2; in r_reg()
133 for (i = curoff - map.mapoff; i >= 0; i--) { in r_reg()
134 if (style == RBYTES && --off == 0) in r_reg()
139 /* `i' is either the map offset of a '\n', or -1. */ in r_reg()
145 if (mapprint(&map, curoff + 1, lineend - curoff - 1) != 0) { in r_reg()
150 curoff--; in r_reg()
152 if (style == RLINES) in r_reg()
153 off--; in r_reg()
155 if (off == 0 && style != REVERSE) { in r_reg()
177 * r_buf -- display a non-regular file in reverse order by line.
179 * This is the function that saves the entire input, storing the data in a
183 * particular buffer. If we run out of memory, input is discarded (and the
209 enomem += first->len; in r_buf()
215 /* Fill the block with input data. */ in r_buf()
218 p = tl->l + len; in r_buf()
219 len += fread(p, 1, BSZ - len, fp); in r_buf()
226 tl->len = len; in r_buf()
247 for (p = tl->l + tl->len - 1, llen = 0; p >= tl->l; in r_buf()
248 --p, ++llen) { in r_buf()
249 int start = (tl == first && p == tl->l); in r_buf()
266 if (tr->len) in r_buf()
267 WR(&tr->l, tr->len); in r_buf()
275 tl->len = llen; in r_buf()