aboutsummaryrefslogtreecommitdiffstats
path: root/radharc.c
diff options
context:
space:
mode:
Diffstat (limited to 'radharc.c')
-rw-r--r--radharc.c68
1 files changed, 62 insertions, 6 deletions
diff --git a/radharc.c b/radharc.c
index 0805b33..ac53ca3 100644
--- a/radharc.c
+++ b/radharc.c
@@ -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;