Merge pull request #139 from Joshix-1/replacement-fix

Fibal replacement fix
This commit is contained in:
TheDarkBug 2021-10-03 23:56:06 +02:00 committed by GitHub
commit d4a46f2fa4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -188,7 +188,8 @@ void parse_config()
// opening and reading the config file
FILE *config;
if (config_directory == NULL) {
if (config_directory == NULL)
{
if (homedir != NULL)
config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r");
}
@ -710,36 +711,32 @@ 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)))
{
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);
return replace(original, search, replacer);
}
}
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));
original[0] = 0;
strcpy(original, buffer);
replace(original, search, replacer);
return replace(original, search, replacer);
}
}
void print_ascii()
@ -1158,9 +1155,9 @@ void uwu_hw(char *hwname)
{
#define HW_TO_UWU(original, uwuified) \
replace_ignorecase(hwname, original, uwuified);
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("cpu", "CPUwU")
HW_TO_UWU("gpu", "GPUwU")
HW_TO_UWU("graphics", "Gwaphics")
HW_TO_UWU("corporation", "COwOpowation")