Path: utzoo!utgpu!news-server.csri.toronto.edu!csri.toronto.edu!wayne Newsgroups: comp.os.minix From: wayne@csri.toronto.edu (Wayne Hayes) Subject: p.c for Minix (more(1) replacement) Message-ID: <1990Jul23.011015.15237@jarvis.csri.toronto.edu> Organization: CSRI, University of Toronto Date: 23 Jul 90 05:10:15 GMT Lines: 113 Here is p(1) for Minix. It is a simple replacement for more(1), because I'm sick of the long delay it takes more to start up. Has anyone else wondered why such a simple program takes so loooong to start up? Sheesh. For p(1), you just press return for each new screen or press q{return} to quit. It accepts piped input, and accepts an optional single option to set the screen size in lines (default 23, which allows 1 or 2 lines overlap between screens). It'll also take an arbitrary number of files on the command line. It should also compile on any UNIX box. Hey, now that I think of it, it'll probably compile *anywhere*, it's not that specialized... USAGE: p [-linesPerPage] [file_list] --- "The number of programs that can be done with the Hubble Space Telescope has always greatly exceeded the time available for their execution, and this remains true even with the telescope in its current state." -- HST Science Working Group and User's Commitee Report, 1990 June 29. Wayne Hayes INTERNET: wayne@csri.utoronto.ca CompuServe: 72401,3525 ----------------------------- cut here ----------------------------------- /*********** p.c for Minix, by Wayne Hayes wayne@csri.utoronto.ca ********/ #include #include char USAGE[] = "USAGE: p [-linesPerPage] [filename1] [filename2] [...]"; void Fatal(s) char *s; { printf("%s\n", s); exit(1); } int cookedstrlen(s) char *s; { int len; for(len = 0; *s; s++) if(*s == '\t') len += 8 - len % 8; else len++; return len; } #define MAXLINELEN 80 int MAXLINES = 23; static FILE *con; void Wait(fp) FILE *fp; { int c = getc(con); /* each char moves a screen */ if(c == 'q') { fclose(fp); fclose(con); exit(0); } } void p(fp) FILE *fp; { char line[MAXLINELEN]; int n = 0, len; while(fgets(line, sizeof(line), fp)) { len = strlen(line); if(line[len - 1] == '\n') line[len - 1] = '\0'; len = cookedstrlen(line); n += 1 + len / sizeof(line); printf("%s", line); if(n < MAXLINES) putchar('\n'); else { n = 0; Wait(fp); } } } main(argc, argv) char *argv[]; { FILE *in; int i = 1; con = fopen("/dev/tty", "r"); if(argc > 1 && argv[1][0] == '-') { MAXLINES = atoi(argv[1] + 1); if(argv[1][1] == 'h' || argv[1][1] == '?' || MAXLINES < 1) Fatal(USAGE); i++; } if(argc == i) p(stdin); else for( ; i < argc; i++) { if((in=fopen(argv[i], "r")) == NULL) perror(argv[i]); else { printf("%s\n", argv[i]); p(in); if(i < argc - 1) { printf("--EOF--"); Wait(in); fclose(in); } } } fclose(con); }