From a7784f5a8853b2b25041d250e39b5c3f4a69b6cf Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Wed, 5 May 2021 21:12:42 +0200 Subject: [PATCH] better os output --- src/modules/os.c | 81 +++++++++++++++++++++++---------------------- src/util/FFstrbuf.c | 5 +++ src/util/FFstrbuf.h | 1 + 3 files changed, 47 insertions(+), 40 deletions(-) diff --git a/src/modules/os.c b/src/modules/os.c index f85a72d4b..ebf663088 100644 --- a/src/modules/os.c +++ b/src/modules/os.c @@ -115,51 +115,52 @@ void ffPrintOS(FFinstance* instance) FF_STRBUF_CREATE(os); - if(result->prettyName.length > 0) - { + //Name + if(result->name.length > 0) + ffStrbufAppend(&os, &result->name); + else if(result->id.length > 0) + ffStrbufAppend(&os, &result->id); + else if(result->prettyName.length > 0) ffStrbufAppend(&os, &result->prettyName); - } - else if(result->name.length == 0 && result->id.length == 0) - { - ffStrbufAppend(&os, &result->systemName); - } else + ffStrbufAppend(&os, &result->systemName); + + //Version + if(result->versionID.length > 0) { - if(result->name.length > 0) - ffStrbufAppend(&os, &result->name); - else - ffStrbufAppend(&os, &result->id); - - if(result->version.length > 0) - { - ffStrbufAppendC(&os, ' '); - ffStrbufAppend(&os, &result->version); - } - else - { - if(result->versionID.length > 0) - { - ffStrbufAppendC(&os, ' '); - ffStrbufAppend(&os, &result->versionID); - } - - if(result->variant.length > 0) - { - ffStrbufAppendS(&os, " ("); - ffStrbufAppend(&os, &result->variant); - ffStrbufAppendC(&os, ')'); - } - else if(result->variantID.length > 0) - { - ffStrbufAppendS(&os, " ("); - ffStrbufAppend(&os, &result->variantID); - ffStrbufAppendC(&os, ')'); - } - } + ffStrbufAppendC(&os, ' '); + ffStrbufAppend(&os, &result->versionID); + } + else if(result->version.length > 0) + { + ffStrbufAppendC(&os, ' '); + ffStrbufAppend(&os, &result->version); } - ffStrbufAppendC(&os, ' '); - ffStrbufAppendS(&os, instance->state.utsname.machine); + //Codename + if(result->codename.length > 0) + { + ffStrbufAppendC(&os, ' '); + ffStrbufAppend(&os, &result->codename); + } + + //Variant + if(result->variant.length > 0) + { + ffStrbufAppendS(&os, " ["); + ffStrbufAppend(&os, &result->variant); + ffStrbufAppendC(&os, ']'); + } + else if(result->variantID.length > 0) + { + ffStrbufAppendS(&os, " ["); + ffStrbufAppend(&os, &result->variantID); + ffStrbufAppendC(&os, ']'); + } + + ffStrbufAppendS(&os, " ("); + ffStrbufAppend(&os, &result->architecture); + ffStrbufAppendC(&os, ')'); ffPrintAndSaveToCache(instance, FF_OS_MODULE_NAME, &instance->config.osKey, &os, &instance->config.osFormat, FF_OS_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->systemName}, diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index f54b2da53..2bb1420a8 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -397,6 +397,11 @@ uint32_t ffStrbufFirstIndexAfterS(const FFstrbuf* strbuf, uint32_t start, const return strbuf->length; } +uint32_t ffStrbufFirstIndexS(const FFstrbuf* strbuf, const char* str) +{ + return ffStrbufFirstIndexAfterS(strbuf, 0, str); +} + uint32_t ffStrbufLastIndexC(const FFstrbuf* strbuf, const char c) { //We need to loop one higher than the actual index, because uint32_t is guranteed to be >= 0, so this statement would always be true diff --git a/src/util/FFstrbuf.h b/src/util/FFstrbuf.h index 23bceec88..2bf6af8ea 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -75,6 +75,7 @@ void ffStrbufRemoveStrings(FFstrbuf* strbuf, uint32_t numStrings, ...); uint32_t ffStrbufFirstIndexAfterC(const FFstrbuf* strbuf, uint32_t start, const char c); uint32_t ffStrbufFirstIndexC(const FFstrbuf* strbuf, const char c); uint32_t ffStrbufFirstIndexAfterS(const FFstrbuf* strbuf, uint32_t start, const char* str); +uint32_t ffStrbufFirstIndexS(const FFstrbuf* strbuf, const char* str); uint32_t ffStrbufLastIndexC(const FFstrbuf* strbuf, const char c); void ffStrbufSubstrBefore(FFstrbuf* strbuf, uint32_t index);