Use bb_getopt_ulflags, save 200-300 bytes
This commit is contained in:
parent
58a2e0e262
commit
792cae5f2a
196
coreutils/ls.c
196
coreutils/ls.c
@ -808,33 +808,72 @@ static int list_single(struct dnode *dn)
|
|||||||
|
|
||||||
/*----------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------*/
|
||||||
|
|
||||||
static const char ls_opts[] = "1AaCdgilnsx"
|
/* "[-]Cadil1", POSIX mandated options, busybox always supports */
|
||||||
#ifdef CONFIG_FEATURE_LS_FILETYPES
|
/* "[-]gnsx", POSIX non-mandated options, busybox always supports */
|
||||||
"Fp"
|
/* "[-]Ak" GNU options, busybox always supports */
|
||||||
#endif
|
/* "[-]FLRctur", POSIX mandated options, busybox optionally supports */
|
||||||
#ifdef CONFIG_FEATURE_LS_RECURSIVE
|
/* "[-]p", POSIX non-mandated options, busybox optionally supports */
|
||||||
"R"
|
/* "[-]SXvThw", GNU options, busybox optionally supports */
|
||||||
#endif
|
/* "[-]K", SELinux mandated options, busybox optionally supports */
|
||||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
/* "[-]e", I think we made this one up */
|
||||||
"rSvX"
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
|
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
|
||||||
"ecut"
|
# define LS_STR_TIMESTAMPS "cetu"
|
||||||
|
#else
|
||||||
|
# define LS_STR_TIMESTAMPS ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||||
|
# define LS_STR_SORTFILES "SXrv"
|
||||||
|
#else
|
||||||
|
# define LS_STR_SORTFILES ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_FEATURE_LS_FILETYPES
|
||||||
|
# define LS_STR_FILETYPES "Fp"
|
||||||
|
#else
|
||||||
|
# define LS_STR_FILETYPES ""
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
|
#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
|
||||||
"L"
|
# define LS_STR_FOLLOW_LINKS "L"
|
||||||
|
#else
|
||||||
|
# define LS_STR_FOLLOW_LINKS ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_FEATURE_LS_RECURSIVE
|
||||||
|
# define LS_STR_RECURSIVE "R"
|
||||||
|
#else
|
||||||
|
# define LS_STR_RECURSIVE ""
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||||
"h"
|
# define LS_STR_HUMAN_READABLE "h"
|
||||||
|
#else
|
||||||
|
# define LS_STR_HUMAN_READABLE ""
|
||||||
#endif
|
#endif
|
||||||
"k"
|
|
||||||
#ifdef CONFIG_SELINUX
|
#ifdef CONFIG_SELINUX
|
||||||
"K"
|
# define LS_STR_SELINUX "K"
|
||||||
|
#else
|
||||||
|
# define LS_STR_SELINUX ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||||
"T:w:"
|
# define LS_STR_AUTOWIDTH "T:w:"
|
||||||
|
#else
|
||||||
|
# define LS_STR_AUTOWIDTH ""
|
||||||
#endif
|
#endif
|
||||||
;
|
|
||||||
|
static const char ls_options[]="Cadil1gnsxAk" \
|
||||||
|
LS_STR_TIMESTAMPS \
|
||||||
|
LS_STR_SORTFILES \
|
||||||
|
LS_STR_FILETYPES \
|
||||||
|
LS_STR_FOLLOW_LINKS \
|
||||||
|
LS_STR_RECURSIVE \
|
||||||
|
LS_STR_HUMAN_READABLE \
|
||||||
|
LS_STR_SELINUX \
|
||||||
|
LS_STR_AUTOWIDTH;
|
||||||
|
|
||||||
#define LIST_MASK_TRIGGER LIST_SHORT
|
#define LIST_MASK_TRIGGER LIST_SHORT
|
||||||
#define STYLE_MASK_TRIGGER STYLE_MASK
|
#define STYLE_MASK_TRIGGER STYLE_MASK
|
||||||
@ -843,23 +882,39 @@ static const char ls_opts[] = "1AaCdgilnsx"
|
|||||||
#define TIME_MASK_TRIGGER TIME_MASK
|
#define TIME_MASK_TRIGGER TIME_MASK
|
||||||
|
|
||||||
static const unsigned opt_flags[] = {
|
static const unsigned opt_flags[] = {
|
||||||
LIST_SHORT | STYLE_SINGLE, /* 1 */
|
|
||||||
DISP_HIDDEN, /* A */
|
|
||||||
DISP_HIDDEN | DISP_DOT, /* a */
|
|
||||||
LIST_SHORT | STYLE_COLUMNS, /* C */
|
LIST_SHORT | STYLE_COLUMNS, /* C */
|
||||||
|
DISP_HIDDEN | DISP_DOT, /* a */
|
||||||
DISP_NOLIST, /* d */
|
DISP_NOLIST, /* d */
|
||||||
0, /* g - ingored */
|
|
||||||
LIST_INO, /* i */
|
LIST_INO, /* i */
|
||||||
LIST_LONG | STYLE_LONG, /* l - remember LS_DISP_HR in mask! */
|
LIST_LONG | STYLE_LONG, /* l - remember LS_DISP_HR in mask! */
|
||||||
|
LIST_SHORT | STYLE_SINGLE, /* 1 */
|
||||||
|
0, /* g - ingored */
|
||||||
LIST_ID_NUMERIC, /* n */
|
LIST_ID_NUMERIC, /* n */
|
||||||
LIST_BLOCKS, /* s */
|
LIST_BLOCKS, /* s */
|
||||||
DISP_ROWS, /* x */
|
DISP_ROWS, /* x */
|
||||||
#ifdef CONFIG_FEATURE_LS_FILETYPES
|
DISP_HIDDEN, /* A */
|
||||||
LIST_FILETYPE | LIST_EXEC, /* F */
|
#ifdef CONFIG_SELINUX
|
||||||
LIST_FILETYPE, /* p */
|
LIST_CONTEXT, /* k */
|
||||||
|
#else
|
||||||
|
0, /* k - ingored */
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_FEATURE_LS_RECURSIVE
|
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
|
||||||
DISP_RECURSIVE, /* R */
|
# ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||||
|
TIME_CHANGE | SORT_CTIME, /* c */
|
||||||
|
# else
|
||||||
|
TIME_CHANGE, /* c */
|
||||||
|
# endif
|
||||||
|
LIST_FULLTIME, /* e */
|
||||||
|
# ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||||
|
SORT_MTIME, /* t */
|
||||||
|
# else
|
||||||
|
0, /* t - ignored -- is this correct? */
|
||||||
|
# endif
|
||||||
|
# ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||||
|
TIME_ACCESS | SORT_ATIME, /* u */
|
||||||
|
# else
|
||||||
|
TIME_ACCESS, /* u */
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||||
SORT_ORDER_REVERSE, /* r */
|
SORT_ORDER_REVERSE, /* r */
|
||||||
@ -867,34 +922,20 @@ static const unsigned opt_flags[] = {
|
|||||||
SORT_VERSION, /* v */
|
SORT_VERSION, /* v */
|
||||||
SORT_EXT, /* v */
|
SORT_EXT, /* v */
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_FEATURE_LS_TIMESTAMPS
|
#ifdef CONFIG_FEATURE_LS_FILETYPES
|
||||||
LIST_FULLTIME, /* e */
|
LIST_FILETYPE | LIST_EXEC, /* F */
|
||||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
LIST_FILETYPE, /* p */
|
||||||
TIME_CHANGE | SORT_CTIME, /* c */
|
|
||||||
#else
|
|
||||||
TIME_CHANGE, /* c */
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
|
||||||
TIME_ACCESS | SORT_ATIME, /* u */
|
|
||||||
#else
|
|
||||||
TIME_ACCESS, /* u */
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
|
||||||
SORT_MTIME, /* t */
|
|
||||||
#else
|
|
||||||
0, /* t - ignored -- is this correct? */
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
|
#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS
|
||||||
FOLLOW_LINKS, /* L */
|
FOLLOW_LINKS, /* L */
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
#ifdef CONFIG_FEATURE_LS_RECURSIVE
|
||||||
LS_DISP_HR, /* h */
|
DISP_RECURSIVE, /* R */
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONFIG_SELINUX
|
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||||
0, /* k - ingored */
|
LS_DISP_HR, /* h */
|
||||||
#else
|
#endif
|
||||||
LIST_CONTEXT, /* k */
|
#ifdef CONFIG_SELINUX
|
||||||
LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME, /* K */
|
LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME, /* K */
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
@ -904,13 +945,24 @@ LS_DISP_HR, /* h */
|
|||||||
|
|
||||||
extern int ls_main(int argc, char **argv)
|
extern int ls_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct dnode **dnf, **dnd;
|
struct dnode **dnd;
|
||||||
int dnfiles, dndirs;
|
struct dnode **dnf;
|
||||||
struct dnode *dn, *cur, **dnp;
|
struct dnode **dnp;
|
||||||
int i, nfiles;
|
struct dnode *dn;
|
||||||
int opt;
|
struct dnode *cur;
|
||||||
int oi, ac;
|
long opt;
|
||||||
|
int nfiles = 0;
|
||||||
|
int dnfiles;
|
||||||
|
int dndirs;
|
||||||
|
int oi;
|
||||||
|
int ac;
|
||||||
|
int i;
|
||||||
char **av;
|
char **av;
|
||||||
|
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||||
|
char *tabstops_str = NULL;
|
||||||
|
char *terminal_width_str = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_SELINUX
|
#ifdef CONFIG_SELINUX
|
||||||
is_flask_enabled_flag = is_flask_enabled();
|
is_flask_enabled_flag = is_flask_enabled();
|
||||||
#endif
|
#endif
|
||||||
@ -923,13 +975,13 @@ extern int ls_main(int argc, char **argv)
|
|||||||
| SORT_NAME | SORT_ORDER_FORWARD
|
| SORT_NAME | SORT_ORDER_FORWARD
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||||
/* Obtain the terminal width. */
|
/* Obtain the terminal width. */
|
||||||
get_terminal_width_height(0, &terminal_width, NULL);
|
get_terminal_width_height(0, &terminal_width, NULL);
|
||||||
/* Go one less... */
|
/* Go one less... */
|
||||||
terminal_width--;
|
terminal_width--;
|
||||||
#endif
|
#endif
|
||||||
nfiles = 0;
|
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_LS_COLOR
|
#ifdef CONFIG_FEATURE_LS_COLOR
|
||||||
if (isatty(fileno(stdout)))
|
if (isatty(fileno(stdout)))
|
||||||
@ -937,27 +989,21 @@ extern int ls_main(int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* process options */
|
/* process options */
|
||||||
while ((opt = getopt(argc, argv, ls_opts)) > 0) {
|
|
||||||
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
#ifdef CONFIG_FEATURE_AUTOWIDTH
|
||||||
if (opt == 'T') {
|
opt = bb_getopt_ulflags(argc, argv, ls_options, &tabstops_str, &terminal_width_str);
|
||||||
tabstops = atoi(optarg);
|
if (tabstops_str) {
|
||||||
continue;
|
tabstops = atoi(tabstops_str);
|
||||||
}
|
}
|
||||||
if (opt == 'w') {
|
if (terminal_width_str) {
|
||||||
terminal_width = atoi(optarg);
|
terminal_width = atoi(terminal_width_str);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (opt == ':') {
|
|
||||||
goto print_usage_message;
|
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
opt = bb_getopt_ulflags(argc, argv, ls_options);
|
||||||
#endif
|
#endif
|
||||||
{
|
/* 16 = maximum options minus tabsize and screewn width */
|
||||||
unsigned int flags;
|
for (i = 0; i < 16; i++) {
|
||||||
const char *p = strchr(ls_opts, opt);
|
if (opt & (1 << i)) {
|
||||||
if (!p) { /* shouldn't be necessary */
|
unsigned int flags = opt_flags[i];
|
||||||
goto print_usage_message;
|
|
||||||
}
|
|
||||||
flags = opt_flags[(int)(p - ls_opts)];
|
|
||||||
if (flags & LIST_MASK_TRIGGER) {
|
if (flags & LIST_MASK_TRIGGER) {
|
||||||
all_fmt &= ~LIST_MASK;
|
all_fmt &= ~LIST_MASK;
|
||||||
}
|
}
|
||||||
@ -989,7 +1035,6 @@ extern int ls_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* sort out which command line options take precedence */
|
/* sort out which command line options take precedence */
|
||||||
#ifdef CONFIG_FEATURE_LS_RECURSIVE
|
#ifdef CONFIG_FEATURE_LS_RECURSIVE
|
||||||
if (all_fmt & DISP_NOLIST)
|
if (all_fmt & DISP_NOLIST)
|
||||||
@ -1088,7 +1133,4 @@ extern int ls_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (status);
|
return (status);
|
||||||
|
|
||||||
print_usage_message:
|
|
||||||
bb_show_usage();
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user