Just improved optimization.

This commit is contained in:
TheDarkBug 2021-01-19 15:46:09 +01:00
parent b682128323
commit e89ac12eef

71
main.c
View file

@ -33,7 +33,6 @@ int main() {
if (uname(&sys_var) == -1) printf("Ah sh-t, an error\n"); if (uname(&sys_var) == -1) printf("Ah sh-t, an error\n");
if (sysinfo(&sys) == -1) printf("Ah sh-t, an error\n"); if (sysinfo(&sys) == -1) printf("Ah sh-t, an error\n");
char version_name[64]; char version_name[64];
FILE *fos_rel = popen("lsb_release -a | grep Description", "r"); FILE *fos_rel = popen("lsb_release -a | grep Description", "r");
fscanf(fos_rel,"%[^\n]", version_name); fscanf(fos_rel,"%[^\n]", version_name);
@ -46,11 +45,7 @@ int main() {
fclose(fcpu); fclose(fcpu);
memmove(&cpu_model[0], &cpu_model[33], 128); memmove(&cpu_model[0], &cpu_model[33], 128);
int ram_max; int ram_max = sys.totalram * sys.mem_unit / 1048576;
FILE *framm = popen("head -n1 /proc/meminfo | awk '{print $2}'", "r");
fscanf(framm, "%i", &ram_max);
fclose(framm);
ram_max = ram_max / 1024;
int ram_used; int ram_used;
FILE *framu = popen("grep -i MemAvailable /proc/meminfo | awk '{print $2}' ", "r"); FILE *framu = popen("grep -i MemAvailable /proc/meminfo | awk '{print $2}' ", "r");
@ -69,7 +64,7 @@ int main() {
printf("%s / __ \\ %s%sSHELL %s%s\n", BLUE, NORMAL, BOLD, NORMAL, shell); printf("%s / __ \\ %s%sSHELL %s%s\n", BLUE, NORMAL, BOLD, NORMAL, shell);
printf("%s / __| |__-\\ %s%sPKGS %s%s", BLUE, NORMAL, BOLD, NORMAL, NORMAL); pkgman(); printf("%s / __| |__-\\ %s%sPKGS %s%s", BLUE, NORMAL, BOLD, NORMAL, NORMAL); pkgman();
printf("%s /_-'' ''-_\\ %s%sUPTIME %s%lid, %lih, %lim\n", BLUE, NORMAL, BOLD, NORMAL, sys.uptime/60/60/24, sys.uptime/60/60%24, sys.uptime/60%60); printf("%s /_-'' ''-_\\ %s%sUPTIME %s%lid, %lih, %lim\n", BLUE, NORMAL, BOLD, NORMAL, sys.uptime/60/60/24, sys.uptime/60/60%24, sys.uptime/60%60);
printf(" %s%s██%s██%s██%s██%s██%s██%s██%s██%s\n", BOLD, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, NORMAL); printf(" %s%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\u2587\u2587%s\n", BOLD, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, NORMAL);
} }
@ -110,57 +105,57 @@ void pkgman() {
fclose(fxbps); fclose(fxbps);
fclose(fyay); fclose(fyay);
int comma = 0; int pipe = 0;
if (apt > 0) { if (apt > 0) {
if (comma == 1) printf(", "); if (pipe == 1) printf(" | ");
printf("apt: %d", apt); printf("apt %d", apt);
comma = 1; pipe = 1;
} }
if (dnf > 0) { if (dnf > 0) {
if(comma == 1) printf(", "); if(pipe == 1) printf(" | ");
printf("dnf: %d", dnf); printf("dnf %d", dnf);
comma = 1; pipe = 1;
} }
if (emerge > 0) { if (emerge > 0) {
if (comma == 1) printf(", "); if (pipe == 1) printf(" | ");
printf("emerge: %d", emerge); printf("emerge %d", emerge);
comma = 1; pipe = 1;
} }
if (flatpak > 0) { if (flatpak > 0) {
if (comma == 1) printf(", "); if (pipe == 1) printf(" | ");
printf("flatpak: %d", flatpak); printf("flatpak %d", flatpak);
comma = 1; pipe = 1;
} }
if (nix > 0) { if (nix > 0) {
if (comma == 1) printf(", "); if (pipe == 1) printf(" | ");
printf("nix: %d", nix); printf("nix %d", nix);
comma = 1; pipe = 1;
} }
if (pacman > 0) { if (pacman > 0) {
if (comma == 1) printf(", "); if (pipe == 1) printf(" | ");
printf("pacman: %d", pacman); printf("pacman %d", pacman);
comma = 1; pipe = 1;
} }
if (rpm > 0) { if (rpm > 0) {
if (comma == 1) printf(", "); if (pipe == 1) printf(" | ");
printf("rpm: %d", rpm); printf("rpm %d", rpm);
comma = 1; pipe = 1;
} }
if (snap > 0) { if (snap > 0) {
if (comma == 1) printf(", "); if (pipe == 1) printf(" | ");
printf("snap: %d", snap); printf("snap %d", snap);
comma = 1; pipe = 1;
} }
if (xbps > 0) { if (xbps > 0) {
if (comma == 1) printf(", "); if (pipe == 1) printf(" | ");
printf("xbps: %d", xbps); printf("xbps %d", xbps);
comma = 1; pipe = 1;
} }
if (yay > 0) { if (yay > 0) {
if (comma == 1) printf(", "); if (pipe == 1) printf(" | ");
printf("yay: %d", yay); printf("yay %d", yay);
comma = 1; pipe = 1;
} }
printf("\n"); printf("\n");
} }