/* * more: do, again, what you'd expect it to do */ #include #include #include /* for strdup() definition */ #include "glob.h" /* * domore() prints a single file, line-by-line */ domore(fd, fn) FILE *fd; char *fn; { static char line_o_text[512]; register line_count = 0; register size, c, i; if (fn) { size = strlen(fn) + 8; for (i=0; i 23) { top:fputs("--more--", stdout);fflush(stdout); c = getch(); fputs("\b\b\b\b\b\b\b\b \b\b\b\b\b\b\b\b", stdout); fflush(stdout); switch (c) { case '\r': line_count--; break; case 'D'-'@': line_count /= 2; break; case ' ': line_count=0; break; case 'n': return 0; case 'b': return -1; case 'q': exit(0); default: putchar(7); goto top; } } } return 1; } /* domore */ /* * end_of_file_prompt() give a [next file is...] prompt and allows you * to 'q','b',[space] on it */ end_of_file_prompt(next) char *next; { register c, i; printf("(next file: %s)", next); fflush(stdout); top:c = getch(); for (i=strlen(next)+13; i>0; i--) fputs("\b \b", stdout); fflush(stdout); switch (c) { default: putchar(7); fflush(stdout); goto top; case 'N': case 'n': return 1; case ' ': case '\r': return 0; case 'Q': case 'q': exit(0); case 'B': case 'b': return -1; } } /* end_of_file_prompt */ /* * more, in the flesh */ main(argc, argv) char **argv; { register i, st; FILE *fd; if (argc > 1) { expand_arglist(argc, argv, (struct args_t*)0); for (i=0; i1)?myargv[i]:(char*)0); fclose(fd); if (st < 0) /* redo same file over again */ i--; else if (isatty(fileno(stdout)) && i < myargc - 1) { /* prompt between files */ while ((st = end_of_file_prompt(myargv[i+1])) > 0) if (++i > myargc-2) exit(0); if (st < 0) i--; } } else fprintf(stderr, "more: can't open %s\n",myargv[i]); } else domore(stdin, (char*)0); exit(0); } /* main */