aboutsummaryrefslogtreecommitdiff
path: root/util-linux
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 /util-linux
parent2ce1edcf544ac675e6762c9861a6b918401ea716 (diff)
downloadbusybox-w32-3cf52d19581b2077480e7d2e63010baa1f5399c1.tar.gz
busybox-w32-3cf52d19581b2077480e7d2e63010baa1f5399c1.tar.bz2
busybox-w32-3cf52d19581b2077480e7d2e63010baa1f5399c1.zip
More stuff...
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/dmesg.c127
-rw-r--r--util-linux/more.c79
2 files changed, 131 insertions, 75 deletions
diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c
index 9096621b0..64265b473 100644
--- a/util-linux/dmesg.c
+++ b/util-linux/dmesg.c
@@ -14,7 +14,6 @@
14 14
15#include <linux/unistd.h> 15#include <linux/unistd.h>
16#include <stdio.h> 16#include <stdio.h>
17#include <getopt.h>
18 17
19#define __NR_klog __NR_syslog 18#define __NR_klog __NR_syslog
20 19
@@ -22,74 +21,78 @@
22#include <sys/klog.h> 21#include <sys/klog.h>
23#define klog klogctl 22#define klog klogctl
24#else 23#else
25static inline _syscall3(int,klog,int,type,char *,b,int,len) 24static inline _syscall3 (int, klog, int, type, char *, b, int, len)
26#endif /* __GLIBC__ */ 25#endif /* __GLIBC__ */
27 26
28const char dmesg_usage[] = "dmesg";
29 27
30int 28
31dmesg_main(int argc, char * * argv) 29static const char dmesg_usage[] = "dmesg [-c] [-n level]\n";
30
31int dmesg_main (int argc, char **argv)
32{ 32{
33 33
34 char buf[4096]; 34 char buf[4096];
35 int i; 35 int i;
36 int n; 36 int n;
37 int c; 37 int level = 0;
38 int level = 0; 38 int lastc;
39 int lastc; 39 int cmd = 3;
40 int cmd = 3;
41 40
42 while ((c = getopt( argc, argv, "cn:" )) != EOF) { 41 argc--;
43 switch (c) { 42 argv++;
44 case 'c':
45 cmd = 4;
46 break;
47 case 'n':
48 cmd = 8;
49 level = atoi(optarg);
50 break;
51 case '?':
52 default:
53 fprintf(stderr, "%s\n", dmesg_usage);
54 exit(1);
55 }
56 }
57 argc -= optind;
58 argv += optind;
59
60 if (argc > 1) {
61 fprintf(stderr, "%s\n", dmesg_usage);
62 exit(1);
63 }
64 43
65 if (cmd == 8) { 44 /* Parse any options */
66 n = klog( cmd, NULL, level ); 45 while (argc && **argv == '-') {
67 if (n < 0) { 46 while (*++(*argv))
68 perror( "klog" ); 47 switch (**argv) {
69 exit( 1 ); 48 case 'c':
70 } 49 cmd = 4;
71 exit( 0 ); 50 break;
72 } 51 case 'n':
52 cmd = 8;
53 if (--argc == 0)
54 goto end;
55 level = atoi (*(++argv));
56 --argc;
57 ++argv;
58 break;
59 default:
60 goto end;
61 }
62 }
73 63
74 n = klog( cmd, buf, sizeof( buf ) ); 64 if (cmd == 8) {
75 if (n < 0) { 65 n = klog (cmd, NULL, level);
76 perror( "klog" ); 66 if (n < 0) {
77 exit( 1 ); 67 perror ("klog");
78 } 68 exit (FALSE);
69 }
70 exit (TRUE);
71 }
79 72
80 lastc = '\n'; 73 n = klog (cmd, buf, sizeof (buf));
81 for (i = 0; i < n; i++) { 74 if (n < 0) {
82 if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') { 75 perror ("klog");
83 i++; 76 exit (FALSE);
84 while (buf[i] >= '0' && buf[i] <= '9') 77 }
85 i++; 78
86 if (buf[i] == '>') 79 lastc = '\n';
80 for (i = 0; i < n; i++) {
81 if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') {
87 i++; 82 i++;
88 } 83 while (buf[i] >= '0' && buf[i] <= '9')
89 lastc = buf[i]; 84 i++;
90 putchar( lastc ); 85 if (buf[i] == '>')
91 } 86 i++;
92 if (lastc != '\n') 87 }
93 putchar( '\n' ); 88 lastc = buf[i];
94 return 0; 89 putchar (lastc);
90 }
91 if (lastc != '\n')
92 putchar ('\n');
93 exit (TRUE);
94
95 end:
96 fprintf (stderr, "Usage: %s\n", dmesg_usage);
97 exit (FALSE);
95} 98}
diff --git a/util-linux/more.c b/util-linux/more.c
index 6ac553e6b..f89387436 100644
--- a/util-linux/more.c
+++ b/util-linux/more.c
@@ -19,27 +19,48 @@
19 * 19 *
20 */ 20 */
21 21
22
23/* Turning this off makes things a bit smaller (and less pretty) */
24#define BB_MORE_TERM
25
26
27
22#include "internal.h" 28#include "internal.h"
23#include <stdio.h> 29#include <stdio.h>
24#include <signal.h> 30#include <signal.h>
25 31
32
26const char more_usage[] = "[file ...]"; 33const char more_usage[] = "[file ...]";
27 34
28//#define ERASE_STUFF 35
36#ifdef BB_MORE_TERM
37 #include <termios.h>
38 #include <signal.h>
39 #include <sys/ioctl.h>
40
41 FILE *cin;
42 struct termios initial_settings, new_settings;
43
44 void gotsig(int sig) {
45 tcsetattr(fileno(cin), TCSANOW, &initial_settings);
46 exit( TRUE);
47 }
48#endif
29 49
30extern int more_main(int argc, char **argv) 50extern int more_main(int argc, char **argv)
31{ 51{
32 int c, lines=0; 52 int c, lines=0, input;
33 int next_page=0, rows = 24; 53 int next_page=0, rows = 24;
34#ifdef ERASE_STUFF 54#ifdef BB_MORE_TERM
35 int cols=79; 55 int cols;
56 struct winsize win;
36#endif 57#endif
37 struct stat st; 58 struct stat st;
38 FILE *file = stdin; 59 FILE *file = stdin;
39 60
40 if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) { 61 if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
41 fprintf(stderr, "Usage: %s %s", *argv, more_usage); 62 fprintf(stderr, "Usage: %s %s", *argv, more_usage);
42 return(FALSE); 63 exit(FALSE);
43 } 64 }
44 argc--; 65 argc--;
45 argv++; 66 argv++;
@@ -48,23 +69,47 @@ extern int more_main(int argc, char **argv)
48 file = fopen(*argv, "r"); 69 file = fopen(*argv, "r");
49 if (file == NULL) { 70 if (file == NULL) {
50 perror("Can't open file"); 71 perror("Can't open file");
51 return(FALSE); 72 exit(FALSE);
52 } 73 }
53 fstat(fileno(file), &st); 74 fstat(fileno(file), &st);
54 fprintf(stderr, "hi\n"); 75 fprintf(stderr, "hi\n");
55 76
77#ifdef BB_MORE_TERM
78 cin = fopen("/dev/tty", "r");
79 tcgetattr(fileno(cin),&initial_settings);
80 new_settings = initial_settings;
81 new_settings.c_lflag &= ~ICANON;
82 new_settings.c_lflag &= ~ECHO;
83 tcsetattr(fileno(cin), TCSANOW, &new_settings);
84
85 (void) signal(SIGINT, gotsig);
86
87 ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
88 if (win.ws_row > 4) rows = win.ws_row - 2;
89 if (win.ws_col > 0) cols = win.ws_col - 1;
90
91
92#endif
56 while ((c = getc(file)) != EOF) { 93 while ((c = getc(file)) != EOF) {
57 if ( next_page ) { 94 if ( next_page ) {
58 int len=0; 95 int len=0;
59 next_page = 0; 96 next_page = 0;
60 lines=0; 97 lines=0;
61 len = fprintf(stdout, "--More-- (%d%% of %ld bytes)", 98 len = fprintf(stdout, "--More-- (%d%% of %ld bytes)%s",
62 (int) (100*( (double) ftell(file) / (double) st.st_size )), 99 (int) (100*( (double) ftell(file) / (double) st.st_size )),
63 st.st_size); 100 st.st_size,
101#ifdef BB_MORE_TERM
102 ""
103#else
104 "\n"
105#endif
106 );
107
64 fflush(stdout); 108 fflush(stdout);
65 getc( stdin); 109 input = getc( stdin);
66#ifdef ERASE_STUFF 110
67 /* Try to erase the "More" message */ 111#ifdef BB_MORE_TERM
112 /* Erase the "More" message */
68 while(len-- > 0) 113 while(len-- > 0)
69 putc('\b', stdout); 114 putc('\b', stdout);
70 while(len++ < cols) 115 while(len++ < cols)
@@ -73,7 +118,12 @@ extern int more_main(int argc, char **argv)
73 putc('\b', stdout); 118 putc('\b', stdout);
74 fflush(stdout); 119 fflush(stdout);
75#endif 120#endif
121
76 } 122 }
123 if (input=='q')
124 goto end;
125 if (input==' ' && c == '\n' )
126 next_page = 1;
77 if ( c == '\n' && ++lines == (rows + 1) ) 127 if ( c == '\n' && ++lines == (rows + 1) )
78 next_page = 1; 128 next_page = 1;
79 putc(c, stdout); 129 putc(c, stdout);
@@ -84,7 +134,10 @@ extern int more_main(int argc, char **argv)
84 argc--; 134 argc--;
85 argv++; 135 argv++;
86 } 136 }
87 return(TRUE); 137end:
138#ifdef BB_MORE_TERM
139 gotsig(0);
140#endif
141 exit(TRUE);
88} 142}
89 143
90