diff --git a/src/common.c b/src/common.c index 5d4ff02d..a5bcad16 100644 --- a/src/common.c +++ b/src/common.c @@ -218,20 +218,6 @@ void ffPrintError(FFinstance* instance, const char* key, const char* message, .. va_end(arguments); } -void ffTrimTrailingWhitespace(char* buffer) -{ - uint32_t end = 0; - - for(uint32_t i = 0; buffer[i] != '\0'; i++) - { - if(buffer[i] != ' ') - end = i; - } - - if(buffer[end + 1] == ' ') - buffer[end + 1] = '\0'; -} - void ffGetFileContent(const char* fileName, FFstrbuf* buffer) { int fd = open(fileName, O_RDONLY); diff --git a/src/fastfetch.c b/src/fastfetch.c index 8e90eaa0..16bd2692 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -401,29 +401,20 @@ static void parseConfigFile(FFinstance* instance, FFdata* data) size_t len = 0; ssize_t read; - while ((read = getline(&lineStart, &len, file)) != -1) { + while ((read = getline(&lineStart, &len, file)) != -1) + { + FFstrbuf line; + ffStrbufInitS(&line, lineStart); + ffStrbufTrimRight(&line, '\n'); + ffStrbufTrim(&line, ' '); - //We need to copy lineStart because we modify this value, but need the original for free - char* line = lineStart; - - if(line[read - 1] == '\n') - line[read - 1] = '\0'; - else - line[read] = '\0'; - - ffTrimTrailingWhitespace(line); - - //This trims leading whitespace - while(*line == ' ') - ++line; - - if(line[0] == '\0' || line[0] == '#') + if(line.length == 0 || line.chars[0] == '#') continue; - char* valueStart = strchr(line, ' '); + char* valueStart = strchr(line.chars, ' '); if(valueStart == NULL) { - parseOption(instance, data, line, NULL); + parseOption(instance, data, line.chars, NULL); } else { @@ -438,16 +429,19 @@ static void parseConfigFile(FFinstance* instance, FFdata* data) //If we want whitespace in values, we need to quote it. This is done to keep consistency with shell. if(*valueStart == '"') { - char* last = valueStart + strlen(valueStart) - 1; + char* last = line.chars + line.length - 1; if(*last == '"') { ++valueStart; *last = '\0'; + --line.length; } } - parseOption(instance, data, line, valueStart); + parseOption(instance, data, line.chars, valueStart); } + + ffStrbufDestroy(&line); } if(lineStart != NULL) diff --git a/src/fastfetch.h b/src/fastfetch.h index 5faa599f..495d8a06 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -122,7 +122,6 @@ void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const c void ffParseFont(char* font, char* buffer); void ffFormatGtkPretty(FFstrbuf* buffer, const char* gtk2, const char* gtk3, const char* gtk4); void ffPrintError(FFinstance* instance, const char* key, const char* message, ...); -void ffTrimTrailingWhitespace(char* buffer); bool ffPrintCachedValue(FFinstance* instance, const char* key); void ffPrintAndSaveCachedValue(FFinstance* instance, const char* key, FFstrbuf* value); void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, ...);