summaryrefslogtreecommitdiffstats
path: root/core/busybox/busybox-1.14.2-ls.patch
blob: 64e0a94f37e49f833fa602326a01ae389075db4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
diff -urpN busybox-1.14.2/coreutils/ls.c busybox-1.14.2-ls/coreutils/ls.c
--- busybox-1.14.2/coreutils/ls.c	2009-06-22 00:40:29.000000000 +0200
+++ busybox-1.14.2-ls/coreutils/ls.c	2009-07-03 12:46:16.000000000 +0200
@@ -144,8 +144,7 @@ static const char ls_options[] ALIGN1 =
 	USE_FEATURE_LS_FOLLOWLINKS("L")   /* 1, 24 */
 	USE_FEATURE_LS_RECURSIVE("R")     /* 1, 25 */
 	USE_FEATURE_HUMAN_READABLE("h")   /* 1, 26 */
-	USE_SELINUX("K") /* 1, 27 */
-	USE_SELINUX("Z") /* 1, 28 */
+	USE_SELINUX("KZ") /* 2, 28 */
 	USE_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 {
@@ -889,16 +898,6 @@ static int list_single(const struct dnod
 }
 
 
-/* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */
-#if ENABLE_FEATURE_LS_COLOR
-/* long option entry used only for --color, which has no short option
- * equivalent */
-static const char ls_color_opt[] ALIGN1 =
-	"color\0" Optional_argument "\xff" /* no short equivalent */
-	;
-#endif
-
-
 int ls_main(int argc UNUSED_PARAM, char **argv)
 {
 	struct dnode **dnd;
@@ -911,8 +910,25 @@ int ls_main(int argc UNUSED_PARAM, char 
 	int dnfiles;
 	int dndirs;
 	int i;
+#if ENABLE_FEATURE_LS_COLOR
+	/* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */
+	/* coreutils 6.10:
+	 * # ls --color=BOGUS
+	 * ls: invalid argument 'BOGUS' for '--color'
+	 * Valid arguments are:
+	 * 'always', 'yes', 'force'
+	 * 'never', 'no', 'none'
+	 * 'auto', 'tty', 'if-tty'
+	 * (and substrings: "--color=alwa" work too)
+	 */
+	static const char ls_longopts[] ALIGN1 =
+		"color\0" Optional_argument "\xff"; /* no short equivalent */
+	static const char color_str[] ALIGN1 =
+		"always\0""yes\0""force\0"
+		"auto\0""tty\0""if-tty\0";
 	/* need to initialize since --color has _an optional_ argument */
-	USE_FEATURE_LS_COLOR(const char *color_opt = "always";)
+	const char *color_opt = color_str; /* "always" */
+#endif
 
 	INIT_G();
 
@@ -927,7 +943,7 @@ int ls_main(int argc UNUSED_PARAM, char 
 #endif
 
 	/* process options */
-	USE_FEATURE_LS_COLOR(applet_long_options = ls_color_opt;)
+	USE_FEATURE_LS_COLOR(applet_long_options = ls_longopts;)
 #if ENABLE_FEATURE_AUTOWIDTH
 	opt_complementary = "T+:w+"; /* -T N, -w N */
 	opt = getopt32(argv, ls_options, &tabstops, &terminal_width
@@ -966,13 +982,20 @@ int ls_main(int argc UNUSED_PARAM, char 
 		if (!p || (p[0] && strcmp(p, "none") != 0))
 			show_color = 1;
 	}
-	if (opt & (1 << i)) {  /* next flag after short options */
-		if (strcmp("always", color_opt) == 0)
-			show_color = 1;
-		else if (strcmp("never", color_opt) == 0)
+	if (opt & OPT_color) {
+		if (color_opt[0] == 'n')
 			show_color = 0;
-		else if (strcmp("auto", color_opt) == 0 && isatty(STDOUT_FILENO))
-			show_color = 1;
+		else switch (index_in_substrings(color_str, color_opt)) {
+		case 3:
+		case 4:
+		case 5:
+			if (isatty(STDOUT_FILENO)) {
+		case 0:
+		case 1:
+		case 2:
+				show_color = 1;
+			}
+		}
 	}
 #endif
 
diff -urpN busybox-1.14.2/testsuite/ls/ls-1-works busybox-1.14.2-ls/testsuite/ls/ls-1-works
--- busybox-1.14.2/testsuite/ls/ls-1-works	2009-06-22 00:32:00.000000000 +0200
+++ busybox-1.14.2-ls/testsuite/ls/ls-1-works	2009-07-02 14:28:45.000000000 +0200
@@ -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
diff -urpN busybox-1.14.2/testsuite/ls/ls-h-works busybox-1.14.2-ls/testsuite/ls/ls-h-works
--- busybox-1.14.2/testsuite/ls/ls-h-works	2009-06-22 00:32:00.000000000 +0200
+++ busybox-1.14.2-ls/testsuite/ls/ls-h-works	2009-07-02 14:28:45.000000000 +0200
@@ -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
diff -urpN busybox-1.14.2/testsuite/ls/ls-l-works busybox-1.14.2-ls/testsuite/ls/ls-l-works
--- busybox-1.14.2/testsuite/ls/ls-l-works	2009-06-22 00:32:00.000000000 +0200
+++ busybox-1.14.2-ls/testsuite/ls/ls-l-works	2009-07-02 14:28:45.000000000 +0200
@@ -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
diff -urpN busybox-1.14.2/testsuite/ls/ls-s-works busybox-1.14.2-ls/testsuite/ls/ls-s-works
--- busybox-1.14.2/testsuite/ls/ls-s-works	2009-06-22 00:32:00.000000000 +0200
+++ busybox-1.14.2-ls/testsuite/ls/ls-s-works	2009-07-02 14:28:45.000000000 +0200
@@ -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