static void wc(FILE *fp, const char *str) { int word = 0, rlen; Rune c; size_t nc = 0, nl = 0, nw = 0; while ((rlen = efgetrune(&c, fp, str))) { nc += (cmode == 'c' || !cmode) ? rlen : (c != Runeerror); if (c == '\n') nl++; if (!isspacerune(c)) word = 1; else if (word) { word = 0; nw++; } } if (word) nw++; tc += nc; tl += nl; tw += nw; output(str, nc, nl, nw); }
static void sequential(struct fdescr *dsc, int fdescrlen, Rune *delim, size_t delimlen) { Rune c, last; size_t i, d; for (i = 0; i < fdescrlen; i++) { d = 0; last = 0; while (efgetrune(&c, dsc[i].fp, dsc[i].name)) { if (last == '\n') { if (delim[d] != '\0') efputrune(&delim[d], stdout, "<stdout>"); d = (d + 1) % delimlen; } if (c != '\n') efputrune(&c, stdout, "<stdout>"); last = c; } if (last == '\n') efputrune(&last, stdout, "<stdout>"); } }
static void strings(FILE *fp, const char *fname, size_t len) { Rune r, *rbuf; size_t i, bread; off_t off; rbuf = ereallocarray(NULL, len, sizeof(*rbuf)); for (off = 0, i = 0; (bread = efgetrune(&r, fp, fname)); ) { off += bread; if (r == Runeerror) continue; if (!isprintrune(r)) { if (i > len) putchar('\n'); i = 0; continue; } if (i < len) { rbuf[i++] = r; continue; } else if (i > len) { efputrune(&r, stdout, "<stdout>"); continue; } printf(format, (long)off - i); for (i = 0; i < len; i++) efputrune(rbuf + i, stdout, "<stdout>"); efputrune(&r, stdout, "<stdout>"); i++; } free(rbuf); }
static void unexpand(const char *file, FILE *fp) { Rune r; size_t last = 0, col = 0, i; int bol = 1; while (efgetrune(&r, fp, file)) { switch (r) { case ' ': if (!bol && !aflag) last++; col++; break; case '\t': if (tablistlen == 1) { if (!bol && !aflag) last += tablist[0] - col % tablist[0]; col += tablist[0] - col % tablist[0]; } else { for (i = 0; i < tablistlen; i++) if (col < tablist[i]) break; if (!bol && !aflag) last = tablist[i]; col = tablist[i]; } break; case '\b': if (bol || aflag) unexpandspan(last, col); col -= (col > 0); last = col; bol = 0; break; case '\n': if (bol || aflag) unexpandspan(last, col); last = col = 0; bol = 1; break; default: if (bol || aflag) unexpandspan(last, col); last = ++col; bol = 0; break; } if ((r != ' ' && r != '\t') || (!aflag && !bol)) efputrune(&r, stdout, "<stdout>"); } if (last < col && (bol || aflag)) unexpandspan(last, col); }
static void parallel(struct fdescr *dsc, int fdescrlen, Rune *delim, size_t delimlen) { Rune c, d; size_t i, m; ssize_t last; nextline: last = -1; for (i = 0; i < fdescrlen; i++) { d = delim[i % delimlen]; c = 0; for (; efgetrune(&c, dsc[i].fp, dsc[i].name) ;) { for (m = last + 1; m < i; m++) efputrune(&(delim[m % delimlen]), stdout, "<stdout>"); last = i; if (c == '\n') { if (i != fdescrlen - 1) c = d; efputrune(&c, stdout, "<stdout>"); break; } efputrune(&c, stdout, "<stdout>"); } if (c == 0 && last != -1) { if (i == fdescrlen - 1) putchar('\n'); else efputrune(&d, stdout, "<stdout>"); last++; } } if (last != -1) goto nextline; }