diff options
| author | Eric Andersen <andersen@codepoet.org> | 1999-10-06 00:30:51 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 1999-10-06 00:30:51 +0000 |
| commit | 4bea32abb5d25e3b83047c22fd3f4e8fae2479cd (patch) | |
| tree | c8aad7a8b8c573c2421b7fb3e58fdd00a3c1fe9b | |
| parent | 2b69c40e8060934c115922c012737bd471956f09 (diff) | |
| download | busybox-w32-4bea32abb5d25e3b83047c22fd3f4e8fae2479cd.tar.gz busybox-w32-4bea32abb5d25e3b83047c22fd3f4e8fae2479cd.tar.bz2 busybox-w32-4bea32abb5d25e3b83047c22fd3f4e8fae2479cd.zip | |
latest and greatest.
| -rw-r--r-- | applets/busybox.c | 2 | ||||
| -rw-r--r-- | busybox.c | 2 | ||||
| -rw-r--r-- | busybox.def.h | 4 | ||||
| -rw-r--r-- | chown.c | 4 | ||||
| -rw-r--r-- | coreutils/chown.c | 4 | ||||
| -rw-r--r-- | coreutils/date.c | 12 | ||||
| -rw-r--r-- | date.c | 12 | ||||
| -rw-r--r-- | internal.h | 1 | ||||
| -rw-r--r-- | more.c | 169 | ||||
| -rw-r--r-- | util-linux/more.c | 169 |
10 files changed, 171 insertions, 208 deletions
diff --git a/applets/busybox.c b/applets/busybox.c index 08ba88d65..9986af389 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
| @@ -102,7 +102,7 @@ static const struct Applet applets[] = { | |||
| 102 | {"mnc", mnc_main}, | 102 | {"mnc", mnc_main}, |
| 103 | #endif | 103 | #endif |
| 104 | #ifdef BB_MORE //bin | 104 | #ifdef BB_MORE //bin |
| 105 | {"more", cat_more_main}, | 105 | {"more", more_main}, |
| 106 | #endif | 106 | #endif |
| 107 | #ifdef BB_MOUNT //bin | 107 | #ifdef BB_MOUNT //bin |
| 108 | {"mount", mount_main}, | 108 | {"mount", mount_main}, |
| @@ -102,7 +102,7 @@ static const struct Applet applets[] = { | |||
| 102 | {"mnc", mnc_main}, | 102 | {"mnc", mnc_main}, |
| 103 | #endif | 103 | #endif |
| 104 | #ifdef BB_MORE //bin | 104 | #ifdef BB_MORE //bin |
| 105 | {"more", cat_more_main}, | 105 | {"more", more_main}, |
| 106 | #endif | 106 | #endif |
| 107 | #ifdef BB_MOUNT //bin | 107 | #ifdef BB_MOUNT //bin |
| 108 | {"mount", mount_main}, | 108 | {"mount", mount_main}, |
diff --git a/busybox.def.h b/busybox.def.h index 7d49ed0c2..2fc50b448 100644 --- a/busybox.def.h +++ b/busybox.def.h | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | #define BB_CHROOT | 11 | #define BB_CHROOT |
| 12 | #define BB_CLEAR | 12 | #define BB_CLEAR |
| 13 | //#define BB_CP | 13 | //#define BB_CP |
| 14 | //#define BB_DATE | 14 | #define BB_DATE |
| 15 | //#define BB_DD | 15 | //#define BB_DD |
| 16 | //#define BB_DESCEND | 16 | //#define BB_DESCEND |
| 17 | //#define BB_DF | 17 | //#define BB_DF |
| @@ -39,7 +39,7 @@ | |||
| 39 | ////#define BB_MKSWAP | 39 | ////#define BB_MKSWAP |
| 40 | //#define BB_MNC | 40 | //#define BB_MNC |
| 41 | //#define BB_MONADIC | 41 | //#define BB_MONADIC |
| 42 | //#define BB_MORE | 42 | #define BB_MORE |
| 43 | //#define BB_MOUNT | 43 | //#define BB_MOUNT |
| 44 | ////#define BB_MT | 44 | ////#define BB_MT |
| 45 | //#define BB_MV | 45 | //#define BB_MV |
| @@ -31,10 +31,10 @@ static int chownApp; | |||
| 31 | static char* invocationName=NULL; | 31 | static char* invocationName=NULL; |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | const char chgrp_usage[] = "[OPTION]... GROUP FILE...\n" | 34 | static const char chgrp_usage[] = "[OPTION]... GROUP FILE...\n" |
| 35 | "Change the group membership of each FILE to GROUP.\n" | 35 | "Change the group membership of each FILE to GROUP.\n" |
| 36 | "\n\tOptions:\n" "\t-R\tchange files and directories recursively\n"; | 36 | "\n\tOptions:\n" "\t-R\tchange files and directories recursively\n"; |
| 37 | const char chown_usage[] = "[OPTION]... OWNER[.[GROUP] FILE...\n" | 37 | static const char chown_usage[] = "[OPTION]... OWNER[.[GROUP] FILE...\n" |
| 38 | "Change the owner and/or group of each FILE to OWNER and/or GROUP.\n" | 38 | "Change the owner and/or group of each FILE to OWNER and/or GROUP.\n" |
| 39 | "\n\tOptions:\n" "\t-R\tchange files and directories recursively\n"; | 39 | "\n\tOptions:\n" "\t-R\tchange files and directories recursively\n"; |
| 40 | 40 | ||
diff --git a/coreutils/chown.c b/coreutils/chown.c index fc0c2424f..5c2ae0da6 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c | |||
| @@ -31,10 +31,10 @@ static int chownApp; | |||
| 31 | static char* invocationName=NULL; | 31 | static char* invocationName=NULL; |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | const char chgrp_usage[] = "[OPTION]... GROUP FILE...\n" | 34 | static const char chgrp_usage[] = "[OPTION]... GROUP FILE...\n" |
| 35 | "Change the group membership of each FILE to GROUP.\n" | 35 | "Change the group membership of each FILE to GROUP.\n" |
| 36 | "\n\tOptions:\n" "\t-R\tchange files and directories recursively\n"; | 36 | "\n\tOptions:\n" "\t-R\tchange files and directories recursively\n"; |
| 37 | const char chown_usage[] = "[OPTION]... OWNER[.[GROUP] FILE...\n" | 37 | static const char chown_usage[] = "[OPTION]... OWNER[.[GROUP] FILE...\n" |
| 38 | "Change the owner and/or group of each FILE to OWNER and/or GROUP.\n" | 38 | "Change the owner and/or group of each FILE to OWNER and/or GROUP.\n" |
| 39 | "\n\tOptions:\n" "\t-R\tchange files and directories recursively\n"; | 39 | "\n\tOptions:\n" "\t-R\tchange files and directories recursively\n"; |
| 40 | 40 | ||
diff --git a/coreutils/date.c b/coreutils/date.c index a52a9a4a8..558517086 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
| @@ -14,7 +14,13 @@ | |||
| 14 | an RFC 822 complient date output for shell scripting | 14 | an RFC 822 complient date output for shell scripting |
| 15 | mail commands */ | 15 | mail commands */ |
| 16 | 16 | ||
| 17 | const char date_usage[] = "date [-uR] [+FORMAT|+%f] [ [-s|-d] MMDDhhmm[[CC]YY]\n | [[[[CCYY.]MM.DD-]hh:mm[:ss]]]] ]"; | 17 | const char date_usage[] = "date [-uR] [+FORMAT|+%f] [ [-s|-d] MMDDhhmm[[CC]YY]\n" |
| 18 | "| [[[[CCYY.]MM.DD-]hh:mm[:ss]]]] ]"; | ||
| 19 | |||
| 20 | //static const char date_usage[] = "Usage: date [OPTION]... [+FORMAT]\n" | ||
| 21 | //"or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n" | ||
| 22 | //"Display the current time in the given FORMAT, or set the system date.\n"; | ||
| 23 | |||
| 18 | 24 | ||
| 19 | static struct option const long_options[] = | 25 | static struct option const long_options[] = |
| 20 | { | 26 | { |
| @@ -153,7 +159,7 @@ date_err(void) { | |||
| 153 | } | 159 | } |
| 154 | 160 | ||
| 155 | int | 161 | int |
| 156 | date_main(struct FileInfo * i, int argc, char * * argv) | 162 | date_main(int argc, char * * argv) |
| 157 | { | 163 | { |
| 158 | char *date_str = NULL; | 164 | char *date_str = NULL; |
| 159 | char *date_fmt = NULL; | 165 | char *date_fmt = NULL; |
| @@ -203,7 +209,7 @@ date_main(struct FileInfo * i, int argc, char * * argv) | |||
| 203 | break; | 209 | break; |
| 204 | 210 | ||
| 205 | default: | 211 | default: |
| 206 | usage(date_usage); | 212 | fprintf(stderr, "Usage: %s", date_usage); |
| 207 | break; | 213 | break; |
| 208 | } | 214 | } |
| 209 | } | 215 | } |
| @@ -14,7 +14,13 @@ | |||
| 14 | an RFC 822 complient date output for shell scripting | 14 | an RFC 822 complient date output for shell scripting |
| 15 | mail commands */ | 15 | mail commands */ |
| 16 | 16 | ||
| 17 | const char date_usage[] = "date [-uR] [+FORMAT|+%f] [ [-s|-d] MMDDhhmm[[CC]YY]\n | [[[[CCYY.]MM.DD-]hh:mm[:ss]]]] ]"; | 17 | const char date_usage[] = "date [-uR] [+FORMAT|+%f] [ [-s|-d] MMDDhhmm[[CC]YY]\n" |
| 18 | "| [[[[CCYY.]MM.DD-]hh:mm[:ss]]]] ]"; | ||
| 19 | |||
| 20 | //static const char date_usage[] = "Usage: date [OPTION]... [+FORMAT]\n" | ||
| 21 | //"or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n" | ||
| 22 | //"Display the current time in the given FORMAT, or set the system date.\n"; | ||
| 23 | |||
| 18 | 24 | ||
| 19 | static struct option const long_options[] = | 25 | static struct option const long_options[] = |
| 20 | { | 26 | { |
| @@ -153,7 +159,7 @@ date_err(void) { | |||
| 153 | } | 159 | } |
| 154 | 160 | ||
| 155 | int | 161 | int |
| 156 | date_main(struct FileInfo * i, int argc, char * * argv) | 162 | date_main(int argc, char * * argv) |
| 157 | { | 163 | { |
| 158 | char *date_str = NULL; | 164 | char *date_str = NULL; |
| 159 | char *date_fmt = NULL; | 165 | char *date_fmt = NULL; |
| @@ -203,7 +209,7 @@ date_main(struct FileInfo * i, int argc, char * * argv) | |||
| 203 | break; | 209 | break; |
| 204 | 210 | ||
| 205 | default: | 211 | default: |
| 206 | usage(date_usage); | 212 | fprintf(stderr, "Usage: %s", date_usage); |
| 207 | break; | 213 | break; |
| 208 | } | 214 | } |
| 209 | } | 215 | } |
diff --git a/internal.h b/internal.h index 75e5503cf..35581287c 100644 --- a/internal.h +++ b/internal.h | |||
| @@ -96,6 +96,7 @@ extern void usage(const char*); | |||
| 96 | extern int busybox_main(int argc, char** argv); | 96 | extern int busybox_main(int argc, char** argv); |
| 97 | extern int block_device_main(int argc, char** argv); | 97 | extern int block_device_main(int argc, char** argv); |
| 98 | extern int cat_more_main(int argc, char** argv); | 98 | extern int cat_more_main(int argc, char** argv); |
| 99 | extern int more_main(int argc, char** argv); | ||
| 99 | extern int chgrp_main(int argc, char** argv); | 100 | extern int chgrp_main(int argc, char** argv); |
| 100 | extern int chmod_main(int argc, char** argv); | 101 | extern int chmod_main(int argc, char** argv); |
| 101 | extern int chown_main(int argc, char** argv); | 102 | extern int chown_main(int argc, char** argv); |
| @@ -1,110 +1,85 @@ | |||
| 1 | /* | ||
| 2 | * Mini more implementation for busybox | ||
| 3 | * | ||
| 4 | * Copyright (C) 1998 by Erik Andersen <andersee@debian.org> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 19 | * | ||
| 20 | */ | ||
| 21 | |||
| 1 | #include "internal.h" | 22 | #include "internal.h" |
| 2 | #include <stdio.h> | 23 | #include <stdio.h> |
| 3 | #include <sys/types.h> | 24 | #include <signal.h> |
| 4 | #include <sys/stat.h> | ||
| 5 | #include <sys/ioctl.h> | ||
| 6 | #include <fcntl.h> | ||
| 7 | |||
| 8 | #define BB_MORE_TERM | ||
| 9 | |||
| 10 | #ifdef BB_MORE_TERM | ||
| 11 | #include <termios.h> | ||
| 12 | #include <signal.h> | ||
| 13 | 25 | ||
| 14 | FILE *cin; | 26 | const char more_usage[] = "[file ...]"; |
| 15 | struct termios initial_settings, new_settings; | ||
| 16 | 27 | ||
| 17 | void gotsig(int sig) { | ||
| 18 | tcsetattr(fileno(cin), TCSANOW, &initial_settings); | ||
| 19 | exit(0); | ||
| 20 | } | ||
| 21 | #endif | ||
| 22 | 28 | ||
| 23 | const char more_usage[] = "more [file]\n" | ||
| 24 | "\n" | ||
| 25 | "\tDisplays a file, one page at a time.\n" | ||
| 26 | "\tIf there are no arguments, the standard input is displayed.\n"; | ||
| 27 | 29 | ||
| 28 | extern int | 30 | extern int more_main(int argc, char **argv) |
| 29 | more_fn(const struct FileInfo * i) | ||
| 30 | { | 31 | { |
| 31 | FILE * f = stdin; | 32 | int c, lines=0; |
| 32 | int c; | 33 | int next_page=0, rows = 24, cols=79; |
| 33 | int lines = 0, tlines = 0; | 34 | struct stat st; |
| 34 | int next_page = 0; | 35 | FILE *file = stdin; |
| 35 | int rows = 24, cols = 79; | ||
| 36 | #ifdef BB_MORE_TERM | ||
| 37 | long sizeb = 0; | ||
| 38 | struct stat st; | ||
| 39 | struct winsize win; | ||
| 40 | #endif | ||
| 41 | |||
| 42 | if ( i ) { | ||
| 43 | if (! (f = fopen(i->source, "r") )) { | ||
| 44 | name_and_error(i->source); | ||
| 45 | return 1; | ||
| 46 | } | ||
| 47 | fstat(fileno(f), &st); | ||
| 48 | sizeb = st.st_size / 100; | ||
| 49 | } | ||
| 50 | |||
| 51 | #ifdef BB_MORE_TERM | ||
| 52 | cin = fopen("/dev/tty", "r"); | ||
| 53 | tcgetattr(fileno(cin),&initial_settings); | ||
| 54 | new_settings = initial_settings; | ||
| 55 | new_settings.c_lflag &= ~ICANON; | ||
| 56 | new_settings.c_lflag &= ~ECHO; | ||
| 57 | tcsetattr(fileno(cin), TCSANOW, &new_settings); | ||
| 58 | |||
| 59 | (void) signal(SIGINT, gotsig); | ||
| 60 | 36 | ||
| 61 | ioctl(STDOUT_FILENO, TIOCGWINSZ, &win); | 37 | if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) { |
| 62 | if (win.ws_row > 4) rows = win.ws_row - 2; | 38 | fprintf(stderr, "Usage: %s %s", *argv, more_usage); |
| 63 | if (win.ws_col > 0) cols = win.ws_col - 1; | 39 | return(FALSE); |
| 40 | } | ||
| 41 | argc--; | ||
| 42 | argv++; | ||
| 64 | 43 | ||
| 44 | while (argc-- > 0) { | ||
| 45 | file = fopen(*argv, "r"); | ||
| 46 | if (file == NULL) { | ||
| 47 | perror(*argv); | ||
| 48 | return(FALSE); | ||
| 49 | } | ||
| 50 | fstat(fileno(file), &st); | ||
| 65 | 51 | ||
| 52 | while ((c = getc(file)) != EOF) { | ||
| 53 | if ( next_page ) { | ||
| 54 | int len=0; | ||
| 55 | next_page = 0; | ||
| 56 | lines=0; | ||
| 57 | len = fprintf(stdout, "--More-- (%d%% of %ld bytes)\n", | ||
| 58 | (int) (100*( (double) ftell(file) / (double) st.st_size )), | ||
| 59 | st.st_size); | ||
| 60 | fflush(stdout); | ||
| 61 | getc( stdin); | ||
| 62 | #if 0 | ||
| 63 | while(len-- > 0) | ||
| 64 | putc('\b', stdout); | ||
| 65 | while(len++ < cols) | ||
| 66 | putc('8', stdout); | ||
| 67 | while(len-- > 0) | ||
| 68 | putc('\b', stdout); | ||
| 69 | fflush(stdout); | ||
| 66 | #endif | 70 | #endif |
| 67 | 71 | } | |
| 68 | while ( (c = getc(f)) != EOF ) { | 72 | if ( c == '\n' && ++lines == (rows + 1) ) |
| 69 | if ( next_page ) { | 73 | next_page = 1; |
| 70 | char garbage; | 74 | putc(c, stdout); |
| 71 | int len; | ||
| 72 | tlines += lines; | ||
| 73 | lines = 0; | ||
| 74 | next_page = 0; //Percentage is based on bytes, not lines. | ||
| 75 | if ( i && i->source ) //It is not very acurate, but still useful. | ||
| 76 | len = printf("%s - %%%2ld - line: %d", i->source, (ftell(f) - sizeb - sizeb) / sizeb, tlines); | ||
| 77 | else | ||
| 78 | len = printf("line: %d", tlines); | ||
| 79 | |||
| 80 | fflush(stdout); | ||
| 81 | #ifndef BB_MORE_TERM | ||
| 82 | read(2, &garbage, 1); | ||
| 83 | #else | ||
| 84 | do { | ||
| 85 | fread(&garbage, 1, 1, cin); | ||
| 86 | } while ((garbage != ' ') && (garbage != '\n')); | ||
| 87 | |||
| 88 | if (garbage == '\n') { | ||
| 89 | lines = rows; | ||
| 90 | tlines -= rows; | ||
| 91 | } | ||
| 92 | garbage = 0; | ||
| 93 | //clear line, since tabs don't overwrite. | ||
| 94 | while(len-- > 0) putchar('\b'); | ||
| 95 | while(len++ < cols) putchar(' '); | ||
| 96 | while(len-- > 0) putchar('\b'); | ||
| 97 | fflush(stdout); | ||
| 98 | #endif | ||
| 99 | } | ||
| 100 | putchar(c); | ||
| 101 | if ( c == '\n' && ++lines == (rows + 1) ) | ||
| 102 | next_page = 1; | ||
| 103 | } | 75 | } |
| 104 | if ( f != stdin ) | 76 | fclose(file); |
| 105 | fclose(f); | 77 | fflush(stdout); |
| 106 | #ifdef BB_MORE_TERM | 78 | |
| 107 | gotsig(0); | 79 | argc--; |
| 108 | #endif | 80 | argv++; |
| 109 | return 0; | 81 | } |
| 82 | return(TRUE); | ||
| 110 | } | 83 | } |
| 84 | |||
| 85 | |||
diff --git a/util-linux/more.c b/util-linux/more.c index 65409999b..2ea709278 100644 --- a/util-linux/more.c +++ b/util-linux/more.c | |||
| @@ -1,110 +1,85 @@ | |||
| 1 | /* | ||
| 2 | * Mini more implementation for busybox | ||
| 3 | * | ||
| 4 | * Copyright (C) 1998 by Erik Andersen <andersee@debian.org> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 19 | * | ||
| 20 | */ | ||
| 21 | |||
| 1 | #include "internal.h" | 22 | #include "internal.h" |
| 2 | #include <stdio.h> | 23 | #include <stdio.h> |
| 3 | #include <sys/types.h> | 24 | #include <signal.h> |
| 4 | #include <sys/stat.h> | ||
| 5 | #include <sys/ioctl.h> | ||
| 6 | #include <fcntl.h> | ||
| 7 | |||
| 8 | #define BB_MORE_TERM | ||
| 9 | |||
| 10 | #ifdef BB_MORE_TERM | ||
| 11 | #include <termios.h> | ||
| 12 | #include <signal.h> | ||
| 13 | 25 | ||
| 14 | FILE *cin; | 26 | const char more_usage[] = "[file ...]"; |
| 15 | struct termios initial_settings, new_settings; | ||
| 16 | 27 | ||
| 17 | void gotsig(int sig) { | ||
| 18 | tcsetattr(fileno(cin), TCSANOW, &initial_settings); | ||
| 19 | exit(0); | ||
| 20 | } | ||
| 21 | #endif | ||
| 22 | 28 | ||
| 23 | const char more_usage[] = "more [file]\n" | ||
| 24 | "\n" | ||
| 25 | "\tDisplays a file, one page at a time.\n" | ||
| 26 | "\tIf there are no arguments, the standard input is displayed.\n"; | ||
| 27 | 29 | ||
| 28 | extern int | 30 | extern int more_main(int argc, char **argv) |
| 29 | more_fn(const struct FileInfo * i) | ||
| 30 | { | 31 | { |
| 31 | FILE * f = stdin; | 32 | int c, lines=0; |
| 32 | int c; | 33 | int next_page=0, rows = 24, cols=79; |
| 33 | int lines = 0, tlines = 0; | 34 | struct stat st; |
| 34 | int next_page = 0; | 35 | FILE *file = stdin; |
| 35 | int rows = 24, cols = 79; | ||
| 36 | #ifdef BB_MORE_TERM | ||
| 37 | long sizeb = 0; | ||
| 38 | struct stat st; | ||
| 39 | struct winsize win; | ||
| 40 | #endif | ||
| 41 | |||
| 42 | if ( i ) { | ||
| 43 | if (! (f = fopen(i->source, "r") )) { | ||
| 44 | name_and_error(i->source); | ||
| 45 | return 1; | ||
| 46 | } | ||
| 47 | fstat(fileno(f), &st); | ||
| 48 | sizeb = st.st_size / 100; | ||
| 49 | } | ||
| 50 | |||
| 51 | #ifdef BB_MORE_TERM | ||
| 52 | cin = fopen("/dev/tty", "r"); | ||
| 53 | tcgetattr(fileno(cin),&initial_settings); | ||
| 54 | new_settings = initial_settings; | ||
| 55 | new_settings.c_lflag &= ~ICANON; | ||
| 56 | new_settings.c_lflag &= ~ECHO; | ||
| 57 | tcsetattr(fileno(cin), TCSANOW, &new_settings); | ||
| 58 | |||
| 59 | (void) signal(SIGINT, gotsig); | ||
| 60 | 36 | ||
| 61 | ioctl(STDOUT_FILENO, TIOCGWINSZ, &win); | 37 | if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) { |
| 62 | if (win.ws_row > 4) rows = win.ws_row - 2; | 38 | fprintf(stderr, "Usage: %s %s", *argv, more_usage); |
| 63 | if (win.ws_col > 0) cols = win.ws_col - 1; | 39 | return(FALSE); |
| 40 | } | ||
| 41 | argc--; | ||
| 42 | argv++; | ||
| 64 | 43 | ||
| 44 | while (argc-- > 0) { | ||
| 45 | file = fopen(*argv, "r"); | ||
| 46 | if (file == NULL) { | ||
| 47 | perror(*argv); | ||
| 48 | return(FALSE); | ||
| 49 | } | ||
| 50 | fstat(fileno(file), &st); | ||
| 65 | 51 | ||
| 52 | while ((c = getc(file)) != EOF) { | ||
| 53 | if ( next_page ) { | ||
| 54 | int len=0; | ||
| 55 | next_page = 0; | ||
| 56 | lines=0; | ||
| 57 | len = fprintf(stdout, "--More-- (%d%% of %ld bytes)\n", | ||
| 58 | (int) (100*( (double) ftell(file) / (double) st.st_size )), | ||
| 59 | st.st_size); | ||
| 60 | fflush(stdout); | ||
| 61 | getc( stdin); | ||
| 62 | #if 0 | ||
| 63 | while(len-- > 0) | ||
| 64 | putc('\b', stdout); | ||
| 65 | while(len++ < cols) | ||
| 66 | putc('8', stdout); | ||
| 67 | while(len-- > 0) | ||
| 68 | putc('\b', stdout); | ||
| 69 | fflush(stdout); | ||
| 66 | #endif | 70 | #endif |
| 67 | 71 | } | |
| 68 | while ( (c = getc(f)) != EOF ) { | 72 | if ( c == '\n' && ++lines == (rows + 1) ) |
| 69 | if ( next_page ) { | 73 | next_page = 1; |
| 70 | char garbage; | 74 | putc(c, stdout); |
| 71 | int len; | ||
| 72 | tlines += lines; | ||
| 73 | lines = 0; | ||
| 74 | next_page = 0; //Percentage is based on bytes, not lines. | ||
| 75 | if ( i && i->source ) //It is not very acurate, but still useful. | ||
| 76 | len = printf("%s - %%%2ld - line: %d", i->source, (ftell(f) - sizeb - sizeb) / sizeb, tlines); | ||
| 77 | else | ||
| 78 | len = printf("line: %d", tlines); | ||
| 79 | |||
| 80 | fflush(stdout); | ||
| 81 | #ifndef BB_MORE_TERM | ||
| 82 | read(2, &garbage, 1); | ||
| 83 | #else | ||
| 84 | do { | ||
| 85 | fread(&garbage, 1, 1, cin); | ||
| 86 | } while ((garbage != ' ') && (garbage != '\n')); | ||
| 87 | |||
| 88 | if (garbage == '\n') { | ||
| 89 | lines = rows; | ||
| 90 | tlines -= rows; | ||
| 91 | } | ||
| 92 | garbage = 0; | ||
| 93 | //clear line, since tabs don't overwrite. | ||
| 94 | while(len-- > 0) putchar('\b'); | ||
| 95 | while(len++ < cols) putchar(' '); | ||
| 96 | while(len-- > 0) putchar('\b'); | ||
| 97 | fflush(stdout); | ||
| 98 | #endif | ||
| 99 | } | ||
| 100 | putchar(c); | ||
| 101 | if ( c == '\n' && ++lines == (rows + 1) ) | ||
| 102 | next_page = 1; | ||
| 103 | } | 75 | } |
| 104 | if ( f != stdin ) | 76 | fclose(file); |
| 105 | fclose(f); | 77 | fflush(stdout); |
| 106 | #ifdef BB_MORE_TERM | 78 | |
| 107 | gotsig(0); | 79 | argc--; |
| 108 | #endif | 80 | argv++; |
| 109 | return 0; | 81 | } |
| 82 | return(TRUE); | ||
| 110 | } | 83 | } |
| 84 | |||
| 85 | |||
