diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-01-26 12:04:06 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-01-26 12:04:06 +0100 |
commit | a2a7a7ec5ee97eff37e968e0577d70af9eb5a20e (patch) | |
tree | e8467074cdcff60a670cc02bff02f4866fb90b40 /src | |
parent | update dist (diff) | |
download | adjbacklight-a2a7a7ec5ee97eff37e968e0577d70af9eb5a20e.tar.gz adjbacklight-a2a7a7ec5ee97eff37e968e0577d70af9eb5a20e.tar.bz2 adjbacklight-a2a7a7ec5ee97eff37e968e0577d70af9eb5a20e.tar.xz |
some small fixes + add -h and --help
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/adjbacklight.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/adjbacklight.c b/src/adjbacklight.c index 98e5bdf..53f3013 100644 --- a/src/adjbacklight.c +++ b/src/adjbacklight.c @@ -177,7 +177,7 @@ int main(int argc, char** argv) int i, j; pid_t pid = 0; char* set = NULL; - int get = 0, all = 0, cols = 80, ndevices = 0; + int get = 0, help = 0, all = 0, cols = 80, ndevices = 0; char** devices = alloca(argc * sizeof(char*)); @@ -188,7 +188,9 @@ int main(int argc, char** argv) { #define T(S) (!strcmp(arg, S)) arg = *(argv + i); - if (T("-a") || T("--all")) + if (T("-h") || T("--help")) + help = 1; + else if (T("-a") || T("--all")) all = 1; else if (T("-c") || T("--copyright") || T("--copying")) { @@ -255,7 +257,8 @@ int main(int argc, char** argv) } #undef T } - if ((all + ndevices + get == 0) && !set) + fflush(stderr); + if (help || ((all + ndevices + get == 0) && !set)) { P("\n"); P("adjbacklight - Convient method for adjusting the backlight on your portable computer"); @@ -494,12 +497,18 @@ int main(int argc, char** argv) free(space); } else if (get) - { - brightness *= 100.f; - brightness /= nbrightness; - printf("%.2f%%\n", brightness); - fflush(stdout); - } + if (nbrightness) + { + brightness *= 100.f; + brightness /= nbrightness; + printf("%.2f%%\n", brightness); + fflush(stdout); + } + else + { + printf("%s\n", "100.00%"); + fflush(stdout); + } } @@ -548,6 +557,9 @@ static int isnumerical(const char* str) case '%': p++; break; + + default: + return 0; } } return p <= 2; |