-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
18 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,24 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#define ERROR(...) do { fprintf(stderr, __VA_ARGS__); return 2; } while(0) | ||
|
||
/* silahkan edit 'DEVICES' dan sesuaikan dengan devices yang kalian punya */ | ||
#define TARGET "/sys/class/backlight/DEVICES/brightness" | ||
|
||
int char_toint(char *arr) { | ||
int num = 0; | ||
short digit, mult = 1, offset = 0; | ||
if (*arr == '-') { | ||
mult = -1; | ||
offset++; | ||
} else if (*arr == '+') { | ||
offset++; | ||
} | ||
while (*(arr + offset) != '\0') { | ||
digit = * (arr + offset) - 48; | ||
num = num * 10 + digit; | ||
offset++; | ||
} | ||
return num * mult; | ||
} | ||
int main(int argc, char **argv) { | ||
|
||
void int_tochar(int num, char *buf) { | ||
short digit, offset = 0; | ||
int save = num, div = 1; | ||
while (save > 0) { | ||
div *= 10; | ||
save /= 10; | ||
} | ||
div /= 10; | ||
if(argc != 2) | ||
ERROR("[%s] untuk cara penggunaan silaskan baca manpage 'man %s'\n", argv[0], argv[0]); | ||
|
||
while (div >= 1) { | ||
digit = num / div % 10; | ||
div /= 10; | ||
*(buf + offset) = digit + 48; | ||
offset++; | ||
} | ||
*(buf + offset) = '\0'; | ||
} | ||
FILE *device_file; | ||
device_file = fopen(TARGET, "w"); | ||
|
||
if(device_file == NULL) | ||
ERROR("[%s] silahkan edit DEVICES di main.c! dan jalankan sebagai root!\n", argv[0]); | ||
|
||
fprintf(device_file, "%s", argv[1]); | ||
fclose(device_file); | ||
|
||
int main(int argc, char *argv[]) { | ||
if (argc == 2) { | ||
FILE *korban; | ||
if (argv[1][0] != '-' && argv[1][0] != '+') { | ||
korban = fopen(TARGET, "w"); | ||
fprintf(korban, "%s", argv[1]); | ||
fclose(korban); | ||
} else { | ||
char buff[4]; | ||
korban = fopen(TARGET, "r"); | ||
fscanf(korban, "%s", buff); | ||
fclose(korban); | ||
int d = char_toint(buff); | ||
int step = char_toint(argv[1]); | ||
d += step; | ||
int_tochar(d, buff); | ||
korban = fopen(TARGET, "w"); | ||
fprintf(korban, "%s", buff); | ||
fclose(korban); | ||
} | ||
return 0; | ||
} else { | ||
printf("please input a valid number and run as root \n"); | ||
return 0; | ||
} | ||
return 0; | ||
} |