removed ffStrbufIsEmpty

This commit is contained in:
Linus Dierheimer
2021-03-23 19:48:52 +01:00
parent a0af3b0eb6
commit f61ffdb149
25 changed files with 91 additions and 93 deletions
+2
View File
@@ -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"
+2 -2
View File
@@ -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;
+3 -3
View File
@@ -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;
+13 -13
View File
@@ -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');
+1 -1
View File
@@ -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);
}
+8 -8
View File
@@ -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');
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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(&gtkPretty, stdout);
+2 -2
View File
@@ -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);
+17 -14
View File
@@ -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);
+1 -1
View File
@@ -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], ");
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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);
}
+11 -11
View File
@@ -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);
+1 -1
View File
@@ -36,7 +36,7 @@ void ffPrintPackages(FFinstance* instance)
return;
}
if(ffStrbufIsEmpty(&instance->config.packagesFormat))
if(instance->config.packagesFormat.length == 0)
{
ffPrintLogoAndKey(instance, "Packages");
+15 -16
View File
@@ -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, &currentRate}
);
}
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, &currentRate}
);
}
ffPrintAndSaveCachedValue(instance, "Resolution", &resolution);
ffStrbufDestroy(&resolution);
+5 -5
View File
@@ -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);
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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");
+1 -1
View File
@@ -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);
-5
View File
@@ -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);
-1
View File
@@ -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);