diff options
| author | Mark Whitley <markw@lineo.com> | 2000-06-16 00:26:51 +0000 |
|---|---|---|
| committer | Mark Whitley <markw@lineo.com> | 2000-06-16 00:26:51 +0000 |
| commit | b9913954054b87f64f0a8010a2d67f0ffd7f5b86 (patch) | |
| tree | 80694d2b35abd758a844fefaed681c38d9d150b5 | |
| parent | 2e965239ee4f19f86e377ade94574c3c73a32425 (diff) | |
| download | busybox-w32-b9913954054b87f64f0a8010a2d67f0ffd7f5b86.tar.gz busybox-w32-b9913954054b87f64f0a8010a2d67f0ffd7f5b86.tar.bz2 busybox-w32-b9913954054b87f64f0a8010a2d67f0ffd7f5b86.zip | |
Added some comments and changed a variable name to be more meaningful. No
fixes yet for the space bug, but should be coming soon.
| -rw-r--r-- | more.c | 27 | ||||
| -rw-r--r-- | util-linux/more.c | 27 |
2 files changed, 44 insertions, 10 deletions
| @@ -87,7 +87,7 @@ static int terminal_height = TERMINAL_HEIGHT; | |||
| 87 | extern int more_main(int argc, char **argv) | 87 | extern int more_main(int argc, char **argv) |
| 88 | { | 88 | { |
| 89 | int c, lines = 0, input = 0; | 89 | int c, lines = 0, input = 0; |
| 90 | int next_page = 0; | 90 | int please_display_more_prompt = 0; |
| 91 | struct stat st; | 91 | struct stat st; |
| 92 | FILE *file; | 92 | FILE *file; |
| 93 | 93 | ||
| @@ -140,10 +140,10 @@ extern int more_main(int argc, char **argv) | |||
| 140 | 140 | ||
| 141 | #endif | 141 | #endif |
| 142 | while ((c = getc(file)) != EOF) { | 142 | while ((c = getc(file)) != EOF) { |
| 143 | if (next_page) { | 143 | if (please_display_more_prompt) { |
| 144 | int len = 0; | 144 | int len = 0; |
| 145 | 145 | ||
| 146 | next_page = 0; | 146 | please_display_more_prompt = 0; |
| 147 | lines = 0; | 147 | lines = 0; |
| 148 | len = fprintf(stdout, "--More-- "); | 148 | len = fprintf(stdout, "--More-- "); |
| 149 | if (file != stdin) { | 149 | if (file != stdin) { |
| @@ -162,6 +162,11 @@ extern int more_main(int argc, char **argv) | |||
| 162 | ); | 162 | ); |
| 163 | 163 | ||
| 164 | fflush(stdout); | 164 | fflush(stdout); |
| 165 | |||
| 166 | /* | ||
| 167 | * We've just displayed the "--More--" prompt, so now we need | ||
| 168 | * to get input from the user. | ||
| 169 | */ | ||
| 165 | #ifdef BB_FEATURE_USE_TERMIOS | 170 | #ifdef BB_FEATURE_USE_TERMIOS |
| 166 | input = getc(cin); | 171 | input = getc(cin); |
| 167 | #else | 172 | #else |
| @@ -180,6 +185,17 @@ extern int more_main(int argc, char **argv) | |||
| 180 | #endif | 185 | #endif |
| 181 | 186 | ||
| 182 | } | 187 | } |
| 188 | |||
| 189 | /* | ||
| 190 | * There are two input streams to worry about here: | ||
| 191 | * | ||
| 192 | * c : the character we are reading from the file being "mored" | ||
| 193 | * input : a character received from the keyboard | ||
| 194 | * | ||
| 195 | * If we hit a newline in the _file_ stream, we want to test and | ||
| 196 | * see if any characters have been hit in the _input_ stream. This | ||
| 197 | * allows the user to quit while in the middle of a file. | ||
| 198 | */ | ||
| 183 | if (c == '\n') { | 199 | if (c == '\n') { |
| 184 | switch (input) { | 200 | switch (input) { |
| 185 | case 'q': | 201 | case 'q': |
| @@ -187,12 +203,13 @@ extern int more_main(int argc, char **argv) | |||
| 187 | case '\n': | 203 | case '\n': |
| 188 | /* increment by just one line if we are at | 204 | /* increment by just one line if we are at |
| 189 | * the end of this line*/ | 205 | * the end of this line*/ |
| 190 | next_page = 1; | 206 | please_display_more_prompt = 1; |
| 191 | break; | 207 | break; |
| 192 | } | 208 | } |
| 193 | if (++lines == terminal_height) | 209 | if (++lines == terminal_height) |
| 194 | next_page = 1; | 210 | please_display_more_prompt = 1; |
| 195 | } | 211 | } |
| 212 | /* If any key other than a return is hit, scroll by one page */ | ||
| 196 | putc(c, stdout); | 213 | putc(c, stdout); |
| 197 | } | 214 | } |
| 198 | fclose(file); | 215 | fclose(file); |
diff --git a/util-linux/more.c b/util-linux/more.c index 974149177..549a41730 100644 --- a/util-linux/more.c +++ b/util-linux/more.c | |||
| @@ -87,7 +87,7 @@ static int terminal_height = TERMINAL_HEIGHT; | |||
| 87 | extern int more_main(int argc, char **argv) | 87 | extern int more_main(int argc, char **argv) |
| 88 | { | 88 | { |
| 89 | int c, lines = 0, input = 0; | 89 | int c, lines = 0, input = 0; |
| 90 | int next_page = 0; | 90 | int please_display_more_prompt = 0; |
| 91 | struct stat st; | 91 | struct stat st; |
| 92 | FILE *file; | 92 | FILE *file; |
| 93 | 93 | ||
| @@ -140,10 +140,10 @@ extern int more_main(int argc, char **argv) | |||
| 140 | 140 | ||
| 141 | #endif | 141 | #endif |
| 142 | while ((c = getc(file)) != EOF) { | 142 | while ((c = getc(file)) != EOF) { |
| 143 | if (next_page) { | 143 | if (please_display_more_prompt) { |
| 144 | int len = 0; | 144 | int len = 0; |
| 145 | 145 | ||
| 146 | next_page = 0; | 146 | please_display_more_prompt = 0; |
| 147 | lines = 0; | 147 | lines = 0; |
| 148 | len = fprintf(stdout, "--More-- "); | 148 | len = fprintf(stdout, "--More-- "); |
| 149 | if (file != stdin) { | 149 | if (file != stdin) { |
| @@ -162,6 +162,11 @@ extern int more_main(int argc, char **argv) | |||
| 162 | ); | 162 | ); |
| 163 | 163 | ||
| 164 | fflush(stdout); | 164 | fflush(stdout); |
| 165 | |||
| 166 | /* | ||
| 167 | * We've just displayed the "--More--" prompt, so now we need | ||
| 168 | * to get input from the user. | ||
| 169 | */ | ||
| 165 | #ifdef BB_FEATURE_USE_TERMIOS | 170 | #ifdef BB_FEATURE_USE_TERMIOS |
| 166 | input = getc(cin); | 171 | input = getc(cin); |
| 167 | #else | 172 | #else |
| @@ -180,6 +185,17 @@ extern int more_main(int argc, char **argv) | |||
| 180 | #endif | 185 | #endif |
| 181 | 186 | ||
| 182 | } | 187 | } |
| 188 | |||
| 189 | /* | ||
| 190 | * There are two input streams to worry about here: | ||
| 191 | * | ||
| 192 | * c : the character we are reading from the file being "mored" | ||
| 193 | * input : a character received from the keyboard | ||
| 194 | * | ||
| 195 | * If we hit a newline in the _file_ stream, we want to test and | ||
| 196 | * see if any characters have been hit in the _input_ stream. This | ||
| 197 | * allows the user to quit while in the middle of a file. | ||
| 198 | */ | ||
| 183 | if (c == '\n') { | 199 | if (c == '\n') { |
| 184 | switch (input) { | 200 | switch (input) { |
| 185 | case 'q': | 201 | case 'q': |
| @@ -187,12 +203,13 @@ extern int more_main(int argc, char **argv) | |||
| 187 | case '\n': | 203 | case '\n': |
| 188 | /* increment by just one line if we are at | 204 | /* increment by just one line if we are at |
| 189 | * the end of this line*/ | 205 | * the end of this line*/ |
| 190 | next_page = 1; | 206 | please_display_more_prompt = 1; |
| 191 | break; | 207 | break; |
| 192 | } | 208 | } |
| 193 | if (++lines == terminal_height) | 209 | if (++lines == terminal_height) |
| 194 | next_page = 1; | 210 | please_display_more_prompt = 1; |
| 195 | } | 211 | } |
| 212 | /* If any key other than a return is hit, scroll by one page */ | ||
| 196 | putc(c, stdout); | 213 | putc(c, stdout); |
| 197 | } | 214 | } |
| 198 | fclose(file); | 215 | fclose(file); |
