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 /editors | |
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 'editors')
-rw-r--r-- | editors/Config.in | 10 | ||||
-rw-r--r-- | editors/vi.c | 50 |
2 files changed, 36 insertions, 24 deletions
diff --git a/editors/Config.in b/editors/Config.in index fd840ae9a..936004c9b 100644 --- a/editors/Config.in +++ b/editors/Config.in | |||
@@ -50,6 +50,16 @@ config VI | |||
50 | learning curve. If you are not already comfortable with 'vi' | 50 | learning curve. If you are not already comfortable with 'vi' |
51 | you may wish to use something else. | 51 | you may wish to use something else. |
52 | 52 | ||
53 | config FEATURE_VI_MAX_LEN | ||
54 | int "Maximum line length in vi" | ||
55 | range 256 16384 | ||
56 | default 1024 | ||
57 | depends on VI | ||
58 | help | ||
59 | vi uses on-stack buffers for intermediate line buffers. | ||
60 | You may want to decrease this parameter if your target machine | ||
61 | benefits from smaller stack usage. | ||
62 | |||
53 | config FEATURE_VI_COLON | 63 | config FEATURE_VI_COLON |
54 | bool "Enable \":\" colon commands (no \"ex\" mode)" | 64 | bool "Enable \":\" colon commands (no \"ex\" mode)" |
55 | default y | 65 | default y |
diff --git a/editors/vi.c b/editors/vi.c index cd64aacc9..b961ca5b8 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -32,7 +32,10 @@ | |||
32 | #define Isprint(c) ((unsigned char)(c) >= ' ' && (c) != 0x7f && (unsigned char)(c) != 0x9b) | 32 | #define Isprint(c) ((unsigned char)(c) >= ' ' && (c) != 0x7f && (unsigned char)(c) != 0x9b) |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #define MAX_SCR_COLS BUFSIZ | 35 | enum { |
36 | MAX_LINELEN = CONFIG_FEATURE_VI_MAX_LEN, | ||
37 | MAX_SCR_COLS = CONFIG_FEATURE_VI_MAX_LEN, | ||
38 | }; | ||
36 | 39 | ||
37 | // Misc. non-Ascii keys that report an escape sequence | 40 | // Misc. non-Ascii keys that report an escape sequence |
38 | #define VI_K_UP (char)128 // cursor key Up | 41 | #define VI_K_UP (char)128 // cursor key Up |
@@ -545,7 +548,7 @@ static char *get_one_address(char * p, int *addr) // get colon addr, if present | |||
545 | char c; | 548 | char c; |
546 | #endif | 549 | #endif |
547 | #if ENABLE_FEATURE_VI_SEARCH | 550 | #if ENABLE_FEATURE_VI_SEARCH |
548 | char *pat, buf[BUFSIZ]; | 551 | char *pat, buf[MAX_LINELEN]; |
549 | #endif | 552 | #endif |
550 | 553 | ||
551 | *addr = -1; // assume no addr | 554 | *addr = -1; // assume no addr |
@@ -648,7 +651,7 @@ static void setops(const char *args, const char *opname, int flg_no, | |||
648 | static void colon(char * buf) | 651 | static void colon(char * buf) |
649 | { | 652 | { |
650 | char c, *orig_buf, *buf1, *q, *r; | 653 | char c, *orig_buf, *buf1, *q, *r; |
651 | char *fn, cmd[BUFSIZ], args[BUFSIZ]; | 654 | char *fn, cmd[MAX_LINELEN], args[MAX_LINELEN]; |
652 | int i, l, li, ch, b, e; | 655 | int i, l, li, ch, b, e; |
653 | int useforce = FALSE, forced = FALSE; | 656 | int useforce = FALSE, forced = FALSE; |
654 | struct stat st_buf; | 657 | struct stat st_buf; |
@@ -679,8 +682,8 @@ static void colon(char * buf) | |||
679 | r = end - 1; | 682 | r = end - 1; |
680 | li = count_lines(text, end - 1); | 683 | li = count_lines(text, end - 1); |
681 | fn = cfn; // default to current file | 684 | fn = cfn; // default to current file |
682 | memset(cmd, '\0', BUFSIZ); // clear cmd[] | 685 | memset(cmd, '\0', MAX_LINELEN); // clear cmd[] |
683 | memset(args, '\0', BUFSIZ); // clear args[] | 686 | memset(args, '\0', MAX_LINELEN); // clear args[] |
684 | 687 | ||
685 | // look for optional address(es) :. :1 :1,9 :'q,'a :% | 688 | // look for optional address(es) :. :1 :1,9 :'q,'a :% |
686 | buf = get_address(buf, &b, &e); | 689 | buf = get_address(buf, &b, &e); |
@@ -763,10 +766,10 @@ static void colon(char * buf) | |||
763 | } | 766 | } |
764 | if (args[0]) { | 767 | if (args[0]) { |
765 | // the user supplied a file name | 768 | // the user supplied a file name |
766 | fn= args; | 769 | fn = args; |
767 | } else if (cfn && cfn[0]) { | 770 | } else if (cfn && cfn[0]) { |
768 | // no user supplied name- use the current filename | 771 | // no user supplied name- use the current filename |
769 | fn= cfn; | 772 | fn = cfn; |
770 | goto vc5; | 773 | goto vc5; |
771 | } else { | 774 | } else { |
772 | // no user file name, no current name- punt | 775 | // no user file name, no current name- punt |
@@ -1984,8 +1987,7 @@ static void start_new_cmd_q(char c) | |||
1984 | // release old cmd | 1987 | // release old cmd |
1985 | free(last_modifying_cmd); | 1988 | free(last_modifying_cmd); |
1986 | // get buffer for new cmd | 1989 | // get buffer for new cmd |
1987 | last_modifying_cmd = xmalloc(BUFSIZ); | 1990 | last_modifying_cmd = xzalloc(MAX_LINELEN); |
1988 | memset(last_modifying_cmd, '\0', BUFSIZ); // clear new cmd queue | ||
1989 | // if there is a current cmd count put it in the buffer first | 1991 | // if there is a current cmd count put it in the buffer first |
1990 | if (cmdcnt > 0) | 1992 | if (cmdcnt > 0) |
1991 | sprintf(last_modifying_cmd, "%d%c", cmdcnt, c); | 1993 | sprintf(last_modifying_cmd, "%d%c", cmdcnt, c); |
@@ -2238,7 +2240,7 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2238 | if (n <= 0) { | 2240 | if (n <= 0) { |
2239 | ri0: | 2241 | ri0: |
2240 | // the Q is empty, wait for a typed char | 2242 | // the Q is empty, wait for a typed char |
2241 | n = read(0, readbuffer, BUFSIZ - 1); | 2243 | n = read(0, readbuffer, MAX_LINELEN - 1); |
2242 | if (n < 0) { | 2244 | if (n < 0) { |
2243 | if (errno == EINTR) | 2245 | if (errno == EINTR) |
2244 | goto ri0; // interrupted sys call | 2246 | goto ri0; // interrupted sys call |
@@ -2268,9 +2270,9 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2268 | tv.tv_usec = 50000; // Wait 5/100 seconds- 1 Sec=1000000 | 2270 | tv.tv_usec = 50000; // Wait 5/100 seconds- 1 Sec=1000000 |
2269 | 2271 | ||
2270 | // keep reading while there are input chars and room in buffer | 2272 | // keep reading while there are input chars and room in buffer |
2271 | while (select(1, &rfds, NULL, NULL, &tv) > 0 && n <= (BUFSIZ - 5)) { | 2273 | while (select(1, &rfds, NULL, NULL, &tv) > 0 && n <= (MAX_LINELEN - 5)) { |
2272 | // read the rest of the ESC string | 2274 | // read the rest of the ESC string |
2273 | int r = read(0, (void *) (readbuffer + n), BUFSIZ - n); | 2275 | int r = read(0, (void *) (readbuffer + n), MAX_LINELEN - n); |
2274 | if (r > 0) { | 2276 | if (r > 0) { |
2275 | n += r; | 2277 | n += r; |
2276 | } | 2278 | } |
@@ -2305,7 +2307,7 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2305 | } | 2307 | } |
2306 | // remove key sequence from Q | 2308 | // remove key sequence from Q |
2307 | readed_for_parse -= n; | 2309 | readed_for_parse -= n; |
2308 | memmove(readbuffer, readbuffer + n, BUFSIZ - n); | 2310 | memmove(readbuffer, readbuffer + n, MAX_LINELEN - n); |
2309 | alarm(3); // we are done waiting for input, turn alarm ON | 2311 | alarm(3); // we are done waiting for input, turn alarm ON |
2310 | return c; | 2312 | return c; |
2311 | } | 2313 | } |
@@ -2340,7 +2342,7 @@ static char get_one_char(void) | |||
2340 | c = readit(); // get the users input | 2342 | c = readit(); // get the users input |
2341 | if (last_modifying_cmd != 0) { | 2343 | if (last_modifying_cmd != 0) { |
2342 | int len = strlen(last_modifying_cmd); | 2344 | int len = strlen(last_modifying_cmd); |
2343 | if (len + 1 >= BUFSIZ) { | 2345 | if (len >= MAX_LINELEN - 1) { |
2344 | psbs("last_modifying_cmd overrun"); | 2346 | psbs("last_modifying_cmd overrun"); |
2345 | } else { | 2347 | } else { |
2346 | // add new char to q | 2348 | // add new char to q |
@@ -2358,7 +2360,7 @@ static char *get_input_line(const char * prompt) // get input line- use "status | |||
2358 | { | 2360 | { |
2359 | static char *obufp; | 2361 | static char *obufp; |
2360 | 2362 | ||
2361 | char buf[BUFSIZ]; | 2363 | char buf[MAX_LINELEN]; |
2362 | char c; | 2364 | char c; |
2363 | int i; | 2365 | int i; |
2364 | 2366 | ||
@@ -2369,7 +2371,7 @@ static char *get_input_line(const char * prompt) // get input line- use "status | |||
2369 | write1(prompt); // write out the :, /, or ? prompt | 2371 | write1(prompt); // write out the :, /, or ? prompt |
2370 | 2372 | ||
2371 | i = strlen(buf); | 2373 | i = strlen(buf); |
2372 | while (i < BUFSIZ) { | 2374 | while (i < MAX_LINELEN) { |
2373 | c = get_one_char(); // read user input | 2375 | c = get_one_char(); // read user input |
2374 | if (c == '\n' || c == '\r' || c == 27) | 2376 | if (c == '\n' || c == '\r' || c == 27) |
2375 | break; // is this end of input | 2377 | break; // is this end of input |
@@ -2514,16 +2516,16 @@ static int file_write(char * fn, char * first, char * last) | |||
2514 | //----- Move the cursor to row x col (count from 0, not 1) ------- | 2516 | //----- Move the cursor to row x col (count from 0, not 1) ------- |
2515 | static void place_cursor(int row, int col, int opti) | 2517 | static void place_cursor(int row, int col, int opti) |
2516 | { | 2518 | { |
2517 | char cm1[BUFSIZ]; | 2519 | char cm1[MAX_LINELEN]; |
2518 | char *cm; | 2520 | char *cm; |
2519 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR | 2521 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR |
2520 | char cm2[BUFSIZ]; | 2522 | char cm2[MAX_LINELEN]; |
2521 | char *screenp; | 2523 | char *screenp; |
2522 | // char cm3[BUFSIZ]; | 2524 | // char cm3[MAX_LINELEN]; |
2523 | int Rrow = last_row; | 2525 | int Rrow = last_row; |
2524 | #endif | 2526 | #endif |
2525 | 2527 | ||
2526 | memset(cm1, '\0', BUFSIZ - 1); // clear the buffer | 2528 | memset(cm1, '\0', MAX_LINELEN); // clear the buffer |
2527 | 2529 | ||
2528 | if (row < 0) row = 0; | 2530 | if (row < 0) row = 0; |
2529 | if (row >= rows) row = rows - 1; | 2531 | if (row >= rows) row = rows - 1; |
@@ -2539,7 +2541,7 @@ static void place_cursor(int row, int col, int opti) | |||
2539 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR | 2541 | #if ENABLE_FEATURE_VI_OPTIMIZE_CURSOR |
2540 | //----- find the minimum # of chars to move cursor ------------- | 2542 | //----- find the minimum # of chars to move cursor ------------- |
2541 | //----- 2. Try moving with discreet chars (Newline, [back]space, ...) | 2543 | //----- 2. Try moving with discreet chars (Newline, [back]space, ...) |
2542 | memset(cm2, '\0', BUFSIZ - 1); // clear the buffer | 2544 | memset(cm2, '\0', MAX_LINELEN); // clear the buffer |
2543 | 2545 | ||
2544 | // move to the correct row | 2546 | // move to the correct row |
2545 | while (row < Rrow) { | 2547 | while (row < Rrow) { |
@@ -2696,7 +2698,7 @@ static void psb(const char *format, ...) | |||
2696 | 2698 | ||
2697 | static void ni(const char * s) // display messages | 2699 | static void ni(const char * s) // display messages |
2698 | { | 2700 | { |
2699 | char buf[BUFSIZ]; | 2701 | char buf[MAX_LINELEN]; |
2700 | 2702 | ||
2701 | print_literal(buf, s); | 2703 | print_literal(buf, s); |
2702 | psbs("\'%s\' is not implemented", buf); | 2704 | psbs("\'%s\' is not implemented", buf); |
@@ -3900,7 +3902,7 @@ static void crash_dummy() | |||
3900 | cd0: | 3902 | cd0: |
3901 | startrbi = rbi = 0; | 3903 | startrbi = rbi = 0; |
3902 | sleeptime = 0; // how long to pause between commands | 3904 | sleeptime = 0; // how long to pause between commands |
3903 | memset(readbuffer, '\0', BUFSIZ); // clear the read buffer | 3905 | memset(readbuffer, '\0', MAX_LINELEN); // clear the read buffer |
3904 | // generate a command by percentages | 3906 | // generate a command by percentages |
3905 | percent = (int) lrand48() % 100; // get a number from 0-99 | 3907 | percent = (int) lrand48() % 100; // get a number from 0-99 |
3906 | if (percent < Mp) { // Movement commands | 3908 | if (percent < Mp) { // Movement commands |
@@ -3985,7 +3987,7 @@ static void crash_test() | |||
3985 | static time_t oldtim; | 3987 | static time_t oldtim; |
3986 | 3988 | ||
3987 | time_t tim; | 3989 | time_t tim; |
3988 | char d[2], msg[BUFSIZ]; | 3990 | char d[2], msg[MAX_LINELEN]; |
3989 | 3991 | ||
3990 | msg[0] = '\0'; | 3992 | msg[0] = '\0'; |
3991 | if (end < text) { | 3993 | if (end < text) { |