diff options
author | Ron Yorston <rmy@pobox.com> | 2012-04-23 15:05:26 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2012-04-23 15:05:26 +0100 |
commit | 15e948bdabe8fc69d821a20dfe2bf00b56eb99f3 (patch) | |
tree | 34375189e2091646ed6f4d55ab0aad172dc471f2 | |
parent | 7543523a11fbc3b8835a334651a3a8084c8a65b7 (diff) | |
download | busybox-w32-15e948bdabe8fc69d821a20dfe2bf00b56eb99f3.tar.gz busybox-w32-15e948bdabe8fc69d821a20dfe2bf00b56eb99f3.tar.bz2 busybox-w32-15e948bdabe8fc69d821a20dfe2bf00b56eb99f3.zip |
win32: support fancy prompts and (limited) tilde expansion
-rw-r--r-- | Makefile.flags | 1 | ||||
-rw-r--r-- | configs/mingw32_defconfig | 6 | ||||
-rw-r--r-- | coreutils/whoami.c | 10 | ||||
-rw-r--r-- | libbb/lineedit.c | 10 | ||||
-rw-r--r-- | win32/mingw.c | 30 |
5 files changed, 43 insertions, 14 deletions
diff --git a/Makefile.flags b/Makefile.flags index 0eb495c60..4cbef0597 100644 --- a/Makefile.flags +++ b/Makefile.flags | |||
@@ -108,6 +108,7 @@ ifeq ($(CONFIG_PLATFORM_MINGW32),y) | |||
108 | # These defintions are not strictly needed, but they help shut up fnmatch.c warnings | 108 | # These defintions are not strictly needed, but they help shut up fnmatch.c warnings |
109 | CFLAGS += -Iwin32 -DHAVE_STRING_H=1 -DHAVE_CONFIG_H=0 -fno-builtin-stpcpy | 109 | CFLAGS += -Iwin32 -DHAVE_STRING_H=1 -DHAVE_CONFIG_H=0 -fno-builtin-stpcpy |
110 | EXEEXT = .exe | 110 | EXEEXT = .exe |
111 | LDLIBS += userenv | ||
111 | ifeq ($(CONFIG_WIN32_NET),y) | 112 | ifeq ($(CONFIG_WIN32_NET),y) |
112 | LDLIBS += ws2_32 | 113 | LDLIBS += ws2_32 |
113 | endif | 114 | endif |
diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig index d014db4ae..aeb07276f 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.20.0 | 3 | # Busybox version: 1.20.0 |
4 | # Mon Apr 23 11:02:02 2012 | 4 | # Mon Apr 23 14:39:03 2012 |
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 |
@@ -110,8 +110,8 @@ CONFIG_FEATURE_EDITING_HISTORY=255 | |||
110 | # CONFIG_FEATURE_EDITING_SAVE_ON_EXIT is not set | 110 | # CONFIG_FEATURE_EDITING_SAVE_ON_EXIT is not set |
111 | # CONFIG_FEATURE_REVERSE_SEARCH is not set | 111 | # CONFIG_FEATURE_REVERSE_SEARCH is not set |
112 | CONFIG_FEATURE_TAB_COMPLETION=y | 112 | CONFIG_FEATURE_TAB_COMPLETION=y |
113 | # CONFIG_FEATURE_USERNAME_COMPLETION is not set | 113 | CONFIG_FEATURE_USERNAME_COMPLETION=y |
114 | # CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set | 114 | CONFIG_FEATURE_EDITING_FANCY_PROMPT=y |
115 | # CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set | 115 | # CONFIG_FEATURE_EDITING_ASK_TERMINAL is not set |
116 | CONFIG_FEATURE_NON_POSIX_CP=y | 116 | CONFIG_FEATURE_NON_POSIX_CP=y |
117 | # CONFIG_FEATURE_VERBOSE_CP_MESSAGE is not set | 117 | # CONFIG_FEATURE_VERBOSE_CP_MESSAGE is not set |
diff --git a/coreutils/whoami.c b/coreutils/whoami.c index 500e07166..30b17cab3 100644 --- a/coreutils/whoami.c +++ b/coreutils/whoami.c | |||
@@ -21,21 +21,11 @@ | |||
21 | int whoami_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 21 | int whoami_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
22 | int whoami_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | 22 | int whoami_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
23 | { | 23 | { |
24 | #if ENABLE_PLATFORM_MINGW32 | ||
25 | char buf[64]; | ||
26 | DWORD len = 64; | ||
27 | #endif | ||
28 | |||
29 | if (argv[1]) | 24 | if (argv[1]) |
30 | bb_show_usage(); | 25 | bb_show_usage(); |
31 | 26 | ||
32 | #if ENABLE_PLATFORM_MINGW32 | ||
33 | GetUserName(buf, &len); | ||
34 | puts(buf); | ||
35 | #else | ||
36 | /* Will complain and die if username not found */ | 27 | /* Will complain and die if username not found */ |
37 | puts(xuid2uname(geteuid())); | 28 | puts(xuid2uname(geteuid())); |
38 | #endif | ||
39 | 29 | ||
40 | return fflush_all(); | 30 | return fflush_all(); |
41 | } | 31 | } |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 77dc1c607..b3ae21510 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -647,6 +647,7 @@ static char *username_path_completion(char *ud) | |||
647 | if (*ud == '/') { /* "~/..." */ | 647 | if (*ud == '/') { /* "~/..." */ |
648 | home = home_pwd_buf; | 648 | home = home_pwd_buf; |
649 | } else { | 649 | } else { |
650 | #if !ENABLE_PLATFORM_MINGW32 | ||
650 | /* "~user/..." */ | 651 | /* "~user/..." */ |
651 | ud = strchr(ud, '/'); | 652 | ud = strchr(ud, '/'); |
652 | *ud = '\0'; /* "~user" */ | 653 | *ud = '\0'; /* "~user" */ |
@@ -654,6 +655,7 @@ static char *username_path_completion(char *ud) | |||
654 | *ud = '/'; /* restore "~user/..." */ | 655 | *ud = '/'; /* restore "~user/..." */ |
655 | if (entry) | 656 | if (entry) |
656 | home = entry->pw_dir; | 657 | home = entry->pw_dir; |
658 | #endif | ||
657 | } | 659 | } |
658 | if (home) { | 660 | if (home) { |
659 | ud = concat_path_file(home, ud); | 661 | ud = concat_path_file(home, ud); |
@@ -668,15 +670,18 @@ static char *username_path_completion(char *ud) | |||
668 | */ | 670 | */ |
669 | static NOINLINE unsigned complete_username(const char *ud) | 671 | static NOINLINE unsigned complete_username(const char *ud) |
670 | { | 672 | { |
673 | #if !ENABLE_PLATFORM_MINGW32 | ||
671 | /* Using _r function to avoid pulling in static buffers */ | 674 | /* Using _r function to avoid pulling in static buffers */ |
672 | char line_buff[256]; | 675 | char line_buff[256]; |
673 | struct passwd pwd; | 676 | struct passwd pwd; |
674 | struct passwd *result; | 677 | struct passwd *result; |
678 | #endif | ||
675 | unsigned userlen; | 679 | unsigned userlen; |
676 | 680 | ||
677 | ud++; /* skip ~ */ | 681 | ud++; /* skip ~ */ |
678 | userlen = strlen(ud); | 682 | userlen = strlen(ud); |
679 | 683 | ||
684 | #if !ENABLE_PLATFORM_MINGW32 | ||
680 | setpwent(); | 685 | setpwent(); |
681 | while (!getpwent_r(&pwd, line_buff, sizeof(line_buff), &result)) { | 686 | while (!getpwent_r(&pwd, line_buff, sizeof(line_buff), &result)) { |
682 | /* Null usernames should result in all users as possible completions. */ | 687 | /* Null usernames should result in all users as possible completions. */ |
@@ -685,6 +690,7 @@ static NOINLINE unsigned complete_username(const char *ud) | |||
685 | } | 690 | } |
686 | } | 691 | } |
687 | endpwent(); | 692 | endpwent(); |
693 | #endif | ||
688 | 694 | ||
689 | return 1 + userlen; | 695 | return 1 + userlen; |
690 | } | 696 | } |
@@ -1824,7 +1830,11 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
1824 | pbuf = cwd_buf; | 1830 | pbuf = cwd_buf; |
1825 | l = strlen(home_pwd_buf); | 1831 | l = strlen(home_pwd_buf); |
1826 | if (l != 0 | 1832 | if (l != 0 |
1833 | #if !ENABLE_PLATFORM_MINGW32 | ||
1827 | && strncmp(home_pwd_buf, cwd_buf, l) == 0 | 1834 | && strncmp(home_pwd_buf, cwd_buf, l) == 0 |
1835 | #else | ||
1836 | && strncasecmp(home_pwd_buf, cwd_buf, l) == 0 | ||
1837 | #endif | ||
1828 | && (cwd_buf[l]=='/' || cwd_buf[l]=='\0') | 1838 | && (cwd_buf[l]=='/' || cwd_buf[l]=='\0') |
1829 | && strlen(cwd_buf + l) < PATH_MAX | 1839 | && strlen(cwd_buf + l) < PATH_MAX |
1830 | ) { | 1840 | ) { |
diff --git a/win32/mingw.c b/win32/mingw.c index b99c88444..657d106ed 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #include "libbb.h" | 1 | #include "libbb.h" |
2 | #include <userenv.h> | ||
2 | 3 | ||
3 | unsigned int _CRT_fmode = _O_BINARY; | 4 | unsigned int _CRT_fmode = _O_BINARY; |
4 | 5 | ||
@@ -495,6 +496,33 @@ int mingw_rename(const char *pold, const char *pnew) | |||
495 | return -1; | 496 | return -1; |
496 | } | 497 | } |
497 | 498 | ||
499 | static char *gethomedir(void) | ||
500 | { | ||
501 | static char buf[PATH_MAX]; | ||
502 | DWORD len = sizeof(buf); | ||
503 | HANDLE h; | ||
504 | char *s; | ||
505 | |||
506 | buf[0] = '\0'; | ||
507 | if ( !OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &h) ) | ||
508 | return buf; | ||
509 | |||
510 | if ( !GetUserProfileDirectory(h, buf, &len) ) { | ||
511 | CloseHandle(h); | ||
512 | return buf; | ||
513 | } | ||
514 | |||
515 | CloseHandle(h); | ||
516 | |||
517 | for ( s=buf; *s; ++s ) { | ||
518 | if ( *s == '\\' ) { | ||
519 | *s = '/'; | ||
520 | } | ||
521 | } | ||
522 | |||
523 | return buf; | ||
524 | } | ||
525 | |||
498 | struct passwd *getpwuid(int uid UNUSED_PARAM) | 526 | struct passwd *getpwuid(int uid UNUSED_PARAM) |
499 | { | 527 | { |
500 | static char user_name[100]; | 528 | static char user_name[100]; |
@@ -505,7 +533,7 @@ struct passwd *getpwuid(int uid UNUSED_PARAM) | |||
505 | return NULL; | 533 | return NULL; |
506 | p.pw_name = user_name; | 534 | p.pw_name = user_name; |
507 | p.pw_gecos = "unknown"; | 535 | p.pw_gecos = "unknown"; |
508 | p.pw_dir = NULL; | 536 | p.pw_dir = gethomedir(); |
509 | return &p; | 537 | return &p; |
510 | } | 538 | } |
511 | 539 | ||