rework long option handling. saves ~1.2k
[oweals/busybox.git] / coreutils / od_bloaty.c
index c69470a145fc5ce3a013153768353d08a428150c..335efe7ca93a3ea7bad9d2e1fd1e8c535b25a4bd 100644 (file)
@@ -49,8 +49,7 @@ diff -u -a std bbox >bbox.diff || { echo Different!; sleep 1; }
 
 */
 
-
-#include "busybox.h"
+#include "libbb.h"
 #include <getopt.h>
 
 #define assert(a) ((void)0)
@@ -159,7 +158,7 @@ static const signed char width_bytes[] = {
    initializer in the width_bytes array.  */
 struct dummy {
        int assert_width_bytes_matches_size_spec_decl
-               [sizeof width_bytes / sizeof width_bytes[0] == N_SIZE_SPECS ? 1 : -1];
+               [ARRAY_SIZE(width_bytes) == N_SIZE_SPECS ? 1 : -1];
 };
 
 static size_t string_min;
@@ -542,7 +541,7 @@ check_and_close(void)
                fmt = SIGNED_DECIMAL;
                size = INT or LONG; (whichever integral_type_size[4] resolves to)
                print_function = print_int; (assuming size == INT)
-               fmt_string = "%011d%c";
+               fmt_string = "%011d%c";
        }
    S_ORIG is solely for reporting errors.  It should be the full format
    string argument. */
@@ -823,7 +822,7 @@ skip(off_t n_skip)
                                n_bytes_read = fread(buf, 1, n_bytes_to_read, in_stream);
                                n_skip -= n_bytes_read;
                                if (n_bytes_read != n_bytes_to_read)
-                                       break; /* EOF on this file or error */
+                                       break; /* EOF on this file or error */
                        }
                }
                if (n_skip == 0)
@@ -1243,17 +1242,16 @@ int od_main(int argc, char **argv)
                OPT_traditional = (1 << 18) * ENABLE_GETOPT_LONG,
        };
 #if ENABLE_GETOPT_LONG
-       static const struct option long_options[] = {
-               { "skip-bytes",    required_argument, NULL, 'j' },
-               { "address-radix", required_argument, NULL, 'A' },
-               { "read-bytes",    required_argument, NULL, 'N' },
-               { "format",        required_argument, NULL, 't' },
-               { "output-duplicates", no_argument,   NULL, 'v' },
-               { "strings",       optional_argument, NULL, 'S' },
-               { "width",         optional_argument, NULL, 'w' },
-               { "traditional",   no_argument,       NULL, 0xff },
-               { NULL, 0, NULL, 0 }
-       };
+       static const char od_longopts[] =
+               "skip-bytes\0"        Required_argument "j"
+               "address-radix\0"     Required_argument "A"
+               "read-bytes\0"        Required_argument "N"
+               "format\0"            Required_argument "t"
+               "output-duplicates\0" No_argument       "v"
+               "strings\0"           Optional_argument "S"
+               "width\0"             Optional_argument "w"
+               "traditional\0"       No_argument       "\xff"
+               "\0";
 #endif
        char *str_A, *str_N, *str_j, *str_S;
        char *str_w = NULL;
@@ -1268,7 +1266,7 @@ int od_main(int argc, char **argv)
        /* Parse command line */
        opt_complementary = "t::"; // list
 #if ENABLE_GETOPT_LONG
-       applet_long_options = long_options;
+       applet_long_options = od_longopts;
 #endif
        opt = getopt32(argc, argv, "A:N:abcdfhij:lot:vxsS:"
                "w::", // -w with optional param
@@ -1312,7 +1310,6 @@ int od_main(int argc, char **argv)
        if (opt & OPT_l) decode_format_string("d4");
        if (opt & OPT_o) decode_format_string("o2");
        //if (opt & OPT_t)...
-       lst_t = llist_rev(lst_t);
        while (lst_t) {
                decode_format_string(lst_t->data);
                lst_t = lst_t->link;
@@ -1334,7 +1331,7 @@ int od_main(int argc, char **argv)
        /* If the --traditional option is used, there may be from
         * 0 to 3 remaining command line arguments;  handle each case
         * separately.
-        *      od [file] [[+]offset[.][b] [[+]label[.][b]]]
+        * od [file] [[+]offset[.][b] [[+]label[.][b]]]
         * The offset and pseudo_start have the same syntax.
         *
         * FIXME: POSIX 1003.1-2001 with XSI requires support for the