diff options
Diffstat (limited to 'sh.c')
-rw-r--r-- | sh.c | 37 |
1 files changed, 15 insertions, 22 deletions
@@ -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)); |