mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
better structure looping
This commit is contained in:
+28
-34
@@ -478,36 +478,37 @@ static void parseConfigFile(FFinstance* instance, FFdata* data)
|
||||
if(line.length == 0 || line.chars[0] == '#')
|
||||
continue;
|
||||
|
||||
char* valueStart = strchr(line.chars, ' ');
|
||||
if(valueStart == NULL)
|
||||
uint32_t firstSpace = ffStrbufFirstIndexC(&line, ' ');
|
||||
|
||||
if(firstSpace >= line.length)
|
||||
{
|
||||
parseOption(instance, data, line.chars, NULL);
|
||||
ffStrbufDestroy(&line);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Seperate key and value by simply replacing the first space with a \0
|
||||
*valueStart = '\0';
|
||||
|
||||
//Seperate key and value by simply replacing the first space with a \0
|
||||
char* valueStart = &line.chars[firstSpace];
|
||||
*valueStart = '\0';
|
||||
++valueStart;
|
||||
|
||||
//Trim whitespace at beginn of value
|
||||
while(*valueStart == ' ')
|
||||
++valueStart;
|
||||
|
||||
//Trim whitespace at beginn of value
|
||||
while(*valueStart == ' ')
|
||||
++valueStart;
|
||||
|
||||
//If we want whitespace in values, we need to quote it. This is done to keep consistency with shell.
|
||||
if(*valueStart == '"')
|
||||
//If we want whitespace in values, we need to quote it. This is done to keep consistency with shell.
|
||||
if(*valueStart == '"')
|
||||
{
|
||||
char* last = line.chars + line.length - 1;
|
||||
if(*last == '"')
|
||||
{
|
||||
char* last = line.chars + line.length - 1;
|
||||
if(*last == '"')
|
||||
{
|
||||
++valueStart;
|
||||
*last = '\0';
|
||||
--line.length;
|
||||
}
|
||||
++valueStart;
|
||||
*last = '\0';
|
||||
--line.length;
|
||||
}
|
||||
|
||||
parseOption(instance, data, line.chars, valueStart);
|
||||
}
|
||||
|
||||
parseOption(instance, data, line.chars, valueStart);
|
||||
ffStrbufDestroy(&line);
|
||||
}
|
||||
|
||||
@@ -623,22 +624,15 @@ static void run(FFinstance* instance, FFdata* data)
|
||||
if(data->structure.length == 0)
|
||||
ffStrbufSetS(&data->structure, FASTFETCH_DEFAULT_STRUCTURE);
|
||||
|
||||
char* remaining = data->structure.chars;
|
||||
char* colon = NULL;
|
||||
|
||||
while(true)
|
||||
uint32_t lastIndex = 0;
|
||||
while (lastIndex < data->structure.length)
|
||||
{
|
||||
colon = strchr(remaining, ':');
|
||||
uint32_t colonIndex = ffStrbufFirstIndexAfterC(&data->structure, lastIndex, ':');
|
||||
data->structure.chars[colonIndex] = '\0';
|
||||
|
||||
if(colon != NULL)
|
||||
*colon = '\0';
|
||||
parseStructureCommand(instance, data, data->structure.chars + lastIndex);
|
||||
|
||||
parseStructureCommand(instance, data, remaining);
|
||||
|
||||
if(colon != NULL)
|
||||
remaining = colon + 1;
|
||||
else
|
||||
break;
|
||||
lastIndex = colonIndex + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -77,12 +77,11 @@ void ffPrintDisk(FFinstance* instance)
|
||||
uint32_t lastIndex = 0;
|
||||
while (lastIndex < instance->config.diskFolders.length)
|
||||
{
|
||||
uint32_t colonIndex = ffStrbufFirstIndexC(&instance->config.diskFolders, ':');
|
||||
|
||||
if(colonIndex < instance->config.diskFolders.length)
|
||||
instance->config.diskFolders.chars[colonIndex] = '\0';
|
||||
uint32_t colonIndex = ffStrbufFirstIndexAfterC(&instance->config.diskFolders, lastIndex, ':');
|
||||
instance->config.diskFolders.chars[colonIndex] = '\0';
|
||||
|
||||
printFolder(instance, instance->config.diskFolders.chars + lastIndex);
|
||||
|
||||
lastIndex = colonIndex + 1;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-2
@@ -333,9 +333,9 @@ void ffStrbufRemoveStrings(FFstrbuf* strbuf, uint32_t numStrings, ...)
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t ffStrbufFirstIndexC(FFstrbuf* strbuf, const char c)
|
||||
uint32_t ffStrbufFirstIndexAfterC(FFstrbuf* strbuf, uint32_t start, const char c)
|
||||
{
|
||||
for(uint32_t i = 0; i < strbuf->length; i++)
|
||||
for(uint32_t i = start; i < strbuf->length; i++)
|
||||
{
|
||||
if(strbuf->chars[i] == c)
|
||||
return i;
|
||||
@@ -343,6 +343,11 @@ uint32_t ffStrbufFirstIndexC(FFstrbuf* strbuf, const char c)
|
||||
return strbuf->length;
|
||||
}
|
||||
|
||||
uint32_t ffStrbufFirstIndexC(FFstrbuf* strbuf, const char c)
|
||||
{
|
||||
return ffStrbufFirstIndexAfterC(strbuf, 0, c);
|
||||
}
|
||||
|
||||
uint32_t ffStrbufLastIndexC(FFstrbuf* strbuf, const char c)
|
||||
{
|
||||
//We need to loop one higher than the actual index, because uint32_t is guranteed to be >= 0, so this statement would always be true
|
||||
|
||||
@@ -68,6 +68,7 @@ void ffStrbufTrim(FFstrbuf* strbuf, char c);
|
||||
|
||||
void ffStrbufRemoveStrings(FFstrbuf* strbuf, uint32_t numStrings, ...);
|
||||
|
||||
uint32_t ffStrbufFirstIndexAfterC(FFstrbuf* strbuf, uint32_t start, const char c);
|
||||
uint32_t ffStrbufFirstIndexC(FFstrbuf* strbuf, const char c);
|
||||
uint32_t ffStrbufLastIndexC(FFstrbuf* strbuf, const char c);
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@ int main(int argc, char** argv)
|
||||
puts("Configuration");
|
||||
ffLoadLogoSet(&instance.config, "arch");
|
||||
ffStrbufSetS(&instance.config.color, instance.config.logo.color);
|
||||
instance.config.showErrors = true;
|
||||
instance.config.recache = true;
|
||||
instance.config.cacheSave = false;
|
||||
)
|
||||
|
||||
FASTFETCH_TEST_PERFORMANCE(ffPrintTitle(&instance))
|
||||
|
||||
Reference in New Issue
Block a user