diff options
author | Denis Vlasenko | 2008-02-12 17:12:28 +0000 |
---|---|---|
committer | Denis Vlasenko | 2008-02-12 17:12:28 +0000 |
commit | a68cb75a2e72303ef4a609cab28d25ccc789d685 (patch) | |
tree | c9f1fd8ef0c1d50341c4377ce467c94ec6944881 /coreutils | |
parent | 0b18cd3d04b17acec73af3d2cafd00c59a3f807f (diff) | |
download | busybox-a68cb75a2e72303ef4a609cab28d25ccc789d685.zip busybox-a68cb75a2e72303ef4a609cab28d25ccc789d685.tar.gz |
Applied post 1.9.0 fixes
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/stty.c | 24 | ||||
-rw-r--r-- | coreutils/test.c | 49 |
2 files changed, 31 insertions, 42 deletions
diff --git a/coreutils/stty.c b/coreutils/stty.c index ade2468..298fb5b 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c @@ -780,30 +780,14 @@ static const struct suffix_mult stty_suffixes[] = { static const struct mode_info *find_mode(const char *name) { - int i = 0; - const char *m = mode_name; - - while (*m) { - if (strcmp(name, m) == 0) - return &mode_info[i]; - m += strlen(m) + 1; - i++; - } - return NULL; + int i = index_in_strings(mode_name, name); + return i >= 0 ? &mode_info[i] : NULL; } static const struct control_info *find_control(const char *name) { - int i = 0; - const char *m = mode_name; - - while (*m) { - if (strcmp(name, m) == 0) - return &control_info[i]; - m += strlen(m) + 1; - i++; - } - return NULL; + int i = index_in_strings(control_name, name); + return i >= 0 ? &control_info[i] : NULL; } enum { diff --git a/coreutils/test.c b/coreutils/test.c index a30a508..22dadac 100644 --- a/coreutils/test.c +++ b/coreutils/test.c @@ -555,7 +555,7 @@ int test_main(int argc, char **argv) { int res; const char *arg0; - bool _off; + bool negate = 0; arg0 = bb_basename(argv[0]); if (arg0[0] == '[') { @@ -578,9 +578,8 @@ int test_main(int argc, char **argv) INIT_S(); res = setjmp(leaving); - if (res) { + if (res) goto ret; - } /* resetting ngroups is probably unnecessary. it will * force a new call to getgroups(), which prevents using @@ -592,34 +591,40 @@ int test_main(int argc, char **argv) */ ngroups = 0; + //argc--; + argv++; + /* Implement special cases from POSIX.2, section 4.62.4 */ - if (argc == 1) { + if (!argv[0]) { /* "test" */ res = 1; goto ret; } - if (argc == 2) { - res = (*argv[1] == '\0'); + if (LONE_CHAR(argv[0], '!') && argv[1]) { + negate = 1; + //argc--; + argv++; + } + if (!argv[1]) { /* "test [!] arg" */ + res = (*argv[0] == '\0'); goto ret; } - - /* remember if we saw argc==4 which wants *no* '!' test */ - _off = argc - 4; - if (_off ? (LONE_CHAR(argv[1], '!')) - : (argv[1][0] != '!' || argv[1][1] != '\0') - ) { - if (argc == 3) { - res = (*argv[2] != '\0'); - goto ret; - } - - t_lex(argv[2 + _off]); + if (argv[2] && !argv[3]) { + t_lex(argv[1]); if (t_wp_op && t_wp_op->op_type == BINOP) { - t_wp = &argv[1 + _off]; - res = (binop() == _off); + /* "test [!] arg1 <binary_op> arg2" */ + t_wp = &argv[0]; + res = (binop() == 0); goto ret; } } - t_wp = &argv[1]; + + /* Some complex expression. Undo '!' removal */ + if (negate) { + negate = 0; + //argc++; + argv--; + } + t_wp = &argv[0]; res = !oexpr(t_lex(*t_wp)); if (*t_wp != NULL && *++t_wp != NULL) { @@ -628,5 +633,5 @@ int test_main(int argc, char **argv) } ret: DEINIT_S(); - return res; + return negate ? !res : res; } |