From 3cf52d19581b2077480e7d2e63010baa1f5399c1 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 12 Oct 1999 22:26:06 +0000 Subject: More stuff... --- more.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 13 deletions(-) (limited to 'more.c') diff --git a/more.c b/more.c index 6ac553e6b..f89387436 100644 --- a/more.c +++ b/more.c @@ -19,27 +19,48 @@ * */ + +/* Turning this off makes things a bit smaller (and less pretty) */ +#define BB_MORE_TERM + + + #include "internal.h" #include #include + const char more_usage[] = "[file ...]"; -//#define ERASE_STUFF + +#ifdef BB_MORE_TERM + #include + #include + #include + + FILE *cin; + struct termios initial_settings, new_settings; + + void gotsig(int sig) { + tcsetattr(fileno(cin), TCSANOW, &initial_settings); + exit( TRUE); + } +#endif extern int more_main(int argc, char **argv) { - int c, lines=0; + int c, lines=0, input; int next_page=0, rows = 24; -#ifdef ERASE_STUFF - int cols=79; +#ifdef BB_MORE_TERM + int cols; + struct winsize win; #endif struct stat st; FILE *file = stdin; if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) { fprintf(stderr, "Usage: %s %s", *argv, more_usage); - return(FALSE); + exit(FALSE); } argc--; argv++; @@ -48,23 +69,47 @@ extern int more_main(int argc, char **argv) file = fopen(*argv, "r"); if (file == NULL) { perror("Can't open file"); - return(FALSE); + exit(FALSE); } fstat(fileno(file), &st); fprintf(stderr, "hi\n"); +#ifdef BB_MORE_TERM + cin = fopen("/dev/tty", "r"); + tcgetattr(fileno(cin),&initial_settings); + new_settings = initial_settings; + new_settings.c_lflag &= ~ICANON; + new_settings.c_lflag &= ~ECHO; + tcsetattr(fileno(cin), TCSANOW, &new_settings); + + (void) signal(SIGINT, gotsig); + + ioctl(STDOUT_FILENO, TIOCGWINSZ, &win); + if (win.ws_row > 4) rows = win.ws_row - 2; + if (win.ws_col > 0) cols = win.ws_col - 1; + + +#endif while ((c = getc(file)) != EOF) { if ( next_page ) { int len=0; next_page = 0; lines=0; - len = fprintf(stdout, "--More-- (%d%% of %ld bytes)", + len = fprintf(stdout, "--More-- (%d%% of %ld bytes)%s", (int) (100*( (double) ftell(file) / (double) st.st_size )), - st.st_size); + st.st_size, +#ifdef BB_MORE_TERM + "" +#else + "\n" +#endif + ); + fflush(stdout); - getc( stdin); -#ifdef ERASE_STUFF - /* Try to erase the "More" message */ + input = getc( stdin); + +#ifdef BB_MORE_TERM + /* Erase the "More" message */ while(len-- > 0) putc('\b', stdout); while(len++ < cols) @@ -73,7 +118,12 @@ extern int more_main(int argc, char **argv) putc('\b', stdout); fflush(stdout); #endif + } + if (input=='q') + goto end; + if (input==' ' && c == '\n' ) + next_page = 1; if ( c == '\n' && ++lines == (rows + 1) ) next_page = 1; putc(c, stdout); @@ -84,7 +134,10 @@ extern int more_main(int argc, char **argv) argc--; argv++; } - return(TRUE); +end: +#ifdef BB_MORE_TERM + gotsig(0); +#endif + exit(TRUE); } - -- cgit v1.2.3