diff options
author | Eric Andersen | 1999-10-12 22:26:06 +0000 |
---|---|---|
committer | Eric Andersen | 1999-10-12 22:26:06 +0000 |
commit | 3cf52d19581b2077480e7d2e63010baa1f5399c1 (patch) | |
tree | d91b0cb332ebc976126e36a394655dde7a15d8b1 /util-linux | |
parent | 2ce1edcf544ac675e6762c9861a6b918401ea716 (diff) | |
download | busybox-3cf52d19581b2077480e7d2e63010baa1f5399c1.zip busybox-3cf52d19581b2077480e7d2e63010baa1f5399c1.tar.gz |
More stuff...
Diffstat (limited to 'util-linux')
-rw-r--r-- | util-linux/dmesg.c | 127 | ||||
-rw-r--r-- | util-linux/more.c | 79 |
2 files changed, 131 insertions, 75 deletions
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c index 9096621..64265b4 100644 --- a/util-linux/dmesg.c +++ b/util-linux/dmesg.c @@ -14,7 +14,6 @@ #include <linux/unistd.h> #include <stdio.h> -#include <getopt.h> #define __NR_klog __NR_syslog @@ -22,74 +21,78 @@ #include <sys/klog.h> #define klog klogctl #else -static inline _syscall3(int,klog,int,type,char *,b,int,len) -#endif /* __GLIBC__ */ +static inline _syscall3 (int, klog, int, type, char *, b, int, len) +#endif /* __GLIBC__ */ -const char dmesg_usage[] = "dmesg"; -int -dmesg_main(int argc, char * * argv) + +static const char dmesg_usage[] = "dmesg [-c] [-n level]\n"; + +int dmesg_main (int argc, char **argv) { - char buf[4096]; - int i; - int n; - int c; - int level = 0; - int lastc; - int cmd = 3; + char buf[4096]; + int i; + int n; + int level = 0; + int lastc; + int cmd = 3; - while ((c = getopt( argc, argv, "cn:" )) != EOF) { - switch (c) { - case 'c': - cmd = 4; - break; - case 'n': - cmd = 8; - level = atoi(optarg); - break; - case '?': - default: - fprintf(stderr, "%s\n", dmesg_usage); - exit(1); - } - } - argc -= optind; - argv += optind; - - if (argc > 1) { - fprintf(stderr, "%s\n", dmesg_usage); - exit(1); - } + argc--; + argv++; - if (cmd == 8) { - n = klog( cmd, NULL, level ); - if (n < 0) { - perror( "klog" ); - exit( 1 ); - } - exit( 0 ); - } + /* Parse any options */ + while (argc && **argv == '-') { + while (*++(*argv)) + switch (**argv) { + case 'c': + cmd = 4; + break; + case 'n': + cmd = 8; + if (--argc == 0) + goto end; + level = atoi (*(++argv)); + --argc; + ++argv; + break; + default: + goto end; + } + } - n = klog( cmd, buf, sizeof( buf ) ); - if (n < 0) { - perror( "klog" ); - exit( 1 ); - } + if (cmd == 8) { + n = klog (cmd, NULL, level); + if (n < 0) { + perror ("klog"); + exit (FALSE); + } + exit (TRUE); + } - lastc = '\n'; - for (i = 0; i < n; i++) { - if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') { - i++; - while (buf[i] >= '0' && buf[i] <= '9') - i++; - if (buf[i] == '>') + n = klog (cmd, buf, sizeof (buf)); + if (n < 0) { + perror ("klog"); + exit (FALSE); + } + + lastc = '\n'; + for (i = 0; i < n; i++) { + if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') { i++; - } - lastc = buf[i]; - putchar( lastc ); - } - if (lastc != '\n') - putchar( '\n' ); - return 0; + while (buf[i] >= '0' && buf[i] <= '9') + i++; + if (buf[i] == '>') + i++; + } + lastc = buf[i]; + putchar (lastc); + } + if (lastc != '\n') + putchar ('\n'); + exit (TRUE); + + end: + fprintf (stderr, "Usage: %s\n", dmesg_usage); + exit (FALSE); } diff --git a/util-linux/more.c b/util-linux/more.c index 6ac553e..f893874 100644 --- a/util-linux/more.c +++ b/util-linux/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); } - |