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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/* cfetch is my try to implement a neofetch/fastfetch/commiefetch clone in C.
* Copyright (C) 2026 Anser <https://codeberg.org/Anser/cfetch>
*
* cfetch is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* cfetch is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "../include/cfetch.h"
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#define MAX_LOGOS 5
static const struct ascii_mapping_t ascii_mappings[] =
{
{"cccp", "cccp.ascii"},
{"cccp_shield", "cccp_shield.ascii"},
{"ascii_hammer", "ascii_hammer.ascii"},
{"east_germany", "east_germany.ascii"},
{"soviet_star", "soviet_star.ascii"},
{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) {
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(get_ascii_path(), 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("OS: %s\n", info->distro);
printf("Kernel: %s\n", info->kernel);
printf("CPU: %s\n", info->cpu);
printf("%s\n", info->memory);
printf("\n");
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;
}
}
}
*/
|