1 /* col - eliminate reverse line feeds */
14 Tabstop = 8, /* must be power of 2 */
17 static int bflag, xflag, fflag;
20 static int ll, llh, mustwr;
23 static char *page[PL];
25 static char lbuff[LINELN];
26 static Biobuf bin, bout;
28 void emit(char *s, int lineno);
29 void incr(void), decr(void);
35 fprint(2, "usage: %s [-bfx]\n", argv0);
40 main(int argc, char **argv)
60 for (ll=0; ll < PL; ll++)
68 Binit(&bin, 0, OREAD);
69 Binit(&bout, 1, OWRITE);
70 while ((ch = Bgetrune(&bin)) != Beof) {
85 case '7': /* reverse full line feed */
90 case '8': /* reverse half line feed */
101 case '9': /* forward half line feed */
124 cp = (cp + Tabstop) & -Tabstop;
137 if (!isascii(c) || isprint(c)) {
145 for (i=0; i < PL; i++) {
146 lno = (mustwr+i) % PL;
148 emit(page[lno], mustwr+i-PL);
150 emit(" ", (llh + 1) & -2);
177 while (*line == '\b')
179 if (bflag || *line == '\0' || *line == ' ')
180 cp += runetochar(line, &c) - 1;
203 if (page[lno] != nil)
205 page[lno] = malloc((unsigned)strlen(lbuff) + 2);
206 if (page[lno] == nil)
207 sysfatal("out of memory");
208 strcpy(page[lno], lbuff);
223 strcpy(line, page[lno]);
227 emit(char *s, int lineno)
231 static int cline = 0;
234 while (cline < lineno - 1) {
239 if (cline != lineno) {
251 if ((++ncp & 7) == 0 && !xflag) {
279 if (ll >= mustwr && page[lno]) {
280 emit(page[lno], ll - PL);
291 if (ll > mustwr - PL) {