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;
}
+1 -1
View File
@@ -64,7 +64,7 @@ static inline void printHelp()
" -l <name>, --logo <name>: sets the shown logo. Also changes the main color accordingly\n"
" --color-logo <?value>: if set to false, the logo will be black / white\n"
"\n"
"Format options: Provide the format string for custom output (+)\n"
"Format options: Provide the format string for custom output. Use fastfetch --help *-format for specific help.\n"
" --os-format <format>\n"
" --host-format <format>\n"
" --kernel-format <format>\n"
+1
View File
@@ -272,6 +272,7 @@ void ffGetGtkPretty(FFstrbuf* buffer, const FFstrbuf* gtk2, const FFstrbuf* gtk3
void ffGetFont(const char* font, FFstrbuf* name, double* size);
void ffGetFontPretty(FFstrbuf* buffer, const FFstrbuf* name, double size);
bool ffGetPropValue(const char* line, const char* start, FFstrbuf* buffer);
bool ffGetPropValueFromLines(const char* lines, const char* start, FFstrbuf* buffer);
//common/settings.c
FFvariant ffSettingsGetDConf(FFinstance* instance, const char* key, FFvarianttype type);
+3 -2
View File
@@ -54,10 +54,11 @@ void ffPrintGPU(FFinstance* instance)
if(ffPrintFromCache(instance, FF_GPU_MODULE_NAME, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS))
return;
void* pci = dlopen(instance->config.libPCI.length == 0 ? "libpci.so" : instance->config.libPCI.chars, RTLD_LAZY);
const char* pciLibName = instance->config.libPCI.length == 0 ? "libpci.so" : instance->config.libPCI.chars;
void* pci = dlopen(pciLibName, RTLD_LAZY);
if(pci == NULL)
{
ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS, "dlopen(\"libpci.so\", RTLD_LAZY) == NULL");
ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS, "dlopen(\"%s\", RTLD_LAZY) == NULL", pciLibName);
return;
}
+6 -6
View File
@@ -6,15 +6,15 @@
#define FF_PACKAGES_MODULE_NAME "Packages"
#define FF_PACKAGES_NUM_FORMAT_ARGS 7
static uint32_t getNumElements(const char* dirname, unsigned char type) {
uint32_t num_elements = 0;
DIR * dirp;
struct dirent *entry;
dirp = opendir(dirname);
static uint32_t getNumElements(const char* dirname, unsigned char type)
{
DIR* dirp = opendir(dirname);
if(dirp == NULL)
return 0;
uint32_t num_elements = 0;
struct dirent *entry;
while((entry = readdir(dirp)) != NULL) {
if(entry->d_type == type)
++num_elements;
+3 -2
View File
@@ -35,10 +35,11 @@ static void xCloseDisplay(void* library, Display* display)
void ffPrintResolutionX11Backend(FFinstance* instance)
{
void* x11 = dlopen(instance->config.libX11.length == 0 ? "libX11.so" : instance->config.libX11.chars, RTLD_LAZY);
const char* libX11Name = instance->config.libX11.length == 0 ? "libX11.so" : instance->config.libX11.chars;
void* x11 = dlopen(libX11Name, RTLD_LAZY);
if(x11 == NULL)
{
ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.resolutionKey, &instance->config.resolutionFormat, FF_RESOLUTION_NUM_FORMAT_ARGS, "dlopen(\"libX11.so\", RTLD_LAZY) == NULL");
ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.resolutionKey, &instance->config.resolutionFormat, FF_RESOLUTION_NUM_FORMAT_ARGS, "dlopen(\"%s\", RTLD_LAZY) == NULL", libX11Name);
return;
}