From cc399b471fac12a593a8ab113799d67177d91d35 Mon Sep 17 00:00:00 2001 From: Joshix Date: Sun, 3 Oct 2021 19:53:32 +0200 Subject: [PATCH 1/4] use recursion to fix missing replacement --- uwufetch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 068d48c..1acf975 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -738,8 +738,8 @@ void replace_ignorecase(char *original, char *search, char *replacer) original[0] = 0; strcpy(original, buffer); - replace(original, search, replacer); - return replace(original, search, replacer); + + return replace_ignorecase(original, search, replacer); } void print_ascii() From 07b2c4a4d8b546b08cc3d66ad1555e594329d00c Mon Sep 17 00:00:00 2001 From: Joshix Date: Sun, 3 Oct 2021 21:33:53 +0200 Subject: [PATCH 2/4] use while loop instead of recursion for replace functions --- uwufetch.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 1acf975..2532cca 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -710,36 +710,29 @@ replace("Hello World!", "World", "everyone") void replace(char *original, char *search, char *replacer) { char *ch; - if (!(ch = strstr(original, search))) - return; - char buffer[1024]; + while (ch = strstr(original, search)) { + strncpy(buffer, original, ch - original); + buffer[ch - original] = 0; + sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search)); - strncpy(buffer, original, ch - original); - buffer[ch - original] = 0; - sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search)); - - original[0] = 0; - strcpy(original, buffer); - return replace(original, search, replacer); + original[0] = 0; + strcpy(original, buffer); + } } void replace_ignorecase(char *original, char *search, char *replacer) { char *ch; - if (!(ch = strcasestr(original, search))) - return; + char buffer[1024]; + while (ch = strcasestr(original, search)) { + strncpy(buffer, original, ch - original); + buffer[ch - original] = 0; + sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search)); - char buffer[1024]; - - strncpy(buffer, original, ch - original); - buffer[ch - original] = 0; - sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search)); - - original[0] = 0; - strcpy(original, buffer); - - return replace_ignorecase(original, search, replacer); + original[0] = 0; + strcpy(original, buffer); + } } void print_ascii() From d6d9962b9328fa35deeee451047977c902930cfd Mon Sep 17 00:00:00 2001 From: TheDarkBug Date: Sun, 3 Oct 2021 23:48:10 +0200 Subject: [PATCH 3/4] CPU string fix try + some formatting --- uwufetch.c | 63 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 2532cca..6a23ac2 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -173,9 +173,9 @@ int main(int argc, char *argv[]) for (int i = 0; gpu_model[i][0]; i++) { - uwu_hw(gpu_model[i]); + uwu_hw(gpu_model[i]); } - uwu_hw(cpu_model); + // uwu_hw("cpu"); uwu_hw(host_model); print_info(); @@ -188,10 +188,11 @@ void parse_config() // opening and reading the config file FILE *config; - if (config_directory == NULL) { - if (homedir != NULL) - config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r"); - } + if (config_directory == NULL) + { + if (homedir != NULL) + config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r"); + } else config = fopen(config_directory, "r"); if (config == NULL) @@ -480,11 +481,11 @@ void get_info() if (sscanf(line, "model name : %[^\n]", cpu_model)) #endif break; - char *tmp_user = getenv("USER"); - if (tmp_user == NULL) - sprintf(user, "%s", ""); - else - sprintf(user, "%s", tmp_user); + char *tmp_user = getenv("USER"); + if (tmp_user == NULL) + sprintf(user, "%s", ""); + else + sprintf(user, "%s", tmp_user); if (iscygwin == 0) fclose(os_release); } @@ -532,9 +533,9 @@ void get_info() gethostname(host, 256); char *tmp_shell = getenv("SHELL"); if (tmp_shell == NULL) - sprintf(shell, "%s", ""); + sprintf(shell, "%s", ""); else - sprintf(shell, "%s", tmp_shell); + sprintf(shell, "%s", tmp_shell); if (strlen(shell) > 16) memmove(&shell, &shell[27], strlen(shell)); // android shell was too long, this works only for termux @@ -711,28 +712,30 @@ void replace(char *original, char *search, char *replacer) { char *ch; char buffer[1024]; - while (ch = strstr(original, search)) { - strncpy(buffer, original, ch - original); - buffer[ch - original] = 0; - sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search)); + while (ch = strstr(original, search)) + { + strncpy(buffer, original, ch - original); + buffer[ch - original] = 0; + sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search)); - original[0] = 0; - strcpy(original, buffer); - } + original[0] = 0; + strcpy(original, buffer); + } } void replace_ignorecase(char *original, char *search, char *replacer) { char *ch; - char buffer[1024]; - while (ch = strcasestr(original, search)) { - strncpy(buffer, original, ch - original); - buffer[ch - original] = 0; - sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search)); + char buffer[1024]; + while (ch = strcasestr(original, search)) + { + strncpy(buffer, original, ch - original); + buffer[ch - original] = 0; + sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search)); - original[0] = 0; - strcpy(original, buffer); - } + original[0] = 0; + strcpy(original, buffer); + } } void print_ascii() @@ -1151,9 +1154,9 @@ void uwu_hw(char *hwname) { #define HW_TO_UWU(original, uwuified) \ replace_ignorecase(hwname, original, uwuified); - + replace(hwname, "CPU", "CPUwU"); + replace(hwname, "cpu", "CPUwU"); HW_TO_UWU("lenovo", "LenOwO") - HW_TO_UWU("cpu", "CPUwU") HW_TO_UWU("gpu", "GPUwU") HW_TO_UWU("graphics", "Gwaphics") HW_TO_UWU("corporation", "COwOpowation") From 87c0cbe954df5b35d37520fdb2f7258ead666312 Mon Sep 17 00:00:00 2001 From: TheDarkBug Date: Sun, 3 Oct 2021 23:54:59 +0200 Subject: [PATCH 4/4] Fixed recursion segfault --- uwufetch.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/uwufetch.c b/uwufetch.c index 6a23ac2..15c6029 100644 --- a/uwufetch.c +++ b/uwufetch.c @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) { uwu_hw(gpu_model[i]); } - // uwu_hw("cpu"); + uwu_hw(cpu_model); uwu_hw(host_model); print_info(); @@ -712,8 +712,9 @@ void replace(char *original, char *search, char *replacer) { char *ch; char buffer[1024]; - while (ch = strstr(original, search)) + while ((ch = strstr(original, search))) { + ch = strstr(original, search); strncpy(buffer, original, ch - original); buffer[ch - original] = 0; sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search)); @@ -727,7 +728,7 @@ void replace_ignorecase(char *original, char *search, char *replacer) { char *ch; char buffer[1024]; - while (ch = strcasestr(original, search)) + while ((ch = strcasestr(original, search))) { strncpy(buffer, original, ch - original); buffer[ch - original] = 0; @@ -1154,7 +1155,7 @@ void uwu_hw(char *hwname) { #define HW_TO_UWU(original, uwuified) \ replace_ignorecase(hwname, original, uwuified); - replace(hwname, "CPU", "CPUwU"); + replace(hwname, "CPU", "CC\bPUwU"); // for some reasons this caused a segfault, using a \b char fixes it replace(hwname, "cpu", "CPUwU"); HW_TO_UWU("lenovo", "LenOwO") HW_TO_UWU("gpu", "GPUwU")