E: Fix nasty formatting in backlight code.

SVN revision: 61612
This commit is contained in:
Christopher Michael 2011-07-23 17:46:25 +00:00
parent b86e5d282f
commit c13c53af23
1 changed files with 15 additions and 34 deletions

View File

@ -57,8 +57,7 @@ write_file(const char *file, int val)
/* externally accessible functions */ /* externally accessible functions */
int int
main(int argc, main(int argc, char **argv)
char **argv)
{ {
int i; int i;
int level; int level;
@ -72,21 +71,15 @@ main(int argc,
(!strcmp(argv[i], "-help")) || (!strcmp(argv[i], "-help")) ||
(!strcmp(argv[i], "--help"))) (!strcmp(argv[i], "--help")))
{ {
printf( printf("This is an internal tool for Enlightenment.\n"
"This is an internal tool for Enlightenment.\n" "do not use it.\n");
"do not use it.\n"
);
exit(0); exit(0);
} }
} }
if (argc == 2) if (argc == 2)
{ level = atoi(argv[1]);
level = atoi(argv[1]);
}
else else
{ exit(1);
exit(1);
}
if (setuid(0) != 0) if (setuid(0) != 0)
{ {
@ -99,7 +92,7 @@ main(int argc,
exit(7); exit(7);
} }
maxstr = read_file("/sys/devices/virtual/backlight/acpi_video0/max_brightness"); maxstr = read_file("/sys/devices/virtual/backlight/acpi_video0/max_brightness_max");
if (maxstr) if (maxstr)
{ {
maxlevel = atoi(maxstr); maxlevel = atoi(maxstr);
@ -110,7 +103,8 @@ main(int argc,
} }
else else
{ {
snprintf(file, sizeof(file), "/sys/devices/virtual/backlight/acpi_video0/brightness"); snprintf(file, sizeof(file),
"/sys/devices/virtual/backlight/acpi_video0/brightness");
free(maxstr); free(maxstr);
maxstr = NULL; maxstr = NULL;
} }
@ -127,7 +121,9 @@ main(int argc,
{ {
char buf[4096]; char buf[4096];
snprintf(buf, sizeof(buf), "/sys/devices/virtual/backlight/%s/max_brightness", dp->d_name); snprintf(buf, sizeof(buf),
"/sys/devices/virtual/backlight/%s/max_brightness",
dp->d_name);
maxstr = read_file(buf); maxstr = read_file(buf);
if (maxstr) if (maxstr)
{ {
@ -139,7 +135,9 @@ main(int argc,
} }
else else
{ {
snprintf(file, sizeof(file), "/sys/devices/virtual/backlight/%s/brightness", dp->d_name); snprintf(file, sizeof(file),
"/sys/devices/virtual/backlight/%s/brightness",
dp->d_name);
free(maxstr); free(maxstr);
maxstr = NULL; maxstr = NULL;
break; break;
@ -149,23 +147,6 @@ main(int argc,
} }
closedir(dirp); closedir(dirp);
} }
if (maxlevel <= 0)
{
struct stat st;
snprintf(file, sizeof(file), "/sys/class/leds/lcd-backlight/brightness");
if (stat(file, &st) == 0)
{
maxlevel = 255;
maxstr = read_file("/sys/devices/leds/lcd-backlight/max_brightness");
if (maxstr)
{
maxlevel = atoi(maxstr);
free(maxstr);
if (maxlevel <= 0) maxlevel = 255;
}
}
}
if (maxlevel > 0) if (maxlevel > 0)
{ {
curlevel = ((maxlevel * level) + (500 / maxlevel)) / 1000; curlevel = ((maxlevel * level) + (500 / maxlevel)) / 1000;