From 028a269b2438dfe54fd948b57abb9440dd47191e Mon Sep 17 00:00:00 2001 From: Guaxinim5573 Date: Wed, 14 Apr 2021 18:38:49 -0300 Subject: [PATCH] add --config --- uwufetch.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 08a264f..97236da 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -62,7 +62,7 @@ int ascii_image_flag = 0, show_colors = 1; char user[32], host[256], shell[64], kernel[256], version_name[64], cpu_model[256], gpu_model[8][256] = {{'0'}, {'0'}, {'0'}, {'0'}, {'0'}, {'0'}, {'0'}, {'0'}}, - pkgman_name[64], image_name[32]; + pkgman_name[64], image_name[128], *config_directory = NULL; // functions definitions, to use them in main() int pkgman(); @@ -81,7 +81,7 @@ int main(int argc, char *argv[]) { int opt = 0; static struct option long_options[] = { { "ascii", no_argument, NULL, 'a' }, - { "config", required_argument, NULL, 0}, + { "config", required_argument, NULL, 'c'}, { "distro", required_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, { "image", optional_argument, NULL, 'i' }, @@ -89,12 +89,14 @@ int main(int argc, char *argv[]) { { NULL, 0, NULL, 0 } }; get_info(); - parse_config(); - while ((opt = getopt_long(argc, argv, "ad:hi::l", long_options, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "ac:d:hi::l", long_options, NULL)) != -1) { switch (opt) { case 'a': ascii_image_flag = 0; break; + case 'c': + config_directory = optarg; + break; case 'd': if (optarg) sprintf(version_name, "%s", optarg); break; @@ -103,10 +105,8 @@ int main(int argc, char *argv[]) { return 0; case 'i': ascii_image_flag = 1; - char *image_dir = NULL; - if(!optarg && argv[optind] != NULL && argv[optind][0] != '-') image_dir = argv[optind++]; - else image_dir = optarg; - if(image_dir != NULL) sprintf(image_name, "%s", image_dir); + if(!optarg && argv[optind] != NULL && argv[optind][0] != '-') sprintf(image_name, "%s", argv[optind++]); + else if(optarg) sprintf(image_name, "%s", optarg); break; case 'l': list(argv[0]); @@ -115,6 +115,7 @@ int main(int argc, char *argv[]) { break; } } + parse_config(); if ((argc == 1 && ascii_image_flag == 0) || (argc > 1 && ascii_image_flag == 0)) print_ascii(); else if (ascii_image_flag) print_image(); uwu_name(); @@ -125,12 +126,14 @@ void parse_config() { char line[256]; char *homedir = getenv("HOME"); char *temp_buffer = ""; - - FILE *config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r"); + FILE *config; + + if(config_directory == NULL) config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r"); + else config = fopen(config_directory, "r"); if(config == NULL) return; while(fgets(line, sizeof(line), config)) { if(line[0] == '#') continue; - ascii_image_flag = sscanf(line, "image=%s", image_name); + if(strlen(image_name) < 1 && ascii_image_flag == 0) ascii_image_flag = sscanf(line, "image=%s", image_name); sscanf(line, "distro=%s", version_name); if (sscanf(line, "nouser%s", temp_buffer)) show_user_info = 0; if (sscanf(line, "noos%s", temp_buffer)) show_os = 0;