mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:24:58 +02:00
better ffGetPropValue
This commit is contained in:
@@ -83,11 +83,11 @@ static void detectGTKFromConfigFile(const char* filename, FFGTKResult* result)
|
||||
while(getline(&line, &len, file) != -1)
|
||||
{
|
||||
if(result->theme.length == 0)
|
||||
ffGetPropValue(line, "gtk-theme-name=", &result->theme);
|
||||
ffGetPropValue(line, "gtk-theme-name =", &result->theme);
|
||||
if(result->icons.length == 0)
|
||||
ffGetPropValue(line, "gtk-icon-theme-name=", &result->icons);
|
||||
ffGetPropValue(line, "gtk-icon-theme-name =", &result->icons);
|
||||
if(result->font.length == 0)
|
||||
ffGetPropValue(line, "gtk-font-name=", &result->font);
|
||||
ffGetPropValue(line, "gtk-font-name =", &result->font);
|
||||
}
|
||||
|
||||
if(line != NULL)
|
||||
|
||||
@@ -42,13 +42,13 @@ static bool detectFromConfigFile(const FFstrbuf* filename, FFPlasmaResult* resul
|
||||
}
|
||||
|
||||
if(category == PLASMA_CATEGORY_KDE)
|
||||
ffGetPropValue(line, "widgetStyle=", &result->widgetStyle);
|
||||
ffGetPropValue(line, "widgetStyle =", &result->widgetStyle);
|
||||
else if(category == PLASMA_CATEGORY_ICONS)
|
||||
ffGetPropValue(line, "Theme=", &result->icons);
|
||||
ffGetPropValue(line, "Theme =", &result->icons);
|
||||
else if(category == PLASMA_CATEGORY_GENERAL)
|
||||
{
|
||||
ffGetPropValue(line, "ColorScheme=", &result->colorScheme);
|
||||
ffGetPropValue(line, "font=", &result->font);
|
||||
ffGetPropValue(line, "ColorScheme =", &result->colorScheme);
|
||||
ffGetPropValue(line, "font =", &result->font);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -212,21 +212,21 @@ static void getKDE(FFWMDEResult* result)
|
||||
{
|
||||
ffStrbufSetS(&result->deProcessName, "plasmashell");
|
||||
ffStrbufSetS(&result->dePrettyName, "KDE Plasma");
|
||||
ffParsePropFile("/usr/share/xsessions/plasma.desktop", "X-KDE-PluginInfo-Version=", &result->deVersion);
|
||||
ffParsePropFile("/usr/share/xsessions/plasma.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
|
||||
}
|
||||
|
||||
static void getGnome(FFWMDEResult* result)
|
||||
{
|
||||
ffStrbufSetS(&result->deProcessName, "gnome-shell");
|
||||
ffStrbufSetS(&result->dePrettyName, "GNOME");
|
||||
ffParsePropFile("/usr/share/gnome-shell/org.gnome.Extensions", "version: ", &result->deVersion);
|
||||
ffParsePropFile("/usr/share/gnome-shell/org.gnome.Extensions", "version :", &result->deVersion);
|
||||
}
|
||||
|
||||
static void getCinnamon(FFWMDEResult* result)
|
||||
{
|
||||
ffStrbufSetS(&result->deProcessName, "cinnamon");
|
||||
ffStrbufSetS(&result->dePrettyName, "Cinnamon");
|
||||
ffParsePropFile("/usr/share/applications/cinnamon.desktop", "X-GNOME-Bugzilla-Version=", &result->deVersion);
|
||||
ffParsePropFile("/usr/share/applications/cinnamon.desktop", "X-GNOME-Bugzilla-Version =", &result->deVersion);
|
||||
}
|
||||
|
||||
static void getMate(FFinstance* instance, FFWMDEResult* result)
|
||||
@@ -261,7 +261,7 @@ static void getXFCE4(FFinstance* instance, FFWMDEResult* result)
|
||||
{
|
||||
ffStrbufSetS(&result->deProcessName, "xfce4-session");
|
||||
ffStrbufSetS(&result->dePrettyName, "Xfce4");
|
||||
ffParsePropFile("/usr/share/gtk-doc/html/libxfce4ui/index.html", "<div><p class=\"releaseinfo\">Version ", &result->deVersion);
|
||||
ffParsePropFile("/usr/share/gtk-doc/html/libxfce4ui/index.html", "<div><p class=\"releaseinfo\">Version", &result->deVersion);
|
||||
|
||||
if(result->deVersion.length == 0 && instance->config.allowSlowOperations)
|
||||
{
|
||||
|
||||
@@ -118,7 +118,7 @@ bool ffGetPropValue(const char* line, const char* start, FFstrbuf* buffer)
|
||||
|
||||
while(start[startIndex] != '\0')
|
||||
{
|
||||
// Any amount of whitespace in the format string matches any amount of whitespace in the line
|
||||
// Any amount of whitespace in the format string matches any amount of whitespace in the line, even none
|
||||
if(start[startIndex] == ' ' || start[startIndex] == '\t')
|
||||
{
|
||||
while(start[startIndex] == ' ' || start[startIndex] == '\t')
|
||||
@@ -137,6 +137,10 @@ bool ffGetPropValue(const char* line, const char* start, FFstrbuf* buffer)
|
||||
++startIndex;
|
||||
}
|
||||
|
||||
//Skip any amount of whitespace at the begin of the value
|
||||
while(line[lineIndex] == ' ' || line[lineIndex] == '\t')
|
||||
++lineIndex;
|
||||
|
||||
//Allow quotet values
|
||||
const char* quotes = NULL;
|
||||
if(line[lineIndex] == '"' || line[lineIndex] == '\'')
|
||||
@@ -146,7 +150,7 @@ bool ffGetPropValue(const char* line, const char* start, FFstrbuf* buffer)
|
||||
while(line[lineIndex] != '\n' && line[lineIndex] != '\0' && (quotes == NULL || *quotes != line[lineIndex]))
|
||||
ffStrbufAppendC(buffer, line[lineIndex++]);
|
||||
|
||||
ffStrbufTrim(buffer, ' ');
|
||||
ffStrbufTrimRight(buffer, ' ');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ void ffPrintLocale(FFinstance* instance)
|
||||
FFstrbuf locale;
|
||||
ffStrbufInit(&locale);
|
||||
|
||||
ffParsePropFile("/etc/locale.conf", "LANG=", &locale);
|
||||
ffParsePropFile("/etc/locale.conf", "LANG =", &locale);
|
||||
|
||||
if (locale.length == 0)
|
||||
getLocaleFromEnv(&locale);
|
||||
|
||||
+10
-10
@@ -54,16 +54,16 @@ const FFOSResult* ffDetectOS(FFinstance* instance)
|
||||
// https://www.freedesktop.org/software/systemd/man/os-release.html
|
||||
while (getline(&line, &len, osRelease) != -1)
|
||||
{
|
||||
ffGetPropValue(line, "NAME=", &result.name);
|
||||
ffGetPropValue(line, "PRETTY_NAME=", &result.prettyName);
|
||||
ffGetPropValue(line, "ID=", &result.id);
|
||||
ffGetPropValue(line, "ID_LIKE=", &result.idLike);
|
||||
ffGetPropValue(line, "VARIANT=", &result.variant);
|
||||
ffGetPropValue(line, "VARIANT_ID=", &result.variantID);
|
||||
ffGetPropValue(line, "VERSION=", &result.version);
|
||||
ffGetPropValue(line, "VERSION_ID=", &result.versionID);
|
||||
ffGetPropValue(line, "VERSION_CODENAME=", &result.codename);
|
||||
ffGetPropValue(line, "BUILD_ID=", &result.buildID);
|
||||
ffGetPropValue(line, "NAME =", &result.name);
|
||||
ffGetPropValue(line, "PRETTY_NAME =", &result.prettyName);
|
||||
ffGetPropValue(line, "ID =", &result.id);
|
||||
ffGetPropValue(line, "ID_LIKE =", &result.idLike);
|
||||
ffGetPropValue(line, "VARIANT =", &result.variant);
|
||||
ffGetPropValue(line, "VARIANT_ID =", &result.variantID);
|
||||
ffGetPropValue(line, "VERSION =", &result.version);
|
||||
ffGetPropValue(line, "VERSION_ID =", &result.versionID);
|
||||
ffGetPropValue(line, "VERSION_CODENAME =", &result.codename);
|
||||
ffGetPropValue(line, "BUILD_ID =", &result.buildID);
|
||||
}
|
||||
|
||||
if(line != NULL)
|
||||
|
||||
@@ -48,7 +48,7 @@ static void printKonsole(FFinstance* instance)
|
||||
{
|
||||
FFstrbuf profile;
|
||||
ffStrbufInit(&profile);
|
||||
ffParsePropFileConfig(instance, "konsolerc", "DefaultProfile=", &profile);
|
||||
ffParsePropFileConfig(instance, "konsolerc", "DefaultProfile =", &profile);
|
||||
|
||||
if(profile.length == 0)
|
||||
{
|
||||
@@ -64,7 +64,7 @@ static void printKonsole(FFinstance* instance)
|
||||
|
||||
FFstrbuf font;
|
||||
ffStrbufInit(&font);
|
||||
ffParsePropFileHome(instance, profilePath.chars, "Font=", &font);
|
||||
ffParsePropFileHome(instance, profilePath.chars, "Font =", &font);
|
||||
|
||||
if(font.length == 0)
|
||||
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath.chars);
|
||||
@@ -118,7 +118,7 @@ static void printXCFETerminal(FFinstance* instance)
|
||||
FFstrbuf useSysFont;
|
||||
ffStrbufInit(&useSysFont);
|
||||
|
||||
if(!ffParsePropFileConfig(instance, "xfce4/terminal/terminalrc", "FontUseSystem=", &useSysFont))
|
||||
if(!ffParsePropFileConfig(instance, "xfce4/terminal/terminalrc", "FontUseSystem =", &useSysFont))
|
||||
{
|
||||
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't open \"$XDG_CONFIG_HOME/xfce4/terminal/terminalrc\"");
|
||||
ffStrbufDestroy(&useSysFont);
|
||||
@@ -127,7 +127,7 @@ static void printXCFETerminal(FFinstance* instance)
|
||||
|
||||
if(useSysFont.length == 0 || ffStrbufIgnCaseCompS(&useSysFont, "FALSE") == 0)
|
||||
{
|
||||
printTerminalFontFromConfigFile(instance, "xfce4/terminal/terminalrc", "FontName=");
|
||||
printTerminalFontFromConfigFile(instance, "xfce4/terminal/terminalrc", "FontName =");
|
||||
ffStrbufDestroy(&useSysFont);
|
||||
return;
|
||||
}
|
||||
@@ -147,7 +147,7 @@ static void printTTY(FFinstance* instance)
|
||||
FFstrbuf font;
|
||||
ffStrbufInit(&font);
|
||||
|
||||
ffParsePropFile("/etc/vconsole.conf", "Font=", &font);
|
||||
ffParsePropFile("/etc/vconsole.conf", "Font =", &font);
|
||||
|
||||
if(font.length == 0)
|
||||
{
|
||||
@@ -178,7 +178,7 @@ void ffPrintTerminalFont(FFinstance* instance)
|
||||
else if(ffStrbufIgnCaseCompS(&result->exeName, "xfce4-terminal") == 0)
|
||||
printXCFETerminal(instance);
|
||||
else if(ffStrbufIgnCaseCompS(&result->exeName, "lxterminal") == 0)
|
||||
printTerminalFontFromConfigFile(instance, "lxterminal/lxterminal.conf", "fontname=");
|
||||
printTerminalFontFromConfigFile(instance, "lxterminal/lxterminal.conf", "fontname =");
|
||||
else if(ffStrbufIgnCaseCompS(&result->exeName, "tilix") == 0)
|
||||
printTilixTerminal(instance);
|
||||
else if(ffStrbufStartsWithIgnCaseS(&result->exeName, "/dev/tty"))
|
||||
|
||||
@@ -196,7 +196,7 @@ void ffPrintWMTheme(FFinstance* instance)
|
||||
}
|
||||
|
||||
if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "KWin") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "KDE") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "Plasma") == 0)
|
||||
printWMThemeFromConfigFile(instance, "kwinrc", "theme=", "Breeze");
|
||||
printWMThemeFromConfigFile(instance, "kwinrc", "theme =", "Breeze");
|
||||
else if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "Xfwm4") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "Xfwm") == 0)
|
||||
printXFWM4(instance);
|
||||
else if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "Mutter") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "Gnome") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "Ubuntu") == 0)
|
||||
|
||||
Reference in New Issue
Block a user