[PATCH] ls: make -C exclusive with -l and -1 (bug 2959).
James Youngman
jay at gnu.org
Sat Dec 18 15:32:01 UTC 2010
Also explain why we cannot do this right now for -c and -u (and that
means this change does not fully fix bug 2959).
Signed-off-by: James Youngman <jay at gnu.org>
---
coreutils/ls.c | 33 ++++++++++++++++++++++++---------
1 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 72f58c2..dc78b5c 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -57,9 +57,11 @@ COLUMN_GAP = 2, /* includes the file type char */
/* what is the overall style of the listing */
STYLE_COLUMNS = 1 << 21, /* fill columns */
-STYLE_LONG = 2 << 21, /* one record per line, extended info */
-STYLE_SINGLE = 3 << 21, /* one record per line */
-STYLE_MASK = STYLE_SINGLE,
+STYLE_SINGLE = 2 << 21, /* one record per line */
+STYLE_LONG = 3 << 21, /* one record per line, extended info */
+STYLE_MASK = STYLE_LONG,
+/* If we add -m it's exclusive with respect to -l (last specified wins). */
+/* -x and -l are exclusive, but this works implicitly. */
/* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */
/* what file information will be listed */
@@ -102,13 +104,22 @@ SORT_VERSION = 5 << 28, /* sort by version */
SORT_EXT = 6 << 28, /* sort by file name extension */
SORT_DIR = 7 << 28, /* sort by file or directory */
SORT_MASK = (7 << 28) * ENABLE_FEATURE_LS_SORTFILES,
-
+/* TODO: -c (SORT_CTIME) and -u (SORT_ATIME) should be exclusive
+ (i.e. override the effect of the other), but making that work
+ requires giving them unique bits in the flags passed into getopt32,
+ so that we can make them complementary options. We don't have
+ enough bits for that. The existing *_TRIGGER mechanism can't be
+ used for this purpose, because it considers the options in the
+ order they appear in opt_flags, not the order they appear on the
+ command line.
+*/
/* which of the three times will be used */
TIME_CHANGE = (1 << 23) * ENABLE_FEATURE_LS_TIMESTAMPS,
TIME_ACCESS = (1 << 24) * ENABLE_FEATURE_LS_TIMESTAMPS,
TIME_MASK = (3 << 23) * ENABLE_FEATURE_LS_TIMESTAMPS,
FOLLOW_LINKS = (1 << 25) * ENABLE_FEATURE_LS_FOLLOWLINKS,
+/* -H and -L would be exclusive if -H were supported. */
LS_DISP_HR = (1 << 26) * ENABLE_FEATURE_HUMAN_READABLE,
@@ -123,6 +134,8 @@ SPLIT_SUBDIR = 2,
/* "[-]Cadil1", POSIX mandated options, busybox always supports */
/* "[-]gnsx", POSIX non-mandated options, busybox always supports */
+/* "[-]L", POSIX mandated option, busybox does not support */
+/* "[-]m", POSIX non-mandated option, busybox does not support */
/* "[-]Q" GNU option? busybox always supports */
/* "[-]Ak" GNU options, busybox always supports */
/* "[-]FLRctur", POSIX mandated options, busybox optionally supports */
@@ -741,7 +754,7 @@ static void showfiles(struct dnode **dn, unsigned nfiles)
unsigned nexttab = 0;
unsigned column_width = 0; /* used only by STYLE_COLUMNS */
- if (all_fmt & STYLE_LONG) { /* STYLE_LONG or STYLE_SINGLE */
+ if ((all_fmt & STYLE_SINGLE) || ((all_fmt & STYLE_MASK) == STYLE_LONG)) {
ncols = 1;
} else {
/* find the longest file name, use that as the column width */
@@ -984,8 +997,8 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
/* process options */
IF_FEATURE_LS_COLOR(applet_long_options = ls_longopts;)
+ opt_complementary = "C-1:C-l" IF_FEATURE_AUTOWIDTH(":T+:w+"); /* -T N, -w N */
#if ENABLE_FEATURE_AUTOWIDTH
- opt_complementary = "T+:w+"; /* -T N, -w N */
opt = getopt32(argv, ls_options, &tabstops, &terminal_width
IF_FEATURE_LS_COLOR(, &color_opt));
#else
@@ -1006,7 +1019,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
if (flags & TIME_MASK)
all_fmt &= ~TIME_MASK;
if (flags & LIST_CONTEXT)
- all_fmt |= STYLE_SINGLE;
+ all_fmt = (all_fmt & ~STYLE_MASK) | STYLE_SINGLE;
/* huh?? opt cannot be 'l' */
//if (LS_DISP_HR && opt == 'l')
// all_fmt &= ~LS_DISP_HR;
@@ -1054,7 +1067,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
if ((all_fmt & STYLE_MASK) == STYLE_LONG && (all_fmt & LIST_ID_NUMERIC))
all_fmt &= ~LIST_ID_NAME; /* don't list names if numeric uid */
- /* choose a display format */
+ /* choose a display format if one was not already specified by an option */
if (!(all_fmt & STYLE_MASK))
all_fmt |= (isatty(STDOUT_FILENO) ? STYLE_COLUMNS : STYLE_SINGLE);
@@ -1070,7 +1083,9 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
nfiles = 0;
do {
/* NB: follow links on command line unless -l or -s */
- cur = my_stat(*argv, *argv, !(all_fmt & (STYLE_LONG|LIST_BLOCKS)));
+ const int follow = !(all_fmt & LIST_BLOCKS)
+ && ((all_fmt & STYLE_MASK) != STYLE_LONG);
+ cur = my_stat(*argv, *argv, follow);
argv++;
if (!cur)
continue;
--
1.7.2.3
More information about the busybox
mailing list