From 6cdb694e3385cda962951a179056fdc20b341d26 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 18 Aug 2022 11:36:30 +0200 Subject: [PATCH] Do simple \ replacement in user strings --- src/common/printing.c | 36 ++++++++++++++++++++++++++++++++++-- src/common/printing.h | 1 + src/modules/custom.c | 3 ++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/common/printing.c b/src/common/printing.c index 7ce26e93b..552328d53 100644 --- a/src/common/printing.c +++ b/src/common/printing.c @@ -30,7 +30,7 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod ffParseFormatString(&key, customKeyFormat, 1, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex} }); - ffStrbufWriteTo(&key, stdout); + ffPrintUserString(key.chars); ffStrbufDestroy(&key); } @@ -53,7 +53,8 @@ void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t m if(buffer.length > 0) { ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat); - ffStrbufPutTo(&buffer, stdout); + ffPrintUserString(buffer.chars); + putchar('\n'); } ffStrbufDestroy(&buffer); @@ -129,3 +130,34 @@ void ffPrintCharTimes(char c, uint32_t times) for(uint32_t i = 0; i < times; i++) putchar(c); } + +void ffPrintUserString(const char* value) +{ + while(*value != '\0') + { + if(*value != '\\') + { + putchar(*value); + ++value; + continue; + } + + ++value; + + if(*value == 'n') + putchar('\n'); + else if(*value == 't') + putchar('\t'); + else if(*value == 'e') + putchar('\e'); + else if(*value == '\\') + putchar('\\'); + else + { + putchar('\\'); + putchar(*value); + } + + ++value; + } +} diff --git a/src/common/printing.h b/src/common/printing.h index 186716751..7eb6ffae6 100644 --- a/src/common/printing.h +++ b/src/common/printing.h @@ -13,5 +13,6 @@ void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t mo void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...); void ffPrintColor(const FFstrbuf* colorValue); void ffPrintCharTimes(char c, uint32_t times); +void ffPrintUserString(const char* str); #endif diff --git a/src/modules/custom.c b/src/modules/custom.c index 50b96607c..31eb597a8 100644 --- a/src/modules/custom.c +++ b/src/modules/custom.c @@ -4,5 +4,6 @@ void ffPrintCustom(FFinstance* instance, const char* key, const char* value) { ffPrintLogoAndKey(instance, key, 0, NULL); - puts(value); + ffPrintUserString(value); + putchar('\n'); }