diff options
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/bbconfig.c | 1 | ||||
-rw-r--r-- | miscutils/dc.c | 2 | ||||
-rw-r--r-- | miscutils/less.c | 86 | ||||
-rw-r--r-- | miscutils/man.c | 22 |
4 files changed, 110 insertions, 1 deletions
diff --git a/miscutils/bbconfig.c b/miscutils/bbconfig.c index 501349548..aa42de648 100644 --- a/miscutils/bbconfig.c +++ b/miscutils/bbconfig.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include "libbb.h" | 35 | #include "libbb.h" |
36 | #include "bbconfigopts.h" | 36 | #include "bbconfigopts.h" |
37 | #if ENABLE_FEATURE_COMPRESS_BBCONFIG | 37 | #if ENABLE_FEATURE_COMPRESS_BBCONFIG |
38 | #define BB_ARCHIVE_PUBLIC | ||
38 | # include "bb_archive.h" | 39 | # include "bb_archive.h" |
39 | # include "bbconfigopts_bz2.h" | 40 | # include "bbconfigopts_bz2.h" |
40 | #endif | 41 | #endif |
diff --git a/miscutils/dc.c b/miscutils/dc.c index b922a7184..f752a1377 100644 --- a/miscutils/dc.c +++ b/miscutils/dc.c | |||
@@ -56,7 +56,7 @@ typedef unsigned long data_t; | |||
56 | #define DATA_FMT "l" | 56 | #define DATA_FMT "l" |
57 | #else | 57 | #else |
58 | typedef unsigned long long data_t; | 58 | typedef unsigned long long data_t; |
59 | #define DATA_FMT "ll" | 59 | #define DATA_FMT LL_FMT |
60 | #endif | 60 | #endif |
61 | 61 | ||
62 | 62 | ||
diff --git a/miscutils/less.c b/miscutils/less.c index 938d9842f..6b5c8c2dd 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -145,6 +145,10 @@ | |||
145 | 145 | ||
146 | #include <sched.h> /* sched_yield() */ | 146 | #include <sched.h> /* sched_yield() */ |
147 | 147 | ||
148 | #if ENABLE_PLATFORM_MINGW32 | ||
149 | #include <conio.h> | ||
150 | #endif | ||
151 | |||
148 | #include "libbb.h" | 152 | #include "libbb.h" |
149 | #include "common_bufsiz.h" | 153 | #include "common_bufsiz.h" |
150 | #if ENABLE_FEATURE_LESS_REGEXP | 154 | #if ENABLE_FEATURE_LESS_REGEXP |
@@ -236,7 +240,9 @@ struct globals { | |||
236 | smallint winsize_err; | 240 | smallint winsize_err; |
237 | #endif | 241 | #endif |
238 | smallint terminated; | 242 | smallint terminated; |
243 | #if !ENABLE_PLATFORM_MINGW32 | ||
239 | struct termios term_orig, term_less; | 244 | struct termios term_orig, term_less; |
245 | #endif | ||
240 | char kbd_input[KEYCODE_BUFFER_SIZE]; | 246 | char kbd_input[KEYCODE_BUFFER_SIZE]; |
241 | }; | 247 | }; |
242 | #define G (*ptr_to_globals) | 248 | #define G (*ptr_to_globals) |
@@ -298,7 +304,9 @@ struct globals { | |||
298 | static void set_tty_cooked(void) | 304 | static void set_tty_cooked(void) |
299 | { | 305 | { |
300 | fflush_all(); | 306 | fflush_all(); |
307 | #if !ENABLE_PLATFORM_MINGW32 | ||
301 | tcsetattr(kbd_fd, TCSANOW, &term_orig); | 308 | tcsetattr(kbd_fd, TCSANOW, &term_orig); |
309 | #endif | ||
302 | } | 310 | } |
303 | 311 | ||
304 | /* Move the cursor to a position (x,y), where (0,0) is the | 312 | /* Move the cursor to a position (x,y), where (0,0) is the |
@@ -575,6 +583,11 @@ static void read_lines(void) | |||
575 | last_line_pos = 0; | 583 | last_line_pos = 0; |
576 | break; | 584 | break; |
577 | } | 585 | } |
586 | #if ENABLE_PLATFORM_MINGW32 | ||
587 | if (c == '\r') { | ||
588 | continue; | ||
589 | } | ||
590 | #endif | ||
578 | /* NUL is substituted by '\n'! */ | 591 | /* NUL is substituted by '\n'! */ |
579 | if (c == '\0') c = '\n'; | 592 | if (c == '\0') c = '\n'; |
580 | *p++ = c; | 593 | *p++ = c; |
@@ -671,7 +684,12 @@ static void update_num_lines(void) | |||
671 | /* only do this for regular files */ | 684 | /* only do this for regular files */ |
672 | if (num_lines == REOPEN_AND_COUNT || num_lines == REOPEN_STDIN) { | 685 | if (num_lines == REOPEN_AND_COUNT || num_lines == REOPEN_STDIN) { |
673 | count = 0; | 686 | count = 0; |
687 | #if !ENABLE_PLATFORM_MINGW32 | ||
674 | fd = open("/proc/self/fd/0", O_RDONLY); | 688 | fd = open("/proc/self/fd/0", O_RDONLY); |
689 | #else | ||
690 | /* don't even try to access /proc on WIN32 */ | ||
691 | fd = -1; | ||
692 | #endif | ||
675 | if (fd < 0 && num_lines == REOPEN_AND_COUNT) { | 693 | if (fd < 0 && num_lines == REOPEN_AND_COUNT) { |
676 | /* "filename" is valid only if REOPEN_AND_COUNT */ | 694 | /* "filename" is valid only if REOPEN_AND_COUNT */ |
677 | fd = open(filename, O_RDONLY); | 695 | fd = open(filename, O_RDONLY); |
@@ -854,7 +872,12 @@ static void print_found(const char *line) | |||
854 | match_status = 1; | 872 | match_status = 1; |
855 | } | 873 | } |
856 | 874 | ||
875 | #if !ENABLE_PLATFORM_MINGW32 | ||
857 | printf("%s%s\n", growline ? growline : "", str); | 876 | printf("%s%s\n", growline ? growline : "", str); |
877 | #else | ||
878 | /* skip newline, we use explicit positioning on WIN32 */ | ||
879 | printf("%s%s", growline ? growline : "", str); | ||
880 | #endif | ||
858 | free(growline); | 881 | free(growline); |
859 | } | 882 | } |
860 | #else | 883 | #else |
@@ -890,7 +913,12 @@ static void print_ascii(const char *str) | |||
890 | *p = '\0'; | 913 | *p = '\0'; |
891 | print_hilite(buf); | 914 | print_hilite(buf); |
892 | } | 915 | } |
916 | #if !ENABLE_PLATFORM_MINGW32 | ||
893 | puts(str); | 917 | puts(str); |
918 | #else | ||
919 | /* skip newline, we use explicit positioning on WIN32 */ | ||
920 | printf("%s", str); | ||
921 | #endif | ||
894 | } | 922 | } |
895 | 923 | ||
896 | /* Print the buffer */ | 924 | /* Print the buffer */ |
@@ -900,6 +928,10 @@ static void buffer_print(void) | |||
900 | 928 | ||
901 | move_cursor(0, 0); | 929 | move_cursor(0, 0); |
902 | for (i = 0; i <= max_displayed_line; i++) { | 930 | for (i = 0; i <= max_displayed_line; i++) { |
931 | #if ENABLE_PLATFORM_MINGW32 | ||
932 | /* make sure we're on the right line */ | ||
933 | move_cursor(i+1, 0); | ||
934 | #endif | ||
903 | printf(CLEAR_2_EOL); | 935 | printf(CLEAR_2_EOL); |
904 | if (option_mask32 & FLAG_N) | 936 | if (option_mask32 & FLAG_N) |
905 | print_lineno(buffer[i]); | 937 | print_lineno(buffer[i]); |
@@ -1087,9 +1119,13 @@ static void reinitialize(void) | |||
1087 | if (G.winsize_err) | 1119 | if (G.winsize_err) |
1088 | printf(ESC"[999;999H" ESC"[6n"); | 1120 | printf(ESC"[999;999H" ESC"[6n"); |
1089 | #endif | 1121 | #endif |
1122 | #if ENABLE_PLATFORM_MINGW32 | ||
1123 | reset_screen(); | ||
1124 | #endif | ||
1090 | buffer_fill_and_print(); | 1125 | buffer_fill_and_print(); |
1091 | } | 1126 | } |
1092 | 1127 | ||
1128 | #if !ENABLE_PLATFORM_MINGW32 | ||
1093 | static int64_t getch_nowait(void) | 1129 | static int64_t getch_nowait(void) |
1094 | { | 1130 | { |
1095 | int rd; | 1131 | int rd; |
@@ -1151,6 +1187,46 @@ static int64_t getch_nowait(void) | |||
1151 | set_tty_cooked(); | 1187 | set_tty_cooked(); |
1152 | return key64; | 1188 | return key64; |
1153 | } | 1189 | } |
1190 | #else | ||
1191 | static int64_t getch_nowait(void) | ||
1192 | { | ||
1193 | int64_t c; | ||
1194 | |||
1195 | retry: | ||
1196 | c = _getch(); | ||
1197 | if (c == 0 || c == 0xe0) { | ||
1198 | switch (_getch()) { | ||
1199 | case 0x48: | ||
1200 | c = KEYCODE_UP; | ||
1201 | break; | ||
1202 | case 0x50: | ||
1203 | c = KEYCODE_DOWN; | ||
1204 | break; | ||
1205 | case 0x49: | ||
1206 | c = KEYCODE_PAGEUP; | ||
1207 | break; | ||
1208 | case 0x51: | ||
1209 | c = KEYCODE_PAGEDOWN; | ||
1210 | break; | ||
1211 | case 0x47: | ||
1212 | c = KEYCODE_HOME; | ||
1213 | break; | ||
1214 | case 0x4f: | ||
1215 | c = KEYCODE_END; | ||
1216 | break; | ||
1217 | default: | ||
1218 | goto retry; | ||
1219 | } | ||
1220 | } | ||
1221 | |||
1222 | /* Position cursor if line input is done */ | ||
1223 | if (less_gets_pos >= 0) | ||
1224 | move_cursor(max_displayed_line + 2, less_gets_pos + 1); | ||
1225 | fflush_all(); | ||
1226 | |||
1227 | return c; | ||
1228 | } | ||
1229 | #endif | ||
1154 | 1230 | ||
1155 | /* Grab a character from input without requiring the return key. | 1231 | /* Grab a character from input without requiring the return key. |
1156 | * May return KEYCODE_xxx values. | 1232 | * May return KEYCODE_xxx values. |
@@ -1791,10 +1867,12 @@ static void keypress_process(int keypress) | |||
1791 | number_process(keypress); | 1867 | number_process(keypress); |
1792 | } | 1868 | } |
1793 | 1869 | ||
1870 | #if !ENABLE_PLATFORM_MINGW32 | ||
1794 | static void sig_catcher(int sig) | 1871 | static void sig_catcher(int sig) |
1795 | { | 1872 | { |
1796 | less_exit(- sig); | 1873 | less_exit(- sig); |
1797 | } | 1874 | } |
1875 | #endif | ||
1798 | 1876 | ||
1799 | #if ENABLE_FEATURE_LESS_WINCH | 1877 | #if ENABLE_FEATURE_LESS_WINCH |
1800 | static void sigwinch_handler(int sig UNUSED_PARAM) | 1878 | static void sigwinch_handler(int sig UNUSED_PARAM) |
@@ -1806,7 +1884,9 @@ static void sigwinch_handler(int sig UNUSED_PARAM) | |||
1806 | int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1884 | int less_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
1807 | int less_main(int argc, char **argv) | 1885 | int less_main(int argc, char **argv) |
1808 | { | 1886 | { |
1887 | #if !ENABLE_PLATFORM_MINGW32 | ||
1809 | char *tty_name; | 1888 | char *tty_name; |
1889 | #endif | ||
1810 | int tty_fd; | 1890 | int tty_fd; |
1811 | 1891 | ||
1812 | INIT_G(); | 1892 | INIT_G(); |
@@ -1865,6 +1945,7 @@ int less_main(int argc, char **argv) | |||
1865 | if (option_mask32 & FLAG_TILDE) | 1945 | if (option_mask32 & FLAG_TILDE) |
1866 | empty_line_marker = ""; | 1946 | empty_line_marker = ""; |
1867 | 1947 | ||
1948 | #if !ENABLE_PLATFORM_MINGW32 | ||
1868 | /* Some versions of less can survive w/o controlling tty, | 1949 | /* Some versions of less can survive w/o controlling tty, |
1869 | * try to do the same. This also allows to specify an alternative | 1950 | * try to do the same. This also allows to specify an alternative |
1870 | * tty via "less 1<>TTY". | 1951 | * tty via "less 1<>TTY". |
@@ -1890,8 +1971,13 @@ int less_main(int argc, char **argv) | |||
1890 | } | 1971 | } |
1891 | G.kbd_fd_orig_flags = ndelay_on(tty_fd); | 1972 | G.kbd_fd_orig_flags = ndelay_on(tty_fd); |
1892 | kbd_fd = tty_fd; /* save in a global */ | 1973 | kbd_fd = tty_fd; /* save in a global */ |
1974 | #else | ||
1975 | kbd_fd = tty_fd = 0; | ||
1976 | #endif | ||
1893 | 1977 | ||
1978 | #if !ENABLE_PLATFORM_MINGW32 | ||
1894 | get_termios_and_make_raw(tty_fd, &term_less, &term_orig, TERMIOS_RAW_CRNL_INPUT); | 1979 | get_termios_and_make_raw(tty_fd, &term_less, &term_orig, TERMIOS_RAW_CRNL_INPUT); |
1980 | #endif | ||
1895 | 1981 | ||
1896 | IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(tty_fd, &width, &max_displayed_line); | 1982 | IF_FEATURE_LESS_ASK_TERMINAL(G.winsize_err =) get_terminal_width_height(tty_fd, &width, &max_displayed_line); |
1897 | /* 20: two tabstops + 4 */ | 1983 | /* 20: two tabstops + 4 */ |
diff --git a/miscutils/man.c b/miscutils/man.c index ba6bb4c01..567323a88 100644 --- a/miscutils/man.c +++ b/miscutils/man.c | |||
@@ -199,11 +199,19 @@ static char **add_MANPATH(char **man_path_list, int *count_mp, char *path) | |||
199 | if (path) while (*path) { | 199 | if (path) while (*path) { |
200 | char *next_path; | 200 | char *next_path; |
201 | char **path_element; | 201 | char **path_element; |
202 | #if ENABLE_PLATFORM_MINGW32 | ||
203 | char save; | ||
202 | 204 | ||
205 | next_path = (char *)next_path_sep(path); | ||
206 | #else | ||
203 | next_path = strchr(path, ':'); | 207 | next_path = strchr(path, ':'); |
208 | #endif | ||
204 | if (next_path) { | 209 | if (next_path) { |
205 | if (next_path == path) /* "::"? */ | 210 | if (next_path == path) /* "::"? */ |
206 | goto next; | 211 | goto next; |
212 | #if ENABLE_PLATFORM_MINGW32 | ||
213 | save = *next_path; | ||
214 | #endif | ||
207 | *next_path = '\0'; | 215 | *next_path = '\0'; |
208 | } | 216 | } |
209 | /* Do we already have path? */ | 217 | /* Do we already have path? */ |
@@ -222,7 +230,11 @@ static char **add_MANPATH(char **man_path_list, int *count_mp, char *path) | |||
222 | if (!next_path) | 230 | if (!next_path) |
223 | break; | 231 | break; |
224 | /* "path" may be a result of getenv(), be nice and don't mangle it */ | 232 | /* "path" may be a result of getenv(), be nice and don't mangle it */ |
233 | #if ENABLE_PLATFORM_MINGW32 | ||
234 | *next_path = save; | ||
235 | #else | ||
225 | *next_path = ':'; | 236 | *next_path = ':'; |
237 | #endif | ||
226 | next: | 238 | next: |
227 | path = next_path + 1; | 239 | path = next_path + 1; |
228 | } | 240 | } |
@@ -302,6 +314,16 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
302 | } | 314 | } |
303 | config_close(parser); | 315 | config_close(parser); |
304 | 316 | ||
317 | #if ENABLE_PLATFORM_MINGW32 | ||
318 | { | ||
319 | char *exepath = xstrdup(bb_busybox_exec_path); | ||
320 | char *relpath = concat_path_file(dirname(exepath), "man"); | ||
321 | man_path_list = add_MANPATH(man_path_list, &count_mp, relpath); | ||
322 | free(relpath); | ||
323 | free(exepath); | ||
324 | } | ||
325 | #endif | ||
326 | |||
305 | { | 327 | { |
306 | /* environment overrides setting from man.config */ | 328 | /* environment overrides setting from man.config */ |
307 | char *env_pager = getenv("MANPAGER"); | 329 | char *env_pager = getenv("MANPAGER"); |