diff options
author | Ron Yorston <rmy@pobox.com> | 2013-03-19 11:18:39 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2013-03-19 11:18:39 +0000 |
commit | 63d2c5fead323df5f4250ed544d0bc03527c8936 (patch) | |
tree | 660979b139a4bc4b143c08843cb7efbc69bdcb4d /shell | |
parent | 27fc2d535588728ac3ca69337271471fb6fe3ee9 (diff) | |
parent | a42f530e034b673726a91ea5d8202254e677f066 (diff) | |
download | busybox-w32-63d2c5fead323df5f4250ed544d0bc03527c8936.tar.gz busybox-w32-63d2c5fead323df5f4250ed544d0bc03527c8936.tar.bz2 busybox-w32-63d2c5fead323df5f4250ed544d0bc03527c8936.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 61 | ||||
-rw-r--r-- | shell/hush.c | 9 | ||||
-rw-r--r-- | shell/hush_test/hush-misc/source2.right | 4 | ||||
-rwxr-xr-x | shell/hush_test/hush-misc/source2.tests | 8 | ||||
-rw-r--r-- | shell/math.c | 12 | ||||
-rw-r--r-- | shell/math.h | 5 |
6 files changed, 45 insertions, 54 deletions
diff --git a/shell/ash.c b/shell/ash.c index 75c01ec14..962fc2609 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -441,6 +441,9 @@ static void trace_vprintf(const char *fmt, va_list va); | |||
441 | /* ============ Utility functions */ | 441 | /* ============ Utility functions */ |
442 | #define xbarrier() do { __asm__ __volatile__ ("": : :"memory"); } while (0) | 442 | #define xbarrier() do { __asm__ __volatile__ ("": : :"memory"); } while (0) |
443 | 443 | ||
444 | #define is_name(c) ((c) == '_' || isalpha((unsigned char)(c))) | ||
445 | #define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c))) | ||
446 | |||
444 | static int isdigit_str9(const char *str) | 447 | static int isdigit_str9(const char *str) |
445 | { | 448 | { |
446 | int maxlen = 9 + 1; /* max 9 digits: 999999999 */ | 449 | int maxlen = 9 + 1; /* max 9 digits: 999999999 */ |
@@ -2064,27 +2067,6 @@ getoptsreset(const char *value) | |||
2064 | } | 2067 | } |
2065 | #endif | 2068 | #endif |
2066 | 2069 | ||
2067 | /* math.h has these, otherwise define our private copies */ | ||
2068 | #if !ENABLE_SH_MATH_SUPPORT | ||
2069 | #define is_name(c) ((c) == '_' || isalpha((unsigned char)(c))) | ||
2070 | #define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c))) | ||
2071 | /* | ||
2072 | * Return the pointer to the first char which is not part of a legal variable name | ||
2073 | * (a letter or underscore followed by letters, underscores, and digits). | ||
2074 | */ | ||
2075 | static const char* | ||
2076 | endofname(const char *name) | ||
2077 | { | ||
2078 | if (!is_name(*name)) | ||
2079 | return name; | ||
2080 | while (*++name) { | ||
2081 | if (!is_in_name(*name)) | ||
2082 | break; | ||
2083 | } | ||
2084 | return name; | ||
2085 | } | ||
2086 | #endif | ||
2087 | |||
2088 | /* | 2070 | /* |
2089 | * Compares two strings up to the first = or '\0'. The first | 2071 | * Compares two strings up to the first = or '\0'. The first |
2090 | * string must be terminated by '='; the second may be terminated by | 2072 | * string must be terminated by '='; the second may be terminated by |
@@ -12774,6 +12756,9 @@ dotcmd(int argc, char **argv) | |||
12774 | /* "false; . empty_file; echo $?" should print 0, not 1: */ | 12756 | /* "false; . empty_file; echo $?" should print 0, not 1: */ |
12775 | exitstatus = 0; | 12757 | exitstatus = 0; |
12776 | 12758 | ||
12759 | /* This aborts if file isn't found, which is POSIXly correct. | ||
12760 | * bash returns exitcode 1 instead. | ||
12761 | */ | ||
12777 | fullname = find_dot_file(argv[1]); | 12762 | fullname = find_dot_file(argv[1]); |
12778 | 12763 | ||
12779 | argv += 2; | 12764 | argv += 2; |
@@ -12785,6 +12770,9 @@ dotcmd(int argc, char **argv) | |||
12785 | shellparam.p = argv; | 12770 | shellparam.p = argv; |
12786 | }; | 12771 | }; |
12787 | 12772 | ||
12773 | /* This aborts if file can't be opened, which is POSIXly correct. | ||
12774 | * bash returns exitcode 1 instead. | ||
12775 | */ | ||
12788 | setinputfile(fullname, INPUT_PUSH_FILE); | 12776 | setinputfile(fullname, INPUT_PUSH_FILE); |
12789 | commandname = fullname; | 12777 | commandname = fullname; |
12790 | cmdloop(0); | 12778 | cmdloop(0); |
@@ -13832,27 +13820,21 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
13832 | #endif | 13820 | #endif |
13833 | procargs(argv); | 13821 | procargs(argv); |
13834 | 13822 | ||
13835 | #if ENABLE_FEATURE_EDITING_SAVEHISTORY | ||
13836 | if (iflag) { | ||
13837 | const char *hp = lookupvar("HISTFILE"); | ||
13838 | if (!hp) { | ||
13839 | hp = lookupvar("HOME"); | ||
13840 | if (hp) { | ||
13841 | char *defhp = concat_path_file(hp, ".ash_history"); | ||
13842 | setvar("HISTFILE", defhp, 0); | ||
13843 | free(defhp); | ||
13844 | } | ||
13845 | } | ||
13846 | } | ||
13847 | #endif | ||
13848 | if (argv[0] && argv[0][0] == '-') | 13823 | if (argv[0] && argv[0][0] == '-') |
13849 | isloginsh = 1; | 13824 | isloginsh = 1; |
13850 | if (isloginsh) { | 13825 | if (isloginsh) { |
13826 | const char *hp; | ||
13827 | |||
13851 | state = 1; | 13828 | state = 1; |
13852 | read_profile("/etc/profile"); | 13829 | read_profile("/etc/profile"); |
13853 | state1: | 13830 | state1: |
13854 | state = 2; | 13831 | state = 2; |
13855 | read_profile(".profile"); | 13832 | hp = lookupvar("HOME"); |
13833 | if (hp) { | ||
13834 | hp = concat_path_file(hp, ".profile"); | ||
13835 | read_profile(hp); | ||
13836 | free((char*)hp); | ||
13837 | } | ||
13856 | } | 13838 | } |
13857 | state2: | 13839 | state2: |
13858 | state = 3; | 13840 | state = 3; |
@@ -13884,6 +13866,15 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
13884 | #if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY | 13866 | #if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY |
13885 | if (iflag) { | 13867 | if (iflag) { |
13886 | const char *hp = lookupvar("HISTFILE"); | 13868 | const char *hp = lookupvar("HISTFILE"); |
13869 | if (!hp) { | ||
13870 | hp = lookupvar("HOME"); | ||
13871 | if (hp) { | ||
13872 | hp = concat_path_file(hp, ".ash_history"); | ||
13873 | setvar("HISTFILE", hp, 0); | ||
13874 | free((char*)hp); | ||
13875 | hp = lookupvar("HISTFILE"); | ||
13876 | } | ||
13877 | } | ||
13887 | if (hp) | 13878 | if (hp) |
13888 | line_input_state->hist_file = hp; | 13879 | line_input_state->hist_file = hp; |
13889 | # if ENABLE_FEATURE_SH_HISTFILESIZE | 13880 | # if ENABLE_FEATURE_SH_HISTFILESIZE |
diff --git a/shell/hush.c b/shell/hush.c index e2dc1e2d0..b23325725 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -8880,6 +8880,9 @@ static int FAST_FUNC builtin_source(char **argv) | |||
8880 | free(arg_path); | 8880 | free(arg_path); |
8881 | if (!input) { | 8881 | if (!input) { |
8882 | /* bb_perror_msg("%s", *argv); - done by fopen_or_warn */ | 8882 | /* bb_perror_msg("%s", *argv); - done by fopen_or_warn */ |
8883 | /* POSIX: non-interactive shell should abort here, | ||
8884 | * not merely fail. So far no one complained :) | ||
8885 | */ | ||
8883 | return EXIT_FAILURE; | 8886 | return EXIT_FAILURE; |
8884 | } | 8887 | } |
8885 | close_on_exec_on(fileno(input)); | 8888 | close_on_exec_on(fileno(input)); |
@@ -8889,12 +8892,14 @@ static int FAST_FUNC builtin_source(char **argv) | |||
8889 | /* "we are inside sourced file, ok to use return" */ | 8892 | /* "we are inside sourced file, ok to use return" */ |
8890 | G.flag_return_in_progress = -1; | 8893 | G.flag_return_in_progress = -1; |
8891 | #endif | 8894 | #endif |
8892 | save_and_replace_G_args(&sv, argv); | 8895 | if (argv[1]) |
8896 | save_and_replace_G_args(&sv, argv); | ||
8893 | 8897 | ||
8894 | parse_and_run_file(input); | 8898 | parse_and_run_file(input); |
8895 | fclose(input); | 8899 | fclose(input); |
8896 | 8900 | ||
8897 | restore_G_args(&sv, argv); | 8901 | if (argv[1]) |
8902 | restore_G_args(&sv, argv); | ||
8898 | #if ENABLE_HUSH_FUNCTIONS | 8903 | #if ENABLE_HUSH_FUNCTIONS |
8899 | G.flag_return_in_progress = sv_flg; | 8904 | G.flag_return_in_progress = sv_flg; |
8900 | #endif | 8905 | #endif |
diff --git a/shell/hush_test/hush-misc/source2.right b/shell/hush_test/hush-misc/source2.right new file mode 100644 index 000000000..0587bad67 --- /dev/null +++ b/shell/hush_test/hush-misc/source2.right | |||
@@ -0,0 +1,4 @@ | |||
1 | 0:arg0 1:arg1 2:arg2 | ||
2 | Ok1:0 | ||
3 | 0:arg0 1:q 2:w | ||
4 | Ok2:0 | ||
diff --git a/shell/hush_test/hush-misc/source2.tests b/shell/hush_test/hush-misc/source2.tests new file mode 100755 index 000000000..40b6b83cd --- /dev/null +++ b/shell/hush_test/hush-misc/source2.tests | |||
@@ -0,0 +1,8 @@ | |||
1 | echo 'echo "0:$0 1:$1 2:$2"' >sourced1 | ||
2 | set -- 1 2 3 | ||
3 | "$THIS_SH" -c '. ./sourced1' arg0 arg1 arg2 | ||
4 | echo Ok1:$? | ||
5 | "$THIS_SH" -c '. ./sourced1 q w e' arg0 arg1 arg2 | ||
6 | echo Ok2:$? | ||
7 | |||
8 | rm sourced1 | ||
diff --git a/shell/math.c b/shell/math.c index 15c003965..3da151137 100644 --- a/shell/math.c +++ b/shell/math.c | |||
@@ -494,18 +494,6 @@ static const char op_tokens[] ALIGN1 = { | |||
494 | }; | 494 | }; |
495 | #define ptr_to_rparen (&op_tokens[sizeof(op_tokens)-7]) | 495 | #define ptr_to_rparen (&op_tokens[sizeof(op_tokens)-7]) |
496 | 496 | ||
497 | const char* FAST_FUNC | ||
498 | endofname(const char *name) | ||
499 | { | ||
500 | if (!is_name(*name)) | ||
501 | return name; | ||
502 | while (*++name) { | ||
503 | if (!is_in_name(*name)) | ||
504 | break; | ||
505 | } | ||
506 | return name; | ||
507 | } | ||
508 | |||
509 | static arith_t FAST_FUNC | 497 | static arith_t FAST_FUNC |
510 | evaluate_string(arith_state_t *math_state, const char *expr) | 498 | evaluate_string(arith_state_t *math_state, const char *expr) |
511 | { | 499 | { |
diff --git a/shell/math.h b/shell/math.h index 2d305eb12..864bee691 100644 --- a/shell/math.h +++ b/shell/math.h | |||
@@ -73,11 +73,6 @@ typedef long arith_t; | |||
73 | #define strto_arith_t strtoul | 73 | #define strto_arith_t strtoul |
74 | #endif | 74 | #endif |
75 | 75 | ||
76 | /* ash's and hush's endofname is the same, so... */ | ||
77 | # define is_name(c) ((c) == '_' || isalpha((unsigned char)(c))) | ||
78 | # define is_in_name(c) ((c) == '_' || isalnum((unsigned char)(c))) | ||
79 | const char* FAST_FUNC endofname(const char *name); | ||
80 | |||
81 | typedef const char* FAST_FUNC (*arith_var_lookup_t)(const char *name); | 76 | typedef const char* FAST_FUNC (*arith_var_lookup_t)(const char *name); |
82 | typedef void FAST_FUNC (*arith_var_set_t)(const char *name, const char *val); | 77 | typedef void FAST_FUNC (*arith_var_set_t)(const char *name, const char *val); |
83 | //typedef const char* FAST_FUNC (*arith_var_endofname_t)(const char *name); | 78 | //typedef const char* FAST_FUNC (*arith_var_endofname_t)(const char *name); |