aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-02-28 12:16:10 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-02-28 12:16:10 +0100
commit9f368e38fbd165144a7398d3e6d8ae68ea97a3e6 (patch)
tree7cba90b22722ee669effe40bcae1575fa2c277b7
parentc6450c974f4ff8520113d727d58fa74f474cd913 (diff)
downloadbusybox-w32-9f368e38fbd165144a7398d3e6d8ae68ea97a3e6.tar.gz
busybox-w32-9f368e38fbd165144a7398d3e6d8ae68ea97a3e6.tar.bz2
busybox-w32-9f368e38fbd165144a7398d3e6d8ae68ea97a3e6.zip
ls: fix bits for -T, -w and --color; make -n imply -l; fix comments
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/ls.c45
1 files changed, 20 insertions, 25 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 2242fbaac..8d25b5d5f 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -159,7 +159,7 @@ STYLE_MASK = STYLE_SINGLE,
159 159
160/* which of the three times will be used */ 160/* which of the three times will be used */
161TIME_CHANGE = (1 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS, 161TIME_CHANGE = (1 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS,
162TIME_ACCESS = (1 << 22) * ENABLE_FEATURE_LS_TIMESTAMPS, 162TIME_ACCESS = (2 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS,
163TIME_MASK = (3 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS, 163TIME_MASK = (3 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS,
164 164
165/* how will the files be sorted (CONFIG_FEATURE_LS_SORTFILES) */ 165/* how will the files be sorted (CONFIG_FEATURE_LS_SORTFILES) */
@@ -189,10 +189,9 @@ LIST_LONG = LIST_MODEBITS | LIST_NLINKS | LIST_ID_NAME | LIST_SIZE | \
189/* Not fully compatible - we show not only '/' but other chars too */ 189/* Not fully compatible - we show not only '/' but other chars too */
190/* -SXvhTw GNU options, busybox optionally supports */ 190/* -SXvhTw GNU options, busybox optionally supports */
191/* -T TABWIDTH is ignored (we don't use tabs on output) */ 191/* -T TABWIDTH is ignored (we don't use tabs on output) */
192/* -K SELinux mandated options, busybox optionally supports */ 192/* -KZ SELinux mandated options, busybox optionally supports */
193/* (coreutils 8.4 has no -K, remove it?) */
193/* -e I think we made this one up (looks similar to GNU --full-time) */ 194/* -e I think we made this one up (looks similar to GNU --full-time) */
194/* Std opts we do not support: */
195/* -H Follow the links on command line only */
196static const char ls_options[] ALIGN1 = 195static const char ls_options[] ALIGN1 =
197 "Cadil1gnsxQAk" /* 13 opts, total 13 */ 196 "Cadil1gnsxQAk" /* 13 opts, total 13 */
198 IF_FEATURE_LS_TIMESTAMPS("cetu") /* 4, 17 */ 197 IF_FEATURE_LS_TIMESTAMPS("cetu") /* 4, 17 */
@@ -235,7 +234,7 @@ enum {
235 OPTBIT_L = OPTBIT_K + 2 * ENABLE_SELINUX, 234 OPTBIT_L = OPTBIT_K + 2 * ENABLE_SELINUX,
236 OPTBIT_H, /* 27 */ 235 OPTBIT_H, /* 27 */
237 OPTBIT_h = OPTBIT_L + 2 * ENABLE_FEATURE_LS_FOLLOWLINKS, 236 OPTBIT_h = OPTBIT_L + 2 * ENABLE_FEATURE_LS_FOLLOWLINKS,
238 OPTBIT_T = OPTBIT_h + 2 * ENABLE_FEATURE_HUMAN_READABLE, 237 OPTBIT_T = OPTBIT_h + 1 * ENABLE_FEATURE_HUMAN_READABLE,
239 OPTBIT_w, /* 30 */ 238 OPTBIT_w, /* 30 */
240 OPTBIT_color = OPTBIT_T + 2 * ENABLE_FEATURE_AUTOWIDTH, 239 OPTBIT_color = OPTBIT_T + 2 * ENABLE_FEATURE_AUTOWIDTH,
241 240
@@ -269,12 +268,12 @@ static const uint32_t opt_flags[] = {
269 LIST_LONG | STYLE_LONG, /* l */ 268 LIST_LONG | STYLE_LONG, /* l */
270 STYLE_SINGLE, /* 1 */ 269 STYLE_SINGLE, /* 1 */
271 0, /* g (don't show owner) - handled via OPT_g */ 270 0, /* g (don't show owner) - handled via OPT_g */
272 LIST_ID_NUMERIC, /* n */ 271 LIST_ID_NUMERIC | LIST_LONG | STYLE_LONG, /* n (assumes l) */
273 LIST_BLOCKS, /* s */ 272 LIST_BLOCKS, /* s */
274 DISP_ROWS | STYLE_COLUMNAR, /* x */ 273 DISP_ROWS | STYLE_COLUMNAR, /* x */
275 0, /* Q (quote filename) - handled via OPT_Q */ 274 0, /* Q (quote filename) - handled via OPT_Q */
276 DISP_HIDDEN, /* A */ 275 DISP_HIDDEN, /* A */
277 ENABLE_SELINUX * LIST_CONTEXT, /* k (ignored if !SELINUX) */ 276 ENABLE_SELINUX * (LIST_CONTEXT|STYLE_SINGLE), /* k (ignored if !SELINUX) */
278#if ENABLE_FEATURE_LS_TIMESTAMPS 277#if ENABLE_FEATURE_LS_TIMESTAMPS
279 TIME_CHANGE | (ENABLE_FEATURE_LS_SORTFILES * SORT_CTIME), /* c */ 278 TIME_CHANGE | (ENABLE_FEATURE_LS_SORTFILES * SORT_CTIME), /* c */
280 LIST_FULLTIME, /* e */ 279 LIST_FULLTIME, /* e */
@@ -295,8 +294,8 @@ static const uint32_t opt_flags[] = {
295 DISP_RECURSIVE, /* R */ 294 DISP_RECURSIVE, /* R */
296#endif 295#endif
297#if ENABLE_SELINUX 296#if ENABLE_SELINUX
298 LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME, /* K */ 297 LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME|STYLE_SINGLE, /* K */
299 LIST_MODEBITS|LIST_ID_NAME|LIST_CONTEXT, /* Z */ 298 LIST_MODEBITS|LIST_ID_NAME|LIST_CONTEXT|STYLE_SINGLE, /* Z */
300#endif 299#endif
301 (1U << 31) 300 (1U << 31)
302 /* options after Z are not processed through opt_flags */ 301 /* options after Z are not processed through opt_flags */
@@ -688,8 +687,16 @@ static NOINLINE unsigned list_single(const struct dnode *dn)
688 column += printf("%-10s ", (char *) bb_mode_string(dn->dstat.st_mode)); 687 column += printf("%-10s ", (char *) bb_mode_string(dn->dstat.st_mode));
689 if (all_fmt & LIST_NLINKS) 688 if (all_fmt & LIST_NLINKS)
690 column += printf("%4lu ", (long) dn->dstat.st_nlink); 689 column += printf("%4lu ", (long) dn->dstat.st_nlink);
690 if (all_fmt & LIST_ID_NUMERIC) {
691 if (option_mask32 & OPT_g)
692 column += printf("%-8u ", (int) dn->dstat.st_gid);
693 else
694 column += printf("%-8u %-8u ",
695 (int) dn->dstat.st_uid,
696 (int) dn->dstat.st_gid);
697 }
691#if ENABLE_FEATURE_LS_USERNAME 698#if ENABLE_FEATURE_LS_USERNAME
692 if (all_fmt & LIST_ID_NAME) { 699 else if (all_fmt & LIST_ID_NAME) {
693 if (option_mask32 & OPT_g) { 700 if (option_mask32 & OPT_g) {
694 column += printf("%-8.8s ", 701 column += printf("%-8.8s ",
695 get_cached_groupname(dn->dstat.st_gid)); 702 get_cached_groupname(dn->dstat.st_gid));
@@ -700,14 +707,6 @@ static NOINLINE unsigned list_single(const struct dnode *dn)
700 } 707 }
701 } 708 }
702#endif 709#endif
703 if (all_fmt & LIST_ID_NUMERIC) {
704 if (option_mask32 & OPT_g)
705 column += printf("%-8u ", (int) dn->dstat.st_gid);
706 else
707 column += printf("%-8u %-8u ",
708 (int) dn->dstat.st_uid,
709 (int) dn->dstat.st_gid);
710 }
711 if (all_fmt & LIST_SIZE) { 710 if (all_fmt & LIST_SIZE) {
712 if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) { 711 if (S_ISBLK(dn->dstat.st_mode) || S_ISCHR(dn->dstat.st_mode)) {
713 column += printf("%4u, %3u ", 712 column += printf("%4u, %3u ",
@@ -1040,7 +1039,8 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1040 1039
1041 init_unicode(); 1040 init_unicode();
1042 1041
1043 all_fmt = ENABLE_FEATURE_LS_SORTFILES * SORT_NAME; 1042 if (ENABLE_FEATURE_LS_SORTFILES)
1043 all_fmt = SORT_NAME;
1044 1044
1045#if ENABLE_FEATURE_AUTOWIDTH 1045#if ENABLE_FEATURE_AUTOWIDTH
1046 /* obtain the terminal width */ 1046 /* obtain the terminal width */
@@ -1081,8 +1081,6 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1081 if (flags & TIME_MASK) 1081 if (flags & TIME_MASK)
1082 all_fmt &= ~TIME_MASK; 1082 all_fmt &= ~TIME_MASK;
1083 1083
1084 if (flags & LIST_CONTEXT)
1085 all_fmt |= STYLE_SINGLE;
1086 all_fmt |= flags; 1084 all_fmt |= flags;
1087 } 1085 }
1088 } 1086 }
@@ -1121,11 +1119,8 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
1121 if (all_fmt & TIME_ACCESS) 1119 if (all_fmt & TIME_ACCESS)
1122 all_fmt = (all_fmt & ~SORT_MASK) | SORT_ATIME; 1120 all_fmt = (all_fmt & ~SORT_MASK) | SORT_ATIME;
1123 } 1121 }
1124 if ((all_fmt & STYLE_MASK) != STYLE_LONG) /* only for long list */ 1122 if ((all_fmt & STYLE_MASK) != STYLE_LONG) /* not -l? */
1125 all_fmt &= ~(LIST_ID_NUMERIC|LIST_ID_NAME|LIST_FULLTIME); 1123 all_fmt &= ~(LIST_ID_NUMERIC|LIST_ID_NAME|LIST_FULLTIME);
1126 if (ENABLE_FEATURE_LS_USERNAME)
1127 if ((all_fmt & STYLE_MASK) == STYLE_LONG && (all_fmt & LIST_ID_NUMERIC))
1128 all_fmt &= ~LIST_ID_NAME; /* don't list names if numeric uid */
1129 1124
1130 /* choose a display format if one was not already specified by an option */ 1125 /* choose a display format if one was not already specified by an option */
1131 if (!(all_fmt & STYLE_MASK)) 1126 if (!(all_fmt & STYLE_MASK))