diff options
author | Mattias Andrée <maandree@kth.se> | 2016-07-10 23:11:21 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2016-07-10 23:11:21 +0200 |
commit | fa76ad43732634545971fa202024f8fd2789c7f3 (patch) | |
tree | b8e5e587aa5711f08b234d808a7931bd977824b7 | |
parent | Get the pathname of the socket (diff) | |
download | coopgammad-fa76ad43732634545971fa202024f8fd2789c7f3.tar.gz coopgammad-fa76ad43732634545971fa202024f8fd2789c7f3.tar.bz2 coopgammad-fa76ad43732634545971fa202024f8fd2789c7f3.tar.xz |
Add adjustment method name parser
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r-- | src/gammad.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/gammad.c b/src/gammad.c index 7edc119..15e8359 100644 --- a/src/gammad.c +++ b/src/gammad.c @@ -40,7 +40,7 @@ const char* argv0; * Get the pathname of the socket * * @param site The site - * @return The pathname of the socket + * @return The pathname of the socket, `NULL` on error */ static char* get_socket_pathname(libgamma_site_state_t* site) { @@ -98,6 +98,42 @@ static char* get_socket_pathname(libgamma_site_state_t* site) /** + * Parse adjustment method name (or stringised number) + * + * @param arg The adjustment method name (or stringised number) + * @return The adjustment method, -1 (negative) on error + */ +static int get_method(char* arg) +{ +#if LIBGAMMA_METHOD_MAX > 5 +# warning libgamma has added more adjustment methods +#endif + + char* p; + + if (!strcmp(arg, "dummy")) return LIBGAMMA_METHOD_DUMMY; + if (!strcmp(arg, "randr")) return LIBGAMMA_METHOD_X_RANDR; + if (!strcmp(arg, "vidmode")) return LIBGAMMA_METHOD_X_VIDMODE; + if (!strcmp(arg, "drm")) return LIBGAMMA_METHOD_LINUX_DRM; + if (!strcmp(arg, "gdi")) return LIBGAMMA_METHOD_W32_GDI; + if (!strcmp(arg, "quartz")) return LIBGAMMA_METHOD_QUARTZ_CORE_GRAPHICS; + + if (!*arg || (/* avoid overflow: */ strlen(arg) > 4)) + goto bad; + for (p = arg; *p; p++) + if (('0' > *p) || (*p > '9')) + goto bad; + + return atoi(arg); + + bad: + fprintf(stderr, "%s: unrecognised adjustment method name: %s\n", argv0, arg); + errno = 0; + return -1; +} + + +/** * Get the name of a CRTC * * @param info Information about the CRTC |