Skip to content

Commit 6cdb694

Browse files
Do simple \ replacement in user strings
1 parent 8301628 commit 6cdb694

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/common/printing.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod
3030
ffParseFormatString(&key, customKeyFormat, 1, (FFformatarg[]){
3131
{FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex}
3232
});
33-
ffStrbufWriteTo(&key, stdout);
33+
ffPrintUserString(key.chars);
3434
ffStrbufDestroy(&key);
3535
}
3636

@@ -53,7 +53,8 @@ void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t m
5353
if(buffer.length > 0)
5454
{
5555
ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat);
56-
ffStrbufPutTo(&buffer, stdout);
56+
ffPrintUserString(buffer.chars);
57+
putchar('\n');
5758
}
5859

5960
ffStrbufDestroy(&buffer);
@@ -129,3 +130,34 @@ void ffPrintCharTimes(char c, uint32_t times)
129130
for(uint32_t i = 0; i < times; i++)
130131
putchar(c);
131132
}
133+
134+
void ffPrintUserString(const char* value)
135+
{
136+
while(*value != '\0')
137+
{
138+
if(*value != '\\')
139+
{
140+
putchar(*value);
141+
++value;
142+
continue;
143+
}
144+
145+
++value;
146+
147+
if(*value == 'n')
148+
putchar('\n');
149+
else if(*value == 't')
150+
putchar('\t');
151+
else if(*value == 'e')
152+
putchar('\e');
153+
else if(*value == '\\')
154+
putchar('\\');
155+
else
156+
{
157+
putchar('\\');
158+
putchar(*value);
159+
}
160+
161+
++value;
162+
}
163+
}

src/common/printing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t mo
1313
void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...);
1414
void ffPrintColor(const FFstrbuf* colorValue);
1515
void ffPrintCharTimes(char c, uint32_t times);
16+
void ffPrintUserString(const char* str);
1617

1718
#endif

src/modules/custom.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
void ffPrintCustom(FFinstance* instance, const char* key, const char* value)
55
{
66
ffPrintLogoAndKey(instance, key, 0, NULL);
7-
puts(value);
7+
ffPrintUserString(value);
8+
putchar('\n');
89
}

0 commit comments

Comments
 (0)