From fa76ad43732634545971fa202024f8fd2789c7f3 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 10 Jul 2016 23:11:21 +0200 Subject: Add adjustment method name parser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/gammad.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) 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) { @@ -97,6 +97,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 * -- cgit v1.2.3-70-g09d2