diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-10 15:08:44 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-10 15:08:44 +0000 |
| commit | e8a0788b249cbac5bf5b2aa2d81bb8f6b29a7a4b (patch) | |
| tree | fcdf3d51b6d60986b634c693d71355867bca82ff /libbb | |
| parent | d4fea900bdb92d7bba71348a40cb00b6748a8ecc (diff) | |
| download | busybox-w32-e8a0788b249cbac5bf5b2aa2d81bb8f6b29a7a4b.tar.gz busybox-w32-e8a0788b249cbac5bf5b2aa2d81bb8f6b29a7a4b.tar.bz2 busybox-w32-e8a0788b249cbac5bf5b2aa2d81bb8f6b29a7a4b.zip | |
moved biggest stack buffers to malloc space, or made their size configurable
(8k of shell line edit buffer is an overkill)
# make ARCH=i386 bloatcheck
function old new delta
read_line_input 3933 3967 +34
ifaddrlist 348 345 -3
do_loadfont 208 191 -17
edit_file 840 819 -21
.rodata 129112 129080 -32
uncompress 1305 1268 -37
loadfont_main 566 495 -71
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/6 up/down: 34/-181) Total: -147 bytes
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/Config.in | 12 | ||||
| -rw-r--r-- | libbb/lineedit.c | 45 |
2 files changed, 34 insertions, 23 deletions
diff --git a/libbb/Config.in b/libbb/Config.in index 112a3d658..a1ff7c056 100644 --- a/libbb/Config.in +++ b/libbb/Config.in | |||
| @@ -30,7 +30,17 @@ config FEATURE_EDITING | |||
| 30 | bool "Command line editing" | 30 | bool "Command line editing" |
| 31 | default n | 31 | default n |
| 32 | help | 32 | help |
| 33 | Enable command editing (mainly for shell). | 33 | Enable line editing (mainly for shell command line). |
| 34 | |||
| 35 | config FEATURE_EDITING_MAX_LEN | ||
| 36 | int "Maximum length of input" | ||
| 37 | range 128 8192 | ||
| 38 | default 1024 | ||
| 39 | depends on FEATURE_EDITING | ||
| 40 | help | ||
| 41 | Line editing code uses on-stack buffers for storage. | ||
| 42 | You may want to decrease this parameter if your target machine | ||
| 43 | benefits from smaller stack usage. | ||
| 34 | 44 | ||
| 35 | config FEATURE_EDITING_FANCY_KEYS | 45 | config FEATURE_EDITING_FANCY_KEYS |
| 36 | bool "Additional editing keys" | 46 | bool "Additional editing keys" |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index b950d7f26..1f2e6a54e 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
| @@ -28,7 +28,6 @@ | |||
| 28 | - not true viewing if length prompt less terminal width | 28 | - not true viewing if length prompt less terminal width |
| 29 | */ | 29 | */ |
| 30 | 30 | ||
| 31 | //#include <sys/ioctl.h> | ||
| 32 | #include "libbb.h" | 31 | #include "libbb.h" |
| 33 | 32 | ||
| 34 | 33 | ||
| @@ -59,6 +58,7 @@ | |||
| 59 | #define ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR \ | 58 | #define ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR \ |
| 60 | (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) | 59 | (ENABLE_FEATURE_USERNAME_COMPLETION || ENABLE_FEATURE_EDITING_FANCY_PROMPT) |
| 61 | 60 | ||
| 61 | enum { MAX_LINELEN = CONFIG_FEATURE_EDITING_MAX_LEN }; | ||
| 62 | 62 | ||
| 63 | static line_input_t *state; | 63 | static line_input_t *state; |
| 64 | 64 | ||
| @@ -327,8 +327,8 @@ static void username_tab_completion(char *ud, char *with_shash_flg) | |||
| 327 | home = entry->pw_dir; | 327 | home = entry->pw_dir; |
| 328 | } | 328 | } |
| 329 | if (home) { | 329 | if (home) { |
| 330 | if ((userlen + strlen(home) + 1) < BUFSIZ) { | 330 | if ((userlen + strlen(home) + 1) < MAX_LINELEN) { |
| 331 | char temp2[BUFSIZ]; /* argument size */ | 331 | char temp2[MAX_LINELEN]; /* argument size */ |
| 332 | 332 | ||
| 333 | /* /home/user/... */ | 333 | /* /home/user/... */ |
| 334 | sprintf(temp2, "%s%s", home, ud); | 334 | sprintf(temp2, "%s%s", home, ud); |
| @@ -410,7 +410,7 @@ static void exe_n_cwd_tab_completion(char *command, int type) | |||
| 410 | { | 410 | { |
| 411 | DIR *dir; | 411 | DIR *dir; |
| 412 | struct dirent *next; | 412 | struct dirent *next; |
| 413 | char dirbuf[BUFSIZ]; | 413 | char dirbuf[MAX_LINELEN]; |
| 414 | struct stat st; | 414 | struct stat st; |
| 415 | char *path1[1]; | 415 | char *path1[1]; |
| 416 | char **paths = path1; | 416 | char **paths = path1; |
| @@ -496,16 +496,16 @@ static void exe_n_cwd_tab_completion(char *command, int type) | |||
| 496 | #define QUOT (UCHAR_MAX+1) | 496 | #define QUOT (UCHAR_MAX+1) |
| 497 | 497 | ||
| 498 | #define collapse_pos(is, in) { \ | 498 | #define collapse_pos(is, in) { \ |
| 499 | memmove(int_buf+(is), int_buf+(in), (BUFSIZ+1-(is)-(in))*sizeof(int)); \ | 499 | memmove(int_buf+(is), int_buf+(in), (MAX_LINELEN+1-(is)-(in))*sizeof(int)); \ |
| 500 | memmove(pos_buf+(is), pos_buf+(in), (BUFSIZ+1-(is)-(in))*sizeof(int)); } | 500 | memmove(pos_buf+(is), pos_buf+(in), (MAX_LINELEN+1-(is)-(in))*sizeof(int)); } |
| 501 | 501 | ||
| 502 | static int find_match(char *matchBuf, int *len_with_quotes) | 502 | static int find_match(char *matchBuf, int *len_with_quotes) |
| 503 | { | 503 | { |
| 504 | int i, j; | 504 | int i, j; |
| 505 | int command_mode; | 505 | int command_mode; |
| 506 | int c, c2; | 506 | int c, c2; |
| 507 | int int_buf[BUFSIZ + 1]; | 507 | int int_buf[MAX_LINELEN + 1]; |
| 508 | int pos_buf[BUFSIZ + 1]; | 508 | int pos_buf[MAX_LINELEN + 1]; |
| 509 | 509 | ||
| 510 | /* set to integer dimension characters and own positions */ | 510 | /* set to integer dimension characters and own positions */ |
| 511 | for (i = 0;; i++) { | 511 | for (i = 0;; i++) { |
| @@ -731,7 +731,7 @@ static void input_tab(int *lastWasTab) | |||
| 731 | if (!*lastWasTab) { | 731 | if (!*lastWasTab) { |
| 732 | char *tmp, *tmp1; | 732 | char *tmp, *tmp1; |
| 733 | int len_found; | 733 | int len_found; |
| 734 | char matchBuf[BUFSIZ]; | 734 | char matchBuf[MAX_LINELEN]; |
| 735 | int find_type; | 735 | int find_type; |
| 736 | int recalc_pos; | 736 | int recalc_pos; |
| 737 | 737 | ||
| @@ -781,6 +781,7 @@ static void input_tab(int *lastWasTab) | |||
| 781 | if (!matches) | 781 | if (!matches) |
| 782 | return; /* not found */ | 782 | return; /* not found */ |
| 783 | /* find minimal match */ | 783 | /* find minimal match */ |
| 784 | // ash: yet another failure in trying to achieve "we don't die on OOM" | ||
| 784 | tmp1 = xstrdup(matches[0]); | 785 | tmp1 = xstrdup(matches[0]); |
| 785 | for (tmp = tmp1; *tmp; tmp++) | 786 | for (tmp = tmp1; *tmp; tmp++) |
| 786 | for (len_found = 1; len_found < num_matches; len_found++) | 787 | for (len_found = 1; len_found < num_matches; len_found++) |
| @@ -807,7 +808,7 @@ static void input_tab(int *lastWasTab) | |||
| 807 | } | 808 | } |
| 808 | len_found = strlen(tmp); | 809 | len_found = strlen(tmp); |
| 809 | /* have space to placed match? */ | 810 | /* have space to placed match? */ |
| 810 | if ((len_found - strlen(matchBuf) + command_len) < BUFSIZ) { | 811 | if ((len_found - strlen(matchBuf) + command_len) < MAX_LINELEN) { |
| 811 | /* before word for match */ | 812 | /* before word for match */ |
| 812 | command_ps[cursor - recalc_pos] = 0; | 813 | command_ps[cursor - recalc_pos] = 0; |
| 813 | /* save tail line */ | 814 | /* save tail line */ |
| @@ -888,14 +889,14 @@ static void load_history(const char *fromfile) | |||
| 888 | fp = fopen(fromfile, "r"); | 889 | fp = fopen(fromfile, "r"); |
| 889 | if (fp) { | 890 | if (fp) { |
| 890 | for (hi = 0; hi < MAX_HISTORY;) { | 891 | for (hi = 0; hi < MAX_HISTORY;) { |
| 891 | char * hl = xmalloc_getline(fp); | 892 | char *hl = xmalloc_getline(fp); |
| 892 | int l; | 893 | int l; |
| 893 | 894 | ||
| 894 | if (!hl) | 895 | if (!hl) |
| 895 | break; | 896 | break; |
| 896 | l = strlen(hl); | 897 | l = strlen(hl); |
| 897 | if (l >= BUFSIZ) | 898 | if (l >= MAX_LINELEN) |
| 898 | hl[BUFSIZ-1] = 0; | 899 | hl[MAX_LINELEN-1] = '\0'; |
| 899 | if (l == 0 || hl[0] == ' ') { | 900 | if (l == 0 || hl[0] == ' ') { |
| 900 | free(hl); | 901 | free(hl); |
| 901 | continue; | 902 | continue; |
| @@ -1264,8 +1265,8 @@ int read_line_input(const char* prompt, char* command, int maxsize, line_input_t | |||
| 1264 | #endif | 1265 | #endif |
| 1265 | 1266 | ||
| 1266 | // FIXME: audit & improve this | 1267 | // FIXME: audit & improve this |
| 1267 | if (maxsize > BUFSIZ) | 1268 | if (maxsize > MAX_LINELEN) |
| 1268 | maxsize = BUFSIZ; | 1269 | maxsize = MAX_LINELEN; |
| 1269 | 1270 | ||
| 1270 | /* With null flags, no other fields are ever used */ | 1271 | /* With null flags, no other fields are ever used */ |
| 1271 | state = st ? st : (line_input_t*) &const_int_0; | 1272 | state = st ? st : (line_input_t*) &const_int_0; |
| @@ -1646,14 +1647,14 @@ int read_line_input(const char* prompt, char* command, int maxsize, line_input_t | |||
| 1646 | /* Delete */ | 1647 | /* Delete */ |
| 1647 | input_delete(0); | 1648 | input_delete(0); |
| 1648 | break; | 1649 | break; |
| 1649 | case '1': | 1650 | case '1': // vt100? linux vt? or what? |
| 1650 | case 'H': | 1651 | case '7': // vt100? linux vt? or what? |
| 1651 | /* <Home> */ | 1652 | case 'H': /* xterm's <Home> */ |
| 1652 | input_backward(cursor); | 1653 | input_backward(cursor); |
| 1653 | break; | 1654 | break; |
| 1654 | case '4': | 1655 | case '4': // vt100? linux vt? or what? |
| 1655 | case 'F': | 1656 | case '8': // vt100? linux vt? or what? |
| 1656 | /* <End> */ | 1657 | case 'F': /* xterm's <End> */ |
| 1657 | input_end(); | 1658 | input_end(); |
| 1658 | break; | 1659 | break; |
| 1659 | default: | 1660 | default: |
| @@ -1766,7 +1767,7 @@ const char *applet_name = "debug stuff usage"; | |||
| 1766 | 1767 | ||
| 1767 | int main(int argc, char **argv) | 1768 | int main(int argc, char **argv) |
| 1768 | { | 1769 | { |
| 1769 | char buff[BUFSIZ]; | 1770 | char buff[MAX_LINELEN]; |
| 1770 | char *prompt = | 1771 | char *prompt = |
| 1771 | #if ENABLE_FEATURE_EDITING_FANCY_PROMPT | 1772 | #if ENABLE_FEATURE_EDITING_FANCY_PROMPT |
| 1772 | "\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:" | 1773 | "\\[\\033[32;1m\\]\\u@\\[\\x1b[33;1m\\]\\h:" |
