summaryrefslogtreecommitdiff
path: root/util-linux/more.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-12 22:26:06 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-12 22:26:06 +0000
commit3cf52d19581b2077480e7d2e63010baa1f5399c1 (patch)
treed91b0cb332ebc976126e36a394655dde7a15d8b1 /util-linux/more.c
parent2ce1edcf544ac675e6762c9861a6b918401ea716 (diff)
downloadbusybox-w32-3cf52d19581b2077480e7d2e63010baa1f5399c1.tar.gz
busybox-w32-3cf52d19581b2077480e7d2e63010baa1f5399c1.tar.bz2
busybox-w32-3cf52d19581b2077480e7d2e63010baa1f5399c1.zip
More stuff...
Diffstat (limited to 'util-linux/more.c')
-rw-r--r--util-linux/more.c79
1 files changed, 66 insertions, 13 deletions
diff --git a/util-linux/more.c b/util-linux/more.c
index 6ac553e6b..f89387436 100644
--- a/util-linux/more.c
+++ b/util-linux/more.c
@@ -19,27 +19,48 @@
19 * 19 *
20 */ 20 */
21 21
22
23/* Turning this off makes things a bit smaller (and less pretty) */
24#define BB_MORE_TERM
25
26
27
22#include "internal.h" 28#include "internal.h"
23#include <stdio.h> 29#include <stdio.h>
24#include <signal.h> 30#include <signal.h>
25 31
32
26const char more_usage[] = "[file ...]"; 33const char more_usage[] = "[file ...]";
27 34
28//#define ERASE_STUFF 35
36#ifdef BB_MORE_TERM
37 #include <termios.h>
38 #include <signal.h>
39 #include <sys/ioctl.h>
40
41 FILE *cin;
42 struct termios initial_settings, new_settings;
43
44 void gotsig(int sig) {
45 tcsetattr(fileno(cin), TCSANOW, &initial_settings);
46 exit( TRUE);
47 }
48#endif
29 49
30extern int more_main(int argc, char **argv) 50extern int more_main(int argc, char **argv)
31{ 51{
32 int c, lines=0; 52 int c, lines=0, input;
33 int next_page=0, rows = 24; 53 int next_page=0, rows = 24;
34#ifdef ERASE_STUFF 54#ifdef BB_MORE_TERM
35 int cols=79; 55 int cols;
56 struct winsize win;
36#endif 57#endif
37 struct stat st; 58 struct stat st;
38 FILE *file = stdin; 59 FILE *file = stdin;
39 60
40 if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) { 61 if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
41 fprintf(stderr, "Usage: %s %s", *argv, more_usage); 62 fprintf(stderr, "Usage: %s %s", *argv, more_usage);
42 return(FALSE); 63 exit(FALSE);
43 } 64 }
44 argc--; 65 argc--;
45 argv++; 66 argv++;
@@ -48,23 +69,47 @@ extern int more_main(int argc, char **argv)
48 file = fopen(*argv, "r"); 69 file = fopen(*argv, "r");
49 if (file == NULL) { 70 if (file == NULL) {
50 perror("Can't open file"); 71 perror("Can't open file");
51 return(FALSE); 72 exit(FALSE);
52 } 73 }
53 fstat(fileno(file), &st); 74 fstat(fileno(file), &st);
54 fprintf(stderr, "hi\n"); 75 fprintf(stderr, "hi\n");
55 76
77#ifdef BB_MORE_TERM
78 cin = fopen("/dev/tty", "r");
79 tcgetattr(fileno(cin),&initial_settings);
80 new_settings = initial_settings;
81 new_settings.c_lflag &= ~ICANON;
82 new_settings.c_lflag &= ~ECHO;
83 tcsetattr(fileno(cin), TCSANOW, &new_settings);
84
85 (void) signal(SIGINT, gotsig);
86
87 ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
88 if (win.ws_row > 4) rows = win.ws_row - 2;
89 if (win.ws_col > 0) cols = win.ws_col - 1;
90
91
92#endif
56 while ((c = getc(file)) != EOF) { 93 while ((c = getc(file)) != EOF) {
57 if ( next_page ) { 94 if ( next_page ) {
58 int len=0; 95 int len=0;
59 next_page = 0; 96 next_page = 0;
60 lines=0; 97 lines=0;
61 len = fprintf(stdout, "--More-- (%d%% of %ld bytes)", 98 len = fprintf(stdout, "--More-- (%d%% of %ld bytes)%s",
62 (int) (100*( (double) ftell(file) / (double) st.st_size )), 99 (int) (100*( (double) ftell(file) / (double) st.st_size )),
63 st.st_size); 100 st.st_size,
101#ifdef BB_MORE_TERM
102 ""
103#else
104 "\n"
105#endif
106 );
107
64 fflush(stdout); 108 fflush(stdout);
65 getc( stdin); 109 input = getc( stdin);
66#ifdef ERASE_STUFF 110
67 /* Try to erase the "More" message */ 111#ifdef BB_MORE_TERM
112 /* Erase the "More" message */
68 while(len-- > 0) 113 while(len-- > 0)
69 putc('\b', stdout); 114 putc('\b', stdout);
70 while(len++ < cols) 115 while(len++ < cols)
@@ -73,7 +118,12 @@ extern int more_main(int argc, char **argv)
73 putc('\b', stdout); 118 putc('\b', stdout);
74 fflush(stdout); 119 fflush(stdout);
75#endif 120#endif
121
76 } 122 }
123 if (input=='q')
124 goto end;
125 if (input==' ' && c == '\n' )
126 next_page = 1;
77 if ( c == '\n' && ++lines == (rows + 1) ) 127 if ( c == '\n' && ++lines == (rows + 1) )
78 next_page = 1; 128 next_page = 1;
79 putc(c, stdout); 129 putc(c, stdout);
@@ -84,7 +134,10 @@ extern int more_main(int argc, char **argv)
84 argc--; 134 argc--;
85 argv++; 135 argv++;
86 } 136 }
87 return(TRUE); 137end:
138#ifdef BB_MORE_TERM
139 gotsig(0);
140#endif
141 exit(TRUE);
88} 142}
89 143
90