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.
This commit is contained in:
parent
c53e374e15
commit
d74e395127
1 changed files with 12 additions and 10 deletions
22
uwufetch.c
22
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[6], "%d", &rpm);
|
||||||
fscanf(file[7], "%d", &xbps);
|
fscanf(file[7], "%d", &xbps);
|
||||||
for (int i = 0; i < 8; i++) fclose(file[i]);
|
for (int i = 0; i < 8; i++) fclose(file[i]);
|
||||||
|
|
||||||
if (apt > 0) { total += apt; strcat(pkgman_name, "(apt)"); }
|
#define ADD_PACKAGES(package_count, pkgman_to_add) if (package_count > 0) { total += package_count; strcat(pkgman_name, pkgman_to_add); }
|
||||||
if (dnf > 0) { total += dnf; strcat(pkgman_name, "(dnf)"); }
|
ADD_PACKAGES(apt, "(apt)")
|
||||||
if (emerge > 0) { total += emerge; strcat(pkgman_name, "(emerge)"); }
|
ADD_PACKAGES(dnf, "(dnf)")
|
||||||
if (flatpak > 0) { total += flatpak; strcat(pkgman_name, "(flatpak)"); }
|
ADD_PACKAGES(emerge, "(emerge)")
|
||||||
if (nix > 0) { total += nix; strcat(pkgman_name, "(nix)"); }
|
ADD_PACKAGES(flatpak,"(flatpak)")
|
||||||
if (pacman > 0) { total += pacman; strcat(pkgman_name, "(pacman)"); }
|
ADD_PACKAGES(nix, "(nix)")
|
||||||
if (rpm > 0) { total += rpm; strcat(pkgman_name, "(rpm)"); }
|
ADD_PACKAGES(pacman, "(pacman)")
|
||||||
if (xbps > 0) { total += xbps; strcat(pkgman_name, "(xbps)"); }
|
ADD_PACKAGES(rpm, "(rpm)")
|
||||||
|
ADD_PACKAGES(xbps, "(xbps)")
|
||||||
|
#undef ADD_PACKAGES
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
@ -363,4 +365,4 @@ void uwu_name() { // changes distro name to uwufied(?) name
|
||||||
// BSD
|
// BSD
|
||||||
else if (strcmp(version_name, "freebsd") == 0) sprintf(version_name, "%s", "FweeBSD");
|
else if (strcmp(version_name, "freebsd") == 0) sprintf(version_name, "%s", "FweeBSD");
|
||||||
else if (strcmp(version_name, "openbsd") == 0) sprintf(version_name, "%s", "OwOpenBSD");
|
else if (strcmp(version_name, "openbsd") == 0) sprintf(version_name, "%s", "OwOpenBSD");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue