Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
archaes authored Dec 16, 2019
2 parents ed160d9 + 8ce0f81 commit ee67385
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 65 deletions.
10 changes: 2 additions & 8 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
73 changes: 16 additions & 57 deletions main.c
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;
}

0 comments on commit ee67385

Please sign in to comment.