1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-22 18:25:18 +00:00

🩹 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

@ -958,8 +958,8 @@ void CrealityDWINClass::Update_Status_Bar(bool refresh/*=false*/) {
static bool new_msg;
static uint8_t msgscrl = 0;
static char lastmsg[64];
if (strcmp_P(lastmsg, statusmsg) != 0 || refresh) {
strcpy_P(lastmsg, statusmsg);
if (strcmp(lastmsg, statusmsg) != 0 || refresh) {
strcpy(lastmsg, statusmsg);
msgscrl = 0;
new_msg = true;
}
@ -4695,10 +4695,7 @@ void CrealityDWINClass::Modify_Option(uint8_t value, const char * const * option
/* Main Functions */
void CrealityDWINClass::Update_Status(const char * const text) {
char header[4];
LOOP_L_N(i, 3) header[i] = text[i];
header[3] = '\0';
if (strcmp_P(header, PSTR("<F>")) == 0) {
if (strncmp_P(text, PSTR("<F>"), 3) == 0) {
LOOP_L_N(i, _MIN((size_t)LONG_FILENAME_LENGTH, strlen(text))) filename[i] = text[i + 3];
filename[_MIN((size_t)LONG_FILENAME_LENGTH - 1, strlen(text))] = '\0';
Draw_Print_Filename(true);
@ -4722,10 +4719,10 @@ void CrealityDWINClass::Start_Print(bool sd) {
card.selectFileByName(fname);
}
#endif
strcpy_P(filename, card.longest_filename());
strcpy(filename, card.longest_filename());
}
else
strcpy_P(filename, "Host Print");
strcpy_P(filename, PSTR("Host Print"));
TERN_(LCD_SET_PROGRESS_MANUALLY, ui.set_progress(0));
TERN_(USE_M73_REMAINING_TIME, ui.set_remaining_time(0));
Draw_Print_Screen();

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);
}

View File

@ -63,6 +63,7 @@ uint8_t* get_utf8_value_cb(uint8_t *pstart, read_byte_cb_t cb_read_byte, wchar_t
/* Returns length of string in CHARACTERS, NOT BYTES */
uint8_t utf8_strlen(const char *pstart);
uint8_t utf8_strlen_P(PGM_P pstart);
inline uint8_t utf8_strlen(FSTR_P fstart) { return utf8_strlen_P(FTOP(fstart)); }
/* Returns start byte position of desired char number */
uint8_t utf8_byte_pos_by_char_num(const char *pstart, const uint8_t charnum);

View File

@ -190,6 +190,9 @@ inline lcd_uint_t lcd_put_u8str_ind_P(const lcd_uint_t col, const lcd_uint_t row
lcd_moveto(col, row);
return lcd_put_u8str_ind_P(pstr, ind, inStr, maxlen);
}
inline lcd_uint_t lcd_put_u8str_ind(FSTR_P const fstr, const int8_t ind, FSTR_P const inFstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH) {
return lcd_put_u8str_ind_P(FTOP(fstr), ind, FTOP(inFstr), maxlen);
}
inline lcd_uint_t lcd_put_u8str_ind(const lcd_uint_t col, const lcd_uint_t row, FSTR_P const fstr, const int8_t ind, FSTR_P const inFstr=nullptr, const lcd_uint_t maxlen=LCD_WIDTH) {
return lcd_put_u8str_ind_P(col, row, FTOP(fstr), ind, FTOP(inFstr), maxlen);
}

View File

@ -114,8 +114,8 @@ class MenuItem_confirm : public MenuItemBase {
selectFunc_t yesFunc, selectFunc_t noFunc,
PGM_P const pref, FSTR_P const string, PGM_P const suff=nullptr
) {
char str[strlen_P((PGM_P)string) + 1];
strcpy_P(str, (PGM_P)string);
char str[strlen_P(FTOP(string)) + 1];
strcpy_P(str, FTOP(string));
select_screen(yes, no, yesFunc, noFunc, pref, str, suff);
}
// Shortcut for prompt with "NO"/ "YES" labels