Possible fix for #27
This commit is contained in:
parent
e2b8971577
commit
da1b4470a1
1 changed files with 28 additions and 26 deletions
54
uwufetch.c
54
uwufetch.c
|
@ -85,42 +85,44 @@ int main(int argc, char *argv[]) {
|
||||||
int pkgman() { // this is just a function that returns the total of installed packages
|
int pkgman() { // this is just a function that returns the total of installed packages
|
||||||
int apt, apk, dnf, emerge, flatpak, guix, nix, pacman, rpm, xbps, total = 0;
|
int apt, apk, dnf, emerge, flatpak, guix, nix, pacman, rpm, xbps, total = 0;
|
||||||
|
|
||||||
FILE *file[9];
|
FILE *file[10]; // when you add a new package manager support, make sure to update the array size.
|
||||||
file[0] = popen("dpkg-query -f '${binary:Package}\n' -W 2> /dev/null | wc -l", "r");
|
file[0] = popen("dpkg-query -f '${binary:Package}\n' -W 2> /dev/null | wc -l", "r");
|
||||||
file[1] = popen("apk info 2> /dev/null | wc -l", "r");
|
file[1] = popen("apk info 2> /dev/null | wc -l", "r");
|
||||||
file[2] = popen("dnf list installed 2> /dev/null | wc -l", "r");
|
file[2] = popen("dnf list installed 2> /dev/null | wc -l", "r");
|
||||||
file[3] = popen("guix package --list-installed 2> /dev/null | wc -l", "r");
|
file[3] = popen("qlist -I 2> /dev/null | wc -l", "r");
|
||||||
file[4] = popen("qlist -I 2> /dev/null | wc -l", "r");
|
file[4] = popen("flatpak list 2> /dev/null | wc -l", "r");
|
||||||
file[5] = popen("flatpak list 2> /dev/null | wc -l", "r");
|
file[5] = popen("guix package --list-installed 2> /dev/null | wc -l", "r");
|
||||||
file[6] = popen("nix-store -q --requisites /run/current-sys_vartem/sw 2> /dev/null | wc -l", "r");
|
file[6] = popen("nix-store -q --requisites /run/current-sys_vartem/sw 2> /dev/null | wc -l", "r");
|
||||||
file[7] = popen("pacman -Qq 2> /dev/null | wc -l", "r");
|
file[7] = popen("pacman -Qq 2> /dev/null | wc -l", "r");
|
||||||
file[8] = popen("rpm -qa --last 2> /dev/null | wc -l", "r");
|
file[8] = popen("rpm -qa --last 2> /dev/null | wc -l", "r");
|
||||||
file[9] = popen("xbps-query -l 2> /dev/null | wc -l", "r");
|
file[9] = popen("xbps-query -l 2> /dev/null | wc -l", "r");
|
||||||
|
|
||||||
fscanf(file[0], "%d", &apt);
|
// the if statements are there for error handling and for preventing the #27 issue
|
||||||
fscanf(file[1], "%d", &apk);
|
if (fscanf(file[0], "%d", &apt) == 3) apt = 0;
|
||||||
fscanf(file[2], "%d", &dnf);
|
if (fscanf(file[1], "%d", &apk) == 3) apk = 0;
|
||||||
fscanf(file[3], "%d", &emerge);
|
if (fscanf(file[2], "%d", &dnf) == 3) dnf = 0;
|
||||||
fscanf(file[4], "%d", &flatpak);
|
if (fscanf(file[3], "%d", &emerge) == 3) emerge = 0;
|
||||||
fscanf(file[5], "%d", &guix);
|
if (fscanf(file[4], "%d", &flatpak) == 3) flatpak = 0;
|
||||||
fscanf(file[6], "%d", &nix);
|
if (fscanf(file[5], "%d", &guix) == 3) guix = 0;
|
||||||
fscanf(file[7], "%d", &pacman);
|
if (fscanf(file[6], "%d", &nix) == 3) nix = 0;
|
||||||
fscanf(file[8], "%d", &rpm);
|
if (fscanf(file[7], "%d", &pacman) == 3) pacman = 0;
|
||||||
fscanf(file[9], "%d", &xbps);
|
if (fscanf(file[8], "%d", &rpm) == 3) rpm = 0;
|
||||||
|
if (fscanf(file[9], "%d", &xbps) == 3) xbps = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) fclose(file[i]);
|
for (int i = 0; i < 8; i++) fclose(file[i]);
|
||||||
|
|
||||||
#define ADD_PACKAGES(package_count, pkgman_to_add) if (package_count > 0) { total += package_count; strcat(pkgman_name, pkgman_to_add); }
|
#define ADD_PKGMAN_NAME(package_count, pkgman_to_add) if (package_count > 0) { total += package_count; strcat(pkgman_name, pkgman_to_add); }
|
||||||
ADD_PACKAGES(apt, "(apt)")
|
ADD_PKGMAN_NAME(apt, "(apt)")
|
||||||
ADD_PACKAGES(apk, "(apk)")
|
ADD_PKGMAN_NAME(apk, "(apk)")
|
||||||
ADD_PACKAGES(dnf, "(dnf)")
|
ADD_PKGMAN_NAME(dnf, "(dnf)")
|
||||||
ADD_PACKAGES(emerge, "(emerge)")
|
ADD_PKGMAN_NAME(emerge, "(emerge)")
|
||||||
ADD_PACKAGES(flatpak,"(flatpak)")
|
ADD_PKGMAN_NAME(flatpak,"(flatpak)")
|
||||||
ADD_PACKAGES(guix ,"(guix)")
|
ADD_PKGMAN_NAME(guix ,"(guix)")
|
||||||
ADD_PACKAGES(nix, "(nix)")
|
ADD_PKGMAN_NAME(nix, "(nix)")
|
||||||
ADD_PACKAGES(pacman, "(pacman)")
|
ADD_PKGMAN_NAME(pacman, "(pacman)")
|
||||||
ADD_PACKAGES(rpm, "(rpm)")
|
ADD_PKGMAN_NAME(rpm, "(rpm)")
|
||||||
ADD_PACKAGES(xbps, "(xbps)")
|
ADD_PKGMAN_NAME(xbps, "(xbps)")
|
||||||
#undef ADD_PACKAGES
|
#undef ADD_PKGMAN_NAME
|
||||||
|
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue