diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-23 18:23:19 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-23 18:24:05 +0100 |
commit | f5bd6f631c22530698024afb595418f156e48261 (patch) | |
tree | 3ebaf85371101d5332ed4378cb33edd359eccec8 | |
parent | 11540a8da47318e34267f6ff033825ebabbd9181 (diff) | |
download | busybox-w32-f5bd6f631c22530698024afb595418f156e48261.tar.gz busybox-w32-f5bd6f631c22530698024afb595418f156e48261.tar.bz2 busybox-w32-f5bd6f631c22530698024afb595418f156e48261.zip |
ls: handle -a and -A through option_mask32
function old new delta
ls_main 685 682 -3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | coreutils/ls.c | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index eb14a34e4..d11019f7d 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -215,8 +215,6 @@ LIST_MASK = (LIST_CLASSIFY << 1) - 1, | |||
215 | 215 | ||
216 | /* what files will be displayed */ | 216 | /* what files will be displayed */ |
217 | DISP_DIRNAME = 1 << 13, /* 2 or more items? label directories */ | 217 | DISP_DIRNAME = 1 << 13, /* 2 or more items? label directories */ |
218 | DISP_HIDDEN = 1 << 14, /* show filenames starting with . */ | ||
219 | DISP_DOT = 1 << 15, /* show . and .. */ | ||
220 | DISP_NOLIST = 1 << 16, /* show directory as itself, not contents */ | 218 | DISP_NOLIST = 1 << 16, /* show directory as itself, not contents */ |
221 | DISP_RECURSIVE = 1 << 17, /* show directory and everything below it */ | 219 | DISP_RECURSIVE = 1 << 17, /* show directory and everything below it */ |
222 | DISP_ROWS = 1 << 18, /* print across rows */ | 220 | DISP_ROWS = 1 << 18, /* print across rows */ |
@@ -258,7 +256,7 @@ static const char ls_options[] ALIGN1 = | |||
258 | ; | 256 | ; |
259 | enum { | 257 | enum { |
260 | //OPT_C = (1 << 0), | 258 | //OPT_C = (1 << 0), |
261 | //OPT_a = (1 << 1), | 259 | OPT_a = (1 << 1), |
262 | //OPT_d = (1 << 2), | 260 | //OPT_d = (1 << 2), |
263 | //OPT_i = (1 << 3), | 261 | //OPT_i = (1 << 3), |
264 | //OPT_1 = (1 << 4), | 262 | //OPT_1 = (1 << 4), |
@@ -267,7 +265,7 @@ enum { | |||
267 | //OPT_n = (1 << 7), | 265 | //OPT_n = (1 << 7), |
268 | //OPT_s = (1 << 8), | 266 | //OPT_s = (1 << 8), |
269 | //OPT_x = (1 << 9), | 267 | //OPT_x = (1 << 9), |
270 | //OPT_A = (1 << 10), | 268 | OPT_A = (1 << 10), |
271 | //OPT_k = (1 << 11), | 269 | //OPT_k = (1 << 11), |
272 | 270 | ||
273 | OPTBIT_F = 12, | 271 | OPTBIT_F = 12, |
@@ -317,7 +315,7 @@ enum { | |||
317 | /* TODO: simple toggles may be stored as OPT_xxx bits instead */ | 315 | /* TODO: simple toggles may be stored as OPT_xxx bits instead */ |
318 | static const uint32_t opt_flags[] = { | 316 | static const uint32_t opt_flags[] = { |
319 | STYLE_COLUMNAR, /* C */ | 317 | STYLE_COLUMNAR, /* C */ |
320 | DISP_HIDDEN | DISP_DOT, /* a */ | 318 | 0, /* a */ |
321 | DISP_NOLIST, /* d */ | 319 | DISP_NOLIST, /* d */ |
322 | LIST_INO, /* i */ | 320 | LIST_INO, /* i */ |
323 | STYLE_SINGLE, /* 1 */ | 321 | STYLE_SINGLE, /* 1 */ |
@@ -326,7 +324,7 @@ static const uint32_t opt_flags[] = { | |||
326 | LIST_LONG | STYLE_LONG | LIST_ID_NUMERIC, /* n (assumes l) */ | 324 | LIST_LONG | STYLE_LONG | LIST_ID_NUMERIC, /* n (assumes l) */ |
327 | LIST_BLOCKS, /* s */ | 325 | LIST_BLOCKS, /* s */ |
328 | DISP_ROWS | STYLE_COLUMNAR, /* x */ | 326 | DISP_ROWS | STYLE_COLUMNAR, /* x */ |
329 | DISP_HIDDEN, /* A */ | 327 | 0, /* A */ |
330 | ENABLE_SELINUX * (LIST_CONTEXT|STYLE_SINGLE), /* k (ignored if !SELINUX) */ | 328 | ENABLE_SELINUX * (LIST_CONTEXT|STYLE_SINGLE), /* k (ignored if !SELINUX) */ |
331 | #if ENABLE_FEATURE_LS_FILETYPES | 329 | #if ENABLE_FEATURE_LS_FILETYPES |
332 | LIST_FILETYPE | LIST_CLASSIFY, /* F */ | 330 | LIST_FILETYPE | LIST_CLASSIFY, /* F */ |
@@ -990,13 +988,13 @@ static struct dnode **scan_one_dir(const char *path, unsigned *nfiles_p) | |||
990 | 988 | ||
991 | /* are we going to list the file- it may be . or .. or a hidden file */ | 989 | /* are we going to list the file- it may be . or .. or a hidden file */ |
992 | if (entry->d_name[0] == '.') { | 990 | if (entry->d_name[0] == '.') { |
993 | if ((!entry->d_name[1] || (entry->d_name[1] == '.' && !entry->d_name[2])) | 991 | if (!(option_mask32 & (OPT_a|OPT_A))) |
994 | && !(G.all_fmt & DISP_DOT) | 992 | continue; /* skip all dotfiles if no -a/-A */ |
993 | if (!(option_mask32 & OPT_a) | ||
994 | && (!entry->d_name[1] || (entry->d_name[1] == '.' && !entry->d_name[2])) | ||
995 | ) { | 995 | ) { |
996 | continue; | 996 | continue; /* if only -A, skip . and .. but show other dotfiles */ |
997 | } | 997 | } |
998 | if (!(G.all_fmt & DISP_HIDDEN)) | ||
999 | continue; | ||
1000 | } | 998 | } |
1001 | fullname = concat_path_file(path, entry->d_name); | 999 | fullname = concat_path_file(path, entry->d_name); |
1002 | cur = my_stat(fullname, bb_basename(fullname), 0); | 1000 | cur = my_stat(fullname, bb_basename(fullname), 0); |
@@ -1220,7 +1218,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
1220 | if (ENABLE_FEATURE_LS_RECURSIVE && (G.all_fmt & DISP_NOLIST)) | 1218 | if (ENABLE_FEATURE_LS_RECURSIVE && (G.all_fmt & DISP_NOLIST)) |
1221 | G.all_fmt &= ~DISP_RECURSIVE; /* no recurse if listing only dir */ | 1219 | G.all_fmt &= ~DISP_RECURSIVE; /* no recurse if listing only dir */ |
1222 | if ((G.all_fmt & STYLE_MASK) != STYLE_LONG) { /* not -l? */ | 1220 | if ((G.all_fmt & STYLE_MASK) != STYLE_LONG) { /* not -l? */ |
1223 | G.all_fmt &= ~(LIST_ID_NUMERIC|LIST_ID_NAME|LIST_FULLTIME); | 1221 | G.all_fmt &= ~(LIST_ID_NUMERIC|LIST_ID_NAME); |
1224 | if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) { | 1222 | if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) { |
1225 | /* when to sort by time? -t[cu] sorts by time even with -l */ | 1223 | /* when to sort by time? -t[cu] sorts by time even with -l */ |
1226 | /* (this is achieved by opt_flags[] element for -t) */ | 1224 | /* (this is achieved by opt_flags[] element for -t) */ |