diff options
| author | Ron Yorston <rmy@pobox.com> | 2015-08-04 13:45:34 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2015-08-06 13:14:37 +0100 |
| commit | fb69410e583f04ede9e641e9f4bb0df83a67e882 (patch) | |
| tree | 043381544cd591f628af2f810a28ca893ea35f21 | |
| parent | 6fe172c34f6c559a0028d506dabd428ef640d388 (diff) | |
| download | busybox-w32-fb69410e583f04ede9e641e9f4bb0df83a67e882.tar.gz busybox-w32-fb69410e583f04ede9e641e9f4bb0df83a67e882.tar.bz2 busybox-w32-fb69410e583f04ede9e641e9f4bb0df83a67e882.zip | |
less: port to WIN32 and enable by default
| -rw-r--r-- | configs/mingw32_defconfig | 20 | ||||
| -rw-r--r-- | configs/mingw64_defconfig | 20 | ||||
| -rw-r--r-- | miscutils/less.c | 84 |
3 files changed, 104 insertions, 20 deletions
diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig index d22d32049..e412e934a 100644 --- a/configs/mingw32_defconfig +++ b/configs/mingw32_defconfig | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | # | 1 | # |
| 2 | # Automatically generated make config: don't edit | 2 | # Automatically generated make config: don't edit |
| 3 | # Busybox version: 1.24.0.git | 3 | # Busybox version: 1.24.0.git |
| 4 | # Tue Aug 4 09:49:37 2015 | 4 | # Tue Aug 4 13:13:10 2015 |
| 5 | # | 5 | # |
| 6 | CONFIG_HAVE_DOT_CONFIG=y | 6 | CONFIG_HAVE_DOT_CONFIG=y |
| 7 | # CONFIG_PLATFORM_POSIX is not set | 7 | # CONFIG_PLATFORM_POSIX is not set |
| @@ -667,17 +667,17 @@ CONFIG_FEATURE_CROND_DIR="" | |||
| 667 | # CONFIG_I2CSET is not set | 667 | # CONFIG_I2CSET is not set |
| 668 | # CONFIG_I2CDUMP is not set | 668 | # CONFIG_I2CDUMP is not set |
| 669 | # CONFIG_I2CDETECT is not set | 669 | # CONFIG_I2CDETECT is not set |
| 670 | # CONFIG_LESS is not set | 670 | CONFIG_LESS=y |
| 671 | CONFIG_FEATURE_LESS_MAXLINES=0 | 671 | CONFIG_FEATURE_LESS_MAXLINES=9999999 |
| 672 | # CONFIG_FEATURE_LESS_BRACKETS is not set | 672 | CONFIG_FEATURE_LESS_BRACKETS=y |
| 673 | # CONFIG_FEATURE_LESS_FLAGS is not set | 673 | CONFIG_FEATURE_LESS_FLAGS=y |
| 674 | # CONFIG_FEATURE_LESS_TRUNCATE is not set | 674 | CONFIG_FEATURE_LESS_TRUNCATE=y |
| 675 | # CONFIG_FEATURE_LESS_MARKS is not set | 675 | CONFIG_FEATURE_LESS_MARKS=y |
| 676 | # CONFIG_FEATURE_LESS_REGEXP is not set | 676 | CONFIG_FEATURE_LESS_REGEXP=y |
| 677 | # CONFIG_FEATURE_LESS_WINCH is not set | 677 | # CONFIG_FEATURE_LESS_WINCH is not set |
| 678 | # CONFIG_FEATURE_LESS_ASK_TERMINAL is not set | 678 | # CONFIG_FEATURE_LESS_ASK_TERMINAL is not set |
| 679 | # CONFIG_FEATURE_LESS_DASHCMD is not set | 679 | CONFIG_FEATURE_LESS_DASHCMD=y |
| 680 | # CONFIG_FEATURE_LESS_LINENUMS is not set | 680 | CONFIG_FEATURE_LESS_LINENUMS=y |
| 681 | # CONFIG_NANDWRITE is not set | 681 | # CONFIG_NANDWRITE is not set |
| 682 | # CONFIG_NANDDUMP is not set | 682 | # CONFIG_NANDDUMP is not set |
| 683 | # CONFIG_RFKILL is not set | 683 | # CONFIG_RFKILL is not set |
diff --git a/configs/mingw64_defconfig b/configs/mingw64_defconfig index 549b2039f..5017b2f89 100644 --- a/configs/mingw64_defconfig +++ b/configs/mingw64_defconfig | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | # | 1 | # |
| 2 | # Automatically generated make config: don't edit | 2 | # Automatically generated make config: don't edit |
| 3 | # Busybox version: 1.24.0.git | 3 | # Busybox version: 1.24.0.git |
| 4 | # Tue Aug 4 10:25:49 2015 | 4 | # Tue Aug 4 13:41:22 2015 |
| 5 | # | 5 | # |
| 6 | CONFIG_HAVE_DOT_CONFIG=y | 6 | CONFIG_HAVE_DOT_CONFIG=y |
| 7 | # CONFIG_PLATFORM_POSIX is not set | 7 | # CONFIG_PLATFORM_POSIX is not set |
| @@ -667,17 +667,17 @@ CONFIG_FEATURE_CROND_DIR="" | |||
| 667 | # CONFIG_I2CSET is not set | 667 | # CONFIG_I2CSET is not set |
| 668 | # CONFIG_I2CDUMP is not set | 668 | # CONFIG_I2CDUMP is not set |
| 669 | # CONFIG_I2CDETECT is not set | 669 | # CONFIG_I2CDETECT is not set |
| 670 | # CONFIG_LESS is not set | 670 | CONFIG_LESS=y |
| 671 | CONFIG_FEATURE_LESS_MAXLINES=0 | 671 | CONFIG_FEATURE_LESS_MAXLINES=9999999 |
| 672 | # CONFIG_FEATURE_LESS_BRACKETS is not set | 672 | CONFIG_FEATURE_LESS_BRACKETS=y |
| 673 | # CONFIG_FEATURE_LESS_FLAGS is not set | 673 | CONFIG_FEATURE_LESS_FLAGS=y |
| 674 | # CONFIG_FEATURE_LESS_TRUNCATE is not set | 674 | CONFIG_FEATURE_LESS_TRUNCATE=y |
| 675 | # CONFIG_FEATURE_LESS_MARKS is not set | 675 | CONFIG_FEATURE_LESS_MARKS=y |
| 676 | # CONFIG_FEATURE_LESS_REGEXP is not set | 676 | CONFIG_FEATURE_LESS_REGEXP=y |
| 677 | # CONFIG_FEATURE_LESS_WINCH is not set | 677 | # CONFIG_FEATURE_LESS_WINCH is not set |
| 678 | # CONFIG_FEATURE_LESS_ASK_TERMINAL is not set | 678 | # CONFIG_FEATURE_LESS_ASK_TERMINAL is not set |
| 679 | # CONFIG_FEATURE_LESS_DASHCMD is not set | 679 | CONFIG_FEATURE_LESS_DASHCMD=y |
| 680 | # CONFIG_FEATURE_LESS_LINENUMS is not set | 680 | CONFIG_FEATURE_LESS_LINENUMS=y |
| 681 | # CONFIG_NANDWRITE is not set | 681 | # CONFIG_NANDWRITE is not set |
| 682 | # CONFIG_NANDDUMP is not set | 682 | # CONFIG_NANDDUMP is not set |
| 683 | # CONFIG_RFKILL is not set | 683 | # CONFIG_RFKILL is not set |
diff --git a/miscutils/less.c b/miscutils/less.c index 7a441bf7e..86dcebb10 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
| @@ -126,6 +126,10 @@ | |||
| 126 | 126 | ||
| 127 | #include <sched.h> /* sched_yield() */ | 127 | #include <sched.h> /* sched_yield() */ |
| 128 | 128 | ||
| 129 | #if ENABLE_PLATFORM_MINGW32 | ||
| 130 | #include <conio.h> | ||
| 131 | #endif | ||
| 132 | |||
| 129 | #include "libbb.h" | 133 | #include "libbb.h" |
| 130 | #if ENABLE_FEATURE_LESS_REGEXP | 134 | #if ENABLE_FEATURE_LESS_REGEXP |
| 131 | #include "xregex.h" | 135 | #include "xregex.h" |
| @@ -304,8 +308,10 @@ static void less_exit(int code) | |||
| 304 | { | 308 | { |
| 305 | set_tty_cooked(); | 309 | set_tty_cooked(); |
| 306 | clear_line(); | 310 | clear_line(); |
| 311 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 307 | if (code < 0) | 312 | if (code < 0) |
| 308 | kill_myself_with_sig(- code); /* does not return */ | 313 | kill_myself_with_sig(- code); /* does not return */ |
| 314 | #endif | ||
| 309 | exit(code); | 315 | exit(code); |
| 310 | } | 316 | } |
| 311 | 317 | ||
| @@ -516,6 +522,11 @@ static void read_lines(void) | |||
| 516 | last_line_pos = 0; | 522 | last_line_pos = 0; |
| 517 | break; | 523 | break; |
| 518 | } | 524 | } |
| 525 | #if ENABLE_PLATFORM_MINGW32 | ||
| 526 | if (c == '\r') { | ||
| 527 | continue; | ||
| 528 | } | ||
| 529 | #endif | ||
| 519 | /* NUL is substituted by '\n'! */ | 530 | /* NUL is substituted by '\n'! */ |
| 520 | if (c == '\0') c = '\n'; | 531 | if (c == '\0') c = '\n'; |
| 521 | *p++ = c; | 532 | *p++ = c; |
| @@ -622,7 +633,12 @@ static void update_num_lines(void) | |||
| 622 | /* only do this for regular files */ | 633 | /* only do this for regular files */ |
| 623 | if (num_lines == REOPEN_AND_COUNT || num_lines == REOPEN_STDIN) { | 634 | if (num_lines == REOPEN_AND_COUNT || num_lines == REOPEN_STDIN) { |
| 624 | count = 0; | 635 | count = 0; |
| 636 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 625 | fd = open("/proc/self/fd/0", O_RDONLY); | 637 | fd = open("/proc/self/fd/0", O_RDONLY); |
| 638 | #else | ||
| 639 | /* don't even try to access /proc on WIN32 */ | ||
| 640 | fd = -1; | ||
| 641 | #endif | ||
| 626 | if (fd < 0 && num_lines == REOPEN_AND_COUNT) { | 642 | if (fd < 0 && num_lines == REOPEN_AND_COUNT) { |
| 627 | /* "filename" is valid only if REOPEN_AND_COUNT */ | 643 | /* "filename" is valid only if REOPEN_AND_COUNT */ |
| 628 | fd = open(filename, O_RDONLY); | 644 | fd = open(filename, O_RDONLY); |
| @@ -805,7 +821,12 @@ static void print_found(const char *line) | |||
| 805 | match_status = 1; | 821 | match_status = 1; |
| 806 | } | 822 | } |
| 807 | 823 | ||
| 824 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 808 | printf("%s%s\n", growline ? growline : "", str); | 825 | printf("%s%s\n", growline ? growline : "", str); |
| 826 | #else | ||
| 827 | /* skip newline, we use explicit positioning on WIN32 */ | ||
| 828 | printf("%s%s", growline ? growline : "", str); | ||
| 829 | #endif | ||
| 809 | free(growline); | 830 | free(growline); |
| 810 | } | 831 | } |
| 811 | #else | 832 | #else |
| @@ -841,7 +862,12 @@ static void print_ascii(const char *str) | |||
| 841 | *p = '\0'; | 862 | *p = '\0'; |
| 842 | print_hilite(buf); | 863 | print_hilite(buf); |
| 843 | } | 864 | } |
| 865 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 844 | puts(str); | 866 | puts(str); |
| 867 | #else | ||
| 868 | /* skip newline, we use explicit positioning on WIN32 */ | ||
| 869 | printf("%s", str); | ||
| 870 | #endif | ||
| 845 | } | 871 | } |
| 846 | 872 | ||
| 847 | /* Print the buffer */ | 873 | /* Print the buffer */ |
| @@ -851,6 +877,10 @@ static void buffer_print(void) | |||
| 851 | 877 | ||
| 852 | move_cursor(0, 0); | 878 | move_cursor(0, 0); |
| 853 | for (i = 0; i <= max_displayed_line; i++) { | 879 | for (i = 0; i <= max_displayed_line; i++) { |
| 880 | #if ENABLE_PLATFORM_MINGW32 | ||
| 881 | /* make sure we're on the right line */ | ||
| 882 | move_cursor(i+1, 0); | ||
| 883 | #endif | ||
| 854 | printf(CLEAR_2_EOL); | 884 | printf(CLEAR_2_EOL); |
| 855 | if (option_mask32 & FLAG_N) | 885 | if (option_mask32 & FLAG_N) |
| 856 | print_lineno(buffer[i]); | 886 | print_lineno(buffer[i]); |
| @@ -1037,9 +1067,13 @@ static void reinitialize(void) | |||
| 1037 | if (G.winsize_err) | 1067 | if (G.winsize_err) |
| 1038 | printf("\033[999;999H" "\033[6n"); | 1068 | printf("\033[999;999H" "\033[6n"); |
| 1039 | #endif | 1069 | #endif |
| 1070 | #if ENABLE_PLATFORM_MINGW32 | ||
| 1071 | puts(CLEAR); | ||
| 1072 | #endif | ||
| 1040 | buffer_fill_and_print(); | 1073 | buffer_fill_and_print(); |
| 1041 | } | 1074 | } |
| 1042 | 1075 | ||
| 1076 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 1043 | static int64_t getch_nowait(void) | 1077 | static int64_t getch_nowait(void) |
| 1044 | { | 1078 | { |
| 1045 | int rd; | 1079 | int rd; |
| @@ -1101,6 +1135,46 @@ static int64_t getch_nowait(void) | |||
| 1101 | set_tty_cooked(); | 1135 | set_tty_cooked(); |
| 1102 | return key64; | 1136 | return key64; |
| 1103 | } | 1137 | } |
| 1138 | #else | ||
| 1139 | static int64_t getch_nowait(void) | ||
| 1140 | { | ||
| 1141 | int64_t c; | ||
| 1142 | |||
| 1143 | retry: | ||
| 1144 | c = _getch(); | ||
| 1145 | if (c == 0 || c == 0xe0) { | ||
| 1146 | switch (_getch()) { | ||
| 1147 | case 0x48: | ||
| 1148 | c = KEYCODE_UP; | ||
| 1149 | break; | ||
| 1150 | case 0x50: | ||
| 1151 | c = KEYCODE_DOWN; | ||
| 1152 | break; | ||
| 1153 | case 0x49: | ||
| 1154 | c = KEYCODE_PAGEUP; | ||
| 1155 | break; | ||
| 1156 | case 0x51: | ||
| 1157 | c = KEYCODE_PAGEDOWN; | ||
| 1158 | break; | ||
| 1159 | case 0x47: | ||
| 1160 | c = KEYCODE_HOME; | ||
| 1161 | break; | ||
| 1162 | case 0x4f: | ||
| 1163 | c = KEYCODE_END; | ||
| 1164 | break; | ||
| 1165 | default: | ||
| 1166 | goto retry; | ||
| 1167 | } | ||
| 1168 | } | ||
| 1169 | |||
| 1170 | /* Position cursor if line input is done */ | ||
| 1171 | if (less_gets_pos >= 0) | ||
| 1172 | move_cursor(max_displayed_line + 2, less_gets_pos + 1); | ||
| 1173 | fflush_all(); | ||
| 1174 | |||
| 1175 | return c; | ||
| 1176 | } | ||
| 1177 | #endif | ||
| 1104 | 1178 | ||
| 1105 | /* Grab a character from input without requiring the return key. | 1179 | /* Grab a character from input without requiring the return key. |
| 1106 | * May return KEYCODE_xxx values. | 1180 | * May return KEYCODE_xxx values. |
| @@ -1728,10 +1802,12 @@ static void keypress_process(int keypress) | |||
| 1728 | number_process(keypress); | 1802 | number_process(keypress); |
| 1729 | } | 1803 | } |
| 1730 | 1804 | ||
| 1805 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 1731 | static void sig_catcher(int sig) | 1806 | static void sig_catcher(int sig) |
| 1732 | { | 1807 | { |
| 1733 | less_exit(- sig); | 1808 | less_exit(- sig); |
| 1734 | } | 1809 | } |
| 1810 | #endif | ||
| 1735 | 1811 | ||
| 1736 | #if ENABLE_FEATURE_LESS_WINCH | 1812 | #if ENABLE_FEATURE_LESS_WINCH |
| 1737 | static void sigwinch_handler(int sig UNUSED_PARAM) | 1813 | static void sigwinch_handler(int sig UNUSED_PARAM) |
| @@ -1743,8 +1819,10 @@ static void sigwinch_handler(int sig UNUSED_PARAM) | |||
| 1743 | int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1819 | int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 1744 | int less_main(int argc, char **argv) | 1820 | int less_main(int argc, char **argv) |
| 1745 | { | 1821 | { |
| 1822 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 1746 | char *tty_name; | 1823 | char *tty_name; |
| 1747 | int tty_fd; | 1824 | int tty_fd; |
| 1825 | #endif | ||
| 1748 | 1826 | ||
| 1749 | INIT_G(); | 1827 | INIT_G(); |
| 1750 | 1828 | ||
| @@ -1778,6 +1856,7 @@ int less_main(int argc, char **argv) | |||
| 1778 | if (option_mask32 & FLAG_TILDE) | 1856 | if (option_mask32 & FLAG_TILDE) |
| 1779 | empty_line_marker = ""; | 1857 | empty_line_marker = ""; |
| 1780 | 1858 | ||
| 1859 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 1781 | /* Some versions of less can survive w/o controlling tty, | 1860 | /* Some versions of less can survive w/o controlling tty, |
| 1782 | * try to do the same. This also allows to specify an alternative | 1861 | * try to do the same. This also allows to specify an alternative |
| 1783 | * tty via "less 1<>TTY". | 1862 | * tty via "less 1<>TTY". |
| @@ -1800,6 +1879,9 @@ int less_main(int argc, char **argv) | |||
| 1800 | } | 1879 | } |
| 1801 | ndelay_on(tty_fd); | 1880 | ndelay_on(tty_fd); |
| 1802 | kbd_fd = tty_fd; /* save in a global */ | 1881 | kbd_fd = tty_fd; /* save in a global */ |
| 1882 | #else | ||
| 1883 | kbd_fd = 0; | ||
| 1884 | #endif | ||
| 1803 | 1885 | ||
| 1804 | tcgetattr(kbd_fd, &term_orig); | 1886 | tcgetattr(kbd_fd, &term_orig); |
| 1805 | term_less = term_orig; | 1887 | term_less = term_orig; |
| @@ -1816,7 +1898,9 @@ int less_main(int argc, char **argv) | |||
| 1816 | max_displayed_line -= 2; | 1898 | max_displayed_line -= 2; |
| 1817 | 1899 | ||
| 1818 | /* We want to restore term_orig on exit */ | 1900 | /* We want to restore term_orig on exit */ |
| 1901 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 1819 | bb_signals(BB_FATAL_SIGS, sig_catcher); | 1902 | bb_signals(BB_FATAL_SIGS, sig_catcher); |
| 1903 | #endif | ||
| 1820 | #if ENABLE_FEATURE_LESS_WINCH | 1904 | #if ENABLE_FEATURE_LESS_WINCH |
| 1821 | signal(SIGWINCH, sigwinch_handler); | 1905 | signal(SIGWINCH, sigwinch_handler); |
| 1822 | #endif | 1906 | #endif |
