diff --git a/README b/README index 604a978..8d8ef7f 100644 --- a/README +++ b/README @@ -4,15 +4,9 @@ kecerahan kontrol kecerahan layar dengan cli #instalasi -sebelum memulai, pastikan 'tcc' sudah tersedia sebagai compiler-nya, -jika belum silahkan instal terlebih dahulu di https://bellard.org/tcc/ -atau instal melalui package manager yang sudah tersedia di OS anda. -======= -========= -#pemasangan -edit terlebih dahulu file main.c dan ganti DEVICES pada line 3: +silahkan clone terlebih dahulu 'git clone git://github.com/owodev/kecerahan.git' -kemudian, edit terlebih dahulu file kecerahan.c dan ganti DEVICES pada line 3: +kemudian, edit file main.c dan ganti DEVICES pada baris 3: # define TARGET "/sys/class/backlight/DEVICES/brightness" lalu ketik: diff --git a/main.c b/main.c index 2dbbe6b..1f9304f 100644 --- a/main.c +++ b/main.c @@ -1,65 +1,24 @@ #include +#include + +#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; }