diff --git a/Makefile b/Makefile index 4545ed9..8dfb485 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ ifeq ($(OS),GNU/Linux) OBJ := info.o main.o queue.o utils.o SRC := src/main.c src/info.c src/queue.c src/utils.c INSTALLPATH := /usr/bin + INSTALL_FLAGS := -Dm 755 INCLUDE := -l curl -l pci endif @@ -19,13 +20,14 @@ ifeq ($(OS),Android) OBJ := info.o main.o queue.o utils.o SRC := src/main.c src/info.c src/queue.c src/utils.c INSTALLPATH := $(PREFIX)/bin + INSTALL_FLAGS := -Dm 755 INCLUDE := -l curl endif ifeq ($(KERNEL),Darwin) - INSTALLPATH := /usr/local/bin - SRC := src/main.c src/info.c src/queue.c src/macos_infos.c src/bsdwrap.c src/macos_gpu_string.m src/utils.c OBJ := info.o main.o macos_infos.o bsdwrap.o macos_gpu_string.o utils.o + SRC := src/main.c src/info.c src/queue.c src/macos_infos.c src/bsdwrap.c src/macos_gpu_string.m src/utils.c + INSTALLPATH := /usr/local/bin INCLUDE := -framework Foundation -framework IOKit -l curl endif @@ -67,7 +69,7 @@ debug: build/debug build/debug install: build/$(TARGET) - install -Dm 755 build/$(TARGET) $(DESTDIR)$(INSTALLPATH)/$(TARGET) || \ + install $(INSTALL_FLAGS) build/$(TARGET) $(DESTDIR)$(INSTALLPATH)/$(TARGET) || \ bash -c 'echo -e "\e[31m\e[1mERROR\e[0m: Running without root proviliges?"' uninstall: diff --git a/src/info.c b/src/info.c index b163456..f4e6f40 100644 --- a/src/info.c +++ b/src/info.c @@ -409,7 +409,7 @@ int packages(char *dest) { } } #endif - if(config.pkg_brew && (access("/usr/local/bin/brew", F_OK) || !access("/opt/homebrew/bin/brew", F_OK) || !access("/bin/brew", F_OK))) { + if(config.pkg_brew && (!access("/usr/local/bin/brew", F_OK) || !access("/opt/homebrew/bin/brew", F_OK) || !access("/bin/brew", F_OK))) { pipe(pipes); if(!fork()) { diff --git a/src/macos_gpu_string.m b/src/macos_gpu_string.m index 1f05354..3a7f9e9 100644 --- a/src/macos_gpu_string.m +++ b/src/macos_gpu_string.m @@ -8,7 +8,7 @@ CFMutableDictionaryRef dict = IOServiceMatching("IOPCIDevice"); io_iterator_t iter; int success; - const char *result; + const char *result = NULL; #if __OSX_AVAILABLE_STARTING(__MAC_12_0,__IPHONE_NA) @@ -47,8 +47,6 @@ result = [modelName cStringUsingEncoding:NSUTF8StringEncoding]; } } - else - return NULL; CFRelease(services); IOObjectRelease(entry); diff --git a/src_old/bsdwrap.c b/src_old/bsdwrap.c deleted file mode 100644 index 03f31a2..0000000 --- a/src_old/bsdwrap.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "bsdwrap.h" - -int sysctl_wrap(void *out, size_t outsize, int domain, int field) { - int mib[] = {domain, field}; - int error = sysctl(mib, 2, out, &outsize, NULL, 0); - - if(error < 0) - return -1; - - return 0; -} diff --git a/src_old/bsdwrap.h b/src_old/bsdwrap.h deleted file mode 100644 index 67053b5..0000000 --- a/src_old/bsdwrap.h +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - - -/* - * Header for BSD standard system-querying - * functions (also applicable to macos and - * possibly linux). - */ - -/* - * This is a wrapper function over the fairly - * cryptic BSD `sysctl` function. - * - * Note that `out` is meant to be casted by the - * user as it can return various types depending on the query. - * If the type is _slightly_ incorrect, the function will fail. - * - * The function returns 0 if the query was successful, - * or -1 if the query failed. - * - * To find the expected values for `domain` and `field`, - * refer to the `sysctl` man pages. - * - * ex. For querying total memory size. - * - * ```c - * uint64_t size; - * size_t len = sizeof(uin64_t); - * sysctl_wrap(&size, &len, - * CTL_HW, // Query the hardware domain. - * HW_MEMSIZE); // Get memory size from the hardware domain. - * ``` - */ - -int sysctl_wrap(void *out, size_t outsize, int domain, int field); diff --git a/src_old/info.c b/src_old/info.c deleted file mode 100644 index 0a98323..0000000 --- a/src_old/info.c +++ /dev/null @@ -1,1079 +0,0 @@ -#include -#include -#include - -#ifdef __APPLE__ -#include "bsdwrap.h" -#include "macos_infos.h" -#else -#include -#endif - -#include -#include -#include -#include - -// defined by the makefile if pacman exists -// compile in the makefile using `make PACMAN=/bin/pacman ` -#ifdef ARCH_BASED -#include -#include -#endif - -#include -#include - -#include "info.h" - -/* __APPLE__ should only be defined on macOS - * _WIN32 should only be defined in Windows (I won't support it) - * __linux__ should only be defined on linux - * - * Those can be used to determine the - * platform the code is being compiled - * in and act consequently - */ - -// separators - prints a separator -void separator() { - printf("%s", config.separator); -} -void separator2() { - printf("%s", config.separator2); -} - -// title - prints a title in the format user@hostname -void title() { - static char hostname[HOST_NAME_MAX + 1]; - gethostname(hostname, HOST_NAME_MAX); - - struct passwd *pw; - uid_t uid = geteuid(); - - pw = uid == -1 && 0 ? NULL : getpwuid(uid); - if(!pw) { - fflush(stdout); - fprintf(stderr, "%s%s[Unsupported]", config.color, config.bold); - fflush(stderr); - printf("\e[0m@%s%s%s\e[0m", config.color, config.bold, hostname); - return; - } - char *username = pw->pw_name; - - printf("%s%s\e[0m@%s%s%s\e[0m", config.title_prefix, username, config.color, config.bold, hostname); -} - -// hostname - getting the computer hostname (defined in /etc/hostname) -void hostname() { - char format[100]; - snprintf(format, 100, "%s%s", config.hostname_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - char hostname[HOST_NAME_MAX + 1]; - gethostname(hostname, HOST_NAME_MAX + 1); - - printf("%s", hostname); -} - -// user - get the current login -void user() { - char format[100]; - snprintf(format, 100, "%s%s", config.user_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - struct passwd *pw; - uid_t uid = geteuid(); - - pw = uid == -1 ? NULL : getpwuid(uid); - if(!pw) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - } - char *username = pw->pw_name; - fputs(username, stdout); -} - -// uptime - prints the uptime -void uptime() { - char format[100]; - snprintf(format, 100, "%s%s", config.uptime_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - #ifdef __APPLE__ - struct timeval boottime; - int error; - long uptime; - error = sysctl_wrap(&boottime, sizeof(boottime), CTL_KERN, KERN_BOOTTIME); - - if(error < 0) - uptime = 0; - - time_t boot_seconds = boottime.tv_sec; - time_t current_seconds = time(NULL); - - uptime = (long)difftime(current_seconds, boot_seconds); - #else - struct sysinfo info; - sysinfo(&info); - - const long uptime = info.uptime; - #endif - - long days = uptime/86400; - char hours = uptime/3600 - days*24; - char mins = uptime/60 - days*1440 - hours*60; - - if(days) { - printf("%ldd ", days); // print the number of days passed if more than 0 - } - if(hours) { - printf("%dh ", hours); // print the number of days passed if more than 0 - } - if(mins) { - printf("%dm ", mins); // print the number of minutes passed if more than 0 - } - else if(uptime < 60) { - printf("%lds", uptime); // print the number of seconds passed if less than 60 - } -} - -//os - prints the os name + arch -#ifdef __APPLE__ -void os() { - char format[100]; - snprintf(format, 100, "%s%s", config.os_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - struct utsname name; - uname(&name); - - printf("macOS %s", name.machine); -} -#else -void os() { - char format[100]; - snprintf(format, 100, "%s%s", config.os_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - struct utsname name; - uname(&name); - - FILE *fp = fopen("/etc/os-release", "r"); - if(!fp) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - printf(" %s", name.machine); - return; - } - - char buf[64]; - char *os_name = buf, *end; - - read_after_sequence(fp, "PRETTY_NAME", buf, 64); - fclose(fp); - if(os_name[0] == '"' || os_name[0] == '\'') - ++os_name; - - end = strchr(os_name, '\n'); - if(!end) - goto error; - *end = 0; - - if((end = strchr(os_name, '"'))) *end = 0; - else if((end = strchr(os_name, '\''))) *end = 0; - - - printf("%s %s", os_name, name.machine); - - return; - - error: - fflush(stdout); - fputs("[Bad Format]", stderr); - fflush(stderr); - printf(" %s", name.machine); - return; -} -#endif - -// prints the kernel version -void kernel() { - char format[100]; - snprintf(format, 100, "%s%s", config.kernel_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - struct utsname name; - uname(&name); - - printf("%s ", name.release); -} - -// desktop - prints the current desktop environment -#ifdef __APPLE__ -void desktop() { - char format[100]; - snprintf(format, 100, "%s%s", config.desktop_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - printf("Aqua"); -} -#else -void desktop() { - char format[100]; - snprintf(format, 100, "%s%s", config.desktop_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - const char *desktop = getenv("SWAYSOCK") ? "Sway" : - (desktop = getenv("XDG_CURRENT_DESKTOP")) ? desktop : - (desktop = getenv("DESKTOP_SESSION")) ? desktop : - getenv("KDE_SESSION_VERSION") ? "KDE" : - getenv("GNOME_DESKTOP_SESSION_ID") ? "GNOME" : - getenv("MATE_DESKTOP_SESSION_ID") ? "mate" : - getenv("TDE_FULL_SESSION") ? "Trinity" : - !strcmp("linux", getenv("TERM")) ? "none" : - NULL; - if(desktop) { - printf("%s", desktop); - return; - } - - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); -} -#endif - -// shell (current) - prints the name of the parent process -void shell() { - char format[100]; - snprintf(format, 100, "%s%s", config.shell_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - #ifdef __linux__ - char path[32]; - - sprintf(path, "/proc/%d/cmdline", getppid()); - - FILE *fp = fopen(path, "r"); - if(fp) { - char shell[128]; - shell[fread(shell, 1, 127, fp)] = 0; - - printf("%s", basename(shell)); - fclose(fp); - return; - } - #endif - - char *shell = getenv("SHELL"); - if(!shell) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } - - printf("%s", basename(shell)); -} - -// shell (default) - prints the user default shell -void login_shell() { - char format[100]; - snprintf(format, 100, "%s%s", config.default_shell_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - char *shell = getenv("SHELL"); - - if(shell) { - printf("%s", basename(shell)); - return; - } - - fflush(stdout); - fputs("[Unknown]", stderr); - fflush(stderr); - -} - -// terminal - prints the current terminal -void term() { - char format[100]; - snprintf(format, 100, "%s%s", config.term_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - char *terminal = getenv("TERM"); - if(terminal) { - terminal = strcmp("xterm-kitty", terminal) ? terminal : "kitty"; - - printf("%s", terminal); - return; - } - - fflush(stdout); - fputs("[Unknown]", stderr); - fflush(stderr); -} - -// packages - prints the number of installed packages -#ifdef __APPLE__ -void packages() { - char format[100]; - snprintf(format, 100, "%s%s", config.packages_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - if(access("/usr/local/bin/brew", F_OK) && access("/opt/homebrew/bin/brew", F_OK)) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - } - - int pipes[2]; - char packages[10]; - pipe(pipes); - - if(!fork()) { - close(pipes[0]); - dup2(pipes[1], STDOUT_FILENO); - - execlp("sh", "sh", "-c", "ls $(brew --cellar 2>/dev/null)| wc -l", NULL); - } - - int status; - wait(&status); - - if(WIFEXITED(status) && WEXITSTATUS(status) == 0) { - close(pipes[1]); - packages[read(pipes[0], packages, 9) - 1] = 0; - close(pipes[0]); - - if(packages[0] != '0' && packages[0]) { - printf("%d (brew) ", atoi(packages)); - return; - } - } - - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); -} -#else -void packages() { - char format[100]; - snprintf(format, 100, "%s%s", config.packages_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - int pipes[2]; - char packages[10]; - bool supported; - - #ifdef ARCH_BASED - alpm_errno_t err; - alpm_handle_t *handle = alpm_initialize("/", "/var/lib/pacman/", &err); - alpm_db_t *db_local = alpm_get_localdb(handle); - size_t pkgs = 0; - - for(alpm_list_t *entry = alpm_db_get_pkgcache(db_local); entry; entry = alpm_list_next(entry)) - ++pkgs; - - alpm_release(handle); - - if(pkgs) { - printf("%ld (pacman) ", pkgs); - supported = true; - } - #endif - if(!access("/usr/bin/dpkg-query", F_OK)) { - pipe(pipes); - - if(!fork()) { - close(*pipes); - dup2(pipes[1], STDOUT_FILENO); - - execlp("sh", "sh", "-c", "dpkg-query -f '.\n' -W 2>/dev/null | wc -l", NULL); - } - wait(NULL); - close(pipes[1]); - packages[read(pipes[0], packages, 10) - 1] = 0; - close(*pipes); - - if(packages[0] != '0' && packages[0]) - printf("%s (dpkg) ", packages); - supported = true; - } - - if(!access("/usr/bin/rpm", F_OK)) { - pipe(pipes); - - if(!fork()) { - close(*pipes); - dup2(pipes[1], STDOUT_FILENO); - - execlp("sh", "sh", "-c", "rpm -qa 2>/dev/null | wc -l", NULL); - } - wait(NULL); - close(pipes[1]); - packages[read(pipes[0], packages, 10) - 1] = 0; - close(*pipes); - - if(packages[0] != '0' && packages[0]) { - printf("%s (rpm) ", packages); - supported = true; - } - } - - if(!access("/usr/bin/flatpak", F_OK)) { - pipe(pipes); - - if(!fork()) { - close(*pipes); - dup2(pipes[1], STDOUT_FILENO); - - execlp("sh", "sh", "-c", "flatpak list 2>/dev/null | wc -l", NULL); - } - wait(NULL); - close(pipes[1]); - packages[read(pipes[0], packages, 10) - 1] = 0; - close(*pipes); - - if(packages[0] != '0' && packages[0]) { - printf("%s (flatpak) ", packages); - supported = true; - } - } - - if(!access("/usr/bin/snap", F_OK)) { - pipe(pipes); - - if(!fork()) { - close(*pipes); - dup2(pipes[1], STDOUT_FILENO); - - execlp("sh", "sh", "-c", "snap list 2> /dev/null | wc -l", NULL); // sending stderr to null to avoid snap printing shit when installed with 0 pacakges - } - wait(NULL); - close(pipes[1]); - packages[read(pipes[0], packages, 10) - 1] = 0; - close(*pipes); - - if(packages[0] != '0' && packages[0]) { - printf("%d (snap) ", atoi(packages) - 1); - supported = true; - } - } - - if(!supported) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - } -} -#endif - -// host - prints the current host machine -#ifdef __APPLE__ -void host() { - char format[100]; - snprintf(format, 100, "%s%s", config.host_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - const size_t BUF_SIZE = 128; - char buf[BUF_SIZE]; - sysctlbyname("hw.model", &buf, (size_t*)&BUF_SIZE, NULL, 0); - - printf("%s", buf); -} -#else -void host() { - char format[100]; - snprintf(format, 100, "%s%s", config.host_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - FILE *fp = fopen("/sys/devices/virtual/dmi/id/product_name", "r"); - if(!fp) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } - fseek(fp, 0, SEEK_END); - size_t len = ftell(fp); - rewind(fp); - - char model[len]; - model[fread(model, 1, len, fp) - 1] = 0; - fclose(fp); - - fp = fopen("/sys/devices/virtual/dmi/id/product_version", "r"); - if(!fp) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } - fseek(fp, 0, SEEK_END); - len = ftell(fp); - rewind(fp); - - char model_ver[len]; - model_ver[fread(model_ver, 1, len, fp) - 1] = 0; - fclose(fp); - - printf("%s", model); - if(*model_ver) - printf(" %s", model_ver); -} -#endif - -// bios - prints the current host machine -#ifdef __APPLE__ -void bios() { - char format[100]; - snprintf(format, 100, "%s%s", config.bios_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); -} -#else -void bios() { - char format[100]; - snprintf(format, 100, "%s%s", config.bios_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - bool errors = false; - - FILE *fp = fopen("/sys/devices/virtual/dmi/id/bios_vendor", "r"); - if(!fp) { - errors = true; - } else { - fseek(fp, 0, SEEK_END); - size_t len = ftell(fp); - rewind(fp); - - char vendor[len]; - vendor[fread(vendor, 1, len, fp) - 1] = 0; - - printf("%s", vendor); - fclose(fp); - } - - fp = fopen("/sys/devices/virtual/dmi/id/bios_version", "r"); - if(!fp) { - if(errors) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } else { - return; - } - } - - fseek(fp, 0, SEEK_END); - size_t len = ftell(fp); - rewind(fp); - - char version[len]; - version[fread(version, 1, len, fp) - 1] = 0; - - printf(" %s", version); - - fclose(fp); - - return; -} -#endif - -// cpu - prints the current CPU -#ifdef __APPLE__ -void cpu() { - char format[100]; - snprintf(format, 100, "%s%s", config.cpu_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - size_t BUF_SIZE = 128; - char buf[BUF_SIZE]; - sysctlbyname("machdep.cpu.brand_string", buf, &BUF_SIZE, NULL, 0); - - char *ptr; - - // cleaning the string from various garbage - if((ptr = strstr(buf, "(R)"))) - memmove(ptr, ptr+3, strlen(ptr+1)); - if((ptr = strstr(buf, "(TM)"))) - memmove(ptr, ptr+4, strlen(ptr+1)); - if((ptr = strstr(buf, " CPU"))) - memmove(ptr, ptr+4, strlen(ptr+1)); - - if(!config.print_cpu_brand) { - if((ptr = strstr(buf, "Intel Core "))) - memmove(ptr, ptr+11, strlen(ptr+11)+1); - else if((ptr = strstr(buf, "Apple "))) - memmove(ptr, ptr+6, strlen(ptr+6)+1); - } - - if(!config.print_cpu_freq) { - if((ptr = strstr(buf, " @"))) - *ptr = 0; - } - - printf("%s", buf); -} -#else -void cpu() { - char format[100]; - snprintf(format, 100, "%s%s", config.cpu_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - FILE *fp = fopen("/proc/cpuinfo", "r"); - if(!fp) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } - - char buf[256]; - char *cpu_info = buf; - - read_after_sequence(fp, "model name", buf, 256); - fclose(fp); - if(!(buf[0])) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } - cpu_info += 2; - - char *end; - if((end = strstr(cpu_info, " @"))) { - *end = 0; - } - - if(!end) { - end = strchr(cpu_info, '\n'); - if(!end) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } - *end = 0; - } - - char *ptr = end; - - // cleaning the string from various garbage - if((end = strstr(cpu_info, "(R)"))) - memmove(end, end+3, strlen(end+3)+1); - if((end = strstr(cpu_info, "(TM)"))) - memmove(end, end+4, strlen(end+4)+1); - if((end = strstr(cpu_info, " CPU"))) - memmove(end, end+4, strlen(end+4)+1); - if((end = strstr(cpu_info, "th Gen "))) - memmove(end-2, end+7, strlen(end+7)+1); - if((end = strstr(cpu_info, "-Core Processor"))) { - end -= 4; - end = strchr(end, ' '); - *end = 0; - } - - if(!config.print_cpu_brand) { - if((end = strstr(cpu_info, "Intel Core"))) - memmove(end, end+11, strlen(end+1)); - if((end = strstr(cpu_info, "AMD"))) - memmove(end, end+4, strlen(end+1)); - } - - printf("%s", cpu_info); - - // Printing the clock frequency the cpu is currently running at - if(!config.print_cpu_freq) - return; - - char *cpu_freq = strstr(ptr+1, "cpu MHz"); - if(!cpu_freq) - return; - - cpu_freq = strchr(cpu_freq, ':'); - if(!cpu_freq) - return; - cpu_freq += 2; - - end = strchr(cpu_freq, '\n'); - if(!end) - return; - - *end = 0; - - printf(" @ %g GHz", (float)(atoi(cpu_freq)/100) / 10); -} -#endif - -// gpu - prints the current GPU -#ifdef __APPLE__ -void gpu() { - char format[100]; - snprintf(format, 100, "%s%s", config.gpu_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - struct utsname name; - uname(&name); - - char *gpu_string; - - if(strcmp(name.machine, "arm64")) { - gpu_string = get_gpu_string(); - if(!gpu_string) - goto error; - } - else{ - char buf[1024]; - int pipes[2]; - int pipes2[2]; - pipe(pipes); - pipe(pipes2); - - if(!fork()) { - dup2(pipes[1], STDOUT_FILENO); - dup2(pipes[1], STDERR_FILENO); - close(pipes[0]); - close(pipes[1]); - close(pipes2[0]); - close(pipes2[1]); - execlp("/usr/sbin/system_profiler", "system_profiler", "SPDisplaysDataType", NULL); - } - close(pipes2[0]); - close(pipes2[1]); - close(pipes[1]); - wait(NULL); - int bytes = read(pipes[0], buf, 1024); - close(pipes[0]); - - if(bytes < 1) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } - - gpu_string = strstr(buf, "Chipset Model: "); - if(!gpu_string) - goto error; - gpu_string += 15; - char *end = strchr(gpu_string, '\n'); - if(!end) - goto error; - *end = 0; - } - - char *ptr; - if((ptr = strstr(gpu_string, "Intel "))) - gpu_string += 6; - else if((ptr = strstr(gpu_string, "AMD "))) - gpu_string += 4; - //else if((ptr = strstr(gpu_string, "Apple "))) - // gpu_string += 6; - - printf("%s", gpu_string); - - return; - - error: - if(!gpu_string) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } -} -#else -void gpu() { - char format[100]; - snprintf(format, 100, "%s%s", config.gpu_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - if(!access("/usr/bin/lspci", F_OK)) { - int pipes[2]; - int pipes2[2]; - char *lspci = malloc(0x2000); - - pipe(pipes); - pipe(pipes2); - if(!fork()) { - close(pipes[0]); - close(pipes2[0]); - dup2(pipes[1], STDOUT_FILENO); - dup2(pipes2[1], STDERR_FILENO); - execlp("lspci", "lspci", "-mm", NULL); - } - wait(NULL); - close(pipes[1]); - close(pipes2[1]); - lspci[read(pipes[0], lspci, 0x2000)] = 0; - close(pipes[0]); - close(pipes2[0]); - char *gpu = strstr(lspci, "3D"); - if(!gpu) { - gpu = strstr(lspci, "VGA"); - if(!gpu) { - goto error; - } - } - - for(int i = 0; i < 4; ++i) { - gpu = strchr(gpu, '"'); - if(!gpu) - goto error; - ++gpu; - /* VGA compatible controller" "Intel Corporation" "WhiskeyLake-U GT2 [UHD Graphics 620]" - * "Intel Corporation" "WhiskeyLake-U GT2 [UHD Graphics 620]" - * Intel Corporation" "WhiskeyLake-U GT2 [UHD Graphics 620]" - * "WhiskeyLake-U GT2 [UHD Graphics 620]" - * WhiskeyLake-U GT2 [UHD Graphics 620]" - */ - } - - char *end = strchr(gpu, '"'); // WhiskeyLake-U GT2 [UHD Graphics 620] - if(!end) - goto error; - *end = 0; - - char *ptr; - if(!config.print_gpu_arch) { - if((ptr = strchr(gpu, '['))) { - end = strchr(ptr, ']'); - if(end) { - *end = 0; - gpu = ptr + 1; - } - } - if((ptr = strchr(gpu, '('))) { - if(ptr > lspci + 1) { - *(ptr-1) = 0; - } - } - } - - if((end = strstr(gpu, " Integrated Graphics Controller"))) - *end = 0; - printf("%s", gpu); - free(lspci); - return; - - error: - free(lspci); - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; -} -#endif - -// memory - prints the amount of memory that's currently in use -#ifdef __APPLE__ -void memory() { - char format[100]; - snprintf(format, 100, "%s%s", config.mem_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - bytes_t usedram = used_mem_size(); - bytes_t totalram = system_mem_size(); - - if(usedram == 0 || totalram == 0) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } - - printf("%llu MiB / %llu MiB (%llu%%)", usedram/1048576, totalram/1048576, (usedram * 100) / totalram); - return; -} -#else -void memory() { - char format[100]; - snprintf(format, 100, "%s%s", config.mem_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - struct sysinfo info; - sysinfo(&info); - - unsigned long totalram = info.totalram / 1024; - unsigned long freeram = info.freeram / 1024; - unsigned long bufferram = info.bufferram / 1024; - - FILE *fp = fopen("/proc/meminfo", "r"); - - if(!fp) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } - - char buf[256]; - char *cachedram = buf; - - read_after_sequence(fp, "Cached:", buf, 256); - fclose(fp); - - if(!(*buf)) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } - cachedram += 2; - - char *end; - end = strstr(cachedram, " kB"); - - if(!end) { - fflush(stdout); - fputs("[Unsupported]", stderr); - fflush(stderr); - return; - } - - (*end) = 0; - - unsigned long usedram = totalram - freeram - bufferram - atol(cachedram); - - printf("%lu MiB / %lu MiB", usedram/1024, totalram/1024); - - if(config.print_mem_perc) - printf(" (%lu%%)", (usedram * 100) / totalram); - return; -} -#endif - -// public IP adress - get the public IP address -void public_ip() { - char format[100]; - snprintf(format, 100, "%s%s", config.pub_ip_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - char public_ip[20]; - int pipes[2]; - - pipe(pipes); - if(!fork()) { - close(*pipes); - dup2(pipes[1], STDOUT_FILENO); - - execlp("curl", "curl", "-s", "ident.me", NULL); // using curl --silent to get the Public IP aress - } - wait(NULL); - close(pipes[1]); - - - public_ip[read(pipes[0], public_ip, 20)] = 0; - - close(*pipes); - printf("%s", public_ip); -} - -// local IP adress - get the local IP address -void local_ip() { - char format[100]; - snprintf(format, 100, "%s%s", config.loc_ip_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - struct ifaddrs *ifAddrStruct=NULL; - struct ifaddrs *ifa=NULL; - - void *tmpAddrPtr=NULL; - - getifaddrs(&ifAddrStruct); - - for(ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) { - if(!ifa->ifa_addr) { - continue; - } - if(ifa->ifa_addr->sa_family == AF_INET) { // check it is IP4 - // is a valid IP4 Address - tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; - char addressBuffer[INET_ADDRSTRLEN]; - inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); - if(strcmp(addressBuffer, "127.0.0.1")) - printf("%s", addressBuffer); - } - } -} - -// pwd - prints the current working directory -void pwd() { - char format[100]; - snprintf(format, 100, "%s%s", config.pwd_label, config.dash); - if(config.align_infos) printf("%-16s\e[0m", format); - else printf("%s\e[0m ", format); - - char *pwd = getenv("PWD"); - if(pwd) { - printf("%s", pwd); - return; - } - - fflush(stdout); - fputs("[Unknown]", stderr); - fflush(stderr); -} - -// terminal colors -void colors() { - printf("%s", config.col_prefix); - for(int i = 0; i < 8; ++i) { - printf("\e[4%dm", i); - for(int j = 0; j < config.col_block_len; ++j) - printf(" "); - } - printf("\e[0m"); - fflush(stdout); -} -// terminal colors (light version) -void light_colors() { - printf("%s", config.col_prefix); - for(int i = 0; i < 8; ++i) { - printf("\e[10%dm", i); - for(int j = 0; j < config.col_block_len; ++j) - printf(" "); - } - printf("\e[0m"); - fflush(stdout); -} diff --git a/src_old/info.h b/src_old/info.h deleted file mode 100644 index 33f5c1e..0000000 --- a/src_old/info.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef INFO_H -#define INFO_H -#include -#include -#include -#include - -#include "queue.h" -#include "vars.h" - -#ifndef HOST_NAME_MAX -#ifdef _POSIX_HOST_NAME_MAX -#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX -#else -#define HOST_NAME_MAX 128 -#endif -#endif - -// Not sure if this -#ifndef LOGIN_NAME_MAX -#define LOGIN_NAME_MAX HOST_NAME_MAX -#endif - -void separator(); // prints a separator - -void separator2(); // prints a different separator - -void title(); // prints a title in the format user@hostname - -void hostname(); // getting the computer hostname - -void user(); // get the currently logged user - -void uptime(); // prints the uptime - -void os(); // prints the os name + arch - -void bios(); // prints the current BIOS version - -void kernel(); // prints the kernel version - -void desktop(); // prints the current desktop environment - -void shell(); // prints the shell that called albafetch - -void login_shell(); // prints the user default shell - -void term(); // prints the current terminal - -void packages(); // prints the number of installed packages - -void host(); // prints the current host machine - -void cpu(); // prints the current CPU - -void gpu(); // prints the current GPU - -void memory(); // prints the used memory in the format used MiB / total MiB (XX%) - -void public_ip(); // get the public IP adress - -void local_ip(); // get the local IP adress - WORK IN PROGRESS - -void pwd(); // prints the current working directory - -void colors(); // prints the terminal colors -void light_colors();// prints the light version of the terminal colors - -#endif diff --git a/src_old/logos.h b/src_old/logos.h deleted file mode 100644 index 48504f5..0000000 --- a/src_old/logos.h +++ /dev/null @@ -1,401 +0,0 @@ -#ifndef LOGOS_H -#define LOGOS_H - -static const char *logos[][32] = { // please leave logos[0] to Linux and logos[1] to OSX - { // Linux - default logo - "linux", // this first line contains the distro ID, taken from /etc/os-relase - "\e[90m", // default color for the printed text - " ", // numbers of spaces to use when ran out of logo space - "\e[90m ##### ", // just the logo - "\e[90m ####### ", - "\e[90m ##\e[37mO\e[90m#\e[37mO\e[90m## ", - "\e[90m #\e[33m#####\e[90m# ", - "\e[90m ##\e[37m##\e[33m###\e[37m##\e[90m## ", - "\e[90m #\e[37m##########\e[90m## ", - "\e[90m #\e[37m############\e[90m## ", - "\e[90m #\e[37m############\e[90m### ", - "\e[33m ##\e[90m#\e[37m###########\e[90m##\e[33m# ", - "\e[33m######\e[90m#\e[37m#######\e[90m#\e[33m######", - "\e[33m#######\e[90m#\e[37m#####\e[90m#\e[33m#######", - "\e[33m #####\e[90m#######\e[33m##### ", - "" // an empty string concludes the logo, to know when it should stop printing - }, - { // MacOS X - "apple", - "\e[35m", - " ", - "\e[32m 'c. ", - "\e[32m ,xNMM. ", - "\e[32m .OMMMMo ", - "\e[32m OMMM0, ", - "\e[32m .;loddo:' loolloddol;. ", - "\e[32m cKMMMMMMMMMMNWMMMMMMMMMM0: ", - "\e[33m .KMMMMMMMMMMMMMMMMMMMMMMMWd. ", - "\e[33m XMMMMMMMMMMMMMMMMMMMMMMMX. ", - "\e[31m;MMMMMMMMMMMMMMMMMMMMMMMM: ", - "\e[31m:MMMMMMMMMMMMMMMMMMMMMMMM: ", - "\e[31m.MMMMMMMMMMMMMMMMMMMMMMMMX. ", - "\e[31m kMMMMMMMMMMMMMMMMMMMMMMMMWd. ", - "\e[35m .XMMMMMMMMMMMMMMMMMMMMMMMMMMk", - "\e[35m .XMMMMMMMMMMMMMMMMMMMMMMMMK.", - "\e[34m kMMMMMMMMMMMMMMMMMMMMMMd ", - "\e[34m ;KMMMMMMMWXXWMMMMMMMk. ", - "\e[34m .cooc,. .,coo:. ", - "" - }, - { // Arch Linux - "arch", - "\e[36m", - " ", - "\e[36m -` ", - "\e[36m .o+` ", - "\e[36m `ooo/ ", - "\e[36m `+oooo: ", - "\e[36m `+oooooo: ", - "\e[36m -+oooooo+: ", - "\e[36m `/:-:++oooo+: ", - "\e[36m `/++++/+++++++: ", - "\e[36m `/++++++++++++++: ", - "\e[36m `/+++ooooooooooooo/` ", - "\e[36m ./ooosssso++osssssso+` ", - "\e[36m .oossssso-````/ossssss+` ", - "\e[36m -osssssso. :ssssssso. ", - "\e[36m :osssssss/ osssso+++. ", - "\e[36m /ossssssss/ +ssssooo/- ", - "\e[36m `/ossssso+/:- -:/+osssso+- ", - "\e[36m `+sso+:-` `.-/+oso: ", - "\e[36m`++:. `-/+/", - "\e[36m.` `/", - "" - }, - { // Arch Linux (small version) - "arch_small", - "\e[36m", - "\e[36m ", - "\e[36m /\\ ", - "\e[36m / \\ ", - "\e[36m /\\ \\ ", - "\e[36m / \\ ", - "\e[36m / ,, \\ ", - "\e[36m / | | -\\ ", - "\e[36m/_-'' ''-_\\", - "" - }, - { // Debian - "debian", - "\e[31m", - " ", - "\e[31m _,met$$$$$gg. ", - "\e[31m ,g$$$$$$$$$$$$$$$P. ", - "\e[31m ,g$$P\" \"\"\"Y$$.\". ", - "\e[31m ,$$P' `$$$. ", - "\e[31m',$$P ,ggs. `$$b: ", - "\e[31m`d$$' ,$P\"' \e[37m.\e[31m $$$ ", - "\e[31m $$P d$' \e[37m,\e[31m $$P ", - "\e[31m $$: $$. \e[37m-\e[31m ,d$$' ", - "\e[31m $$; Y$b._ _,d$P' ", - "\e[31m Y$$. \e[37m`.\e[31m`\"Y$$$$P\"' ", - "\e[31m `$$b \e[37m\"-.__\e[31m ", - "\e[31m `Y$$ ", - "\e[31m `Y$$. ", - "\e[31m `$$b. ", - "\e[31m `Y$$b. ", - "\e[31m `\"Y$b._ ", - "\e[31m `\"\"\" ", - "" - }, - { // Linux Mint - "linuxmint", - "\e[32m", - " ", - "\e[37m ...-:::::-... ", - "\e[37m .-MMMMMMMMMMMMMMM-. ", - "\e[37m .-MMMM\e[32m`..-:::::::-..`\e[37mMMMM-. ", - "\e[37m .:MMMM\e[32m.:MMMMMMMMMMMMMMM:.\e[37mMMMM:. ", - "\e[37m -MMM\e[32m-M---MMMMMMMMMMMMMMMMMMM.\e[37mMMM- ", - "\e[37m `:MMM\e[32m:MM` :MMMM:....::-...-MMMM:\e[37mMMM:` ", - "\e[37m :MMM\e[32m:MMM` :MM:` `` `` `:MMM:\e[37mMMM: ", - "\e[37m.MMM\e[32m.MMMM` :MM. -MM. .MM- `MMMM.\e[37mMMM.", - "\e[37m:MMM\e[32m:MMMM` :MM. -MM- .MM: `MMMM-\e[37mMMM:", - "\e[37m:MMM\e[32m:MMMM` :MM. -MM- .MM: `MMMM:\e[37mMMM:", - "\e[37m:MMM\e[32m:MMMM` :MM. -MM- .MM: `MMMM-\e[37mMMM:", - "\e[37m.MMM\e[32m.MMMM` :MM:--:MM:--:MM: `MMMM.\e[37mMMM.", - "\e[37m :MMM\e[32m:MMM- `-MMMMMMMMMMMM-` -MMM-\e[37mMMM: ", - "\e[37m :MMM\e[32m:MMM:` `:MMM:\e[37mMMM: ", - "\e[37m .MMM\e[32m.MMMM:--------------:MMMM.\e[37mMMM. ", - "\e[37m '-MMMM\e[32m.-MMMMMMMMMMMMMMM-.\e[37mMMMM-' ", - "\e[37m '.-MMMM\e[32m``--:::::--``\e[37mMMMM-.' ", - "\e[37m '-MMMMMMMMMMMMM-' ", - "\e[37m ``-:::::-`` ", - "" - }, - { // Endeavour OS - "endeavouros", - "\e[35m", - " ", - "\e[31m ./\e[35mo\e[34m. ", - "\e[31m ./\e[35msssso\e[34m- ", - "\e[31m `:\e[35mosssssss+\e[34m- ", - "\e[31m `:+\e[35msssssssssso\e[34m/. ", - "\e[31m `-/o\e[35mssssssssssssso\e[34m/. ", - "\e[31m `-/+\e[35msssssssssssssssso\e[34m+:` ", - "\e[31m `-:/+\e[35msssssssssssssssssso«\e[34m+/. ", - "\e[31m `.://\e[35mosssssssssssssssssssso\e[34m++- ", - "\e[31m .://+\e[35mssssssssssssssssssssssso\e[34m++: ", - "\e[31m .:///\e[35mossssssssssssssssssssssssso\e[34m++: ", - "\e[31m `:////\e[35mssssssssssssssssssssssssssso\e[34m+++.", - "\e[31m`-////+\e[35mssssssssssssssssssssssssssso\e[34m++++-", - "\e[31m `..-+\e[35moosssssssssssssssssssssssso\e[34m+++++/`", - "\e[34m ./++++++++++++++++++++++++++++++/:. ", - "\e[34m `:::::::::::::::::::::::::------`` ", - "" - }, - { // Ubuntu - "ubuntu", - "\e[31m", - " ", - "\e[31m .-/+oossssoo+/-. ", - "\e[31m `:+ssssssssssssssssss+:` ", - "\e[31m -+ssssssssssssssssssyyssss+- ", - "\e[31m .ossssssssssssssssss\e[37mdMMMNy\e[31msssso. ", - "\e[31m /sssssssssss\e[37mhdmmNNmmyNMMMMh\e[31mssssss/ ", - "\e[31m +sssssssss\e[37mhm\e[31myd\e[37mMMMMMMMNddddy\e[31mssssssss+ ", - "\e[31m /ssssssss\e[37mhNMMM\e[31myh\e[37mhyyyyhmNMMMNh\e[31mssssssss/ ", - "\e[31m.ssssssss\e[37mdMMMNh\e[31mssssssssss\e[37mhNMMMd\e[31mssssssss.", - "\e[31m+ssss\e[37mhhhyNMMNy\e[31mssssssssssss\e[37myNMMMy\e[31msssssss+", - "\e[31moss\e[37myNMMMNyMMh\e[31mssssssssssssss\e[37mhmmmh\e[31mssssssso", - "\e[31moss\e[37myNMMMNyMMh\e[31msssssssssssssshmmmhssssssso", - "\e[31m+ssss\e[37mhhhyNMMNy\e[31mssssssssssss\e[37myNMMMy\e[31msssssss+", - "\e[31m.ssssssss\e[37mdMMMNh\e[31mssssssssss\e[37mhNMMMd\e[31mssssssss.", - "\e[31m /ssssssss\e[37mhNMMM\e[31myh\e[37mhyyyyhdNMMMNh\e[31mssssssss/ ", - "\e[31m +sssssssss\e[37mdm\e[31myd\e[37mMMMMMMMMddddy\e[31mssssssss+ ", - "\e[31m /sssssssssss\e[37mhdmNNNNmyNMMMMh\e[31mssssss/ ", - "\e[31m .ossssssssssssssssss\e[37mdMMMNy\e[31msssso. ", - "\e[31m -+sssssssssssssssss\e[37myyy\e[31mssss+- ", - "\e[31m `:+ssssssssssssssssss+:` ", - "\e[31m .-/+oossssoo+/-. ", - "" - }, - { // Parrot OS - "parrot", - "\e[36m", - " ", - "\e[36m `:oho/-` ", - "\e[36m`mMMMMMMMMMMMNmmdhy- ", - "\e[36m dMMMMMMMMMMMMMMMMMMs` ", - "\e[36m +MMsohNMMMMMMMMMMMMMm/ ", - "\e[36m .My .+dMMMMMMMMMMMMMh. ", - "\e[36m + :NMMMMMMMMMMMMNo ", - "\e[36m `yMMMMMMMMMMMMMm: ", - "\e[36m /NMMMMMMMMMMMMMy` ", - "\e[36m .hMMMMMMMMMMMMMN+ ", - "\e[36m ``-NMMMMMMMMMd- ", - "\e[36m /MMMMMMMMMMMs` ", - "\e[36m mMMMMMMMsyNMN/ ", - "\e[36m +MMMMMMMo :sNh. ", - "\e[36m `NMMMMMMm -o/", - "\e[36m oMMMMMMM. ", - "\e[36m `NMMMMMM+ ", - "\e[36m +MMd/NMh ", - "\e[36m mMm -mN` ", - "\e[36m /MM `h: ", - "\e[36m dM` . ", - "\e[36m :M- ", - "\e[36m d: ", - "\e[36m -+ ", - "\e[36m - ", - "" - }, - { // Manjaro Linux - "manjaro", - "\e[32m", - " ", - "\e[32m██████████████████ ████████", - "\e[32m██████████████████ ████████", - "\e[32m██████████████████ ████████", - "\e[32m██████████████████ ████████", - "\e[32m████████ ████████", - "\e[32m████████ ████████ ████████", - "\e[32m████████ ████████ ████████", - "\e[32m████████ ████████ ████████", - "\e[32m████████ ████████ ████████", - "\e[32m████████ ████████ ████████", - "\e[32m████████ ████████ ████████", - "\e[32m████████ ████████ ████████", - "\e[32m████████ ████████ ████████", - "\e[32m████████ ████████ ████████", - "" - }, - { // Fedora - "fedora", - "\e[34m", - " ", - "\e[34m /:-------------:\\ ", - "\e[34m :-------------------:: ", - "\e[34m :-----------\e[39m/shhOHbmp\e[34m---:\\ ", - "\e[34m /-----------\e[39momMMMNNNMMD\e[34m] ---: ", - "\e[34m :-----------\e[39msMMMMNMNMP\e[34m. ---: ", - "\e[34m :-----------\e[39m:MMMdP\e[34m------- ---\\", - "\e[34m,------------\e[39m:MMMd\e[34m-------- ---:", - "\e[34m:------------\e[39m:MMMd\e[34m------- .---:", - "\e[34m:---- \e[39moNMMMMMMMMMNho\e[34m .----:", - "\e[34m:-- .\e[39m+shhhMMMmhhy++\e[34m .------/", - "\e[34m:- -------\e[39m:MMMd\e[34m--------------: ", - "\e[34m:- --------\e[39m/MMMd\e[34m-------------; ", - "\e[34m:- ------\e[39m/hMMMy\e[34m------------: ", - "\e[34m:-- \e[39m:dMNdhhdNMMNo\e[34m------------; ", - "\e[34m:---\e[39m:sdNMMMMNds:\e[34m------------: ", - "\e[34m:------\e[39m:://:\e[34m-------------:: ", - "\e[34m:---------------------:// ", - "" - }, - { // KDE Neon - "neon", - "\e[32m", - " ", - "\e[32m `..---+/---..` ", - "\e[32m `---.`` `` `.---.` ", - "\e[32m .--.` `` `-:-. ", - "\e[32m `:/: `.----//----.` :/- ", - "\e[32m .:. `---` `--.` .:` ", - "\e[32m .:` `--` .:- `:. ", - "\e[32m `/ `:. `.-::-.` -:` `/` ", - "\e[32m /. /. `:++++++++:` .: .: ", - "\e[32m`/ .: `+++++++++++/ /` `+`", - "\e[32m/+` -- .++++++++++++` :. .+:", - "\e[32m`/ .: `+++++++++++/ /` `+`", - "\e[32m /` /. `:++++++++:` .: .: ", - "\e[32m ./ `:. `.:::-.` -:` `/` ", - "\e[32m .:` `--` .:- `:. ", - "\e[32m .:. `---` `--.` .:` ", - "\e[32m `:/: `.----//----.` :/- ", - "\e[32m .-:.` `` `-:-. ", - "\e[32m `---.`` `` `.---.` ", - "\e[32m `..---+/---..` ", - "" - }, - { // Pop!_OS - "pop", - "\e[36m", - " ", - "\e[36m ///////////// ", - "\e[36m ///////////////////// ", - "\e[36m ///////\e[39m*767\e[36m//////////////// ", - "\e[36m //////\e[39m7676767676*\e[36m////////////// ", - "\e[36m /////\e[39m76767\e[36m//\e[39m7676767\e[36m////////////// ", - "\e[36m /////\e[39m767676\e[36m///\e[39m*76767\e[36m/////////////// ", - "\e[36m ///////\e[39m767676\e[36m///\e[39m76767\e[36m].///\e[39m7676*\e[36m///////", - "\e[36m/////////\e[39m767676\e[36m//\e[39m76767\e[36m///\e[39m767676\e[36m////////", - "\e[36m//////////\e[39m76767676767\e[36m////\e[39m76767\e[36m/////////", - "\e[36m///////////\e[39m76767676\e[36m//////\e[39m7676\e[36m//////////", - "\e[36m////////////,\e[39m7676\e[36m,///////\e[39m767\e[36m///////////", - "\e[36m/////////////*\e[39m7676\e[36m///////\e[39m76\e[36m////////////", - "\e[36m///////////////\e[39m7676\e[36m////////////////////", - "\e[36m ///////////////\e[39m7676\e[36m///\e[39m767\e[36m//////////// ", - "\e[36m //////////////////////\e[39m'\e[36m//////////// ", - "\e[36m //////\e[39m.7676767676767676767,\e[36m////// ", - "\e[36m /////\e[39m767676767676767676767\e[36m///// ", - "\e[36m /////////////////////////// ", - "\e[36m ///////////////////// ", - "\e[36m ///////////// ", - "" - }, - { // Gentoo - "gentoo", - "\e[35m", - " ", - "\e[35m -/oyddmdhs+:. ", - "\e[35m -o\e[97mdNMMMMMMMMNNmhy+\e[35m-` ", - "\e[35m -y\e[97mNMMMMMMMMMMMNNNmmdhy\e[35m+- ", - "\e[35m `o\e[97mmMMMMMMMMMMMMNmdmmmmddhhy\e[35m/` ", - "\e[35m om\e[97mMMMMMMMMMMMN\e[35mhhyyyo\e[97mhmdddhhhd\e[35mo` ", - "\e[35m.y\e[97mdMMMMMMMMMMd\e[35mhs++so/s\e[97mmdddhhhhdm\e[35m+` ", - "\e[35m oy\e[97mhdmNMMMMMMMN\e[35mdyooy\e[97mdmddddhhhhyhN\e[35md.", - "\e[35m :o\e[97myhhdNNMMMMMMMNNNmmdddhhhhhyym\e[35mMh", - "\e[35m .:\e[97m+sydNMMMMMNNNmmmdddhhhhhhmM\e[35mmy", - "\e[35m /m\e[97mMMMMMMNNNmmmdddhhhhhmMNh\e[35ms:", - "\e[35m `o\e[97mNMMMMMMMNNNmmmddddhhdmMNhs\e[35m+` ", - "\e[35m `s\e[97mNMMMMMMMMNNNmmmdddddmNMmhs\e[35m/. ", - "\e[35m /N\e[97mMMMMMMMMNNNNmmmdddmNMNdso\e[35m:` ", - "\e[35m+M\e[97mMMMMMMNNNNNmmmmdmNMNdso\e[35m/- ", - "\e[35myM\e[97mMNNNNNNNmmmmmNNMmhs+/\e[35m-` ", - "\e[35m/h\e[97mMMNNNNNNNNMNdhs++/\e[35m-` ", - "\e[35m `/\e[97mohdmmddhys+++/:\e[35m.` ", - "\e[35m `-//////:--. ", - "" - }, - { // Windows - "windows", - "\e[34m", - " ", - "\e[31m ,.=:!!t3Z3z., ", - "\e[31m :tt:::tt333EE3 ", - "\e[31m Et:::ztt33EEEL \e[32m@Ee., .., ", - "\e[31m ;tt:::tt333EE7 \e[32m;EEEEEEttttt33# ", - "\e[31m :Et:::zt333EEQ. \e[32m$EEEEEttttt33QL ", - "\e[31m it::::tt333EEF \e[32m@EEEEEEttttt33F ", - "\e[31m ;3=*^```\"*4EEV \e[32m:EEEEEEttttt33@. ", - "\e[34m ,.=::::!t=., \e[31m` \e[32m@EEEEEEtttz33QF ", - "\e[34m ;::::::::zt33) \e[32m\"4EEEtttji3P* ", - "\e[34m :t::::::::tt33.\e[33m:Z3z.. \e[32m`` \e[33m,..g. ", - "\e[34m i::::::::zt33F \e[33mAEEEtttt::::ztF ", - "\e[34m ;:::::::::t33V \e[33m;EEEttttt::::t3 ", - "\e[34m E::::::::zt33L \e[33m@EEEtttt::::z3F ", - "\e[34m{3=*^```\"*4E3) \e[33m;EEEtttt:::::tZ` ", - "\e[34m `\e[33m \e[33m:EEEEtttt::::z7 ", - "\e[33m \"VEzjt:;;z>*` ", - "" - }, - { // ElementaryOS - "elementary", - "\e[34m", - " ", - "\e[0m eeeeeeeeeeeeeeeee ", - "\e[37m eeeeeeeeeeeeeeeeeeeeeee ", - "\e[37m eeeee eeeeeeeeeeee eeeee ", - "\e[37m eeee eeeee eee eeee ", - "\e[37m eeee eeee eee eeee ", - "\e[37meee eee eee eee ", - "\e[37meee eee eee eee ", - "\e[37mee eee eeee eeee ", - "\e[37mee eee eeeee eeeeee ", - "\e[37mee eee eeeee eeeee ee ", - "\e[37meee eeee eeeeee eeeee eee ", - "\e[37meee eeeeeeeeee eeeeee eee ", - "\e[37m eeeeeeeeeeeeeeeeeeeeeeee eeeee ", - "\e[37m eeeeeeee eeeeeeeeeeee eeee ", - "\e[37m eeeee eeeee ", - "\e[37m eeeeeee eeeeeee ", - "\e[37m eeeeeeeeeeeeeeeee ", - "" - }, - { // Garuda Linux - "garuda", - "\e[35m", - "\e[0m ", - "\e[0m __,,,,,,,_ ", - "\e[0m _╓╗╣╫╠╠╠╠╠╠╠╠╠╠╠╠╠╕╗╗┐_ ", - "\e[0m ╥╢╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╥, ", - "\e[0m ╗╠╠╠╠╠╠╠╝╜╜╜╜╝╢╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠┐ ", - "\e[0m ╣╠╠╠╠╠╠╠╠╢╣╢╗╕ , `\"╘╠╠╠╠╠╠╠╠╠╠╠╠╠╠╔╥_ ", - "\e[0m ╒╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╕╙╥╥╜ `\"╜╠╬╠╠╠╠╠╠╠╠╠╠╠╥, ", - "\e[0m ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╗╥╥╥╥╗╗╬╠╠╠╠╠╠╠╝╙╠╠╣╠╠╠╠╢┐ ", - "\e[0m ╣╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╥╬╣╠╠╠╠╠╠╠╠╗ ", - "\e[0m ╒╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╗", - "\e[0m ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠", - "\e[0m ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╬ ```\"╜╝╢╠╠╡", - "\e[0m╒╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╣, ╘╠╪ ", - "\e[0m╞╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╢┐ ╜ ", - "\e[0m`╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╗ ", - "\e[0m,╬╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠\"╕ ", - "\e[0m╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╗ ", - "\e[0m╝^╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╝╣╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╡ ", - "\e[0m ╔╜`╞┘╢╛╜ ╡╢╠\"╚╠╠╜╝┌╞╞\"╢╠╠╠╠╠╠╠╠╠╠╣╩╢╪ ", - "\e[0m ╜╒\" `╜ ` ╜╙╕ └╣╠╠╠╠╕ ╞╙╖ ", - "\e[0m ╠╠╠ ", - "\e[0m ╜ ", - "" - } -}; - -#endif diff --git a/src_old/macos_gpu_string.m b/src_old/macos_gpu_string.m deleted file mode 100644 index 06421e6..0000000 --- a/src_old/macos_gpu_string.m +++ /dev/null @@ -1,48 +0,0 @@ -#include "macos_infos.h" - -#import - -char *get_gpu_string() -{ - CFMutableDictionaryRef dict = IOServiceMatching("IOPCIDevice"); - io_iterator_t iter; - int success; - const char *result; - - mach_port_t port = kIOMainPortDefault; // maybe kIOMasterPortDefault but it's apparently deprecated since macOS Monterey - success = IOServiceGetMatchingServices(port, dict, &iter); - if(success != kIOReturnSuccess) - return NULL; - - io_registry_entry_t entry; - - while((entry = IOIteratorNext(iter))) - { - CFMutableDictionaryRef services; - success = IORegistryEntryCreateCFProperties(entry, &services, kCFAllocatorDefault, kNilOptions); - if(success != kIOReturnSuccess) - { - IOObjectRelease(entry); - continue; - } - - const void *gpu_model = CFDictionaryGetValue(services, @"model"); - if(gpu_model != nil) - { - if(CFGetTypeID(gpu_model) == CFDataGetTypeID()) - { - NSString *modelName = [[NSString alloc] initWithData: - (NSData *)gpu_model encoding:NSASCIIStringEncoding]; - - result = [modelName cStringUsingEncoding:NSUTF8StringEncoding]; - } - } - - CFRelease(services); - IOObjectRelease(entry); - } - - IOObjectRelease(iter); - - return (char*)result; -} diff --git a/src_old/macos_infos.c b/src_old/macos_infos.c deleted file mode 100644 index 27afd78..0000000 --- a/src_old/macos_infos.c +++ /dev/null @@ -1,68 +0,0 @@ -#include "macos_infos.h" - -/* STATIC HELPERS */ - -const static vm_size_t FALLBACK_PAGE_SIZE = 4096; - -static vm_size_t page_size(mach_port_t host) { - vm_size_t page_size; - int error; - - error = host_page_size(host, &page_size); - - return (error < 0) ? page_size : FALLBACK_PAGE_SIZE; -} - -/* - * Original source: - * https://opensource.apple.com/source/system_cmds/system_cmds-496/vm_stat.tproj/vm_stat.c.auto.html - */ -static int get_stats(struct vm_statistics64 *stat, mach_port_t host) { - int error; - - unsigned count = HOST_VM_INFO64_COUNT; - error = host_statistics64(host, - HOST_VM_INFO64, - (host_info64_t) stat, - &count); - - if(error != KERN_SUCCESS) - return error; - - return 0; -} - -/* EXPORTS */ - -bytes_t system_mem_size() { - uint64_t size; - int error; - - error = sysctl_wrap(&size, sizeof(uint64_t), CTL_HW, HW_MEMSIZE); - - // Since no computer should have 0 bytes of memory, - // 0 indicates failure. - if(error < 0) - return 0; - - return size; -} - -bytes_t used_mem_size() { - pages_t internal, wired, compressed; - mach_port_t host = mach_host_self(); - - struct vm_statistics64 vm_stat; - if(get_stats(&vm_stat, host) < 0) - return 0; - - internal = vm_stat.internal_page_count - vm_stat.purgeable_count; - wired = vm_stat.wire_count; - compressed = vm_stat.compressor_page_count; - - return (internal + wired + compressed) * page_size(host); -} -/* -char *processor() { - pages_t cpu; -}*/ diff --git a/src_old/macos_infos.h b/src_old/macos_infos.h deleted file mode 100644 index 363cdd4..0000000 --- a/src_old/macos_infos.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#ifndef MACOS_INFOS_H -#define MACOS_INFOS_H - -#include -#include -#include - -#include - -#include "bsdwrap.h" - -typedef uint64_t bytes_t; -typedef uint64_t pages_t; - -char *get_gpu_string(); - -/* - * Gets the used memory int - */ -bytes_t used_mem_size(); - -bytes_t system_mem_size(); - -#endif //MACOS_INFOS_H diff --git a/src_old/main.c b/src_old/main.c deleted file mode 100644 index 12c79d5..0000000 --- a/src_old/main.c +++ /dev/null @@ -1,638 +0,0 @@ -#include "info.h" -#include "logos.h" -#include "stdlib.h" - -/* TODO: - * use strlen() to determine how far to --align ("%-%ds", max(strlen(a), strlen(b)) + 2 <-- NOT actual code) - * !!! option to choose what order the infos are printed in ( modules {"a", "b"} in albafetch.conf) - * --ascii for custom ascii art (conflicts with --logo) - work in progress (lines [64; 76]U[318; 356]) - * remove the lspci dependency for gpu() - */ - -// CONFIGURATION OPTIONS: -char *separator_string; // what is used as separator between sections -char *dash; // default separator - -// default config -Config config = { - "\e[0m------------------", // separator - "", // separator2 - ":", // dash - true, // print_cpu_freq - true, // print_cpu_brand - true, // print_gpu_arch - true, // print_mem_perc - false, // align stats - "", // color - "\e[1m", // bold - // Labels: - "", // title_prefix - "", // col_prefix - 3, // col_block_len - "Hostname", // hostname - "User", // user - "Uptime", // uptime - "OS", // os - "Kernel", // kernel - "Desktop", // desktop - "Shell", // shell - "Shell", // default_shell_label - "Terminal", // terminal - "Packages", // packages - "Host", // host - "BIOS", // bios - "CPU", // cpu - "GPU", // gpu - "Memory", // memory - "Publ. IP", // public IP - "Loc. IP", // local IP - "Directory" // pwd -}; - -bool print_cpu_freq; - -bool default_bold = false; -char default_color[33] = ""; -char default_logo[33] = ""; - -char **logo; - -char spacing[32] = " "; -char spacing_first[32] = ""; -char spacing_last[32] = ""; - -/* Check what I wrote about logo_from_string - should be around line 320 - * also, this will be useful for determining how far to --align (to do comment at line 6) -int max(const int *nums, unsigned const int lenght) { - if(!lenght) return 0; - int current_max = *nums; - - for(int i = 1; i < lenght; ++i) { - if(nums[i] > current_max) - current_max = nums[i]; - } - - return current_max; -} -*/ - -void unescape(char *str) { - // check every \ in the given string and unescape \n and \e - while((str=strchr(str, '\\'))) { - switch(*str) { - default: - break; - case '\\': - memmove(str, str+1, strlen(str+1)+1); - break; - case 'n': - memmove(str, str+1, strlen(str+1)+1); - *str = '\n'; - break; - case 'e': - memmove(str, str+1, strlen(str+1)+1); - *str = '\e'; - break; - } - ++str; - } -} - -// in the following, a return code of 1 means success -bool parse_config_option(char* source, char *dest, char *field) { - char *ptr; - - // looks for the keyword, checks the string between the following " " - - if((ptr = strstr(source, field))) { - if((ptr = strchr(ptr, '"'))) { - ++ptr; - - if(((field = strchr(ptr, '"'))) && ptr) { - *field = 0; - strcpy(dest, ptr); - *field = '"'; - return 1; - } - } - } - - return 0; -} - -// in the following, a return code of 1 means success -bool parse_config_bool(char *source, bool *dest, char *field) { - char *ptr; - - // looks for the keyword, checks the string between the following " " - - if((ptr = strstr(source, field))) { - if((ptr = strchr(ptr, '"'))) { - ++ptr; - - if(((field = strchr(ptr, '"'))) && ptr) { - *field = 0; - *dest = !strcmp(ptr, "true"); - *field = '"'; - return 1; - } - } - } - - return 0; -} - -// parsing the file provided in path for config options -void parse_config(const char *path, const bool using_custom_config) { - // really bad code here, you don't need to look - - FILE *fp = fopen(path, "r"); - if(!fp) { - if(using_custom_config) - fprintf(stderr, "\e[91m\e[1mWARNING\e[0m: failed to open the file specified using --config (%s), using defaults.\n", path); - return; - } - fseek(fp, 0, SEEK_END); - size_t len = ftell(fp); - rewind(fp); - char *conf = malloc(len+1); - conf[fread(conf, 1, len, fp)] = 0; - fclose(fp); - - unescape(conf); - - // remove comments - char *ptr = conf; - char *ptr2 = conf; - while((ptr = strchr(ptr, ';'))) { - ptr2 = strchr(ptr, '\n'); - memmove(ptr, ptr2+1, strlen(ptr2+1)+1); - } - ptr = ptr2 = conf; - while((ptr = strchr(ptr, '#'))) { - ptr2 = strchr(ptr, '\n'); - memmove(ptr, ptr2+1, strlen(ptr2+1)+1); - } - - // spacing - parse_config_option(conf, spacing, "spacing"); - - // spacing_first - parse_config_option(conf, spacing_first, "spacing_first"); - - // spacing_last - parse_config_option(conf, spacing_last, "spacing_last"); - - - // separators - parse_config_option(conf, config.separator, "separator"); - parse_config_option(conf, config.separator2, "separator2"); - - // dash - parse_config_option(conf, config.dash, "dash"); - - // print_cpu_freq - parse_config_bool(conf, &config.print_cpu_freq, "print_cpu_freq"); - - // print_cpu_brand - parse_config_bool(conf, &config.print_cpu_brand, "print_cpu_brand"); - - // print_gpu_arch - parse_config_bool(conf, &config.print_gpu_arch, "print_gpu_arch"); - - // print_mem_perc - parse_config_bool(conf, &config.print_mem_perc, "print_mem_perc"); - - // align_infos - parse_config_bool(conf, &config.align_infos, "align_infos"); - - // color - if(parse_config_option(conf, config.color, "default_color")) - strcpy(default_color, config.color); - - // bold - bool bold; - if((default_bold = parse_config_bool(conf, &bold, "default_bold"))) { - if(bold) - strcpy(config.bold, "\e[1m"); - else - strcpy(config.bold, ""); - } - - // logo - if((ptr = strstr(conf, "default_logo"))) { - if((ptr = strchr(ptr, '"'))) { - ++ptr; - if(((ptr2 = strchr(ptr, '"'))) && ptr) { - *ptr2 = 0; - for(int i = 0; i < sizeof(logos)/sizeof(*logos); ++i) - if(!strcmp(logos[i][0], ptr)) { - logo = (char**)logos[i]; - strcpy(default_logo, *logo); - } - *ptr2 = '"'; - } - } - } - - // col_block_len - if((ptr = strstr(conf, "col_block_len"))) { - if((ptr = strchr(ptr, '"'))) { - ++ptr; - if((ptr2 = strchr(ptr, '"'))) { - *ptr2 = 0; - config.col_block_len = atoi(ptr); - *ptr2 = '"'; - } - } - } - - // LABELS - // title - parse_config_option(conf, config.title_prefix, "title_prefix"); - - // colors - parse_config_option(conf, config.col_prefix, "col_prefix"); - - // hostname - parse_config_option(conf, config.hostname_label, "hostname_label"); - - // user - parse_config_option(conf, config.user_label, "user_label"); - - // uptime - parse_config_option(conf, config.uptime_label, "uptime_label"); - - // os - parse_config_option(conf, config.os_label, "os_label"); - - // kernel - parse_config_option(conf, config.kernel_label, "kernel_label"); - - // desktop - parse_config_option(conf, config.desktop_label, "desktop_label"); - - // shell (current) - parse_config_option(conf, config.shell_label, "shell_label"); - - // shell(default) - parse_config_option(conf, config.default_shell_label, "def_shell_label"); - - // terminal - parse_config_option(conf, config.term_label, "term_label"); - - // packages - parse_config_option(conf, config.packages_label, "packages_label"); - - // host - parse_config_option(conf, config.host_label, "host_label"); - - // bios - parse_config_option(conf, config.bios_label, "bios_label"); - - // cpu - parse_config_option(conf, config.cpu_label, "cpu_label"); - - // gpu - parse_config_option(conf, config.gpu_label, "gpu_label"); - - // memory - parse_config_option(conf, config.mem_label, "mem_label"); - - // public IP - parse_config_option(conf, config.pub_ip_label, "pub_ip_label"); - - // local IP - parse_config_option(conf, config.loc_ip_label, "loc_ip_label"); - - // pwd - parse_config_option(conf, config.pwd_label, "pwd_label"); - - free(conf); -} - -int printLogo(const int line) { - if(*logo[line]) { - printf("%s%s%s", config.bold, logo[line], config.color); - return line+1; - } else { - printf("%s%s%s", config.bold, logo[2], config.color); - return line; - } -} - -/* // I'm working on this part - I swear - I'm trying to implement getting a custom logo from a string (line per line) -void logo_from_string(char *str, char **dest) { - unescape(str); - - char *ptr; - int string_lengths[28]; - memset(string_lengths, 0, sizeof(string_lengths)/sizeof(string_lengths[0])); - int line_count = 3; - char placeholder_line[64] = ""; - char *temp_logo[32] = { - "custom", - "", - }; - - // place the lines in the array - // TODO fix this loop, it's broken AF, it just works as a segfault farm, lol - while((ptr = strchr(str, '\n'))) { - if(line_count > 31) // prevent buffer overflow - break; - - *ptr = 0; - temp_logo[line_count++] = str; - string_lengths[line_count-4] = (int)strlen(str); - *ptr = '\n'; - - str = ptr+1; - } - - for(int i = 0; i < max(string_lengths, sizeof(string_lengths)/sizeof(string_lengths[0])); ++i) - strcat(placeholder_line, " "); - - temp_logo[2] = placeholder_line; - temp_logo[line_count] = ""; - - puts("HELLO"); - - dest = temp_logo; -} -*/ - -int main(const int argc, const char **argv) { - bool user_is_an_idiot = false; // rtfm and stfu - - // are the following command line args used? - bool asking_help = false; - int asking_color = 0; - int asking_bold = 0; - int asking_logo = 0; - int asking_align = 0; - - bool using_custom_config = false; - - // the config that's normally used is ~/.config/albafetch.conf - char config_file[LOGIN_NAME_MAX + 33] = ""; - - char *home = getenv("HOME"); - // I really hope this part will never need to run - if(!home) { - fflush(stdout); - fputs("\e[31m\e[1mERROR\e[0m:$HOME is not set, interrupting!\n", stderr); - fflush(stderr); - - return 1; - } - if(!home[0]) { - fflush(stdout); - fputs("\e[31m\e[1mERROR\e[0m:$HOME is empty, interrupting!\n", stderr); - fflush(stderr); - - return 1; - } - - // parsing the command args - for(int i = 1; i < argc; ++i) { - if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) - asking_help = true; - else if(!strcmp(argv[i], "-c") || !strcmp(argv[i], "--color")) - asking_color = i+1; - else if(!strcmp(argv[i], "-b") || !strcmp(argv[i], "--bold")) - asking_bold = i+1; - else if(!strcmp(argv[i], "-l") || !strcmp(argv[i], "--logo")) - asking_logo = i+1; - else if(!strcmp(argv[i], "--align") || !strcmp(argv[i], "-a")) - asking_align = i+1; - else if(!strcmp(argv[i], "--config")) { - if(i+1 < argc) { - using_custom_config = true; - strcpy(config_file, argv[i+1]); - continue; - } - fputs("\e[31m\e[1mERROR\e[0m: --config requires a extra argument! Use --help for more info\n", stderr); - user_is_an_idiot = true; - } - } - - if(!using_custom_config) { - char *config_home = getenv("XDG_CONFIG_HOME"); - if(config_home) { // is XDG_CONFIG_HOME set? - if(config_home[0]) // is XDG_CONFIG_HOME empty? - snprintf(config_file, LOGIN_NAME_MAX + 32, "%s/albafetch.conf", config_home); - else - snprintf(config_file, LOGIN_NAME_MAX + 32, "%s/.config/albafetch.conf", home); - } - else - snprintf(config_file, LOGIN_NAME_MAX + 32, "%s/.config/albafetch.conf", home); - } - - parse_config(config_file, using_custom_config); - if(!(*spacing_first)) strcpy(spacing_first, spacing); - if(!(*spacing_last)) strcpy(spacing_last, spacing); - - //logo_from_string("line1\nline2\nline3\nline4\nline5\nline6\n", logo); - - if(asking_color) { - if(asking_color < argc) { - char *colors[9][2] = { - {"black", "\e[30m"}, - {"red", "\e[31m"}, - {"green", "\e[32m"}, - {"yellow", "\e[33m"}, - {"blue", "\e[34m"}, - {"purple", "\e[35m"}, - {"cyan", "\e[36m"}, - {"gray", "\e[90m"}, - {"white", "\e[37m"}, - }; - - for(int j = 0; j < 9; ++j) { - if(!strcmp(argv[asking_color], *colors[j])) { - strcpy(config.color, colors[j][1]); - goto color; - } - } - - fputs("\e[31m\e[1mERROR\e[0m: invalid color! Use --help for more info\n", stderr); - user_is_an_idiot = true; - - color: ; - } else { - fputs("\e[31m\e[1mERROR\e[0m: --color requires a color! Use --help for more info\n", stderr); - user_is_an_idiot = true; - } - } - - if(asking_logo) { - if(asking_logo < argc) { - for(int j = 0; j < sizeof(logos)/sizeof(*logos); ++j) - if(!strcmp(logos[j][0], argv[asking_logo])) { - logo = (char**)logos[j]; - goto logo_arg_found; - } - logo = (char**)logos[0]; - logo_arg_found: ; - } else { - fputs("\e[31m\e[1mERROR\e[0m: --logo requires a extra argument! Use --help for more info\n", stderr); - user_is_an_idiot = true; - } - } - - // set logo and color if not defined yet - if(!logo) { - #ifdef __APPLE__ - logo = (char**)logos[1]; - goto logo_found; - #else - FILE *fp = fopen("/etc/os-release", "r"); - if(!fp) { - logo = (char**)logos[0]; - goto logo_found; - } - - char os_id[32]; - read_after_sequence(fp, "\nID", os_id, 32); - if(!(*os_id)) - read_after_sequence(fp, "ID", os_id, 32); - fclose(fp); - - char *end = strchr(os_id, '\n'); - if(!end) - return -1; - *end = 0; - - for(int i = 0; i < sizeof(logos)/sizeof(*logos); ++i) - if(!strcmp(logos[i][0], os_id)) { - logo = (char**)logos[i]; - goto logo_found; - } - logo = (char**)logos[0]; - #endif - - logo_found: ; - } - if(!(*config.color)) - strcpy(config.color, logo[1]); - - if(asking_help) { - printf("%s%salbafetch\e[0m - a system fetch utility\n", - config.color, config.bold); - - printf("\n%s%sFLAGS\e[0m:\n", - config.color, config.bold); - - printf("\t%s%s-h\e[0m,%s%s --help\e[0m:\t Print this help menu and exit\n", - config.color, config.bold, config.color, config.bold); - - printf("\t%s%s-c\e[0m,%s%s --color\e[0m:\t Change the output color (%s%s\e[0m)\n" - "\t\t\t [\e[30mblack\e[0m, \e[31mred\e[0m, \e[32mgreen\e[0m, \e[33myellow\e[0m," - " \e[34mblue\e[0m, \e[35mpurple\e[0m, \e[36mcyan\e[0m, \e[90mgray\e[0m," - " \e[37mwhite\e[0m]\n", - config.color, config.bold, config.color, config.bold, default_color[0] ? default_color : logo[1], default_color[0] ? "default" : "logo default"); - - printf("\t%s%s-b\e[0m,%s%s --bold\e[0m:\t Specifies if bold should be used in colored parts (default: %s\e[0m)\n" - "\t\t\t [\e[1mon\e[0m, off]\n", - config.color, config.bold, config.color, config.bold, default_bold ? "\e[1mon" : "off"); - - printf("\t%s%s-l\e[0m,%s%s --logo\e[0m:\t Changes the logo that will be displayed (%s)\n" - "\t\t\t [linux, apple, arch, arch_small, debian, linuxmint, endeavouros, ubuntu]\n" - "\t\t\t [parrot, manjaro, fedora, neon, pop, gentoo, windows]\n", - config.color, config.bold, config.color, config.bold, default_logo[0] ? default_logo : "OS default"); - - printf("\t%s%s-a\e[0m, %s%s--align\e[0m:\t Alignes the infos if set (default: %s)\n" - "\t\t\t [on, off]\n", config.color, config.bold, config.color, config.bold, config.align_infos ? "on" : "off"); - - printf("\t%s%s--config\e[0m:\t Specifies a custom config (default: ~/.config/albafetch.conf)\n" - "\t\t\t [path]\n", config.color, config.bold); - - printf("\nReport a bug: %s%shttps://github.com/alba4k/albafetch/issues\e[0m\n", - config.color, config.bold); - - return 0; - } - - if(asking_align) { - if(asking_logo < argc) { - if(!strcmp(argv[asking_align], "on")) - config.align_infos = true; - else if(!strcmp(argv[asking_align], "off")) - config.align_infos = false; - else { - fputs("\e[31m\e[1mERROR\e[0m: invalid extra argument for --align! Use --help for more info\n", stderr); - user_is_an_idiot = true; - } - } else { - fputs("\e[31m\e[1mERROR\e[0m: --align requires a extra argument! Use --help for more info\n", stderr); - user_is_an_idiot = true; - } - } - - if(asking_bold) { - if(asking_bold < argc) { - if(!strcmp(argv[asking_bold], "on")) - strcpy(config.bold, "\e[1m"); - else if(!strcmp(argv[asking_bold], "off")) - strcpy(config.bold, ""); - else { - fputs("\e[31m\e[1mERROR\e[0m: invalid extra argument for --bold! Use --help for more info\n", stderr); - user_is_an_idiot = true; - } - } else { - fputs("\e[31m\e[1mERROR\e[0m: --bold requires a extra argument! Use --help for more info\n", stderr); - user_is_an_idiot = true; - } - } - - // die if the user is a fucking moron - if(user_is_an_idiot) - return 1; - - void (*infos[])() = { - title, - separator, - uptime, - separator, - os, - kernel, - desktop, - shell, - term, - packages, - separator, - host, - cpu, - gpu, - memory, - separator2, - colors, - light_colors - }; - - // The following line works because infos is declared on the stack, - // so sizeof returns it's real size and not the size of a pointer. - const int info_lines = (int)(sizeof(infos) / sizeof(*infos)) - 1; - - int line = 3; // keeps track of the line that's currently printing - - // logo and infos - for(int i = 0; i <= info_lines; ++i) { - line = printLogo(line); - if(line == 4) printf("%s", spacing_first); - else if(i == info_lines) printf("%s", spacing_last); - else printf("%s", spacing); - infos[i](); - printf("\n"); - } - - // ******** remaining lines of the logo ******** - while(*logo[line]) { - line = printLogo(line); - printf("\n"); - } - printf("\e[0m"); - fflush(stdout); - - return 0; -} diff --git a/src_old/queue.c b/src_old/queue.c deleted file mode 100644 index e49648a..0000000 --- a/src_old/queue.c +++ /dev/null @@ -1,111 +0,0 @@ -#include "queue.h" - -Queue *queue_with_size(size_t size) { - Queue *q = malloc(sizeof(Queue)); - - size_t byte_size = sizeof(char) * size; - q->data = malloc(byte_size); - memset(q->data, 0, byte_size); - - q->alloc_size = size; - q->size = 0; - q->offset = 0; - - return q; -} - -int requeue(Queue *q) { - // If there is no available space, - // requeueing won't do anything. - if(q->size == q->alloc_size) - return -1; - - size_t used_byte_size = sizeof(char) * q->size; - char buf[q->size]; - - char *relevant_data_start = q->data + q->offset; - memcpy(buf, relevant_data_start, used_byte_size); - - memcpy(q->data, buf, used_byte_size); - q->offset = 0; - - return 0; -} - -int enqueue(Queue *q, char val) { - if(q->size >= q->alloc_size) - return QUEUE_FULL; - - size_t write_index = q->size + q->offset; - - if(write_index >= q->alloc_size) { - // We know that a requeue is possible because we check that the queue is not full. - requeue(q); - write_index = q->size; - } - - q->data[write_index] = val; - q->size++; - - return QUEUE_OK; -} - -int dequeue(Queue *q, char *out) { - // If there is no elements in the array, returns the null character. - if(q->size < 1) - return QUEUE_EMPTY; - - // If the offset is greater than data, - // it points to nothing. - if(q->offset >= q->alloc_size) - return QUEUE_EMPTY; - - char front = q->data[q->offset]; - - q->offset++; // Increment the front. - q->size--; // Decrease the size since we removed a character. - - *out = front; - - return QUEUE_OK; -} - -void destroy_queue(Queue *q) { - free(q->data); - free(q); -} - -void read_after_sequence(FILE *fp, const char *seq, char *buffer, size_t buffer_size) { - size_t seq_size = strlen(seq); - Queue *q = queue_with_size(3 * seq_size); - int ch, error; - char elem; - - while((ch = fgetc(fp)) != EOF) { - if(q->size < seq_size) { - enqueue(q, ch); - continue; - } - - assert(q->size == seq_size); // Window is of correct width - - if(strncmp((char *) q->data + q->offset, seq, seq_size) == 0) - break; - - error = dequeue(q, &elem); - assert(error != QUEUE_EMPTY); // Queue should always have at least `seq_size` items - - error = enqueue(q, ch); - assert(error != QUEUE_FULL); // Queue should maintain same size, as 1 item is added and another is removed - } - - destroy_queue(q); - - // Actually read for the rest of the file, or the buffer. - for(size_t i = 0; i < buffer_size; ++i) { - if((ch = fgetc(fp)) == EOF) - break; - - buffer[i] = ch; - } -} diff --git a/src_old/queue.h b/src_old/queue.h deleted file mode 100644 index 1c33a48..0000000 --- a/src_old/queue.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#ifndef QUEUE_H -#define QUEUE_H - -#include -#include -#include -#include - -#define QUEUE_OK 0 -#define QUEUE_EMPTY -1 -#define QUEUE_FULL -2 - -typedef struct { - size_t offset; - size_t size; - size_t alloc_size; - char *data; -} Queue; - -Queue *queue_with_size(size_t size); - -int requeue(Queue *q); - -int enqueue(Queue *q, char val); - -int dequeue(Queue *q, char *out); - -void destroy_queue(Queue *q); - -void test_queue(); - -void read_after_sequence(FILE *fp, const char *seq, char *buffer, size_t buffer_size); - -#endif // QUEUE_H diff --git a/src_old/vars.h b/src_old/vars.h deleted file mode 100644 index 5571912..0000000 --- a/src_old/vars.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef VARS_H -#define VARS_H - -typedef struct { - char separator[65]; - char separator2[65]; - char dash[33]; - bool print_cpu_freq; - bool print_cpu_brand; - bool print_gpu_arch; - bool print_mem_perc; - bool align_infos; - char color[33]; - char bold[33]; - // Labels: - char title_prefix[33]; - char col_prefix[33]; - int col_block_len; - char hostname_label[33]; - char user_label[33]; - char uptime_label[33]; - char os_label[33]; - char kernel_label[33]; - char desktop_label[33]; - char shell_label[33]; - char default_shell_label[33]; - char term_label[33]; - char packages_label[33]; - char host_label[33]; - char bios_label[33]; - char cpu_label[33]; - char gpu_label[33]; - char mem_label[33]; - char pub_ip_label[33]; - char loc_ip_label[33]; - char pwd_label[33]; -} Config; - -extern Config config; - -#endif