fixed
This commit is contained in:
parent
ce965804d3
commit
2d8ac6280f
9 changed files with 116 additions and 51 deletions
89
src/main.c
89
src/main.c
|
@ -2,36 +2,71 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include "structs.h"
|
||||
#include "config.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
#ifdef ERROR_STR
|
||||
char *error_str = ERROR_STR;
|
||||
#else
|
||||
char *error_str = "none";
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef STRIP_RESET_ESCAPE
|
||||
char *reset = "";
|
||||
#else
|
||||
char *reset = "\033[0m";
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DONT_PRINT_LOGO
|
||||
char l_flag = 1;
|
||||
#else
|
||||
char l_flag = 0;
|
||||
char *d_flag = NULL;
|
||||
#endif
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "hld:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'l':
|
||||
l_flag = 1;
|
||||
break;
|
||||
void print_unescape(char newline, char *str) {
|
||||
#ifdef STRIP_LOGO_ESCAPES
|
||||
size_t len = strlen(str);
|
||||
|
||||
case 'd':
|
||||
d_flag = optarg;
|
||||
break;
|
||||
char *str2 = malloc(len);
|
||||
if (str2 == NULL) {
|
||||
fprintf(stderr, "kfetch: malloc: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
case 'h':
|
||||
default:
|
||||
printf("kfetch [-hld]\n\t-h Help\n\t-l Dont print logo\n\t-d STR Set STR as distro name\n");
|
||||
return 0;
|
||||
size_t j = 0;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (str[i] == '\033') {
|
||||
while (str[i] != 'm') {
|
||||
if (i > len) {
|
||||
fputs("kfetch: wrong logo string\n", stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
str2[j] = str[i];
|
||||
j++;
|
||||
}
|
||||
|
||||
str2[j] = '\0';
|
||||
printf("%s%c", str2, newline);
|
||||
|
||||
free(str2);
|
||||
#else
|
||||
printf("%s%c", str, newline);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
FETCH fetch = Init();
|
||||
if (d_flag != NULL) {
|
||||
snprintf(fetch.os_name, sizeof(fetch.os_name), "%s", d_flag);
|
||||
GetArt(&fetch, 0);
|
||||
}
|
||||
|
||||
size_t j = 0;
|
||||
for (size_t i = 0; i < sizeof(CONFIG) / sizeof(PARAMETR); i++) {
|
||||
|
@ -40,29 +75,29 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* Print ascii logo */
|
||||
if (j < fetch.logo_size && !l_flag)
|
||||
printf("%s", fetch.logo[j]);
|
||||
print_unescape('\0', fetch.logo[j]);
|
||||
|
||||
else if (j >= fetch.logo_size && !l_flag)
|
||||
printf("%s", fetch.logo[fetch.logo_size - 1]);
|
||||
print_unescape('\0', fetch.logo[fetch.logo_size - 1]);
|
||||
|
||||
/* Function exec */
|
||||
printf("%s%s", fetch.color, CONFIG[i].par.str0);
|
||||
printf("%s%s", fetch.logo_color, CONFIG[i].par.str0);
|
||||
if (CONFIG[i].func(CONFIG[i].par, fetch))
|
||||
printf("%s%s", FONT_COLOR, ON_ERROR_STR);
|
||||
printf("%s%s", fetch.font_color, error_str);
|
||||
|
||||
else {
|
||||
if (CONFIG[i].par.str1 != NULL)
|
||||
printf(CONFIG[i].par.str1, fetch.color);
|
||||
printf(CONFIG[i].par.str1, fetch.font_color);
|
||||
}
|
||||
|
||||
j++;
|
||||
printf("\033[0m\n");
|
||||
printf("%s\n", reset);
|
||||
}
|
||||
|
||||
for (; j < fetch.logo_size - 1; j++)
|
||||
if (!l_flag)
|
||||
printf("%s\n", fetch.logo[j]);
|
||||
print_unescape('\n', fetch.logo[j]);
|
||||
|
||||
printf("\033[0m");
|
||||
printf("%s", reset);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue