-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgam.c
More file actions
51 lines (51 loc) · 1.06 KB
/
gam.c
File metadata and controls
51 lines (51 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#define GAM_NAME "gam "
#define GAM_VERSION "version 0.1 "
#define GAM_DESC GAM_NAME "- tiny command line utility to change X11 gamma\n"
#define GAM_COPYING "Copyright 2017, Alisa Bedard\n"
#include "gamma.h"
#include <stdlib.h>
#include <unistd.h>
#define GAM_OPTS "g:hrv"
#define GAM_HELP GAM_DESC GAM_COPYING \
"gam -[" GAM_OPTS "] [GAMMA]\n" \
"[GAMMA]\n" \
"-g GAMMA\tset gamma value\n" \
"-r\t\trestore gamma to 1.0\n" \
"-v\t\tshow gam version\n" \
"-h\t\tshow gam usage\n"
int main(int argc, char ** argv)
{
char optstring[] = "g:hrv";
int opt;
while ((opt = getopt(argc, argv, optstring)) != -1)
switch (opt) {
case 'g':
set_gamma:
batwarn_set_gamma(atof(optarg));
return 0;
case 'r':
batwarn_set_gamma(1.0);
return 0;
case 'v':
goto version;
case 'h':
default:
goto usage;
}
if (argc < 2)
goto usage;
optarg=argv[argc - 1];
goto set_gamma;
usage:
#define PRINT(buf) write(1, buf, sizeof(buf))
{
char ubuf[] = GAM_HELP;
PRINT(ubuf);
}
version:
{
char vbuf[] = GAM_NAME GAM_VERSION "\n";
PRINT(vbuf);
}
return 0;
}