diff options
author | Mattias Andrée <m@maandree.se> | 2025-02-05 18:49:19 +0100 |
---|---|---|
committer | Mattias Andrée <m@maandree.se> | 2025-02-05 18:49:19 +0100 |
commit | 9e1aef46b9ea5fc51c19c2a475bc466e25d502d5 (patch) | |
tree | 35d67e7f437acf1a0c90eb996d3be8cc40798671 /radharc.c | |
parent | Add support for -t get/? and transition from applied temperature when starting (diff) | |
download | radharc-9e1aef46b9ea5fc51c19c2a475bc466e25d502d5.tar.gz radharc-9e1aef46b9ea5fc51c19c2a475bc466e25d502d5.tar.bz2 radharc-9e1aef46b9ea5fc51c19c2a475bc466e25d502d5.tar.xz |
Add -W linear
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'radharc.c')
-rw-r--r-- | radharc.c | 68 |
1 files changed, 62 insertions, 6 deletions
@@ -12,11 +12,7 @@ #include <libred.h> -#if 0 -# define IF_LINEARISING(...) __VA_ARGS__ -#else -# define IF_LINEARISING(...) ((void)0) -#endif +#define IF_LINEARISING(...) do { if (linearise) { __VA_ARGS__; } } while (0) /** @@ -106,6 +102,14 @@ static int xflag = 0; */ static int print_temperature = 0; +/** + * Whether the effect shall be put into an embedded + * cg-linear(1) equivalent block. This is generally + * a good idea unless you are using cg-linear(1) + * explicitly. + */ +static int linearise = 1; + /** * Set to 1 by `handle_args` if the used arguments @@ -167,7 +171,7 @@ usage(void) fprintf(stderr, "usage: %s [-M method] [-S site] [-c crtc] ... [-R rule] [-p priority]" " [-f fade-in] [-F fade-out] [-h [high-temp][@high-elev]] [-l [low-temp][@low-elev]]" - " (-L latitude:longitude | -t temperature [-d] | -x)\n", argv0); + " [-W options] ... (-L latitude:longitude | -t temperature [-d] | -x)\n", argv0); exit(1); } @@ -194,6 +198,55 @@ parse_double(double *out, const char *str) /** + * Parse -W argument + */ +static void +vendor_options(char *arg) +{ + char *next, *value; + + for (; arg; arg = next) { + while (*arg == ',') + arg++; + if (!*arg) + break; + + next = strchr(arg, ','); + if (next) + *next++ = '\0'; + + value = strchr(arg, '='); + if (value) + *value++ = '\0'; + + if (!strcmp(arg, "linear")) { + if (!value) + goto missing_value; + else if (!strcmp(value, "yes")) + linearise = 1; + else if (!strcmp(value, "no")) + linearise = 0; + else + goto invalid_value; + } else { + fprintf(stderr, "%s: invalid -W option: %s\n", argv0, arg); + exit(1); + } + } + + return; + +missing_value: + fprintf(stderr, "%s: invalid -W option '%s' is missing associated value\n", argv0, arg); + exit(1); + +invalid_value: + fprintf(stderr, "%s: invalid value on -W option '%s': %s\n", argv0, arg, value); + exit(1); +} + + +/** * Handle a command line option * * @param opt The option, it is a NUL-terminate two-character @@ -269,6 +322,9 @@ handle_opt(char *opt, char *arg) xflag = 0; } return 1; + case 'W': + vendor_options(arg); + return 1; case 'x': xflag = 1; dflag = 0; |