ls: fix --color handling. Closes bug 435.
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 2 Jul 2009 12:25:51 +0000 (14:25 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 2 Jul 2009 12:25:51 +0000 (14:25 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
coreutils/ls.c
testsuite/ls/ls-1-works
testsuite/ls/ls-h-works
testsuite/ls/ls-l-works
testsuite/ls/ls-s-works

index 379b0f94ffc9ab3aa737c30612332bf54698fe75..db42601e231ba81de82a4052febdb1f3d5501942 100644 (file)
@@ -144,8 +144,7 @@ static const char ls_options[] ALIGN1 =
        IF_FEATURE_LS_FOLLOWLINKS("L")   /* 1, 24 */
        IF_FEATURE_LS_RECURSIVE("R")     /* 1, 25 */
        IF_FEATURE_HUMAN_READABLE("h")   /* 1, 26 */
-       IF_SELINUX("K") /* 1, 27 */
-       IF_SELINUX("Z") /* 1, 28 */
+       IF_SELINUX("KZ") /* 2, 28 */
        IF_FEATURE_AUTOWIDTH("T:w:") /* 2, 30 */
        ;
 enum {
@@ -162,6 +161,16 @@ enum {
        OPT_Q = (1 << 10),
        //OPT_A = (1 << 11),
        //OPT_k = (1 << 12),
+       OPTBIT_color = 13
+               + 4 * ENABLE_FEATURE_LS_TIMESTAMPS
+               + 4 * ENABLE_FEATURE_LS_SORTFILES
+               + 2 * ENABLE_FEATURE_LS_FILETYPES
+               + 1 * ENABLE_FEATURE_LS_FOLLOWLINKS
+               + 1 * ENABLE_FEATURE_LS_RECURSIVE
+               + 1 * ENABLE_FEATURE_HUMAN_READABLE
+               + 2 * ENABLE_SELINUX
+               + 2 * ENABLE_FEATURE_AUTOWIDTH,
+       OPT_color = 1 << OPTBIT_color,
 };
 
 enum {
@@ -966,7 +975,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
                if (!p || (p[0] && strcmp(p, "none") != 0))
                        show_color = 1;
        }
-       if (opt & (1 << i)) {  /* next flag after short options */
+       if (opt & OPT_color) {  /* next flag after short options */
                if (strcmp("always", color_opt) == 0)
                        show_color = 1;
                else if (strcmp("never", color_opt) == 0)
index 8ad484fc38ac389207c6d907fbfa6b5f02d832ec..885694920d040071fa32a4c813d87f55aa3f225d 100644 (file)
@@ -1,4 +1,4 @@
 [ -n "$d" ] || d=..
-ls -1 "$d" > logfile.gnu
-busybox ls -1 "$d" > logfile.bb
-cmp logfile.gnu logfile.bb
+LC_ALL=C ls -1 "$d" > logfile.gnu
+LC_ALL=C busybox ls -1 "$d" > logfile.bb
+diff -ubw logfile.gnu logfile.bb
index 7331262c957b49943759d0977b5e29871a3d34e7..0c83f7cc5fe5fab8a83ed03d22a9533b25b6d400 100644 (file)
@@ -1,4 +1,4 @@
 [ -n "$d" ] || d=..
-ls -h "$d" > logfile.gnu
-busybox ls -h "$d" > logfile.bb
-cmp logfile.gnu logfile.bb
+LC_ALL=C ls -h "$d" > logfile.gnu
+LC_ALL=C busybox ls -h "$d" > logfile.bb
+diff -ubw logfile.gnu logfile.bb
index efc2b196e173bf2a0ff290a15a5b5e1b524409d6..1bad34bcf50c9d374d420f1c0ad7d080c3158e02 100644 (file)
@@ -1,4 +1,4 @@
 [ -n "$d" ] || d=..
 LC_ALL=C ls -l "$d" > logfile.gnu
-busybox ls -l "$d" > logfile.bb
-diff -w logfile.gnu logfile.bb
+LC_ALL=C busybox ls -l "$d" > logfile.bb
+diff -ubw logfile.gnu logfile.bb
index 6c8bf3627e7176960071ac711a06dd0fdbdbb14a..0a9d7526f3e372ba1dd42d7e20154be5ed03d8d2 100644 (file)
@@ -1,4 +1,4 @@
 [ -n "$d" ] || d=..
 LC_ALL=C ls -1s "$d" > logfile.gnu
-busybox ls -1s "$d" > logfile.bb
-cmp logfile.gnu logfile.bb
+LC_ALL=C busybox ls -1s "$d" > logfile.bb
+diff -ubw logfile.gnu logfile.bb