Fixed build errors on linux (line 356)

This commit is contained in:
TheDarkBug 2021-04-16 10:48:39 +02:00
parent d3822b5c54
commit 4b2f69c166

View file

@ -20,10 +20,10 @@
#include <unistd.h> #include <unistd.h>
#include <getopt.h> #include <getopt.h>
#ifdef __APPLE__ #ifdef __APPLE__
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <time.h> #include <time.h>
#else #else
#include <sys/sysinfo.h> #include <sys/sysinfo.h>
#endif #endif
#include <sys/utsname.h> #include <sys/utsname.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -42,20 +42,20 @@
#define PINK "\x1b[38;5;201m" #define PINK "\x1b[38;5;201m"
#define LPINK "\x1b[38;5;213m" #define LPINK "\x1b[38;5;213m"
#ifdef __APPLE__ #ifdef __APPLE__
// buffers where data fetched from sysctl are stored // buffers where data fetched from sysctl are stored
// CPU // CPU
#define CPUBUFFERLEN 128 #define CPUBUFFERLEN 128
char cpu_buffer[CPUBUFFERLEN]; char cpu_buffer[CPUBUFFERLEN];
size_t cpu_buffer_len = CPUBUFFERLEN; size_t cpu_buffer_len = CPUBUFFERLEN;
// Installed RAM // Installed RAM
int64_t mem_buffer = 0; int64_t mem_buffer = 0;
size_t mem_buffer_len = sizeof(mem_buffer); size_t mem_buffer_len = sizeof(mem_buffer);
// uptime // uptime
struct timeval time_buffer; struct timeval time_buffer;
size_t time_buffer_len = sizeof(time_buffer); size_t time_buffer_len = sizeof(time_buffer);
#endif #endif
struct package_manager struct package_manager
@ -65,7 +65,7 @@ struct package_manager
}; };
struct utsname sys_var; struct utsname sys_var;
#ifndef __APPLE__ #ifndef __APPLE__
struct sysinfo sys; struct sysinfo sys;
#endif #endif
struct winsize win; struct winsize win;
int ram_total, ram_used = 0; int ram_total, ram_used = 0;
@ -207,14 +207,14 @@ int pkgman()
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)"},
{"brew list --formulae 2> /dev/null | wc -l", "(brew)"}, {"brew list --formulae 2> /dev/null | wc -l", "(brew)"},
{"dnf list installed 2> /dev/null | wc -l", "(dnf)"}, {"dnf list installed 2> /dev/null | wc -l", "(dnf)"},
{"qlist -I 2> /dev/null | wc -l", "(emerge)"}, {"qlist -I 2> /dev/null | wc -l", "(emerge)"},
{"flatpak list 2> /dev/null | wc -l", "(flatpack)"}, {"flatpak list 2> /dev/null | wc -l", "(flatpack)"},
{"guix package --list-installed 2> /dev/null | wc -l", "(guix)"}, {"guix package --list-installed 2> /dev/null | wc -l", "(guix)"},
{"nix-store -q --requisites /run/current-sys_vartem/sw 2> /dev/null | wc -l", "(nix)"}, {"nix-store -q --requisites /run/current-sys_vartem/sw 2> /dev/null | wc -l", "(nix)"},
{"pacman -Qq 2> /dev/null | wc -l", "(pacman)"}, {"pacman -Qq 2> /dev/null | wc -l", "(pacman)"},
{"port installed 2> /dev/null | tail -n +2 | wc -l", "(port)"}, {"port installed 2> /dev/null | tail -n +2 | wc -l", "(port)"},
{"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)"}};
@ -242,13 +242,13 @@ int pkgman()
#ifdef __APPLE__ #ifdef __APPLE__
int uptime_mac() int uptime_mac()
{ {
int mib[2] = { CTL_KERN, KERN_BOOTTIME }; int mib[2] = {CTL_KERN, KERN_BOOTTIME};
sysctl(mib, 2, &time_buffer, &time_buffer_len, NULL, 0); sysctl(mib, 2, &time_buffer, &time_buffer_len, NULL, 0);
time_t bsec = time_buffer.tv_sec; time_t bsec = time_buffer.tv_sec;
time_t csec = time(NULL); time_t csec = time(NULL);
return difftime(csec, bsec); return difftime(csec, bsec);
} }
#endif #endif
@ -284,7 +284,7 @@ void print_info()
NORMAL, BOLD, NORMAL, (ram_used), ram_total); NORMAL, BOLD, NORMAL, (ram_used), ram_total);
if (show_resolution) if (show_resolution)
printf("\033[18C%s%sRESOLUTION%s %dx%d\n", printf("\033[18C%s%sRESOLUTION%s %dx%d\n",
NORMAL, BOLD, NORMAL, screen_width, screen_height); NORMAL, BOLD, NORMAL, screen_width, screen_height);
if (show_shell) if (show_shell)
printf("\033[18C%s%sSHELL %s%s\n", printf("\033[18C%s%sSHELL %s%s\n",
NORMAL, BOLD, NORMAL, shell); NORMAL, BOLD, NORMAL, shell);
@ -292,17 +292,17 @@ void print_info()
printf("\033[18C%s%sPKGS %s%s%d %s\n", printf("\033[18C%s%sPKGS %s%s%d %s\n",
NORMAL, BOLD, NORMAL, NORMAL, pkgs, pkgman_name); NORMAL, BOLD, NORMAL, NORMAL, pkgs, pkgman_name);
if (show_uptime) if (show_uptime)
#ifndef __APPLE__ #ifndef __APPLE__
printf("\033[18C%s%sUWUPTIME %s" /*"%lid, "*/ "%lih, %lim\n", printf("\033[18C%s%sUWUPTIME %s" /*"%lid, "*/ "%lih, %lim\n",
NORMAL, BOLD, NORMAL, /*sys.uptime/60/60/24,*/ sys.uptime / 60 / 60, sys.uptime / 60 % 60); NORMAL, BOLD, NORMAL, /*sys.uptime/60/60/24,*/ sys.uptime / 60 / 60, sys.uptime / 60 % 60);
#else #else
if(sys.uptime/3600 < 24) if (sys.uptime / 3600 < 24)
printf("\033[18C%s%sUWUPTIME %s%lih, %lim\n", printf("\033[18C%s%sUWUPTIME %s%lih, %lim\n",
NORMAL, BOLD, NORMAL, sys.uptime/3600, sys.uptime/60%60); NORMAL, BOLD, NORMAL, sys.uptime / 3600, sys.uptime / 60 % 60);
else else
printf("\033[18C%s%sUWUPTIME %s%lid, %lih, %lim\n", printf("\033[18C%s%sUWUPTIME %s%lid, %lih, %lim\n",
NORMAL, BOLD, NORMAL, sys.uptime/86400, sys.uptime/3600%24, sys.uptime/60%60); NORMAL, BOLD, NORMAL, sys.uptime / 86400, sys.uptime / 3600 % 24, sys.uptime / 60 % 60);
#endif #endif
if (show_colors) if (show_colors)
printf("\033[18C%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", printf("\033[18C%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); BOLD, BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, NORMAL);
@ -350,13 +350,15 @@ void get_info()
break; break;
} }
else if (library) // macOS else if (library) // macOS
{ {
closedir(library); closedir(library);
sysctlbyname("machdep.cpu.brand_string", &cpu_buffer, &cpu_buffer_len, NULL, 0); #ifdef __APPLE__
sysctlbyname("machdep.cpu.brand_string", &cpu_buffer, &cpu_buffer_len, NULL, 0);
sprintf(version_name, "macos"); sprintf(version_name, "macos");
sprintf(cpu_model, "%s", cpu_buffer); sprintf(cpu_model, "%s", cpu_buffer);
} #endif
}
else else
sprintf(version_name, "unknown"); sprintf(version_name, "unknown");
} }
@ -371,7 +373,7 @@ void get_info()
// system resources // system resources
uname(&sys_var); uname(&sys_var);
sysinfo(&sys); // somehow this function has to be called again in print_info() sysinfo(&sys); // somehow this function has to be called again in print_info()
truncate_name(sys_var.release); truncate_name(sys_var.release);
sprintf(kernel, "%s %s %s", sys_var.sysname, sys_var.release, sys_var.machine); sprintf(kernel, "%s %s %s", sys_var.sysname, sys_var.release, sys_var.machine);
@ -400,18 +402,24 @@ void get_info()
fclose(meminfo); fclose(meminfo);
#else #else
// Used // Used
FILE *mem_wired_fp, *mem_active_fp, *mem_compressed_fp; FILE *mem_wired_fp, *mem_active_fp, *mem_compressed_fp;
mem_wired_fp = popen("vm_stat | awk '/wired/ { printf $4 }' | cut -d '.' -f 1", "r"); mem_wired_fp = popen("vm_stat | awk '/wired/ { printf $4 }' | cut -d '.' -f 1", "r");
mem_active_fp = popen("vm_stat | awk '/active/ { printf $3 }' | cut -d '.' -f 1", "r"); mem_active_fp = popen("vm_stat | awk '/active/ { printf $3 }' | cut -d '.' -f 1", "r");
mem_compressed_fp = popen("vm_stat | awk '/occupied/ { printf $5 }' | cut -d '.' -f 1", "r"); mem_compressed_fp = popen("vm_stat | awk '/occupied/ { printf $5 }' | cut -d '.' -f 1", "r");
char mem_wired_ch[2137], mem_active_ch[2137], mem_compressed_ch[2137]; char mem_wired_ch[2137], mem_active_ch[2137], mem_compressed_ch[2137];
while(fgets(mem_wired_ch, sizeof(mem_wired_ch), mem_wired_fp) != NULL) { while (fgets(mem_wired_ch, sizeof(mem_wired_ch), mem_wired_fp) != NULL)
while(fgets(mem_active_ch, sizeof(mem_active_ch), mem_active_fp) != NULL) { {
while(fgets(mem_compressed_ch, sizeof(mem_compressed_ch), mem_compressed_fp) != NULL) {} while (fgets(mem_active_ch, sizeof(mem_active_ch), mem_active_fp) != NULL)
{
while (fgets(mem_compressed_ch, sizeof(mem_compressed_ch), mem_compressed_fp) != NULL)
{
}
} }
} }
pclose(mem_wired_fp); pclose(mem_active_fp); pclose(mem_compressed_fp); pclose(mem_wired_fp);
pclose(mem_active_fp);
pclose(mem_compressed_fp);
int mem_wired = atoi(mem_wired_ch); int mem_wired = atoi(mem_wired_ch);
int mem_active = atoi(mem_active_ch); int mem_active = atoi(mem_active_ch);
@ -440,12 +448,12 @@ void get_info()
// get gpus with lspci command // get gpus with lspci command
if (strcmp(version_name, "android") != 0) if (strcmp(version_name, "android") != 0)
{ {
#ifndef __APPLE__ #ifndef __APPLE__
gpu = popen("lspci -mm 2> /dev/null | grep \"VGA\" | cut --fields=4,6 -d '\"' --output-delimiter=\" \" | sed \"s/ Controller.*//\"", "r"); gpu = popen("lspci -mm 2> /dev/null | grep \"VGA\" | cut --fields=4,6 -d '\"' --output-delimiter=\" \" | sed \"s/ Controller.*//\"", "r");
#else #else
gpu = popen("system_profiler SPDisplaysDataType | awk -F ': ' '/Chipset Model: /{ print $2 }'", "r"); gpu = popen("system_profiler SPDisplaysDataType | awk -F ': ' '/Chipset Model: /{ print $2 }'", "r");
#endif #endif
} }
else else
gpu = popen("getprop ro.hardware.vulkan 2> /dev/null", "r"); gpu = popen("getprop ro.hardware.vulkan 2> /dev/null", "r");
} }
@ -690,15 +698,16 @@ void print_ascii()
} }
else if (strcmp(version_name, "macos") == 0) else if (strcmp(version_name, "macos") == 0)
{ {
printf("\033[1E\033[3C%s .:`\n" printf("\033[1E\033[3C%s .:`\n"
" .--``--.\n" " .--``--.\n"
"%s ww OwO w\n" "%s ww OwO w\n"
"%s w w\n" "%s w w\n"
"%s w w\n" "%s w w\n"
"%s w w\n" "%s w w\n"
" www_-_www\n\n", GREEN, YELLOW, RED, PINK, BLUE); " www_-_www\n\n",
} GREEN, YELLOW, RED, PINK, BLUE);
}
// everything else // everything else
else else