v4l-utils: fix optional args for short opts
authorHans Verkuil <hans.verkuil@cisco.com>
Sat, 22 Feb 2014 10:13:01 +0000 (11:13 +0100)
committerHans Verkuil <hans.verkuil@cisco.com>
Sat, 22 Feb 2014 10:13:01 +0000 (11:13 +0100)
I always wondered why I couldn't do e.g. -s10 where 10 is the optional
argument for the short option -s. It worked fine with --streaming=10.
It turns out that in the optstring passed to getopt_long you have to
specify such an option as 's::' and I didn't so that.

This is now fixed.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/v4l2-compliance/v4l2-compliance.cpp
utils/v4l2-ctl/v4l2-ctl.cpp
utils/v4l2-dbg/v4l2-dbg.cpp

index 4acc943..5df7660 100644 (file)
@@ -45,6 +45,7 @@
    case is used to retrieve a setting. */
 enum Option {
        OptSetDevice = 'd',
+       OptSetExpBufDevice = 'e',
        OptSetFreq = 'f',
        OptHelp = 'h',
        OptSetInput = 'i',
@@ -56,7 +57,6 @@ enum Option {
        OptVerbose = 'v',
        OptSetVbiDevice = 'V',
        OptUseWrapper = 'w',
-       OptSetExpBufDevice = 128,
        OptLast = 256
 };
 
@@ -103,7 +103,7 @@ static void usage(void)
        printf("                     if <dev> starts with a digit, then /dev/radio<dev> is used.\n");
        printf("  -V, --vbi-device=<dev> use device <dev> as the vbi device.\n");
        printf("                     if <dev> starts with a digit, then /dev/vbi<dev> is used.\n");
-       printf("  --expbuf-device=<dev> use device <dev> to obtain DMABUF handles.\n");
+       printf("  -e, --expbuf-device=<dev> use device <dev> to obtain DMABUF handles.\n");
        printf("                     if <dev> starts with a digit, then /dev/video<dev> is used.\n");
        printf("                     only /dev/videoX devices are supported.\n");
        printf("  -i, --set-input    select input for streaming tests (default is 0).\n");
@@ -472,15 +472,19 @@ int main(int argc, char **argv)
        const char *expbuf_device = NULL;       /* --expbuf-device device */
        struct v4l2_capability vcap;            /* list_cap */
        unsigned frame_count = 100;
-       char short_options[26 * 2 * 2 + 1];
+       char short_options[26 * 2 * 3 + 1];
        int idx = 0;
 
        for (i = 0; long_options[i].name; i++) {
                if (!isalpha(long_options[i].val))
                        continue;
                short_options[idx++] = long_options[i].val;
-               if (long_options[i].has_arg == required_argument)
+               if (long_options[i].has_arg == required_argument) {
                        short_options[idx++] = ':';
+               } else if (long_options[i].has_arg == optional_argument) {
+                       short_options[idx++] = ':';
+                       short_options[idx++] = ':';
+               }
        }
        while (1) {
                int option_index = 0;
index f8a925d..737d1a6 100644 (file)
@@ -773,7 +773,7 @@ int main(int argc, char **argv)
        __u32 poll_for_event = 0;       /* poll for this event */
        const char *poll_event_id = NULL;
        unsigned secs = 0;
-       char short_options[26 * 2 * 2 + 1];
+       char short_options[26 * 2 * 3 + 1];
        int idx = 0;
 
        memset(&vcap, 0, sizeof(vcap));
@@ -786,8 +786,12 @@ int main(int argc, char **argv)
                if (!isalpha(long_options[i].val))
                        continue;
                short_options[idx++] = long_options[i].val;
-               if (long_options[i].has_arg == required_argument)
+               if (long_options[i].has_arg == required_argument) {
                        short_options[idx++] = ':';
+               } else if (long_options[i].has_arg == optional_argument) {
+                       short_options[idx++] = ':';
+                       short_options[idx++] = ':';
+               }
        }
        while (1) {
                int option_index = 0;
index 06b081c..d5ffc12 100644 (file)
@@ -375,7 +375,7 @@ int main(int argc, char **argv)
        struct v4l2_dbg_register get_reg;
        struct v4l2_dbg_chip_info chip_info;
        const struct board_list *curr_bd = NULL;
-       char short_options[26 * 2 * 2 + 1];
+       char short_options[26 * 2 * 3 + 1];
        int idx = 0;
        std::string reg_min_arg, reg_max_arg;
        std::string reg_set_arg;
@@ -397,8 +397,12 @@ int main(int argc, char **argv)
                if (!isalpha(long_options[i].val))
                        continue;
                short_options[idx++] = long_options[i].val;
-               if (long_options[i].has_arg == required_argument)
+               if (long_options[i].has_arg == required_argument) {
                        short_options[idx++] = ':';
+               } else if (long_options[i].has_arg == optional_argument) {
+                       short_options[idx++] = ':';
+                       short_options[idx++] = ':';
+               }
        }
        while (1) {
                int option_index = 0;