aboutsummaryrefslogtreecommitdiff
path: root/src/ascii.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ascii.c')
-rw-r--r--src/ascii.c133
1 files changed, 69 insertions, 64 deletions
diff --git a/src/ascii.c b/src/ascii.c
index f1acce7..f2e466f 100644
--- a/src/ascii.c
+++ b/src/ascii.c
@@ -4,62 +4,67 @@
#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[] =
+static const struct ascii_mapping_t ascii_mappings[] =
{
- {"cccp", "cccp.ascii"},
- {"cccp_shield", "cccp_shield.ascii"},
- {NULL, NULL}
+ {"cccp", "cccp.ascii"},
+ {"cccp_shield", "cccp_shield.ascii"},
+ {NULL, NULL}
};
-const char* get_ascii_name(const distro_mapping_t *d_map, int art)
+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)
{
- 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;
+ // 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_ascii_art(system_info_t *info, int art)
+void print_system_info(struct system_info_t *info)
{
- // 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);
+ 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 ?
@@ -67,22 +72,22 @@ void print_ascii_art(system_info_t *info, int art)
// und dann get_line_length?
// alles im struct speicher?
/*
-void get_line_length(ascii_art_t *ascii, const char **line)
-{
- size_t length = 0;
+ 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;
- }
+ if (line == NULL)
+ {
+ perror("get_line_length: pointer NULL");
+ return;
+ }
- for (int i = 0; line[i] != NULL; i++) {
- length = strlen(line[i]);
+ for (int i = 0; line[i] != NULL; i++) {
+ length = strlen(line[i]);
- if (length > ascii->lines) {
- max_length = length;
- }
- }
-}
-*/
+ if (length > ascii->lines) {
+ max_length = length;
+ }
+ }
+ }
+ */