diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-23 20:08:22 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-01-23 20:08:22 +0100 |
commit | 4cde4cca65c80106bdd97a7e532f3b80cf25fae5 (patch) | |
tree | 226e864184a7aeb454a9e74ef0e7799b077ef318 /coreutils | |
parent | 96d9c5bdbd5829decd478231846baaad8dd55426 (diff) | |
download | busybox-w32-4cde4cca65c80106bdd97a7e532f3b80cf25fae5.tar.gz busybox-w32-4cde4cca65c80106bdd97a7e532f3b80cf25fae5.tar.bz2 busybox-w32-4cde4cca65c80106bdd97a7e532f3b80cf25fae5.zip |
ls: handle -d and -R through option_mask32
function old new delta
scan_and_display_dirs_recur 545 550 +5
display_single 1039 1044 +5
append_char 67 68 +1
display_files 399 396 -3
ls_main 736 717 -19
opt_flags 68 11 -57
.rodata 168864 168784 -80
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/4 up/down: 11/-159) Total: -148 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils')
-rw-r--r-- | coreutils/ls.c | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index c62e84263..3052fda32 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -198,14 +198,12 @@ LIST_LONG = 1 << 0, /* long listing (-l and equivalents) */ | |||
198 | 198 | ||
199 | /* what files will be displayed */ | 199 | /* what files will be displayed */ |
200 | DISP_DIRNAME = 1 << 1, /* 2 or more items? label directories */ | 200 | DISP_DIRNAME = 1 << 1, /* 2 or more items? label directories */ |
201 | DISP_NOLIST = 1 << 2, /* show directory as itself, not contents */ | 201 | DISP_ROWS = 1 << 2, /* print across rows */ |
202 | DISP_RECURSIVE = 1 << 3, /* show directory and everything below it */ | ||
203 | DISP_ROWS = 1 << 4, /* print across rows */ | ||
204 | 202 | ||
205 | /* what is the overall style of the listing */ | 203 | /* what is the overall style of the listing */ |
206 | STYLE_COLUMNAR = 1 << 5, /* many records per line */ | 204 | STYLE_COLUMNAR = 1 << 3, /* many records per line */ |
207 | STYLE_LONG = 2 << 5, /* one record per line, extended info */ | 205 | STYLE_LONG = 2 << 3, /* one record per line, extended info */ |
208 | STYLE_SINGLE = 3 << 5, /* one record per line */ | 206 | STYLE_SINGLE = 3 << 3, /* one record per line */ |
209 | STYLE_MASK = STYLE_SINGLE, | 207 | STYLE_MASK = STYLE_SINGLE, |
210 | }; | 208 | }; |
211 | 209 | ||
@@ -236,7 +234,7 @@ static const char ls_options[] ALIGN1 = | |||
236 | enum { | 234 | enum { |
237 | //OPT_C = (1 << 0), | 235 | //OPT_C = (1 << 0), |
238 | OPT_a = (1 << 1), | 236 | OPT_a = (1 << 1), |
239 | //OPT_d = (1 << 2), | 237 | OPT_d = (1 << 2), |
240 | OPT_i = (1 << 3), | 238 | OPT_i = (1 << 3), |
241 | //OPT_1 = (1 << 4), | 239 | //OPT_1 = (1 << 4), |
242 | OPT_l = (1 << 5), | 240 | OPT_l = (1 << 5), |
@@ -292,10 +290,10 @@ enum { | |||
292 | }; | 290 | }; |
293 | 291 | ||
294 | /* TODO: simple toggles may be stored as OPT_xxx bits instead */ | 292 | /* TODO: simple toggles may be stored as OPT_xxx bits instead */ |
295 | static const uint32_t opt_flags[] = { | 293 | static const uint8_t opt_flags[] = { |
296 | STYLE_COLUMNAR, /* C */ | 294 | STYLE_COLUMNAR, /* C */ |
297 | 0, /* a */ | 295 | 0, /* a */ |
298 | DISP_NOLIST, /* d */ | 296 | 0, /* d */ |
299 | 0, /* i */ | 297 | 0, /* i */ |
300 | STYLE_SINGLE, /* 1 */ | 298 | STYLE_SINGLE, /* 1 */ |
301 | LIST_LONG | STYLE_LONG, /* l - by keeping it after -1, "ls -l -1" ignores -1 */ | 299 | LIST_LONG | STYLE_LONG, /* l - by keeping it after -1, "ls -l -1" ignores -1 */ |
@@ -303,20 +301,8 @@ static const uint32_t opt_flags[] = { | |||
303 | LIST_LONG | STYLE_LONG, /* n (numeris uid/gid) - handled via OPT_n. assumes l */ | 301 | LIST_LONG | STYLE_LONG, /* n (numeris uid/gid) - handled via OPT_n. assumes l */ |
304 | 0, /* s */ | 302 | 0, /* s */ |
305 | DISP_ROWS | STYLE_COLUMNAR, /* x */ | 303 | DISP_ROWS | STYLE_COLUMNAR, /* x */ |
306 | 0, /* A */ | 304 | 0xff |
307 | 0, /* k (ignored) */ | 305 | /* options after -x are not processed through opt_flags */ |
308 | #if ENABLE_FEATURE_LS_FILETYPES | ||
309 | 0, /* F */ | ||
310 | 0, /* p */ | ||
311 | #endif | ||
312 | #if ENABLE_FEATURE_LS_RECURSIVE | ||
313 | DISP_RECURSIVE, /* R */ | ||
314 | #endif | ||
315 | #if ENABLE_SELINUX | ||
316 | 0, /* Z */ | ||
317 | #endif | ||
318 | (1U << 31) | ||
319 | /* options after Z are not processed through opt_flags */ | ||
320 | }; | 306 | }; |
321 | 307 | ||
322 | 308 | ||
@@ -1048,7 +1034,9 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first) | |||
1048 | struct dnode **subdnp; | 1034 | struct dnode **subdnp; |
1049 | 1035 | ||
1050 | for (; *dn; dn++) { | 1036 | for (; *dn; dn++) { |
1051 | if (G.all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) { | 1037 | if ((G.all_fmt & DISP_DIRNAME) |
1038 | || (option_mask32 & OPT_R) | ||
1039 | ) { | ||
1052 | if (!first) | 1040 | if (!first) |
1053 | bb_putchar('\n'); | 1041 | bb_putchar('\n'); |
1054 | first = 0; | 1042 | first = 0; |
@@ -1067,7 +1055,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first) | |||
1067 | sort_and_display_files(subdnp, nfiles); | 1055 | sort_and_display_files(subdnp, nfiles); |
1068 | 1056 | ||
1069 | if (ENABLE_FEATURE_LS_RECURSIVE | 1057 | if (ENABLE_FEATURE_LS_RECURSIVE |
1070 | && (G.all_fmt & DISP_RECURSIVE) | 1058 | && (option_mask32 & OPT_R) |
1071 | ) { | 1059 | ) { |
1072 | struct dnode **dnd; | 1060 | struct dnode **dnd; |
1073 | unsigned dndirs; | 1061 | unsigned dndirs; |
@@ -1165,7 +1153,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
1165 | if (opt & OPT_full_time ) bb_error_msg("--full-time"); | 1153 | if (opt & OPT_full_time ) bb_error_msg("--full-time"); |
1166 | exit(0); | 1154 | exit(0); |
1167 | #endif | 1155 | #endif |
1168 | for (i = 0; opt_flags[i] != (1U << 31); i++) { | 1156 | for (i = 0; opt_flags[i] != 0xff; i++) { |
1169 | if (opt & (1 << i)) { | 1157 | if (opt & (1 << i)) { |
1170 | uint32_t flags = opt_flags[i]; | 1158 | uint32_t flags = opt_flags[i]; |
1171 | 1159 | ||
@@ -1208,8 +1196,8 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
1208 | #endif | 1196 | #endif |
1209 | 1197 | ||
1210 | /* sort out which command line options take precedence */ | 1198 | /* sort out which command line options take precedence */ |
1211 | if (ENABLE_FEATURE_LS_RECURSIVE && (G.all_fmt & DISP_NOLIST)) | 1199 | if (ENABLE_FEATURE_LS_RECURSIVE && (opt & OPT_d)) |
1212 | G.all_fmt &= ~DISP_RECURSIVE; /* no recurse if listing only dir */ | 1200 | option_mask32 &= ~OPT_R; /* no recurse if listing only dir */ |
1213 | if ((G.all_fmt & STYLE_MASK) != STYLE_LONG) { /* not -l? */ | 1201 | if ((G.all_fmt & STYLE_MASK) != STYLE_LONG) { /* not -l? */ |
1214 | if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) { | 1202 | if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) { |
1215 | /* when to sort by time? -t[cu] sorts by time even with -l */ | 1203 | /* when to sort by time? -t[cu] sorts by time even with -l */ |
@@ -1270,7 +1258,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv) | |||
1270 | break; | 1258 | break; |
1271 | } | 1259 | } |
1272 | 1260 | ||
1273 | if (G.all_fmt & DISP_NOLIST) { | 1261 | if (option_mask32 & OPT_d) { |
1274 | sort_and_display_files(dnp, nfiles); | 1262 | sort_and_display_files(dnp, nfiles); |
1275 | } else { | 1263 | } else { |
1276 | dnd = splitdnarray(dnp, SPLIT_DIR); | 1264 | dnd = splitdnarray(dnp, SPLIT_DIR); |