diff options
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r-- | libbb/lineedit.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 93ab86426..7f64a9691 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -338,7 +338,7 @@ int adjust_width_and_validate_wc(unsigned *width_adj, int wc); | |||
338 | /* Put 'command_ps[cursor]', cursor++. | 338 | /* Put 'command_ps[cursor]', cursor++. |
339 | * Advance cursor on screen. If we reached right margin, scroll text up | 339 | * Advance cursor on screen. If we reached right margin, scroll text up |
340 | * and remove terminal margin effect by printing 'next_char' */ | 340 | * and remove terminal margin effect by printing 'next_char' */ |
341 | #define HACK_FOR_WRONG_WIDTH 1 | 341 | #define HACK_FOR_WRONG_WIDTH 1 && !ENABLE_PLATFORM_MINGW32 |
342 | static void put_cur_glyph_and_inc_cursor(void) | 342 | static void put_cur_glyph_and_inc_cursor(void) |
343 | { | 343 | { |
344 | CHAR_T c = command_ps[cursor]; | 344 | CHAR_T c = command_ps[cursor]; |
@@ -643,6 +643,7 @@ static char *username_path_completion(char *ud) | |||
643 | if (*ud == '/') { /* "~/..." */ | 643 | if (*ud == '/') { /* "~/..." */ |
644 | home = home_pwd_buf; | 644 | home = home_pwd_buf; |
645 | } else { | 645 | } else { |
646 | #if !ENABLE_PLATFORM_MINGW32 | ||
646 | /* "~user/..." */ | 647 | /* "~user/..." */ |
647 | ud = strchr(ud, '/'); | 648 | ud = strchr(ud, '/'); |
648 | *ud = '\0'; /* "~user" */ | 649 | *ud = '\0'; /* "~user" */ |
@@ -650,6 +651,7 @@ static char *username_path_completion(char *ud) | |||
650 | *ud = '/'; /* restore "~user/..." */ | 651 | *ud = '/'; /* restore "~user/..." */ |
651 | if (entry) | 652 | if (entry) |
652 | home = entry->pw_dir; | 653 | home = entry->pw_dir; |
654 | #endif | ||
653 | } | 655 | } |
654 | if (home) { | 656 | if (home) { |
655 | ud = concat_path_file(home, ud); | 657 | ud = concat_path_file(home, ud); |
@@ -664,15 +666,18 @@ static char *username_path_completion(char *ud) | |||
664 | */ | 666 | */ |
665 | static NOINLINE unsigned complete_username(const char *ud) | 667 | static NOINLINE unsigned complete_username(const char *ud) |
666 | { | 668 | { |
669 | #if !ENABLE_PLATFORM_MINGW32 | ||
667 | /* Using _r function to avoid pulling in static buffers */ | 670 | /* Using _r function to avoid pulling in static buffers */ |
668 | char line_buff[256]; | 671 | char line_buff[256]; |
669 | struct passwd pwd; | 672 | struct passwd pwd; |
670 | struct passwd *result; | 673 | struct passwd *result; |
674 | #endif | ||
671 | unsigned userlen; | 675 | unsigned userlen; |
672 | 676 | ||
673 | ud++; /* skip ~ */ | 677 | ud++; /* skip ~ */ |
674 | userlen = strlen(ud); | 678 | userlen = strlen(ud); |
675 | 679 | ||
680 | #if !ENABLE_PLATFORM_MINGW32 | ||
676 | setpwent(); | 681 | setpwent(); |
677 | while (!getpwent_r(&pwd, line_buff, sizeof(line_buff), &result)) { | 682 | while (!getpwent_r(&pwd, line_buff, sizeof(line_buff), &result)) { |
678 | /* Null usernames should result in all users as possible completions. */ | 683 | /* Null usernames should result in all users as possible completions. */ |
@@ -681,6 +686,7 @@ static NOINLINE unsigned complete_username(const char *ud) | |||
681 | } | 686 | } |
682 | } | 687 | } |
683 | endpwent(); | 688 | endpwent(); |
689 | #endif | ||
684 | 690 | ||
685 | return 1 + userlen; | 691 | return 1 + userlen; |
686 | } | 692 | } |
@@ -711,7 +717,11 @@ static int path_parse(char ***p) | |||
711 | tmp = (char*)pth; | 717 | tmp = (char*)pth; |
712 | npth = 1; /* path component count */ | 718 | npth = 1; /* path component count */ |
713 | while (1) { | 719 | while (1) { |
720 | #if ENABLE_PLATFORM_MINGW32 | ||
721 | tmp = next_path_sep(tmp); | ||
722 | #else | ||
714 | tmp = strchr(tmp, ':'); | 723 | tmp = strchr(tmp, ':'); |
724 | #endif | ||
715 | if (!tmp) | 725 | if (!tmp) |
716 | break; | 726 | break; |
717 | tmp++; | 727 | tmp++; |
@@ -724,7 +734,11 @@ static int path_parse(char ***p) | |||
724 | res[0] = tmp = xstrdup(pth); | 734 | res[0] = tmp = xstrdup(pth); |
725 | npth = 1; | 735 | npth = 1; |
726 | while (1) { | 736 | while (1) { |
737 | #if ENABLE_PLATFORM_MINGW32 | ||
738 | tmp = next_path_sep(tmp); | ||
739 | #else | ||
727 | tmp = strchr(tmp, ':'); | 740 | tmp = strchr(tmp, ':'); |
741 | #endif | ||
728 | if (!tmp) | 742 | if (!tmp) |
729 | break; | 743 | break; |
730 | *tmp++ = '\0'; /* ':' -> '\0' */ | 744 | *tmp++ = '\0'; /* ':' -> '\0' */ |
@@ -1863,7 +1877,11 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
1863 | /* /home/user[/something] -> ~[/something] */ | 1877 | /* /home/user[/something] -> ~[/something] */ |
1864 | l = strlen(home_pwd_buf); | 1878 | l = strlen(home_pwd_buf); |
1865 | if (l != 0 | 1879 | if (l != 0 |
1880 | #if !ENABLE_PLATFORM_MINGW32 | ||
1866 | && strncmp(home_pwd_buf, cwd_buf, l) == 0 | 1881 | && strncmp(home_pwd_buf, cwd_buf, l) == 0 |
1882 | #else | ||
1883 | && strncasecmp(home_pwd_buf, cwd_buf, l) == 0 | ||
1884 | #endif | ||
1867 | && (cwd_buf[l] == '/' || cwd_buf[l] == '\0') | 1885 | && (cwd_buf[l] == '/' || cwd_buf[l] == '\0') |
1868 | ) { | 1886 | ) { |
1869 | cwd_buf[0] = '~'; | 1887 | cwd_buf[0] = '~'; |
@@ -2210,9 +2228,16 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman | |||
2210 | 2228 | ||
2211 | INIT_S(); | 2229 | INIT_S(); |
2212 | 2230 | ||
2231 | #if ENABLE_PLATFORM_MINGW32 | ||
2232 | memset(initial_settings.c_cc, sizeof(initial_settings.c_cc), 0); | ||
2233 | initial_settings.c_cc[VINTR] = CTRL('C'); | ||
2234 | initial_settings.c_cc[VEOF] = CTRL('D'); | ||
2235 | if (!isatty(0) || !isatty(1)) { | ||
2236 | #else | ||
2213 | if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 | 2237 | if (tcgetattr(STDIN_FILENO, &initial_settings) < 0 |
2214 | || !(initial_settings.c_lflag & ECHO) | 2238 | || !(initial_settings.c_lflag & ECHO) |
2215 | ) { | 2239 | ) { |
2240 | #endif | ||
2216 | /* Happens when e.g. stty -echo was run before */ | 2241 | /* Happens when e.g. stty -echo was run before */ |
2217 | parse_and_put_prompt(prompt); | 2242 | parse_and_put_prompt(prompt); |
2218 | /* fflush_all(); - done by parse_and_put_prompt */ | 2243 | /* fflush_all(); - done by parse_and_put_prompt */ |