diff options
author | Thomas Voss <mail@thomasvoss.com> | 2022-11-13 09:34:39 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2022-11-13 09:34:39 +0100 |
commit | 8f60ff9a434f90cadb4d4a1e8564a4e0bf8741f0 (patch) | |
tree | 28e2254660978239becb30e8195f03efd0be25a6 | |
parent | a503d1703f92ec3aa67f2aefdfb3488c340e14f8 (diff) |
Support long options
-rw-r--r-- | lux.c | 23 |
1 files changed, 19 insertions, 4 deletions
@@ -15,12 +15,11 @@ * PERFORMANCE OF THIS SOFTWARE. */ -#define _POSIX_C_SOURCE 2 - #include <err.h> +#include <getopt.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <lux.h> @@ -37,11 +36,27 @@ main(int argc, char **argv) int br, max, opt; double pr; lux_t disp; + const char *optstr = "d:D:gGi:I:s:S:"; + static struct option longopts[] = { + {"decrease", required_argument, NULL, 'd'}, + {"decrease-percent", required_argument, NULL, 'D'}, + {"get", no_argument, NULL, 'g'}, + {"get-percent", no_argument, NULL, 'G'}, + {"increase", required_argument, NULL, 'i'}, + {"increase-percent", required_argument, NULL, 'I'}, + {"set", required_argument, NULL, 's'}, + {"set-percent", required_argument, NULL, 'S'}, + {NULL, 0, NULL, 0} + }; luxinit(&disp); if (argc == 1) goto Gflag; - else while ((opt = getopt(argc, argv, ":d:D:gGi:I:s:S:")) != -1) { + else while (true) { + opt = getopt_long(argc, argv, optstr, longopts, NULL); + if (opt == -1) + break; + switch (opt) { case 'g': if ((br = luxget(&disp)) == -1) |