aboutsummaryrefslogtreecommitdiff
path: root/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 /more.c
parent2ce1edcf544ac675e6762c9861a6b918401ea716 (diff)
downloadbusybox-3cf52d19581b2077480e7d2e63010baa1f5399c1.tar.gz
More stuff...
Diffstat (limited to 'more.c')
-rw-r--r--more.c79
1 files changed, 66 insertions, 13 deletions
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 <stdio.h>
#include <signal.h>
+
const char more_usage[] = "[file ...]";
-//#define ERASE_STUFF
+
+#ifdef BB_MORE_TERM
+ #include <termios.h>
+ #include <signal.h>
+ #include <sys/ioctl.h>
+
+ 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);
}
-