Skip to content

Commit

Permalink
chore: Small cleanup to improve readability
Browse files Browse the repository at this point in the history
  • Loading branch information
lajp committed Jun 25, 2023
1 parent 71df730 commit aa62173
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions blmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ usage()
int
main(int argc, char** argv)
{
int max_brightness;
int current_brightness;
int max_brightness, current_brightness;

FILE* max_brightness_file = fopen(BACKLIGHT_PATH_BASE "max_brightness", "r");
if (!max_brightness_file) {
Expand All @@ -40,7 +39,7 @@ main(int argc, char** argv)
fclose(current_brightness_file);

if (argc < 2) {
printf("%d%%\n", (int)((double)current_brightness/(double)max_brightness*(double)100));
printf("%d%%\n", (int)round(((double)current_brightness / (double)max_brightness * 100.0)));
return EXIT_SUCCESS;
}

Expand All @@ -56,22 +55,22 @@ main(int argc, char** argv)

if (sscanf(&argv[1][1], "%d", &brightness_change) > 0) {
if (strchr(&argv[1][1], '%')) {
brightness_change *= ((double)max_brightness/(double)100);
brightness_change *= ((double)max_brightness / 100.0);
}
brightness = current_brightness + brightness_change*change_mult;
brightness = current_brightness + brightness_change * change_mult;
} else {
fprintf(stderr, "Unknown argument provded: %s\n", argv[1]);
fprintf(stderr, "Unknown argument provided: %s\n", argv[1]);
usage();
}
break;
}
default:
if (sscanf(argv[1], "%d", &brightness) > 0) {
if (strchr(argv[1], '%')) {
brightness = round((double)brightness*((double)max_brightness/(double)100));
brightness = round((double)brightness * ((double)max_brightness / 100.0));
}
} else {
fprintf(stderr, "Unknown argument provded: %s\n", argv[1]);
fprintf(stderr, "Unknown argument provided: %s\n", argv[1]);
usage();
}
break;
Expand Down

0 comments on commit aa62173

Please sign in to comment.