/* * This file is part of the UCB release of Plan 9. It is subject to the license * terms in the LICENSE file found in the top-level directory of this * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No * part of the UCB release of Plan 9, including this file, may be copied, * modified, propagated, or distributed except according to the terms contained * in the LICENSE file. */ #include #include #include #define DEF 22 /* lines in chunk: 3*DEF == 66, #lines per nroff page */ Biobuf *cons; Biobuf bout; int pglen = DEF; void printfile(int); void main(int argc, char *argv[]) { int n; int f; if((cons = Bopen("/dev/cons", OREAD)) == 0) { fprint(2, "p: can't open /dev/cons\n"); exits("missing /dev/cons"); } Binit(&bout, 1, OWRITE); n = 0; while(argc > 1) { --argc; argv++; if(*argv[0] == '-'){ pglen = atoi(&argv[0][1]); if(pglen <= 0) pglen = DEF; } else { n++; f = open(argv[0], OREAD); if(f < 0){ fprint(2, "p: can't open %s - %r\n", argv[0]); continue; } printfile(f); close(f); } } if(n == 0) printfile(0); exits(0); } void printfile(int f) { int i, j, n; char *s, *cmd; Biobuf *b; b = malloc(sizeof(Biobuf)); Binit(b, f, OREAD); for(;;){ for(i=1; i <= pglen; i++) { s = Brdline(b, '\n'); if(s == 0){ n = Blinelen(b); if(n > 0) /* line too int32_t for Brdline */ for(j=0; j