Merge pull request #138 from Joshix-1/replacement-fix
fix replacing ignorecase with multiple things to replace
This commit is contained in:
commit
9f32cc1a6d
1 changed files with 9 additions and 5 deletions
10
uwufetch.c
10
uwufetch.c
|
@ -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,17 +726,19 @@ 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);
|
||||
replace(original, search, replacer);
|
||||
return replace(original, search, replacer);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue