🩹 Fix FSTR / PSTR usage

This commit is contained in:
Scott Lahteine
2022-03-12 17:12:21 -06:00
committed by Scott Lahteine
parent c49f26a7ae
commit 4028c1cfc7
12 changed files with 43 additions and 45 deletions

View File

@ -421,7 +421,7 @@ bool UIFlashStorage::is_present = false;
uint32_t addr;
uint8_t buff[write_page_size];
strcpy_P( (char*) buff, (const char*) filename);
strcpy_P((char*)buff, FTOP(filename));
MediaFileReader reader;
if (!reader.open((char*) buff)) {

View File

@ -106,8 +106,8 @@ bool BioPrintingDialogBox::onTouchEnd(uint8_t tag) {
}
void BioPrintingDialogBox::setStatusMessage(FSTR_P message) {
char buff[strlen_P((const char*)message)+1];
strcpy_P(buff, (const char*) message);
char buff[strlen_P(FTOP(message)) + 1];
strcpy_P(buff, FTOP(message));
setStatusMessage(buff);
}

View File

@ -242,10 +242,10 @@ class CommandProcessor : public CLCD::CommandFifo {
}
CommandProcessor& toggle2(int16_t x, int16_t y, int16_t w, int16_t h, FSTR_P no, FSTR_P yes, bool state, uint16_t options = FTDI::OPT_3D) {
char text[strlen_P((const char *)no) + strlen_P((const char *)yes) + 2];
strcpy_P(text, (const char *)no);
char text[strlen_P(FTOP(no)) + strlen_P(FTOP(yes)) + 2];
strcpy_P(text, FTOP(no));
strcat(text, "\xFF");
strcat_P(text, (const char *)yes);
strcat_P(text, FTOP(yes));
return toggle(x, y, w, h, text, state, options);
}

View File

@ -135,9 +135,9 @@ namespace FTDI {
}
}
void draw_text_box(CommandProcessor& cmd, int x, int y, int w, int h, FSTR_P pstr, uint16_t options, uint8_t font) {
char str[strlen_P((const char*)pstr) + 1];
strcpy_P(str, (const char*)pstr);
void draw_text_box(CommandProcessor& cmd, int x, int y, int w, int h, FSTR_P fstr, uint16_t options, uint8_t font) {
char str[strlen_P(FTOP(fstr)) + 1];
strcpy_P(str, FTOP(fstr));
draw_text_box(cmd, x, y, w, h, (const char*) str, options, font);
}
} // namespace FTDI

View File

@ -33,6 +33,7 @@ namespace FTDI {
const bool use_utf8 = has_utf8_chars(str);
#define CHAR_WIDTH(c) use_utf8 ? utf8_fm.get_char_width(c) : clcd_fm.char_widths[(uint8_t)c]
#else
constexpr bool use_utf8 = false;
#define CHAR_WIDTH(c) utf8_fm.get_char_width(c)
#endif
FontMetrics utf8_fm(font);
@ -53,21 +54,17 @@ namespace FTDI {
breakPoint = (char*)next;
}
if (lineWidth > w) {
*breakPoint = '\0';
strcpy_P(breakPoint,PSTR("..."));
}
if (lineWidth > w)
strcpy_P(breakPoint, PSTR("..."));
cmd.apply_text_alignment(x, y, w, h, options);
#if ENABLED(TOUCH_UI_USE_UTF8)
if (use_utf8) {
draw_utf8_text(cmd, x, y, str, font_size_t::from_romfont(font), options);
} else
#endif
{
cmd.CLCD::CommandFifo::text(x, y, font, options);
cmd.CLCD::CommandFifo::str(str);
}
if (use_utf8) {
TERN_(TOUCH_UI_USE_UTF8, draw_utf8_text(cmd, x, y, str, font_size_t::from_romfont(font), options));
}
else {
cmd.CLCD::CommandFifo::text(x, y, font, options);
cmd.CLCD::CommandFifo::str(str);
}
}
/**
@ -80,9 +77,9 @@ namespace FTDI {
_draw_text_with_ellipsis(cmd, x, y, w, h, tmp, options, font);
}
void draw_text_with_ellipsis(CommandProcessor& cmd, int x, int y, int w, int h, FSTR_P pstr, uint16_t options, uint8_t font) {
char tmp[strlen_P((const char*)pstr) + 3];
strcpy_P(tmp, (const char*)pstr);
void draw_text_with_ellipsis(CommandProcessor& cmd, int x, int y, int w, int h, FSTR_P fstr, uint16_t options, uint8_t font) {
char tmp[strlen_P(FTOP(fstr)) + 3];
strcpy_P(tmp, FTOP(fstr));
_draw_text_with_ellipsis(cmd, x, y, w, h, tmp, options, font);
}
} // namespace FTDI

View File

@ -191,9 +191,9 @@
return render_utf8_text(nullptr, 0, 0, str, fs, maxlen);
}
uint16_t FTDI::get_utf8_text_width(FSTR_P pstr, font_size_t fs) {
char str[strlen_P((const char*)pstr) + 1];
strcpy_P(str, (const char*)pstr);
uint16_t FTDI::get_utf8_text_width(FSTR_P fstr, font_size_t fs) {
char str[strlen_P(FTOP(fstr)) + 1];
strcpy_P(str, FTOP(fstr));
return get_utf8_text_width(str, fs);
}
@ -234,9 +234,9 @@
cmd.cmd(RESTORE_CONTEXT());
}
void FTDI::draw_utf8_text(CommandProcessor& cmd, int x, int y, FSTR_P pstr, font_size_t fs, uint16_t options) {
char str[strlen_P((const char*)pstr) + 1];
strcpy_P(str, (const char*)pstr);
void FTDI::draw_utf8_text(CommandProcessor& cmd, int x, int y, FSTR_P fstr, font_size_t fs, uint16_t options) {
char str[strlen_P(FTOP(fstr)) + 1];
strcpy_P(str, FTOP(fstr));
draw_utf8_text(cmd, x, y, (const char*) str, fs, options);
}

View File

@ -245,8 +245,8 @@ void BaseNumericAdjustmentScreen::widgets_t::adjuster(uint8_t tag, FSTR_P label,
}
if (_what & FOREGROUND) {
char b[strlen_P(value)+1];
strcpy_P(b,value);
char b[strlen(value) + 1];
strcpy(b, value);
adjuster_sram_val(tag, label, b, is_enabled);
}
}

View File

@ -345,8 +345,8 @@ void StatusScreen::draw_status_message(draw_mode_t what, const char *message) {
}
void StatusScreen::setStatusMessage(FSTR_P message) {
char buff[strlen_P((const char * const)message)+1];
strcpy_P(buff, (const char * const) message);
char buff[strlen_P(FTOP(message)) + 1];
strcpy_P(buff, FTOP(message));
setStatusMessage((const char *) buff);
}