diff options
| author | Anser <rostgans@tutamail.com> | 2026-08-12 00:47:59 +0200 |
|---|---|---|
| committer | Anser <rostgans@tutamail.com> | 2026-08-12 00:47:59 +0200 |
| commit | d195f0a76a3ce64761958f7d33ccbdbac3844fec (patch) | |
| tree | 5dd884d5a4ba600704288e316867ea94dcceb59c | |
| parent | dc31d5c3d4d329ddae97d93b41869c96b5f97b2f (diff) | |
trying to workout how to get the maxline width
| -rw-r--r-- | include/cfetch.h | 1 | ||||
| -rw-r--r-- | src/ascii.c | 71 | ||||
| -rw-r--r-- | src/cfetch.c | 4 |
3 files changed, 27 insertions, 49 deletions
diff --git a/include/cfetch.h b/include/cfetch.h index d8a6f92..268fa22 100644 --- a/include/cfetch.h +++ b/include/cfetch.h @@ -34,6 +34,7 @@ void print_ascii_art(system_info_t *info, int art); void get_cpu(system_info_t *info); void get_memory(system_info_t *info); void get_os(system_info_t *info); +void get_line_length(ascii_art_t *ascii, const char **line); /* Util functions */ diff --git a/src/ascii.c b/src/ascii.c index b4df816..2fee648 100644 --- a/src/ascii.c +++ b/src/ascii.c @@ -1,5 +1,6 @@ #include "../include/cfetch.h" #include <stddef.h> +#include <stdio.h> #define MAX_LOGOS 2 @@ -22,8 +23,8 @@ static const distro_mapping_t distro_mappings[] = 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"); + fprintf(stderr, "get_ascii_path: index out of bounce\n"); + fprintf(stdout, "Get default ascii art.\n"); art = 0; } @@ -35,76 +36,52 @@ 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); + char* path = concat("ascii/", name); + printf("path: %s\n", path); 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 + char line[64]; + while (fgets(line, sizeof(line), file)) { + printf("%s", line); + } - // return path ? + // free pointers free(path); } -/* -int get_line_length(const char **line) +// brauche ich diese function überhaupt, mit dieser signatur ? +// get_max_ascii_length +// und dann get_line_length? +// alles im struct speicher? +void get_line_length(ascii_art_t *ascii, const char **line) { size_t length = 0; - size_t max_length = 0; - if (line == NULL) return -1; + if (line == NULL) + { + perror("get_line_length: pointer NULL"); + return; + } + for (int i = 0; line[i] != NULL; i++) { length = strlen(line[i]); - if (length > max_length) { + if (length > ascii->lines) { 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; - } -} -*/ diff --git a/src/cfetch.c b/src/cfetch.c index 1a71f2c..caabbc9 100644 --- a/src/cfetch.c +++ b/src/cfetch.c @@ -21,14 +21,14 @@ int main(void) { system_info_t info = { 0 }; // set default artwork - int art_logo = 0; + int art_logo = 5; // set systeminformation // use // to uncomment or comment get_os(&info); get_memory(&info); get_cpu(&info); - //print_ascii_art(&info, art_logo); + print_ascii_art(&info, art_logo); return 0; } |
