]> git.alsa-project.org Git - alsa-utils.git/commitdiff
axfer: truncate parsed arguments before operating subcommand
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 3 Dec 2018 21:33:42 +0000 (06:33 +0900)
committerTakashi Iwai <tiwai@suse.de>
Wed, 5 Dec 2018 14:23:50 +0000 (15:23 +0100)
When subcommands are operated, top-most two arguments are already
parsed in renewed command system, thus they're useless. Besides,
they're possible to be parsed by getopt_long(3).

This commit truncates these options before entering subcommand
operation.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
axfer/main.c
axfer/subcmd-list.c
axfer/subcmd-transfer.c

index 954dd5e46c91500cd26ec4a7c835a6b0a90de404..f9ee44eff91bc1d2ae10ff0a1c7219277b050614 100644 (file)
@@ -251,8 +251,14 @@ int main(int argc, char *const *argv)
                // The second option should be either 'capture' or 'direction'
                // if subcommand is neither 'version' nor 'help'.
                if (subcmd != SUBCMD_VERSION && subcmd != SUBCMD_HELP) {
-                       if (!detect_direction(argc, argv, &direction))
+                       if (!detect_direction(argc, argv, &direction)) {
                                subcmd = SUBCMD_HELP;
+                       } else {
+                               // argv[0] is needed for unparsed option to use
+                               // getopt_long(3).
+                               argc -= 2;
+                               argv += 2;
+                       }
                }
        }
 
index f8f0952e750a225ed4965d7af079838f240d4a0a..1ea9669af31b4d2f8707c509ff60c1d8c8db8989 100644 (file)
@@ -233,11 +233,11 @@ static int detect_operation(int argc, char *const *argv, enum list_op *op)
        };
        int i;
 
-       if (strcmp(argv[1], "list") || argc < 3)
+       if (argc < 2)
                return false;
 
        for (i = 0; i < ARRAY_SIZE(ops); ++i) {
-               if (!strcmp(argv[2], ops[i])) {
+               if (!strcmp(argv[1], ops[i])) {
                        *op = i;
                        return true;
                }
@@ -252,11 +252,9 @@ int subcmd_list(int argc, char *const *argv, snd_pcm_stream_t direction)
        int err = 0;
 
        // Renewed command system.
-       if (argc > 1) {
-               if (!detect_operation(argc, argv, &op) &&
-                   !decide_operation(argc, argv, &op))
-                               err = -EINVAL;
-       }
+       if (!detect_operation(argc, argv, &op) &&
+           !decide_operation(argc, argv, &op))
+                       err = -EINVAL;
 
        if (op == LIST_OP_DEVICE)
                err = list_devices(direction);
index d5f16cb80ebd0f8f057c8b35b22b12763940529c..3ca745a6d7a1b153501127a10fd4ff3a218a91e5 100644 (file)
@@ -435,13 +435,6 @@ int subcmd_transfer(int argc, char *const *argv, snd_pcm_stream_t direction)
        uint64_t actual_frame_count = 0;
        int err = 0;
 
-       // Renewed command system.
-       if (argc > 2 && !strcmp(argv[1], "transfer")) {
-               // Go ahead to parse file paths properly.
-               --argc;
-               ++argv;
-       }
-
        err = prepare_signal_handler(&ctx);
        if (err < 0)
                return err;