int ar_main(int argc, char **argv)
{
archive_handle_t *archive_handle;
- unsigned long opt;
+ unsigned opt;
static const char msg_unsupported_err[] =
"Archive %s not supported. Install binutils 'ar'.";
char magic[8];
archive_handle = init_handle();
/* Prepend '-' to the first argument if required */
- bb_opt_complementally = "--:p:t:x:-1:?:p--tx:t--px:x--pt";
- opt = bb_getopt_ulflags(argc, argv, "ptxovcr");
+ opt_complementary = "--:p:t:x:-1:?:p--tx:t--px:x--pt";
+ opt = getopt32(argc, argv, "ptxovcr");
if (opt & AR_CTX_PRINT) {
archive_handle->action_data = data_extract_to_stdout;
{
USE_DESKTOP(long long) int status;
char *filename;
- unsigned long opt;
+ unsigned opt;
int src_fd, dst_fd;
- opt = bb_getopt_ulflags(argc, argv, "cf");
+ opt = getopt32(argc, argv, "cf");
/* Set input filename and number */
filename = argv[optind];
{
archive_handle_t *archive_handle;
char *cpio_filename = NULL;
- unsigned long opt;
+ unsigned opt;
/* Initialise */
archive_handle = init_handle();
archive_handle->seek = seek_by_char;
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
- opt = bb_getopt_ulflags(argc, argv, "ituvF:dm", &cpio_filename);
+ opt = getopt32(argc, argv, "ituvF:dm", &cpio_filename);
/* One of either extract or test options must be given */
if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
archive_handle_t *ar_archive;
archive_handle_t *tar_archive;
llist_t *control_tar_llist = NULL;
- unsigned long opt;
+ unsigned opt;
char *extract_dir = NULL;
short argcount = 1;
llist_add_to(&control_tar_llist, "control.tar.bz2");
#endif
- bb_opt_complementally = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
- opt = bb_getopt_ulflags(argc, argv, "cefXx");
+ opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
+ opt = getopt32(argc, argv, "cefXx");
if (opt & DPKG_DEB_OPT_CONTENTS) {
tar_archive->action_header = header_verbose_list;
{
USE_DESKTOP(long long) int status;
int exitcode = 0;
- unsigned long opt;
+ unsigned opt;
- opt = bb_getopt_ulflags(argc, argv, "cftdv");
+ opt = getopt32(argc, argv, "cftdv");
/* if called as zcat */
if (strcmp(bb_applet_name, "zcat") == 0) {
opt |= GUNZIP_OPT_STDOUT;
OPT_force = 0x2,
};
- unsigned long opt;
+ unsigned opt;
int result;
int inFileNum;
int outFileNum;
struct stat statBuf;
char *delFileName;
- opt = bb_getopt_ulflags(argc, argv, "cf123456789qv" USE_GUNZIP("d"));
+ opt = getopt32(argc, argv, "cf123456789qv" USE_GUNZIP("d"));
//if (opt & 0x1) // -c
//if (opt & 0x2) // -f
/* Ignore 1-9 (compression level) options */
//if (opt & 0x800) // -q
//if (opt & 0x1000) // -v
if (ENABLE_GUNZIP && (opt & 0x2000)) { // -d
- /* FIXME: bb_getopt_ulflags should not depend on optind */
+ /* FIXME: getopt32 should not depend on optind */
optind = 1;
return gunzip_main(argc, argv);
}
archive_handle_t *tar_handle;
char *base_dir = NULL;
const char *tar_filename = "-";
- unsigned long opt;
+ unsigned opt;
llist_t *excludes = NULL;
/* Initialise default values */
tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS | ARCHIVE_PRESERVE_DATE | ARCHIVE_EXTRACT_UNCONDITIONAL;
/* Prepend '-' to the first argument if required */
- bb_opt_complementally = ENABLE_FEATURE_TAR_CREATE ?
+ opt_complementary = ENABLE_FEATURE_TAR_CREATE ?
"--:X::T::\n::c:t:x:?:c--tx:t--cx:x--ct" :
"--:X::T::\n::t:x:?:t--x:x--t";
if (ENABLE_FEATURE_TAR_LONG_OPTIONS)
- bb_applet_long_options = tar_long_options;
- opt = bb_getopt_ulflags(argc, argv, tar_options,
+ applet_long_options = tar_long_options;
+ opt = getopt32(argc, argv, tar_options,
&base_dir, /* Change to dir <optarg> */
&tar_filename /* archive filename */
#ifdef CONFIG_FEATURE_TAR_FROM
int status = EXIT_SUCCESS;
unsigned long flags;
- flags = bb_getopt_ulflags(argc, argv, "cf");
+ flags = getopt32(argc, argv, "cf");
while (optind < argc) {
char *compressed_file = argv[optind++];
{
USE_DESKTOP(long long) int status;
char *filename;
- unsigned long opt;
+ unsigned opt;
int src_fd, dst_fd;
- opt = bb_getopt_ulflags(argc, argv, "c");
+ opt = getopt32(argc, argv, "c");
/* Set input filename and number */
filename = argv[optind];
const char *device = CURRENT_TTY;
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
- bb_applet_long_options = setconsole_long_options;
+ applet_long_options = setconsole_long_options;
#endif
- flags = bb_getopt_ulflags(argc, argv, "r");
+ flags = getopt32(argc, argv, "r");
if (argc - optind > 1)
bb_show_usage();
setlocale(LC_TIME, "");
#endif
- flags = bb_getopt_ulflags(argc, argv, "jy");
+ flags = getopt32(argc, argv, "jy");
julian = flags & 1;
FILE *f;
int retval = EXIT_SUCCESS;
- bb_getopt_ulflags(argc, argv, "u");
+ getopt32(argc, argv, "u");
argv += optind;
if (!*argv) {
int retval = EXIT_SUCCESS, fd;
unsigned long flags;
- flags = bb_getopt_ulflags(argc, argv, "etv");
+ flags = getopt32(argc, argv, "etv");
#define CATV_OPT_e (1<<0)
#define CATV_OPT_t (1<<1)
#define CATV_OPT_v (1<<2)
int recursiveFlag;
int retval = EXIT_SUCCESS;
- recursiveFlag = bb_getopt_ulflags(argc, argv, "R");
+ recursiveFlag = getopt32(argc, argv, "R");
if (argc - optind < 2) {
bb_show_usage();
int retval = EXIT_SUCCESS;
char *groupName;
- flags = bb_getopt_ulflags(argc, argv, "Rh");
+ flags = getopt32(argc, argv, "Rh");
if (flags & FLAG_h) chown_func = lchown;
xfunc_error_retval = 2; /* 1 is returned if files are different. */
- opt = bb_getopt_ulflags(argc, argv, opt_chars);
+ opt = getopt32(argc, argv, opt_chars);
if (((opt & (CMP_OPT_s|CMP_OPT_l)) == (CMP_OPT_s|CMP_OPT_l))
|| (((unsigned int)(--argc - optind)) > 1))
{
unsigned long flags;
- flags = bb_getopt_ulflags(argc, argv, "123");
+ flags = getopt32(argc, argv, "123");
if (optind + 2 != argc)
bb_show_usage();
int flags;
int status = 0;
- flags = bb_getopt_ulflags(argc, argv, "pdRfiarPHL");
+ flags = getopt32(argc, argv, "pdRfiarPHL");
if (flags & 32) {
flags |= (FILEUTILS_PRESERVE_STATUS | FILEUTILS_RECUR | FILEUTILS_DEREFERENCE);
#include "busybox.h"
/* option vars */
-static const char *const optstring = "b:c:f:d:sn";
-
+static const char optstring[] = "b:c:f:d:sn";
#define CUT_OPT_BYTE_FLGS (1<<0)
#define CUT_OPT_CHAR_FLGS (1<<1)
#define CUT_OPT_FIELDS_FLGS (1<<2)
#define CUT_OPT_DELIM_FLGS (1<<3)
#define CUT_OPT_SUPPRESS_FLGS (1<<4)
-static unsigned long opt;
+static unsigned opt;
static char delim = '\t'; /* delimiter, default is tab */
{
char *sopt, *ltok;
- bb_opt_complementally = "b--bcf:c--bcf:f--bcf";
- opt =
- bb_getopt_ulflags(argc, argv, optstring, &sopt, &sopt, &sopt, <ok);
+ opt_complementary = "b--bcf:c--bcf:f--bcf";
+ opt = getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, <ok);
if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
bb_error_msg_and_die
("expected a list of bytes, characters, or fields");
{
time_t tm;
struct tm tm_time;
- unsigned long opt;
+ unsigned opt;
int ifmt = -1;
char *date_str = NULL;
char *date_fmt = NULL;
char *isofmt_arg;
char *hintfmt_arg;
- bb_opt_complementally = "?:d--s:s--d"
+ opt_complementary = "?:d--s:s--d"
USE_FEATURE_DATE_ISOFMT(":R--I:I--R");
- opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:"
+ opt = getopt32(argc, argv, "Rs:ud:r:"
USE_FEATURE_DATE_ISOFMT("I::D:"),
&date_str, &date_str, &filename
USE_FEATURE_DATE_ISOFMT(, &isofmt_arg, &hintfmt_arg));
unsigned long df_disp_hr = KILOBYTE;
#endif
int status = EXIT_SUCCESS;
- unsigned long opt;
+ unsigned opt;
FILE *mount_table;
struct mntent *mount_entry;
struct statfs s;
const char *disp_units_hdr = hdr_1k;
#ifdef CONFIG_FEATURE_HUMAN_READABLE
- bb_opt_complementally = "h-km:k-hm:m-hk";
- opt = bb_getopt_ulflags(argc, argv, "hmk");
+ opt_complementary = "h-km:k-hm:m-hk";
+ opt = getopt32(argc, argv, "hmk");
if(opt & 1) {
df_disp_hr = 0;
disp_units_hdr = " Size";
disp_units_hdr = "1M-blocks";
}
#else
- opt = bb_getopt_ulflags(argc, argv, "k");
+ opt = getopt32(argc, argv, "k");
#endif
bb_printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n",
char *U_opt;
llist_t *L_arg = NULL;
- bb_opt_complementally = "L::";
+ opt_complementary = "L::";
cmd_flags =
- bb_getopt_ulflags(argc, argv, "abdiL:NqrsS:tTU:wu", &L_arg, &start,
+ getopt32(argc, argv, "abdiL:NqrsS:tTU:wu", &L_arg, &start,
&U_opt);
if (cmd_flags & FLAG_L) {
ConvType = CT_UNIX2DOS; /*1 */
}
/* -u and -d are mutally exclusive */
- bb_opt_complementally = "?:u--d:d--u";
+ opt_complementary = "?:u--d:d--u";
/* process parameters */
/* -u convert to unix */
/* -d convert to dos */
- o = bb_getopt_ulflags(argc, argv, "du");
+ o = getopt32(argc, argv, "du");
/* Do the conversion requested by an argument else do the default
* conversion depending on our name. */
int slink_depth_save;
int print_final_total;
char *smax_print_depth;
- unsigned long opt;
+ unsigned opt;
#ifdef CONFIG_FEATURE_DU_DEFUALT_BLOCKSIZE_1K
if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */
* ignore -a. This is consistent with -s being equivalent to -d 0.
*/
#ifdef CONFIG_FEATURE_HUMAN_READABLE
- bb_opt_complementally = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
- opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
+ opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
+ opt = getopt32(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
if((opt & (1 << 9))) {
/* -h opt */
disp_hr = 0;
disp_hr = KILOBYTE;
}
#else
- bb_opt_complementally = "H-L:L-H:s-d:d-s";
- opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth);
+ opt_complementary = "H-L:L-H:s-d:d-s";
+ opt = getopt32(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth);
#if !defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
if((opt & (1 << 2))) {
/* -k opt */
static char *cleanenv[1] = { NULL };
char **ep;
- unsigned long opt;
+ unsigned opt;
llist_t *unset_env = NULL;
extern char **environ;
- bb_opt_complementally = "u::";
+ opt_complementary = "u::";
#if ENABLE_FEATURE_ENV_LONG_OPTIONS
- bb_applet_long_options = env_long_options;
+ applet_long_options = env_long_options;
#endif
- opt = bb_getopt_ulflags(argc, argv, "+iu:", &unset_env);
+ opt = getopt32(argc, argv, "+iu:", &unset_env);
argv += optind;
if (*argv && (argv[0][0] == '-') && !argv[0][1]) {
}
}
- flags = bb_getopt_ulflags(argc, argv, "bsw:", &w_opt);
+ flags = getopt32(argc, argv, "bsw:", &w_opt);
if (flags & FLAG_WIDTH)
width = bb_xgetlarg(w_opt, 10, 1, 10000);
}
#endif
- /* No size benefit in converting this to bb_getopt_ulflags */
+ /* No size benefit in converting this to getopt32 */
while ((opt = getopt(argc, argv, head_opts)) > 0) {
switch (opt) {
#if ENABLE_FEATURE_FANCY_HEAD
/* Don't allow -n -r -nr -ug -rug -nug -rnug */
/* Don't allow more than one username */
- bb_opt_complementally = "?1:?:u--g:g--u:r?ug:n?ug";
- flags = bb_getopt_ulflags(argc, argv, "rnug");
+ opt_complementary = "?1:?:u--g:g--u:r?ug:n?ug";
+ flags = getopt32(argc, argv, "rnug");
/* This values could be overwritten later */
uid = geteuid();
int ret = EXIT_SUCCESS, flags, i, isdir;
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
- bb_applet_long_options = install_long_options;
+ applet_long_options = install_long_options;
#endif
- bb_opt_complementally = "?:s--d:d--s";
+ opt_complementary = "?:s--d:d--s";
/* -c exists for backwards compatibility, its needed */
- flags = bb_getopt_ulflags(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str); /* 'a' must be 2nd */
+ flags = getopt32(argc, argv, "cdpsg:m:o:", &gid_str, &mode_str, &uid_str); /* 'a' must be 2nd */
/* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */
if (flags & INSTALL_OPT_PRESERVE_TIME) {
mode_t mode = 0666;
char *smode = NULL;
- bb_getopt_ulflags(argc, argv, "m:", &smode);
+ getopt32(argc, argv, "m:", &smode);
if(smode) {
if (bb_parse_mode(smode, &mode))
umask(0);
struct stat statbuf;
int (*link_func)(const char *, const char *);
- flag = bb_getopt_ulflags(argc, argv, "sfnbS:", &suffix);
+ flag = getopt32(argc, argv, "sfnbS:", &suffix);
if (argc == optind) {
bb_show_usage();
struct dnode **dnp;
struct dnode *dn;
struct dnode *cur;
- long opt;
+ unsigned opt;
int nfiles = 0;
int dnfiles;
int dndirs;
#endif
#ifdef CONFIG_FEATURE_LS_COLOR
- bb_applet_long_options = ls_color_opt;
+ applet_long_options = ls_color_opt;
#endif
/* process options */
#ifdef CONFIG_FEATURE_AUTOWIDTH
- opt = bb_getopt_ulflags(argc, argv, ls_options, &tabstops_str, &terminal_width_str
+ opt = getopt32(argc, argv, ls_options, &tabstops_str, &terminal_width_str
#ifdef CONFIG_FEATURE_LS_COLOR
, &color_opt
#endif
terminal_width = atoi(terminal_width_str);
}
#else
- opt = bb_getopt_ulflags(argc, argv, ls_options
+ opt = getopt32(argc, argv, ls_options
#ifdef CONFIG_FEATURE_LS_COLOR
, &color_opt
#endif
: HASH_SHA1;
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK)
- flags = bb_getopt_ulflags(argc, argv, "scw");
+ flags = getopt32(argc, argv, "scw");
else optind = 1;
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK && !(flags & FLAG_CHECK)) {
mode_t mode = (mode_t)(-1);
int status = EXIT_SUCCESS;
int flags = 0;
- unsigned long opt;
+ unsigned opt;
char *smode;
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
- bb_applet_long_options = mkdir_long_options;
+ applet_long_options = mkdir_long_options;
#endif
- opt = bb_getopt_ulflags(argc, argv, "m:p", &smode);
+ opt = getopt32(argc, argv, "m:p", &smode);
if(opt & 1) {
mode = 0777;
if (!bb_parse_mode (smode, &mode)) {
int status = 0;
#if ENABLE_FEATURE_MV_LONG_OPTIONS
- bb_applet_long_options = mv_long_options;
+ applet_long_options = mv_long_options;
#endif
- bb_opt_complementally = "f-i:i-f";
- flags = bb_getopt_ulflags(argc, argv, "fi");
+ opt_complementary = "f-i:i-f";
+ flags = getopt32(argc, argv, "fi");
if (optind + 2 > argc) {
bb_show_usage();
}
{
int status = 0;
int flags = 0;
- unsigned long opt;
+ unsigned opt;
- bb_opt_complementally = "f-i:i-f";
- opt = bb_getopt_ulflags(argc, argv, "fiRr");
+ opt_complementary = "f-i:i-f";
+ opt = getopt32(argc, argv, "fiRr");
if(opt & 1)
flags |= FILEUTILS_FORCE;
if(opt & 2)
int do_dot;
char *path;
- flags = bb_getopt_ulflags(argc, argv, "p");
+ flags = getopt32(argc, argv, "p");
argv += optind;
int ok = 1;
int (*statfunc)(char const *, char const *) = do_stat;
- flags = bb_getopt_ulflags(argc, argv, "ftL"
+ flags = getopt32(argc, argv, "ftL"
USE_FEATURE_STAT_FORMAT("c:", &format)
);
int (*sum_func)(const char *, int) = bsd_sum_file;
/* give the bsd func priority over sysv func */
- flags = bb_getopt_ulflags(argc, argv, "sr");
+ flags = getopt32(argc, argv, "sr");
if (flags & 1)
sum_func = sysv_sum_file;
if (flags & 2)
int c;
#endif
- flags = bb_getopt_ulflags(argc, argv, "ia"); /* 'a' must be 2nd */
+ flags = getopt32(argc, argv, "ia"); /* 'a' must be 2nd */
mode += (flags & 2); /* Since 'a' is the 2nd option... */
int flags;
int status = EXIT_SUCCESS;
- flags = bb_getopt_ulflags(argc, argv, "c");
+ flags = getopt32(argc, argv, "c");
argv += optind;
xfunc_error_retval = 2; /* SUSv3 requires > 1 for error. */
- silent = bb_getopt_ulflags(argc, argv, "s");
+ silent = getopt32(argc, argv, "s");
/* gnu tty outputs a warning that it is ignoring all args. */
bb_warn_ignoring_args(argc - optind);
const unsigned short int *delta;
char toprint;
- toprint = bb_getopt_ulflags(argc, argv, options);
+ toprint = getopt32(argc, argv, options);
if (argc != optind) {
bb_show_usage();
char *outname = NULL;
char *line;
- bb_getopt_ulflags(argc, argv, "o:", &outname);
+ getopt32(argc, argv, "o:", &outname);
if (optind == argc) {
src_stream = stdin;
RESERVE_CONFIG_BUFFER(dst_buf, DST_BUF_SIZE + 1);
tbl = bb_uuenc_tbl_std;
- if (bb_getopt_ulflags(argc, argv, "m") & 1) {
+ if (getopt32(argc, argv, "m") & 1) {
tbl = bb_uuenc_tbl_base64;
}
char in_word;
unsigned print_type;
- print_type = bb_getopt_ulflags(argc, argv, "lwcL");
+ print_type = getopt32(argc, argv, "lwcL");
if (print_type == 0) {
print_type = (1 << WC_LINES) | (1 << WC_WORDS) | (1 << WC_CHARS);
int mktemp_main(int argc, char **argv)
{
- unsigned long flags = bb_getopt_ulflags(argc, argv, "dq");
+ unsigned long flags = getopt32(argc, argv, "dq");
if (optind + 1 != argc)
bb_show_usage();
int readlink_main(int argc, char **argv)
{
char *buf;
- unsigned long opt = ENABLE_FEATURE_READLINK_FOLLOW ?
- bb_getopt_ulflags(argc, argv, "f") : 0;
+ unsigned opt = ENABLE_FEATURE_READLINK_FOLLOW ?
+ getopt32(argc, argv, "f") : 0;
if (argc != (ENABLE_FEATURE_READLINK_FOLLOW ? optind + 1 : 2))
bb_show_usage();
int start_stop_daemon_main(int argc, char **argv)
{
- unsigned long opt;
+ unsigned opt;
char *signame = NULL;
char *startas = NULL;
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
// int retries = -1;
#endif
#if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS
- bb_applet_long_options = ssd_long_options;
+ applet_long_options = ssd_long_options;
#endif
/* Check required one context option was given */
- bb_opt_complementally = "K:S:?:K--S:S--K:m?p:K?xpun:S?xa";
- opt = bb_getopt_ulflags(argc, argv, "KSbqm"
+ opt_complementary = "K:S:?:K--S:S--K:m?p:K?xpun:S?xa";
+ opt = getopt32(argc, argv, "KSbqm"
// USE_FEATURE_START_STOP_DAEMON_FANCY("ovR:")
USE_FEATURE_START_STOP_DAEMON_FANCY("ov")
"a:n:s:u:c:x:p:"
have to test the return value (xmalloc(), xstrdup(), etc), wrapped versions
of open(), close(), read(), and write() that test for their own failures
and/or retry automatically, linked list management functions (llist.c),
-command line argument parsing (getopt_ulflags.c), and a whole lot more.</p>
+command line argument parsing (getopt32.c), and a whole lot more.</p>
<hr />
<p>
{
int i;
- flags = bb_getopt_ulflags(argc, argv, "Radlv");
+ flags = getopt32(argc, argv, "Radlv");
if (optind > argc - 1)
lsattr_args(".");
int awk_main(int argc, char **argv)
{
- unsigned long opt;
+ unsigned opt;
char *opt_F, *opt_v, *opt_W;
char *s, *s1;
int i, j, c, flen;
free(s);
}
- opt = bb_getopt_ulflags(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &programname, &opt_W);
+ opt = getopt32(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &programname, &opt_W);
if (opt & 0x1) setvar_s(V[FS], opt_F); // -F
if (opt & 0x2) if (!is_assignment(opt_v)) bb_show_usage(); // -v
if (opt & 0x4) { // -f
{
char *p, *i;
- ret = bb_getopt_ulflags(argc, argv, "p:i:", &p, &i);
+ ret = getopt32(argc, argv, "p:i:", &p, &i);
if (ret & 1)
patch_level = bb_xgetlarg(p, 10, -1, USHRT_MAX);
if (ret & 2) {
int sed_main(int argc, char **argv)
{
- unsigned long opt;
+ unsigned opt;
llist_t *opt_e, *opt_f;
int status = EXIT_SUCCESS;
/* do normal option parsing */
opt_e = opt_f = NULL;
- bb_opt_complementally = "e::f::"; /* can occur multiple times */
- opt = bb_getopt_ulflags(argc, argv, "irne:f:", &opt_e, &opt_f);
+ opt_complementary = "e::f::"; /* can occur multiple times */
+ opt = getopt32(argc, argv, "irne:f:", &opt_e, &opt_f);
if (opt & 0x1) { // -i
bbg.in_place++;
atexit(cleanup_outname);
if (opt & 0x2) bbg.regex_type|=REG_EXTENDED; // -r
if (opt & 0x4) bbg.be_quiet++; // -n
if (opt & 0x8) { // -e
- /* getopt_ulflags reverses order of arguments, handle it */
+ /* getopt32 reverses order of arguments, handle it */
add_cmds_link(opt_e);
}
if (opt & 0x10) { // -f
- /* getopt_ulflags reverses order of arguments, handle it */
+ /* getopt32 reverses order of arguments, handle it */
add_files_link(opt_f);
}
/* if we didn't get a pattern from -e or -f, use argv[optind] */
/* options */
-static unsigned long opt;
+static unsigned opt;
#define GREP_OPTS "lnqvscFiHhe:f:Lo"
#define GREP_OPT_l (1<<0)
#define PRINT_FILES_WITH_MATCHES (opt & GREP_OPT_l)
char *slines_before;
char *Copt;
- bb_opt_complementally = "H-h:e::f::C-AB";
- opt = bb_getopt_ulflags(argc, argv,
+ opt_complementary = "H-h:e::f::C-AB";
+ opt = getopt32(argc, argv,
GREP_OPTS GREP_OPT_CONTEXT OPT_EGREP,
&pattern_head, &fopt,
&slines_after, &slines_before, &Copt);
before_buf = (char **)xzalloc(lines_before * sizeof(char *));
#else
/* with auto sanity checks */
- bb_opt_complementally = "H-h:e::f::c-n:q-n:l-n";
- opt = bb_getopt_ulflags(argc, argv, GREP_OPTS OPT_EGREP,
+ opt_complementary = "H-h:e::f::c-n:q-n:l-n";
+ opt = getopt32(argc, argv, GREP_OPTS OPT_EGREP,
&pattern_head, &fopt);
#endif
invert_search = (opt & GREP_OPT_v) != 0; /* 0 | 1 */
size_t n_chars = 0;
long orig_arg_max;
const char *eof_str = "_";
- unsigned long opt;
+ unsigned opt;
size_t n_max_chars;
#if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM
xlist_t* (*read_args)(xlist_t*, const char*, size_t, char*) = process_stdin;
#define read_args process_stdin
#endif
- opt = bb_getopt_ulflags(argc, argv, OPTION_STR, &max_args, &max_chars, &eof_str);
+ opt = getopt32(argc, argv, OPTION_STR, &max_args, &max_chars, &eof_str);
if (opt & OPT_ZEROTERM)
USE_FEATURE_XARGS_SUPPORT_ZERO_TERM(read_args = process0_stdin);
extern off_t fdlength(int fd);
#define BB_GETOPT_ERROR 0x80000000UL
-extern const char *bb_opt_complementally;
-extern const struct option *bb_applet_long_options;
-extern unsigned long bb_getopt_ulflags(int argc, char **argv, const char *applet_opts, ...);
+extern const char *opt_complementary;
+extern const struct option *applet_long_options;
+extern uint32_t getopt32(int argc, char **argv, const char *applet_opts, ...);
extern int bb_vfprintf(FILE * __restrict stream, const char * __restrict format,
va_list arg) __attribute__ ((format (printf, 2, 0)));
#ifndef BUILD_INDIVIDUAL
extern struct BB_applet *find_applet_by_name(const char *name);
-void run_applet_by_name(const char *name, int argc, char **argv);
+extern void run_applet_by_name(const char *name, int argc, char **argv);
#endif
/* dmalloc will redefine these to it's own implementation. It is safe
for(which=0;delay[which]!=*bb_applet_name;which++);
/* Parse and handle arguments */
- flags = bb_getopt_ulflags(argc, argv, "d:nf", &delay);
+ flags = getopt32(argc, argv, "d:nf", &delay);
if (flags&1) sleep(atoi(delay));
if (!(flags&2)) sync();
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c \
xgethostbyname.c xgethostbyname2.c xreadlink.c xgetlarg.c \
fclose_nonstdin.c fflush_stdout_and_exit.c \
- getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
+ getopt32.c default_error_retval.c wfopen_input.c speed_table.c \
perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \
warn_ignoring_args.c concat_subpath_file.c vfork_daemon_rexec.c \
bb_do_delay.c
--- /dev/null
+/* vi: set sw=4 ts=4: */
+/*
+ * universal getopt32 implementation for busybox
+ *
+ * Copyright (C) 2003-2005 Vladimir Oleynik <dzo@simtreas.ru>
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ */
+
+#include "libbb.h"
+#include <getopt.h>
+
+/* Documentation
+
+uint32_t
+getopt32(int argc, char **argv, const char *applet_opts, ...)
+
+ The command line options must be declared in const char
+ *applet_opts as a string of chars, for example:
+
+ flags = getopt32(argc, argv, "rnug");
+
+ If one of the given options is found, a flag value is added to
+ the return value (an unsigned long).
+
+ The flag value is determined by the position of the char in
+ applet_opts string. For example, in the above case:
+
+ flags = getopt32(argc, argv, "rnug");
+
+ "r" will add 1 (bit 0)
+ "n" will add 2 (bit 1)
+ "u will add 4 (bit 2)
+ "g" will add 8 (bit 3)
+
+ and so on. You can also look at the return value as a bit
+ field and each option sets one bit.
+
+ On exit, global variable optind is set so that if you
+ will do argc -= optind; argv += optind; then
+ argc will be equal to number of remaining non-option
+ arguments, first one would be in argv[0], next in argv[1] and so on
+ (options and their parameters will be moved into argv[]
+ positions prior to argv[optind]).
+
+ ":" If one of the options requires an argument, then add a ":"
+ after the char in applet_opts and provide a pointer to store
+ the argument. For example:
+
+ char *pointer_to_arg_for_a;
+ char *pointer_to_arg_for_b;
+ char *pointer_to_arg_for_c;
+ char *pointer_to_arg_for_d;
+
+ flags = getopt32(argc, argv, "a:b:c:d:",
+ &pointer_to_arg_for_a, &pointer_to_arg_for_b,
+ &pointer_to_arg_for_c, &pointer_to_arg_for_d);
+
+ The type of the pointer (char* or llist_t*) may be controlled
+ by the "::" special separator that is set in the external string
+ opt_complementary (see below for more info).
+
+ "::" If option can have an *optional* argument, then add a "::"
+ after its char in applet_opts and provide a pointer to store
+ the argument. Note that optional arguments _must_
+ immediately follow the option: -oparam, not -o param.
+
+ "+" If the first character in the applet_opts string is a plus,
+ then option processing will stop as soon as a non-option is
+ encountered in the argv array. Useful for applets like env
+ which should not process arguments to subprograms:
+ env -i ls -d /
+ Here we want env to process just the '-i', not the '-d'.
+
+const struct option *applet_long_options
+
+ This struct allows you to define long options. The syntax for
+ declaring the array is just like that of getopt's longopts.
+ (see getopt(3))
+
+ static const struct option applet_long_options[] = {
+ //name,has_arg,flag,val
+ { "verbose", 0, 0, 'v' },
+ { 0, 0, 0, 0 }
+ };
+ applet_long_options = applet_long_options;
+
+ The last member of struct option (val) typically is set to
+ matching short option from applet_opts. If there is no matching
+ char in applet_opts, then:
+ - return bit have next position after short options
+ - if has_arg is not "no_argument", use ptr for arg also
+ - opt_complementary affects it too
+
+ Note: a good applet will make long options configurable via the
+ config process and not a required feature. The current standard
+ is to name the config option CONFIG_FEATURE_<applet>_LONG_OPTIONS.
+
+const char *opt_complementary
+
+ ":" The colon (":") is used to separate groups of two or more chars
+ and/or groups of chars and special characters (stating some
+ conditions to be checked).
+
+ "abc" If groups of two or more chars are specified, the first char
+ is the main option and the other chars are secondary options.
+ Their flags will be turned on if the main option is found even
+ if they are not specifed on the command line. For example:
+
+ opt_complementary = "abc";
+ flags = getopt32(argc, argv, "abcd")
+
+ If getopt() finds "-a" on the command line, then
+ getopt32's return value will be as if "-a -b -c" were
+ found.
+
+ "ww" Adjacent double options have a counter associated which indicates
+ the number of occurences of the option.
+ For example the ps applet needs:
+ if w is given once, GNU ps sets the width to 132,
+ if w is given more than once, it is "unlimited"
+
+ int w_counter = 0;
+ opt_complementary = "ww";
+ getopt32(argc, argv, "w", &w_counter);
+ if (w_counter)
+ width = (w_counter == 1) ? 132 : INT_MAX;
+ else
+ get_terminal_width(...&width...);
+
+ w_counter is a pointer to an integer. It has to be passed to
+ getopt32() after all other option argument sinks.
+
+ For example: accept multiple -v to indicate the level of verbosity
+ and for each -b optarg, add optarg to my_b. Finally, if b is given,
+ turn off c and vice versa:
+
+ llist_t *my_b = NULL;
+ int verbose_level = 0;
+ opt_complementary = "vv:b::b-c:c-b";
+ f = getopt32(argc, argv, "vb:c", &my_b, &verbose_level);
+ if (f & 2) // -c after -b unsets -b flag
+ while (my_b) { dosomething_with(my_b->data); my_b = my_b->link; }
+ if (my_b) // but llist is stored if -b is specified
+ free_llist(my_b);
+ if (verbose_level) bb_printf("verbose level is %d\n", verbose_level);
+
+Special characters:
+
+ "-" A dash between two options causes the second of the two
+ to be unset (and ignored) if it is given on the command line.
+
+ [FIXME: what if they are the same? like "x-x"? Is it ever useful?]
+
+ For example:
+ The du applet has the options "-s" and "-d depth". If
+ getopt32 finds -s, then -d is unset or if it finds -d
+ then -s is unset. (Note: busybox implements the GNU
+ "--max-depth" option as "-d".) To obtain this behavior, you
+ set opt_complementary = "s-d:d-s". Only one flag value is
+ added to getopt32's return value depending on the
+ position of the options on the command line. If one of the
+ two options requires an argument pointer (":" in applet_opts
+ as in "d:") optarg is set accordingly.
+
+ char *smax_print_depth;
+
+ opt_complementary = "s-d:d-s:x-x";
+ opt = getopt32(argc, argv, "sd:x", &smax_print_depth);
+
+ if (opt & 2)
+ max_print_depth = atoi(smax_print_depth);
+ if (opt & 4)
+ printf("Detected odd -x usage\n");
+
+ "-" A dash as the first char in a opt_complementary group forces
+ all arguments to be treated as options, even if they have
+ no leading dashes. Next char in this case can't be a digit (0-9),
+ use ':' or end of line. For example:
+
+ opt_complementary = "-:w-x:x-w";
+ getopt32(argc, argv, "wx");
+
+ Allows any arguments to be given without a dash (./program w x)
+ as well as with a dash (./program -x).
+
+ "-N" A dash as the first char in a opt_complementary group followed
+ by a single digit (0-9) means that at least N non-option
+ arguments must be present on the command line
+
+ "V-" An option with dash before colon or end-of-line results in
+ bb_show_usage being called if this option is encountered.
+ This is typically used to implement "print verbose usage message
+ and exit" option.
+
+ "--" A double dash between two options, or between an option and a group
+ of options, means that they are mutually exclusive. Unlike
+ the "-" case above, an error will be forced if the options
+ are used together.
+
+ For example:
+ The cut applet must have only one type of list specified, so
+ -b, -c and -f are mutally exclusive and should raise an error
+ if specified together. In this case you must set
+ opt_complementary = "b--cf:c--bf:f--bc". If two of the
+ mutually exclusive options are found, getopt32's
+ return value will have the error flag set (BB_GETOPT_ERROR) so
+ that we can check for it:
+
+ if (flags & BB_GETOPT_ERROR)
+ bb_show_usage();
+
+ "x--x" Variation of the above, it means that -x option should occur
+ at most once.
+
+ "?" A "?" as the first char in a opt_complementary group means:
+ if BB_GETOPT_ERROR is detected, don't return, call bb_show_usage
+ and exit instead. Next char after '?' can't be a digit.
+
+ "?N" A "?" as the first char in a opt_complementary group followed
+ by a single digit (0-9) means that at most N arguments must be present
+ on the command line.
+
+ "::" A double colon after a char in opt_complementary means that the
+ option can occur multiple times. Each occurrence will be saved as
+ a llist_t element instead of char*.
+
+ For example:
+ The grep applet can have one or more "-e pattern" arguments.
+ In this case you should use getopt32() as follows:
+
+ llist_t *patterns = NULL;
+
+ (this pointer must be initializated to NULL if the list is empty
+ as required by *llist_add_to(llist_t *old_head, char *new_item).)
+
+ opt_complementary = "e::";
+
+ getopt32(argc, argv, "e:", &patterns);
+ $ grep -e user -e root /etc/passwd
+ root:x:0:0:root:/root:/bin/bash
+ user:x:500:500::/home/user:/bin/bash
+
+ "--" A double dash at the beginning of opt_complementary means the
+ argv[1] string should always be treated as options, even if it isn't
+ prefixed with a "-". This is useful for special syntax in applets
+ such as "ar" and "tar":
+ tar xvf foo.tar
+
+ "?" An "?" between an option and a group of options means that
+ at least one of them is required to occur if the first option
+ occurs in preceding command line arguments.
+
+ For example from "id" applet:
+
+ // Don't allow -n -r -rn -ug -rug -nug -rnug
+ opt_complementary = "r?ug:n?ug:?u--g:g--u";
+ flags = getopt32(argc, argv, "rnug");
+
+ This example allowed only:
+ $ id; id -u; id -g; id -ru; id -nu; id -rg; id -ng; id -rnu; id -rng
+
+ "X" A opt_complementary group with just a single letter means
+ that this option is required. If more than one such group exists,
+ at least one option is required to occur (not all of them).
+ For example from "start-stop-daemon" applet:
+
+ // Don't allow -KS -SK, but -S or -K is required
+ opt_complementary = "K:S:?K--S:S--K";
+ flags = getopt32(argc, argv, "KS...);
+
+
+ Don't forget to use ':'. For example, "?322-22-23X-x-a"
+ is interpreted as "?3:22:-2:2-2:2-3Xa:2--x" -
+ max 3 args; count uses of '-2'; min 2 args; if there is
+ a '-2' option then unset '-3', '-X' and '-a'; if there is
+ a '-2' and after it a '-x' then error out.
+*/
+
+/* Code here assumes that 'unsigned' is at least 32 bits wide */
+
+const char *opt_complementary;
+
+typedef struct {
+ int opt;
+ int list_flg;
+ unsigned switch_on;
+ unsigned switch_off;
+ unsigned incongruously;
+ unsigned requires;
+ void **optarg; /* char **optarg or llist_t **optarg */
+ int *counter;
+} t_complementary;
+
+/* You can set applet_long_options for parse called long options */
+#if ENABLE_GETOPT_LONG
+static const struct option bb_default_long_options[] = {
+/* { "help", 0, NULL, '?' }, */
+ { 0, 0, 0, 0 }
+};
+
+const struct option *applet_long_options = bb_default_long_options;
+#endif
+
+uint32_t
+getopt32(int argc, char **argv, const char *applet_opts, ...)
+{
+ unsigned flags = 0;
+ unsigned requires = 0;
+ t_complementary complementary[sizeof(flags) * 8 + 1];
+ int c;
+ const unsigned char *s;
+ t_complementary *on_off;
+ va_list p;
+#if ENABLE_GETOPT_LONG
+ const struct option *l_o;
+#endif
+ unsigned trigger;
+ char **pargv = NULL;
+ int min_arg = 0;
+ int max_arg = -1;
+
+#define SHOW_USAGE_IF_ERROR 1
+#define ALL_ARGV_IS_OPTS 2
+#define FIRST_ARGV_IS_OPT 4
+#define FREE_FIRST_ARGV_IS_OPT 8
+ int spec_flgs = 0;
+
+ va_start(p, applet_opts);
+
+ c = 0;
+ on_off = complementary;
+ memset(on_off, 0, sizeof(complementary));
+
+ /* skip GNU extension */
+ s = (const unsigned char *)applet_opts;
+ if (*s == '+' || *s == '-')
+ s++;
+ for (; *s; s++) {
+ if (c >= (int)(sizeof(flags)*8))
+ break;
+ on_off->opt = *s;
+ on_off->switch_on = (1 << c);
+ if (s[1] == ':') {
+ on_off->optarg = va_arg(p, void **);
+ do
+ s++;
+ while (s[1] == ':');
+ }
+ on_off++;
+ c++;
+ }
+
+#if ENABLE_GETOPT_LONG
+ for (l_o = applet_long_options; l_o->name; l_o++) {
+ if (l_o->flag)
+ continue;
+ for (on_off = complementary; on_off->opt != 0; on_off++)
+ if (on_off->opt == l_o->val)
+ break;
+ if (on_off->opt == 0) {
+ if (c >= (int)(sizeof(flags)*8))
+ break;
+ on_off->opt = l_o->val;
+ on_off->switch_on = (1 << c);
+ if (l_o->has_arg != no_argument)
+ on_off->optarg = va_arg(p, void **);
+ c++;
+ }
+ }
+#endif /* ENABLE_GETOPT_LONG */
+ for (s = (const unsigned char *)opt_complementary; s && *s; s++) {
+ t_complementary *pair;
+ unsigned *pair_switch;
+
+ if (*s == ':')
+ continue;
+ c = s[1];
+ if (*s == '?') {
+ if (c < '0' || c > '9') {
+ spec_flgs |= SHOW_USAGE_IF_ERROR;
+ } else {
+ max_arg = c - '0';
+ s++;
+ }
+ continue;
+ }
+ if (*s == '-') {
+ if (c < '0' || c > '9') {
+ if (c == '-') {
+ spec_flgs |= FIRST_ARGV_IS_OPT;
+ s++;
+ } else
+ spec_flgs |= ALL_ARGV_IS_OPTS;
+ } else {
+ min_arg = c - '0';
+ s++;
+ }
+ continue;
+ }
+ for (on_off = complementary; on_off->opt; on_off++)
+ if (on_off->opt == *s)
+ break;
+ if (c == ':' && s[2] == ':') {
+ on_off->list_flg++;
+ continue;
+ }
+ if (c == ':' || c == '\0') {
+ requires |= on_off->switch_on;
+ continue;
+ }
+ if (c == '-' && (s[2] == ':' || s[2] == '\0')) {
+ flags |= on_off->switch_on;
+ on_off->incongruously |= on_off->switch_on;
+ s++;
+ continue;
+ }
+ if (c == *s) {
+ on_off->counter = va_arg(p, int *);
+ s++;
+ }
+ pair = on_off;
+ pair_switch = &(pair->switch_on);
+ for (s++; *s && *s != ':'; s++) {
+ if (*s == '?') {
+ pair_switch = &(pair->requires);
+ } else if (*s == '-') {
+ if (pair_switch == &(pair->switch_off))
+ pair_switch = &(pair->incongruously);
+ else
+ pair_switch = &(pair->switch_off);
+ } else {
+ for (on_off = complementary; on_off->opt; on_off++)
+ if (on_off->opt == *s) {
+ *pair_switch |= on_off->switch_on;
+ break;
+ }
+ }
+ }
+ s--;
+ }
+ va_end (p);
+
+#if ENABLE_AR || ENABLE_TAR
+ if (spec_flgs & FIRST_ARGV_IS_OPT) {
+ if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') {
+ argv[1] = xasprintf("-%s", argv[1]);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ spec_flgs |= FREE_FIRST_ARGV_IS_OPT;
+ }
+ }
+#endif
+#if ENABLE_GETOPT_LONG
+ while ((c = getopt_long(argc, argv, applet_opts,
+ applet_long_options, NULL)) >= 0) {
+#else
+ while ((c = getopt(argc, argv, applet_opts)) >= 0) {
+#endif /* ENABLE_GETOPT_LONG */
+loop_arg_is_opt:
+ for (on_off = complementary; on_off->opt != c; on_off++) {
+ /* c==0 if long opt have non NULL flag */
+ if (on_off->opt == 0 && c != 0)
+ bb_show_usage();
+ }
+ if (flags & on_off->incongruously) {
+ if ((spec_flgs & SHOW_USAGE_IF_ERROR))
+ bb_show_usage();
+ flags |= BB_GETOPT_ERROR;
+ }
+ trigger = on_off->switch_on & on_off->switch_off;
+ flags &= ~(on_off->switch_off ^ trigger);
+ flags |= on_off->switch_on ^ trigger;
+ flags ^= trigger;
+ if (on_off->counter)
+ (*(on_off->counter))++;
+ if (on_off->list_flg) {
+ llist_add_to((llist_t **)(on_off->optarg), optarg);
+ } else if (on_off->optarg) {
+ *(char **)(on_off->optarg) = optarg;
+ }
+ if (pargv != NULL)
+ break;
+ }
+
+ if (spec_flgs & ALL_ARGV_IS_OPTS) {
+ /* process argv is option, for example "ps" applet */
+ if (pargv == NULL)
+ pargv = argv + optind;
+ while (*pargv) {
+ c = **pargv;
+ if (c == '\0') {
+ pargv++;
+ } else {
+ (*pargv)++;
+ goto loop_arg_is_opt;
+ }
+ }
+ }
+
+#if (ENABLE_AR || ENABLE_TAR) && ENABLE_FEATURE_CLEAN_UP
+ if (spec_flgs & FREE_FIRST_ARGV_IS_OPT)
+ free(argv[1]);
+#endif
+ /* check depending requires for given options */
+ for (on_off = complementary; on_off->opt; on_off++) {
+ if (on_off->requires && (flags & on_off->switch_on) &&
+ (flags & on_off->requires) == 0)
+ bb_show_usage();
+ }
+ if (requires && (flags & requires) == 0)
+ bb_show_usage();
+ argc -= optind;
+ if (argc < min_arg || (max_arg >= 0 && argc > max_arg))
+ bb_show_usage();
+ return flags;
+}
+++ /dev/null
-/* vi: set sw=4 ts=4: */
-/*
- * universal getopt_ulflags implementation for busybox
- *
- * Copyright (C) 2003-2005 Vladimir Oleynik <dzo@simtreas.ru>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include "libbb.h"
-#include <getopt.h>
-
-/* Documentation
-
-unsigned long
-bb_getopt_ulflags(int argc, char **argv, const char *applet_opts, ...)
-
- The command line options must be declared in const char
- *applet_opts as a string of chars, for example:
-
- flags = bb_getopt_ulflags(argc, argv, "rnug");
-
- If one of the given options is found, a flag value is added to
- the return value (an unsigned long).
-
- The flag value is determined by the position of the char in
- applet_opts string. For example, in the above case:
-
- flags = bb_getopt_ulflags(argc, argv, "rnug");
-
- "r" will add 1 (bit 0)
- "n" will add 2 (bit 1)
- "u will add 4 (bit 2)
- "g" will add 8 (bit 3)
-
- and so on. You can also look at the return value as a bit
- field and each option sets one bit.
-
- On exit, global variable optind is set so that if you
- will do argc -= optind; argv += optind; then
- argc will be equal to number of remaining non-option
- arguments, first one would be in argv[0], next in argv[1] and so on
- (options and their parameters will be moved into argv[]
- positions prior to argv[optind]).
-
- ":" If one of the options requires an argument, then add a ":"
- after the char in applet_opts and provide a pointer to store
- the argument. For example:
-
- char *pointer_to_arg_for_a;
- char *pointer_to_arg_for_b;
- char *pointer_to_arg_for_c;
- char *pointer_to_arg_for_d;
-
- flags = bb_getopt_ulflags(argc, argv, "a:b:c:d:",
- &pointer_to_arg_for_a, &pointer_to_arg_for_b,
- &pointer_to_arg_for_c, &pointer_to_arg_for_d);
-
- The type of the pointer (char* or llist_t*) may be controlled
- by the "::" special separator that is set in the external string
- bb_opt_complementally (see below for more info).
-
- "::" If option can have an *optional* argument, then add a "::"
- after its char in applet_opts and provide a pointer to store
- the argument. Note that optional arguments _must_
- immediately follow the option: -oparam, not -o param.
-
- "+" If the first character in the applet_opts string is a plus,
- then option processing will stop as soon as a non-option is
- encountered in the argv array. Useful for applets like env
- which should not process arguments to subprograms:
- env -i ls -d /
- Here we want env to process just the '-i', not the '-d'.
-
-const struct option *bb_applet_long_options
-
- This struct allows you to define long options. The syntax for
- declaring the array is just like that of getopt's longopts.
- (see getopt(3))
-
- static const struct option applet_long_options[] = {
- //name,has_arg,flag,val
- { "verbose", 0, 0, 'v' },
- { 0, 0, 0, 0 }
- };
- bb_applet_long_options = applet_long_options;
-
- The last member of struct option (val) typically is set to
- matching short option from applet_opts. If there is no matching
- char in applet_opts, then:
- - return bit have next position after short options
- - if has_arg is not "no_argument", use ptr for arg also
- - bb_opt_complementally affects it too
-
- Note: a good applet will make long options configurable via the
- config process and not a required feature. The current standard
- is to name the config option CONFIG_FEATURE_<applet>_LONG_OPTIONS.
-
-const char *bb_opt_complementally
-
- this should be bb_opt_complementary, but we'll just keep it as
- bb_opt_complementally due to the Russian origins
-
- ":" The colon (":") is used to separate groups of two or more chars
- and/or groups of chars and special characters (stating some
- conditions to be checked).
-
- "abc" If groups of two or more chars are specified, the first char
- is the main option and the other chars are secondary options.
- Their flags will be turned on if the main option is found even
- if they are not specifed on the command line. For example:
-
- bb_opt_complementally = "abc";
- flags = bb_getopt_ulflags(argc, argv, "abcd")
-
- If getopt() finds "-a" on the command line, then
- bb_getopt_ulflags's return value will be as if "-a -b -c" were
- found.
-
- "ww" Adjacent double options have a counter associated which indicates
- the number of occurences of the option.
- For example the ps applet needs:
- if w is given once, GNU ps sets the width to 132,
- if w is given more than once, it is "unlimited"
-
- int w_counter = 0;
- bb_opt_complementally = "ww";
- bb_getopt_ulflags(argc, argv, "w", &w_counter);
- if (w_counter)
- width = (w_counter == 1) ? 132 : INT_MAX;
- else
- get_terminal_width(...&width...);
-
- w_counter is a pointer to an integer. It has to be passed to
- bb_getopt_ulflags() after all other option argument sinks.
-
- For example: accept multiple -v to indicate the level of verbosity
- and for each -b optarg, add optarg to my_b. Finally, if b is given,
- turn off c and vice versa:
-
- llist_t *my_b = NULL;
- int verbose_level = 0;
- bb_opt_complementally = "vv:b::b-c:c-b";
- f = bb_getopt_ulflags(argc, argv, "vb:c", &my_b, &verbose_level);
- if (f & 2) // -c after -b unsets -b flag
- while (my_b) { dosomething_with(my_b->data); my_b = my_b->link; }
- if (my_b) // but llist is stored if -b is specified
- free_llist(my_b);
- if (verbose_level) bb_printf("verbose level is %d\n", verbose_level);
-
-Special characters:
-
- "-" A dash between two options causes the second of the two
- to be unset (and ignored) if it is given on the command line.
-
- [FIXME: what if they are the same? like "x-x"? Is it ever useful?]
-
- For example:
- The du applet has the options "-s" and "-d depth". If
- bb_getopt_ulflags finds -s, then -d is unset or if it finds -d
- then -s is unset. (Note: busybox implements the GNU
- "--max-depth" option as "-d".) To obtain this behavior, you
- set bb_opt_complementally = "s-d:d-s". Only one flag value is
- added to bb_getopt_ulflags's return value depending on the
- position of the options on the command line. If one of the
- two options requires an argument pointer (":" in applet_opts
- as in "d:") optarg is set accordingly.
-
- char *smax_print_depth;
-
- bb_opt_complementally = "s-d:d-s:x-x";
- opt = bb_getopt_ulflags(argc, argv, "sd:x", &smax_print_depth);
-
- if (opt & 2)
- max_print_depth = atoi(smax_print_depth);
- if (opt & 4)
- printf("Detected odd -x usage\n");
-
- "-" A dash as the first char in a bb_opt_complementally group forces
- all arguments to be treated as options, even if they have
- no leading dashes. Next char in this case can't be a digit (0-9),
- use ':' or end of line. For example:
-
- bb_opt_complementally = "-:w-x:x-w";
- bb_getopt_ulflags(argc, argv, "wx");
-
- Allows any arguments to be given without a dash (./program w x)
- as well as with a dash (./program -x).
-
- "-N" A dash as the first char in a bb_opt_complementally group followed
- by a single digit (0-9) means that at least N non-option
- arguments must be present on the command line
-
- "V-" An option with dash before colon or end-of-line results in
- bb_show_usage being called if this option is encountered.
- This is typically used to implement "print verbose usage message
- and exit" option.
-
- "--" A double dash between two options, or between an option and a group
- of options, means that they are mutually exclusive. Unlike
- the "-" case above, an error will be forced if the options
- are used together.
-
- For example:
- The cut applet must have only one type of list specified, so
- -b, -c and -f are mutally exclusive and should raise an error
- if specified together. In this case you must set
- bb_opt_complementally = "b--cf:c--bf:f--bc". If two of the
- mutually exclusive options are found, bb_getopt_ulflags's
- return value will have the error flag set (BB_GETOPT_ERROR) so
- that we can check for it:
-
- if (flags & BB_GETOPT_ERROR)
- bb_show_usage();
-
- "x--x" Variation of the above, it means that -x option should occur
- at most once.
-
- "?" A "?" as the first char in a bb_opt_complementally group means:
- if BB_GETOPT_ERROR is detected, don't return, call bb_show_usage
- and exit instead. Next char after '?' can't be a digit.
-
- "?N" A "?" as the first char in a bb_opt_complementally group followed
- by a single digit (0-9) means that at most N arguments must be present
- on the command line.
-
- "::" A double colon after a char in bb_opt_complementally means that the
- option can occur multiple times. Each occurrence will be saved as
- a llist_t element instead of char*.
-
- For example:
- The grep applet can have one or more "-e pattern" arguments.
- In this case you should use bb_getopt_ulflags() as follows:
-
- llist_t *patterns = NULL;
-
- (this pointer must be initializated to NULL if the list is empty
- as required by *llist_add_to(llist_t *old_head, char *new_item).)
-
- bb_opt_complementally = "e::";
-
- bb_getopt_ulflags(argc, argv, "e:", &patterns);
- $ grep -e user -e root /etc/passwd
- root:x:0:0:root:/root:/bin/bash
- user:x:500:500::/home/user:/bin/bash
-
- "--" A double dash at the beginning of bb_opt_complementally means the
- argv[1] string should always be treated as options, even if it isn't
- prefixed with a "-". This is useful for special syntax in applets
- such as "ar" and "tar":
- tar xvf foo.tar
-
- "?" An "?" between an option and a group of options means that
- at least one of them is required to occur if the first option
- occurs in preceding command line arguments.
-
- For example from "id" applet:
-
- // Don't allow -n -r -rn -ug -rug -nug -rnug
- bb_opt_complementally = "r?ug:n?ug:?u--g:g--u";
- flags = bb_getopt_ulflags(argc, argv, "rnug");
-
- This example allowed only:
- $ id; id -u; id -g; id -ru; id -nu; id -rg; id -ng; id -rnu; id -rng
-
- "X" A bb_opt_complementally group with just a single letter means
- that this option is required. If more than one such group exists,
- at least one option is required to occur (not all of them).
- For example from "start-stop-daemon" applet:
-
- // Don't allow -KS -SK, but -S or -K is required
- bb_opt_complementally = "K:S:?K--S:S--K";
- flags = bb_getopt_ulflags(argc, argv, "KS...);
-
-
- Don't forget to use ':'. For example, "?322-22-23X-x-a"
- is interpreted as "?3:22:-2:2-2:2-3Xa:2--x" -
- max 3 args; count uses of '-2'; min 2 args; if there is
- a '-2' option then unset '-3', '-X' and '-a'; if there is
- a '-2' and after it a '-x' then error out.
-*/
-
-/* this should be bb_opt_complementary, but we'll just keep it as
- bb_opt_complementally due to the Russian origins */
-const char *bb_opt_complementally;
-
-typedef struct {
- int opt;
- int list_flg;
- unsigned long switch_on;
- unsigned long switch_off;
- unsigned long incongruously;
- unsigned long requires;
- void **optarg; /* char **optarg or llist_t **optarg */
- int *counter;
-} t_complementally;
-
-/* You can set bb_applet_long_options for parse called long options */
-#if ENABLE_GETOPT_LONG
-static const struct option bb_default_long_options[] = {
-/* { "help", 0, NULL, '?' }, */
- { 0, 0, 0, 0 }
-};
-
-const struct option *bb_applet_long_options = bb_default_long_options;
-#endif
-
-unsigned long
-bb_getopt_ulflags(int argc, char **argv, const char *applet_opts, ...)
-{
- unsigned long flags = 0;
- unsigned long requires = 0;
- t_complementally complementally[sizeof(flags) * 8 + 1];
- int c;
- const unsigned char *s;
- t_complementally *on_off;
- va_list p;
-#if ENABLE_GETOPT_LONG
- const struct option *l_o;
-#endif
- unsigned long trigger;
- char **pargv = NULL;
- int min_arg = 0;
- int max_arg = -1;
-
-#define SHOW_USAGE_IF_ERROR 1
-#define ALL_ARGV_IS_OPTS 2
-#define FIRST_ARGV_IS_OPT 4
-#define FREE_FIRST_ARGV_IS_OPT 8
- int spec_flgs = 0;
-
- va_start(p, applet_opts);
-
- c = 0;
- on_off = complementally;
- memset(on_off, 0, sizeof(complementally));
-
- /* skip GNU extension */
- s = (const unsigned char *)applet_opts;
- if (*s == '+' || *s == '-')
- s++;
- for (; *s; s++) {
- if (c >= (int)(sizeof(flags)*8))
- break;
- on_off->opt = *s;
- on_off->switch_on = (1 << c);
- if (s[1] == ':') {
- on_off->optarg = va_arg(p, void **);
- do
- s++;
- while (s[1] == ':');
- }
- on_off++;
- c++;
- }
-
-#if ENABLE_GETOPT_LONG
- for (l_o = bb_applet_long_options; l_o->name; l_o++) {
- if (l_o->flag)
- continue;
- for (on_off = complementally; on_off->opt != 0; on_off++)
- if (on_off->opt == l_o->val)
- break;
- if (on_off->opt == 0) {
- if (c >= (int)(sizeof(flags)*8))
- break;
- on_off->opt = l_o->val;
- on_off->switch_on = (1 << c);
- if (l_o->has_arg != no_argument)
- on_off->optarg = va_arg(p, void **);
- c++;
- }
- }
-#endif /* ENABLE_GETOPT_LONG */
- for (s = (const unsigned char *)bb_opt_complementally; s && *s; s++) {
- t_complementally *pair;
- unsigned long *pair_switch;
-
- if (*s == ':')
- continue;
- c = s[1];
- if (*s == '?') {
- if (c < '0' || c > '9') {
- spec_flgs |= SHOW_USAGE_IF_ERROR;
- } else {
- max_arg = c - '0';
- s++;
- }
- continue;
- }
- if (*s == '-') {
- if (c < '0' || c > '9') {
- if (c == '-') {
- spec_flgs |= FIRST_ARGV_IS_OPT;
- s++;
- } else
- spec_flgs |= ALL_ARGV_IS_OPTS;
- } else {
- min_arg = c - '0';
- s++;
- }
- continue;
- }
- for (on_off = complementally; on_off->opt; on_off++)
- if (on_off->opt == *s)
- break;
- if (c == ':' && s[2] == ':') {
- on_off->list_flg++;
- continue;
- }
- if (c == ':' || c == '\0') {
- requires |= on_off->switch_on;
- continue;
- }
- if (c == '-' && (s[2] == ':' || s[2] == '\0')) {
- flags |= on_off->switch_on;
- on_off->incongruously |= on_off->switch_on;
- s++;
- continue;
- }
- if (c == *s) {
- on_off->counter = va_arg(p, int *);
- s++;
- }
- pair = on_off;
- pair_switch = &(pair->switch_on);
- for (s++; *s && *s != ':'; s++) {
- if (*s == '?') {
- pair_switch = &(pair->requires);
- } else if (*s == '-') {
- if (pair_switch == &(pair->switch_off))
- pair_switch = &(pair->incongruously);
- else
- pair_switch = &(pair->switch_off);
- } else {
- for (on_off = complementally; on_off->opt; on_off++)
- if (on_off->opt == *s) {
- *pair_switch |= on_off->switch_on;
- break;
- }
- }
- }
- s--;
- }
- va_end (p);
-
-#if ENABLE_AR || ENABLE_TAR
- if (spec_flgs & FIRST_ARGV_IS_OPT) {
- if (argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') {
- argv[1] = xasprintf("-%s", argv[1]);
- if (ENABLE_FEATURE_CLEAN_UP)
- spec_flgs |= FREE_FIRST_ARGV_IS_OPT;
- }
- }
-#endif
-#if ENABLE_GETOPT_LONG
- while ((c = getopt_long(argc, argv, applet_opts,
- bb_applet_long_options, NULL)) >= 0) {
-#else
- while ((c = getopt(argc, argv, applet_opts)) >= 0) {
-#endif /* ENABLE_GETOPT_LONG */
-loop_arg_is_opt:
- for (on_off = complementally; on_off->opt != c; on_off++) {
- /* c==0 if long opt have non NULL flag */
- if (on_off->opt == 0 && c != 0)
- bb_show_usage();
- }
- if (flags & on_off->incongruously) {
- if ((spec_flgs & SHOW_USAGE_IF_ERROR))
- bb_show_usage();
- flags |= BB_GETOPT_ERROR;
- }
- trigger = on_off->switch_on & on_off->switch_off;
- flags &= ~(on_off->switch_off ^ trigger);
- flags |= on_off->switch_on ^ trigger;
- flags ^= trigger;
- if (on_off->counter)
- (*(on_off->counter))++;
- if (on_off->list_flg) {
- llist_add_to((llist_t **)(on_off->optarg), optarg);
- } else if (on_off->optarg) {
- *(char **)(on_off->optarg) = optarg;
- }
- if (pargv != NULL)
- break;
- }
-
- if (spec_flgs & ALL_ARGV_IS_OPTS) {
- /* process argv is option, for example "ps" applet */
- if (pargv == NULL)
- pargv = argv + optind;
- while (*pargv) {
- c = **pargv;
- if (c == '\0') {
- pargv++;
- } else {
- (*pargv)++;
- goto loop_arg_is_opt;
- }
- }
- }
-
-#if (ENABLE_AR || ENABLE_TAR) && ENABLE_FEATURE_CLEAN_UP
- if (spec_flgs & FREE_FIRST_ARGV_IS_OPT)
- free(argv[1]);
-#endif
- /* check depending requires for given options */
- for (on_off = complementally; on_off->opt; on_off++) {
- if (on_off->requires && (flags & on_off->switch_on) &&
- (flags & on_off->requires) == 0)
- bb_show_usage();
- }
- if (requires && (flags & requires) == 0)
- bb_show_usage();
- argc -= optind;
- if (argc < min_arg || (max_arg >= 0 && argc > max_arg))
- bb_show_usage();
- return flags;
-}
gid_t gid = 0;
/* check for min, max and missing args and exit on error */
- bb_opt_complementally = "-1:?2:?";
+ opt_complementary = "-1:?2:?";
- if (bb_getopt_ulflags(argc, argv, "g:", &group)) {
+ if (getopt32(argc, argv, "g:", &group)) {
gid = bb_xgetlarg(group, 10, 0, LONG_MAX);
}
/* move past the commandline options */
pw.pw_dir = NULL;
/* check for min, max and missing args and exit on error */
- bb_opt_complementally = "-1:?1:?";
- flags = bb_getopt_ulflags(argc, argv, "h:g:s:G:DSH", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup);
+ opt_complementary = "-1:?1:?";
+ flags = getopt32(argc, argv, "h:g:s:G:DSH", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup);
/* got root? */
if(geteuid()) {
{
char *ts;
- op->flags = bb_getopt_ulflags(argc, argv, opt_string,
+ op->flags = getopt32(argc, argv, opt_string,
&(op->initstring), &fakehost, &(op->issue),
&(op->login), &ts);
if(op->flags & F_INITSTRING) {
char username[USERNAME_SIZE];
const char *tmp;
int amroot;
- unsigned long opt;
+ unsigned opt;
int count = 0;
struct passwd *pw;
char *opt_host = NULL;
signal(SIGALRM, alarm_handler);
alarm(TIMEOUT);
- opt = bb_getopt_ulflags(argc, argv, "f:h:p", &opt_user, &opt_host);
+ opt = getopt32(argc, argv, "f:h:p", &opt_user, &opt_host);
if (opt & LOGIN_OPT_f) {
if (!amroot)
bb_error_msg_and_die("-f is for root only");
OPT_delete = 0x8, /* -d - delete password */
OPT_lud = 0xe,
};
- unsigned long opt;
+ unsigned opt;
char *opt_a;
int amroot;
char *cp;
amroot = (getuid() == 0);
openlog("passwd", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH);
- opt = bb_getopt_ulflags(argc, argv, "a:lud", &opt_a);
+ opt = getopt32(argc, argv, "a:lud", &opt_a);
argc -= optind;
argv += optind;
if (opt & OPT_algo) algo = get_algo(opt_a); // -a
const char *tty;
char *old_user;
- flags = bb_getopt_ulflags(argc, argv, "mplc:s:", &opt_command, &opt_shell);
+ flags = getopt32(argc, argv, "mplc:s:", &opt_command, &opt_shell);
#define SU_OPT_mp (3)
#define SU_OPT_l (4)
logmode = LOGMODE_BOTH;
openlog(bb_applet_name, 0, LOG_AUTH);
- if (bb_getopt_ulflags (argc, argv, "t:", &timeout_arg)) {
+ if (getopt32 (argc, argv, "t:", &timeout_arg)) {
if (safe_strtoi(timeout_arg, &timeout)) {
timeout = 0;
}
bb_show_usage();
}
- o_lock_all = bb_getopt_ulflags (argc, argv, "a");
+ o_lock_all = getopt32 (argc, argv, "a");
if((pw = getpwuid(getuid())) == NULL) {
bb_error_msg_and_die("Unknown uid %d", getuid());
enum {
OPT_quiet = 0x1
};
- unsigned long opt;
+ unsigned opt;
char *opt_o, *opt_f, *opt_p, *opt_t;
struct timex txc;
int i, ret, sep;
const char *descript;
txc.modes=0;
- opt = bb_getopt_ulflags(argc, argv, "qo:f:p:t:",
+ opt = getopt32(argc, argv, "qo:f:p:t:",
&opt_o, &opt_f, &opt_p, &opt_t);
//if (opt & 0x1) // -q
if (opt & 0x2) { // -o
int crond_main(int ac, char **av)
{
- unsigned long opt;
+ unsigned opt;
char *lopt, *Lopt, *copt;
#if ENABLE_DEBUG_CROND_OPTION
char *dopt;
- bb_opt_complementally = "f-b:b-f:S-L:L-S:d-l";
+ opt_complementary = "f-b:b-f:S-L:L-S:d-l";
#else
- bb_opt_complementally = "f-b:b-f:S-L:L-S";
+ opt_complementary = "f-b:b-f:S-L:L-S";
#endif
opterr = 0; /* disable getopt 'errors' message. */
- opt = bb_getopt_ulflags(ac, av, "l:L:fbSc:"
+ opt = getopt32(ac, av, "l:L:fbSc:"
#if ENABLE_DEBUG_CROND_OPTION
"d:"
#endif
struct mntent *m;
int dev;
- /*bb_opt_complementally = "t--T:T--t";*/
- flags = bb_getopt_ulflags(argc, argv, "tT");
+ /*opt_complementary = "t--T:T--t";*/
+ flags = getopt32(argc, argv, "tT");
device = argv[optind] ? : DEFAULT_CDROM;
m = find_mount_point(device, bb_path_mtab_file);
/* check if we recognise the device type */
printf("\n");
- if(!(val[GEN_CONFIG] & NOT_ATA))
+ if (!(val[GEN_CONFIG] & NOT_ATA))
{
dev = ATA_DEV;
printf("ATA device, with ");
}
- else if(val[GEN_CONFIG]==CFA_SUPPORT_VAL)
+ else if (val[GEN_CONFIG]==CFA_SUPPORT_VAL)
{
dev = ATA_DEV;
like_std = 4;
printf("CompactFlash ATA device, with ");
}
- else if(!(val[GEN_CONFIG] & NOT_ATAPI))
+ else if (!(val[GEN_CONFIG] & NOT_ATAPI))
{
dev = ATAPI_DEV;
eqpt = (val[GEN_CONFIG] & EQPT_TYPE) >> SHIFT_EQPT;
(val[CONFIG]==PWRD_NID_VAL) || (val[CONFIG]==PWRD_ID_VAL) )
{
like_std = 5;
- if((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL))
+ if ((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==STBY_ID_VAL))
printf("powers-up in standby; SET FEATURES subcmd spins-up.\n");
- if(((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE))
+ if (((val[CONFIG]==STBY_NID_VAL) || (val[CONFIG]==PWRD_NID_VAL)) && (val[GEN_CONFIG] & INCOMPLETE))
printf("\n\tWARNING: ID response incomplete.\n\tFollowing data may be incorrect.\n\n");
}
{
if (val[MINOR] && (val[MINOR] <= MINOR_MAX))
{
- if(like_std < 3) like_std = 3;
+ if (like_std < 3) like_std = 3;
std = actual_ver[val[MINOR]];
- if(std) printf("\n\tUsed: %s ",minor_str[val[MINOR]]);
+ if (std) printf("\n\tUsed: %s ",minor_str[val[MINOR]]);
}
/* looks like when they up-issue the std, they obsolete one;
like_std = ii;
kk = like_std >4 ? like_std-4: 0;
}
- if(min_std > ii) min_std = ii;
+ if (min_std > ii) min_std = ii;
}
jj <<= 1;
}
- if(like_std < 3) like_std = 3;
+ if (like_std < 3) like_std = 3;
}
/* Figure out what standard the device is using if it hasn't told
* us. If we know the std, check if the device is using any of
* the words from the next level up. It happens.
*/
- if(like_std < std) like_std = std;
+ if (like_std < std) like_std = std;
if (((std == 5) || (!std && (like_std < 6))) &&
((((val[CMDS_SUPP_1] & VALID) == VALID_VAL) &&
jj = val[CDR_MAJOR] >> 1;
for (ii = 1; ii <15; ii++)
{
- if(jj & 0x0001) printf("-%u ", ii);
+ if (jj & 0x0001) printf("-%u ", ii);
jj >>= 1;
}
}
jj = val[GEN_CONFIG] >> 1;
for (ii = 1; ii < 15; ii++)
{
- if(jj & 0x0001) printf("\t%s\n",ata1_cfg_str[ii]);
+ if (jj & 0x0001) printf("\t%s\n",ata1_cfg_str[ii]);
jj >>=1;
}
}
}
}
/* Removable Media Status Notification feature set */
- if((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP)
+ if ((val[RM_STAT] & RM_STAT_BITS) == RM_STAT_SUP)
printf("\t%s supported\n", cmd_feat_str[27]);
}
printf("\n");
- if(!(id->field_valid&1))
+ if (!(id->field_valid&1))
printf(" (maybe):");
printf(" CurCHS=%u/%u/%u, CurSects=%lu, LBA=%s",id->cur_cyls, id->cur_heads,
static void print_flag(unsigned long flag, char *s, unsigned long value)
{
- if(flag)
+ if (flag)
printf(" setting %s to %ld\n", s, value);
}
}
/*------- getopt short options --------*/
-static const char hdparm_options[]= "gfu::n::p:r::m::c::k::a::B:tTh"\
+static const char hdparm_options[] = "gfu::n::p:r::m::c::k::a::B:tTh"
USE_FEATURE_HDPARM_GET_IDENTITY("iI")
USE_FEATURE_HDPARM_HDIO_GETSET_DMA("d::")
#ifdef HDIO_DRIVE_CMD
- "S:D:P:X:K:A:L:W:CyYzZ"
+ "S:D:P:X:K:A:L:W:CyYzZ"
#endif
USE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF("U:")
#ifdef HDIO_GET_QDMA
#ifdef HDIO_SET_QDMA
- "Q:"
+ "Q:"
#else
- "Q"
+ "Q"
#endif
#endif
USE_FEATURE_HDPARM_HDIO_DRIVE_RESET("w")
#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
if (c == 'R') {
parse_opts(NULL, &scan_hwif, &hwif_data, 0, INT_MAX);
- hwif_ctrl = bb_xgetlarg((argv[optind]) ? argv[optind] : "", 10, 0, INT_MAX);
- hwif_irq = bb_xgetlarg((argv[optind+1]) ? argv[optind+1] : "", 10, 0, INT_MAX);
+ hwif_ctrl = bb_xgetlarg((argv[optind]) ? argv[optind] : "", 10, 0, INT_MAX);
+ hwif_irq = bb_xgetlarg((argv[optind+1]) ? argv[optind+1] : "", 10, 0, INT_MAX);
/* Move past the 2 additional arguments */
argv += 2;
argc -= 2;
#endif
}
/* When no flags are given (flagcount = 0), -acdgkmnru is assumed. */
- if (!flagcount){
+ if (!flagcount) {
get_mult = get_io32bit = get_unmask = get_keep = get_readonly = get_readahead = get_geom = 1;
USE_FEATURE_HDPARM_HDIO_GETSET_DMA(get_dma = 1);
}
int keypress;
- flags = bb_getopt_ulflags(argc, argv, "EMmN~");
+ flags = getopt32(argc, argv, "EMmN~");
argc -= optind;
argv += optind;
int linenum = 0;
int ret = EXIT_SUCCESS;
- bb_getopt_ulflags(argc, argv, "d:", &line);
+ getopt32(argc, argv, "d:", &line);
if (line)
table = xfopen(line, "r");
int mountpoint_main(int argc, char **argv)
{
- int opt = bb_getopt_ulflags(argc, argv, "qdx");
+ int opt = getopt32(argc, argv, "qdx");
#define OPT_q (1)
#define OPT_d (2)
#define OPT_x (4)
int strings_main(int argc, char **argv)
{
int n, c, i = 0, status = EXIT_SUCCESS;
- unsigned long opt;
+ unsigned opt;
unsigned long count;
FILE *file = stdin;
char *string;
const char *fmt = "%s: ";
char *n_arg = "4";
- opt = bb_getopt_ulflags(argc, argv, "afon:", &n_arg);
+ opt = getopt32(argc, argv, "afon:", &n_arg);
/* -a is our default behaviour */
argc -= optind;
int watchdog_main(int argc, char **argv)
{
- unsigned long opts;
+ unsigned opts;
unsigned long timer_duration = 30; /* Userspace timer duration, in seconds */
char *t_arg;
- opts = bb_getopt_ulflags(argc, argv, "Ft:", &t_arg);
+ opts = getopt32(argc, argv, "Ft:", &t_arg);
if (opts & OPT_TIMER)
timer_duration = bb_xgetlarg(t_arg, 10, 0, INT_MAX);
struct utsname myuname;
/* Parse any options */
- option_mask = bb_getopt_ulflags(argc, argv, OPTION_STR, &opt_o);
+ option_mask = getopt32(argc, argv, OPTION_STR, &opt_o);
if (option_mask & OPT_o) { // -o /* name the output module */
free(m_name);
m_name = xstrdup(opt_o);
int rc = EXIT_SUCCESS;
char *unused;
- bb_opt_complementally = "?V-:q-v:v-q";
- main_opts = bb_getopt_ulflags(argc, argv, "acdklnqrst:vVC:",
+ opt_complementary = "?V-:q-v:v-q";
+ main_opts = getopt32(argc, argv, "acdklnqrst:vVC:",
&unused, &unused);
if((main_opts & (DUMP_CONF_EXIT | LIST_ALL)))
return EXIT_SUCCESS;
unsigned int flags = O_NONBLOCK|O_EXCL;
/* Parse command line. */
- n = bb_getopt_ulflags(argc, argv, "wfa");
+ n = getopt32(argc, argv, "wfa");
if((n & 1)) // --wait
flags &= ~O_NONBLOCK;
if((n & 2)) // --force
xsetuid(getuid());
{
- unsigned long opt;
+ unsigned opt;
char *_count, *_timeout;
/* Dad also sets quit_on_reply.
* Advert also sets unsolicited.
*/
- bb_opt_complementally = "Df:AU";
- opt = bb_getopt_ulflags(argc, argv, "DUAqfbc:w:i:s:",
+ opt_complementary = "Df:AU";
+ opt = getopt32(argc, argv, "DUAqfbc:w:i:s:",
&_count, &_timeout, &device, &source);
cfg |= opt & 0x3f; /* set respective flags */
if (opt & 0x40) /* -c: count */
char *sttl=NULL, *sport=NULL;
if(argc > 1)
- flags = bb_getopt_ulflags(argc, argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport);
+ flags = getopt32(argc, argv, "i:c:t:p:dv", &listen_interface, &fileconf, &sttl, &sport);
if(sttl)
if(!(ttl = atol(sttl)))
bb_show_usage();
struct whereto_t whereto; /* who to wake up */
/* handle misc user options */
- flags = bb_getopt_ulflags(argc, argv, "bi:p:", &ifname, &pass);
+ flags = getopt32(argc, argv, "bi:p:", &ifname, &pass);
if (optind == argc)
bb_show_usage();
if (pass)
FD_SET(0, &G.readfds);
/* handle -b <ip> parameter */
- bb_getopt_ulflags(argc, argv, "b:", &bind_ip_address);
+ getopt32(argc, argv, "b:", &bind_ip_address);
/* handle optional REPLY STRING */
if (optind < argc)
G.identuser = argv[optind];
int ftpgetput_main(int argc, char **argv)
{
/* content-length of the file */
- unsigned long opt;
+ unsigned opt;
char *port = "ftp";
/* socket to ftp server */
* Decipher the command line
*/
if (ENABLE_FEATURE_FTPGETPUT_LONG_OPTIONS)
- bb_applet_long_options = ftpgetput_long_options;
+ applet_long_options = ftpgetput_long_options;
- opt = bb_getopt_ulflags(argc, argv, "cvu:p:P:", &server->user, &server->password, &port);
+ opt = getopt32(argc, argv, "cvu:p:P:", &server->user, &server->password, &port);
/* Process the non-option command line arguments */
if (argc - optind != 3) {
};
char buf[256];
- unsigned long opt;
+ unsigned opt;
char *hostname_str = NULL;
if (argc < 1)
bb_show_usage();
- opt = bb_getopt_ulflags(argc, argv, "dfisF:", &hostname_str);
+ opt = getopt32(argc, argv, "dfisF:", &hostname_str);
/* Output in desired format */
if (opt & OPT_dfis) {
int httpd_main(int argc, char *argv[])
{
- unsigned long opt;
+ unsigned opt;
const char *home_httpd = home;
char *url_for_decode;
USE_FEATURE_HTTPD_ENCODE_URL_STR(const char *url_for_encode;)
config->ContentLength = -1;
- opt = bb_getopt_ulflags(argc, argv, httpd_opts,
+ opt = getopt32(argc, argv, httpd_opts,
&(config->configFile), &url_for_decode, &home_httpd
USE_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode)
USE_FEATURE_HTTPD_BASIC_AUTH(, &(config->realm))
cmds = iface_down;
}
- option_mask = bb_getopt_ulflags(argc, argv, OPTION_STR, &interfaces);
+ option_mask = getopt32(argc, argv, OPTION_STR, &interfaces);
if (argc - optind > 0) {
if (DO_ALL) bb_show_usage();
} else
openlog(bb_applet_name, LOG_PID | LOG_NOWAIT, LOG_DAEMON);
- opt = bb_getopt_ulflags(argc, argv, "R:f", &stoomany);
+ opt = getopt32(argc, argv, "R:f", &stoomany);
if(opt & 1) {
char *e;
char *ipstr;
if (ENABLE_FEATURE_IPCALC_LONG_OPTIONS)
- bb_applet_long_options = long_options;
+ applet_long_options = long_options;
- mode = bb_getopt_ulflags(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs"));
+ mode = getopt32(argc, argv, "mbn" USE_FEATURE_IPCALC_FANCY("phs"));
argc -= optind;
argv += optind;
int if_index = 1;
mactable_t *ch;
- if (1 & bb_getopt_ulflags(argc, argv, "sc:", &fname)) {
+ if (1 & getopt32(argc, argv, "sc:", &fname)) {
openlog(bb_applet_name, 0, LOG_LOCAL0);
logmode = LOGMODE_SYSLOG;
}
#define NETSTAT_CONNECTED 0x01
#define NETSTAT_LISTENING 0x02
#define NETSTAT_NUMERIC 0x04
-/* Must match getopt_ulflags option string */
+/* Must match getopt32 option string */
#define NETSTAT_TCP 0x10
#define NETSTAT_UDP 0x20
#define NETSTAT_RAW 0x40
OPT_extended = 0x4,
OPT_showroute = 0x100,
};
- unsigned long opt;
+ unsigned opt;
#ifdef CONFIG_FEATURE_IPV6
int inet = 1;
int inet6 = 1;
#endif
/* Option string must match NETSTAT_xxx constants */
- opt = bb_getopt_ulflags(argc, argv, "laentuwxr");
+ opt = getopt32(argc, argv, "laentuwxr");
if (opt & 0x1) { // -l
flags &= ~NETSTAT_CONNECTED;
flags |= NETSTAT_LISTENING;
int route_main(int argc, char **argv)
{
- unsigned long opt;
+ unsigned opt;
int what;
char *family;
}
}
- opt = bb_getopt_ulflags(argc, argv, "A:ne", &family);
+ opt = getopt32(argc, argv, "A:ne", &family);
if ((opt & ROUTE_OPT_A) && strcmp(family, "inet")) {
#ifdef CONFIG_FEATURE_IPV6
bb_show_usage();
#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
- if (1 & bb_getopt_ulflags(argc, argv, "al:", &autologin))
+ if (1 & getopt32(argc, argv, "al:", &autologin))
autologin = getenv("USER");
if (optind < argc) {
int
telnetd_main(int argc, char **argv)
{
- unsigned long opt;
+ unsigned opt;
fd_set rdfdset, wrfdset;
int selret;
#ifndef CONFIG_FEATURE_TELNETD_INETD
openlog(bb_applet_name, 0, LOG_USER);
logmode = LOGMODE_SYSLOG;
- opt = bb_getopt_ulflags(argc, argv, "f:l:" USE_FEATURE_TELNETD_INETD("p:b:"),
+ opt = getopt32(argc, argv, "f:l:" USE_FEATURE_TELNETD_INETD("p:b:"),
&issuefile, &loginpath
SKIP_FEATURE_TELNETD_INETD(, &opt_portnbr, &opt_bindaddr));
//if (opt & 1) // -f
#endif
#if defined(CONFIG_FEATURE_TFTP_GET) && defined(CONFIG_FEATURE_TFTP_PUT)
- bb_opt_complementally = GET_COMPL PUT_COMPL ":?g--p:p--g";
+ opt_complementary = GET_COMPL PUT_COMPL ":?g--p:p--g";
#elif defined(CONFIG_FEATURE_TFTP_GET) || defined(CONFIG_FEATURE_TFTP_PUT)
- bb_opt_complementally = GET_COMPL PUT_COMPL;
+ opt_complementary = GET_COMPL PUT_COMPL;
#endif
- cmd = bb_getopt_ulflags(argc, argv, GET PUT "l:r:" BS,
+ cmd = getopt32(argc, argv, GET PUT "l:r:" BS,
&localfile, &remotefile BS_ARG);
cmd &= (tftp_cmd_get | tftp_cmd_put);
opterr = 0;
#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE
- bb_opt_complementally = "x-x:g::";
+ opt_complementary = "x-x:g::";
#else
- bb_opt_complementally = "x-x";
+ opt_complementary = "x-x";
#endif
- op = bb_getopt_ulflags(argc, argv, "FIlnrdvxt:i:m:p:q:s:w:z:f:"
+ op = getopt32(argc, argv, "FIlnrdvxt:i:m:p:q:s:w:z:f:"
#define USAGE_OP_DONT_FRAGMNT (1<<0) /* F */
#define USAGE_OP_USE_ICMP (1<<1) /* I */
#define USAGE_OP_TTL_FLAG (1<<2) /* l */
int wget_main(int argc, char **argv)
{
int n, try=5, status;
- unsigned long opt;
+ unsigned opt;
int port;
char *proxy = 0;
char *dir_prefix=NULL;
/*
* Crack command line.
*/
- bb_opt_complementally = "-1:\203::";
+ opt_complementary = "-1:\203::";
#if ENABLE_FEATURE_WGET_LONG_OPTIONS
- bb_applet_long_options = wget_long_options;
+ applet_long_options = wget_long_options;
#endif
- opt = bb_getopt_ulflags(argc, argv, "cq\213O:\203:P:Y:U:",
+ opt = getopt32(argc, argv, "cq\213O:\203:P:Y:U:",
&fname_out, &headers_llist,
&dir_prefix, &proxy_flag, &user_agent);
if (strcmp(proxy_flag, "off") == 0) {
#define VDBG(fmt,args...) \
do { } while (0)
-static unsigned long opts;
+static unsigned opts;
#define FOREGROUND (opts & 1)
#define QUIT (opts & 2)
// parse commandline: prog [options] ifname script
char *r_opt;
- bb_opt_complementally = "vv:vf"; // -v accumulates and implies -f
- opts = bb_getopt_ulflags(argc, argv, "fqr:v", &r_opt, &verbose);
+ opt_complementary = "vv:vf"; // -v accumulates and implies -f
+ opts = getopt32(argc, argv, "fqr:v", &r_opt, &verbose);
if (!FOREGROUND) {
/* Do it early, before all bb_xx_msg calls */
logmode = LOGMODE_SYSLOG;
unsigned long int opt;
#if ENABLE_FEATURE_PIDOF_OMIT
llist_t *omits = NULL; /* list of pids to omit */
- bb_opt_complementally = _OMIT_COMPL("o::");
+ opt_complementary = _OMIT_COMPL("o::");
#endif
/* do unconditional option parsing */
- opt = bb_getopt_ulflags(argc, argv,
+ opt = getopt32(argc, argv,
_SINGLE_COMPL("s") _OMIT_COMPL("o:")
_OMIT(&omits));
int terminal_width;
int w_count = 0;
- bb_opt_complementally = "-:ww";
+ opt_complementary = "-:ww";
#else
# define terminal_width 79
#endif
#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX
/* handle arguments */
#if ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX
- i = bb_getopt_ulflags(argc, argv, "wc", &w_count);
+ i = getopt32(argc, argv, "wc", &w_count);
#elif ENABLE_FEATURE_PS_WIDE && !ENABLE_SELINUX
- bb_getopt_ulflags(argc, argv, "w", &w_count);
+ getopt32(argc, argv, "w", &w_count);
#else /* !ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX */
- i = bb_getopt_ulflags(argc, argv, "c");
+ i = getopt32(argc, argv, "c");
#endif
#if ENABLE_FEATURE_PS_WIDE
/* if w is given once, GNU ps sets the width to 132,
/* do normal option parsing */
interval = 5;
- bb_opt_complementally = "-";
- option_mask = bb_getopt_ulflags(argc, argv, "d:n:b",
+ opt_complementary = "-";
+ option_mask = getopt32(argc, argv, "d:n:b",
&sinterval, &siterations);
if (option_mask & 0x1) interval = atoi(sinterval); // -d
if (option_mask & 0x2) iterations = atoi(siterations); // -n
{
char *m,*d,*o,*p,*f,*c,*r,*t,*n;
- option_mask = bb_getopt_ulflags(argc, argv, "u:U:e:m:d:o:p:f:c:r:t:/:n:vP012",
+ option_mask = getopt32(argc, argv, "u:U:e:m:d:o:p:f:c:r:t:/:n:vP012",
&set_user,&env_user,&env_dir,
&m,&d,&o,&p,&f,&c,&r,&t,&root,&n);
// if (option_mask & 0x1) // -u
static void softlimit(int argc, char **argv)
{
char *a,*c,*d,*f,*l,*m,*o,*p,*r,*s,*t;
- option_mask = bb_getopt_ulflags(argc, argv, "a:c:d:f:l:m:o:p:r:s:t:",
+ option_mask = getopt32(argc, argv, "a:c:d:f:l:m:o:p:r:s:t:",
&a,&c,&d,&f,&l,&m,&o,&p,&r,&s,&t);
if (option_mask & 0x001) limita = bb_xgetularg10(a); // -a
if (option_mask & 0x002) limitc = bb_xgetularg10(c); // -c
char *command=NULL;
FILE *f;
- bb_getopt_ulflags(argc, argv, "c:", &command);
+ getopt32(argc, argv, "c:", &command);
f = argv[optind] ? xfopen(argv[optind],"r") : NULL;
if (command) handle(command);
int lash_main(int argc_l, char **argv_l)
{
- unsigned long opt;
+ unsigned opt;
FILE *input = stdin;
argc = argc_l;
argv = argv_l;
}
}
- opt = bb_getopt_ulflags(argc_l, argv_l, "+ic:", &local_pending_command);
+ opt = getopt32(argc_l, argv_l, "+ic:", &local_pending_command);
#define LASH_OPT_i (1<<0)
#define LASH_OPT_c (1<<2)
if (opt & LASH_OPT_c) {
{
- unsigned long opt;
+ unsigned opt;
/* do normal option parsing */
- opt = bb_getopt_ulflags(argc, argv, "c:n", &start);
+ opt = getopt32(argc, argv, "c:n", &start);
if (opt & OPT_LEVEL) {
/* Valid levels are between 1 and 8 */
int logger_main(int argc, char **argv)
{
- unsigned long opt;
+ unsigned opt;
char *opt_p, *opt_t;
int pri = LOG_USER | LOG_NOTICE;
int option = 0;
bb_getpwuid(name, geteuid(), sizeof(name));
/* Parse any options */
- opt = bb_getopt_ulflags(argc, argv, "p:st:", &opt_p, &opt_t);
+ opt = getopt32(argc, argv, "p:st:", &opt_p, &opt_t);
if (opt & 0x1) pri = pencode(opt_p); // -p
if (opt & 0x2) option |= LOG_PERROR; // -s
if (opt & 0x4) safe_strncpy(name, opt_t, sizeof(name)); // -t
char *p;
/* do normal option parsing */
- option_mask = bb_getopt_ulflags(argc, argv, OPTION_STR, OPTION_PARAM);
+ option_mask = getopt32(argc, argv, OPTION_STR, OPTION_PARAM);
if (option_mask & OPT_mark) MarkInterval = atoi(opt_m) * 60; // -m
//if (option_mask & OPT_nofork) // -n
//if (option_mask & OPT_outfile) // -O
int dmesg_main(int argc, char *argv[])
{
char *size, *level;
- int flags = bb_getopt_ulflags(argc, argv, "cs:n:", &size, &level);
+ int flags = getopt32(argc, argv, "cs:n:", &size, &level);
if (flags & 4) {
if (klogctl(8, NULL, bb_xgetlarg(level, 10, 0, 10)))
if (argc < 2) {
bb_show_usage();
}
- verify = !bb_getopt_ulflags(argc, argv, "n");
+ verify = !getopt32(argc, argv, "n");
argv += optind;
xstat(*argv, &st);
#define init_longopt() add_longopt(NULL,0)
/* Register a long option. The contents of name is copied. */
-void add_longopt(const char *name,int has_arg)
+void add_longopt(const char *name, int has_arg)
{
if (!name) { /* init */
free(long_options);
int hwclock_main ( int argc, char **argv )
{
- unsigned long opt;
+ unsigned opt;
int utc;
#if ENABLE_FEATURE_HWCLOCK_LONG_OPTIONS
{ "systohc", 0, 0, 'w' },
{ 0, 0, 0, 0 }
};
- bb_applet_long_options = hwclock_long_options;
+ applet_long_options = hwclock_long_options;
#endif
- bb_opt_complementally = "?:r--ws:w--rs:s--wr:l--u:u--l";
- opt = bb_getopt_ulflags(argc, argv, "lursw");
+ opt_complementary = "?:r--ws:w--rs:s--wr:l--u:u--l";
+ opt = getopt32(argc, argv, "lursw");
/* If -u or -l wasn't given check if we are using utc */
if (opt & (HWCLOCK_OPT_UTC | HWCLOCK_OPT_LOCALTIME))
{
int id = 0;
unsigned flags = 0;
- unsigned long opt;
+ unsigned opt;
char *opt_i;
#define flag_print (1<<0)
#define flag_msg (1<<1)
#define flag_sem (1<<2)
#define flag_shm (1<<3)
- opt = bb_getopt_ulflags(argc, argv, "i:aqsmtcplu", &opt_i);
+ opt = getopt32(argc, argv, "i:aqsmtcplu", &opt_i);
if (opt & 0x1) { // -i
id = atoi(opt_i);
flags |= flag_print;
int losetup_main(int argc, char **argv)
{
- unsigned long opt;
+ unsigned opt;
char *opt_o;
int offset = 0;
- opt = bb_getopt_ulflags(argc, argv, "do:", &opt_o);
+ opt = getopt32(argc, argv, "do:", &opt_o);
argc -= optind;
argv += optind;
const char *fstabname;
FILE *fstab;
int i, j, rc = 0;
- unsigned long opt;
+ unsigned opt;
struct mntent mtpair[2], *mtcur = mtpair;
/* parse long options, like --bind and --move. Note that -o option
// Parse remaining options
- opt = bb_getopt_ulflags(argc, argv, "o:t:rwanfvs", &opt_o, &fstype);
+ opt = getopt32(argc, argv, "o:t:rwanfvs", &opt_o, &fstype);
if (opt & 0x1) append_mount_options(&cmdopts, opt_o); // -o
//if (opt & 0x2) // -t
if (opt & 0x4) append_mount_options(&cmdopts, "ro"); // -r
time_t remote_time;
unsigned long flags;
- bb_opt_complementally = "-1";
- flags = bb_getopt_ulflags(argc, argv, "sp");
+ opt_complementary = "-1";
+ flags = getopt32(argc, argv, "sp");
remote_time = askremotedate(argv[optind]);
proFile = defaultpro;
mapFile = defaultmap;
- bb_opt_complementally = "nn:aa:bb:ss:ii:rr:vv";
- bb_getopt_ulflags(argc, argv, "M:m:p:nabsirv",
+ opt_complementary = "nn:aa:bb:ss:ii:rr:vv";
+ getopt32(argc, argv, "M:m:p:nabsirv",
&mult, &mapFile, &proFile,
&optNative, &optAll, &optBins, &optSub,
&optInfo, &optReset, &optVerbose);
if (argc == 1)
bb_show_usage();
- ret = bb_getopt_ulflags(argc, argv, "a");
+ ret = getopt32(argc, argv, "a");
if (ret & DO_ALL)
return do_em_all();
// Parse args (-c console)
- bb_opt_complementally="-2";
- bb_getopt_ulflags(argc,argv,"c:",&console);
+ opt_complementary="-2";
+ getopt32(argc,argv,"c:",&console);
// Change to new root directory and verify it's a different fs.
struct mntent me;
FILE *fp;
int status = EXIT_SUCCESS;
- unsigned long opt;
+ unsigned opt;
struct mtab_list {
char *dir;
char *device;
/* Parse any options */
- opt = bb_getopt_ulflags(argc, argv, OPTION_STRING);
+ opt = getopt32(argc, argv, OPTION_STRING);
argc -= optind;
argv += optind;