Merge branch 'LinusDierheimer:master' into master

This commit is contained in:
DarN
2021-05-17 06:15:10 +02:00
8 changed files with 79 additions and 42 deletions
-3
View File
@@ -239,13 +239,10 @@ static void getMate(FFinstance* instance, FFWMDEResult* result)
//I parse the file 3 times by purpose, because the properties are not guaranteed to be in order
ffParsePropFile("/usr/share/mate-about/mate-version.xml", "<platform>", &result->deVersion);
ffStrbufSubstrBeforeFirstC(&result->deVersion, '<');
ffStrbufAppendC(&result->deVersion, '.');
ffParsePropFile("/usr/share/mate-about/mate-version.xml", "<minor>", &result->deVersion);
ffStrbufSubstrBeforeFirstC(&result->deVersion, '<');
ffStrbufAppendC(&result->deVersion, '.');
ffParsePropFile("/usr/share/mate-about/mate-version.xml", "<micro>", &result->deVersion);
ffStrbufSubstrBeforeFirstC(&result->deVersion, '<');
if(result->deVersion.length == 0 && instance->config.allowSlowOperations)
{
+5 -5
View File
@@ -292,23 +292,24 @@ void ffCacheClose(FFcache* cache)
bool ffParsePropFile(const char* fileName, const char* start, FFstrbuf* buffer)
{
char* line = NULL;
size_t len = 0;
FILE* file = fopen(fileName, "r");
if(file == NULL)
return false; // handle errors in higher functions
char* line = NULL;
size_t len = 0;
while (getline(&line, &len, file) != -1)
{
if(ffGetPropValue(line, start, buffer))
break;
}
fclose(file);
if(line != NULL)
free(line);
fclose(file);
return true;
}
@@ -329,7 +330,6 @@ bool ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const c
bool ffParsePropFileConfig(FFinstance* instance, const char* relativeFile, const char* start, FFstrbuf* buffer)
{
uint32_t bufferLengthStart = buffer->length;
bool foundAFile = false;
+60 -23
View File
@@ -107,50 +107,87 @@ void ffGetFontPretty(FFstrbuf* buffer, const FFstrbuf* name, double size)
}
}
bool ffGetPropValue(const char* line, const char* start, FFstrbuf* buffer)
static bool getPropValueLine(const char** linePtr, const char* start, FFstrbuf* buffer)
{
uint32_t lineIndex = 0;
uint32_t startIndex = 0;
const char* line = *linePtr;
if(*line == '\0')
return false;
//Skip any amount of whitespace at the begin of line
while(line[lineIndex] == ' ' || line[lineIndex] == '\t')
++lineIndex;
while(*line == ' ' || *line == '\t')
++line;
while(start[startIndex] != '\0')
while(*start != '\0')
{
// Any amount of whitespace in the format string matches any amount of whitespace in the line, even none
if(start[startIndex] == ' ' || start[startIndex] == '\t')
if(*start == ' ' || *start == '\t')
{
while(start[startIndex] == ' ' || start[startIndex] == '\t')
++startIndex;
while(*start == ' ' || *start == '\t')
++start;
while(line[lineIndex] == ' ' || line[lineIndex] == '\t')
++lineIndex;
while(*line == ' ' || *line == '\t')
++line;
continue;
}
if(line[lineIndex] == '\0' || line[lineIndex] != start[startIndex])
//Line doesn't match start, skip it
if(*line != *start || *line == '\0')
return false;
++lineIndex;
++startIndex;
//Line and start match, continue testing
++line;
++start;
}
//Skip any amount of whitespace at the begin of the value
while(line[lineIndex] == ' ' || line[lineIndex] == '\t')
++lineIndex;
char valueEnd = '\n';
//Allow quotet values
const char* quotes = NULL;
if(line[lineIndex] == '"' || line[lineIndex] == '\'')
quotes = &line[lineIndex++];
//Allow faster parsing of XML
if(*(line - 1) == '>')
valueEnd = '<';
//Skip any amount of whitespace at the begin of the value
while(*line == ' ' || *line == '\t')
++line;
//Allow faster parsing of quotet values
if(*line == '"' || *line == '\'')
{
valueEnd = *line;
++line;
}
//Copy the value to the buffer
while(line[lineIndex] != '\n' && line[lineIndex] != '\0' && (quotes == NULL || *quotes != line[lineIndex]))
ffStrbufAppendC(buffer, line[lineIndex++]);
while(*line != valueEnd && *line != '\n' && *line != '\0')
{
ffStrbufAppendC(buffer, *line);
++line;
}
ffStrbufTrimRight(buffer, ' ');
return true;
}
bool ffGetPropValue(const char* line, const char* start, FFstrbuf* buffer)
{
return getPropValueLine(&line, start, buffer);
}
bool ffGetPropValueFromLines(const char* lines, const char* start, FFstrbuf* buffer)
{
while(!getPropValueLine(&lines, start, buffer))
{
while(*lines != '\0' && *lines != '\n')
++lines;
if(*lines == '\0')
return false;
//Skip '\n'
++lines;
}
return true;
}