diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-21 15:23:45 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-12-21 15:23:45 +0000 |
| commit | f65d1338dc525294e454bae181708adf3acebe2d (patch) | |
| tree | b558303f6b85412a999b30932615d1dbb4658b08 | |
| parent | d51d14e36fbc174db3eacd203fd00685dcc02011 (diff) | |
| download | busybox-w32-f65d1338dc525294e454bae181708adf3acebe2d.tar.gz busybox-w32-f65d1338dc525294e454bae181708adf3acebe2d.tar.bz2 busybox-w32-f65d1338dc525294e454bae181708adf3acebe2d.zip | |
less: restore TAB display (was showing as inverse I after prev changes :)
| -rw-r--r-- | miscutils/less.c | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 174155e95..85a4ae92d 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
| @@ -191,11 +191,10 @@ static void print_hilite(const char *str) | |||
| 191 | 191 | ||
| 192 | static void data_readlines(void) | 192 | static void data_readlines(void) |
| 193 | { | 193 | { |
| 194 | unsigned i; | 194 | unsigned i, pos; |
| 195 | unsigned n = 1; | 195 | unsigned lineno = 1; |
| 196 | int w = width; | 196 | int w = width; |
| 197 | /* "remained unused space" in a line (0 if line fills entire width) */ | 197 | char terminated, last_terminated = 1; |
| 198 | int rem, last_rem = 1; /* "not 0" */ | ||
| 199 | char *current_line, *p; | 198 | char *current_line, *p; |
| 200 | FILE *fp; | 199 | FILE *fp; |
| 201 | 200 | ||
| @@ -210,41 +209,47 @@ static void data_readlines(void) | |||
| 210 | 209 | ||
| 211 | flines = NULL; | 210 | flines = NULL; |
| 212 | if (option_mask32 & FLAG_N) { | 211 | if (option_mask32 & FLAG_N) { |
| 213 | w -= 6; | 212 | w -= 8; |
| 214 | } | 213 | } |
| 215 | for (i = 0; !feof(fp) && i <= MAXLINES; i++) { | 214 | for (i = 0; !feof(fp) && i <= MAXLINES; i++) { |
| 216 | flines = xrealloc(flines, (i+1) * sizeof(char *)); | 215 | flines = xrealloc(flines, (i+1) * sizeof(char *)); |
| 217 | current_line = xmalloc(w); | 216 | current_line = xmalloc(w); |
| 218 | again: | 217 | again: |
| 219 | p = current_line; | 218 | p = current_line; |
| 220 | rem = w - 1; | 219 | pos = 0; |
| 221 | do { | 220 | terminated = 0; |
| 221 | while (1) { | ||
| 222 | int c = getc(fp); | 222 | int c = getc(fp); |
| 223 | if (c == '\t') pos += (pos^7) & 7; | ||
| 224 | pos++; | ||
| 225 | if (pos >= w) { ungetc(c, fp); break; } | ||
| 223 | if (c == EOF) break; | 226 | if (c == EOF) break; |
| 224 | if (c == '\n') break; | 227 | if (c == '\n') { terminated = 1; break; } |
| 225 | /* NUL is substituted by '\n'! */ | 228 | /* NUL is substituted by '\n'! */ |
| 226 | if (c == '\0') c = '\n'; | 229 | if (c == '\0') c = '\n'; |
| 227 | *p++ = c; | 230 | *p++ = c; |
| 228 | } while (--rem); | 231 | } |
| 229 | *p = '\0'; | 232 | *p = '\0'; |
| 230 | if (fp != stdin) | 233 | if (fp != stdin) |
| 231 | die_if_ferror(fp, filename); | 234 | die_if_ferror(fp, filename); |
| 232 | 235 | ||
| 233 | /* Corner case: linewrap with only "" wrapping to next line */ | 236 | /* Corner case: linewrap with only "" wrapping to next line */ |
| 234 | /* Looks ugly on screen, so we do not store this empty line */ | 237 | /* Looks ugly on screen, so we do not store this empty line */ |
| 235 | if (!last_rem && !current_line[0]) { | 238 | if (!last_terminated && !current_line[0]) { |
| 236 | last_rem = 1; /* "not 0" */ | 239 | last_terminated = 1; |
| 237 | n++; | 240 | lineno++; |
| 238 | goto again; | 241 | goto again; |
| 239 | } | 242 | } |
| 240 | 243 | ||
| 241 | last_rem = rem; | 244 | last_terminated = terminated; |
| 242 | if (option_mask32 & FLAG_N) { | 245 | if (option_mask32 & FLAG_N) { |
| 243 | flines[i] = xasprintf((n <= 99999) ? "%5u %s" : "%05u %s", | 246 | /* Width of 7 preserves tab spacing in the text */ |
| 244 | n % 100000, current_line); | 247 | flines[i] = xasprintf( |
| 248 | (lineno <= 9999999) ? "%7u %s" : "%07u %s", | ||
| 249 | lineno % 10000000, current_line); | ||
| 245 | free(current_line); | 250 | free(current_line); |
| 246 | if (rem) | 251 | if (terminated) |
| 247 | n++; | 252 | lineno++; |
| 248 | } else { | 253 | } else { |
| 249 | flines[i] = xrealloc(current_line, strlen(current_line)+1); | 254 | flines[i] = xrealloc(current_line, strlen(current_line)+1); |
| 250 | } | 255 | } |
| @@ -339,12 +344,12 @@ static void status_print(void) | |||
| 339 | } | 344 | } |
| 340 | 345 | ||
| 341 | static char controls[] = | 346 | static char controls[] = |
| 342 | /**/"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" | 347 | /* NUL: never encountered; TAB: not converted */ |
| 348 | /**/"\x01\x02\x03\x04\x05\x06\x07\x08" "\x0a\x0b\x0c\x0d\x0e\x0f" | ||
| 343 | "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" | 349 | "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" |
| 344 | "\x7f\x9b"; /* DEL and infamous Meta-ESC :( */ | 350 | "\x7f\x9b"; /* DEL and infamous Meta-ESC :( */ |
| 345 | static char ctrlconv[] = | 351 | static char ctrlconv[] = |
| 346 | /* Note that on input NUL is converted to '\n' ('\x0a') */ | 352 | /* '\n': it's a former NUL - subst with '@', not 'J' */ |
| 347 | /* Therefore we subst '\n' with '@', not 'J' */ | ||
| 348 | "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x40\x4b\x4c\x4d\x4e\x4f" | 353 | "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x40\x4b\x4c\x4d\x4e\x4f" |
| 349 | "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f"; | 354 | "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f"; |
| 350 | 355 | ||
| @@ -402,10 +407,10 @@ static void print_found(const char *line) | |||
| 402 | } | 407 | } |
| 403 | 408 | ||
| 404 | if (!growline) { | 409 | if (!growline) { |
| 405 | printf("%s"CLEAR_2_EOL"\n", str); | 410 | printf(CLEAR_2_EOL"%s\n", str); |
| 406 | return; | 411 | return; |
| 407 | } | 412 | } |
| 408 | printf("%s%s"CLEAR_2_EOL"\n", growline, str); | 413 | printf(CLEAR_2_EOL"%s%s\n", growline, str); |
| 409 | free(growline); | 414 | free(growline); |
| 410 | } | 415 | } |
| 411 | 416 | ||
| @@ -415,6 +420,7 @@ static void print_ascii(const char *str) | |||
| 415 | char *p; | 420 | char *p; |
| 416 | size_t n; | 421 | size_t n; |
| 417 | 422 | ||
| 423 | printf(CLEAR_2_EOL); | ||
| 418 | while (*str) { | 424 | while (*str) { |
| 419 | n = strcspn(str, controls); | 425 | n = strcspn(str, controls); |
| 420 | if (n) { | 426 | if (n) { |
| @@ -438,7 +444,7 @@ static void print_ascii(const char *str) | |||
| 438 | *p = '\0'; | 444 | *p = '\0'; |
| 439 | print_hilite(buf); | 445 | print_hilite(buf); |
| 440 | } | 446 | } |
| 441 | printf("%s"CLEAR_2_EOL"\n", str); | 447 | puts(str); |
| 442 | } | 448 | } |
| 443 | 449 | ||
| 444 | /* Print the buffer */ | 450 | /* Print the buffer */ |
| @@ -578,7 +584,7 @@ static void change_file(int direction) | |||
| 578 | reinitialise(); | 584 | reinitialise(); |
| 579 | } else { | 585 | } else { |
| 580 | clear_line(); | 586 | clear_line(); |
| 581 | print_hilite((direction > 0) ? "No next file" : "No previous file"); | 587 | print_hilite(direction > 0 ? "No next file" : "No previous file"); |
| 582 | } | 588 | } |
| 583 | } | 589 | } |
| 584 | 590 | ||
| @@ -644,19 +650,18 @@ static void colon_process(void) | |||
| 644 | static int normalize_match_pos(int match) | 650 | static int normalize_match_pos(int match) |
| 645 | { | 651 | { |
| 646 | match_pos = match; | 652 | match_pos = match; |
| 647 | if (match < 0) | ||
| 648 | return (match_pos = 0); | ||
| 649 | if (match >= num_matches) | 653 | if (match >= num_matches) |
| 650 | { | ||
| 651 | match_pos = num_matches - 1; | 654 | match_pos = num_matches - 1; |
| 652 | } | 655 | if (match < 0) |
| 656 | return (match_pos = 0); | ||
| 653 | return match_pos; | 657 | return match_pos; |
| 654 | } | 658 | } |
| 655 | 659 | ||
| 656 | #if ENABLE_FEATURE_LESS_REGEXP | 660 | #if ENABLE_FEATURE_LESS_REGEXP |
| 657 | static void goto_match(int match) | 661 | static void goto_match(int match) |
| 658 | { | 662 | { |
| 659 | buffer_line(match_lines[normalize_match_pos(match)]); | 663 | if (num_matches) |
| 664 | buffer_line(match_lines[normalize_match_pos(match)]); | ||
| 660 | } | 665 | } |
| 661 | 666 | ||
| 662 | static void regex_process(void) | 667 | static void regex_process(void) |
| @@ -1063,6 +1068,7 @@ static void keypress_process(int keypress) | |||
| 1063 | regex_process(); | 1068 | regex_process(); |
| 1064 | break; | 1069 | break; |
| 1065 | case 'n': | 1070 | case 'n': |
| 1071 | //printf("HERE 3\n");sleep(1); | ||
| 1066 | goto_match(match_pos + 1); | 1072 | goto_match(match_pos + 1); |
| 1067 | break; | 1073 | break; |
| 1068 | case 'N': | 1074 | case 'N': |
