From 0d3500c66f2fc9fd6310685e4e70d1cfbc74af21 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sun, 21 Mar 2021 11:18:06 +0100 Subject: [PATCH] command help --- completions/bash | 1 + src/common.c | 44 +++------- src/fastfetch.c | 202 +++++++++++-------------------------------- src/modules/kernel.c | 1 + src/modules/locale.c | 46 +++++----- 5 files changed, 89 insertions(+), 205 deletions(-) diff --git a/completions/bash b/completions/bash index 15df090a8..48cc65799 100644 --- a/completions/bash +++ b/completions/bash @@ -4,6 +4,7 @@ __fastfetch_complete_help() { local __ff_helps=( "color" + "format" "os-format" "host-format" "kernel-format" diff --git a/src/common.c b/src/common.c index 5d2a7f2c3..1ac6877e6 100644 --- a/src/common.c +++ b/src/common.c @@ -370,33 +370,20 @@ void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs FFstrbuf argnumstr; ffStrbufInit(&argnumstr); - while(true) - { + while(formatstr->chars[i] != '}' && formatstr->chars[i] != '\0') ffStrbufAppendC(&argnumstr, formatstr->chars[i++]); - if(formatstr->chars[i] == '}') - break; - - if(formatstr->chars[i] == '\0') - { - fprintf(stderr, "Error: format string \"%s\" ends with an uncomplete placeholder %s\n", formatstr->chars, argnumstr.chars); - ffStrbufDestroy(buffer); - exit(802); - } - } - - if(ffStrbufGetC(&argnumstr, 0) == '-') - { - fprintf(stderr, "Error: format string \"%s\" placeholder value \"%s\" is negative\n", formatstr->chars, argnumstr.chars); - ffStrbufDestroy(buffer); - exit(803); - } - - if(sscanf(argnumstr.chars, "%u", &argIndex) != 1) - { - fprintf(stderr, "Error: format string \"%s\" placeholder value \"%s\" could not be parsed to uint32_t\n", formatstr->chars, argnumstr.chars); - ffStrbufDestroy(buffer); - exit(804); + if( + ffStrbufGetC(&argnumstr, 0) == '-' || + sscanf(argnumstr.chars, "%u", &argIndex) != 1 || + argIndex > numArgs + ) { + ffStrbufAppendC(buffer, '{'); + ffStrbufAppend(buffer, &argnumstr); + if(formatstr->chars[i] != '\0') + ffStrbufAppendC(buffer, '}'); + ffStrbufDestroy(&argnumstr); + continue; } ffStrbufDestroy(&argnumstr); @@ -405,13 +392,6 @@ void ffParseFormatString(FFstrbuf* buffer, FFstrbuf* formatstr, uint32_t numArgs if(argIndex == 0) argIndex = 1; - if(argIndex > numArgs) - { - fprintf(stderr, "Error: format string \"%s\" placeholder {%u} wants higher argument than number of arguments (%u)\n", formatstr->chars, argIndex, numArgs); - ffStrbufDestroy(buffer); - exit(805); - } - FFformatarg arg = arguments[argIndex - 1]; if(arg.type == FF_FORMAT_ARG_TYPE_INT) diff --git a/src/fastfetch.c b/src/fastfetch.c index 18665b797..652adf4fd 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -80,8 +80,8 @@ static inline void printHelp() "\n" "Library optins: Set the path of a library to load\n" " --lib-PCI \n" - " --lib-X11 :\n" - " --lib-Xrandr :\n" + " --lib-X11 \n" + " --lib-Xrandr \n" "\n" "If an value starts with an ?, it is optional. \"true\" will be used if not set.\n" "An (+) at the end indicates that more help can be printed with --help