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 | |
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')
-rw-r--r-- | libbb/dump.c | 2 | ||||
-rw-r--r-- | libbb/lineedit.c | 124 | ||||
-rw-r--r-- | libbb/login.c | 3 | ||||
-rw-r--r-- | libbb/time.c | 21 |
4 files changed, 110 insertions, 40 deletions
diff --git a/libbb/dump.c b/libbb/dump.c index 7e435643b..566881a78 100644 --- a/libbb/dump.c +++ b/libbb/dump.c | |||
@@ -333,7 +333,7 @@ static void do_skip(priv_dumper_t *dumper, const char *fname, int statok) | |||
333 | return; | 333 | return; |
334 | } | 334 | } |
335 | } | 335 | } |
336 | if (fseek(stdin, dumper->pub.dump_skip, SEEK_SET)) { | 336 | if (fseeko(stdin, dumper->pub.dump_skip, SEEK_SET)) { |
337 | bb_simple_perror_msg_and_die(fname); | 337 | bb_simple_perror_msg_and_die(fname); |
338 | } | 338 | } |
339 | dumper->address += dumper->pub.dump_skip; | 339 | dumper->address += dumper->pub.dump_skip; |
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 | } |
diff --git a/libbb/login.c b/libbb/login.c index 8a82c6add..8f080b775 100644 --- a/libbb/login.c +++ b/libbb/login.c | |||
@@ -16,7 +16,6 @@ | |||
16 | #define LOGIN " login: " | 16 | #define LOGIN " login: " |
17 | 17 | ||
18 | static const char fmtstr_d[] ALIGN1 = "%A, %d %B %Y"; | 18 | static const char fmtstr_d[] ALIGN1 = "%A, %d %B %Y"; |
19 | static const char fmtstr_t[] ALIGN1 = "%H:%M:%S"; | ||
20 | 19 | ||
21 | void FAST_FUNC print_login_issue(const char *issue_file, const char *tty) | 20 | void FAST_FUNC print_login_issue(const char *issue_file, const char *tty) |
22 | { | 21 | { |
@@ -73,7 +72,7 @@ void FAST_FUNC print_login_issue(const char *issue_file, const char *tty) | |||
73 | strftime(buf, sizeof(buf), fmtstr_d, localtime(&t)); | 72 | strftime(buf, sizeof(buf), fmtstr_d, localtime(&t)); |
74 | break; | 73 | break; |
75 | case 't': | 74 | case 't': |
76 | strftime(buf, sizeof(buf), fmtstr_t, localtime(&t)); | 75 | strftime_HHMMSS(buf, sizeof(buf), &t); |
77 | break; | 76 | break; |
78 | case 'l': | 77 | case 'l': |
79 | outbuf = tty; | 78 | outbuf = tty; |
diff --git a/libbb/time.c b/libbb/time.c index e2b938471..57e14b66c 100644 --- a/libbb/time.c +++ b/libbb/time.c | |||
@@ -187,6 +187,27 @@ time_t FAST_FUNC validate_tm_time(const char *date_str, struct tm *ptm) | |||
187 | return t; | 187 | return t; |
188 | } | 188 | } |
189 | 189 | ||
190 | static char* strftime_fmt(char *buf, unsigned len, time_t *tp, const char *fmt) | ||
191 | { | ||
192 | time_t t; | ||
193 | if (!tp) { | ||
194 | tp = &t; | ||
195 | time(tp); | ||
196 | } | ||
197 | /* Returns pointer to NUL */ | ||
198 | return buf + strftime(buf, len, fmt, localtime(tp)); | ||
199 | } | ||
200 | |||
201 | char* FAST_FUNC strftime_HHMMSS(char *buf, unsigned len, time_t *tp) | ||
202 | { | ||
203 | return strftime_fmt(buf, len, tp, "%H:%M:%S"); | ||
204 | } | ||
205 | |||
206 | char* FAST_FUNC strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) | ||
207 | { | ||
208 | return strftime_fmt(buf, len, tp, "%Y-%m-%d %H:%M:%S"); | ||
209 | } | ||
210 | |||
190 | #if ENABLE_MONOTONIC_SYSCALL | 211 | #if ENABLE_MONOTONIC_SYSCALL |
191 | 212 | ||
192 | #include <sys/syscall.h> | 213 | #include <sys/syscall.h> |