diff options
| author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-12-21 17:03:20 +0000 |
|---|---|---|
| committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-12-21 17:03:20 +0000 |
| commit | fb7712f5e2d776f7b3656a1d6bda6eedada6601e (patch) | |
| tree | 4ca29edf7ec51ac415cfee78b04cacb9998652d9 /miscutils | |
| parent | a977f2e328a76d472a3da63de1c2b59c95673514 (diff) | |
| download | busybox-w32-fb7712f5e2d776f7b3656a1d6bda6eedada6601e.tar.gz busybox-w32-fb7712f5e2d776f7b3656a1d6bda6eedada6601e.tar.bz2 busybox-w32-fb7712f5e2d776f7b3656a1d6bda6eedada6601e.zip | |
less: a few fixes for cases where we overflow status line
git-svn-id: svn://busybox.net/trunk/busybox@17034 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/less.c | 90 |
1 files changed, 31 insertions, 59 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 85a4ae92d..03b93973f 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
| @@ -148,7 +148,7 @@ static int tless_getch(void) | |||
| 148 | return input; | 148 | return input; |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | static char* tless_gets(void) | 151 | static char* tless_gets(int sz) |
| 152 | { | 152 | { |
| 153 | int c; | 153 | int c; |
| 154 | int i = 0; | 154 | int i = 0; |
| @@ -164,11 +164,12 @@ static char* tless_gets(void) | |||
| 164 | } | 164 | } |
| 165 | if (c < ' ') | 165 | if (c < ' ') |
| 166 | continue; | 166 | continue; |
| 167 | if (i >= width - sz - 1) | ||
| 168 | continue; /* len limit */ | ||
| 167 | putchar(c); | 169 | putchar(c); |
| 168 | result[i++] = c; | 170 | result[i++] = c; |
| 169 | result = xrealloc(result, i+1); | 171 | result = xrealloc(result, i+1); |
| 170 | result[i] = '\0'; | 172 | result[i] = '\0'; |
| 171 | if (i >= width-1) return result; | ||
| 172 | } | 173 | } |
| 173 | } | 174 | } |
| 174 | 175 | ||
| @@ -189,6 +190,12 @@ static void print_hilite(const char *str) | |||
| 189 | printf(HIGHLIGHT"%s"NORMAL, str); | 190 | printf(HIGHLIGHT"%s"NORMAL, str); |
| 190 | } | 191 | } |
| 191 | 192 | ||
| 193 | static void print_statusline(const char *str) | ||
| 194 | { | ||
| 195 | clear_line(); | ||
| 196 | printf(HIGHLIGHT"%.*s"NORMAL, width-1, str); | ||
| 197 | } | ||
| 198 | |||
| 192 | static void data_readlines(void) | 199 | static void data_readlines(void) |
| 193 | { | 200 | { |
| 194 | unsigned i, pos; | 201 | unsigned i, pos; |
| @@ -277,6 +284,7 @@ static void m_status_print(void) | |||
| 277 | { | 284 | { |
| 278 | int percentage; | 285 | int percentage; |
| 279 | 286 | ||
| 287 | clear_line(); | ||
| 280 | printf(HIGHLIGHT"%s", filename); | 288 | printf(HIGHLIGHT"%s", filename); |
| 281 | if (num_files > 1) | 289 | if (num_files > 1) |
| 282 | printf(" (file %i of %i)", current_file, num_files); | 290 | printf(" (file %i of %i)", current_file, num_files); |
| @@ -293,22 +301,6 @@ static void m_status_print(void) | |||
| 293 | printf("%i%% "NORMAL, percentage); | 301 | printf("%i%% "NORMAL, percentage); |
| 294 | } | 302 | } |
| 295 | 303 | ||
| 296 | #if 0 | ||
| 297 | /* Print a status line if -m was specified */ | ||
| 298 | static void medium_status_print(void) | ||
| 299 | { | ||
| 300 | int percentage; | ||
| 301 | |||
| 302 | percentage = calc_percent(); | ||
| 303 | if (!line_pos) | ||
| 304 | printf(HIGHLIGHT"%s %i%% "NORMAL, filename, percentage); | ||
| 305 | else if (line_pos >= num_flines - height + 2) | ||
| 306 | print_hilite("(END)"); | ||
| 307 | else | ||
| 308 | printf(HIGHLIGHT"%i%% "NORMAL, percentage); | ||
| 309 | } | ||
| 310 | #endif | ||
| 311 | |||
| 312 | #endif | 304 | #endif |
| 313 | 305 | ||
| 314 | /* Print the status line */ | 306 | /* Print the status line */ |
| @@ -322,12 +314,10 @@ static void status_print(void) | |||
| 322 | m_status_print(); | 314 | m_status_print(); |
| 323 | return; | 315 | return; |
| 324 | } | 316 | } |
| 325 | //if (option_mask32 & FLAG_m) { | ||
| 326 | // medium_status_print(); | ||
| 327 | // return; | ||
| 328 | //} | ||
| 329 | /* No flags set */ | 317 | /* No flags set */ |
| 330 | #endif | 318 | #endif |
| 319 | |||
| 320 | clear_line(); | ||
| 331 | if (line_pos && line_pos < num_flines - height + 2) { | 321 | if (line_pos && line_pos < num_flines - height + 2) { |
| 332 | putchar(':'); | 322 | putchar(':'); |
| 333 | return; | 323 | return; |
| @@ -458,7 +448,6 @@ static void buffer_print(void) | |||
| 458 | print_found(buffer[i]); | 448 | print_found(buffer[i]); |
| 459 | else | 449 | else |
| 460 | print_ascii(buffer[i]); | 450 | print_ascii(buffer[i]); |
| 461 | fputs(CLEAR_2_EOL, stdout); /* clears status line */ | ||
| 462 | status_print(); | 451 | status_print(); |
| 463 | } | 452 | } |
| 464 | 453 | ||
| @@ -557,10 +546,9 @@ static void reinitialise(void) | |||
| 557 | 546 | ||
| 558 | static void examine_file(void) | 547 | static void examine_file(void) |
| 559 | { | 548 | { |
| 560 | clear_line(); | 549 | print_statusline("Examine: "); |
| 561 | printf("Examine: "); | ||
| 562 | free(filename); | 550 | free(filename); |
| 563 | filename = tless_gets(); | 551 | filename = tless_gets(sizeof("Examine: ")-1); |
| 564 | /* files start by = argv. why we assume that argv is infinitely long?? | 552 | /* files start by = argv. why we assume that argv is infinitely long?? |
| 565 | files[num_files] = filename; | 553 | files[num_files] = filename; |
| 566 | current_file = num_files + 1; | 554 | current_file = num_files + 1; |
| @@ -583,8 +571,7 @@ static void change_file(int direction) | |||
| 583 | filename = xstrdup(files[current_file - 1]); | 571 | filename = xstrdup(files[current_file - 1]); |
| 584 | reinitialise(); | 572 | reinitialise(); |
| 585 | } else { | 573 | } else { |
| 586 | clear_line(); | 574 | print_statusline(direction > 0 ? "No next file" : "No previous file"); |
| 587 | print_hilite(direction > 0 ? "No next file" : "No previous file"); | ||
| 588 | } | 575 | } |
| 589 | } | 576 | } |
| 590 | 577 | ||
| @@ -613,8 +600,7 @@ static void colon_process(void) | |||
| 613 | int keypress; | 600 | int keypress; |
| 614 | 601 | ||
| 615 | /* Clear the current line and print a prompt */ | 602 | /* Clear the current line and print a prompt */ |
| 616 | clear_line(); | 603 | print_statusline(" :"); |
| 617 | printf(" :"); | ||
| 618 | 604 | ||
| 619 | keypress = tless_getch(); | 605 | keypress = tless_getch(); |
| 620 | switch (keypress) { | 606 | switch (keypress) { |
| @@ -626,7 +612,6 @@ static void colon_process(void) | |||
| 626 | break; | 612 | break; |
| 627 | #if ENABLE_FEATURE_LESS_FLAGS | 613 | #if ENABLE_FEATURE_LESS_FLAGS |
| 628 | case 'f': | 614 | case 'f': |
| 629 | clear_line(); | ||
| 630 | m_status_print(); | 615 | m_status_print(); |
| 631 | break; | 616 | break; |
| 632 | #endif | 617 | #endif |
| @@ -681,7 +666,7 @@ static void regex_process(void) | |||
| 681 | /* Get the uncompiled regular expression from the user */ | 666 | /* Get the uncompiled regular expression from the user */ |
| 682 | clear_line(); | 667 | clear_line(); |
| 683 | putchar((option_mask32 & LESS_STATE_MATCH_BACKWARDS) ? '?' : '/'); | 668 | putchar((option_mask32 & LESS_STATE_MATCH_BACKWARDS) ? '?' : '/'); |
| 684 | uncomp_regex = tless_gets(); | 669 | uncomp_regex = tless_gets(1); |
| 685 | if (/*!uncomp_regex ||*/ !uncomp_regex[0]) { | 670 | if (/*!uncomp_regex ||*/ !uncomp_regex[0]) { |
| 686 | free(uncomp_regex); | 671 | free(uncomp_regex); |
| 687 | buffer_print(); | 672 | buffer_print(); |
| @@ -692,8 +677,7 @@ static void regex_process(void) | |||
| 692 | err = regcomp_or_errmsg(&pattern, uncomp_regex, 0); | 677 | err = regcomp_or_errmsg(&pattern, uncomp_regex, 0); |
| 693 | free(uncomp_regex); | 678 | free(uncomp_regex); |
| 694 | if (err) { | 679 | if (err) { |
| 695 | clear_line(); | 680 | print_statusline(err); |
| 696 | fputs(err, stdout); | ||
| 697 | free(err); | 681 | free(err); |
| 698 | return; | 682 | return; |
| 699 | } | 683 | } |
| @@ -862,14 +846,13 @@ static void save_input_to_file(void) | |||
| 862 | int i; | 846 | int i; |
| 863 | FILE *fp; | 847 | FILE *fp; |
| 864 | 848 | ||
| 865 | clear_line(); | 849 | print_statusline("Log file: "); |
| 866 | printf("Log file: "); | 850 | current_line = tless_gets(sizeof("Log file: ")-1); |
| 867 | current_line = tless_gets(); | ||
| 868 | if (strlen(current_line) > 0) { | 851 | if (strlen(current_line) > 0) { |
| 869 | fp = fopen(current_line, "w"); | 852 | fp = fopen(current_line, "w"); |
| 870 | free(current_line); | 853 | free(current_line); |
| 871 | if (!fp) { | 854 | if (!fp) { |
| 872 | print_hilite("Error opening log file"); | 855 | print_statusline("Error opening log file"); |
| 873 | return; | 856 | return; |
| 874 | } | 857 | } |
| 875 | for (i = 0; i < num_flines; i++) | 858 | for (i = 0; i < num_flines; i++) |
| @@ -879,7 +862,7 @@ static void save_input_to_file(void) | |||
| 879 | return; | 862 | return; |
| 880 | } | 863 | } |
| 881 | free(current_line); | 864 | free(current_line); |
| 882 | print_hilite("No log file"); | 865 | print_statusline("No log file"); |
| 883 | } | 866 | } |
| 884 | 867 | ||
| 885 | #if ENABLE_FEATURE_LESS_MARKS | 868 | #if ENABLE_FEATURE_LESS_MARKS |
| @@ -887,8 +870,7 @@ static void add_mark(void) | |||
| 887 | { | 870 | { |
| 888 | int letter; | 871 | int letter; |
| 889 | 872 | ||
| 890 | clear_line(); | 873 | print_statusline("Mark: "); |
| 891 | printf("Mark: "); | ||
| 892 | letter = tless_getch(); | 874 | letter = tless_getch(); |
| 893 | 875 | ||
| 894 | if (isalpha(letter)) { | 876 | if (isalpha(letter)) { |
| @@ -901,8 +883,7 @@ static void add_mark(void) | |||
| 901 | mark_lines[num_marks][1] = line_pos; | 883 | mark_lines[num_marks][1] = line_pos; |
| 902 | num_marks++; | 884 | num_marks++; |
| 903 | } else { | 885 | } else { |
| 904 | clear_line(); | 886 | print_statusline("Invalid mark letter"); |
| 905 | print_hilite("Invalid mark letter"); | ||
| 906 | } | 887 | } |
| 907 | } | 888 | } |
| 908 | 889 | ||
| @@ -911,8 +892,7 @@ static void goto_mark(void) | |||
| 911 | int letter; | 892 | int letter; |
| 912 | int i; | 893 | int i; |
| 913 | 894 | ||
| 914 | clear_line(); | 895 | print_statusline("Go to mark: "); |
| 915 | printf("Go to mark: "); | ||
| 916 | letter = tless_getch(); | 896 | letter = tless_getch(); |
| 917 | clear_line(); | 897 | clear_line(); |
| 918 | 898 | ||
| @@ -923,9 +903,9 @@ static void goto_mark(void) | |||
| 923 | break; | 903 | break; |
| 924 | } | 904 | } |
| 925 | if (num_marks == 14 && letter != mark_lines[14][0]) | 905 | if (num_marks == 14 && letter != mark_lines[14][0]) |
| 926 | print_hilite("Mark not set"); | 906 | print_statusline("Mark not set"); |
| 927 | } else | 907 | } else |
| 928 | print_hilite("Invalid mark letter"); | 908 | print_statusline("Invalid mark letter"); |
| 929 | } | 909 | } |
| 930 | #endif | 910 | #endif |
| 931 | 911 | ||
| @@ -953,10 +933,8 @@ static void match_right_bracket(char bracket) | |||
| 953 | int bracket_line = -1; | 933 | int bracket_line = -1; |
| 954 | int i; | 934 | int i; |
| 955 | 935 | ||
| 956 | clear_line(); | ||
| 957 | |||
| 958 | if (strchr(flines[line_pos], bracket) == NULL) { | 936 | if (strchr(flines[line_pos], bracket) == NULL) { |
| 959 | print_hilite("No bracket in top line"); | 937 | print_statusline("No bracket in top line"); |
| 960 | return; | 938 | return; |
| 961 | } | 939 | } |
| 962 | for (i = line_pos + 1; i < num_flines; i++) { | 940 | for (i = line_pos + 1; i < num_flines; i++) { |
| @@ -966,7 +944,7 @@ static void match_right_bracket(char bracket) | |||
| 966 | } | 944 | } |
| 967 | } | 945 | } |
| 968 | if (bracket_line == -1) | 946 | if (bracket_line == -1) |
| 969 | print_hilite("No matching bracket found"); | 947 | print_statusline("No matching bracket found"); |
| 970 | buffer_line(bracket_line - height + 2); | 948 | buffer_line(bracket_line - height + 2); |
| 971 | } | 949 | } |
| 972 | 950 | ||
| @@ -975,13 +953,8 @@ static void match_left_bracket(char bracket) | |||
| 975 | int bracket_line = -1; | 953 | int bracket_line = -1; |
| 976 | int i; | 954 | int i; |
| 977 | 955 | ||
| 978 | clear_line(); | ||
| 979 | |||
| 980 | if (strchr(flines[line_pos + height - 2], bracket) == NULL) { | 956 | if (strchr(flines[line_pos + height - 2], bracket) == NULL) { |
| 981 | print_hilite("No bracket in bottom line"); | 957 | print_statusline("No bracket in bottom line"); |
| 982 | /* ?? */ | ||
| 983 | /*printf("%s", flines[line_pos + height]);*/ | ||
| 984 | /*sleep(4);*/ | ||
| 985 | return; | 958 | return; |
| 986 | } | 959 | } |
| 987 | 960 | ||
| @@ -992,7 +965,7 @@ static void match_left_bracket(char bracket) | |||
| 992 | } | 965 | } |
| 993 | } | 966 | } |
| 994 | if (bracket_line == -1) | 967 | if (bracket_line == -1) |
| 995 | print_hilite("No matching bracket found"); | 968 | print_statusline("No matching bracket found"); |
| 996 | buffer_line(bracket_line); | 969 | buffer_line(bracket_line); |
| 997 | } | 970 | } |
| 998 | 971 | ||
| @@ -1058,7 +1031,6 @@ static void keypress_process(int keypress) | |||
| 1058 | break; | 1031 | break; |
| 1059 | #if ENABLE_FEATURE_LESS_FLAGS | 1032 | #if ENABLE_FEATURE_LESS_FLAGS |
| 1060 | case '=': | 1033 | case '=': |
| 1061 | clear_line(); | ||
| 1062 | m_status_print(); | 1034 | m_status_print(); |
| 1063 | break; | 1035 | break; |
| 1064 | #endif | 1036 | #endif |
