diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-04-09 22:48:12 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-04-09 22:48:12 +0000 |
commit | e5dfced23a904d08afa5dcee190c3c3d845d9f50 (patch) | |
tree | ef367ee8a9096884fb40debdc9e10af8583f9d5f /shell | |
parent | a75e2867435faa68ea03735fe09ad298fa3e4e72 (diff) | |
download | busybox-w32-e5dfced23a904d08afa5dcee190c3c3d845d9f50.tar.gz busybox-w32-e5dfced23a904d08afa5dcee190c3c3d845d9f50.tar.bz2 busybox-w32-e5dfced23a904d08afa5dcee190c3c3d845d9f50.zip |
Apply Vladimir's latest cleanup patch.
-Erik
Diffstat (limited to 'shell')
-rw-r--r-- | shell/cmdedit.c | 249 | ||||
-rw-r--r-- | shell/lash.c | 37 |
2 files changed, 112 insertions, 174 deletions
diff --git a/shell/cmdedit.c b/shell/cmdedit.c index a3710812f..eef1a88c8 100644 --- a/shell/cmdedit.c +++ b/shell/cmdedit.c | |||
@@ -31,8 +31,6 @@ | |||
31 | */ | 31 | */ |
32 | 32 | ||
33 | 33 | ||
34 | //#define TEST | ||
35 | |||
36 | #include <stdio.h> | 34 | #include <stdio.h> |
37 | #include <errno.h> | 35 | #include <errno.h> |
38 | #include <unistd.h> | 36 | #include <unistd.h> |
@@ -43,10 +41,16 @@ | |||
43 | #include <signal.h> | 41 | #include <signal.h> |
44 | #include <limits.h> | 42 | #include <limits.h> |
45 | 43 | ||
46 | #ifndef TEST | ||
47 | |||
48 | #include "busybox.h" | 44 | #include "busybox.h" |
49 | 45 | ||
46 | #ifdef BB_LOCALE_SUPPORT | ||
47 | #define Isprint(c) isprint((c)) | ||
48 | #else | ||
49 | #define Isprint(c) ( (c) >= ' ' && (c) != ((unsigned char)'\233') ) | ||
50 | #endif | ||
51 | |||
52 | #ifndef TEST | ||
53 | |||
50 | #define D(x) | 54 | #define D(x) |
51 | 55 | ||
52 | #else | 56 | #else |
@@ -59,13 +63,6 @@ | |||
59 | 63 | ||
60 | #define D(x) x | 64 | #define D(x) x |
61 | 65 | ||
62 | #ifndef TRUE | ||
63 | #define TRUE 1 | ||
64 | #endif | ||
65 | #ifndef FALSE | ||
66 | #define FALSE 0 | ||
67 | #endif | ||
68 | |||
69 | #endif /* TEST */ | 66 | #endif /* TEST */ |
70 | 67 | ||
71 | #ifdef BB_FEATURE_COMMAND_TAB_COMPLETION | 68 | #ifdef BB_FEATURE_COMMAND_TAB_COMPLETION |
@@ -92,29 +89,6 @@ | |||
92 | #endif /* advanced FEATURES */ | 89 | #endif /* advanced FEATURES */ |
93 | 90 | ||
94 | 91 | ||
95 | #ifdef TEST | ||
96 | void *xrealloc(void *old, size_t size) | ||
97 | { | ||
98 | return realloc(old, size); | ||
99 | } | ||
100 | |||
101 | void *xmalloc(size_t size) | ||
102 | { | ||
103 | return malloc(size); | ||
104 | } | ||
105 | char *xstrdup(const char *s) | ||
106 | { | ||
107 | return strdup(s); | ||
108 | } | ||
109 | |||
110 | void *xcalloc(size_t size, size_t se) | ||
111 | { | ||
112 | return calloc(size, se); | ||
113 | } | ||
114 | |||
115 | #define error_msg(s, d) fprintf(stderr, s, d) | ||
116 | #endif /* TEST */ | ||
117 | |||
118 | 92 | ||
119 | struct history { | 93 | struct history { |
120 | char *s; | 94 | char *s; |
@@ -238,7 +212,7 @@ static void win_changed(int nsig) | |||
238 | static void cmdedit_reset_term(void) | 212 | static void cmdedit_reset_term(void) |
239 | { | 213 | { |
240 | if ((handlers_sets & SET_RESET_TERM) != 0) { | 214 | if ((handlers_sets & SET_RESET_TERM) != 0) { |
241 | /* sparc and other have broken termios support: use old termio handling. */ | 215 | /* sparc and other have broken termios support: use old termio handling. */ |
242 | setTermSettings(fileno(stdin), (void *) &initial_settings); | 216 | setTermSettings(fileno(stdin), (void *) &initial_settings); |
243 | handlers_sets &= ~SET_RESET_TERM; | 217 | handlers_sets &= ~SET_RESET_TERM; |
244 | } | 218 | } |
@@ -270,9 +244,9 @@ static void cmdedit_set_out_char(int next_char) | |||
270 | int c = (int)((unsigned char) command_ps[cursor]); | 244 | int c = (int)((unsigned char) command_ps[cursor]); |
271 | 245 | ||
272 | if (c == 0) | 246 | if (c == 0) |
273 | c = ' '; /* destroy end char? */ | 247 | c = ' '; /* destroy end char? */ |
274 | #ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT | 248 | #ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT |
275 | if (!isprint(c)) { /* Inverse put non-printable characters */ | 249 | if (!Isprint(c)) { /* Inverse put non-printable characters */ |
276 | if (c >= 128) | 250 | if (c >= 128) |
277 | c -= 128; | 251 | c -= 128; |
278 | if (c < ' ') | 252 | if (c < ' ') |
@@ -328,7 +302,7 @@ static void input_backward(int num) | |||
328 | { | 302 | { |
329 | if (num > cursor) | 303 | if (num > cursor) |
330 | num = cursor; | 304 | num = cursor; |
331 | cursor -= num; /* new cursor (in command, not terminal) */ | 305 | cursor -= num; /* new cursor (in command, not terminal) */ |
332 | 306 | ||
333 | if (cmdedit_x >= num) { /* no to up line */ | 307 | if (cmdedit_x >= num) { /* no to up line */ |
334 | cmdedit_x -= num; | 308 | cmdedit_x -= num; |
@@ -369,147 +343,116 @@ static void parse_prompt(const char *prmt_ptr) | |||
369 | put_prompt(); | 343 | put_prompt(); |
370 | } | 344 | } |
371 | #else | 345 | #else |
372 | static void add_to_prompt(char **prmt_mem_ptr, int *alm, | ||
373 | int *prmt_len, const char *addb) | ||
374 | { | ||
375 | *prmt_len += strlen(addb); | ||
376 | if (*alm < (*prmt_len) + 1) { | ||
377 | *alm = (*prmt_len) + 1; | ||
378 | *prmt_mem_ptr = xrealloc(*prmt_mem_ptr, *alm); | ||
379 | } | ||
380 | strcat(*prmt_mem_ptr, addb); | ||
381 | } | ||
382 | |||
383 | static void parse_prompt(const char *prmt_ptr) | 346 | static void parse_prompt(const char *prmt_ptr) |
384 | { | 347 | { |
385 | int alm = strlen(prmt_ptr) + 1; /* supposedly require memory */ | ||
386 | int prmt_len = 0; | 348 | int prmt_len = 0; |
387 | int sub_len = 0; | 349 | int sub_len = 0; |
388 | int flg_not_length = '['; | 350 | char flg_not_length = '['; |
389 | char *prmt_mem_ptr = xstrdup(prmt_ptr); | 351 | char *prmt_mem_ptr = xcalloc(1, 1); |
390 | char pwd_buf[PATH_MAX + 1]; | 352 | char *pwd_buf = xgetcwd(0); |
391 | char buf[16]; | 353 | char buf2[PATH_MAX + 1]; |
392 | int c; | 354 | char buf[2]; |
393 | 355 | char c; | |
394 | pwd_buf[0] = 0; | 356 | char *pbuf; |
395 | *prmt_mem_ptr = 0; | ||
396 | 357 | ||
397 | while (*prmt_ptr) { | 358 | while (*prmt_ptr) { |
359 | pbuf = buf; | ||
360 | pbuf[1] = 0; | ||
398 | c = *prmt_ptr++; | 361 | c = *prmt_ptr++; |
399 | if (c == '\\') { | 362 | if (c == '\\') { |
400 | c = *prmt_ptr; | 363 | const char *cp = prmt_ptr; |
401 | if (c == 0) | 364 | int l; |
365 | |||
366 | c = process_escape_sequence(&prmt_ptr); | ||
367 | if(prmt_ptr==cp) { | ||
368 | if (*cp == 0) | ||
402 | break; | 369 | break; |
403 | prmt_ptr++; | 370 | c = *prmt_ptr++; |
404 | switch (c) { | 371 | switch (c) { |
405 | #ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR | 372 | #ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR |
406 | case 'u': | 373 | case 'u': |
407 | add_to_prompt(&prmt_mem_ptr, &alm, &prmt_len, user_buf); | 374 | pbuf = user_buf; |
408 | continue; | 375 | break; |
409 | #endif | 376 | #endif |
410 | case 'h': | 377 | case 'h': |
411 | if (hostname_buf[0] == 0) { | 378 | pbuf = hostname_buf; |
412 | hostname_buf = xcalloc(256, 1); | 379 | if (*pbuf == 0) { |
413 | if (gethostname(hostname_buf, 255) < 0) { | 380 | pbuf = xcalloc(256, 1); |
414 | strcpy(hostname_buf, "?"); | 381 | if (gethostname(pbuf, 255) < 0) { |
382 | strcpy(pbuf, "?"); | ||
415 | } else { | 383 | } else { |
416 | char *s = strchr(hostname_buf, '.'); | 384 | char *s = strchr(pbuf, '.'); |
417 | 385 | ||
418 | if (s) | 386 | if (s) |
419 | *s = 0; | 387 | *s = 0; |
420 | } | 388 | } |
389 | hostname_buf = pbuf; | ||
421 | } | 390 | } |
422 | add_to_prompt(&prmt_mem_ptr, &alm, &prmt_len, | 391 | break; |
423 | hostname_buf); | 392 | case '$': |
424 | continue; | ||
425 | case '$': | ||
426 | c = my_euid == 0 ? '#' : '$'; | 393 | c = my_euid == 0 ? '#' : '$'; |
427 | break; | 394 | break; |
428 | #ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR | 395 | #ifdef BB_FEATURE_GETUSERNAME_AND_HOMEDIR |
429 | case 'w': | 396 | case 'w': |
430 | if (pwd_buf[0] == 0) { | 397 | pbuf = pwd_buf; |
431 | int l; | 398 | l = strlen(home_pwd_buf); |
432 | 399 | if (home_pwd_buf[0] != 0 && | |
433 | getcwd(pwd_buf, PATH_MAX); | 400 | strncmp(home_pwd_buf, pbuf, l) == 0 && |
434 | l = strlen(home_pwd_buf); | 401 | (pbuf[l]=='/' || pbuf[l]=='\0') && |
435 | if (home_pwd_buf[0] != 0 && | 402 | strlen(pwd_buf+l)<PATH_MAX) { |
436 | strncmp(home_pwd_buf, pwd_buf, l) == 0) { | 403 | pbuf = buf2; |
437 | strcpy(pwd_buf + 1, pwd_buf + l); | 404 | *pbuf = '~'; |
438 | pwd_buf[0] = '~'; | 405 | strcpy(pbuf+1, pwd_buf+l); |
439 | } | 406 | } |
440 | } | 407 | break; |
441 | add_to_prompt(&prmt_mem_ptr, &alm, &prmt_len, pwd_buf); | ||
442 | continue; | ||
443 | #endif | 408 | #endif |
444 | case 'W': | 409 | case 'W': |
445 | if (pwd_buf[0] == 0) { | 410 | pbuf = pwd_buf; |
446 | char *z; | 411 | cp = strrchr(pbuf,'/'); |
447 | 412 | if ( (cp != NULL) && (cp != pbuf) ) | |
448 | getcwd(pwd_buf, PATH_MAX); | 413 | pbuf += (cp-pbuf)+1; |
449 | z = strrchr(pwd_buf,'/'); | 414 | break; |
450 | if ( (z != NULL) && (z != pwd_buf) ) { | 415 | case '!': |
451 | z++; | 416 | snprintf(pbuf = buf2, sizeof(buf2), "%d", num_ok_lines); |
452 | strcpy(pwd_buf,z); | 417 | break; |
453 | } | 418 | case 'e': case 'E': /* \e \E = \033 */ |
454 | } | ||
455 | add_to_prompt(&prmt_mem_ptr, &alm, &prmt_len, pwd_buf); | ||
456 | continue; | ||
457 | case '!': | ||
458 | snprintf(buf, sizeof(buf), "%d", num_ok_lines); | ||
459 | add_to_prompt(&prmt_mem_ptr, &alm, &prmt_len, buf); | ||
460 | continue; | ||
461 | case 'e': | ||
462 | case 'E': /* \e \E = \033 */ | ||
463 | c = '\033'; | 419 | c = '\033'; |
464 | break; | 420 | break; |
465 | case 'x': | 421 | case 'x': case 'X': |
466 | case 'X': | ||
467 | case '0': | ||
468 | case '1': | ||
469 | case '2': | ||
470 | case '3': | ||
471 | case '4': | ||
472 | case '5': | ||
473 | case '6': | ||
474 | case '7':{ | ||
475 | int l; | ||
476 | int ho = 0; | ||
477 | char *eho; | ||
478 | |||
479 | if (c == 'X') | ||
480 | c = 'x'; | ||
481 | |||
482 | for (l = 0; l < 3;) { | 422 | for (l = 0; l < 3;) { |
483 | 423 | int h; | |
484 | buf[l++] = *prmt_ptr; | 424 | buf2[l++] = *prmt_ptr; |
485 | buf[l] = 0; | 425 | buf2[l] = 0; |
486 | ho = strtol(buf, &eho, c == 'x' ? 16 : 8); | 426 | h = strtol(buf2, &pbuf, 16); |
487 | if (ho > UCHAR_MAX || (eho - buf) < l) { | 427 | if (h > UCHAR_MAX || (pbuf - buf2) < l) { |
488 | l--; | 428 | l--; |
489 | break; | 429 | break; |
490 | } | 430 | } |
491 | prmt_ptr++; | 431 | prmt_ptr++; |
492 | } | 432 | } |
493 | buf[l] = 0; | 433 | buf2[l] = 0; |
494 | ho = strtol(buf, 0, c == 'x' ? 16 : 8); | 434 | c = (char)strtol(buf2, 0, 16); |
495 | c = ho == 0 ? '?' : (char) ho; | 435 | if(c==0) |
436 | c = '?'; | ||
437 | pbuf = buf; | ||
496 | break; | 438 | break; |
497 | } | 439 | case '[': case ']': |
498 | case '[': | ||
499 | case ']': | ||
500 | if (c == flg_not_length) { | 440 | if (c == flg_not_length) { |
501 | flg_not_length = flg_not_length == '[' ? ']' : '['; | 441 | flg_not_length = flg_not_length == '[' ? ']' : '['; |
502 | continue; | 442 | continue; |
503 | } | 443 | } |
504 | break; | 444 | break; |
505 | } | 445 | } |
446 | } | ||
506 | } | 447 | } |
507 | buf[0] = c; | 448 | if(pbuf == buf) |
508 | buf[1] = 0; | 449 | *pbuf = c; |
509 | add_to_prompt(&prmt_mem_ptr, &alm, &prmt_len, buf); | 450 | prmt_len += strlen(pbuf); |
451 | prmt_mem_ptr = strcat(xrealloc(prmt_mem_ptr, prmt_len+1), pbuf); | ||
510 | if (flg_not_length == ']') | 452 | if (flg_not_length == ']') |
511 | sub_len++; | 453 | sub_len++; |
512 | } | 454 | } |
455 | free(pwd_buf); | ||
513 | cmdedit_prompt = prmt_mem_ptr; | 456 | cmdedit_prompt = prmt_mem_ptr; |
514 | cmdedit_prmt_len = prmt_len - sub_len; | 457 | cmdedit_prmt_len = prmt_len - sub_len; |
515 | put_prompt(); | 458 | put_prompt(); |
@@ -789,7 +732,7 @@ static char **exe_n_cwd_tab_completion(char *command, int *num_matches, | |||
789 | char **paths = path1; | 732 | char **paths = path1; |
790 | int npaths; | 733 | int npaths; |
791 | int i; | 734 | int i; |
792 | char found[BUFSIZ + 4 + PATH_MAX]; | 735 | char *found; |
793 | char *pfind = strrchr(command, '/'); | 736 | char *pfind = strrchr(command, '/'); |
794 | 737 | ||
795 | path1[0] = "."; | 738 | path1[0] = "."; |
@@ -822,7 +765,6 @@ static char **exe_n_cwd_tab_completion(char *command, int *num_matches, | |||
822 | continue; | 765 | continue; |
823 | 766 | ||
824 | while ((next = readdir(dir)) != NULL) { | 767 | while ((next = readdir(dir)) != NULL) { |
825 | const char *str_merge = "%s/%s"; | ||
826 | char *str_found = next->d_name; | 768 | char *str_found = next->d_name; |
827 | 769 | ||
828 | /* matched ? */ | 770 | /* matched ? */ |
@@ -835,25 +777,23 @@ static char **exe_n_cwd_tab_completion(char *command, int *num_matches, | |||
835 | else | 777 | else |
836 | continue; | 778 | continue; |
837 | } | 779 | } |
838 | if (paths[i][strlen(paths[i]) - 1] == '/') | 780 | found = concat_path_file(paths[i], str_found); |
839 | str_merge = "%s%s"; | ||
840 | sprintf(found, str_merge, paths[i], str_found); | ||
841 | /* hmm, remover in progress? */ | 781 | /* hmm, remover in progress? */ |
842 | if (stat(found, &st) < 0) | 782 | if (stat(found, &st) < 0) |
843 | continue; | 783 | goto cont; |
844 | /* find with dirs ? */ | 784 | /* find with dirs ? */ |
845 | if (paths[i] != dirbuf) | 785 | if (paths[i] != dirbuf) |
846 | strcpy(found, next->d_name); /* only name */ | 786 | strcpy(found, next->d_name); /* only name */ |
847 | if (S_ISDIR(st.st_mode)) { | 787 | if (S_ISDIR(st.st_mode)) { |
848 | /* name is directory */ | 788 | /* name is directory */ |
849 | /* algorithmic only "/" ? */ | 789 | str_found = found; |
850 | if (*str_found) | 790 | found = concat_path_file(found, ""); |
851 | strcat(found, "/"); | 791 | free(str_found); |
852 | str_found = add_quote_for_spec_chars(found); | 792 | str_found = add_quote_for_spec_chars(found); |
853 | } else { | 793 | } else { |
854 | /* not put found file if search only dirs for cd */ | 794 | /* not put found file if search only dirs for cd */ |
855 | if (type == FIND_DIR_ONLY) | 795 | if (type == FIND_DIR_ONLY) |
856 | continue; | 796 | goto cont; |
857 | str_found = add_quote_for_spec_chars(found); | 797 | str_found = add_quote_for_spec_chars(found); |
858 | if (type == FIND_FILE_ONLY || | 798 | if (type == FIND_FILE_ONLY || |
859 | (type == FIND_EXE_ONLY && is_execute(&st) == TRUE)) | 799 | (type == FIND_EXE_ONLY && is_execute(&st) == TRUE)) |
@@ -863,6 +803,8 @@ static char **exe_n_cwd_tab_completion(char *command, int *num_matches, | |||
863 | matches = xrealloc(matches, (nm + 1) * sizeof(char *)); | 803 | matches = xrealloc(matches, (nm + 1) * sizeof(char *)); |
864 | 804 | ||
865 | matches[nm++] = str_found; | 805 | matches[nm++] = str_found; |
806 | cont: | ||
807 | free(found); | ||
866 | } | 808 | } |
867 | closedir(dir); | 809 | closedir(dir); |
868 | } | 810 | } |
@@ -1440,7 +1382,7 @@ extern void cmdedit_read_input(char *prompt, char command[BUFSIZ]) | |||
1440 | } | 1382 | } |
1441 | } else | 1383 | } else |
1442 | #endif | 1384 | #endif |
1443 | if (!isprint(c)) /* Skip non-printable characters */ | 1385 | if (!Isprint(c)) /* Skip non-printable characters */ |
1444 | break; | 1386 | break; |
1445 | 1387 | ||
1446 | if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */ | 1388 | if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */ |
@@ -1554,6 +1496,9 @@ extern void cmdedit_terminate(void) | |||
1554 | 1496 | ||
1555 | #ifdef TEST | 1497 | #ifdef TEST |
1556 | 1498 | ||
1499 | const char *applet_name = "debug stuff usage"; | ||
1500 | const char *memory_exhausted = "Memory exhausted"; | ||
1501 | |||
1557 | #ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT | 1502 | #ifdef BB_FEATURE_NONPRINTABLE_INVERSE_PUT |
1558 | #include <locale.h> | 1503 | #include <locale.h> |
1559 | #endif | 1504 | #endif |
diff --git a/shell/lash.c b/shell/lash.c index 89325b63d..ee45b1a0d 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
@@ -64,7 +64,10 @@ | |||
64 | #include <sys/wait.h> | 64 | #include <sys/wait.h> |
65 | #include <unistd.h> | 65 | #include <unistd.h> |
66 | #include <getopt.h> | 66 | #include <getopt.h> |
67 | |||
68 | #ifdef BB_LOCALE_SUPPORT | ||
67 | #include <locale.h> | 69 | #include <locale.h> |
70 | #endif | ||
68 | 71 | ||
69 | //#define BB_FEATURE_SH_WORDEXP | 72 | //#define BB_FEATURE_SH_WORDEXP |
70 | 73 | ||
@@ -80,7 +83,6 @@ | |||
80 | #include "cmdedit.h" | 83 | #include "cmdedit.h" |
81 | 84 | ||
82 | 85 | ||
83 | static const int MAX_LINE = 256; /* size of input buffer for cwd data */ | ||
84 | static const int MAX_READ = 128; /* size of input buffer for `read' builtin */ | 86 | static const int MAX_READ = 128; /* size of input buffer for `read' builtin */ |
85 | #define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n" | 87 | #define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n" |
86 | 88 | ||
@@ -230,7 +232,7 @@ static char syntax_err[]="syntax error near unexpected token"; | |||
230 | #endif | 232 | #endif |
231 | 233 | ||
232 | static char *PS1; | 234 | static char *PS1; |
233 | static char *PS2; | 235 | static char *PS2 = "> "; |
234 | 236 | ||
235 | 237 | ||
236 | #ifdef DEBUG_SHELL | 238 | #ifdef DEBUG_SHELL |
@@ -294,7 +296,7 @@ static int builtin_cd(struct child_prog *child) | |||
294 | printf("cd: %s: %m\n", newdir); | 296 | printf("cd: %s: %m\n", newdir); |
295 | return EXIT_FAILURE; | 297 | return EXIT_FAILURE; |
296 | } | 298 | } |
297 | getcwd(cwd, sizeof(char)*MAX_LINE); | 299 | cwd = xgetcwd(cwd); |
298 | 300 | ||
299 | return EXIT_SUCCESS; | 301 | return EXIT_SUCCESS; |
300 | } | 302 | } |
@@ -410,7 +412,6 @@ static int builtin_jobs(struct child_prog *child) | |||
410 | /* built-in 'pwd' handler */ | 412 | /* built-in 'pwd' handler */ |
411 | static int builtin_pwd(struct child_prog *dummy) | 413 | static int builtin_pwd(struct child_prog *dummy) |
412 | { | 414 | { |
413 | getcwd(cwd, MAX_LINE); | ||
414 | printf( "%s\n", cwd); | 415 | printf( "%s\n", cwd); |
415 | return EXIT_SUCCESS; | 416 | return EXIT_SUCCESS; |
416 | } | 417 | } |
@@ -434,13 +435,14 @@ static int builtin_export(struct child_prog *child) | |||
434 | #ifndef BB_FEATURE_SH_SIMPLE_PROMPT | 435 | #ifndef BB_FEATURE_SH_SIMPLE_PROMPT |
435 | if (strncmp(v, "PS1=", 4)==0) | 436 | if (strncmp(v, "PS1=", 4)==0) |
436 | PS1 = getenv("PS1"); | 437 | PS1 = getenv("PS1"); |
437 | else if (strncmp(v, "PS2=", 4)==0) | ||
438 | PS2 = getenv("PS2"); | ||
439 | #endif | 438 | #endif |
439 | |||
440 | #ifdef BB_LOCALE_SUPPORT | ||
440 | if(strncmp(v, "LC_ALL=", 7)==0) | 441 | if(strncmp(v, "LC_ALL=", 7)==0) |
441 | setlocale(LC_ALL, getenv("LC_ALL")); | 442 | setlocale(LC_ALL, getenv("LC_ALL")); |
442 | if(strncmp(v, "LC_CTYPE=", 9)==0) | 443 | if(strncmp(v, "LC_CTYPE=", 9)==0) |
443 | setlocale(LC_CTYPE, getenv("LC_CTYPE")); | 444 | setlocale(LC_CTYPE, getenv("LC_CTYPE")); |
445 | #endif | ||
444 | 446 | ||
445 | return (res); | 447 | return (res); |
446 | } | 448 | } |
@@ -623,10 +625,7 @@ static int builtin_unset(struct child_prog *child) | |||
623 | */ | 625 | */ |
624 | static int run_command_predicate(char *cmd) | 626 | static int run_command_predicate(char *cmd) |
625 | { | 627 | { |
626 | int n=strlen(cmd); | 628 | local_pending_command = xstrdup(cmd); |
627 | local_pending_command = xmalloc(n+1); | ||
628 | strncpy(local_pending_command, cmd, n); | ||
629 | local_pending_command[n]='\0'; | ||
630 | return( busy_loop(NULL)); | 629 | return( busy_loop(NULL)); |
631 | } | 630 | } |
632 | #endif | 631 | #endif |
@@ -808,15 +807,10 @@ static inline void cmdedit_set_initial_prompt(void) | |||
808 | { | 807 | { |
809 | #ifdef BB_FEATURE_SH_SIMPLE_PROMPT | 808 | #ifdef BB_FEATURE_SH_SIMPLE_PROMPT |
810 | PS1 = NULL; | 809 | PS1 = NULL; |
811 | PS2 = "> "; | ||
812 | #else | 810 | #else |
813 | PS1 = getenv("PS1"); | 811 | PS1 = getenv("PS1"); |
814 | if(PS1==0) { | 812 | if(PS1==0) |
815 | PS1 = "\\w \\$ "; | 813 | PS1 = "\\w \\$ "; |
816 | } | ||
817 | PS2 = getenv("PS2"); | ||
818 | if(PS2==0) | ||
819 | PS2 = "> "; | ||
820 | #endif | 814 | #endif |
821 | } | 815 | } |
822 | 816 | ||
@@ -954,7 +948,7 @@ static int expand_arguments(char *command) | |||
954 | /* Fix up escape sequences to be the Real Thing(tm) */ | 948 | /* Fix up escape sequences to be the Real Thing(tm) */ |
955 | while( command && command[ix]) { | 949 | while( command && command[ix]) { |
956 | if (command[ix] == '\\') { | 950 | if (command[ix] == '\\') { |
957 | char *tmp = command+ix+1; | 951 | const char *tmp = command+ix+1; |
958 | command[ix] = process_escape_sequence( &tmp ); | 952 | command[ix] = process_escape_sequence( &tmp ); |
959 | memmove(command+ix + 1, tmp, strlen(tmp)+1); | 953 | memmove(command+ix + 1, tmp, strlen(tmp)+1); |
960 | } | 954 | } |
@@ -1829,8 +1823,10 @@ static int busy_loop(FILE * input) | |||
1829 | #ifdef BB_FEATURE_CLEAN_UP | 1823 | #ifdef BB_FEATURE_CLEAN_UP |
1830 | void free_memory(void) | 1824 | void free_memory(void) |
1831 | { | 1825 | { |
1832 | if (cwd) | 1826 | if (cwd) { |
1833 | free(cwd); | 1827 | free(cwd); |
1828 | cwd = NULL; | ||
1829 | } | ||
1834 | if (local_pending_command) | 1830 | if (local_pending_command) |
1835 | free(local_pending_command); | 1831 | free(local_pending_command); |
1836 | 1832 | ||
@@ -1850,7 +1846,6 @@ int shell_main(int argc_l, char **argv_l) | |||
1850 | 1846 | ||
1851 | /* These variables need re-initializing when recursing */ | 1847 | /* These variables need re-initializing when recursing */ |
1852 | shell_context = 0; | 1848 | shell_context = 0; |
1853 | cwd=NULL; | ||
1854 | local_pending_command = NULL; | 1849 | local_pending_command = NULL; |
1855 | close_me_head = NULL; | 1850 | close_me_head = NULL; |
1856 | job_list.head = NULL; | 1851 | job_list.head = NULL; |
@@ -1921,8 +1916,7 @@ int shell_main(int argc_l, char **argv_l) | |||
1921 | } | 1916 | } |
1922 | 1917 | ||
1923 | /* initialize the cwd -- this is never freed...*/ | 1918 | /* initialize the cwd -- this is never freed...*/ |
1924 | cwd=(char*)xmalloc(sizeof(char)*MAX_LINE+1); | 1919 | cwd = xgetcwd(0); |
1925 | getcwd(cwd, sizeof(char)*MAX_LINE); | ||
1926 | 1920 | ||
1927 | #ifdef BB_FEATURE_CLEAN_UP | 1921 | #ifdef BB_FEATURE_CLEAN_UP |
1928 | atexit(free_memory); | 1922 | atexit(free_memory); |
@@ -1932,7 +1926,6 @@ int shell_main(int argc_l, char **argv_l) | |||
1932 | cmdedit_set_initial_prompt(); | 1926 | cmdedit_set_initial_prompt(); |
1933 | #else | 1927 | #else |
1934 | PS1 = NULL; | 1928 | PS1 = NULL; |
1935 | PS2 = "> "; | ||
1936 | #endif | 1929 | #endif |
1937 | 1930 | ||
1938 | return (busy_loop(input)); | 1931 | return (busy_loop(input)); |