diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-19 22:26:25 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-19 22:26:25 +0000 |
commit | f5a3838e2ffb1e75b878f9ac48a6951d4d209f5a (patch) | |
tree | b131d6e42bbbcce9eee2417f9ae52de6e5a4374e /util-linux/more.c | |
parent | e674eb78e4cbd52d4b044d8e67d1620b32244e8f (diff) | |
download | busybox-w32-f5a3838e2ffb1e75b878f9ac48a6951d4d209f5a.tar.gz busybox-w32-f5a3838e2ffb1e75b878f9ac48a6951d4d209f5a.tar.bz2 busybox-w32-f5a3838e2ffb1e75b878f9ac48a6951d4d209f5a.zip |
More stuff
Diffstat (limited to 'util-linux/more.c')
-rw-r--r-- | util-linux/more.c | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/util-linux/more.c b/util-linux/more.c index 772d51b18..745ae2bc4 100644 --- a/util-linux/more.c +++ b/util-linux/more.c | |||
@@ -27,22 +27,33 @@ | |||
27 | 27 | ||
28 | #include "internal.h" | 28 | #include "internal.h" |
29 | #include <stdio.h> | 29 | #include <stdio.h> |
30 | #include <fcntl.h> | ||
30 | #include <signal.h> | 31 | #include <signal.h> |
31 | 32 | ||
32 | 33 | ||
33 | static const char more_usage[] = "[file ...]"; | 34 | static const char more_usage[] = "[file ...]"; |
34 | 35 | ||
35 | 36 | ||
37 | /* ED: sparc termios is broken: revert back to old termio handling. */ | ||
36 | #ifdef BB_MORE_TERM | 38 | #ifdef BB_MORE_TERM |
37 | #include <termios.h> | 39 | |
38 | #include <signal.h> | 40 | |
39 | #include <sys/ioctl.h> | 41 | #if defined (__sparc__) |
42 | # define USE_OLD_TERMIO | ||
43 | # include <termio.h> | ||
44 | # include <sys/ioctl.h> | ||
45 | # define termios termio | ||
46 | # define stty(fd,argp) ioctl(fd,TCSETAF,argp) | ||
47 | #else | ||
48 | # include <termios.h> | ||
49 | # define stty(fd,argp) tcsetattr(fd,TCSANOW,argp) | ||
50 | #endif | ||
40 | 51 | ||
41 | FILE *cin; | 52 | FILE *cin; |
42 | struct termios initial_settings, new_settings; | 53 | struct termios initial_settings, new_settings; |
43 | 54 | ||
44 | void gotsig(int sig) { | 55 | void gotsig(int sig) { |
45 | tcsetattr(fileno(cin), TCSANOW, &initial_settings); | 56 | stty(fileno(cin), &initial_settings); |
46 | exit( TRUE); | 57 | exit( TRUE); |
47 | } | 58 | } |
48 | #endif | 59 | #endif |
@@ -50,13 +61,9 @@ static const char more_usage[] = "[file ...]"; | |||
50 | extern int more_main(int argc, char **argv) | 61 | extern int more_main(int argc, char **argv) |
51 | { | 62 | { |
52 | int c, lines=0, input=0; | 63 | int c, lines=0, input=0; |
53 | int next_page=0, rows = 24; | 64 | int next_page=0; |
54 | #ifdef BB_MORE_TERM | ||
55 | int cols=79; | ||
56 | struct winsize win; | ||
57 | #endif | ||
58 | struct stat st; | 65 | struct stat st; |
59 | FILE *file = stdin; | 66 | FILE *file; |
60 | 67 | ||
61 | if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) { | 68 | if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) { |
62 | usage (more_usage); | 69 | usage (more_usage); |
@@ -64,39 +71,48 @@ extern int more_main(int argc, char **argv) | |||
64 | argc--; | 71 | argc--; |
65 | argv++; | 72 | argv++; |
66 | 73 | ||
67 | while (argc-- > 0) { | 74 | while (argc >= 0) { |
75 | if (argc==0) { | ||
76 | file = stdin; | ||
77 | } | ||
78 | else | ||
68 | file = fopen(*argv, "r"); | 79 | file = fopen(*argv, "r"); |
80 | |||
69 | if (file == NULL) { | 81 | if (file == NULL) { |
70 | perror("Can't open file"); | 82 | perror("Can't open file"); |
71 | exit(FALSE); | 83 | exit(FALSE); |
72 | } | 84 | } |
73 | fstat(fileno(file), &st); | 85 | fstat(fileno(file), &st); |
74 | fprintf(stderr, "hi\n"); | ||
75 | 86 | ||
76 | #ifdef BB_MORE_TERM | 87 | #ifdef BB_MORE_TERM |
77 | cin = fopen("/dev/tty", "r"); | 88 | cin = fopen("/dev/tty", "r"); |
89 | if (!cin) | ||
90 | cin = fopen("/dev/console", "r"); | ||
91 | #ifdef USE_OLD_TERMIO | ||
92 | ioctl(fileno(cin),TCGETA,&initial_settings); | ||
93 | #else | ||
78 | tcgetattr(fileno(cin),&initial_settings); | 94 | tcgetattr(fileno(cin),&initial_settings); |
95 | #endif | ||
79 | new_settings = initial_settings; | 96 | new_settings = initial_settings; |
80 | new_settings.c_lflag &= ~ICANON; | 97 | new_settings.c_lflag &= ~ICANON; |
81 | new_settings.c_lflag &= ~ECHO; | 98 | new_settings.c_lflag &= ~ECHO; |
82 | tcsetattr(fileno(cin), TCSANOW, &new_settings); | 99 | stty(fileno(cin), &new_settings); |
83 | 100 | ||
84 | (void) signal(SIGINT, gotsig); | 101 | (void) signal(SIGINT, gotsig); |
85 | 102 | ||
86 | ioctl(STDOUT_FILENO, TIOCGWINSZ, &win); | ||
87 | if (win.ws_row > 4) rows = win.ws_row - 2; | ||
88 | if (win.ws_col > 0) cols = win.ws_col - 1; | ||
89 | |||
90 | |||
91 | #endif | 103 | #endif |
92 | while ((c = getc(file)) != EOF) { | 104 | while ((c = getc(file)) != EOF) { |
93 | if ( next_page ) { | 105 | if ( next_page ) { |
94 | int len=0; | 106 | int len=0; |
95 | next_page = 0; | 107 | next_page = 0; |
96 | lines=0; | 108 | lines=0; |
97 | len = fprintf(stdout, "--More-- (%d%% of %ld bytes)%s", | 109 | len = fprintf(stdout, "--More-- "); |
110 | if (file != stdin) { | ||
111 | len += fprintf(stdout, "(%d%% of %ld bytes)", | ||
98 | (int) (100*( (double) ftell(file) / (double) st.st_size )), | 112 | (int) (100*( (double) ftell(file) / (double) st.st_size )), |
99 | st.st_size, | 113 | st.st_size); |
114 | } | ||
115 | len += fprintf(stdout, "%s", | ||
100 | #ifdef BB_MORE_TERM | 116 | #ifdef BB_MORE_TERM |
101 | "" | 117 | "" |
102 | #else | 118 | #else |
@@ -105,13 +121,13 @@ extern int more_main(int argc, char **argv) | |||
105 | ); | 121 | ); |
106 | 122 | ||
107 | fflush(stdout); | 123 | fflush(stdout); |
108 | input = getc( stdin); | 124 | input = getc( cin); |
109 | 125 | ||
110 | #ifdef BB_MORE_TERM | 126 | #ifdef BB_MORE_TERM |
111 | /* Erase the "More" message */ | 127 | /* Erase the "More" message */ |
112 | while(len-- > 0) | 128 | while(len-- > 0) |
113 | putc('\b', stdout); | 129 | putc('\b', stdout); |
114 | while(len++ < cols) | 130 | while(len++ < 79) |
115 | putc(' ', stdout); | 131 | putc(' ', stdout); |
116 | while(len-- > 0) | 132 | while(len-- > 0) |
117 | putc('\b', stdout); | 133 | putc('\b', stdout); |
@@ -123,7 +139,7 @@ extern int more_main(int argc, char **argv) | |||
123 | goto end; | 139 | goto end; |
124 | if (input==' ' && c == '\n' ) | 140 | if (input==' ' && c == '\n' ) |
125 | next_page = 1; | 141 | next_page = 1; |
126 | if ( c == '\n' && ++lines == (rows + 1) ) | 142 | if ( c == '\n' && ++lines == 24 ) |
127 | next_page = 1; | 143 | next_page = 1; |
128 | putc(c, stdout); | 144 | putc(c, stdout); |
129 | } | 145 | } |