diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-05-31 21:31:56 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-05-31 21:31:56 +0000 |
commit | 2c31c731f0026b9f92dc0e07542fb8e38cad7dd2 (patch) | |
tree | 0f4c197180854003f7e169adbb0d0c056cc6f8b0 | |
parent | 5a0772ad0b877d851856a7954de650d1db92eb5d (diff) | |
download | busybox-w32-2c31c731f0026b9f92dc0e07542fb8e38cad7dd2.tar.gz busybox-w32-2c31c731f0026b9f92dc0e07542fb8e38cad7dd2.tar.bz2 busybox-w32-2c31c731f0026b9f92dc0e07542fb8e38cad7dd2.zip |
more: stop using bss
# make && make bloatcheck
function old new delta
gotsig 86 107 +21
more_main 777 781 +4
cin_fileno 4 - -4
set_tty_to_initial_mode 25 - -25
new_settings 120 60 -60
initial_settings 120 60 -60
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 2/2 up/down: 25/-149) Total: -124 bytes
git-svn-id: svn://busybox.net/trunk/busybox@18715 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | miscutils/less.c | 2 | ||||
-rw-r--r-- | util-linux/more.c | 40 |
2 files changed, 29 insertions, 13 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 58c1ec217..d5301bf58 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -209,6 +209,8 @@ static void fill_match_lines(unsigned pos); | |||
209 | * Has to deal with EOF and EPIPE on input, | 209 | * Has to deal with EOF and EPIPE on input, |
210 | * with line wrapping, with last line not ending in '\n' | 210 | * with line wrapping, with last line not ending in '\n' |
211 | * (possibly not ending YET!), with backspace and tabs. | 211 | * (possibly not ending YET!), with backspace and tabs. |
212 | * It reads input again if last time we got an EOF (thus supporting | ||
213 | * growing files) or EPIPE (watching output of slow process like make). | ||
212 | * | 214 | * |
213 | * Variables used: | 215 | * Variables used: |
214 | * flines[] - array of lines already read. Linewrap may cause | 216 | * flines[] - array of lines already read. Linewrap may cause |
diff --git a/util-linux/more.c b/util-linux/more.c index 30ef896bc..4083d8eea 100644 --- a/util-linux/more.c +++ b/util-linux/more.c | |||
@@ -15,26 +15,39 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "libbb.h" | 17 | #include "libbb.h" |
18 | #if ENABLE_FEATURE_USE_TERMIOS | ||
19 | #include <termios.h> | ||
20 | #endif /* FEATURE_USE_TERMIOS */ | ||
18 | 21 | ||
19 | 22 | ||
20 | #if ENABLE_FEATURE_USE_TERMIOS | 23 | #if ENABLE_FEATURE_USE_TERMIOS |
21 | static int cin_fileno; | ||
22 | #include <termios.h> | ||
23 | #define setTermSettings(fd, argp) tcsetattr(fd, TCSANOW, argp) | ||
24 | #define getTermSettings(fd, argp) tcgetattr(fd, argp); | ||
25 | 24 | ||
26 | static struct termios initial_settings, new_settings; | 25 | struct globals { |
26 | int cin_fileno; | ||
27 | struct termios initial_settings; | ||
28 | struct termios new_settings; | ||
29 | }; | ||
30 | #define G (*(struct globals*)bb_common_bufsiz1) | ||
31 | //#define G (*ptr_to_globals) | ||
32 | #define initial_settings (G.initial_settings) | ||
33 | #define new_settings (G.new_settings ) | ||
34 | #define cin_fileno (G.cin_fileno ) | ||
35 | #define INIT_G() ((void)0) | ||
36 | //#define INIT_G() PTR_TO_GLOBALS = xzalloc(sizeof(G)) | ||
27 | 37 | ||
28 | static void set_tty_to_initial_mode(void) | 38 | #define setTermSettings(fd, argp) tcsetattr(fd, TCSANOW, argp) |
29 | { | 39 | #define getTermSettings(fd, argp) tcgetattr(fd, argp) |
30 | setTermSettings(cin_fileno, &initial_settings); | ||
31 | } | ||
32 | 40 | ||
33 | static void gotsig(int sig) | 41 | static void gotsig(int sig) |
34 | { | 42 | { |
35 | putchar('\n'); | 43 | putchar('\n'); |
44 | setTermSettings(cin_fileno, &initial_settings); | ||
36 | exit(EXIT_FAILURE); | 45 | exit(EXIT_FAILURE); |
37 | } | 46 | } |
47 | |||
48 | #else /* !FEATURE_USE_TERMIOS */ | ||
49 | #define INIT_G() ((void)0) | ||
50 | #define setTermSettings(fd, argp) ((void)0) | ||
38 | #endif /* FEATURE_USE_TERMIOS */ | 51 | #endif /* FEATURE_USE_TERMIOS */ |
39 | 52 | ||
40 | 53 | ||
@@ -50,6 +63,8 @@ int more_main(int argc, char **argv) | |||
50 | int terminal_width; | 63 | int terminal_width; |
51 | int terminal_height; | 64 | int terminal_height; |
52 | 65 | ||
66 | INIT_G(); | ||
67 | |||
53 | argv++; | 68 | argv++; |
54 | /* Another popular pager, most, detects when stdout | 69 | /* Another popular pager, most, detects when stdout |
55 | * is not a tty and turns into cat. This makes sense. */ | 70 | * is not a tty and turns into cat. This makes sense. */ |
@@ -68,7 +83,6 @@ int more_main(int argc, char **argv) | |||
68 | new_settings.c_cc[VMIN] = 1; | 83 | new_settings.c_cc[VMIN] = 1; |
69 | new_settings.c_cc[VTIME] = 0; | 84 | new_settings.c_cc[VTIME] = 0; |
70 | setTermSettings(cin_fileno, &new_settings); | 85 | setTermSettings(cin_fileno, &new_settings); |
71 | atexit(set_tty_to_initial_mode); | ||
72 | signal(SIGINT, gotsig); | 86 | signal(SIGINT, gotsig); |
73 | signal(SIGQUIT, gotsig); | 87 | signal(SIGQUIT, gotsig); |
74 | signal(SIGTERM, gotsig); | 88 | signal(SIGTERM, gotsig); |
@@ -95,7 +109,6 @@ int more_main(int argc, char **argv) | |||
95 | lines = 0; | 109 | lines = 0; |
96 | page_height = terminal_height; | 110 | page_height = terminal_height; |
97 | while ((c = getc(file)) != EOF) { | 111 | while ((c = getc(file)) != EOF) { |
98 | |||
99 | if ((please_display_more_prompt & 3) == 3) { | 112 | if ((please_display_more_prompt & 3) == 3) { |
100 | len = printf("--More-- "); | 113 | len = printf("--More-- "); |
101 | if (/*file != stdin &&*/ st.st_size > 0) { | 114 | if (/*file != stdin &&*/ st.st_size > 0) { |
@@ -129,8 +142,8 @@ int more_main(int argc, char **argv) | |||
129 | /* | 142 | /* |
130 | * There are two input streams to worry about here: | 143 | * There are two input streams to worry about here: |
131 | * | 144 | * |
132 | * c : the character we are reading from the file being "mored" | 145 | * c : the character we are reading from the file being "mored" |
133 | * input : a character received from the keyboard | 146 | * input: a character received from the keyboard |
134 | * | 147 | * |
135 | * If we hit a newline in the _file_ stream, we want to test and | 148 | * If we hit a newline in the _file_ stream, we want to test and |
136 | * see if any characters have been hit in the _input_ stream. This | 149 | * see if any characters have been hit in the _input_ stream. This |
@@ -169,5 +182,6 @@ int more_main(int argc, char **argv) | |||
169 | fflush(stdout); | 182 | fflush(stdout); |
170 | } while (*argv && *++argv); | 183 | } while (*argv && *++argv); |
171 | end: | 184 | end: |
185 | setTermSettings(cin_fileno, &initial_settings); | ||
172 | return 0; | 186 | return 0; |
173 | } | 187 | } |