summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2018-03-16 18:56:50 +0100
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2018-03-19 12:00:09 +0200
commit60970ec27cb906c9fd4ae023820f8c5be0b63487 (patch)
treeac5df9b3f5f99993b9bd25ca6f2c4a54e7f643be
parent2e24198974c83a7e4a7d6fec6bdaccb5775b875b (diff)
downloadweston-60970ec27cb906c9fd4ae023820f8c5be0b63487.tar.gz
simple-dmabuf-drm: use getopt_long
Signed-off-by: Guido Günther <agx@sigxcpu.org> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
-rw-r--r--clients/simple-dmabuf-drm.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/clients/simple-dmabuf-drm.c b/clients/simple-dmabuf-drm.c
index 427597ab..4f26e4a9 100644
--- a/clients/simple-dmabuf-drm.c
+++ b/clients/simple-dmabuf-drm.c
@@ -38,6 +38,7 @@
#include <sys/mman.h>
#include <signal.h>
#include <fcntl.h>
+#include <getopt.h>
#include <xf86drm.h>
@@ -877,30 +878,32 @@ main(int argc, char **argv)
struct window *window;
int opts = 0;
int import_format = DRM_FORMAT_XRGB8888;
- int ret = 0, i = 0;
-
- if (argc > 1) {
- static const char import_mode[] = "--import-immediate=";
- static const char format[] = "--import-format=";
- static const char y_inverted[] = "--y-inverted=";
- for (i = 1; i < argc; i++) {
- if (!strncmp(argv[i], import_mode,
- sizeof(import_mode) - 1)) {
- if (is_true(argv[i] + sizeof(import_mode) - 1))
- opts |= OPT_IMMEDIATE;
- }
- else if (!strncmp(argv[i], format, sizeof(format) - 1)) {
- import_format = parse_import_format(argv[i]
- + sizeof(format) - 1);
- }
- else if (!strncmp(argv[i], y_inverted,
- sizeof(y_inverted) - 1)) {
- if (is_true(argv[i] + sizeof(y_inverted) - 1))
- opts |= OPT_Y_INVERTED;
- }
- else {
- print_usage_and_exit();
- }
+ int c, option_index, ret = 0;
+
+ static struct option long_options[] = {
+ {"import-format", required_argument, 0, 'f' },
+ {"import-immediate", required_argument, 0, 'i' },
+ {"y-inverted", required_argument, 0, 'y' },
+ {"help", no_argument , 0, 'h' },
+ {0, 0, 0, 0}
+ };
+
+ while ((c = getopt_long(argc, argv, "hf:i:y:",
+ long_options, &option_index)) != -1) {
+ switch (c) {
+ case 'f':
+ import_format = parse_import_format(optarg);
+ break;
+ case 'i':
+ if (is_true(optarg))
+ opts |= OPT_IMMEDIATE;
+ break;
+ case 'y':
+ if (is_true(optarg))
+ opts |= OPT_Y_INVERTED;
+ break;
+ default:
+ print_usage_and_exit();
}
}