aboutsummaryrefslogtreecommitdiff
path: root/brightnessctl.c
diff options
context:
space:
mode:
authorGravatar Alexander Kobel <a-kobel@a-kobel.de>2020-04-15 12:49:10 +0200
committerGravatar Hummer12007 <hilobakho@gmail.com>2020-04-20 13:40:18 +0300
commitae0a9eb524e73de4b6d8948c2ff5324ad0174d5f (patch)
tree049dfcae85743a8d6a2fcc8ac6ea98880e5bfe41 /brightnessctl.c
parentc314e068268d3266c2a104fd073eee607e75d0c4 (diff)
Make optarg parsing more robust
Allow -n MIN as equivalent to -nMIN and --min-value=MIN.
Diffstat (limited to 'brightnessctl.c')
-rw-r--r--brightnessctl.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/brightnessctl.c b/brightnessctl.c
index 6045ec3..a042fc8 100644
--- a/brightnessctl.c
+++ b/brightnessctl.c
@@ -121,9 +121,7 @@ int main(int argc, char **argv) {
if (strcmp(name.sysname, "Linux"))
fail("This program only supports Linux.\n");
p.exponent = 1;
- while (1) {
- if ((c = getopt_long(argc, argv, "lqpmn::e::srhVc:d:", options, NULL)) < 0)
- break;
+ while ((c = getopt_long(argc, argv, "lqpmn::e::srhVc:d:", options, NULL)) >= 0) {
switch (c) {
case 'l':
p.list = true;
@@ -146,12 +144,16 @@ int main(int argc, char **argv) {
case 'n':
if (optarg)
p.min = atol(optarg);
+ else if (NULL != argv[optind] && '-' != argv[optind][0])
+ p.min = atol(argv[optind++]);
else
p.min = 1;
break;
case 'e':
if (optarg)
p.exponent = atof(optarg);
+ else if (NULL != argv[optind] && atof(argv[optind]) > 0.0)
+ p.exponent = atol(argv[optind++]);
else
p.exponent = 4;
break;
@@ -643,8 +645,8 @@ Options:\n\
-q, --quiet\t\t\tsuppress output.\n\
-p, --pretend\t\t\tdo not perform write operations.\n\
-m, --machine-readable\tproduce machine-readable output.\n\
- -n, --min-value\t\tset minimum brightness, defaults to 1.\n\
- -e, --exponent[=K]\t\tchanges percentage curve to exponential.\n\
+ -n, --min-value[=MIN]\t\tset minimum brightness (to 1 if MIN is omitted).\n\
+ -e, --exponent[=K]\t\tchanges percentage curve to exponential (to 4 if K is omitted).\n\
-s, --save\t\t\tsave previous state in a temporary file.\n\
-r, --restore\t\t\trestore previous saved state.\n\
-h, --help\t\t\tprint this help.\n\
@@ -665,4 +667,3 @@ Valid values:\n\
percentage delta\t\tExample: 50%%- or +10%%\n\
\n");
}
-