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

fix replacing ignorecase with multiple things to replace
This commit is contained in:
TheDarkBug 2021-10-03 13:52:50 +02:00 committed by GitHub
commit 9f32cc1a6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -173,7 +173,7 @@ 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(host_model);
@ -188,9 +188,10 @@ 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");
}
else
config = fopen(config_directory, "r");
if (config == NULL)
@ -708,11 +709,12 @@ replace("Hello World!", "World", "everyone")
*/
void replace(char *original, char *search, char *replacer)
{
char buffer[1024];
char *ch;
if (!(ch = strstr(original, search)))
return;
char buffer[1024];
strncpy(buffer, original, ch - original);
buffer[ch - original] = 0;
sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search));
@ -724,18 +726,20 @@ void replace(char *original, char *search, char *replacer)
void replace_ignorecase(char *original, char *search, char *replacer)
{
char buffer[1024];
char *ch;
if (!(ch = strcasestr(original, search)))
return;
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(original, search, replacer);
replace(original, search, replacer);
return replace(original, search, replacer);
}
void print_ascii()