From f61ffdb149885ad827613f02034797c876f45dd6 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Tue, 23 Mar 2021 19:48:52 +0100 Subject: [PATCH] removed ffStrbufIsEmpty --- completions/bash | 2 ++ src/common.c | 4 ++-- src/fastfetch.c | 6 +++--- src/modules/battery.c | 26 +++++++++++++------------- src/modules/cpu.c | 2 +- src/modules/de.c | 16 ++++++++-------- src/modules/disk.c | 2 +- src/modules/font.c | 2 +- src/modules/gpu.c | 4 ++-- src/modules/host.c | 31 +++++++++++++++++-------------- src/modules/icons.c | 2 +- src/modules/kernel.c | 2 +- src/modules/locale.c | 2 +- src/modules/memory.c | 2 +- src/modules/os.c | 22 +++++++++++----------- src/modules/packages.c | 2 +- src/modules/resolution.c | 31 +++++++++++++++---------------- src/modules/shell.c | 10 +++++----- src/modules/terminal.c | 2 +- src/modules/terminalfont.c | 2 +- src/modules/theme.c | 2 +- src/modules/uptime.c | 2 +- src/modules/wm.c | 2 +- src/util/FFstrbuf.c | 5 ----- src/util/FFstrbuf.h | 1 - 25 files changed, 91 insertions(+), 93 deletions(-) diff --git a/completions/bash b/completions/bash index edec3b599..63ea3ccd8 100644 --- a/completions/bash +++ b/completions/bash @@ -15,6 +15,7 @@ __fastfetch_complete_help() "wm-format" "theme-format" "icons-format" + "font-format" "terminal-format" "terminal-font-format" "cpu-format" @@ -134,6 +135,7 @@ __fastfetch_completion() "--wm-format" "--theme-format" "--icons-format" + "--font-format" "--terminal-format" "--terminal-font-format" "--cpu-format" diff --git a/src/common.c b/src/common.c index 8beb57417..5d4ff02d9 100644 --- a/src/common.c +++ b/src/common.c @@ -263,7 +263,7 @@ static const FFstrbuf* getCacheDir(FFinstance* instance) ffStrbufInitS(&cacheDir, getenv("XDG_CACHE_HOME")); - if(ffStrbufIsEmpty(&cacheDir)) + if(cacheDir.length == 0) { ffStrbufSetS(&cacheDir, instance->state.passwd->pw_dir); ffStrbufAppendS(&cacheDir, "/.cache/"); @@ -293,7 +293,7 @@ bool ffPrintCachedValue(FFinstance* instance, const char* key) ffStrbufDestroy(&cacheFile); - if(ffStrbufIsEmpty(&value)) + if(value.length == 0) { ffStrbufDestroy(&value); return false; diff --git a/src/fastfetch.c b/src/fastfetch.c index cd5241c56..8e90eaa0a 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -484,13 +484,13 @@ static void parseArguments(FFinstance* instance, FFdata* data, int argc, const c static void applyData(FFinstance* instance, FFdata* data) { //We must do this after parsing all options because of color options - if(ffStrbufIsEmpty(&data->logoName)) + if(data->logoName.length == 0) ffLoadLogo(&instance->config); else ffLoadLogoSet(&instance->config, data->logoName.chars); //This must be done after loading the logo - if(ffStrbufIsEmpty(&instance->config.color)) + if(instance->config.color.length == 0) ffStrbufSetS(&instance->config.color, instance->config.logo.color); } @@ -557,7 +557,7 @@ static void parseStructureCommand(FFinstance* instance, FFdata* data, const char static void run(FFinstance* instance, FFdata* data) { - if(ffStrbufIsEmpty(&data->structure)) + if(data->structure.length == 0) ffStrbufSetS(&data->structure, FASTFETCH_DEFAULT_STRUCTURE); char* remaining = data->structure.chars; diff --git a/src/modules/battery.c b/src/modules/battery.c index 2ad0f8dfd..1856769db 100644 --- a/src/modules/battery.c +++ b/src/modules/battery.c @@ -33,12 +33,12 @@ static void printBattery(FFinstance* instance, uint8_t index) sprintf(key, "Battery %i", index); if( - ffStrbufIsEmpty(&manufactor) && - ffStrbufIsEmpty(&model) && - ffStrbufIsEmpty(&technology) && - ffStrbufIsEmpty(&capacity) && - ffStrbufIsEmpty(&status) && - ffStrbufIsEmpty(&instance->config.batteryFormat) + manufactor.length == 0 && + model.length == 0 && + technology.length == 0 && + capacity.length == 0 && + status.length == 0 && + instance->config.batteryFormat.length == 0 ) { ffPrintError(instance, key, "No file in /sys/class/power_supply/BAT0/ could be read or all battery options are disabled"); return; @@ -46,29 +46,29 @@ static void printBattery(FFinstance* instance, uint8_t index) ffPrintLogoAndKey(instance, key); - if(ffStrbufIsEmpty(&instance->config.batteryFormat)) + if(instance->config.batteryFormat.length == 0) { - if(!ffStrbufIsEmpty(&manufactor)) + if(manufactor.length > 0) printf("%s ", manufactor.chars); - if(!ffStrbufIsEmpty(&model)) + if(model.length > 0) printf("%s ", manufactor.chars); - if(!ffStrbufIsEmpty(&technology)) + if(technology.length > 0) printf("(%s) ", technology.chars); - if(!ffStrbufIsEmpty(&capacity)) + if(capacity.length > 0) { printf("[%s%%", capacity.chars); - if(ffStrbufIsEmpty(&status)) + if(status.length == 0) puts("]"); else printf("; %s]\n", status.chars); } else { - if(!ffStrbufIsEmpty(&status)) + if(status.length > 0) printf("[%s]", status.chars); else putchar('\n'); diff --git a/src/modules/cpu.c b/src/modules/cpu.c index fcc50a333..b56a4a760 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -35,7 +35,7 @@ void ffPrintCPU(FFinstance* instance) FF_STRBUF_CREATE(cpu); - if(ffStrbufIsEmpty(&instance->config.cpuFormat)) + if(instance->config.cpuFormat.length == 0) { ffStrbufSetF(&cpu, "%s (%i) @ %.9gGHz", name, numProcs, ghz); } diff --git a/src/modules/de.c b/src/modules/de.c index a6e5053a0..b62189512 100644 --- a/src/modules/de.c +++ b/src/modules/de.c @@ -14,7 +14,7 @@ void ffPrintDesktopEnvironment(FFinstance* instance) { FFstrbuf sessionDesktop; ffStrbufInitS(&sessionDesktop, getenv("XDG_CURRENT_DESKTOP")); - if(ffStrbufIsEmpty(&sessionDesktop)) + if(sessionDesktop.length == 0) ffStrbufSetS(&sessionDesktop, getenv("XDG_SESSION_DESKTOP")); FF_STRBUF_CREATE(sessionVersion); @@ -23,7 +23,7 @@ void ffPrintDesktopEnvironment(FFinstance* instance) if(ffStrbufIgnCaseCompS(&sessionDesktop, "KDE") == 0) getKDE(&sessionDesktop, &sessionVersion, &sessionType); - if(ffStrbufIsEmpty(&sessionType)) + if(sessionType.length == 0) { const char* xdgSessionType = getenv("XDG_SESSION_TYPE"); if(strcasecmp(xdgSessionType, "wayland") == 0) @@ -38,9 +38,9 @@ void ffPrintDesktopEnvironment(FFinstance* instance) ffStrbufSetS(&sessionType, xdgSessionType); } - if(ffStrbufIsEmpty(&instance->config.deFormat)) + if(instance->config.deFormat.length == 0) { - if(ffStrbufIsEmpty(&sessionDesktop) && ffStrbufIsEmpty(&sessionType)) + if(sessionDesktop.length == 0 && sessionType.length == 0) { ffPrintError(instance, "DE", "Neither DE nor Display Server could be determined"); return; @@ -48,21 +48,21 @@ void ffPrintDesktopEnvironment(FFinstance* instance) ffPrintLogoAndKey(instance, "DE"); - if(!ffStrbufIsEmpty(&sessionDesktop)) + if(sessionDesktop.length > 0) { ffStrbufWriteTo(&sessionDesktop, stdout); - if(!ffStrbufIsEmpty(&sessionVersion)) + if(sessionVersion.length > 0) { putchar(' '); ffStrbufWriteTo(&sessionVersion, stdout); } - if(!ffStrbufIsEmpty(&sessionType)) + if(sessionType.length > 0) putchar(' '); } - if(!ffStrbufIsEmpty(&sessionType)) + if(sessionType.length > 0) printf("(%s)", sessionType.chars); putchar('\n'); diff --git a/src/modules/disk.c b/src/modules/disk.c index e7ddd6cc6..03730d55b 100644 --- a/src/modules/disk.c +++ b/src/modules/disk.c @@ -21,7 +21,7 @@ void ffPrintDisk(FFinstance* instance) ffPrintLogoAndKey(instance, "Disk (/)"); - if(ffStrbufIsEmpty(&instance->config.diskFormat)) + if(instance->config.diskFormat.length == 0) { printf("%uGB / %uGB (%u%%)\n", used, total, percentage); } diff --git a/src/modules/font.c b/src/modules/font.c index de9c05613..fc603461e 100644 --- a/src/modules/font.c +++ b/src/modules/font.c @@ -43,7 +43,7 @@ void ffPrintFont(FFinstance* instance) ffPrintLogoAndKey(instance, "Font"); - if(ffStrbufIsEmpty(&instance->config.fontFormat)) + if(instance->config.fontFormat.length == 0) { printf("%s [Plasma], ", plasmaPretty); ffStrbufPutTo(>kPretty, stdout); diff --git a/src/modules/gpu.c b/src/modules/gpu.c index 56ed9b8e0..ff2d4dec3 100644 --- a/src/modules/gpu.c +++ b/src/modules/gpu.c @@ -25,7 +25,7 @@ static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_ FF_STRBUF_CREATE(gpu); - if(ffStrbufIsEmpty(&instance->config.gpuFormat)) + if(instance->config.gpuFormat.length == 0) { ffStrbufSetF(&gpu, "%s %s", vendorPretty, name); } @@ -44,7 +44,7 @@ static void handleGPU(FFinstance* instance, struct pci_access* pacc, struct pci_ void ffPrintGPU(FFinstance* instance) { void* pci; - if(ffStrbufIsEmpty(&instance->config.libPCI)) + if(instance->config.libPCI.length == 0) pci = dlopen("libpci.so", RTLD_LAZY); else pci = dlopen(instance->config.libPCI.chars, RTLD_LAZY); diff --git a/src/modules/host.c b/src/modules/host.c index 1910ae84c..a08872419 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -16,26 +16,18 @@ void ffPrintHost(FFinstance* instance) FF_STRBUF_CREATE(host); - if(ffStrbufIsEmpty(&instance->config.hostFormat)) + if(instance->config.hostFormat.length == 0) { - ffParseFormatString(&host, &instance->config.hostFormat, 3, - (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &family}, - (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &name}, - (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &version} - ); - } - else - { - if(ffStrbufIsEmpty(&family) && ffStrbufIsEmpty(&name)) + if(family.length == 0 && name.length == 0) { ffPrintError(instance, "Host", "neither family nor name could be determined"); return; } - else if(ffStrbufIsEmpty(&name)) + else if(name.length == 0) { ffStrbufAppend(&host, &family); } - else if(ffStrbufIsEmpty(&family)) + else if(family.length == 0) { ffStrbufAppend(&host, &name); } @@ -46,12 +38,23 @@ void ffPrintHost(FFinstance* instance) ffStrbufAppend(&host, &name); } - if(!ffStrbufIsEmpty(&version) && ffStrbufIgnCaseCompS(&version, "None") != 0) - { + if( + version.length > 0 && + ffStrbufIgnCaseCompS(&version, "None") != 0 && + ffStrbufIgnCaseCompS(&version, "To be filled by O.E.M.") != 0 + ) { ffStrbufAppendC(&host, ' '); ffStrbufAppend(&host, &version); } } + else + { + ffParseFormatString(&host, &instance->config.hostFormat, 3, + (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &family}, + (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &name}, + (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &version} + ); + } ffPrintAndSaveCachedValue(instance, "Host", &host); ffStrbufDestroy(&host); diff --git a/src/modules/icons.c b/src/modules/icons.c index 21b5b79eb..fb2832412 100644 --- a/src/modules/icons.c +++ b/src/modules/icons.c @@ -25,7 +25,7 @@ void ffPrintIcons(FFinstance* instance) ffPrintLogoAndKey(instance, "Icons"); - if(ffStrbufIsEmpty(&instance->config.iconsFormat)) + if(instance->config.iconsFormat.length == 0) { if(plasma[0] == '\0') printf("Breeze [Plasma], "); diff --git a/src/modules/kernel.c b/src/modules/kernel.c index 90cdb68d0..6370457d1 100644 --- a/src/modules/kernel.c +++ b/src/modules/kernel.c @@ -2,7 +2,7 @@ void ffPrintKernel(FFinstance* instance) { - if(ffStrbufIsEmpty(&instance->config.kernelFormat)) + if(instance->config.kernelFormat.length == 0) { ffPrintLogoAndKey(instance, "Kernel"); puts(instance->state.utsname.release); diff --git a/src/modules/locale.c b/src/modules/locale.c index 64e576bd8..dac90646a 100644 --- a/src/modules/locale.c +++ b/src/modules/locale.c @@ -41,7 +41,7 @@ void ffPrintLocale(FFinstance* instance) FF_STRBUF_CREATE(locale); - if(ffStrbufIsEmpty(&instance->config.localeFormat)) + if(instance->config.localeFormat.length == 0) { ffStrbufSetS(&locale, localeCode); } diff --git a/src/modules/memory.c b/src/modules/memory.c index 098350a1d..b623177ad 100644 --- a/src/modules/memory.c +++ b/src/modules/memory.c @@ -32,7 +32,7 @@ void ffPrintMemory(FFinstance* instance) ffPrintLogoAndKey(instance, "Memory"); - if(ffStrbufIsEmpty(&instance->config.memoryFormat)) + if(instance->config.memoryFormat.length == 0) { printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage); } diff --git a/src/modules/os.c b/src/modules/os.c index 40d1c36f0..f16f97493 100644 --- a/src/modules/os.c +++ b/src/modules/os.c @@ -7,25 +7,25 @@ void ffPrintOS(FFinstance* instance) char name[256]; ffParsePropFile("/etc/os-release", "NAME=\"%[^\"]+", name); - if(name[0] == '\0' && ffStrbufIsEmpty(&instance->config.osFormat)) //With custom format string we pass an empty string as name - { - ffPrintError(instance, "OS", "\"NAME=\\\"%[^\\\"]+\" not found in \"/etc/os-release\""); - return; - } - FF_STRBUF_CREATE(os); - if(!ffStrbufIsEmpty(&instance->config.osFormat)) + if(instance->config.osFormat.length == 0) + { + if(name[0] == '\0') + { + ffPrintError(instance, "OS", "\"NAME=\\\"%[^\\\"]+\" not found in \"/etc/os-release\""); + return; + } + + ffStrbufSetF(&os, "%s %s", name, instance->state.utsname.machine); + } + else { ffParseFormatString(&os, &instance->config.osFormat, 2, (FFformatarg){FF_FORMAT_ARG_TYPE_STRING, name}, (FFformatarg){FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.machine} ); } - else - { - ffStrbufSetF(&os, "%s %s", name, instance->state.utsname.machine); - } ffPrintAndSaveCachedValue(instance, "OS", &os); ffStrbufDestroy(&os); diff --git a/src/modules/packages.c b/src/modules/packages.c index e512229ff..74cc69af2 100644 --- a/src/modules/packages.c +++ b/src/modules/packages.c @@ -36,7 +36,7 @@ void ffPrintPackages(FFinstance* instance) return; } - if(ffStrbufIsEmpty(&instance->config.packagesFormat)) + if(instance->config.packagesFormat.length == 0) { ffPrintLogoAndKey(instance, "Packages"); diff --git a/src/modules/resolution.c b/src/modules/resolution.c index 05cd0621e..aa42afbee 100644 --- a/src/modules/resolution.c +++ b/src/modules/resolution.c @@ -6,10 +6,10 @@ static int getCurrentRate(FFinstance* instance, Display* display) { void* xrandr; - if(!ffStrbufIsEmpty(&instance->config.libXrandr)) - xrandr = dlopen(instance->config.libXrandr.chars, RTLD_LAZY); - else + if(instance->config.libXrandr.length == 0) xrandr = dlopen("libXrandr.so", RTLD_LAZY); + else + xrandr = dlopen(instance->config.libXrandr.chars, RTLD_LAZY); if(xrandr == NULL) return 0; @@ -44,10 +44,10 @@ void ffPrintResolution(FFinstance* instance) return; void* x11; - if(!ffStrbufIsEmpty(&instance->config.libX11)) - x11 = dlopen(instance->config.libX11.chars, RTLD_LAZY); - else + if(instance->config.libX11.length == 0) x11 = dlopen("libX11.so", RTLD_LAZY); + else + x11 = dlopen(instance->config.libX11.chars, RTLD_LAZY); if(x11 == NULL) { ffPrintError(instance, "Resolution", "dlopen(\"libX11.so\", RTLD_LAZY) == NULL"); @@ -76,22 +76,21 @@ void ffPrintResolution(FFinstance* instance) FF_STRBUF_CREATE(resolution); - if(!ffStrbufIsEmpty(&instance->config.resolutionFormat)) - { - - ffParseFormatString(&resolution, &instance->config.resolutionFormat, 3, - (FFformatarg){FF_FORMAT_ARG_TYPE_INT, &screen->width}, - (FFformatarg){FF_FORMAT_ARG_TYPE_INT, &screen->height}, - (FFformatarg){FF_FORMAT_ARG_TYPE_INT, ¤tRate} - ); - } - else + if(instance->config.resolutionFormat.length == 0) { ffStrbufAppendF(&resolution, "%ix%i", screen->width, screen->height); if(currentRate > 0) ffStrbufAppendF(&resolution, " @ %iHz", currentRate); } + else + { + ffParseFormatString(&resolution, &instance->config.resolutionFormat, 3, + (FFformatarg){FF_FORMAT_ARG_TYPE_INT, &screen->width}, + (FFformatarg){FF_FORMAT_ARG_TYPE_INT, &screen->height}, + (FFformatarg){FF_FORMAT_ARG_TYPE_INT, ¤tRate} + ); + } ffPrintAndSaveCachedValue(instance, "Resolution", &resolution); ffStrbufDestroy(&resolution); diff --git a/src/modules/shell.c b/src/modules/shell.c index fc91df7e8..06c33d5eb 100644 --- a/src/modules/shell.c +++ b/src/modules/shell.c @@ -29,17 +29,17 @@ void ffPrintShell(FFinstance* instance) FF_STRBUF_CREATE(shell); - if(!ffStrbufIsEmpty(&instance->config.shellFormat)) + if(instance->config.shellFormat.length == 0) + { + ffStrbufSetS(&shell, shellName); + } + else { ffParseFormatString(&shell, &instance->config.shellFormat, 2, (FFformatarg){FF_FORMAT_ARG_TYPE_STRING, shellPath}, (FFformatarg){FF_FORMAT_ARG_TYPE_STRING, shellName} ); } - else - { - ffStrbufSetS(&shell, shellName); - } ffPrintAndSaveCachedValue(instance, "Shell", &shell); ffStrbufDestroy(&shell); diff --git a/src/modules/terminal.c b/src/modules/terminal.c index c66b8ff08..78b3de4a0 100644 --- a/src/modules/terminal.c +++ b/src/modules/terminal.c @@ -88,7 +88,7 @@ void ffPrintTerminal(FFinstance* instance) ffPrintLogoAndKey(instance, "Terminal"); - if(ffStrbufIsEmpty(&instance->config.terminalFormat)) + if(instance->config.terminalFormat.length == 0) { ffStrbufPutTo(&instance->state.terminal.value, stdout); } diff --git a/src/modules/terminalfont.c b/src/modules/terminalfont.c index d1d75a545..a453a29cf 100644 --- a/src/modules/terminalfont.c +++ b/src/modules/terminalfont.c @@ -4,7 +4,7 @@ static void printTerminalFont(FFinstance* instance, char* font) { ffPrintLogoAndKey(instance, "Terminal font"); - if(ffStrbufIsEmpty(&instance->config.termFontFormat)) + if(instance->config.termFontFormat.length == 0) { puts(font); } diff --git a/src/modules/theme.c b/src/modules/theme.c index c5e38e9d8..ce26cde5d 100644 --- a/src/modules/theme.c +++ b/src/modules/theme.c @@ -25,7 +25,7 @@ void ffPrintTheme(FFinstance* instance) ffPrintLogoAndKey(instance, "Theme"); - if(ffStrbufIsEmpty(&instance->config.themeFormat)) + if(instance->config.themeFormat.length == 0) { if(plasma[0] != '\0') printf("%s [Plasma], ", plasma); diff --git a/src/modules/uptime.c b/src/modules/uptime.c index be854fba2..d3c817dbf 100644 --- a/src/modules/uptime.c +++ b/src/modules/uptime.c @@ -8,7 +8,7 @@ void ffPrintUptime(FFinstance* instance) uint32_t minutes = (instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600)) / 60; uint32_t seconds = instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600) - (minutes * 60); - if(ffStrbufIsEmpty(&instance->config.uptimeFormat)) + if(instance->config.uptimeFormat.length == 0) { ffPrintLogoAndKey(instance, "Uptime"); diff --git a/src/modules/wm.c b/src/modules/wm.c index 45e78338a..fb76c74af 100644 --- a/src/modules/wm.c +++ b/src/modules/wm.c @@ -49,7 +49,7 @@ void ffPrintWM(FFinstance* instance) return; } - if(ffStrbufIsEmpty(&instance->config.wmFormat)) + if(instance->config.wmFormat.length == 0) { ffPrintLogoAndKey(instance, "WM"); ffStrbufPutTo(&name, stdout); diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index 96a077518..460befe93 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -99,11 +99,6 @@ void ffStrbufClear(FFstrbuf* strbuf) strbuf->length = 0; } -bool ffStrbufIsEmpty(FFstrbuf* strbuf) -{ - return strbuf->length == 0; -} - void ffStrbufSet(FFstrbuf* strbuf, const FFstrbuf* value) { ffStrbufClear(strbuf); diff --git a/src/util/FFstrbuf.h b/src/util/FFstrbuf.h index dc5d3b0c3..4ef4f5679 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -35,7 +35,6 @@ void ffStrbufEnsureCapacity(FFstrbuf* strbuf, uint32_t allocate); void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free); void ffStrbufClear(FFstrbuf* strbuf); -bool ffStrbufIsEmpty(FFstrbuf* strbuf); void ffStrbufSet(FFstrbuf* strbuf, const FFstrbuf* value); void ffStrbufSetS(FFstrbuf* strbuf, const char* value);