From d41ce26d029a3bc11d0154087257d44926f78c44 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 19 Dec 2019 13:32:59 +0100 Subject: drminfo: start getopt_long --- drminfo.c | 60 +++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/drminfo.c b/drminfo.c index a1ed3dc..60c8901 100644 --- a/drminfo.c +++ b/drminfo.c @@ -440,23 +440,53 @@ static void usage(FILE *fp) "usage: drminfo [ options ]\n" "\n" "options:\n" - " -h print this text\n" - " -c pick card\n" - " -a print all card info\n" - " -A print all card info, with plane modifiers\n" - " -m print misc card info\n" - " -s print capabilities\n" - " -o print supported outputs (crtcs)\n" - " -p print supported planes\n" - " -P print supported planes, with modifiers\n" - " -f print supported formats\n" - " -F print testable (drmtest) formats\n" - " -r list properties\n" - " -l list all known formats\n" - " -L get a drm lease for output\n" + " -h | --help print this text\n" + " -c | --card pick card\n" + " --lease get a drm lease for output\n" + "\n" + " -a print all card info\n" + " -A print all card info, with plane modifiers\n" + " -m print misc card info\n" + " -s print capabilities\n" + " -o print supported outputs (crtcs)\n" + " -p print supported planes\n" + " -P print supported planes, with modifiers\n" + " -f print supported formats\n" + " -F print testable (drmtest) formats\n" + " -r list properties\n" + " -l | --list-formats list all known formats\n" "\n"); } +enum { + OPT_LONG_LEASE = 0x100, +}; + +struct option long_opts[] = { + { + /* --- no argument --- */ + .name = "help", + .has_arg = false, + .val = 'h', + },{ + .name = "list-formats", + .has_arg = false, + .val = 'l', + },{ + + /* --- with argument --- */ + .name = "card", + .has_arg = true, + .val = 'c', + },{ + .name = "lease", + .has_arg = true, + .val = OPT_LONG_LEASE, + },{ + /* end of list */ + } +}; + int main(int argc, char **argv) { int card = 0; @@ -473,7 +503,7 @@ int main(int argc, char **argv) char *columns; for (;;) { - c = getopt(argc, argv, "hlaAmsopPfFrL:c:"); + c = getopt(argc, argv, "hlaAmsopPfFrc:"); if (c == -1) break; switch (c) { -- cgit