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
89
90
91
92
93
|
#include "../include/cfetch.h"
#include <stddef.h>
#include <stdio.h>
#define MAX_LOGOS 2
static const struct ascii_mapping_t ascii_mappings[] =
{
{"cccp", "cccp.ascii"},
{"cccp_shield", "cccp_shield.ascii"},
{NULL, NULL}
};
const char* get_ascii_name(const struct ascii_mapping_t *d_map, int art)
{
if (art > MAX_LOGOS) {
fprintf(stderr, "get_ascii_path: index out of bounce\n");
fprintf(stderr, "Get default ascii art.\n");
art = 0;
}
const char* ascii_name = d_map[art].ascii_file;
return ascii_name;
}
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);
if (info->debug == 1) {
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);
}
void print_system_info(struct system_info_t *info)
{
printf("Kernel: %s\n", info->kernel);
printf("CPU: %s\n", info->cpu);
printf("%s\n", info->memory);
//printf(logo)
print_ascii_art(info);
}
// 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;
}
}
}
*/
|