diff --git a/src/main.c b/src/main.c index f3770dc..5551588 100644 --- a/src/main.c +++ b/src/main.c @@ -1,21 +1,66 @@ #define _MAIN_H #include +#include #include "fetch.h" #include "config.h" -int main(void) { +int main(int argc, char **argv) { + unsigned int l_flag = 0; + unsigned int s_flag = 0; + char *d_flag = NULL; + + int opt; + while ((opt = getopt(argc, argv, "hlsd:")) != -1) { + switch (opt) { + case 'l': + l_flag = 1; + break; + + case 's': + s_flag = 1; + break; + + case 'd': + d_flag = optarg; + break; + + case 'h': + default: + printf("kfetch [hl]\n\t[-h Help menu] [-s Strip lines]\n\t[-l Dont print logo]\n\t[-d N Set N as distro name]\n"); + return 0; + } + } + FETCH fetch = Init(); + if (d_flag != NULL) { + snprintf(fetch.os_name, sizeof(fetch.os_name), "%s", d_flag); + GetArt(&fetch); + } int flag = 0; size_t i = 0; for (i = 0; i < sizeof(CONFIG) / sizeof(PARAMETR); i++) { - if (i < fetch.logo_size && !flag) + /* Logo print */ + if (i < fetch.logo_size && !flag && !l_flag) printf("%s", fetch.logo[i]); - if (i >= fetch.logo_size && !flag) + else if (i >= fetch.logo_size && !flag && !l_flag) printf("%s", fetch.logo[fetch.logo_size - 1]); - if (!CONFIG[i].func(CONFIG[i].title, fetch)) { + /* Strip */ + char *title = CONFIG[i].title; + if (s_flag) { + size_t len = strlen(title); + for (size_t i = 0; i < len; i++) { + if (title[0] != ' ') + break; + + title++; + } + } + + /* Function exec */ + if (!CONFIG[i].func(title, fetch)) { flag = 0; printf("\033[0m\n"); }