mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-01 10:32:35 +01:00
Global: major FFstrbuf related code refactor
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ static void fontInit(FFfont* font)
|
||||
{
|
||||
ffStrbufInit(&font->pretty);
|
||||
ffStrbufInit(&font->name);
|
||||
ffStrbufInitA(&font->size, 4);
|
||||
ffStrbufInitA(&font->size, 8);
|
||||
ffListInitA(&font->styles, sizeof(FFstrbuf), 4);
|
||||
}
|
||||
|
||||
|
||||
+1
-18
@@ -134,18 +134,14 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n
|
||||
continue;
|
||||
}
|
||||
|
||||
FFstrbuf placeholderValue;
|
||||
ffStrbufInit(&placeholderValue);
|
||||
FF_STRBUF_AUTO_DESTROY placeholderValue = ffStrbufCreate();
|
||||
|
||||
while(i < formatstr->length && formatstr->chars[i] != '}')
|
||||
ffStrbufAppendC(&placeholderValue, formatstr->chars[i++]);
|
||||
|
||||
// test if for stop, if so break the loop
|
||||
if(placeholderValue.length == 1 && placeholderValue.chars[0] == '-')
|
||||
{
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
break;
|
||||
}
|
||||
|
||||
// test for end of an if, if so do nothing
|
||||
if(placeholderValue.length == 1 && placeholderValue.chars[0] == '?')
|
||||
@@ -155,7 +151,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n
|
||||
else
|
||||
--numOpenIfs;
|
||||
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -167,7 +162,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n
|
||||
else
|
||||
--numOpenNotIfs;
|
||||
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -182,7 +176,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n
|
||||
--numOpenColors;
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -197,7 +190,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n
|
||||
if(index > numArgs)
|
||||
{
|
||||
appendInvalidPlaceholder(buffer, "{?", &placeholderValue, i, formatstr->length);
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -205,13 +197,11 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n
|
||||
if(formatArgSet(&arguments[index - 1]))
|
||||
{
|
||||
++numOpenIfs;
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
// fastforward to the end of the if without printing the in between
|
||||
i = ffStrbufNextIndexS(formatstr, i, "{?}") + 2; // 2 is the length of "{?}" - 1 because the loop will increament it again directly after continue
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -226,7 +216,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n
|
||||
if(index > numArgs)
|
||||
{
|
||||
appendInvalidPlaceholder(buffer, "{/", &placeholderValue, i, formatstr->length);
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -234,13 +223,11 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n
|
||||
if(!formatArgSet(&arguments[index - 1]))
|
||||
{
|
||||
++numOpenNotIfs;
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
// fastforward to the end of the if without printing the in between
|
||||
i = ffStrbufNextIndexS(formatstr, i, "{/}") + 2; // 2 is the length of "{/}" - 1 because the loop will increament it again directly after continue
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -252,7 +239,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n
|
||||
ffStrbufAppendS(buffer, "\033[");
|
||||
ffStrbufAppend(buffer, &placeholderValue);
|
||||
ffStrbufAppendC(buffer, 'm');
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -262,13 +248,10 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t n
|
||||
if(index > numArgs)
|
||||
{
|
||||
appendInvalidPlaceholder(buffer, "{", &placeholderValue, i, formatstr->length);
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
ffFormatAppendFormatArg(buffer, &arguments[index - 1]);
|
||||
|
||||
ffStrbufDestroy(&placeholderValue);
|
||||
}
|
||||
|
||||
ffStrbufTrimRight(buffer, ' ');
|
||||
|
||||
+23
-23
@@ -107,28 +107,28 @@ static void defaultConfig(FFinstance* instance)
|
||||
ffInitSeparatorOptions(&instance->config.separator);
|
||||
ffInitGamepadOptions(&instance->config.gamepad);
|
||||
|
||||
ffStrbufInitA(&instance->config.libPCI, 0);
|
||||
ffStrbufInitA(&instance->config.libVulkan, 0);
|
||||
ffStrbufInitA(&instance->config.libWayland, 0);
|
||||
ffStrbufInitA(&instance->config.libXcbRandr, 0);
|
||||
ffStrbufInitA(&instance->config.libXcb, 0);
|
||||
ffStrbufInitA(&instance->config.libXrandr, 0);
|
||||
ffStrbufInitA(&instance->config.libX11, 0);
|
||||
ffStrbufInitA(&instance->config.libGIO, 0);
|
||||
ffStrbufInitA(&instance->config.libDConf, 0);
|
||||
ffStrbufInitA(&instance->config.libDBus, 0);
|
||||
ffStrbufInitA(&instance->config.libXFConf, 0);
|
||||
ffStrbufInitA(&instance->config.libSQLite3, 0);
|
||||
ffStrbufInitA(&instance->config.librpm, 0);
|
||||
ffStrbufInitA(&instance->config.libImageMagick, 0);
|
||||
ffStrbufInitA(&instance->config.libZ, 0);
|
||||
ffStrbufInitA(&instance->config.libChafa, 0);
|
||||
ffStrbufInitA(&instance->config.libEGL, 0);
|
||||
ffStrbufInitA(&instance->config.libGLX, 0);
|
||||
ffStrbufInitA(&instance->config.libOSMesa, 0);
|
||||
ffStrbufInitA(&instance->config.libOpenCL, 0);
|
||||
ffStrbufInitA(&instance->config.libJSONC, 0);
|
||||
ffStrbufInitA(&instance->config.libfreetype, 0);
|
||||
ffStrbufInit(&instance->config.libPCI);
|
||||
ffStrbufInit(&instance->config.libVulkan);
|
||||
ffStrbufInit(&instance->config.libWayland);
|
||||
ffStrbufInit(&instance->config.libXcbRandr);
|
||||
ffStrbufInit(&instance->config.libXcb);
|
||||
ffStrbufInit(&instance->config.libXrandr);
|
||||
ffStrbufInit(&instance->config.libX11);
|
||||
ffStrbufInit(&instance->config.libGIO);
|
||||
ffStrbufInit(&instance->config.libDConf);
|
||||
ffStrbufInit(&instance->config.libDBus);
|
||||
ffStrbufInit(&instance->config.libXFConf);
|
||||
ffStrbufInit(&instance->config.libSQLite3);
|
||||
ffStrbufInit(&instance->config.librpm);
|
||||
ffStrbufInit(&instance->config.libImageMagick);
|
||||
ffStrbufInit(&instance->config.libZ);
|
||||
ffStrbufInit(&instance->config.libChafa);
|
||||
ffStrbufInit(&instance->config.libEGL);
|
||||
ffStrbufInit(&instance->config.libGLX);
|
||||
ffStrbufInit(&instance->config.libOSMesa);
|
||||
ffStrbufInit(&instance->config.libOpenCL);
|
||||
ffStrbufInit(&instance->config.libJSONC);
|
||||
ffStrbufInit(&instance->config.libfreetype);
|
||||
ffStrbufInit(&instance->config.libPulse);
|
||||
ffStrbufInit(&instance->config.libwlanapi);
|
||||
ffStrbufInit(&instance->config.libnm);
|
||||
@@ -142,7 +142,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
instance->config.weatherTimeout = 0;
|
||||
ffStrbufInitS(&instance->config.weatherOutputFormat, "%t+-+%C+(%l)");
|
||||
|
||||
ffStrbufInitA(&instance->config.playerName, 0);
|
||||
ffStrbufInit(&instance->config.playerName);
|
||||
|
||||
instance->config.percentType = 1;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
|
||||
static void createSubfolders(const char* fileName)
|
||||
{
|
||||
FFstrbuf path;
|
||||
ffStrbufInit(&path);
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
|
||||
|
||||
while(*fileName != '\0')
|
||||
{
|
||||
@@ -18,8 +17,6 @@ static void createSubfolders(const char* fileName)
|
||||
mkdir(path.chars, S_IRWXU | S_IRGRP | S_IROTH);
|
||||
++fileName;
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&path);
|
||||
}
|
||||
|
||||
bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
|
||||
@@ -218,9 +215,7 @@ void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* fol
|
||||
|
||||
void ffListFilesRecursively(const char* path)
|
||||
{
|
||||
FFstrbuf folder;
|
||||
ffStrbufInitS(&folder, path);
|
||||
FF_STRBUF_AUTO_DESTROY folder = ffStrbufCreateS(path);
|
||||
ffStrbufEnsureEndsWithC(&folder, '/');
|
||||
listFilesRecursively(&folder, 0, NULL);
|
||||
ffStrbufDestroy(&folder);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
static void createSubfolders(const char* fileName)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY path;
|
||||
ffStrbufInit(&path);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
|
||||
while(*fileName != '\0')
|
||||
{
|
||||
ffStrbufAppendC(&path, *fileName);
|
||||
@@ -141,9 +139,7 @@ void listFilesRecursively(FFstrbuf* folder, uint8_t indentation, const char* fol
|
||||
|
||||
void ffListFilesRecursively(const char* path)
|
||||
{
|
||||
FFstrbuf folder;
|
||||
ffStrbufInitS(&folder, path);
|
||||
FF_STRBUF_AUTO_DESTROY folder = ffStrbufCreateS(path);
|
||||
ffStrbufEnsureEndsWithC(&folder, '/');
|
||||
listFilesRecursively(&folder, 0, NULL);
|
||||
ffStrbufDestroy(&folder);
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ static void* libraryLoad(const char* path, int maxVersion)
|
||||
if(result != NULL || maxVersion < 0)
|
||||
return result;
|
||||
|
||||
FFstrbuf pathbuf;
|
||||
ffStrbufInitA(&pathbuf, 64);
|
||||
FF_STRBUF_AUTO_DESTROY pathbuf = ffStrbufCreateA(64);
|
||||
ffStrbufAppendS(&pathbuf, path);
|
||||
ffStrbufAppendC(&pathbuf, '.');
|
||||
|
||||
@@ -49,8 +48,6 @@ static void* libraryLoad(const char* path, int maxVersion)
|
||||
ffStrbufSubstrBefore(&pathbuf, originalLength);
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&pathbuf);
|
||||
|
||||
#endif
|
||||
|
||||
return result;
|
||||
|
||||
@@ -75,8 +75,7 @@ bool ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* host, con
|
||||
}
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY command;
|
||||
ffStrbufInitA(&command, 64);
|
||||
FF_STRBUF_AUTO_DESTROY command = ffStrbufCreateA(64);
|
||||
ffStrbufAppendS(&command, "GET ");
|
||||
ffStrbufAppendS(&command, path);
|
||||
ffStrbufAppendS(&command, " HTTP/1.1\nHost: ");
|
||||
|
||||
+3
-14
@@ -26,13 +26,11 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
|
||||
}
|
||||
else
|
||||
{
|
||||
FFstrbuf key;
|
||||
ffStrbufInit(&key);
|
||||
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
|
||||
ffParseFormatString(&key, customKeyFormat, 1, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex}
|
||||
});
|
||||
ffPrintUserString(key.chars);
|
||||
ffStrbufDestroy(&key);
|
||||
}
|
||||
|
||||
if(!instance->config.pipe)
|
||||
@@ -46,9 +44,7 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
|
||||
|
||||
void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments)
|
||||
{
|
||||
FFstrbuf buffer;
|
||||
ffStrbufInitA(&buffer, 256);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreateA(256);
|
||||
ffParseFormatString(&buffer, format, numArgs, arguments);
|
||||
|
||||
if(buffer.length > 0)
|
||||
@@ -57,8 +53,6 @@ void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t m
|
||||
ffPrintUserString(buffer.chars);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&buffer);
|
||||
}
|
||||
|
||||
void ffPrintFormat(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments)
|
||||
@@ -74,15 +68,10 @@ static void printError(FFinstance* instance, const char* moduleName, uint8_t mod
|
||||
|
||||
if(hasCustomErrorFormat)
|
||||
{
|
||||
FFstrbuf error;
|
||||
ffStrbufInit(&error);
|
||||
ffStrbufAppendVF(&error, message, arguments);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY error = ffStrbufCreateVF(message, arguments);
|
||||
ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, customErrorFormat, 1, (FFformatarg[]) {
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &error}
|
||||
});
|
||||
|
||||
ffStrbufDestroy(&error);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -28,8 +28,7 @@ const char* ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
|
||||
BOOL success;
|
||||
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY cmdline;
|
||||
ffStrbufInitF(&cmdline, "\"%s\"", argv[0]);
|
||||
FF_STRBUF_AUTO_DESTROY cmdline = ffStrbufCreateF("\"%s\"", argv[0]);
|
||||
for(char* const* parg = &argv[1]; *parg; ++parg)
|
||||
{
|
||||
ffStrbufAppendC(&cmdline, ' ');
|
||||
|
||||
+3
-15
@@ -146,25 +146,15 @@ done:
|
||||
|
||||
bool ffParsePropFileHomeValues(const FFinstance* instance, const char* relativeFile, uint32_t numQueries, FFpropquery* queries)
|
||||
{
|
||||
FFstrbuf absolutePath;
|
||||
ffStrbufInitA(&absolutePath, 64);
|
||||
ffStrbufAppend(&absolutePath, &instance->state.platform.homeDir);
|
||||
ffStrbufAppendC(&absolutePath, '/');
|
||||
ffStrbufAppendS(&absolutePath, relativeFile);
|
||||
|
||||
bool result = ffParsePropFileValues(absolutePath.chars, numQueries, queries);
|
||||
|
||||
ffStrbufDestroy(&absolutePath);
|
||||
|
||||
return result;
|
||||
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateF("%s/%s", instance->state.platform.homeDir.chars, relativeFile);
|
||||
return ffParsePropFileValues(absolutePath.chars, numQueries, queries);
|
||||
}
|
||||
|
||||
bool ffParsePropFileListValues(const FFlist* list, const char* relativeFile, uint32_t numQueries, FFpropquery* queries)
|
||||
{
|
||||
bool foundAFile = false;
|
||||
|
||||
FFstrbuf baseDir;
|
||||
ffStrbufInitA(&baseDir, 64);
|
||||
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(64);
|
||||
|
||||
FF_LIST_FOR_EACH(FFstrbuf, dirPrefix, *list)
|
||||
{
|
||||
@@ -189,7 +179,5 @@ bool ffParsePropFileListValues(const FFlist* list, const char* relativeFile, uin
|
||||
break;
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&baseDir);
|
||||
|
||||
return foundAFile;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
|
||||
const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY buffer;
|
||||
ffStrbufInit(&buffer);
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
||||
|
||||
if(ffProcessAppendStdOut(&buffer, (char* const[]){
|
||||
FF_TERMUX_API_PATH,
|
||||
|
||||
@@ -8,8 +8,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
|
||||
{
|
||||
uint32_t dirLength = dir->length;
|
||||
|
||||
FFstrbuf testBatteryBuffer;
|
||||
ffStrbufInit(&testBatteryBuffer);
|
||||
FF_STRBUF_AUTO_DESTROY testBatteryBuffer = ffStrbufCreate();
|
||||
|
||||
//type must exist and be "Battery"
|
||||
ffStrbufAppendS(dir, "/type");
|
||||
@@ -17,10 +16,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
|
||||
ffStrbufSubstrBefore(dir, dirLength);
|
||||
|
||||
if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Battery") != 0)
|
||||
{
|
||||
ffStrbufDestroy(&testBatteryBuffer);
|
||||
return;
|
||||
}
|
||||
|
||||
//scope may not exist or must not be "Device"
|
||||
ffStrbufAppendS(dir, "/scope");
|
||||
@@ -28,10 +24,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
|
||||
ffStrbufSubstrBefore(dir, dirLength);
|
||||
|
||||
if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Device") == 0)
|
||||
{
|
||||
ffStrbufDestroy(&testBatteryBuffer);
|
||||
return;
|
||||
}
|
||||
|
||||
BatteryResult* result = ffListAdd(results);
|
||||
|
||||
@@ -41,7 +34,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
|
||||
ffStrbufSubstrBefore(dir, dirLength);
|
||||
if(available)
|
||||
result->capacity = ffStrbufToDouble(&testBatteryBuffer);
|
||||
ffStrbufDestroy(&testBatteryBuffer);
|
||||
|
||||
if(!available)
|
||||
{
|
||||
result->capacity = 0.0/0.0;
|
||||
@@ -76,8 +69,8 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
|
||||
|
||||
const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
|
||||
{
|
||||
FFstrbuf baseDir;
|
||||
ffStrbufInitA(&baseDir, 64);
|
||||
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(64);
|
||||
|
||||
if(instance->config.battery.dir.length > 0)
|
||||
{
|
||||
ffStrbufAppend(&baseDir, &instance->config.battery.dir);
|
||||
@@ -92,10 +85,7 @@ const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
|
||||
|
||||
DIR* dirp = opendir(baseDir.chars);
|
||||
if(dirp == NULL)
|
||||
{
|
||||
ffStrbufDestroy(&baseDir);
|
||||
return "opendir(batteryDir) == NULL";
|
||||
}
|
||||
|
||||
struct dirent* entry;
|
||||
while((entry = readdir(dirp)) != NULL)
|
||||
@@ -110,11 +100,8 @@ const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
|
||||
|
||||
closedir(dirp);
|
||||
|
||||
if(results->length == 0) {
|
||||
ffStrbufDestroy(&baseDir);
|
||||
if(results->length == 0)
|
||||
return "batteryDir doesn't contain any battery folder";
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&baseDir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -13,14 +13,12 @@ const char* ffDetectBrightness(FF_MAYBE_UNUSED FFlist* result)
|
||||
if(dirp == NULL)
|
||||
return "Failed to open `/sys/class/backlight/`";
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY backlightDir;
|
||||
ffStrbufInitA(&backlightDir, 64);
|
||||
FF_STRBUF_AUTO_DESTROY backlightDir = ffStrbufCreateA(64);
|
||||
ffStrbufAppendS(&backlightDir, backlightDirPath);
|
||||
|
||||
uint32_t backlightDirLength = backlightDir.length;
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY buffer;
|
||||
ffStrbufInit(&buffer);
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
||||
|
||||
struct dirent* entry;
|
||||
while((entry = readdir(dirp)) != NULL)
|
||||
|
||||
@@ -7,8 +7,7 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu)
|
||||
|
||||
if (instance->config.cpu.temp)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY cpuTemp;
|
||||
ffStrbufInit(&cpuTemp);
|
||||
FF_STRBUF_AUTO_DESTROY cpuTemp = ffStrbufCreate();
|
||||
if(ffSysctlGetString("temperature", &cpuTemp))
|
||||
cpu->temperature = FF_CPU_TEMP_UNSET;
|
||||
else
|
||||
|
||||
@@ -41,12 +41,10 @@ static void parseCpuInfo(FFCPUResult* cpu, FFstrbuf* physicalCoresBuffer, FFstrb
|
||||
|
||||
static double getGHz(const char* file)
|
||||
{
|
||||
FFstrbuf content;
|
||||
ffStrbufInit(&content);
|
||||
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate();
|
||||
if(ffAppendFileBuffer(file, &content))
|
||||
{
|
||||
double herz = ffStrbufToDouble(&content);
|
||||
ffStrbufDestroy(&content);
|
||||
|
||||
//ffStrbufToDouble failed
|
||||
if(herz != herz)
|
||||
@@ -111,17 +109,10 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu)
|
||||
else
|
||||
cpu->temperature = FF_CPU_TEMP_UNSET;
|
||||
|
||||
FFstrbuf physicalCoresBuffer;
|
||||
ffStrbufInit(&physicalCoresBuffer);
|
||||
|
||||
FFstrbuf cpuMHz;
|
||||
ffStrbufInit(&cpuMHz);
|
||||
|
||||
FFstrbuf cpuIsa;
|
||||
ffStrbufInit(&cpuIsa);
|
||||
|
||||
FFstrbuf cpuUarch;
|
||||
ffStrbufInit(&cpuUarch);
|
||||
FF_STRBUF_AUTO_DESTROY physicalCoresBuffer = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY cpuMHz = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY cpuIsa = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY cpuUarch = ffStrbufCreate();
|
||||
|
||||
parseCpuInfo(cpu, &physicalCoresBuffer, &cpuMHz, &cpuIsa, &cpuUarch);
|
||||
|
||||
@@ -155,9 +146,4 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu)
|
||||
ffStrbufAppendC(&cpu->name, ' ');
|
||||
ffStrbufAppend(&cpu->name, &cpuIsa);
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&physicalCoresBuffer);
|
||||
ffStrbufDestroy(&cpuMHz);
|
||||
ffStrbufDestroy(&cpuIsa);
|
||||
ffStrbufDestroy(&cpuUarch);
|
||||
}
|
||||
|
||||
@@ -112,8 +112,7 @@ static void detectName(FFDisk* disk, const FFstrbuf* device)
|
||||
if(stat(device->chars, &deviceStat) != 0)
|
||||
return;
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY basePath;
|
||||
ffStrbufInit(&basePath);
|
||||
FF_STRBUF_AUTO_DESTROY basePath = ffStrbufCreate();
|
||||
|
||||
//Try partlabel first
|
||||
ffStrbufSetS(&basePath, "/dev/disk/by-partlabel/");
|
||||
|
||||
@@ -40,8 +40,7 @@ static void detectDisplays(FFDisplayServerResult* ds, bool detectName)
|
||||
}
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY name;
|
||||
ffStrbufInit(&name);
|
||||
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
|
||||
if(detectName && CoreDisplay_DisplayCreateInfoDictionary)
|
||||
{
|
||||
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = CoreDisplay_DisplayCreateInfoDictionary(screen);
|
||||
|
||||
@@ -4,11 +4,11 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* ins
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
|
||||
ffStrbufInitA(&ds->wmProcessName, 0);
|
||||
ffStrbufInitA(&ds->wmPrettyName, 0);
|
||||
ffStrbufInitA(&ds->wmProtocolName, 0);
|
||||
ffStrbufInitA(&ds->deProcessName, 0);
|
||||
ffStrbufInitA(&ds->dePrettyName, 0);
|
||||
ffStrbufInitA(&ds->deVersion, 0);
|
||||
ffStrbufInit(&ds->wmProcessName);
|
||||
ffStrbufInit(&ds->wmPrettyName);
|
||||
ffStrbufInit(&ds->wmProtocolName);
|
||||
ffStrbufInit(&ds->deProcessName);
|
||||
ffStrbufInit(&ds->dePrettyName);
|
||||
ffStrbufInit(&ds->deVersion);
|
||||
ffListInitA(&ds->displays, sizeof(FFDisplayResult), 0);
|
||||
}
|
||||
|
||||
@@ -42,8 +42,7 @@ static void detectDisplays(FFDisplayServerResult* ds, bool detectName)
|
||||
DeleteDC(hdc);
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY name;
|
||||
ffStrbufInit(&name);
|
||||
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
|
||||
|
||||
if (detectName)
|
||||
{
|
||||
|
||||
@@ -10,8 +10,7 @@ static void parseDRM(FFDisplayServerResult* result)
|
||||
if(dirp == NULL)
|
||||
return;
|
||||
|
||||
FFstrbuf drmDir;
|
||||
ffStrbufInitA(&drmDir, 64);
|
||||
FF_STRBUF_AUTO_DESTROY drmDir = ffStrbufCreateA(64);
|
||||
ffStrbufAppendS(&drmDir, drmDirPath);
|
||||
|
||||
uint32_t drmDirLength = drmDir.length;
|
||||
@@ -48,7 +47,6 @@ static void parseDRM(FFDisplayServerResult* result)
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
ffStrbufDestroy(&drmDir);
|
||||
}
|
||||
|
||||
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* instance)
|
||||
|
||||
@@ -42,13 +42,11 @@ static void waylandDetectWM(int fd, FFDisplayServerResult* result)
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1)
|
||||
return;
|
||||
|
||||
FFstrbuf procPath;
|
||||
ffStrbufInit(&procPath);
|
||||
FF_STRBUF_AUTO_DESTROY procPath = ffStrbufCreate();
|
||||
ffStrbufAppendF(&procPath, "/proc/%d/cmdline", ucred.pid); //We check the cmdline for the process name, because it is not trimmed.
|
||||
ffReadFileBuffer(procPath.chars, &result->wmProcessName);
|
||||
ffStrbufSubstrBeforeFirstC(&result->wmProcessName, '\0'); //Trim the arguments
|
||||
ffStrbufSubstrAfterLastC(&result->wmProcessName, '/'); //Trim the path
|
||||
ffStrbufDestroy(&procPath);
|
||||
}
|
||||
#else
|
||||
static void waylandDetectWM(int fd, FFDisplayServerResult* result)
|
||||
|
||||
@@ -165,14 +165,9 @@ static void getMate(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
ffStrbufSetS(&result->deProcessName, "mate-session");
|
||||
ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_MATE);
|
||||
|
||||
FFstrbuf major;
|
||||
ffStrbufInit(&major);
|
||||
|
||||
FFstrbuf minor;
|
||||
ffStrbufInit(&minor);
|
||||
|
||||
FFstrbuf micro;
|
||||
ffStrbufInit(µ);
|
||||
FF_STRBUF_AUTO_DESTROY major = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY minor = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY micro = ffStrbufCreate();
|
||||
|
||||
ffParsePropFileDataValues(instance, "mate-about/mate-version.xml", 3, (FFpropquery[]) {
|
||||
{"<platform>", &major},
|
||||
@@ -182,10 +177,6 @@ static void getMate(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
|
||||
ffParseSemver(&result->deVersion, &major, &minor, µ);
|
||||
|
||||
ffStrbufDestroy(&major);
|
||||
ffStrbufDestroy(&minor);
|
||||
ffStrbufDestroy(µ);
|
||||
|
||||
if(result->deVersion.length == 0 && instance->config.allowSlowOperations)
|
||||
{
|
||||
ffProcessAppendStdOut(&result->deVersion, (char* const[]){
|
||||
@@ -244,13 +235,10 @@ static void getLXQt(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
ffParsePropLines(result->deVersion.chars , "liblxqt", &result->deVersion);
|
||||
}
|
||||
|
||||
FFstrbuf wmProcessNameBuffer;
|
||||
ffStrbufInit(&wmProcessNameBuffer);
|
||||
FF_STRBUF_AUTO_DESTROY wmProcessNameBuffer = ffStrbufCreate();
|
||||
|
||||
ffParsePropFileConfig(instance, "lxqt/session.conf", "window_manager =", &wmProcessNameBuffer);
|
||||
applyBetterWM(result, wmProcessNameBuffer.chars);
|
||||
|
||||
ffStrbufDestroy(&wmProcessNameBuffer);
|
||||
}
|
||||
|
||||
static void getBudgie(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
@@ -351,21 +339,14 @@ static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* re
|
||||
if(proc == NULL)
|
||||
return;
|
||||
|
||||
FFstrbuf procPath;
|
||||
ffStrbufInitA(&procPath, 64);
|
||||
FF_STRBUF_AUTO_DESTROY procPath = ffStrbufCreateA(64);
|
||||
ffStrbufAppendS(&procPath, "/proc/");
|
||||
|
||||
uint32_t procPathLength = procPath.length;
|
||||
|
||||
FFstrbuf userID;
|
||||
ffStrbufInit(&userID);
|
||||
ffStrbufAppendF(&userID, "%i", getuid());
|
||||
|
||||
FFstrbuf loginuid;
|
||||
ffStrbufInit(&loginuid);
|
||||
|
||||
FFstrbuf processName;
|
||||
ffStrbufInitA(&processName, 256); //Some processes have large command lines (looking at you chrome)
|
||||
FF_STRBUF_AUTO_DESTROY userID = ffStrbufCreateF("%i", getuid());
|
||||
FF_STRBUF_AUTO_DESTROY loginuid = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY processName = ffStrbufCreateA(256); //Some processes have large command lines (looking at you chrome)
|
||||
|
||||
struct dirent* dirent;
|
||||
while((dirent = readdir(proc)) != NULL)
|
||||
@@ -407,11 +388,6 @@ static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* re
|
||||
}
|
||||
|
||||
closedir(proc);
|
||||
|
||||
ffStrbufDestroy(&processName);
|
||||
ffStrbufDestroy(&loginuid);
|
||||
ffStrbufDestroy(&userID);
|
||||
ffStrbufDestroy(&procPath);
|
||||
}
|
||||
|
||||
void ffdsDetectWMDE(const FFinstance* instance, FFDisplayServerResult* result)
|
||||
|
||||
@@ -10,8 +10,7 @@ const char* ffDetectGamepad(FF_MAYBE_UNUSED const FFinstance* instance, FFlist*
|
||||
if(dirp == NULL)
|
||||
return "opendir(\"/sys/class/input/\") == NULL";
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY path;
|
||||
ffStrbufInitS(&path, "/sys/class/input/");
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/sys/class/input/");
|
||||
uint32_t baseLen = path.length;
|
||||
|
||||
struct dirent* entry;
|
||||
|
||||
@@ -64,14 +64,9 @@ static void drmDetectDeviceName(const FFinstance* instance, FFGPUResult* gpu, PC
|
||||
#endif
|
||||
}
|
||||
|
||||
FFstrbuf query;
|
||||
ffStrbufInit(&query);
|
||||
ffStrbufAppendF(&query, "%X, %X,", device->device_id, revId);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY query = ffStrbufCreateF("%X, %X,", device->device_id, revId);
|
||||
ffParsePropFileData(instance, "libdrm/amdgpu.ids", query.chars, &gpu->name);
|
||||
|
||||
ffStrbufDestroy(&query);
|
||||
|
||||
const char* removeStrings[] = {
|
||||
"AMD ", "ATI ",
|
||||
" (TM)", "(TM)",
|
||||
@@ -116,10 +111,7 @@ static void pciDetectDriverName(FFGPUResult* gpu, PCIData* pci, struct pci_dev*
|
||||
if(!ffStrSet(base))
|
||||
return;
|
||||
|
||||
FFstrbuf path;
|
||||
ffStrbufInitA(&path, 64);
|
||||
ffStrbufAppendF(&path, "%s/devices/%04x:%02x:%02x.%d/driver", base, device->domain, device->bus, device->dev, device->func);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateF("%s/devices/%04x:%02x:%02x.%d/driver", base, device->domain, device->bus, device->dev, device->func);
|
||||
ffStrbufEnsureFree(&gpu->driver, 1023);
|
||||
ssize_t resultLength = readlink(path.chars, gpu->driver.chars, gpu->driver.allocated - 1); //-1 for null terminator
|
||||
if(resultLength > 0)
|
||||
@@ -128,8 +120,6 @@ static void pciDetectDriverName(FFGPUResult* gpu, PCIData* pci, struct pci_dev*
|
||||
gpu->driver.chars[resultLength] = '\0';
|
||||
ffStrbufSubstrAfterLastC(&gpu->driver, '/');
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&path);
|
||||
}
|
||||
|
||||
static void pciDetectTemperatur(FFGPUResult* gpu, struct pci_dev* device)
|
||||
|
||||
@@ -162,8 +162,7 @@ static void detectGTK(const FFinstance* instance, const char* version, FFGTKResu
|
||||
return;
|
||||
|
||||
//We need to do this because we use multiple threads on configDirs
|
||||
FFstrbuf baseDir;
|
||||
ffStrbufInitA(&baseDir, 64);
|
||||
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(64);
|
||||
|
||||
FF_LIST_FOR_EACH(FFstrbuf, configDir, instance->state.platform.configDirs)
|
||||
{
|
||||
@@ -172,8 +171,6 @@ static void detectGTK(const FFinstance* instance, const char* version, FFGTKResu
|
||||
if(allPropertiesSet(result))
|
||||
break;
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&baseDir);
|
||||
}
|
||||
|
||||
#define FF_DETECT_GTK_IMPL(version) \
|
||||
|
||||
@@ -85,8 +85,7 @@ static void detectPlasma(const FFinstance* instance, FFQtResult* result)
|
||||
bool foundAFile = false;
|
||||
|
||||
//We need to do this because we use multiple threads on configDirs
|
||||
FFstrbuf baseDir;
|
||||
ffStrbufInitA(&baseDir, 64);
|
||||
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(64);
|
||||
|
||||
FF_LIST_FOR_EACH(FFstrbuf, configDir, instance->state.platform.configDirs)
|
||||
{
|
||||
@@ -97,13 +96,9 @@ static void detectPlasma(const FFinstance* instance, FFQtResult* result)
|
||||
foundAFile = true;
|
||||
|
||||
if(allValuesSet(result))
|
||||
{
|
||||
ffStrbufDestroy(&baseDir);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&baseDir);
|
||||
if(!foundAFile)
|
||||
return;
|
||||
|
||||
|
||||
@@ -32,6 +32,6 @@ void ffDetectHostImpl(FFHostResult* host)
|
||||
|
||||
//Not implemented
|
||||
|
||||
ffStrbufInitA(&host->productVersion, 0);
|
||||
ffStrbufInitA(&host->productSku, 0);
|
||||
ffStrbufInit(&host->productVersion);
|
||||
ffStrbufInit(&host->productSku);
|
||||
}
|
||||
|
||||
@@ -89,8 +89,7 @@ void ffDetectHostImpl(FFHostResult* host)
|
||||
{
|
||||
ffStrbufAppendS(&host->productName, "Windows Subsystem for Linux");
|
||||
|
||||
FFstrbuf wslVer; //Wide charactors
|
||||
ffStrbufInit(&wslVer);
|
||||
FF_STRBUF_AUTO_DESTROY wslVer = ffStrbufCreate(); //Wide charactors
|
||||
if(!ffProcessAppendStdOut(&wslVer, (char* const[]){
|
||||
"wsl.exe",
|
||||
"--version",
|
||||
@@ -106,7 +105,6 @@ void ffDetectHostImpl(FFHostResult* host)
|
||||
}
|
||||
ffStrbufAppendC(&host->productName, ')');
|
||||
}
|
||||
ffStrbufDestroy(&wslVer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ const char* ffDetectIcons(const FFinstance* instance, FFstrbuf* result)
|
||||
if(plasma->length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
|
||||
return "No icons could be found";
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY gtkPretty;
|
||||
ffStrbufInit(>kPretty);
|
||||
FF_STRBUF_AUTO_DESTROY gtkPretty = ffStrbufCreate();
|
||||
ffParseGTK(>kPretty, gtk2, gtk3, gtk4);
|
||||
|
||||
if(plasma->length > 0)
|
||||
|
||||
@@ -6,7 +6,7 @@ void ffDetectMediaImpl(const FFinstance* instance, FFMediaResult* media);
|
||||
const FFMediaResult* ffDetectMedia(const FFinstance* instance)
|
||||
{
|
||||
FF_DETECTION_INTERNAL_GUARD(FFMediaResult,
|
||||
ffStrbufInitA(&result.error, 0);
|
||||
ffStrbufInit(&result.error);
|
||||
ffStrbufInit(&result.playerId);
|
||||
ffStrbufInit(&result.player);
|
||||
ffStrbufInit(&result.song);
|
||||
|
||||
@@ -107,12 +107,9 @@ static void getCustomBus(FFDBusData* data, const FFinstance* instance, FFMediaRe
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf busName;
|
||||
ffStrbufInit(&busName);
|
||||
ffStrbufAppendS(&busName, FF_DBUS_MPRIS_PREFIX);
|
||||
FF_STRBUF_AUTO_DESTROY busName = ffStrbufCreateS(FF_DBUS_MPRIS_PREFIX);
|
||||
ffStrbufAppend(&busName, &instance->config.playerName);
|
||||
getBusProperties(data, busName.chars, result);
|
||||
ffStrbufDestroy(&busName);
|
||||
}
|
||||
|
||||
static void getBestBus(FFDBusData* data, FFMediaResult* result)
|
||||
|
||||
@@ -107,10 +107,10 @@ void ffDetectOSImpl(FFOSResult* os, const FFinstance* instance)
|
||||
ffStrbufInit(&os->prettyName);
|
||||
ffStrbufInit(&os->versionID);
|
||||
|
||||
ffStrbufInitA(&os->codename, 0);
|
||||
ffStrbufInitA(&os->idLike, 0);
|
||||
ffStrbufInitA(&os->variant, 0);
|
||||
ffStrbufInitA(&os->variantID, 0);
|
||||
ffStrbufInit(&os->codename);
|
||||
ffStrbufInit(&os->idLike);
|
||||
ffStrbufInit(&os->variant);
|
||||
ffStrbufInit(&os->variantID);
|
||||
|
||||
parseSystemVersion(os);
|
||||
|
||||
|
||||
@@ -28,8 +28,7 @@ static uint32_t getNumElements(const char* dirname, unsigned char type)
|
||||
|
||||
static void countBrewPackages(const char* dirname, FFPackagesResult* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY baseDir;
|
||||
ffStrbufInitS(&baseDir, dirname);
|
||||
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateS(dirname);
|
||||
|
||||
uint32_t baseDirLength = baseDir.length;
|
||||
|
||||
@@ -54,8 +53,7 @@ static void getBrewPackages(FFPackagesResult* result)
|
||||
|
||||
static uint32_t countMacPortsPackages(const char* dirname)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY baseDir;
|
||||
ffStrbufInitS(&baseDir, dirname);
|
||||
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateS(dirname);
|
||||
ffStrbufAppendS(&baseDir, "/var/macports/software");
|
||||
|
||||
return getNumElements(baseDir.chars, DT_DIR);
|
||||
|
||||
@@ -132,12 +132,10 @@ static uint32_t getNixPackagesImpl(char* path)
|
||||
if(!ffPathExists(path, FF_PATHTYPE_DIRECTORY))
|
||||
return 0;
|
||||
|
||||
FFstrbuf output;
|
||||
ffStrbufInitA(&output, 128);
|
||||
FF_STRBUF_AUTO_DESTROY output = ffStrbufCreateA(128);
|
||||
|
||||
//https://github.com/LinusDierheimer/fastfetch/issues/195#issuecomment-1191748222
|
||||
FFstrbuf command;
|
||||
ffStrbufInitA(&command, 255);
|
||||
FF_STRBUF_AUTO_DESTROY command = ffStrbufCreateA(255);
|
||||
ffStrbufAppendS(&command, "for x in $(nix-store --query --requisites ");
|
||||
ffStrbufAppendS(&command, path);
|
||||
ffStrbufAppendS(&command, "); do if [ -d $x ]; then echo $x ; fi ; done | cut -d- -f2- | egrep '([0-9]{1,}\\.)+[0-9]{1,}' | egrep -v '\\-doc$|\\-man$|\\-info$|\\-dev$|\\-bin$|^nixos-system-nixos-' | uniq | wc -l");
|
||||
@@ -149,12 +147,7 @@ static uint32_t getNixPackagesImpl(char* path)
|
||||
NULL
|
||||
});
|
||||
|
||||
int result = (int) strtol(output.chars, NULL, 10);
|
||||
|
||||
ffStrbufDestroy(&command);
|
||||
ffStrbufDestroy(&output);
|
||||
|
||||
return (uint32_t) result;
|
||||
return (uint32_t) strtol(output.chars, NULL, 10);
|
||||
}
|
||||
|
||||
static uint32_t getNixPackages(FFstrbuf* baseDir, const char* dirname)
|
||||
@@ -329,8 +322,7 @@ static void getPackageCountsBedrock(const FFinstance* instance, FFstrbuf* baseDi
|
||||
|
||||
void ffDetectPackagesImpl(const FFinstance* instance, FFPackagesResult* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY baseDir;
|
||||
ffStrbufInitA(&baseDir, 512);
|
||||
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(512);
|
||||
ffStrbufAppendS(&baseDir, FASTFETCH_TARGET_DIR_ROOT);
|
||||
|
||||
if(ffStrbufIgnCaseEqualS(&ffDetectOS(instance)->id, "bedrock"))
|
||||
|
||||
@@ -34,8 +34,7 @@ static uint32_t getNumElements(const char* searchPath /* including `\*` suffix *
|
||||
|
||||
static void detectScoop(const FFinstance* instance, FFPackagesResult* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY scoopPath;
|
||||
ffStrbufInitA(&scoopPath, MAX_PATH + 3);
|
||||
FF_STRBUF_AUTO_DESTROY scoopPath = ffStrbufCreateA(MAX_PATH + 3);
|
||||
|
||||
const char* scoopEnv = getenv("SCOOP");
|
||||
if(ffStrSet(scoopEnv))
|
||||
|
||||
@@ -11,8 +11,7 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value)
|
||||
//https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
|
||||
uint32_t dirLength = dir->length;
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY valueBuffer;
|
||||
ffStrbufInit(&valueBuffer);
|
||||
FF_STRBUF_AUTO_DESTROY valueBuffer = ffStrbufCreate();
|
||||
|
||||
ffStrbufAppendS(dir, "temp1_input");
|
||||
if(!ffReadFileBuffer(dir->chars, &valueBuffer))
|
||||
@@ -58,8 +57,7 @@ const FFTempsResult* ffDetectTemps()
|
||||
|
||||
ffListInitA(&result.values, sizeof(FFTempValue), 16);
|
||||
|
||||
FFstrbuf baseDir;
|
||||
ffStrbufInitA(&baseDir, 64);
|
||||
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(64);
|
||||
ffStrbufAppendS(&baseDir, "/sys/class/hwmon/");
|
||||
|
||||
uint32_t baseDirLength = baseDir.length;
|
||||
@@ -67,7 +65,6 @@ const FFTempsResult* ffDetectTemps()
|
||||
DIR* dirp = opendir(baseDir.chars);
|
||||
if(dirp == NULL)
|
||||
{
|
||||
ffStrbufDestroy(&baseDir);
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
}
|
||||
@@ -94,7 +91,6 @@ const FFTempsResult* ffDetectTemps()
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
ffStrbufDestroy(&baseDir);
|
||||
|
||||
ffThreadMutexUnlock(&mutex);
|
||||
return &result;
|
||||
|
||||
@@ -6,11 +6,8 @@
|
||||
|
||||
static void detectAlacritty(const FFinstance* instance, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FFstrbuf fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
|
||||
FFstrbuf fontSize;
|
||||
ffStrbufInit(&fontSize);
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate();
|
||||
|
||||
FFpropquery fontQuery[] = {
|
||||
{"family:", &fontName},
|
||||
@@ -33,15 +30,11 @@ static void detectAlacritty(const FFinstance* instance, FFTerminalFontResult* te
|
||||
ffStrbufAppendS(&fontSize, "11");
|
||||
|
||||
ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars);
|
||||
|
||||
ffStrbufDestroy(&fontName);
|
||||
ffStrbufDestroy(&fontSize);
|
||||
}
|
||||
|
||||
FF_MAYBE_UNUSED static void detectTTY(FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FFstrbuf fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
|
||||
ffParsePropFile(FASTFETCH_TARGET_DIR_ETC"/vconsole.conf", "Font =", &fontName);
|
||||
|
||||
@@ -61,8 +54,6 @@ FF_MAYBE_UNUSED static void detectTTY(FFTerminalFontResult* terminalFont)
|
||||
ffFontInitCopy(&terminalFont->font, fontName.chars);
|
||||
else
|
||||
ffStrbufAppendS(&terminalFont->error, "Couldn't find Font in "FASTFETCH_TARGET_DIR_ETC"/vconsole.conf");
|
||||
|
||||
ffStrbufDestroy(&fontName);
|
||||
}
|
||||
|
||||
#if defined(_WIN32) || defined(__linux__)
|
||||
@@ -113,8 +104,7 @@ static const char* detectFromWTImpl(const FFinstance* instance, FFstrbuf* conten
|
||||
if (!profiles)
|
||||
return "json_object_object_get(root, \"profiles\") failed";
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY wtProfileId;
|
||||
ffStrbufInitS(&wtProfileId, getenv("WT_PROFILE_ID"));
|
||||
FF_STRBUF_AUTO_DESTROY wtProfileId = ffStrbufCreateS(getenv("WT_PROFILE_ID"));
|
||||
ffStrbufTrim(&wtProfileId, '\'');
|
||||
if (wtProfileId.length > 0)
|
||||
{
|
||||
@@ -158,8 +148,7 @@ static const char* detectFromWTImpl(const FFinstance* instance, FFstrbuf* conten
|
||||
static void detectFromWindowsTeriminal(const FFinstance* instance, const FFstrbuf* terminalExe, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
//https://learn.microsoft.com/en-us/windows/terminal/install#settings-json-file
|
||||
FFstrbuf json;
|
||||
ffStrbufInit(&json);
|
||||
FF_STRBUF_AUTO_DESTROY json = ffStrbufCreate();
|
||||
const char* error = NULL;
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -219,22 +208,18 @@ static void detectFromWindowsTeriminal(const FFinstance* instance, const FFstrbu
|
||||
if(error)
|
||||
{
|
||||
ffStrbufAppendS(&terminalFont->error, error);
|
||||
ffStrbufDestroy(&json);
|
||||
return;
|
||||
}
|
||||
ffStrbufTrimRight(&json, '\n');
|
||||
if(json.length == 0)
|
||||
{
|
||||
ffStrbufAppendS(&terminalFont->error, "Cannot find file \"settings.json\"");
|
||||
ffStrbufDestroy(&json);
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf name;
|
||||
ffStrbufInit(&name);
|
||||
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
|
||||
double size = -1;
|
||||
error = detectFromWTImpl(instance, &json, &name, &size);
|
||||
ffStrbufDestroy(&json);
|
||||
|
||||
if(error)
|
||||
ffStrbufAppendS(&terminalFont->error, error);
|
||||
@@ -244,8 +229,6 @@ static void detectFromWindowsTeriminal(const FFinstance* instance, const FFstrbu
|
||||
snprintf(sizeStr, sizeof(sizeStr), "%g", size);
|
||||
ffFontInitValues(&terminalFont->font, name.chars, sizeStr);
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&name);
|
||||
}
|
||||
|
||||
#else //FF_HAVE_JSONC
|
||||
@@ -262,11 +245,8 @@ static void detectFromWindowsTeriminal(const FFinstance* instance, const FFstrbu
|
||||
|
||||
FF_MAYBE_UNUSED static bool detectKitty(const FFinstance* instance, FFTerminalFontResult* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY fontSize;
|
||||
ffStrbufInit(&fontSize);
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate();
|
||||
|
||||
FFpropquery fontQuery[] = {
|
||||
{"font_family ", &fontName},
|
||||
@@ -288,11 +268,8 @@ FF_MAYBE_UNUSED static bool detectKitty(const FFinstance* instance, FFTerminalFo
|
||||
|
||||
static void detectTerminator(const FFinstance* instance, FFTerminalFontResult* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY useSystemFont;
|
||||
ffStrbufInit(&useSystemFont);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
FF_STRBUF_AUTO_DESTROY useSystemFont = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
|
||||
FFpropquery fontQuery[] = {
|
||||
{"use_system_font =", &useSystemFont},
|
||||
@@ -319,8 +296,7 @@ static void detectTerminator(const FFinstance* instance, FFTerminalFontResult* r
|
||||
|
||||
static bool detectWezterm(FF_MAYBE_UNUSED const FFinstance* instance, FFTerminalFontResult* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
|
||||
ffStrbufSetS(&result->error, ffProcessAppendStdOut(&fontName, (char* const[]){
|
||||
"wezterm",
|
||||
@@ -347,11 +323,8 @@ static bool detectWezterm(FF_MAYBE_UNUSED const FFinstance* instance, FFTerminal
|
||||
|
||||
static bool detectTabby(FF_MAYBE_UNUSED const FFinstance* instance, FFTerminalFontResult* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY fontSize;
|
||||
ffStrbufInit(&fontSize);
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate();
|
||||
|
||||
FFpropquery fontQuery[] = {
|
||||
{"font: ", &fontName},
|
||||
@@ -409,7 +382,7 @@ static bool detectTerminalFontCommon(const FFinstance* instance, const FFTermina
|
||||
const FFTerminalFontResult* ffDetectTerminalFont(const FFinstance* instance)
|
||||
{
|
||||
FF_DETECTION_INTERNAL_GUARD(FFTerminalFontResult,
|
||||
ffStrbufInitA(&result.error, 0);
|
||||
ffStrbufInit(&result.error);
|
||||
|
||||
const FFTerminalShellResult* terminalShell = ffDetectTerminalShell(instance);
|
||||
|
||||
|
||||
@@ -46,8 +46,7 @@ static void detectIterm2(const FFinstance* instance, FFTerminalFontResult* termi
|
||||
|
||||
static void detectAppleTerminal(FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY font;
|
||||
ffStrbufInit(&font);
|
||||
FF_STRBUF_AUTO_DESTROY font = ffStrbufCreate();
|
||||
ffOsascript("tell application \"Terminal\" to font name of window frontmost & \" \" & font size of window frontmost", &font);
|
||||
|
||||
if(font.length == 0)
|
||||
|
||||
@@ -35,8 +35,7 @@ static void detectFromGSettings(const FFinstance* instance, char* profilePath, c
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf path;
|
||||
ffStrbufInitA(&path, 128);
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateA(128);
|
||||
ffStrbufAppendS(&path, profilePath);
|
||||
ffStrbufAppendS(&path, defaultProfile);
|
||||
ffStrbufAppendC(&path, '/');
|
||||
@@ -57,64 +56,47 @@ static void detectFromGSettings(const FFinstance* instance, char* profilePath, c
|
||||
else
|
||||
ffStrbufAppendS(&terminalFont->error, "Could't get system monospace font name from GSettings / DConf");
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&path);
|
||||
}
|
||||
|
||||
static void detectFromConfigFile(const FFinstance* instance, const char* configFile, const char* start, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FFstrbuf fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
ffParsePropFileConfig(instance, configFile, start, &fontName);
|
||||
|
||||
if(fontName.length == 0)
|
||||
ffStrbufAppendF(&terminalFont->error, "Couldn't find %s in .config/%s", start, configFile);
|
||||
else
|
||||
ffFontInitPango(&terminalFont->font, fontName.chars);
|
||||
|
||||
ffStrbufDestroy(&fontName);
|
||||
}
|
||||
|
||||
static void detectKonsole(const FFinstance* instance, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FFstrbuf profile;
|
||||
ffStrbufInit(&profile);
|
||||
FF_STRBUF_AUTO_DESTROY profile = ffStrbufCreate();
|
||||
ffParsePropFileConfig(instance, "konsolerc", "DefaultProfile =", &profile);
|
||||
|
||||
if(profile.length == 0)
|
||||
{
|
||||
ffStrbufAppendS(&terminalFont->error, "Couldn't find \"DefaultProfile=%[^\\n]\" in \".config/konsolerc\"");
|
||||
ffStrbufDestroy(&profile);
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf profilePath;
|
||||
ffStrbufInitA(&profilePath, 32);
|
||||
FF_STRBUF_AUTO_DESTROY profilePath = ffStrbufCreateA(32);
|
||||
ffStrbufAppendS(&profilePath, "konsole/");
|
||||
ffStrbufAppend(&profilePath, &profile);
|
||||
|
||||
ffStrbufDestroy(&profile);
|
||||
|
||||
FFstrbuf fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
ffParsePropFileData(instance, profilePath.chars, "Font =", &fontName);
|
||||
|
||||
if(fontName.length == 0)
|
||||
ffStrbufAppendF(&terminalFont->error, "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath.chars);
|
||||
else
|
||||
ffFontInitQt(&terminalFont->font, fontName.chars);
|
||||
|
||||
ffStrbufDestroy(&fontName);
|
||||
ffStrbufDestroy(&profilePath);
|
||||
}
|
||||
|
||||
static void detectXFCETerminal(const FFinstance* instance, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FFstrbuf useSysFont;
|
||||
ffStrbufInit(&useSysFont);
|
||||
|
||||
FFstrbuf fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
FF_STRBUF_AUTO_DESTROY useSysFont = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
|
||||
ffParsePropFileConfigValues(instance, "xfce4/terminal/terminalrc", 2, (FFpropquery[]) {
|
||||
{"FontUseSystem = ", &useSysFont},
|
||||
@@ -136,21 +118,14 @@ static void detectXFCETerminal(const FFinstance* instance, FFTerminalFontResult*
|
||||
else
|
||||
ffStrbufAppendS(&terminalFont->error, "Couldn't find xsettings::/Gtk/MonospaceFontName in XFConf");
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&fontName);
|
||||
ffStrbufDestroy(&useSysFont);
|
||||
}
|
||||
|
||||
static void detectDeepinTerminal(const FFinstance* instance, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FFstrbuf fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY profile = ffStrbufCreate();
|
||||
|
||||
FFstrbuf fontSize;
|
||||
ffStrbufInit(&fontSize);
|
||||
|
||||
FFstrbuf profile;
|
||||
ffStrbufInit(&profile);
|
||||
ffStrbufAppend(&profile, &instance->state.platform.homeDir);
|
||||
ffStrbufAppendS(&profile, ".config/deepin/deepin-terminal/config.conf"); //TODO: Use config dirs
|
||||
FILE* file = fopen(profile.chars, "r");
|
||||
@@ -180,23 +155,17 @@ static void detectDeepinTerminal(const FFinstance* instance, FFTerminalFontResul
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&profile);
|
||||
|
||||
if(fontName.length == 0)
|
||||
ffStrbufAppendS(&fontName, "Noto Sans Mono");
|
||||
if(fontSize.length == 0)
|
||||
ffStrbufAppendS(&fontSize, "11");
|
||||
|
||||
ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars);
|
||||
|
||||
ffStrbufDestroy(&fontName);
|
||||
ffStrbufDestroy(&fontSize);
|
||||
}
|
||||
|
||||
static void detectFootTerminal(const FFinstance* instance, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY font;
|
||||
ffStrbufInit(&font);
|
||||
FF_STRBUF_AUTO_DESTROY font = ffStrbufCreate();
|
||||
|
||||
if (!ffParsePropFileConfig(instance, "foot/foot.ini", "font=", &font) || !ffStrSet(font.chars))
|
||||
{
|
||||
|
||||
@@ -8,11 +8,8 @@
|
||||
|
||||
static void detectMintty(const FFinstance* instance, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY fontSize;
|
||||
ffStrbufInit(&fontSize);
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate();
|
||||
|
||||
if(!ffParsePropFileConfigValues(instance, "mintty/config", 2, (FFpropquery[]) {
|
||||
{"Font=", &fontName},
|
||||
@@ -54,14 +51,9 @@ static void detectConEmu(const FFinstance* instance, FFTerminalFontResult* termi
|
||||
FF_UNUSED(instance)
|
||||
|
||||
//https://conemu.github.io/en/ConEmuXml.html#search-sequence
|
||||
FFstrbuf path;
|
||||
ffStrbufInit(&path);
|
||||
|
||||
FFstrbuf fontName;
|
||||
ffStrbufInit(&fontName);
|
||||
|
||||
FFstrbuf fontSize;
|
||||
ffStrbufInit(&fontSize);
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate();
|
||||
FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate();
|
||||
|
||||
const char* paths[] = { "ConEmuDir", "ConEmuBaseDir", "APPDATA" };
|
||||
for (uint32_t i = 0; i < sizeof(paths) / sizeof(paths[0]); ++i)
|
||||
@@ -77,7 +69,6 @@ static void detectConEmu(const FFinstance* instance, FFTerminalFontResult* termi
|
||||
break;
|
||||
}
|
||||
}
|
||||
ffStrbufDestroy(&path);
|
||||
|
||||
if(fontName.length == 0 && fontSize.length == 0)
|
||||
{
|
||||
@@ -96,9 +87,6 @@ static void detectConEmu(const FFinstance* instance, FFTerminalFontResult* termi
|
||||
ffStrbufAppendS(&fontSize, "14");
|
||||
|
||||
ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars);
|
||||
|
||||
ffStrbufDestroy(&fontName);
|
||||
ffStrbufDestroy(&fontSize);
|
||||
}
|
||||
|
||||
void ffDetectTerminalFontPlatform(const FFinstance* instance, const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont)
|
||||
|
||||
@@ -281,8 +281,7 @@ static void getUserShellFromEnv(const FFinstance* instance, FFTerminalShellResul
|
||||
|
||||
static void getShellVersionGeneric(FFstrbuf* exe, const char* exeName, FFstrbuf* version)
|
||||
{
|
||||
FFstrbuf command;
|
||||
ffStrbufInit(&command);
|
||||
FF_STRBUF_AUTO_DESTROY command = ffStrbufCreate();
|
||||
ffStrbufAppendS(&command, "printf \"%s\" \"$");
|
||||
ffStrbufAppendTransformS(&command, exeName, toupper);
|
||||
ffStrbufAppendS(&command, "_VERSION\"");
|
||||
@@ -297,8 +296,6 @@ static void getShellVersionGeneric(FFstrbuf* exe, const char* exeName, FFstrbuf*
|
||||
});
|
||||
ffStrbufSubstrBeforeFirstC(version, '(');
|
||||
ffStrbufRemoveStrings(version, 2, "-release", "release");
|
||||
|
||||
ffStrbufDestroy(&command);
|
||||
}
|
||||
|
||||
bool fftsGetShellVersion(FFstrbuf* exe, const char* exeName, FFstrbuf* version);
|
||||
|
||||
@@ -18,8 +18,7 @@ const char* ffDetectTheme(const FFinstance* instance, FFstrbuf* result)
|
||||
if(plasma->widgetStyle.length == 0 && plasma->colorScheme.length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
|
||||
return "No themes found";
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY plasmaColorPretty;
|
||||
ffStrbufInit(&plasmaColorPretty);
|
||||
FF_STRBUF_AUTO_DESTROY plasmaColorPretty = ffStrbufCreate();
|
||||
if(ffStrbufStartsWithIgnCase(&plasma->colorScheme, &plasma->widgetStyle))
|
||||
ffStrbufAppendNS(&plasmaColorPretty, plasma->colorScheme.length - plasma->widgetStyle.length, &plasma->colorScheme.chars[plasma->widgetStyle.length]);
|
||||
else
|
||||
@@ -27,8 +26,7 @@ const char* ffDetectTheme(const FFinstance* instance, FFstrbuf* result)
|
||||
|
||||
ffStrbufTrim(&plasmaColorPretty, ' ');
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY gtkPretty;
|
||||
ffStrbufInit(>kPretty);
|
||||
FF_STRBUF_AUTO_DESTROY gtkPretty = ffStrbufCreate();
|
||||
ffParseGTK(>kPretty, gtk2, gtk3, gtk4);
|
||||
|
||||
if(plasma->widgetStyle.length > 0)
|
||||
|
||||
@@ -8,8 +8,7 @@ const char* ffDetectWallpaper(FF_MAYBE_UNUSED const FFinstance* instance, FFstrb
|
||||
|
||||
#ifdef FF_HAVE_SQLITE3
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY path;
|
||||
ffStrbufInitCopy(&path, &instance->state.platform.homeDir);
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateCopy(&instance->state.platform.homeDir);
|
||||
ffStrbufAppendS(&path, "Library/Application Support/Dock/desktoppicture.db");
|
||||
if (ffSettingsGetSQLite3String(instance, path.chars,
|
||||
"SELECT value\n"
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
|
||||
const char* ffDetectWifi(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* result)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY buffer;
|
||||
ffStrbufInit(&buffer);
|
||||
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
||||
|
||||
if(ffProcessAppendStdOut(&buffer, (char* const[]){
|
||||
FF_TERMUX_API_PATH,
|
||||
|
||||
@@ -144,8 +144,7 @@ static const char* detectWifiWithLibnm(const FFinstance* instance, FFlist* resul
|
||||
|
||||
if(instance->config.allowSlowOperations)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY output;
|
||||
ffStrbufInit(&output);
|
||||
FF_STRBUF_AUTO_DESTROY output = ffStrbufCreate();
|
||||
if(!ffProcessAppendStdOut(&output, (char* const[]){
|
||||
"iw",
|
||||
"dev",
|
||||
@@ -216,8 +215,7 @@ static const char* detectWifiWithIoctls(FF_MAYBE_UNUSED const FFinstance* instan
|
||||
if(!infs)
|
||||
return "if_nameindex() failed";
|
||||
|
||||
FFstrbuf path;
|
||||
ffStrbufInit(&path);
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
|
||||
|
||||
for(struct if_nameindex* i = infs; !(i->if_index == 0 && i->if_name == NULL); ++i)
|
||||
{
|
||||
@@ -307,7 +305,6 @@ static const char* detectWifiWithIoctls(FF_MAYBE_UNUSED const FFinstance* instan
|
||||
close(sock);
|
||||
}
|
||||
if_freenameindex(infs);
|
||||
ffStrbufDestroy(&path);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ static bool detectWMThemeFromConfigFile(FFinstance* instance, const char* config
|
||||
{
|
||||
if(!ffParsePropFileConfig(instance, configFile, themeRegex, themeOrError))
|
||||
{
|
||||
ffStrbufInitF(themeOrError, "Config file %s doesn't exist", configFile);
|
||||
ffStrbufAppendF(themeOrError, "Config file %s doesn't exist", configFile);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -131,8 +131,7 @@ static bool detectXFWM4(FFinstance* instance, FFstrbuf* themeOrError)
|
||||
|
||||
static bool detectOpenbox(FFinstance* instance, const FFstrbuf* dePrettyName, FFstrbuf* themeOrError)
|
||||
{
|
||||
FFstrbuf absolutePath;
|
||||
ffStrbufInitA(&absolutePath, 64);
|
||||
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(64);
|
||||
ffStrbufAppend(&absolutePath, &instance->state.platform.homeDir);
|
||||
|
||||
//TODO: use config dirs
|
||||
@@ -150,7 +149,6 @@ static bool detectOpenbox(FFinstance* instance, const FFstrbuf* dePrettyName, FF
|
||||
if(file == NULL)
|
||||
{
|
||||
ffStrbufAppendF(themeOrError, "Couldn't open \"%s\"", absolutePath.chars);
|
||||
ffStrbufDestroy(&absolutePath);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -184,11 +182,9 @@ static bool detectOpenbox(FFinstance* instance, const FFstrbuf* dePrettyName, FF
|
||||
if(themeOrError->length == 0)
|
||||
{
|
||||
ffStrbufAppendF(themeOrError, "Couldn't find theme name in \"%s\"", absolutePath.chars);
|
||||
ffStrbufDestroy(&absolutePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&absolutePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,8 +66,7 @@ bool ffDetectWmTheme(FF_MAYBE_UNUSED FFinstance* instance, FFstrbuf* themeOrErro
|
||||
FF_HKEY_AUTO_DESTROY hKey = NULL;
|
||||
if(ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes", &hKey, NULL))
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY theme;
|
||||
ffStrbufInit(&theme);
|
||||
FF_STRBUF_AUTO_DESTROY theme = ffStrbufCreate();
|
||||
if(ffRegReadStrbuf(hKey, L"CurrentTheme", &theme, NULL))
|
||||
{
|
||||
ffStrbufSubstrBeforeLastC(&theme, '.');
|
||||
|
||||
+1
-4
@@ -612,8 +612,7 @@ static void optionParseConfigFile(FFinstance* instance, FFdata* data, const char
|
||||
|
||||
//Try to load as a relative path
|
||||
|
||||
FFstrbuf absolutePath;
|
||||
ffStrbufInitA(&absolutePath, 128);
|
||||
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(128);
|
||||
|
||||
FF_LIST_FOR_EACH(FFstrbuf, path, instance->state.platform.dataDirs)
|
||||
{
|
||||
@@ -628,8 +627,6 @@ static void optionParseConfigFile(FFinstance* instance, FFdata* data, const char
|
||||
return;
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&absolutePath);
|
||||
|
||||
//File not found
|
||||
|
||||
fprintf(stderr, "Error: couldn't find config: %s\n", value);
|
||||
|
||||
+7
-21
@@ -12,8 +12,7 @@ static FFstrbuf base64Encode(FFstrbuf* in)
|
||||
{
|
||||
const char* base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
FFstrbuf out;
|
||||
ffStrbufInitA(&out, 8 * (1 + in->length / 6));
|
||||
FFstrbuf out = ffStrbufCreateA(8 * (1 + in->length / 6));
|
||||
|
||||
unsigned val = 0;
|
||||
int valb = -6;
|
||||
@@ -41,8 +40,7 @@ static bool printImageIterm(FFinstance* instance)
|
||||
return false;
|
||||
}
|
||||
|
||||
FFstrbuf buf;
|
||||
ffStrbufInit(&buf);
|
||||
FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate();
|
||||
if(!ffAppendFileBuffer(instance->config.logo.source.chars, &buf))
|
||||
{
|
||||
fputs("Logo: Failed to load image file\n", stderr);
|
||||
@@ -51,7 +49,8 @@ static bool printImageIterm(FFinstance* instance)
|
||||
|
||||
ffPrintCharTimes(' ', instance->config.logo.paddingLeft);
|
||||
ffPrintCharTimes('\n', instance->config.logo.paddingTop);
|
||||
FFstrbuf base64 = base64Encode(&buf);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY base64 = base64Encode(&buf);
|
||||
instance->state.logoWidth = instance->config.logo.width + instance->config.logo.paddingLeft + instance->config.logo.paddingRight;
|
||||
instance->state.logoHeight = instance->config.logo.paddingTop + instance->config.logo.height;
|
||||
printf("\033]1337;File=inline=1;width=%u;height=%u;preserveAspectRatio=%u:%s\a\033[9999999D\n\033[%uA",
|
||||
@@ -62,9 +61,6 @@ static bool printImageIterm(FFinstance* instance)
|
||||
(unsigned) instance->state.logoHeight
|
||||
);
|
||||
|
||||
ffStrbufDestroy(&buf);
|
||||
ffStrbufDestroy(&base64);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -289,8 +285,7 @@ static bool printImageKitty(FFinstance* instance, FFLogoRequestData* requestData
|
||||
if(!checkAllocationResult(chars, length))
|
||||
return false;
|
||||
|
||||
FFstrbuf result;
|
||||
ffStrbufInitA(&result, (uint32_t) (length + 1024));
|
||||
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreateA((uint32_t) (length + 1024));
|
||||
|
||||
const char* currentPos = chars;
|
||||
size_t remainingLength = length;
|
||||
@@ -304,7 +299,6 @@ static bool printImageKitty(FFinstance* instance, FFLogoRequestData* requestData
|
||||
|
||||
printImagePixels(instance, requestData, &result, isCompressed ? FF_CACHE_FILE_KITTY_COMPRESSED : FF_CACHE_FILE_KITTY_UNCOMPRESSED);
|
||||
|
||||
ffStrbufDestroy(&result);
|
||||
free(chars);
|
||||
return true;
|
||||
}
|
||||
@@ -532,8 +526,7 @@ static void readCachedStrbuf(FFLogoRequestData* requestData, FFstrbuf* result, c
|
||||
|
||||
static uint32_t readCachedUint32(FFLogoRequestData* requestData, const char* cacheFileName)
|
||||
{
|
||||
FFstrbuf content;
|
||||
ffStrbufInit(&content);
|
||||
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate();
|
||||
readCachedStrbuf(requestData, &content, cacheFileName);
|
||||
|
||||
uint32_t result = 0;
|
||||
@@ -546,27 +539,20 @@ static uint32_t readCachedUint32(FFLogoRequestData* requestData, const char* cac
|
||||
|
||||
memcpy(&result, content.chars, sizeof(result));
|
||||
|
||||
ffStrbufDestroy(&content);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool printCachedChars(FFinstance* instance, FFLogoRequestData* requestData)
|
||||
{
|
||||
FFstrbuf content;
|
||||
ffStrbufInitA(&content, 32768);
|
||||
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreateA(32768);
|
||||
|
||||
if(requestData->type == FF_LOGO_TYPE_IMAGE_CHAFA)
|
||||
readCachedStrbuf(requestData, &content, FF_CACHE_FILE_CHAFA);
|
||||
|
||||
if(content.length == 0)
|
||||
{
|
||||
ffStrbufDestroy(&content);
|
||||
return false;
|
||||
}
|
||||
|
||||
ffLogoPrintChars(instance, content.chars, false);
|
||||
ffStrbufDestroy(&content);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+3
-7
@@ -302,8 +302,7 @@ static void updateLogoPath(FFinstance* instance)
|
||||
if(ffPathExists(options->source.chars, FF_PATHTYPE_FILE))
|
||||
return;
|
||||
|
||||
FFstrbuf fullPath;
|
||||
ffStrbufInit(&fullPath);
|
||||
FF_STRBUF_AUTO_DESTROY fullPath = ffStrbufCreate();
|
||||
|
||||
FF_LIST_FOR_EACH(FFstrbuf, dataDir, instance->state.platform.dataDirs)
|
||||
{
|
||||
@@ -318,20 +317,16 @@ static void updateLogoPath(FFinstance* instance)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&fullPath);
|
||||
}
|
||||
|
||||
static bool logoPrintFileIfExists(FFinstance* instance, bool doColorReplacement, bool raw)
|
||||
{
|
||||
FFLogoOptions* options = &instance->config.logo;
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY content;
|
||||
ffStrbufInit(&content);
|
||||
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate();
|
||||
|
||||
if(!ffAppendFileBuffer(options->source.chars, &content))
|
||||
{
|
||||
ffStrbufDestroy(&content);
|
||||
fputs("Logo: Failed to load file content from logo source\n", stderr);
|
||||
return false;
|
||||
}
|
||||
@@ -341,6 +336,7 @@ static bool logoPrintFileIfExists(FFinstance* instance, bool doColorReplacement,
|
||||
ffLogoPrintCharsRaw(instance, content.chars, content.length);
|
||||
else
|
||||
ffLogoPrintChars(instance, content.chars, doColorReplacement);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,7 @@ static void printBattery(FFinstance* instance, FFBatteryOptions* options, Batter
|
||||
result->status.length > 0 &&
|
||||
ffStrbufIgnCaseCompS(&result->status, "Unknown") != 0;
|
||||
|
||||
FFstrbuf str;
|
||||
ffStrbufInit(&str);
|
||||
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
|
||||
|
||||
if(result->capacity >= 0)
|
||||
{
|
||||
@@ -58,7 +57,6 @@ static void printBattery(FFinstance* instance, FFBatteryOptions* options, Batter
|
||||
}
|
||||
|
||||
ffStrbufPutTo(&str, stdout);
|
||||
ffStrbufDestroy(&str);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -23,8 +23,7 @@ void ffPrintBrightness(FFinstance* instance, FFBrightnessOptions* options)
|
||||
return;
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY key;
|
||||
ffStrbufInit(&key);
|
||||
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
|
||||
|
||||
FF_LIST_FOR_EACH(FFBrightnessResult, item, result)
|
||||
{
|
||||
|
||||
@@ -26,15 +26,12 @@ void ffPrintChassis(FFinstance* instance)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_CHASSIS_MODULE_NAME, 0, &instance->config.chassis.key);
|
||||
|
||||
FFstrbuf output;
|
||||
ffStrbufInitCopy(&output, &result.chassisType);
|
||||
FF_STRBUF_AUTO_DESTROY output = ffStrbufCreateCopy(&result.chassisType);
|
||||
|
||||
if(result.chassisVersion.length > 0)
|
||||
ffStrbufAppendF(&output, " (%s)", result.chassisVersion.chars);
|
||||
|
||||
ffStrbufPutTo(&output, stdout);
|
||||
|
||||
ffStrbufDestroy(&output);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
|
||||
void ffPrintCommand(FFinstance* instance, FFCommandOptions* options)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY result;
|
||||
ffStrbufInit(&result);
|
||||
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate();
|
||||
const char* error = ffProcessAppendStdOut(&result, (char* const[]){
|
||||
options->shell.chars,
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -22,8 +22,7 @@ void ffPrintCPUUsage(FFinstance* instance, FFCPUUsageOptions* options)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_CPUUSAGE_DISPLAY_NAME, 0, &options->moduleArgs.key);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY str;
|
||||
ffStrbufInit(&str);
|
||||
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
|
||||
if(instance->config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
ffAppendPercentBar(instance, &str, (uint8_t)percentage, 0, 5, 8);
|
||||
if(instance->config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT)
|
||||
|
||||
+5
-10
@@ -10,8 +10,7 @@
|
||||
|
||||
static void printDisk(FFinstance* instance, FFDiskOptions* options, const FFDisk* disk)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY key;
|
||||
ffStrbufInit(&key);
|
||||
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
|
||||
|
||||
if(options->moduleArgs.key.length == 0)
|
||||
{
|
||||
@@ -24,12 +23,10 @@ static void printDisk(FFinstance* instance, FFDiskOptions* options, const FFDisk
|
||||
});
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY usedPretty;
|
||||
ffStrbufInit(&usedPretty);
|
||||
FF_STRBUF_AUTO_DESTROY usedPretty = ffStrbufCreate();
|
||||
ffParseSize(disk->bytesUsed, instance->config.binaryPrefixType, &usedPretty);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY totalPretty;
|
||||
ffStrbufInit(&totalPretty);
|
||||
FF_STRBUF_AUTO_DESTROY totalPretty = ffStrbufCreate();
|
||||
ffParseSize(disk->bytesTotal, instance->config.binaryPrefixType, &totalPretty);
|
||||
|
||||
uint8_t bytesPercentage = disk->bytesTotal > 0 ? (uint8_t) (((long double) disk->bytesUsed / (long double) disk->bytesTotal) * 100.0) : 0;
|
||||
@@ -38,8 +35,7 @@ static void printDisk(FFinstance* instance, FFDiskOptions* options, const FFDisk
|
||||
{
|
||||
ffPrintLogoAndKey(instance, key.chars, 0, NULL);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY str;
|
||||
ffStrbufInit(&str);
|
||||
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
|
||||
|
||||
if(disk->bytesTotal > 0)
|
||||
{
|
||||
@@ -109,8 +105,7 @@ static void printMountpoints(FFinstance* instance, FFDiskOptions* options, const
|
||||
const char separator = ':';
|
||||
#endif
|
||||
|
||||
FFstrbuf mountpoints;
|
||||
ffStrbufInitCopy(&mountpoints, &options->folders);
|
||||
FF_STRBUF_AUTO_DESTROY mountpoints = ffStrbufCreateCopy(&options->folders);
|
||||
ffStrbufTrim(&mountpoints, separator);
|
||||
|
||||
uint32_t startIndex = 0;
|
||||
|
||||
@@ -43,8 +43,7 @@ void ffPrintDisplay(FFinstance* instance, FFDisplayOptions* options)
|
||||
return;
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY key;
|
||||
ffStrbufInit(&key);
|
||||
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
|
||||
|
||||
for(uint32_t i = 0; i < dsResult->displays.length; i++)
|
||||
{
|
||||
|
||||
@@ -16,8 +16,7 @@ static void printGPUResult(FFinstance* instance, FFGPUOptions* options, uint8_t
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_GPU_MODULE_NAME, index, &options->moduleArgs.key);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY output;
|
||||
ffStrbufInitA(&output, gpu->vendor.length + 1 + gpu->name.length);
|
||||
FF_STRBUF_AUTO_DESTROY output = ffStrbufCreateA(gpu->vendor.length + 1 + gpu->name.length);
|
||||
|
||||
if(gpu->vendor.length > 0 && !ffStrbufStartsWith(&gpu->name, &gpu->vendor))
|
||||
{
|
||||
|
||||
@@ -25,8 +25,7 @@ void ffPrintHost(FFinstance* instance, FFHostOptions* options)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_HOST_MODULE_NAME, 0, &options->moduleArgs.key);
|
||||
|
||||
FFstrbuf output;
|
||||
ffStrbufInit(&output);
|
||||
FF_STRBUF_AUTO_DESTROY output = ffStrbufCreate();
|
||||
|
||||
if(host->productName.length > 0)
|
||||
ffStrbufAppend(&output, &host->productName);
|
||||
@@ -39,8 +38,6 @@ void ffPrintHost(FFinstance* instance, FFHostOptions* options)
|
||||
}
|
||||
|
||||
ffStrbufPutTo(&output, stdout);
|
||||
|
||||
ffStrbufDestroy(&output);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
+1
-2
@@ -7,8 +7,7 @@
|
||||
|
||||
void ffPrintIcons(FFinstance* instance)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY icons;
|
||||
ffStrbufInit(&icons);
|
||||
FF_STRBUF_AUTO_DESTROY icons = ffStrbufCreate();
|
||||
const char* error = ffDetectIcons(instance, &icons);
|
||||
|
||||
if(error)
|
||||
|
||||
@@ -149,8 +149,7 @@ static const char* printJsonConfig(FFinstance* instance)
|
||||
if (!ffJsonLoadLibrary(instance))
|
||||
return "Failed to load json-c library";
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY content;
|
||||
ffStrbufInit(&content);
|
||||
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate();
|
||||
FF_LIST_FOR_EACH(FFstrbuf, filename, instance->state.platform.configDirs)
|
||||
{
|
||||
uint32_t oldLength = filename->length;
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
void ffPrintLocale(FFinstance* instance, FFLocaleOptions* options)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY locale;
|
||||
ffStrbufInit(&locale);
|
||||
FF_STRBUF_AUTO_DESTROY locale = ffStrbufCreate();
|
||||
|
||||
ffDetectLocale(&locale);
|
||||
if(locale.length == 0)
|
||||
|
||||
@@ -87,8 +87,7 @@ void ffPrintLocalIp(FFinstance* instance, FFLocalIpOptions* options)
|
||||
}
|
||||
else
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY key;
|
||||
ffStrbufInit(&key);
|
||||
FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate();
|
||||
|
||||
FF_LIST_FOR_EACH(FFLocalIpResult, ip, results)
|
||||
{
|
||||
|
||||
+2
-8
@@ -52,8 +52,7 @@ void ffPrintMedia(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf songPretty;
|
||||
ffStrbufInitCopy(&songPretty, &media->song);
|
||||
FF_STRBUF_AUTO_DESTROY songPretty = ffStrbufCreateCopy(&media->song);
|
||||
const char* removeStrings[] = {
|
||||
"(Official Music Video)", "(Official Video)", "(Music Video)", "(Official HD Video)",
|
||||
"[Official Music Video]", "[Official Video]", "[Music Video]", "[Official HD Video]",
|
||||
@@ -72,8 +71,7 @@ void ffPrintMedia(FFinstance* instance)
|
||||
if(instance->config.media.outputFormat.length == 0)
|
||||
{
|
||||
//We don't expose artistPretty to the format, as it might be empty (when the think that the artist is already in the song title)
|
||||
FFstrbuf artistPretty;
|
||||
ffStrbufInitCopy(&artistPretty, &media->artist);
|
||||
FF_STRBUF_AUTO_DESTROY artistPretty = ffStrbufCreateCopy(&media->artist);
|
||||
ffStrbufRemoveIgnCaseEndS(&artistPretty, " - Topic");
|
||||
ffStrbufRemoveIgnCaseEndS(&artistPretty, "VEVO");
|
||||
ffStrbufTrimRight(&artistPretty, ' ');
|
||||
@@ -93,8 +91,6 @@ void ffPrintMedia(FFinstance* instance)
|
||||
ffStrbufAppendF(&songPretty, " (%s)", media->status.chars);
|
||||
|
||||
ffStrbufPutTo(&songPretty, stdout);
|
||||
|
||||
ffStrbufDestroy(&artistPretty);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -106,6 +102,4 @@ void ffPrintMedia(FFinstance* instance)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &media->status}
|
||||
});
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&songPretty);
|
||||
}
|
||||
|
||||
@@ -18,12 +18,10 @@ void ffPrintMemory(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY usedPretty;
|
||||
ffStrbufInit(&usedPretty);
|
||||
FF_STRBUF_AUTO_DESTROY usedPretty = ffStrbufCreate();
|
||||
ffParseSize(storage.bytesUsed, instance->config.binaryPrefixType, &usedPretty);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY totalPretty;
|
||||
ffStrbufInit(&totalPretty);
|
||||
FF_STRBUF_AUTO_DESTROY totalPretty = ffStrbufCreate();
|
||||
ffParseSize(storage.bytesTotal, instance->config.binaryPrefixType, &totalPretty);
|
||||
|
||||
uint8_t percentage = storage.bytesTotal == 0
|
||||
@@ -37,8 +35,7 @@ void ffPrintMemory(FFinstance* instance)
|
||||
puts("Disabled");
|
||||
else
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY str;
|
||||
ffStrbufInit(&str);
|
||||
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
|
||||
|
||||
if(instance->config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
{
|
||||
|
||||
+1
-2
@@ -107,8 +107,7 @@ void ffPrintOS(FFinstance* instance, FFOSOptions* options)
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY result;
|
||||
ffStrbufInit(&result);
|
||||
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate();
|
||||
|
||||
if(ffStrbufIgnCaseCompS(&os->id, "nixos") == 0)
|
||||
buildOutputNixOS(instance, os, &result);
|
||||
|
||||
@@ -17,8 +17,7 @@ void ffPrintPlayer(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf playerPretty;
|
||||
ffStrbufInit(&playerPretty);
|
||||
FF_STRBUF_AUTO_DESTROY playerPretty = ffStrbufCreate();
|
||||
|
||||
//If we are on a website, prepend the website name
|
||||
if(
|
||||
@@ -70,6 +69,4 @@ void ffPrintPlayer(FFinstance* instance)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &media->url}
|
||||
});
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&playerPretty);
|
||||
}
|
||||
|
||||
+3
-12
@@ -14,13 +14,11 @@ void ffPreparePublicIp(FFinstance* instance)
|
||||
status = ffNetworkingSendHttpRequest(&state, "ipinfo.io", "/ip", NULL);
|
||||
else
|
||||
{
|
||||
FFstrbuf host;
|
||||
ffStrbufInitCopy(&host, &instance->config.publicIpUrl);
|
||||
FF_STRBUF_AUTO_DESTROY host = ffStrbufCreateCopy(&instance->config.publicIpUrl);
|
||||
ffStrbufSubstrAfterFirstS(&host, "://");
|
||||
uint32_t pathStartIndex = ffStrbufFirstIndexC(&host, '/');
|
||||
|
||||
FFstrbuf path;
|
||||
ffStrbufInit(&path);
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
|
||||
if(pathStartIndex != host.length)
|
||||
{
|
||||
ffStrbufAppendNS(&path, pathStartIndex, host.chars + (host.length - pathStartIndex));
|
||||
@@ -29,9 +27,6 @@ void ffPreparePublicIp(FFinstance* instance)
|
||||
}
|
||||
|
||||
status = ffNetworkingSendHttpRequest(&state, host.chars, path.length == 0 ? "/" : path.chars, NULL);
|
||||
|
||||
ffStrbufDestroy(&path);
|
||||
ffStrbufDestroy(&host);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,15 +41,13 @@ void ffPrintPublicIp(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf result;
|
||||
ffStrbufInitA(&result, 4096);
|
||||
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreateA(4096);
|
||||
bool success = ffNetworkingRecvHttpResponse(&state, &result, instance->config.publicIpTimeout);
|
||||
if(success) ffStrbufSubstrAfterFirstS(&result, "\r\n\r\n");
|
||||
|
||||
if(!success || result.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIP, "Failed to receive the server response");
|
||||
ffStrbufDestroy(&result);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -69,6 +62,4 @@ void ffPrintPublicIp(FFinstance* instance)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result}
|
||||
});
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&result);
|
||||
}
|
||||
|
||||
+3
-6
@@ -18,12 +18,10 @@ void ffPrintSwap(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY usedPretty;
|
||||
ffStrbufInit(&usedPretty);
|
||||
FF_STRBUF_AUTO_DESTROY usedPretty = ffStrbufCreate();
|
||||
ffParseSize(storage.bytesUsed, instance->config.binaryPrefixType, &usedPretty);
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY totalPretty;
|
||||
ffStrbufInit(&totalPretty);
|
||||
FF_STRBUF_AUTO_DESTROY totalPretty = ffStrbufCreate();
|
||||
ffParseSize(storage.bytesTotal, instance->config.binaryPrefixType, &totalPretty);
|
||||
|
||||
uint8_t percentage = storage.bytesTotal == 0
|
||||
@@ -37,8 +35,7 @@ void ffPrintSwap(FFinstance* instance)
|
||||
puts("Disabled");
|
||||
else
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY str;
|
||||
ffStrbufInit(&str);
|
||||
FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate();
|
||||
|
||||
if(instance->config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT)
|
||||
{
|
||||
|
||||
+3
-11
@@ -7,24 +7,20 @@
|
||||
|
||||
void ffPrintUsers(FFinstance* instance)
|
||||
{
|
||||
FFlist users;
|
||||
FF_LIST_AUTO_DESTROY users;
|
||||
ffListInit(&users, sizeof(FFstrbuf));
|
||||
|
||||
FFstrbuf error;
|
||||
ffStrbufInit(&error);
|
||||
FF_STRBUF_AUTO_DESTROY error = ffStrbufCreate();
|
||||
|
||||
ffDetectUsers(&users, &error);
|
||||
|
||||
if(error.length > 0)
|
||||
{
|
||||
ffPrintError(instance, FF_USERS_MODULE_NAME, 0, &instance->config.users, "%*s", error.length, error.chars);
|
||||
ffListDestroy(&users);
|
||||
ffStrbufDestroy(&error);
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf result;
|
||||
ffStrbufInit(&result);
|
||||
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate();
|
||||
for(uint32_t i = 0; i < users.length; ++i)
|
||||
{
|
||||
if(i > 0)
|
||||
@@ -34,8 +30,6 @@ void ffPrintUsers(FFinstance* instance)
|
||||
ffStrbufDestroy(user);
|
||||
}
|
||||
|
||||
ffListDestroy(&users);
|
||||
|
||||
if(instance->config.users.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_USERS_MODULE_NAME, 0, &instance->config.users.key);
|
||||
@@ -47,6 +41,4 @@ void ffPrintUsers(FFinstance* instance)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result},
|
||||
});
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&result);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
void ffPrintWallpaper(FFinstance* instance)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY wallpaper;
|
||||
ffStrbufInit(&wallpaper);
|
||||
FF_STRBUF_AUTO_DESTROY wallpaper = ffStrbufCreate();
|
||||
const char* error = ffDetectWallpaper(instance, &wallpaper);
|
||||
|
||||
if(error)
|
||||
|
||||
@@ -10,11 +10,9 @@ static int status = -1;
|
||||
|
||||
void ffPrepareWeather(FFinstance* instance)
|
||||
{
|
||||
FFstrbuf path;
|
||||
ffStrbufInitS(&path, "/?format=");
|
||||
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/?format=");
|
||||
ffStrbufAppend(&path, &instance->config.weatherOutputFormat);
|
||||
status = ffNetworkingSendHttpRequest(&state, "wttr.in", path.chars, "User-Agent: curl/0.0.0\r\n");
|
||||
ffStrbufDestroy(&path);
|
||||
}
|
||||
|
||||
void ffPrintWeather(FFinstance* instance)
|
||||
@@ -28,15 +26,13 @@ void ffPrintWeather(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf result;
|
||||
ffStrbufInitA(&result, 4096);
|
||||
FF_STRBUF_AUTO_DESTROY result = ffStrbufCreateA(4096);
|
||||
bool success = ffNetworkingRecvHttpResponse(&state, &result, instance->config.weatherTimeout);
|
||||
if (success) ffStrbufSubstrAfterFirstS(&result, "\r\n\r\n");
|
||||
|
||||
if(!success || result.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_WEATHER_MODULE_NAME, 0, &instance->config.weather, "Failed to receive the server response");
|
||||
ffStrbufDestroy(&result);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,6 +47,4 @@ void ffPrintWeather(FFinstance* instance)
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result}
|
||||
});
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&result);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
void ffPrintWMTheme(FFinstance* instance)
|
||||
{
|
||||
FFstrbuf themeOrError;
|
||||
ffStrbufInit(&themeOrError);
|
||||
FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate();
|
||||
if(ffDetectWmTheme(instance, &themeOrError))
|
||||
{
|
||||
if(instance->config.wmTheme.outputFormat.length == 0)
|
||||
@@ -27,5 +26,4 @@ void ffPrintWMTheme(FFinstance* instance)
|
||||
{
|
||||
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "%*s", themeOrError.length, themeOrError.chars);
|
||||
}
|
||||
ffStrbufDestroy(&themeOrError);
|
||||
}
|
||||
|
||||
@@ -35,16 +35,6 @@ void ffStrbufInitMove(FFstrbuf* strbuf, FFstrbuf* src)
|
||||
ffStrbufInit(strbuf);
|
||||
}
|
||||
|
||||
void ffStrbufInitF(FFstrbuf* strbuf, const char* format, ...)
|
||||
{
|
||||
assert(format != NULL);
|
||||
|
||||
va_list arguments;
|
||||
va_start(arguments, format);
|
||||
ffStrbufInitVF(strbuf, format, arguments);
|
||||
va_end(arguments);
|
||||
}
|
||||
|
||||
void ffStrbufInitVF(FFstrbuf* strbuf, const char* format, va_list arguments)
|
||||
{
|
||||
assert(format != NULL);
|
||||
@@ -458,13 +448,3 @@ uint16_t ffStrbufToUInt16(const FFstrbuf* strbuf, uint16_t defaultValue)
|
||||
unsigned long result = strtoul(strbuf->chars, &str_end, 10);
|
||||
return str_end == strbuf->chars || result > UINT16_MAX ? defaultValue : (uint16_t)result;
|
||||
}
|
||||
|
||||
void ffStrbufDestroy(FFstrbuf* strbuf)
|
||||
{
|
||||
if(strbuf->allocated == 0) return;
|
||||
|
||||
//Avoid free-after-use. These 3 assignments are cheap so don't remove them
|
||||
strbuf->allocated = strbuf->length = 0;
|
||||
free(strbuf->chars);
|
||||
strbuf->chars = CHAR_NULL_PTR;
|
||||
}
|
||||
|
||||
+83
-4
@@ -29,9 +29,8 @@ typedef struct FFstrbuf
|
||||
} FFstrbuf;
|
||||
|
||||
void ffStrbufInitA(FFstrbuf* strbuf, uint32_t allocate);
|
||||
void ffStrbufInitCopy(FFstrbuf* strbuf, const FFstrbuf* src);
|
||||
void ffStrbufInitCopy(FFstrbuf* restrict strbuf, const FFstrbuf* restrict src);
|
||||
void ffStrbufInitMove(FFstrbuf* strbuf, FFstrbuf* src);
|
||||
void ffStrbufInitF(FFstrbuf* strbuf, const char* format, ...);
|
||||
void ffStrbufInitVF(FFstrbuf* strbuf, const char* format, va_list arguments);
|
||||
|
||||
void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free);
|
||||
@@ -91,7 +90,55 @@ void ffStrbufPutTo(const FFstrbuf* strbuf, FILE* file);
|
||||
FF_C_NODISCARD double ffStrbufToDouble(const FFstrbuf* strbuf);
|
||||
FF_C_NODISCARD uint16_t ffStrbufToUInt16(const FFstrbuf* strbuf, uint16_t defaultValue);
|
||||
|
||||
void ffStrbufDestroy(FFstrbuf* strbuf);
|
||||
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateA(uint32_t allocate)
|
||||
{
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInitA(&strbuf, allocate);
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateCopy(const FFstrbuf* src)
|
||||
{
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInitCopy(&strbuf, src);
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateMove(FFstrbuf* src)
|
||||
{
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInitMove(&strbuf, src);
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateVF(const char* format, va_list arguments)
|
||||
{
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInitVF(&strbuf, format, arguments);
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
FF_C_PRINTF(2, 3)
|
||||
static inline void ffStrbufInitF(FFstrbuf* strbuf, const char* format, ...)
|
||||
{
|
||||
va_list arguments;
|
||||
va_start(arguments, format);
|
||||
ffStrbufInitVF(strbuf, format, arguments);
|
||||
va_end(arguments);
|
||||
}
|
||||
|
||||
FF_C_PRINTF(1, 2)
|
||||
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateF(const char* format, ...)
|
||||
{
|
||||
FFstrbuf strbuf;
|
||||
|
||||
va_list arguments;
|
||||
va_start(arguments, format);
|
||||
ffStrbufInitVF(&strbuf, format, arguments);
|
||||
va_end(arguments);
|
||||
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
static inline void ffStrbufRecalculateLength(FFstrbuf* strbuf)
|
||||
{
|
||||
@@ -121,19 +168,40 @@ static inline void ffStrbufInit(FFstrbuf* strbuf)
|
||||
strbuf->chars = CHAR_NULL_PTR;
|
||||
}
|
||||
|
||||
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreate()
|
||||
{
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInit(&strbuf);
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
static inline void ffStrbufInitNS(FFstrbuf* strbuf, uint32_t length, const char* str)
|
||||
{
|
||||
ffStrbufInit(strbuf);
|
||||
ffStrbufAppendNS(strbuf, length, str);
|
||||
}
|
||||
|
||||
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateNS(uint32_t length, const char* str)
|
||||
{
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInitNS(&strbuf, length, str);
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
static inline void ffStrbufInitS(FFstrbuf* strbuf, const char* str)
|
||||
{
|
||||
ffStrbufInit(strbuf);
|
||||
ffStrbufAppendS(strbuf, str);
|
||||
}
|
||||
|
||||
static inline void ffStrbufAppend(FFstrbuf* strbuf, const FFstrbuf* value)
|
||||
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateS(const char* str)
|
||||
{
|
||||
FFstrbuf strbuf;
|
||||
ffStrbufInitS(&strbuf, str);
|
||||
return strbuf;
|
||||
}
|
||||
|
||||
static inline void ffStrbufAppend(FFstrbuf* restrict strbuf, const FFstrbuf* restrict value)
|
||||
{
|
||||
assert(value != strbuf);
|
||||
if(value == NULL)
|
||||
@@ -323,6 +391,17 @@ static inline FF_C_NODISCARD bool ffStrbufEndsWithIgnCase(const FFstrbuf* strbuf
|
||||
return ffStrbufEndsWithIgnCaseNS(strbuf, end->length, end->chars);
|
||||
}
|
||||
|
||||
static inline void ffStrbufDestroy(FFstrbuf* strbuf)
|
||||
{
|
||||
if(strbuf->allocated == 0) return;
|
||||
|
||||
extern char* CHAR_NULL_PTR;
|
||||
//Avoid free-after-use. These 3 assignments are cheap so don't remove them
|
||||
strbuf->allocated = strbuf->length = 0;
|
||||
free(strbuf->chars);
|
||||
strbuf->chars = CHAR_NULL_PTR;
|
||||
}
|
||||
|
||||
#define FF_STRBUF_AUTO_DESTROY FFstrbuf __attribute__((__cleanup__(ffStrbufDestroy)))
|
||||
|
||||
#endif
|
||||
|
||||
+7
-2
@@ -28,12 +28,12 @@ int main(void)
|
||||
FFstrbuf strbuf;
|
||||
|
||||
//destroy 0
|
||||
ffStrbufInitA(&strbuf, 0);
|
||||
ffStrbufInit(&strbuf);
|
||||
ffStrbufDestroy(&strbuf);
|
||||
|
||||
//initA
|
||||
|
||||
ffStrbufInitA(&strbuf, 0);
|
||||
ffStrbufInit(&strbuf);
|
||||
|
||||
VERIFY(strbuf.chars[0] == 0);
|
||||
VERIFY(strbuf.allocated == 0);
|
||||
@@ -216,6 +216,11 @@ int main(void)
|
||||
|
||||
ffStrbufDestroy(&strbuf);
|
||||
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY testCreate = ffStrbufCreateS("TEST");
|
||||
VERIFY(ffStrbufEqualS(&testCreate, "TEST"));
|
||||
}
|
||||
|
||||
//Success
|
||||
puts("\033[32mAll tests passed!"FASTFETCH_TEXT_MODIFIER_RESET);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user