From 451848f6fd0ea4327c8f11ceddd221aae76fa33f Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sat, 12 Feb 2022 22:30:57 +0100 Subject: [PATCH] Small improvements to code quality --- src/data/config.txt | 2 +- src/detection/plasma.c | 2 +- src/fastfetch.c | 25 +++++++++++-------------- src/modules/battery.c | 1 - src/modules/gpu.c | 4 ++-- src/modules/wm.c | 26 ++++++++------------------ src/util/FFstrbuf.c | 2 +- 7 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/data/config.txt b/src/data/config.txt index 81d2dc9d7..2e1fa7c18 100644 --- a/src/data/config.txt +++ b/src/data/config.txt @@ -131,7 +131,7 @@ # Should be a valid path to an existing file. # Note that you might need to run fastfetch with --recache once for it to take affect. # Default is /etc/os-release. ---os-file /etc/os-release +#--os-file /etc/os-release # Key options: # Sets the displayed key of a module diff --git a/src/detection/plasma.c b/src/detection/plasma.c index 4ceb6c0c4..e339fe588 100644 --- a/src/detection/plasma.c +++ b/src/detection/plasma.c @@ -27,7 +27,7 @@ static bool detectFromConfigFile(const FFstrbuf* filename, FFPlasmaResult* resul if(line[0] == '[') { char categoryName[32]; - sscanf(line, "[%32[^]]", categoryName); + sscanf(line, "[%31[^]]", categoryName); if(strcasecmp(categoryName, "General") == 0) category = PLASMA_CATEGORY_GENERAL; diff --git a/src/fastfetch.c b/src/fastfetch.c index e368e50b5..51d12da47 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -927,23 +927,20 @@ static void parseDefaultConfigFile(FFinstance* instance, FFdata* data) ffStrbufAppendS(filename, "config.conf"); - if(access(filename->chars, F_OK) != 0) + FILE* file = fopen(filename->chars, "r"); + if(file != NULL) { - FILE* file = fopen(filename->chars, "w"); - if(file != NULL) - { - fputs(FASTFETCH_DATATEXT_CONFIG, file); - fclose(file); - } + parseConfigFile(instance, data, file); + fclose(file); + ffStrbufSubstrBefore(filename, filenameLength); + return; } - else + + file = fopen(filename->chars, "w"); + if(file != NULL) { - FILE* file = fopen(filename->chars, "r"); - if(file != NULL) - { - parseConfigFile(instance, data, file); - fclose(file); - } + fputs(FASTFETCH_DATATEXT_CONFIG, file); + fclose(file); } ffStrbufSubstrBefore(filename, filenameLength); diff --git a/src/modules/battery.c b/src/modules/battery.c index 1bb57cd3b..1b7847d9c 100644 --- a/src/modules/battery.c +++ b/src/modules/battery.c @@ -87,7 +87,6 @@ static void printBattery(FFinstance* instance, const BatteryResult* result, uint { if(instance->config.batteryFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.batteryKey); bool showStatus = diff --git a/src/modules/gpu.c b/src/modules/gpu.c index 6478113c8..f60501c2b 100644 --- a/src/modules/gpu.c +++ b/src/modules/gpu.c @@ -197,9 +197,9 @@ static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, ffStrbufSubstrAfterFirstC(&namePretty, '['); FFstrbuf gpu; - ffStrbufInitA(&gpu, result->vendor.length + namePretty.length); + ffStrbufInitA(&gpu, result->vendor.length + 1 + namePretty.length); - if(*vendorPretty != '\0') + if(ffStrSet(vendorPretty)) { ffStrbufAppendS(&gpu, vendorPretty); ffStrbufAppendC(&gpu, ' '); diff --git a/src/modules/wm.c b/src/modules/wm.c index f3b06e7d7..925102e50 100644 --- a/src/modules/wm.c +++ b/src/modules/wm.c @@ -22,26 +22,16 @@ void ffPrintWM(FFinstance* instance) { ffPrintLogoAndKey(instance, FF_WM_MODULE_NAME, 0, &instance->config.wmKey); - if(result->wmPrettyName.length == 0 && result->wmProcessName.length == 0) - { - ffStrbufPutTo(&result->wmProtocolName, stdout); - } - else - { - if(result->wmPrettyName.length > 0) - ffStrbufWriteTo(&result->wmPrettyName, stdout); - else - ffStrbufWriteTo(&result->wmProcessName, stdout); + ffStrbufWriteTo(&result->wmPrettyName, stdout); - if(result->wmProtocolName.length > 0) - { - fputs(" (", stdout); - ffStrbufWriteTo(&result->wmProtocolName, stdout); - putchar(')'); - } - - putchar('\n'); + if(result->wmProtocolName.length > 0) + { + fputs(" (", stdout); + ffStrbufWriteTo(&result->wmProtocolName, stdout); + putchar(')'); } + + putchar('\n'); } else { diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index 93d8f3318..3ef43e2e7 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -190,7 +190,7 @@ void ffStrbufAppendVF(FFstrbuf* strbuf, const char* format, va_list arguments) va_end(copy); - if(written <= 0) + if(written == 0) return; strbuf->length += written;