From 729746e50ebc8e4eb4c98f7556a241aec111e07d Mon Sep 17 00:00:00 2001 From: Anser Date: Tue, 11 Aug 2026 13:11:39 +0200 Subject: some more rework in readme.md and src file structure --- src/ascii.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/ascii.c (limited to 'src/ascii.c') diff --git a/src/ascii.c b/src/ascii.c new file mode 100644 index 0000000..b4df816 --- /dev/null +++ b/src/ascii.c @@ -0,0 +1,110 @@ +#include "../include/cfetch.h" +#include + +#define MAX_LOGOS 2 + +/* +typedef struct distro_mapping_t +{ + const char *distro_pattern; + const char *ascii_file; +} distro_mapping_t; +*/ + + +static const distro_mapping_t distro_mappings[] = +{ + {"cccp", "cccp.ascii"}, + {"cccp_shield", "cccp_shield.ascii"}, + {NULL, NULL} +}; + +const char* get_ascii_name(const distro_mapping_t *d_map, int art) +{ + if (art > MAX_LOGOS) { + fprintf(stdout, "get_ascii_path: index out of bounce:\n"); + fprintf(stdout, "get default ascii art.\n"); + art = 0; + } + + const char* ascii_name = d_map[art].ascii_file; + return ascii_name; +} + +void print_ascii_art(system_info_t *info, int art) +{ + // get ascii name + const char* name = get_ascii_name(distro_mappings, art); + char* path = concat("../ascii/", name); + + if (path == NULL) + { + perror("print_ascii_art: could not concat"); + return; + } + FILE* file = fopen(path, "r"); + + if (file == NULL) { + perror("print_ascii_art: could not open file"); + return; + } + // get mapping + + // return path ? + free(path); +} + +/* +int get_line_length(const char **line) +{ + size_t length = 0; + size_t max_length = 0; + + if (line == NULL) return -1; + for (int i = 0; line[i] != NULL; i++) { + length = strlen(line[i]); + + if (length > max_length) { + max_length = length; + } + } + return max_length; +} + + +const char **logo(int index) { + + static const char *logo0[] = { +" _____________", +" / \\", +" | ☆ ☆ ☆ |", +" | ☆ ☭ ☆ |", +" | ☆ ☆ ☆ |", +" \\_____________/", +" Рабочие мира, объединяйтесь!", + NULL + }; + + + static const char *logo1[] = { +" ╔═══════════════════╗", +" ║ ║", +" ║ ☭ C C C P ☭ ║", +" ║ ║", +" ╚═══════════════════╝", +" Власть — Советам!", + NULL + }; + + if (index < 0 || index >= MAX_LOGOS) return NULL; + + switch (index) { + case 0: + return logo0; + case 1: + return logo1; + default: + return NULL; + } +} +*/ -- cgit v1.2.3