diff options
author | Ron Yorston <rmy@pobox.com> | 2016-10-19 17:01:55 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2016-10-19 17:01:55 +0100 |
commit | 075814c60a316cfd088c88f26f75ab21b5850b98 (patch) | |
tree | f6e33ac693630827deb309faa5fa4931588db57d /miscutils | |
parent | 977d65c1bbc57f5cdd0c8bfd67c8b5bb1cd390dd (diff) | |
parent | f37e1155aabde6bd95d267a8aec347cedccb8bc3 (diff) | |
download | busybox-w32-075814c60a316cfd088c88f26f75ab21b5850b98.tar.gz busybox-w32-075814c60a316cfd088c88f26f75ab21b5850b98.tar.bz2 busybox-w32-075814c60a316cfd088c88f26f75ab21b5850b98.zip |
Merge branch busybox (up to "ash: comment out free(p) just before...")
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/less.c | 43 | ||||
-rw-r--r-- | miscutils/man.c | 4 |
2 files changed, 33 insertions, 14 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index f9f6f62d9..8ba687872 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -173,6 +173,7 @@ enum { pattern_valid = 0 }; | |||
173 | struct globals { | 173 | struct globals { |
174 | int cur_fline; /* signed */ | 174 | int cur_fline; /* signed */ |
175 | int kbd_fd; /* fd to get input from */ | 175 | int kbd_fd; /* fd to get input from */ |
176 | int kbd_fd_orig_flags; | ||
176 | int less_gets_pos; | 177 | int less_gets_pos; |
177 | /* last position in last line, taking into account tabs */ | 178 | /* last position in last line, taking into account tabs */ |
178 | size_t last_line_pos; | 179 | size_t last_line_pos; |
@@ -308,6 +309,8 @@ static void print_statusline(const char *str) | |||
308 | static void less_exit(int code) | 309 | static void less_exit(int code) |
309 | { | 310 | { |
310 | set_tty_cooked(); | 311 | set_tty_cooked(); |
312 | if (!(G.kbd_fd_orig_flags & O_NONBLOCK)) | ||
313 | ndelay_off(kbd_fd); | ||
311 | clear_line(); | 314 | clear_line(); |
312 | if (code < 0) | 315 | if (code < 0) |
313 | kill_myself_with_sig(- code); /* does not return */ | 316 | kill_myself_with_sig(- code); /* does not return */ |
@@ -1661,16 +1664,23 @@ static char opp_bracket(char bracket) | |||
1661 | 1664 | ||
1662 | static void match_right_bracket(char bracket) | 1665 | static void match_right_bracket(char bracket) |
1663 | { | 1666 | { |
1664 | unsigned i; | 1667 | unsigned i = cur_fline; |
1665 | 1668 | ||
1666 | if (strchr(flines[cur_fline], bracket) == NULL) { | 1669 | if (i >= max_fline |
1670 | || strchr(flines[i], bracket) == NULL | ||
1671 | ) { | ||
1667 | print_statusline("No bracket in top line"); | 1672 | print_statusline("No bracket in top line"); |
1668 | return; | 1673 | return; |
1669 | } | 1674 | } |
1675 | |||
1670 | bracket = opp_bracket(bracket); | 1676 | bracket = opp_bracket(bracket); |
1671 | for (i = cur_fline + 1; i < max_fline; i++) { | 1677 | for (; i < max_fline; i++) { |
1672 | if (strchr(flines[i], bracket) != NULL) { | 1678 | if (strchr(flines[i], bracket) != NULL) { |
1673 | buffer_line(i); | 1679 | /* |
1680 | * Line with matched right bracket becomes | ||
1681 | * last visible line | ||
1682 | */ | ||
1683 | buffer_line(i - max_displayed_line); | ||
1674 | return; | 1684 | return; |
1675 | } | 1685 | } |
1676 | } | 1686 | } |
@@ -1679,16 +1689,22 @@ static void match_right_bracket(char bracket) | |||
1679 | 1689 | ||
1680 | static void match_left_bracket(char bracket) | 1690 | static void match_left_bracket(char bracket) |
1681 | { | 1691 | { |
1682 | int i; | 1692 | int i = cur_fline + max_displayed_line; |
1683 | 1693 | ||
1684 | if (strchr(flines[cur_fline + max_displayed_line], bracket) == NULL) { | 1694 | if (i >= max_fline |
1695 | || strchr(flines[i], bracket) == NULL | ||
1696 | ) { | ||
1685 | print_statusline("No bracket in bottom line"); | 1697 | print_statusline("No bracket in bottom line"); |
1686 | return; | 1698 | return; |
1687 | } | 1699 | } |
1688 | 1700 | ||
1689 | bracket = opp_bracket(bracket); | 1701 | bracket = opp_bracket(bracket); |
1690 | for (i = cur_fline + max_displayed_line; i >= 0; i--) { | 1702 | for (; i >= 0; i--) { |
1691 | if (strchr(flines[i], bracket) != NULL) { | 1703 | if (strchr(flines[i], bracket) != NULL) { |
1704 | /* | ||
1705 | * Line with matched left bracket becomes | ||
1706 | * first visible line | ||
1707 | */ | ||
1692 | buffer_line(i); | 1708 | buffer_line(i); |
1693 | return; | 1709 | return; |
1694 | } | 1710 | } |
@@ -1859,9 +1875,10 @@ int less_main(int argc, char **argv) | |||
1859 | /* Some versions of less can survive w/o controlling tty, | 1875 | /* Some versions of less can survive w/o controlling tty, |
1860 | * try to do the same. This also allows to specify an alternative | 1876 | * try to do the same. This also allows to specify an alternative |
1861 | * tty via "less 1<>TTY". | 1877 | * tty via "less 1<>TTY". |
1862 | * We don't try to use STDOUT_FILENO directly, | 1878 | * |
1879 | * We prefer not to use STDOUT_FILENO directly, | ||
1863 | * since we want to set this fd to non-blocking mode, | 1880 | * since we want to set this fd to non-blocking mode, |
1864 | * and not bother with restoring it on exit. | 1881 | * and not interfere with other processes which share stdout with us. |
1865 | */ | 1882 | */ |
1866 | tty_name = xmalloc_ttyname(STDOUT_FILENO); | 1883 | tty_name = xmalloc_ttyname(STDOUT_FILENO); |
1867 | if (tty_name) { | 1884 | if (tty_name) { |
@@ -1873,10 +1890,12 @@ int less_main(int argc, char **argv) | |||
1873 | /* Try controlling tty */ | 1890 | /* Try controlling tty */ |
1874 | try_ctty: | 1891 | try_ctty: |
1875 | tty_fd = open(CURRENT_TTY, O_RDONLY); | 1892 | tty_fd = open(CURRENT_TTY, O_RDONLY); |
1876 | if (tty_fd < 0) | 1893 | if (tty_fd < 0) { |
1877 | return bb_cat(argv); | 1894 | /* If all else fails, less 481 uses stdout. Mimic that */ |
1895 | tty_fd = STDOUT_FILENO; | ||
1896 | } | ||
1878 | } | 1897 | } |
1879 | ndelay_on(tty_fd); | 1898 | G.kbd_fd_orig_flags = ndelay_on(tty_fd); |
1880 | kbd_fd = tty_fd; /* save in a global */ | 1899 | kbd_fd = tty_fd; /* save in a global */ |
1881 | #else | 1900 | #else |
1882 | kbd_fd = 0; | 1901 | kbd_fd = 0; |
diff --git a/miscutils/man.c b/miscutils/man.c index 4ce40b247..6d32890d1 100644 --- a/miscutils/man.c +++ b/miscutils/man.c | |||
@@ -232,8 +232,8 @@ int man_main(int argc UNUSED_PARAM, char **argv) | |||
232 | if (!token[1]) | 232 | if (!token[1]) |
233 | continue; | 233 | continue; |
234 | if (strcmp("DEFINE", token[0]) == 0) { | 234 | if (strcmp("DEFINE", token[0]) == 0) { |
235 | if (is_prefixed_with("pager", token[1])) { | 235 | if (is_prefixed_with(token[1], "pager")) { |
236 | pager = xstrdup(skip_whitespace(token[1]) + 5); | 236 | pager = xstrdup(skip_whitespace(token[1] + 5)); |
237 | } | 237 | } |
238 | } else | 238 | } else |
239 | if (strcmp("MANDATORY_MANPATH"+10, token[0]) == 0 /* "MANPATH"? */ | 239 | if (strcmp("MANDATORY_MANPATH"+10, token[0]) == 0 /* "MANPATH"? */ |