From d74e39512729532197f83b286bea41a51c5f1472 Mon Sep 17 00:00:00 2001 From: zegolem Date: Wed, 10 Mar 2021 17:56:38 +0100 Subject: [PATCH 1/2] pkgman(): Created macro to add package counts. This makes the code cleaner and more readable, and should make it easier to add more package managers in the future. I think this whole function should be refactored to use more macros, or even one big macro that makes it so that we can add a new package manager in a single line, rather than modifying so much of the code. --- uwufetch.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 460af8e..dc53146 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -106,15 +106,17 @@ int pkgman() { // this is just a function that returns the total of installed pa fscanf(file[6], "%d", &rpm); fscanf(file[7], "%d", &xbps); for (int i = 0; i < 8; i++) fclose(file[i]); - - if (apt > 0) { total += apt; strcat(pkgman_name, "(apt)"); } - if (dnf > 0) { total += dnf; strcat(pkgman_name, "(dnf)"); } - if (emerge > 0) { total += emerge; strcat(pkgman_name, "(emerge)"); } - if (flatpak > 0) { total += flatpak; strcat(pkgman_name, "(flatpak)"); } - if (nix > 0) { total += nix; strcat(pkgman_name, "(nix)"); } - if (pacman > 0) { total += pacman; strcat(pkgman_name, "(pacman)"); } - if (rpm > 0) { total += rpm; strcat(pkgman_name, "(rpm)"); } - if (xbps > 0) { total += xbps; strcat(pkgman_name, "(xbps)"); } + +#define ADD_PACKAGES(package_count, pkgman_to_add) if (package_count > 0) { total += package_count; strcat(pkgman_name, pkgman_to_add); } + ADD_PACKAGES(apt, "(apt)") + ADD_PACKAGES(dnf, "(dnf)") + ADD_PACKAGES(emerge, "(emerge)") + ADD_PACKAGES(flatpak,"(flatpak)") + ADD_PACKAGES(nix, "(nix)") + ADD_PACKAGES(pacman, "(pacman)") + ADD_PACKAGES(rpm, "(rpm)") + ADD_PACKAGES(xbps, "(xbps)") +#undef ADD_PACKAGES return total; } @@ -363,4 +365,4 @@ void uwu_name() { // changes distro name to uwufied(?) name // BSD else if (strcmp(version_name, "freebsd") == 0) sprintf(version_name, "%s", "FweeBSD"); else if (strcmp(version_name, "openbsd") == 0) sprintf(version_name, "%s", "OwOpenBSD"); -} \ No newline at end of file +} From 0b3dc4448af50f5315ee9efaa917e79ff8eba726 Mon Sep 17 00:00:00 2001 From: TheDarkBug Date: Wed, 10 Mar 2021 19:29:16 +0100 Subject: [PATCH 2/2] print_info() is now a single printf --- .gitignore | 4 +++- README.md | 2 +- uwufetch.c | 30 +++++++++++++++++++----------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 98f73e9..9087a80 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -uwufetch \ No newline at end of file +uwufetch +*.zip + diff --git a/README.md b/README.md index 5ee3745..3c2525b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A meme system info tool for (almost) all your Linux/Unix-based systems, based on ## Currently supported distros -Nyarch Linuwu, Nyartix Linuwu, Debinyan, Fedowa, GentOwO, Miwint, Myanjawo, Pop OwOs, UwUntu, and Void; Plus Nyandroid; and FweeBSD, and OwOpenBSD. +Nyarch Linuwu, Nyartix Linuwu, Debinyan, Fedowa, GentOwO, Miwint, Myanjawo, Pop OwOs, UwUntu, and OwOid; Plus Nyandroid; and FweeBSD, and OwOpenBSD. ## Building and installation diff --git a/uwufetch.c b/uwufetch.c index 460af8e..e54f666 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -120,15 +120,24 @@ int pkgman() { // this is just a function that returns the total of installed pa } void print_info() { // print collected info - printf("\033[9A\033[18C%s%s%s@%s\n", NORMAL, BOLD, user, host); - printf("\033[17C %s%sOWOS %s%s\n", NORMAL, BOLD, NORMAL, version_name); - printf("\033[17C %s%sKERNEL %s%s %s\n", NORMAL, BOLD, NORMAL, sys_var.release, sys_var.machine); - printf("\033[17C %s%sCPUWU %s%s\n", NORMAL, BOLD, NORMAL, cpu_model); - printf("\033[17C %s%sWAM %s%ldM/%iM\n", NORMAL, BOLD, NORMAL, r_usage.ru_maxrss, ram_max); - printf("\033[17C %s%sSHELL %s%s\n", NORMAL, BOLD, NORMAL, shell); - printf("\033[17C %s%sPKGS %s%s%d %s\n", NORMAL, BOLD, NORMAL, NORMAL, pkgs, pkgman_name); - printf("\033[17C %s%sUWUPTIME %s%lid, %lih, %lim\n", NORMAL, BOLD, NORMAL, sys.uptime/60/60/24, sys.uptime/60/60%24, sys.uptime/60%60); - printf("\033[17C %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); + printf( "\033[9A\033[18C%s%s%s@%s\n" + "\033[17C %s%sOWOS %s%s\n" + "\033[17C %s%sKERNEL %s%s %s\n" + "\033[17C %s%sCPUWU %s%s\n" + "\033[17C %s%sWAM %s%ldM/%iM\n" + "\033[17C %s%sSHELL %s%s\n" + "\033[17C %s%sPKGS %s%s%d %s\n" + "\033[17C %s%sUWUPTIME %s%lid, %lih, %lim\n" + "\033[17C %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", + NORMAL, BOLD, user, host, + NORMAL, BOLD, NORMAL, version_name, + NORMAL, BOLD, NORMAL, sys_var.release, sys_var.machine, + NORMAL, BOLD, NORMAL, cpu_model, + NORMAL, BOLD, NORMAL, r_usage.ru_maxrss, ram_max, + NORMAL, BOLD, NORMAL, shell, + NORMAL, BOLD, NORMAL, NORMAL, pkgs, pkgman_name, + NORMAL, BOLD, NORMAL, sys.uptime/60/60/24, sys.uptime/60/60%24, sys.uptime/60%60, + BOLD, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, NORMAL); } void get_info() { // get all necessary info @@ -193,8 +202,7 @@ void list(char* arg) { // prints distribution list arg, BLUE, NORMAL, BLUE, GREEN, // Arch based colors RED, YELLOW, NORMAL, RED, GREEN, BLUE, // Debian based colors NORMAL, BLUE, PINK, GREEN, WHITE, // Other/spare distributions colors - RED, YELLOW // BSD colors - ); + RED, YELLOW); // BSD colors } void print_ascii() { // prints logo (as ascii art) of the given system. distributions listed alphabetically.