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
|
// opening and reading the config file
|
||||||
FILE *config;
|
FILE *config;
|
||||||
if (config_directory == NULL)
|
if (config_directory == NULL) {
|
||||||
if (homedir != NULL)
|
if (homedir != NULL)
|
||||||
config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r");
|
config = fopen(strcat(homedir, "/.config/uwufetch/config"), "r");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
config = fopen(config_directory, "r");
|
config = fopen(config_directory, "r");
|
||||||
if (config == NULL)
|
if (config == NULL)
|
||||||
|
@ -708,11 +709,12 @@ replace("Hello World!", "World", "everyone")
|
||||||
*/
|
*/
|
||||||
void replace(char *original, char *search, char *replacer)
|
void replace(char *original, char *search, char *replacer)
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
|
||||||
char *ch;
|
char *ch;
|
||||||
if (!(ch = strstr(original, search)))
|
if (!(ch = strstr(original, search)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
char buffer[1024];
|
||||||
|
|
||||||
strncpy(buffer, original, ch - original);
|
strncpy(buffer, original, ch - original);
|
||||||
buffer[ch - original] = 0;
|
buffer[ch - original] = 0;
|
||||||
sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search));
|
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)
|
void replace_ignorecase(char *original, char *search, char *replacer)
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
|
||||||
char *ch;
|
char *ch;
|
||||||
if (!(ch = strcasestr(original, search)))
|
if (!(ch = strcasestr(original, search)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
char buffer[1024];
|
||||||
|
|
||||||
strncpy(buffer, original, ch - original);
|
strncpy(buffer, original, ch - original);
|
||||||
buffer[ch - original] = 0;
|
buffer[ch - original] = 0;
|
||||||
sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search));
|
sprintf(buffer + (ch - original), "%s%s", replacer, ch + strlen(search));
|
||||||
|
|
||||||
original[0] = 0;
|
original[0] = 0;
|
||||||
strcpy(original, buffer);
|
strcpy(original, buffer);
|
||||||
|
replace(original, search, replacer);
|
||||||
return replace(original, search, replacer);
|
return replace(original, search, replacer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue