aboutsummaryrefslogtreecommitdiff
path: root/src/ascii.c
blob: f1acce769105c27e2806be278d2d4fdec7ca4753 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "../include/cfetch.h"
#include <stddef.h>
#include <stdio.h>

#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(stderr, "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);
    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);
    }
    
    // free pointers
    free(path);
}

// 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;

    if (line == NULL)
    {
	perror("get_line_length: pointer NULL");
	return;
    }

    for (int i = 0; line[i] != NULL; i++) {
	length = strlen(line[i]);

	if (length > ascii->lines) {
	    max_length = length;
	}
    }
}
*/