getopt_ulflags -> getopt32.
authorDenis Vlasenko <vda.linux@googlemail.com>
Tue, 3 Oct 2006 21:00:06 +0000 (21:00 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Tue, 3 Oct 2006 21:00:06 +0000 (21:00 -0000)
It is impossible to formulate sane ABI based on
size of ulong because it can be 32-bit or 64-bit.
Basically it means that you cannot portably use
more that 32 option chars in one call anyway...
Make it explicit.

121 files changed:
archival/ar.c
archival/bunzip2.c
archival/cpio.c
archival/dpkg_deb.c
archival/gunzip.c
archival/gzip.c
archival/tar.c
archival/uncompress.c
archival/unlzma.c
console-tools/setconsole.c
coreutils/cal.c
coreutils/cat.c
coreutils/catv.c
coreutils/chgrp.c
coreutils/chown.c
coreutils/cmp.c
coreutils/comm.c
coreutils/cp.c
coreutils/cut.c
coreutils/date.c
coreutils/df.c
coreutils/diff.c
coreutils/dos2unix.c
coreutils/du.c
coreutils/env.c
coreutils/fold.c
coreutils/head.c
coreutils/id.c
coreutils/install.c
coreutils/libcoreutils/getopt_mk_fifo_nod.c
coreutils/ln.c
coreutils/ls.c
coreutils/md5_sha1_sum.c
coreutils/mkdir.c
coreutils/mv.c
coreutils/rm.c
coreutils/rmdir.c
coreutils/stat.c
coreutils/sum.c
coreutils/tee.c
coreutils/touch.c
coreutils/tty.c
coreutils/uname.c
coreutils/uudecode.c
coreutils/uuencode.c
coreutils/wc.c
debianutils/mktemp.c
debianutils/readlink.c
debianutils/start_stop_daemon.c
docs/busybox.net/FAQ.html
e2fsprogs/lsattr.c
editors/awk.c
editors/patch.c
editors/sed.c
findutils/grep.c
findutils/xargs.c
include/libbb.h
init/halt.c
libbb/Makefile.in
libbb/getopt32.c [new file with mode: 0644]
libbb/getopt_ulflags.c [deleted file]
loginutils/addgroup.c
loginutils/adduser.c
loginutils/getty.c
loginutils/login.c
loginutils/passwd.c
loginutils/su.c
loginutils/sulogin.c
loginutils/vlock.c
miscutils/adjtimex.c
miscutils/crond.c
miscutils/eject.c
miscutils/hdparm.c
miscutils/less.c
miscutils/makedevs.c
miscutils/mountpoint.c
miscutils/strings.c
miscutils/watchdog.c
modutils/insmod.c
modutils/modprobe.c
modutils/rmmod.c
networking/arping.c
networking/dnsd.c
networking/ether-wake.c
networking/fakeidentd.c
networking/ftpgetput.c
networking/hostname.c
networking/httpd.c
networking/ifupdown.c
networking/inetd.c
networking/ipcalc.c
networking/nameif.c
networking/netstat.c
networking/route.c
networking/telnet.c
networking/telnetd.c
networking/tftp.c
networking/traceroute.c
networking/wget.c
networking/zcip.c
procps/pidof.c
procps/ps.c
procps/top.c
runit/chpst.c
shell/bbsh.c
shell/lash.c
sysklogd/klogd.c
sysklogd/logger.c
sysklogd/syslogd.c
util-linux/dmesg.c
util-linux/fdformat.c
util-linux/getopt.c
util-linux/hwclock.c
util-linux/ipcs.c
util-linux/losetup.c
util-linux/mount.c
util-linux/rdate.c
util-linux/readprofile.c
util-linux/swaponoff.c
util-linux/switch_root.c
util-linux/umount.c

index e10bf7c47c2afade7e5a6f43d0f2299f715ac656..06a879b9306c2c4715d9719820485efb0a5544f4 100644 (file)
@@ -41,7 +41,7 @@ static void header_verbose_list_ar(const file_header_t *file_header)
 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];
@@ -49,8 +49,8 @@ int ar_main(int argc, char **argv)
        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;
index 9d62366c39b509b9a5b20fd401904343ee3675f3..faf997bbe73a93eeafb9d88ed8737295a08d4fe2 100644 (file)
@@ -16,10 +16,10 @@ int bunzip2_main(int argc, char **argv)
 {
        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];
index 48b688e79b11c93ab2bccfa614ee1b7c03f062f5..d0d3288ffdc6ae13732613122517ac6959d7a9e1 100644 (file)
@@ -30,7 +30,7 @@ int cpio_main(int argc, char **argv)
 {
        archive_handle_t *archive_handle;
        char *cpio_filename = NULL;
-       unsigned long opt;
+       unsigned opt;
 
        /* Initialise */
        archive_handle = init_handle();
@@ -38,7 +38,7 @@ int cpio_main(int argc, char **argv)
        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) {
index ce65e219acb5e9469aa74577bd47646dcf727250..80a5f3250c84293dd58f9635bf4808077f0b0b2e 100644 (file)
@@ -18,7 +18,7 @@ int dpkg_deb_main(int argc, char **argv)
        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;
 
@@ -40,8 +40,8 @@ int dpkg_deb_main(int argc, char **argv)
        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;
index 1b496862895148911216fb53d86fbc4e3bd1f8b6..1cde08b4d19c703301431f133f7d6418eab2d6d5 100644 (file)
@@ -40,9 +40,9 @@ int gunzip_main(int argc, char **argv)
 {
        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;
index 2fc9f769802613f372ae04bd0c7d0b0bcbb54e1e..ef3724c3419b8eddfac624aa2a2af158006ef50e 100644 (file)
@@ -1134,14 +1134,14 @@ int gzip_main(int argc, char **argv)
                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 */
@@ -1157,7 +1157,7 @@ int gzip_main(int argc, char **argv)
        //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);
        }
index bfee638b47b255d5182c87b94781fdfe324c9650..3775598ccf18ac7d127609a25260dfbbad056c72 100644 (file)
@@ -688,7 +688,7 @@ int tar_main(int argc, char **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 */
@@ -696,12 +696,12 @@ int tar_main(int argc, char **argv)
        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
index 91568e45f3fbad4d3a531932e72e809d5e1d886d..d1b0d2cb33ea6d4873d9fecf35accbe9c61c00ec 100644 (file)
@@ -16,7 +16,7 @@ int uncompress_main(int argc, char **argv)
        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++];
index b87a3fe79f7ab2aca314dc8a15a012f15e8e2842..20891e316ddff4be9b16e2f33c3747f079a1ddec 100644 (file)
@@ -19,10 +19,10 @@ int unlzma_main(int argc, char **argv)
 {
        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];
index 71fe928dabfd2a1c50581193fc768ec5f8ec4bce..ef81f298bee17420ec089583caf255c5266b99f2 100644 (file)
@@ -24,9 +24,9 @@ int setconsole_main(int argc, char **argv)
        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();
index 8996aa8c766a06a74644a2020a72e9c7551a84ae..ef914128cd6edbc347264dc404c4fc49a6b59809 100644 (file)
@@ -91,7 +91,7 @@ int cal_main(int argc, char **argv)
        setlocale(LC_TIME, "");
 #endif
 
-       flags = bb_getopt_ulflags(argc, argv, "jy");
+       flags = getopt32(argc, argv, "jy");
 
        julian = flags & 1;
 
index 37237ec1d3d356ebab123e4c522a2817a92d90f7..f3baf0a2da4135edc49bfd48e378e0c8585a0400 100644 (file)
@@ -18,7 +18,7 @@ int cat_main(int argc, char **argv)
        FILE *f;
        int retval = EXIT_SUCCESS;
 
-       bb_getopt_ulflags(argc, argv, "u");
+       getopt32(argc, argv, "u");
 
        argv += optind;
        if (!*argv) {
index f8229c20e47798bac7f4e213f5d32165ee995d06..55656b4b2d268af13828a88c0647eb90a5045433 100644 (file)
@@ -17,7 +17,7 @@ int catv_main(int argc, char **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)
index 5064f2d6e8aa1ec2a907084ace821503af5a5945..e62bd16f0047ebbf1a2632e9a19734c7a01e4486 100644 (file)
@@ -31,7 +31,7 @@ int chgrp_main(int argc, char **argv)
        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();
index bb379ac205949898ecbc71acb81dff87e50750fa..b73f66a894b7cba481a076de416959dbafc7138e 100644 (file)
@@ -43,7 +43,7 @@ int chown_main(int argc, char **argv)
        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;
 
index d0d9769974d2a5be5cfbc3b20a798d246b30dfab..07858c64efa69daa7ee7a6bf6c1452e256e4035b 100644 (file)
@@ -54,7 +54,7 @@ int cmp_main(int argc, char **argv)
 
        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))
index 7524a7b2552f9e138ccce2b8c3533b043bb9448b..91f017753afb51b63a87a79e8c46345cc0976ee9 100644 (file)
@@ -112,7 +112,7 @@ int comm_main(int argc, char **argv)
 {
        unsigned long flags;
 
-       flags = bb_getopt_ulflags(argc, argv, "123");
+       flags = getopt32(argc, argv, "123");
 
        if (optind + 2 != argc)
                bb_show_usage();
index 85086aab5dc203f2b52619821ffb1caf66519564..fabfe58e04efdc9baa65920a9837b2bbdc22d511 100644 (file)
@@ -39,7 +39,7 @@ int cp_main(int argc, char **argv)
        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);
index d88a891b021ae50e4856f34d37a53c88d52a6d34..30dbc02dbecf0eceb8c014fa41be525abbd07e94 100644 (file)
 #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 */
 
@@ -179,9 +178,8 @@ int cut_main(int argc, char **argv)
 {
        char *sopt, *ltok;
 
-       bb_opt_complementally = "b--bcf:c--bcf:f--bcf";
-       opt =
-               bb_getopt_ulflags(argc, argv, optstring, &sopt, &sopt, &sopt, &ltok);
+       opt_complementary = "b--bcf:c--bcf:f--bcf";
+       opt = getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, &ltok);
        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");
index 2a82e0413ca74e363a0b6644a8955bbb2bc2f8e1..74e99665d7f11c64d33dbec0457b9c81ecafedbe 100644 (file)
@@ -42,7 +42,7 @@ int date_main(int argc, char **argv)
 {
        time_t tm;
        struct tm tm_time;
-       unsigned long opt;
+       unsigned opt;
        int ifmt = -1;
        char *date_str = NULL;
        char *date_fmt = NULL;
@@ -50,9 +50,9 @@ int date_main(int argc, char **argv)
        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));
index 17ce634a78c9d6157da15f2fd29bdb516108bd6d..94ead32eb36e276ade107f9dc8dc03f23c30f211 100644 (file)
@@ -41,7 +41,7 @@ int df_main(int argc, char **argv)
        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;
@@ -49,8 +49,8 @@ int df_main(int argc, char **argv)
        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";
@@ -60,7 +60,7 @@ int df_main(int argc, char **argv)
                                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",
index 3c409b2cfb1c9d02dc6fff490796f8182fe131f7..2edcd96caa3ca070004199e414a2c8451d84d303 100644 (file)
@@ -1164,9 +1164,9 @@ int diff_main(int argc, char **argv)
        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) {
index 19f1a3257043f669ec950b03d148cab0b7083166..a8038a6dd3aa92ecefe544a6cddf17c69dd776ef 100644 (file)
@@ -93,11 +93,11 @@ int dos2unix_main(int argc, char *argv[])
                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.  */
index 3cc9355530d98d123509c44fdf31e87bd5ca3a5c..1452e58832b0301175bdfd74bddac15f810047ed 100644 (file)
@@ -153,7 +153,7 @@ int du_main(int argc, char **argv)
        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? */
@@ -172,8 +172,8 @@ int du_main(int argc, char **argv)
         * 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;
@@ -187,8 +187,8 @@ int du_main(int argc, char **argv)
                        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 */
index 2af15a37ebe6f87227add4c1091ff3d77bb036a3..d03318feac2b946e4f3c68f0946ada4207c9ec73 100644 (file)
@@ -46,16 +46,16 @@ int env_main(int argc, char** argv)
        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]) {
index aff7bb1d92e32521c0f4d541c9248aa4d4c52bd1..3b5be64fe8b8a673edd96d5864373855aba2e174 100644 (file)
@@ -60,7 +60,7 @@ int fold_main(int argc, char **argv)
                }
        }
 
-       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);
 
index 50694bfefa048ce2f86555c55d41eb3882c0b033..7d5f219d2bf3c211d9d9e5caeda83fafd2b635ea 100644 (file)
@@ -60,7 +60,7 @@ int head_main(int argc, char **argv)
        }
 #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
index 1bedff37aad5754ab8ac7e62d42928521649b412..dd825ab3c18308918103232c232ea6e263bd1a7e 100644 (file)
@@ -50,8 +50,8 @@ int id_main(int argc, char **argv)
 
        /* 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();
index d3d6a58a10098f55b302db47f62c49e76a4cc937..2178d435d2fe3f21516a30a871aaa691abe92c61 100644 (file)
@@ -45,11 +45,11 @@ int install_main(int argc, char **argv)
        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) {
index d1f5b1e8905213d4929c9da3aff93beddcb6d92a..3a3d3411834436f5d6e6f80f03ae15f9cb317452 100644 (file)
@@ -31,7 +31,7 @@ mode_t getopt_mk_fifo_nod(int argc, char **argv)
        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);
index df183581e43a7e4cb06b42f936a8751c473248e4..cd6e470be38192ebf988fea1202c642e9f5c28b6 100644 (file)
@@ -30,7 +30,7 @@ int ln_main(int argc, char **argv)
        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();
index 0099f18feb02f57933bcfda57ff10c90cbdb7529..8ba4ab758ff41afee7ebc13cd60be252089c4007 100644 (file)
@@ -877,7 +877,7 @@ int ls_main(int argc, char **argv)
        struct dnode **dnp;
        struct dnode *dn;
        struct dnode *cur;
-       long opt;
+       unsigned opt;
        int nfiles = 0;
        int dnfiles;
        int dndirs;
@@ -904,12 +904,12 @@ int ls_main(int argc, char **argv)
 #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
@@ -921,7 +921,7 @@ int ls_main(int argc, char **argv)
                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
index c10fac5d07b097bead6b3619f92888a3a1b1ed25..a99e45864c31e6b426cc67ed0761463b9b88b40a 100644 (file)
@@ -91,7 +91,7 @@ int md5_sha1_sum_main(int argc, char **argv)
                : 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)) {
index c09c72f7d9615a52feab399049c112b55f2a45ab..3fe55c39575f8d524c945112c1d7794eaff00ef2 100644 (file)
@@ -34,13 +34,13 @@ int mkdir_main (int argc, char **argv)
        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)) {
index 274aecb45d6db965e0bb5ad1a2662217a2ba6572..770b42417af82178520a27e61527e034cd5d3fb7 100644 (file)
@@ -45,10 +45,10 @@ int mv_main(int argc, char **argv)
        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();
        }
index c787ae342a10f7e32dbb1bdd18a98bce083d2aa8..490694a6e788a51596d4481ed3bcb36cbff36173 100644 (file)
@@ -22,10 +22,10 @@ int rm_main(int argc, char **argv)
 {
        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)
index e1ed34c6eea977b8524b4423d3c695ede2049255..05ea0e9ffe7c6b2104902e0d5ed501e09e164e88 100644 (file)
@@ -22,7 +22,7 @@ int rmdir_main(int argc, char **argv)
        int do_dot;
        char *path;
 
-       flags = bb_getopt_ulflags(argc, argv, "p");
+       flags = getopt32(argc, argv, "p");
 
        argv += optind;
 
index 8e0121849fced196ee9323f9e8a2ad70e269d6df..b9fd42f4a3707d566ee1fcab13806bcbe0531b80 100644 (file)
@@ -516,7 +516,7 @@ int stat_main(int argc, char **argv)
        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)
        );
 
index 99d477fc3809feb7b512d004cee275c44e67e146..61ca582a1577863d039437a9f6a6474e0b2246b2 100644 (file)
@@ -136,7 +136,7 @@ int sum_main(int argc, char **argv)
        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)
index 1f59f0361d1090154b8789d5d4492a35819ae125..a194153e0271bbd8f9b5cf5beca69b4dae8c4fb5 100644 (file)
@@ -28,7 +28,7 @@ int tee_main(int argc, char **argv)
        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... */
 
index 76c05d8c8c2bf9b03188a7849f395e14b1eb0520..e1af7d0dce5458dcd212361f0b31ed4850ce47c5 100644 (file)
@@ -32,7 +32,7 @@ int touch_main(int argc, char **argv)
        int flags;
        int status = EXIT_SUCCESS;
 
-       flags = bb_getopt_ulflags(argc, argv, "c");
+       flags = getopt32(argc, argv, "c");
 
        argv += optind;
 
index eb8c3dd0f81d07696ffd20726d6e7b66ec91b42d..579e6f73cc8f9d4dd3236951db2c2dfe27809d7a 100644 (file)
@@ -23,7 +23,7 @@ int tty_main(int argc, char **argv)
 
        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);
index da12c3aeedf92041d4274c7b83b910eb5ac67424..575fb525c227c45019049cca00fa3ca8ce506e52 100644 (file)
@@ -63,7 +63,7 @@ int uname_main(int argc, char **argv)
        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();
index 21ebce3ace783303a9bd6231684361f23aa91f88..921d29af0cc18e075f947be78daa06eb260d36cc 100644 (file)
@@ -129,7 +129,7 @@ int uudecode_main(int argc, char **argv)
        char *outname = NULL;
        char *line;
 
-       bb_getopt_ulflags(argc, argv, "o:", &outname);
+       getopt32(argc, argv, "o:", &outname);
 
        if (optind == argc) {
                src_stream = stdin;
index 1a8882fc7e5942f171ac2cf3a6f68908d3407dba..58538365e900de3324f3231ffe06d08e35b99d80 100644 (file)
@@ -27,7 +27,7 @@ int uuencode_main(int argc, char **argv)
        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;
        }
 
index 6ddac4dec47989b853d124f31fd8db57845d2b81..359d9fd6dc8e9c2c5d524acee4aabf6cc60ca407 100644 (file)
@@ -87,7 +87,7 @@ int wc_main(int argc, char **argv)
        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);
index 495a2ea3af44b5ca17151a1b66af2e80b0cbd3e1..546e030b0c5ddb5af235de3d53d48e75bd5cf87c 100644 (file)
@@ -18,7 +18,7 @@
 
 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();
index bfe0db6c337c55ca45a58b8a662ec1b1f0a5002d..0d5ad94f42fccfbc66ad61e04b69fbecda442bf2 100644 (file)
@@ -18,8 +18,8 @@
 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();
index dcff1dd86c2f89e961496eb5bb57c4fa47dbc895..57f42d8efb10c545087ea8f46b716ee05e21effd 100644 (file)
@@ -227,7 +227,7 @@ static const struct option ssd_long_options[] = {
 
 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
@@ -235,12 +235,12 @@ int start_stop_daemon_main(int argc, char **argv)
 //     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:"
index fee207486c9998a11c1b6620264cd0411f882d58..af20366b63d4bc8ae5f338faabc512dff572f430 100644 (file)
@@ -567,7 +567,7 @@ for failure and abort the program with an error message so the caller doesn't
 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>
index 5c20d25f381510f58fcfadcee90160d56e50b051..e76f8d9d79c5edc19b6d45649c48f5260031f140 100644 (file)
@@ -124,7 +124,7 @@ int lsattr_main(int argc, char **argv)
 {
        int i;
 
-       flags = bb_getopt_ulflags(argc, argv, "Radlv");
+       flags = getopt32(argc, argv, "Radlv");
 
        if (optind > argc - 1)
                lsattr_args(".");
index b46f25c0a598ee28f46a96b053f76cefd2e2cdbd..c1b56d9e531deeceafbc7f6292a9b87a03737dc0 100644 (file)
@@ -2634,7 +2634,7 @@ static rstream *next_input_file(void)
 
 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;
@@ -2691,7 +2691,7 @@ keep_going:
                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
index a710d8224432bcd9d83b6f95a9de655e36decab8..c18659edaea3568af41c234f04a9dbb9ed28a77c 100644 (file)
@@ -85,7 +85,7 @@ int patch_main(int argc, char **argv)
 
        {
                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) {
index 201665209d61f2d12cd02419ab4355ca5493d7e0..7dba8b45608bae7a43c52f074b24bfaaba8e4f43 100644 (file)
@@ -1109,7 +1109,7 @@ static void add_files_link(llist_t *opt_f)
 
 int sed_main(int argc, char **argv)
 {
-       unsigned long opt;
+       unsigned opt;
        llist_t *opt_e, *opt_f;
        int status = EXIT_SUCCESS;
 
@@ -1126,8 +1126,8 @@ int sed_main(int argc, char **argv)
 
        /* 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);
@@ -1135,11 +1135,11 @@ int sed_main(int argc, char **argv)
        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] */
index 5659a7d2b8baf806e7218b9c2cc3a667a39afa08..35e6aff2d2040fc57872e5a86be9fb10ea338bc5 100644 (file)
@@ -24,7 +24,7 @@
 
 
 /* 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)
@@ -302,8 +302,8 @@ int grep_main(int argc, char **argv)
        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);
@@ -336,8 +336,8 @@ int grep_main(int argc, char **argv)
                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 */
index b6a154f1566b18ecd34e45dcf72d98db0200da9e..278382373946dff85481c36ddb03935ea0b5493c 100644 (file)
@@ -399,7 +399,7 @@ int xargs_main(int argc, char **argv)
        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;
@@ -407,7 +407,7 @@ int xargs_main(int argc, char **argv)
 #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);
index c0de92190280eeb292574cb78e57e7cd58c7af5a..4e96ea4152e7fc7e6c98d92769b1d4227c74e8ea 100644 (file)
@@ -207,9 +207,9 @@ extern void xsetuid(uid_t uid);
 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)));
@@ -232,7 +232,7 @@ extern char *skip_whitespace(const char *);
 
 #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
index 7bd27896ca29e5dae678bc8595a5c8a7d415c8dc..d796a4aea6f0053e32c40c091e2d0c40c807463f 100644 (file)
@@ -34,7 +34,7 @@ RB_AUTOBOOT
        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();
 
index f731e6e03de832e189a2868125eca5a50fb21d65..ef5c6b97a7c66ee6c188f453774158f8841ff789 100644 (file)
@@ -30,7 +30,7 @@ LIBBB-y:= \
        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
diff --git a/libbb/getopt32.c b/libbb/getopt32.c
new file mode 100644 (file)
index 0000000..e084965
--- /dev/null
@@ -0,0 +1,516 @@
+/* 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;
+}
diff --git a/libbb/getopt_ulflags.c b/libbb/getopt_ulflags.c
deleted file mode 100644 (file)
index 9d27c1f..0000000
+++ /dev/null
@@ -1,519 +0,0 @@
-/* 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;
-}
index 13f29bfa3216b785a7d1b98a9552144a4d0c7ba8..236dc109914bf2de3e4f2df625377fccf4e8dc8f 100644 (file)
@@ -90,9 +90,9 @@ int addgroup_main(int argc, char **argv)
        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 */
index 936e48e0a40e6beafb3181d4f2ce1105e06c30e4..8101b20b4febfddad64653cda792e6a1433e701b 100644 (file)
@@ -169,8 +169,8 @@ int adduser_main(int argc, char **argv)
        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()) {
index 22601c74e4f898a2cde169eed4184b0fb7a28c3e..6730fa85c9ad37700daeecc3dd81e13893af031d 100644 (file)
@@ -258,7 +258,7 @@ static void parse_args(int argc, char **argv, struct options *op)
 {
        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) {
index 1b13fa0ccc7c3906747672b89c78c085ea1eea10..1f392c10f7926141dc8f080f22845d20510f3ac8 100644 (file)
@@ -222,7 +222,7 @@ int login_main(int argc, char **argv)
        char username[USERNAME_SIZE];
        const char *tmp;
        int amroot;
-       unsigned long opt;
+       unsigned opt;
        int count = 0;
        struct passwd *pw;
        char *opt_host = NULL;
@@ -234,7 +234,7 @@ int login_main(int argc, char **argv)
        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");
index 211a49ea38b9811df22284d343584e2725740434..54f35d2d5f7c321880db895e2bf9bdc036027088 100644 (file)
@@ -134,7 +134,7 @@ int passwd_main(int argc, char **argv)
                OPT_delete = 0x8, /* -d - delete password */
                OPT_lud = 0xe,
        };
-       unsigned long opt;
+       unsigned opt;
        char *opt_a;
        int amroot;
        char *cp;
@@ -146,7 +146,7 @@ int passwd_main(int argc, char **argv)
 
        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
index c51359ae175021da142ffc923f22c9c5f5be535d..78942014efcf64587897c24c46fbd2128e06fe2a 100644 (file)
@@ -20,7 +20,7 @@ int su_main(int argc, char **argv)
        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)
 
index 8cfb64e9ac1c93dd9e49fe0b53d8e060dd26f302..6edd2582b3f250acffda5fa92e9d7c91f2967fe1 100644 (file)
@@ -46,7 +46,7 @@ int sulogin_main(int argc, char **argv)
        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;
                }
index d472c09251d788311f8ce89b23de43fd0beec7c0..02d1ea772139f1847a19171a0ba366aceec4c6df 100644 (file)
@@ -55,7 +55,7 @@ int vlock_main(int argc, char **argv)
                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());
index 9662bbea9f34bfb43cd6518cf3f3a69b6dabbe19..47af1a5d2e0ae2abcb607d62a008d6d9d3568848 100644 (file)
@@ -47,14 +47,14 @@ int adjtimex_main(int argc, char **argv)
        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
index 3e12fedc8df5a29fb55949ec589520b2d6e71a65..4f25486dd35a590d73de4bc1ef22500bde1b6ff9 100644 (file)
@@ -133,19 +133,19 @@ static void crondlog(const char *ctl, ...)
 
 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
index 272d95980c34d85aca0afb1f8d44f8f2ef93f655..d49396be6a9b481add03f7c94a745e700e4d1e85 100644 (file)
@@ -31,8 +31,8 @@ int eject_main(int argc, char **argv)
        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);
index b90142362af87551cf2e51ef4e4a80c10e9e5c4e..6c46f6a92252e412c460caebc40186bee29b244d 100644 (file)
@@ -575,18 +575,18 @@ static void identify(uint16_t *id_supplied)
 
        /* 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;
@@ -609,9 +609,9 @@ static void identify(uint16_t *id_supplied)
           (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");
        }
 
@@ -629,9 +629,9 @@ static void identify(uint16_t *id_supplied)
        {
                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;
@@ -652,17 +652,17 @@ static void identify(uint16_t *id_supplied)
                                                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) &&
@@ -724,7 +724,7 @@ static void identify(uint16_t *id_supplied)
                        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;
                        }
                }
@@ -743,7 +743,7 @@ static void identify(uint16_t *id_supplied)
                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;
                }
        }
@@ -1018,7 +1018,7 @@ static void identify(uint16_t *id_supplied)
                }
        }
        /* 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]);
 
 
@@ -1196,7 +1196,7 @@ static void dump_identity(const struct hd_driveid *id)
        }
        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,
@@ -1589,7 +1589,7 @@ static void interpret_xfermode(unsigned int xfermode)
 
 static void print_flag(unsigned long flag, char *s, unsigned long value)
 {
-       if(flag)
+       if (flag)
                printf(" setting %s to %ld\n", s, value);
 }
 
@@ -2078,18 +2078,18 @@ static void parse_xfermode(int flag, unsigned long *get, unsigned long *set, int
 }
 
 /*------- 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")
@@ -2154,8 +2154,8 @@ int hdparm_main(int argc, char **argv)
 #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;
@@ -2163,7 +2163,7 @@ int hdparm_main(int argc, char **argv)
 #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);
        }
index bde2a4527507c2156a141c158536c10f0eefce08..63389dcd7ec0b42fe6fe2abe8c38bf9cf1629ef0 100644 (file)
@@ -1102,7 +1102,7 @@ int less_main(int argc, char **argv) {
 
        int keypress;
 
-       flags = bb_getopt_ulflags(argc, argv, "EMmN~");
+       flags = getopt32(argc, argv, "EMmN~");
 
        argc -= optind;
        argv += optind;
index 66b4ce00d44e5d09ebfdeb392d2dac47957ca393..4619e4dd5c9a2be941fa74f6aa206d521f2235e9 100644 (file)
@@ -76,7 +76,7 @@ int makedevs_main(int argc, char **argv)
        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");
 
index 3e5fb4b460ba1874cd0e674230e9e79a8aad636a..dbc8fe0e965029051a70a1905b6a00940583f35a 100644 (file)
@@ -13,7 +13,7 @@
 
 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)
index e9f335ebda5ec4698591f5873cd8b614bd46bbc2..36bcf8b17a4ddf711ba958d1fc175e20362d0716 100644 (file)
 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;
index ebbab2df3cf2cc15087f506254fc7bd4ae963d2d..ae51aba7be584989261018ae68bb7b883bca1c3b 100644 (file)
@@ -25,11 +25,11 @@ static void watchdog_shutdown(int ATTRIBUTE_UNUSED unused)
 
 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);
index 314e87325935b3e1c6ba1dd0bd23313adc10f9c9..0554def06f6b5967b250fc6b7d8eae5718712a38 100644 (file)
@@ -3983,7 +3983,7 @@ int insmod_main( int argc, char **argv)
        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);
index f51de56be5cee056678caa454335e4223e91ffd4..b629390e44c06a8a70e3547736ea13dc22598d9f 100644 (file)
@@ -902,8 +902,8 @@ int modprobe_main(int argc, char** argv)
        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;
index f87fb5e24a68b8cc157b5afc38ed20335c83adbf..ce239a21fd6ffbf728f95ebee75c01149970e2f3 100644 (file)
@@ -44,7 +44,7 @@ int rmmod_main(int argc, char **argv)
        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
index f84c8a75c5669df9b2da239261465b5e633ee9b6..1ff6f90be196c174b7de60603786a707eb3839e5 100644 (file)
@@ -265,14 +265,14 @@ int arping_main(int argc, char **argv)
        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 */
index b0e74d770c88b2e1416e76ea1cacc23f1020bb78..ab3704707ba987db80e2ae2d0f2a8321d252a898 100644 (file)
@@ -372,7 +372,7 @@ int dnsd_main(int argc, char **argv)
        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();
index f4ca889fafc55a6a32505a099f0be39a51618c35..294a9dd3c3756ecb4e2791cddd9e893d10a3e60d 100644 (file)
@@ -120,7 +120,7 @@ int ether_wake_main(int argc, char *argv[])
        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)
index 2d690edba7bc2a69c0fa9deb72a031be603f9046..6070e5f2d0c83d621b8595da298572d9434650f3 100644 (file)
@@ -228,7 +228,7 @@ int fakeidentd_main(int argc, char **argv)
        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];
index 453cce571364d4ff2a64fe4c6917d9cc63c1f522..25b7f142754197ca371184a46b7adcdc929e2e96 100644 (file)
@@ -275,7 +275,7 @@ static const struct option ftpgetput_long_options[] = {
 int ftpgetput_main(int argc, char **argv)
 {
        /* content-length of the file */
-       unsigned long opt;
+       unsigned opt;
        char *port = "ftp";
 
        /* socket to ftp server */
@@ -305,9 +305,9 @@ int ftpgetput_main(int argc, char **argv)
         * 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) {
index 2850bd5bd16b16d9254268c7830273e15cdb9ad1..4fe28d7403f8096bd03633ce9ccb1a95aa56869b 100644 (file)
@@ -55,13 +55,13 @@ int hostname_main(int argc, char **argv)
        };
 
        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) {
index e533594f2b71aceb9e2f44f51aff874d1b09c31c..ac9eac6bfc997d86b090ce9e1a08ddd9f6159c1f 100644 (file)
@@ -1909,7 +1909,7 @@ static const char httpd_opts[] = "c:d:h:"
 
 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;)
@@ -1932,7 +1932,7 @@ int httpd_main(int argc, char *argv[])
 
        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))
index 9dd1c99267863a0dc94adb95da7a4c0ce8503d2b..f34287580c14596fd30522221711699ef7e4e540 100644 (file)
@@ -1088,7 +1088,7 @@ int ifupdown_main(int argc, char **argv)
                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
index 8c8843b9b72b70ebbab9328d833c957376462037..350f91dc48d07af9bc5ad8a90bfd9625d3d31dfa 100644 (file)
@@ -1253,7 +1253,7 @@ inetd_main(int argc, char *argv[])
 
        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;
 
index aafb7869b6897faee9dc2261b7dc6794265340cb..576dfc853938e2c99b689674bcb6bc2302c8d849 100644 (file)
@@ -90,9 +90,9 @@ int ipcalc_main(int argc, char **argv)
        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;
index 3fa257263a8b2a254266be49a9a3232048607ff4..146eccea9ebaea0800f95c4cdf33b0b639950ed5 100644 (file)
@@ -65,7 +65,7 @@ int nameif_main(int argc, char **argv)
        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;
        }
index cadcb0e3102039859ba0199b40da6276ae52de39..bc5c6197419e8b1f9e43347afd4635d193bff5d7 100644 (file)
@@ -21,7 +21,7 @@ extern void displayroutes(int noresolve, int netstatfmt);
 #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
@@ -526,7 +526,7 @@ int netstat_main(int argc, char **argv)
                OPT_extended = 0x4,
                OPT_showroute = 0x100,
        };
-       unsigned long opt;
+       unsigned opt;
 #ifdef CONFIG_FEATURE_IPV6
        int inet = 1;
        int inet6 = 1;
@@ -536,7 +536,7 @@ int netstat_main(int argc, char **argv)
 #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;
index 5fd888617cc022c6ab1193a9a063cdf04ff15b9a..2e6e017b6321f76e8f45ad4400ef58821b0c6477 100644 (file)
@@ -647,7 +647,7 @@ static const char tbl_verb[] =      /* 2nd byte matches RTACTION_* code */
 
 int route_main(int argc, char **argv)
 {
-       unsigned long opt;
+       unsigned opt;
        int what;
        char *family;
 
@@ -662,7 +662,7 @@ int route_main(int argc, char **argv)
                }
        }
 
-       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
index fd0f84d50f86ecfb4d18069dd931915e0eadd9fc..cd4c33a863ae3dbc6b6f0588127451ea1c33c7e9 100644 (file)
@@ -623,7 +623,7 @@ int telnet_main(int argc, char** argv)
                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) {
index 9fa8faf6643c9d28ecde1f348b50df8dfff03fff..808d4be51271acef32a25bf80e33ad9f49ff8e41 100644 (file)
@@ -362,7 +362,7 @@ free_session(struct tsession *ts)
 int
 telnetd_main(int argc, char **argv)
 {
-       unsigned long opt;
+       unsigned opt;
        fd_set rdfdset, wrfdset;
        int selret;
 #ifndef CONFIG_FEATURE_TELNETD_INETD
@@ -387,7 +387,7 @@ telnetd_main(int argc, char **argv)
        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
index 42fd9d2cac73c114cbbd0b9286e32458e1c807bb..5f0c190e2d4f74dc9adea9684350c291fb174163 100644 (file)
@@ -497,13 +497,13 @@ int tftp_main(int argc, char **argv)
 #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);
index e7e1311491d02f385143645a242c772db94c9b50..042cbe35a1ccb6b09c9406280429e9bacf3a00b9 100644 (file)
@@ -949,12 +949,12 @@ traceroute_main(int argc, char *argv[])
 
        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  */
index bbe1bba9a82dfefd9ea73e0d1e1275c8f03e1437..0054a9876094b3e738a3bc7fec8fd663e1bd529c 100644 (file)
@@ -124,7 +124,7 @@ static const struct option wget_long_options[] = {
 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;
@@ -148,11 +148,11 @@ int wget_main(int argc, char **argv)
        /*
         * 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) {
index c6b0d2d8091294930ddc421a38cf98b7cade1eda..d9c1adf194752da4e114621a4a606ec9796ef32c 100644 (file)
@@ -75,7 +75,7 @@ enum {
 #define VDBG(fmt,args...) \
        do { } while (0)
 
-static unsigned long opts;
+static unsigned opts;
 #define FOREGROUND (opts & 1)
 #define QUIT (opts & 2)
 
@@ -217,8 +217,8 @@ int zcip_main(int argc, char *argv[])
 
        // 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;
index c686245ea023f6757b24de0f6f8b690190bc7e0c..e6c954843571de7087d815e9610ca59b22cc8d8d 100644 (file)
@@ -39,11 +39,11 @@ int pidof_main(int argc, char **argv)
        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));
 
index 95502b284ed9782e5e948c2c8edc8c563e7a34bc..0452a5046118106e77a8f62f275786c7c8c1e155 100644 (file)
@@ -23,7 +23,7 @@ int ps_main(int argc, char **argv)
        int terminal_width;
        int w_count = 0;
 
-       bb_opt_complementally = "-:ww";
+       opt_complementary = "-:ww";
 #else
 # define terminal_width 79
 #endif
@@ -31,11 +31,11 @@ int ps_main(int argc, char **argv)
 #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,
index be8ac195b54b5e6d3bbb4008a51bafa0f47db528..ebfbcb80c90e9077544d12f401585b5a0713f266 100644 (file)
@@ -397,8 +397,8 @@ int top_main(int argc, char **argv)
 
        /* 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
index 11ee3d73386f7c527524743f11259d05035781fa..ced28387dc918d614a3450c2e9b88ef928ff085f 100644 (file)
@@ -238,7 +238,7 @@ int chpst_main(int argc, char **argv)
 
        {
                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
@@ -324,7 +324,7 @@ static void envdir(int argc, char **argv)
 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
index 2194bdad63a28896a110493a3e9a364e70333a69..77e186d35b1790bb1dca83c1f8e79e53bfb85b29 100644 (file)
@@ -203,7 +203,7 @@ int bbsh_main(int argc, char *argv[])
        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);
index fd6bea17721142c28e731728ad19fc1e4447ca63..9c862a17f958d8a9f6216ea4f2d943ba1e60b0c4 100644 (file)
@@ -1503,7 +1503,7 @@ static inline void setup_job_control(void)
 
 int lash_main(int argc_l, char **argv_l)
 {
-       unsigned long opt;
+       unsigned opt;
        FILE *input = stdin;
        argc = argc_l;
        argv = argv_l;
@@ -1527,7 +1527,7 @@ int lash_main(int argc_l, char **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) {
index 677c9e6075bbe2011d74e31f59f7426ee526ae5b..e629bec5d022ec80abdfe34785b4efe2b2c1fdcf 100644 (file)
@@ -45,10 +45,10 @@ int klogd_main(int argc, char **argv)
 
 
        {
-               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 */
index a78cf77b9441c02110da55f1f406a766e445a4e1..15a4bfb822025942935098fe0da833b22128ad9d 100644 (file)
@@ -89,7 +89,7 @@ static int pencode(char *s)
 
 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;
@@ -100,7 +100,7 @@ int logger_main(int argc, char **argv)
        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
index 888082924e9f86d0ab8939bdf661c693860521bc..40b98c1cb7f19c1990fd1928754589d4a8ede8ec 100644 (file)
@@ -575,7 +575,7 @@ int syslogd_main(int argc, char **argv)
        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
index 682c4f6961f25e9571c95d9c64e577f102d50faa..277415a2d4da6bd6425cc35df82d46208025915c 100644 (file)
@@ -16,7 +16,7 @@
 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)))
index 9b97e6873d55bb7e2659a67c5381682fc6881e6c..0242d8d3ab4ea9c7ca7fb9e46ac9f5b21c650b8b 100644 (file)
@@ -63,7 +63,7 @@ int fdformat_main(int argc,char **argv)
        if (argc < 2) {
                bb_show_usage();
        }
-       verify = !bb_getopt_ulflags(argc, argv, "n");
+       verify = !getopt32(argc, argv, "n");
        argv += optind;
 
        xstat(*argv, &st);
index a4968b72e38752fee20b57a83eccebf056509961..02bb218b376d3ca5d05d99774b8cf06a5e6f20cb 100644 (file)
@@ -184,7 +184,7 @@ enum { LONG_OPTIONS_INCR = 10 };
 #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);
index e1a67f290d15ec6361e6414cef9c8c74eae663dd..cce31335e2f78a42a4daed0aa1c1e87e7dabbde1 100644 (file)
@@ -182,7 +182,7 @@ static int check_utc(void)
 
 int hwclock_main ( int argc, char **argv )
 {
-       unsigned long opt;
+       unsigned opt;
        int utc;
 
 #if ENABLE_FEATURE_HWCLOCK_LONG_OPTIONS
@@ -194,11 +194,11 @@ static const struct option 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))
index 857065983da9528c4c185c424e31e5d6d0ec98c6..5e58e81da962ffb9acc4841f0d59cb8b24ed2f7e 100644 (file)
@@ -572,14 +572,14 @@ int ipcs_main(int argc, char **argv)
 {
        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;
index 54a160119cc2cc705334cf220752d8930cf247d7..8882ee4da6cc906a4d3fdb06c48ada5ee20d8526 100644 (file)
 
 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;
 
index 565dccd9a16aba7f9bfadc7e14228f9d9fab2a60..899bf855776dd02268970b65476c22ffe4cc3382 100644 (file)
@@ -1428,7 +1428,7 @@ int mount_main(int argc, char **argv)
        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
@@ -1444,7 +1444,7 @@ int mount_main(int argc, char **argv)
 
        // 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
index c740a691e5b6f4818395491177bd11b7a027d860..c24465dc3bc95b20875428194e16d41d1c5bbb83 100644 (file)
@@ -63,8 +63,8 @@ int rdate_main(int argc, char **argv)
        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]);
 
index 29e9f3e42912cf4d9d47ddc49b214795d5124bf7..ff70bf79b88a6d6f24f81495690cab92e75aa520 100644 (file)
@@ -64,8 +64,8 @@ int readprofile_main(int argc, char **argv)
        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);
index ab754848ebb89cdfa771b7b0efe885cfc7243f1b..4fcb239b6fd252b93c8cc47ac945c8391c10fedc 100644 (file)
@@ -66,7 +66,7 @@ int swap_on_off_main(int argc, char **argv)
        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();
 
index 1a599073eb7483f3c212a7bffb9ef117606c85e5..f2d9b6e69b38b82de6183a03736c3caaa890afbc 100644 (file)
@@ -71,8 +71,8 @@ int switch_root_main(int argc, char *argv[])
 
        // 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.
 
index e4308e54718ed085bda3d3f3d5e75fac6d20c59a..9c551f986182d2ef989314c63570e14b27648f4c 100644 (file)
@@ -27,7 +27,7 @@ int umount_main(int argc, char **argv)
        struct mntent me;
        FILE *fp;
        int status = EXIT_SUCCESS;
-       unsigned long opt;
+       unsigned opt;
        struct mtab_list {
                char *dir;
                char *device;
@@ -36,7 +36,7 @@ int umount_main(int argc, char **argv)
 
        /* Parse any options */
 
-       opt = bb_getopt_ulflags(argc, argv, OPTION_STRING);
+       opt = getopt32(argc, argv, OPTION_STRING);
 
        argc -= optind;
        argv += optind;