aboutsummaryrefslogtreecommitdiffstats
path: root/src/gammad.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-07-10 23:18:59 +0200
committerMattias Andrée <maandree@kth.se>2016-07-10 23:18:59 +0200
commit4e794f661261994c8247a2f399c371aad9c71f7a (patch)
tree609722081f17ba4907d4edfb7e4e91beb3e475fa /src/gammad.c
parentAdd adjustment method name parser (diff)
downloadcoopgammad-4e794f661261994c8247a2f399c371aad9c71f7a.tar.gz
coopgammad-4e794f661261994c8247a2f399c371aad9c71f7a.tar.bz2
coopgammad-4e794f661261994c8247a2f399c371aad9c71f7a.tar.xz
Add command line parser
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/gammad.c')
-rw-r--r--src/gammad.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/gammad.c b/src/gammad.c
index 15e8359..97f2d56 100644
--- a/src/gammad.c
+++ b/src/gammad.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <unistd.h>
+#include "arg.h"
#include "output.h"
#include "util.h"
@@ -32,7 +33,7 @@
/**
* The name of the process
*/
-const char* argv0;
+char* argv0;
@@ -161,25 +162,54 @@ static char* get_crtc_name(libgamma_crtc_information_t* info, libgamma_crtc_stat
}
+/**
+ * Print usage information and exit
+ */
+static void usage(void)
+{
+ printf("Usage: %s [-m method] [-s site] [-p]\n", argv0);
+ exit(1);
+}
+
+
int main(int argc, char** argv)
{
- int method, gerror, rc = 1;
+ int method = -1, gerror, rc = 1, preserve = 0;
+ char *sitename = NULL;
libgamma_site_state_t site;
libgamma_partition_state_t* partitions = NULL;
libgamma_crtc_state_t* crtcs = NULL;
struct output* outputs = NULL;
size_t i, j, n, n0, crtcs_n = 0;
- argv0 = argc ? argv[0] : "gammad";
-
memset(&site, 0, sizeof(site));
+ ARGBEGIN
+ {
+ case 's':
+ sitename = EARGF(usage());
+ break;
+ case 'm':
+ method = get_method(EARGF(usage()));
+ if (method < 0)
+ goto fail;
+ break;
+ case 'p':
+ preserve = 1;
+ break;
+ default:
+ usage();
+ }
+ ARGEND;
+ if (argc > 0)
+ usage();
+
/* Get method */
- if (libgamma_list_methods(&method, 1, 0) < 1)
+ if ((method < 0) && (libgamma_list_methods(&method, 1, 0) < 1))
return fprintf(stderr, "%s: no adjustment method available\n", argv0), 1;
/* Get site */
- if ((gerror = libgamma_site_initialise(&site, method, NULL)))
+ if ((gerror = libgamma_site_initialise(&site, method, sitename)))
goto fail_libgamma;
/* Get partitions */