From 5c42cc27e8a5240b2c200b7162f700f791e958f7 Mon Sep 17 00:00:00 2001 From: Anser Date: Wed, 19 Aug 2026 12:45:07 +0200 Subject: added get_ascii_path - added global ascii folder in /opt/cfetch/ --- Makefile | 6 ++++++ src/ascii.c | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index fe2e4a8..19fb8af 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,8 @@ CC = gcc CFLAGS = -Wall -Wextra -Wundef -Wshadow -Wformat=2 PREFIX ?= /usr/local TARGET = cfetch +ASCII = ascii +ASCII_DIR = /opt/$(TARGET) SRC = src/cfetch.c \ src/sysinfo.c \ @@ -35,8 +37,12 @@ $(TARGET): @echo "Finished install of $(TARGET)!" install: $(TARGET) + @echo "Creating directories" mkdir -p $(PREFIX)/bin + mkdir -p $(ASCII_DIR) + @echo "Installing $(TARGET)" cp $(TARGET) $(PREFIX)/bin/$(TARGET) + cp -r $(ASCII) $(ASCII_DIR) uninstall: rm -f $(TARGET) diff --git a/src/ascii.c b/src/ascii.c index 0a2dc67..b199dd4 100644 --- a/src/ascii.c +++ b/src/ascii.c @@ -18,6 +18,7 @@ #include "../include/cfetch.h" #include #include +#include #define MAX_LOGOS 5 @@ -32,6 +33,20 @@ static const struct ascii_mapping_t ascii_mappings[] = {NULL, NULL} }; +char* get_ascii_path(void) +{ + char *path[] = { + "/opt/cfetch/ascii/", + "./ascii/" + }; + + for (size_t i = 0; i < (sizeof(path) / sizeof(path[0])) ; i++) { + if (access(path[i], F_OK) == 0) return path[i]; + } + + return NULL; +} + const char* get_ascii_name(const struct ascii_mapping_t *d_map, int art) { if (art >= MAX_LOGOS) { @@ -48,7 +63,7 @@ void print_ascii_art(struct system_info_t *info) { // get ascii name const char* name = get_ascii_name(ascii_mappings, info->ascii_art); - char* path = concat("ascii/", name); + char* path = concat(get_ascii_path(), name); if (info->debug == 1) { printf("path: %s\n", path); -- cgit v1.2.3