backlight: accept '%' in the brightness input value

Improve friendlyness of the command line by accepting the percent brightness
in both format: with or without a trailing '%'

Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D26692
This commit is contained in:
Baptiste Daroussin 2020-10-06 08:05:19 +00:00
parent 194d562872
commit 4d1308f49b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=366471
2 changed files with 5 additions and 1 deletions

View file

@ -22,7 +22,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd October 02, 2020
.Dd October 06, 2020
.Dt BACKLIGHT 8
.Os
.Sh NAME
@ -63,6 +63,7 @@ When querying the brightness level only print the value.
Query information about the backlight (name, type).
.It Ar value
Set the brightness level to this value, must be between 0 and 100.
A trailing '%' is valid.
.It Ar incr | +
.Op Ar value
Decrement the backlight level.

View file

@ -144,6 +144,9 @@ main(int argc, char *argv[])
action = BACKLIGHT_SET_BRIGHTNESS;
if (argc == 1) {
/* ignore a trailing % for user friendlyness */
if (argv[0][strlen(argv[0]) - 1] == '%')
argv[0][strlen(argv[0]) - 1] = '\0';
percent = strtonum(argv[0], 0, 100, &percent_error);
if (percent_error)
errx(1, "Cannot parse brightness level %s: %s",