mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
removed ffTrimTrailingWhitespace
This commit is contained in:
parent
f61ffdb149
commit
055804a055
14
src/common.c
14
src/common.c
@ -218,20 +218,6 @@ void ffPrintError(FFinstance* instance, const char* key, const char* message, ..
|
|||||||
va_end(arguments);
|
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)
|
void ffGetFileContent(const char* fileName, FFstrbuf* buffer)
|
||||||
{
|
{
|
||||||
int fd = open(fileName, O_RDONLY);
|
int fd = open(fileName, O_RDONLY);
|
||||||
|
@ -401,29 +401,20 @@ static void parseConfigFile(FFinstance* instance, FFdata* data)
|
|||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
ssize_t read;
|
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
|
if(line.length == 0 || line.chars[0] == '#')
|
||||||
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] == '#')
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
char* valueStart = strchr(line, ' ');
|
char* valueStart = strchr(line.chars, ' ');
|
||||||
if(valueStart == NULL)
|
if(valueStart == NULL)
|
||||||
{
|
{
|
||||||
parseOption(instance, data, line, NULL);
|
parseOption(instance, data, line.chars, NULL);
|
||||||
}
|
}
|
||||||
else
|
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 we want whitespace in values, we need to quote it. This is done to keep consistency with shell.
|
||||||
if(*valueStart == '"')
|
if(*valueStart == '"')
|
||||||
{
|
{
|
||||||
char* last = valueStart + strlen(valueStart) - 1;
|
char* last = line.chars + line.length - 1;
|
||||||
if(*last == '"')
|
if(*last == '"')
|
||||||
{
|
{
|
||||||
++valueStart;
|
++valueStart;
|
||||||
*last = '\0';
|
*last = '\0';
|
||||||
|
--line.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parseOption(instance, data, line, valueStart);
|
parseOption(instance, data, line.chars, valueStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ffStrbufDestroy(&line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lineStart != NULL)
|
if(lineStart != NULL)
|
||||||
|
@ -122,7 +122,6 @@ void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const c
|
|||||||
void ffParseFont(char* font, char* buffer);
|
void ffParseFont(char* font, char* buffer);
|
||||||
void ffFormatGtkPretty(FFstrbuf* buffer, const char* gtk2, const char* gtk3, const char* gtk4);
|
void ffFormatGtkPretty(FFstrbuf* buffer, const char* gtk2, const char* gtk3, const char* gtk4);
|
||||||
void ffPrintError(FFinstance* instance, const char* key, const char* message, ...);
|
void ffPrintError(FFinstance* instance, const char* key, const char* message, ...);
|
||||||
void ffTrimTrailingWhitespace(char* buffer);
|
|
||||||
bool ffPrintCachedValue(FFinstance* instance, const char* key);
|
bool ffPrintCachedValue(FFinstance* instance, const char* key);
|
||||||
void ffPrintAndSaveCachedValue(FFinstance* instance, const char* key, FFstrbuf* value);
|
void ffPrintAndSaveCachedValue(FFinstance* instance, const char* key, FFstrbuf* value);
|
||||||
void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, ...);
|
void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs, ...);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user