diff options
author | Ron Yorston <rmy@pobox.com> | 2013-04-03 13:02:14 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2013-04-03 13:02:14 +0100 |
commit | 667d5dd0a428a790df5a73d044cf9a8882ee92f8 (patch) | |
tree | 76291debc380e8d31991c3d2eddcf0add131c7a3 /libbb/lineedit.c | |
parent | 8782950636f76faa8db0ed8c5d698ab0bd1fbf45 (diff) | |
parent | d35cbad0efaa57bf7c5280e62825966f7757906a (diff) | |
download | busybox-w32-667d5dd0a428a790df5a73d044cf9a8882ee92f8.tar.gz busybox-w32-667d5dd0a428a790df5a73d044cf9a8882ee92f8.tar.bz2 busybox-w32-667d5dd0a428a790df5a73d044cf9a8882ee92f8.zip |
Merge branch 'busybox' into merge
Conflicts:
libbb/lineedit.c
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r-- | libbb/lineedit.c | 124 |
1 files changed, 87 insertions, 37 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 09e203159..7f64a9691 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -133,9 +133,6 @@ struct lineedit_statics { | |||
133 | CHAR_T *command_ps; | 133 | CHAR_T *command_ps; |
134 | 134 | ||
135 | const char *cmdedit_prompt; | 135 | const char *cmdedit_prompt; |
136 | #if ENABLE_FEATURE_EDITING_FANCY_PROMPT | ||
137 | int num_ok_lines; /* = 1; */ | ||
138 | #endif | ||
139 | 136 | ||
140 | #if ENABLE_USERNAME_OR_HOMEDIR | 137 | #if ENABLE_USERNAME_OR_HOMEDIR |
141 | char *user_buf; | 138 | char *user_buf; |
@@ -172,7 +169,6 @@ extern struct lineedit_statics *const lineedit_ptr_to_statics; | |||
172 | #define command_len (S.command_len ) | 169 | #define command_len (S.command_len ) |
173 | #define command_ps (S.command_ps ) | 170 | #define command_ps (S.command_ps ) |
174 | #define cmdedit_prompt (S.cmdedit_prompt ) | 171 | #define cmdedit_prompt (S.cmdedit_prompt ) |
175 | #define num_ok_lines (S.num_ok_lines ) | ||
176 | #define user_buf (S.user_buf ) | 172 | #define user_buf (S.user_buf ) |
177 | #define home_pwd_buf (S.home_pwd_buf ) | 173 | #define home_pwd_buf (S.home_pwd_buf ) |
178 | #define matches (S.matches ) | 174 | #define matches (S.matches ) |
@@ -185,7 +181,6 @@ extern struct lineedit_statics *const lineedit_ptr_to_statics; | |||
185 | (*(struct lineedit_statics**)&lineedit_ptr_to_statics) = xzalloc(sizeof(S)); \ | 181 | (*(struct lineedit_statics**)&lineedit_ptr_to_statics) = xzalloc(sizeof(S)); \ |
186 | barrier(); \ | 182 | barrier(); \ |
187 | cmdedit_termw = 80; \ | 183 | cmdedit_termw = 80; \ |
188 | IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines = 1;) \ | ||
189 | IF_USERNAME_OR_HOMEDIR(home_pwd_buf = (char*)null_str;) \ | 184 | IF_USERNAME_OR_HOMEDIR(home_pwd_buf = (char*)null_str;) \ |
190 | IF_FEATURE_EDITING_VI(delptr = delbuf;) \ | 185 | IF_FEATURE_EDITING_VI(delptr = delbuf;) \ |
191 | } while (0) | 186 | } while (0) |
@@ -1546,7 +1541,6 @@ static void remember_in_history(char *str) | |||
1546 | # if ENABLE_FEATURE_EDITING_SAVEHISTORY && !ENABLE_FEATURE_EDITING_SAVE_ON_EXIT | 1541 | # if ENABLE_FEATURE_EDITING_SAVEHISTORY && !ENABLE_FEATURE_EDITING_SAVE_ON_EXIT |
1547 | save_history(str); | 1542 | save_history(str); |
1548 | # endif | 1543 | # endif |
1549 | IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines++;) | ||
1550 | } | 1544 | } |
1551 | 1545 | ||
1552 | #else /* MAX_HISTORY == 0 */ | 1546 | #else /* MAX_HISTORY == 0 */ |
@@ -1782,17 +1776,16 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
1782 | size_t cur_prmt_len = 0; | 1776 | size_t cur_prmt_len = 0; |
1783 | char flg_not_length = '['; | 1777 | char flg_not_length = '['; |
1784 | char *prmt_mem_ptr = xzalloc(1); | 1778 | char *prmt_mem_ptr = xzalloc(1); |
1785 | char *cwd_buf = xrealloc_getcwd_or_warn(NULL); | 1779 | # if ENABLE_USERNAME_OR_HOMEDIR |
1780 | char *cwd_buf = NULL; | ||
1781 | # endif | ||
1782 | char timebuf[sizeof("HH:MM:SS")]; | ||
1786 | char cbuf[2]; | 1783 | char cbuf[2]; |
1787 | char c; | 1784 | char c; |
1788 | char *pbuf; | 1785 | char *pbuf; |
1789 | 1786 | ||
1790 | cmdedit_prmt_len = 0; | 1787 | cmdedit_prmt_len = 0; |
1791 | 1788 | ||
1792 | if (!cwd_buf) { | ||
1793 | cwd_buf = (char *)bb_msg_unknown; | ||
1794 | } | ||
1795 | |||
1796 | cbuf[1] = '\0'; /* never changes */ | 1789 | cbuf[1] = '\0'; /* never changes */ |
1797 | 1790 | ||
1798 | while (*prmt_ptr) { | 1791 | while (*prmt_ptr) { |
@@ -1801,10 +1794,50 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
1801 | pbuf = cbuf; | 1794 | pbuf = cbuf; |
1802 | c = *prmt_ptr++; | 1795 | c = *prmt_ptr++; |
1803 | if (c == '\\') { | 1796 | if (c == '\\') { |
1804 | const char *cp = prmt_ptr; | 1797 | const char *cp; |
1805 | int l; | 1798 | int l; |
1806 | 1799 | /* | |
1807 | c = bb_process_escape_sequence(&prmt_ptr); | 1800 | * Supported via bb_process_escape_sequence: |
1801 | * \a ASCII bell character (07) | ||
1802 | * \e ASCII escape character (033) | ||
1803 | * \n newline | ||
1804 | * \r carriage return | ||
1805 | * \\ backslash | ||
1806 | * \nnn char with octal code nnn | ||
1807 | * Supported: | ||
1808 | * \$ if the effective UID is 0, a #, otherwise a $ | ||
1809 | * \w current working directory, with $HOME abbreviated with a tilde | ||
1810 | * Note: we do not support $PROMPT_DIRTRIM=n feature | ||
1811 | * \W basename of the current working directory, with $HOME abbreviated with a tilde | ||
1812 | * \h hostname up to the first '.' | ||
1813 | * \H hostname | ||
1814 | * \u username | ||
1815 | * \[ begin a sequence of non-printing characters | ||
1816 | * \] end a sequence of non-printing characters | ||
1817 | * \T current time in 12-hour HH:MM:SS format | ||
1818 | * \@ current time in 12-hour am/pm format | ||
1819 | * \A current time in 24-hour HH:MM format | ||
1820 | * \t current time in 24-hour HH:MM:SS format | ||
1821 | * (all of the above work as \A) | ||
1822 | * Not supported: | ||
1823 | * \! history number of this command | ||
1824 | * \# command number of this command | ||
1825 | * \j number of jobs currently managed by the shell | ||
1826 | * \l basename of the shell's terminal device name | ||
1827 | * \s name of the shell, the basename of $0 (the portion following the final slash) | ||
1828 | * \V release of bash, version + patch level (e.g., 2.00.0) | ||
1829 | * \d date in "Weekday Month Date" format (e.g., "Tue May 26") | ||
1830 | * \D{format} | ||
1831 | * format is passed to strftime(3). | ||
1832 | * An empty format results in a locale-specific time representation. | ||
1833 | * The braces are required. | ||
1834 | * Mishandled by bb_process_escape_sequence: | ||
1835 | * \v version of bash (e.g., 2.00) | ||
1836 | */ | ||
1837 | cp = prmt_ptr; | ||
1838 | c = *cp; | ||
1839 | if (c != 't') /* don't treat \t as tab */ | ||
1840 | c = bb_process_escape_sequence(&prmt_ptr); | ||
1808 | if (prmt_ptr == cp) { | 1841 | if (prmt_ptr == cp) { |
1809 | if (*cp == '\0') | 1842 | if (*cp == '\0') |
1810 | break; | 1843 | break; |
@@ -1816,43 +1849,58 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
1816 | pbuf = user_buf ? user_buf : (char*)""; | 1849 | pbuf = user_buf ? user_buf : (char*)""; |
1817 | break; | 1850 | break; |
1818 | # endif | 1851 | # endif |
1852 | case 'H': | ||
1819 | case 'h': | 1853 | case 'h': |
1820 | pbuf = free_me = safe_gethostname(); | 1854 | pbuf = free_me = safe_gethostname(); |
1821 | *strchrnul(pbuf, '.') = '\0'; | 1855 | if (c == 'h') |
1856 | strchrnul(pbuf, '.')[0] = '\0'; | ||
1822 | break; | 1857 | break; |
1823 | case '$': | 1858 | case '$': |
1824 | c = (geteuid() == 0 ? '#' : '$'); | 1859 | c = (geteuid() == 0 ? '#' : '$'); |
1825 | break; | 1860 | break; |
1861 | case 'T': /* 12-hour HH:MM:SS format */ | ||
1862 | case '@': /* 12-hour am/pm format */ | ||
1863 | case 'A': /* 24-hour HH:MM format */ | ||
1864 | case 't': /* 24-hour HH:MM:SS format */ | ||
1865 | /* We show all of them as 24-hour HH:MM */ | ||
1866 | strftime_HHMMSS(timebuf, sizeof(timebuf), NULL)[-3] = '\0'; | ||
1867 | pbuf = timebuf; | ||
1868 | break; | ||
1826 | # if ENABLE_USERNAME_OR_HOMEDIR | 1869 | # if ENABLE_USERNAME_OR_HOMEDIR |
1827 | case 'w': | 1870 | case 'w': /* current dir */ |
1828 | /* /home/user[/something] -> ~[/something] */ | 1871 | case 'W': /* basename of cur dir */ |
1829 | pbuf = cwd_buf; | 1872 | if (!cwd_buf) { |
1830 | l = strlen(home_pwd_buf); | 1873 | cwd_buf = xrealloc_getcwd_or_warn(NULL); |
1831 | if (l != 0 | 1874 | if (!cwd_buf) |
1875 | cwd_buf = (char *)bb_msg_unknown; | ||
1876 | else { | ||
1877 | /* /home/user[/something] -> ~[/something] */ | ||
1878 | l = strlen(home_pwd_buf); | ||
1879 | if (l != 0 | ||
1832 | #if !ENABLE_PLATFORM_MINGW32 | 1880 | #if !ENABLE_PLATFORM_MINGW32 |
1833 | && strncmp(home_pwd_buf, cwd_buf, l) == 0 | 1881 | && strncmp(home_pwd_buf, cwd_buf, l) == 0 |
1834 | #else | 1882 | #else |
1835 | && strncasecmp(home_pwd_buf, cwd_buf, l) == 0 | 1883 | && strncasecmp(home_pwd_buf, cwd_buf, l) == 0 |
1836 | #endif | 1884 | #endif |
1837 | && (cwd_buf[l]=='/' || cwd_buf[l]=='\0') | 1885 | && (cwd_buf[l] == '/' || cwd_buf[l] == '\0') |
1838 | && strlen(cwd_buf + l) < PATH_MAX | 1886 | ) { |
1839 | ) { | 1887 | cwd_buf[0] = '~'; |
1840 | pbuf = free_me = xasprintf("~%s", cwd_buf + l); | 1888 | overlapping_strcpy(cwd_buf + 1, cwd_buf + l); |
1889 | } | ||
1890 | } | ||
1841 | } | 1891 | } |
1842 | break; | ||
1843 | # endif | ||
1844 | case 'W': | ||
1845 | pbuf = cwd_buf; | 1892 | pbuf = cwd_buf; |
1893 | if (c == 'w') | ||
1894 | break; | ||
1846 | cp = strrchr(pbuf, '/'); | 1895 | cp = strrchr(pbuf, '/'); |
1847 | if (cp != NULL && cp != pbuf) | 1896 | if (cp) |
1848 | pbuf += (cp-pbuf) + 1; | 1897 | pbuf = (char*)cp + 1; |
1849 | break; | ||
1850 | case '!': | ||
1851 | pbuf = free_me = xasprintf("%d", num_ok_lines); | ||
1852 | break; | ||
1853 | case 'e': case 'E': /* \e \E = \033 */ | ||
1854 | c = '\033'; | ||
1855 | break; | 1898 | break; |
1899 | # endif | ||
1900 | // bb_process_escape_sequence does this now: | ||
1901 | // case 'e': case 'E': /* \e \E = \033 */ | ||
1902 | // c = '\033'; | ||
1903 | // break; | ||
1856 | case 'x': case 'X': { | 1904 | case 'x': case 'X': { |
1857 | char buf2[4]; | 1905 | char buf2[4]; |
1858 | for (l = 0; l < 3;) { | 1906 | for (l = 0; l < 3;) { |
@@ -1890,8 +1938,10 @@ static void parse_and_put_prompt(const char *prmt_ptr) | |||
1890 | free(free_me); | 1938 | free(free_me); |
1891 | } /* while */ | 1939 | } /* while */ |
1892 | 1940 | ||
1941 | # if ENABLE_USERNAME_OR_HOMEDIR | ||
1893 | if (cwd_buf != (char *)bb_msg_unknown) | 1942 | if (cwd_buf != (char *)bb_msg_unknown) |
1894 | free(cwd_buf); | 1943 | free(cwd_buf); |
1944 | # endif | ||
1895 | cmdedit_prompt = prmt_mem_ptr; | 1945 | cmdedit_prompt = prmt_mem_ptr; |
1896 | put_prompt(); | 1946 | put_prompt(); |
1897 | } | 1947 | } |