/* * reverse -- display input in reverse order by line. * * There are six separate cases for this -- regular and non-regular * files by bytes, lines or the whole file. * * BYTES display N bytes * REG mmap the file and display the lines * NOREG cyclically read characters into a wrap-around buffer * * LINES display N lines * REG mmap the file and display the lines * NOREG cyclically read lines into a wrap-around array of buffers * * FILE display the entire file * REG mmap the file and display the lines * NOREG cyclically read input into a linked list of buffers */ void reverse(FILE *fp, enum STYLE style, off_t off, struct stat *sbp) { if (style != REVERSE && off == 0) return; if (S_ISREG(sbp->st_mode)) r_reg(fp, style, off, sbp); else switch(style) { case FBYTES: case RBYTES: bytes(fp, off); break; case FLINES: case RLINES: lines(fp, off); break; case REVERSE: r_buf(fp); break; default: break; } }
/* * reverse -- display input in reverse order by line. * * There are six separate cases for this -- regular and non-regular * files by bytes, lines or the whole file. * * BYTES display N bytes * REG reverse scan and display the lines * NOREG cyclically read characters into a wrap-around buffer * * LINES display N lines * REG reverse scan and display the lines * NOREG cyclically read lines into a wrap-around array of buffers * * FILE display the entire file * REG reverse scan and display the lines * NOREG cyclically read input into a linked list of buffers */ void reverse(FILE *fp, enum STYLE style, off_t off, struct stat *sbp) { if (style != REVERSE && off == 0) return; if (!S_ISREG(sbp->st_mode) || r_reg(fp, style, off, sbp) != 0) switch(style) { case FBYTES: case RBYTES: (void)bytes(fp, off); break; case FLINES: case RLINES: (void)lines(fp, off); break; case REVERSE: r_buf(fp); break; } }