Fixed #81 and issues in #98 by not using pkgman in mac os

This commit is contained in:
TheDarkBug 2021-05-31 01:04:32 +02:00
parent e5d1d26f27
commit ee077ce0c8

View file

@ -220,11 +220,7 @@ int pkgman()
{ // this is just a function that returns the total of installed packages { // this is just a function that returns the total of installed packages
int total = 0; int total = 0;
#ifdef __APPLE__ #ifndef __APPLE__ // this function is not used on mac os because it causes lots of problems
// we use a completely different struct because some commands in the other actually work in mac os, but they are not what you would expect (try running "apt"), but still doesn't work, maybe because of popen()
struct package_manager pkgmans[] = {
{"ls $(brew --cellar)| wc -l | sed \"s/ //g\" && touch test", "(brew)"}};
#else
struct package_manager pkgmans[] = { struct package_manager pkgmans[] = {
{"apt list --installed 2> /dev/null | wc -l", "(apt)"}, {"apt list --installed 2> /dev/null | wc -l", "(apt)"},
{"apk info 2> /dev/null | wc -l", "(apk)"}, {"apk info 2> /dev/null | wc -l", "(apk)"},
@ -238,8 +234,6 @@ int pkgman()
{"rpm -qa --last 2> /dev/null | wc -l", "(rpm)"}, {"rpm -qa --last 2> /dev/null | wc -l", "(rpm)"},
{"xbps-query -l 2> /dev/null | wc -l", "(xbps)"}, {"xbps-query -l 2> /dev/null | wc -l", "(xbps)"},
{"zypper se --installed-only 2> /dev/null | wc -l", "(zypper)"}}; {"zypper se --installed-only 2> /dev/null | wc -l", "(zypper)"}};
#endif
const unsigned long pkgman_count = sizeof(pkgmans) / sizeof(pkgmans[0]); const unsigned long pkgman_count = sizeof(pkgmans) / sizeof(pkgmans[0]);
// to format the pkgman_name string properly // to format the pkgman_name string properly
@ -270,6 +264,7 @@ int pkgman()
strcat(pkgman_name, current->pkgman_name); // this is the line that breaks mac os, but something strange happens before strcat(pkgman_name, current->pkgman_name); // this is the line that breaks mac os, but something strange happens before
} }
} }
#endif
return total; return total;
} }
@ -323,9 +318,14 @@ void print_info()
if (show_shell) if (show_shell)
printf("\033[18C%s%sSHEWW %s%s\n", printf("\033[18C%s%sSHEWW %s%s\n",
NORMAL, BOLD, NORMAL, shell); NORMAL, BOLD, NORMAL, shell);
#ifdef __APPLE__
if (show_pkgs)
system("ls $(brew --cellar) | wc -l | awk -F' ' '{print \" \x1b[34mw w \x1b[0m\x1b[1mPKGS\x1b[0m \"$1 \" (brew)\"}'");
#else
if (show_pkgs) if (show_pkgs)
printf("\033[18C%s%sPKGS %s%s%d%s %s\n", printf("\033[18C%s%sPKGS %s%s%d%s %s\n",
NORMAL, BOLD, NORMAL, NORMAL, pkgs, ":", pkgman_name); NORMAL, BOLD, NORMAL, NORMAL, pkgs, ":", pkgman_name);
#endif
if (show_uptime) if (show_uptime)
{ {
#ifdef __APPLE__ #ifdef __APPLE__
@ -364,7 +364,8 @@ void get_info()
if (os_release || iscygwin == 1) if (os_release || iscygwin == 1)
{ // get normal vars { // get normal vars
if(iscygwin == 0) { if (iscygwin == 0)
{
while (fgets(line, sizeof(line), os_release)) while (fgets(line, sizeof(line), os_release))
if (sscanf(line, "\nID=%s", version_name)) if (sscanf(line, "\nID=%s", version_name))
break; break;
@ -456,8 +457,11 @@ void get_info()
mem_used_fp = popen("wmic OS GET FreePhysicalMemory | sed -n 2p", "r"); mem_used_fp = popen("wmic OS GET FreePhysicalMemory | sed -n 2p", "r");
mem_total_fp = popen("wmic ComputerSystem GET TotalPhysicalMemory | sed -n 2p", "r"); mem_total_fp = popen("wmic ComputerSystem GET TotalPhysicalMemory | sed -n 2p", "r");
char mem_used_ch[2137], mem_total_ch[2137]; char mem_used_ch[2137], mem_total_ch[2137];
while (fgets(mem_used_ch, sizeof(mem_used_ch), mem_used_fp) != NULL) { while (fgets(mem_used_ch, sizeof(mem_used_ch), mem_used_fp) != NULL)
while (fgets(mem_total_ch, sizeof(mem_total_ch), mem_total_fp) != NULL) {} {
while (fgets(mem_total_ch, sizeof(mem_total_ch), mem_total_fp) != NULL)
{
}
} }
pclose(mem_used_fp); pclose(mem_used_fp);