2 * Mini more implementation for busybox
5 * Copyright (C) 1999 by Lineo, inc.
6 * Blended by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
7 * based on the original more implementation and code from the Debian
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 /* Turning this off makes things a bit smaller (and less pretty) */
38 static const char more_usage[] = "[file ...]";
41 /* ED: sparc termios is broken: revert back to old termio handling. */
45 #if defined (__sparc__)
46 # define USE_OLD_TERMIO
48 # include <sys/ioctl.h>
49 # define termios termio
50 # define stty(fd,argp) ioctl(fd,TCSETAF,argp)
53 # define stty(fd,argp) tcsetattr(fd,TCSANOW,argp)
57 struct termios initial_settings, new_settings;
59 void gotsig(int sig) {
60 stty(fileno(cin), &initial_settings);
65 extern int more_main(int argc, char **argv)
67 int c, lines=0, input=0;
72 if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
83 file = fopen(*argv, "r");
89 fstat(fileno(file), &st);
92 cin = fopen("/dev/tty", "r");
94 cin = fopen("/dev/console", "r");
96 ioctl(fileno(cin),TCGETA,&initial_settings);
98 tcgetattr(fileno(cin),&initial_settings);
100 new_settings = initial_settings;
101 new_settings.c_lflag &= ~ICANON;
102 new_settings.c_lflag &= ~ECHO;
103 stty(fileno(cin), &new_settings);
105 (void) signal(SIGINT, gotsig);
108 while ((c = getc(file)) != EOF) {
113 len = fprintf(stdout, "--More-- ");
115 len += fprintf(stdout, "(%d%% of %ld bytes)",
116 (int) (100*( (double) ftell(file) / (double) st.st_size )),
119 len += fprintf(stdout, "%s",
131 /* Erase the "More" message */
144 if (input==' ' && c == '\n' )
146 if ( c == '\n' && ++lines == 24 )