From 4028c1cfc7bcaf78e49bb98b527353ec30a970de Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 12 Mar 2022 17:12:21 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Fix=20FSTR=20/=20PSTR=20usage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/lcd/e3v2/jyersui/dwin.cpp | 13 ++++----- .../archim2-flash/flash_storage.cpp | 2 +- .../bioprinter/printing_dialog_box.cpp | 4 +-- .../ftdi_eve_lib/extended/command_processor.h | 6 ++-- .../ftdi_eve_lib/extended/text_box.cpp | 6 ++-- .../ftdi_eve_lib/extended/text_ellipsis.cpp | 29 +++++++++---------- .../ftdi_eve_lib/extended/unicode/unicode.cpp | 12 ++++---- .../base_numeric_adjustment_screen.cpp | 4 +-- .../generic/status_screen.cpp | 4 +-- Marlin/src/lcd/fontutils.h | 1 + Marlin/src/lcd/lcdprint.h | 3 ++ Marlin/src/lcd/menu/menu.h | 4 +-- 12 files changed, 43 insertions(+), 45 deletions(-) diff --git a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp index 51df15da73..3e777d4aaa 100644 --- a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp @@ -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("")) == 0) { + if (strncmp_P(text, PSTR(""), 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(); diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/flash_storage.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/flash_storage.cpp index 8b0c0f877c..dbee1e034b 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/flash_storage.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/flash_storage.cpp @@ -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)) { diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/bioprinter/printing_dialog_box.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/bioprinter/printing_dialog_box.cpp index f0c0a59d36..6d177c5a7b 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/bioprinter/printing_dialog_box.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/bioprinter/printing_dialog_box.cpp @@ -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); } diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h index 24e93982c2..648ed5330a 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h @@ -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); } diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp index b4d8156b39..c75cdf1812 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp @@ -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 diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_ellipsis.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_ellipsis.cpp index 698bcdb150..a6d014b56e 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_ellipsis.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_ellipsis.cpp @@ -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 diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp index ca25dea3ca..d428f686b7 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp @@ -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); } diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/base_numeric_adjustment_screen.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/base_numeric_adjustment_screen.cpp index 4415ed50fc..ce3066ae41 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/base_numeric_adjustment_screen.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/base_numeric_adjustment_screen.cpp @@ -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); } } diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/status_screen.cpp b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/status_screen.cpp index 4e76450683..7310577995 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/status_screen.cpp +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/status_screen.cpp @@ -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); } diff --git a/Marlin/src/lcd/fontutils.h b/Marlin/src/lcd/fontutils.h index 3901d4439f..21aee1e939 100644 --- a/Marlin/src/lcd/fontutils.h +++ b/Marlin/src/lcd/fontutils.h @@ -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); diff --git a/Marlin/src/lcd/lcdprint.h b/Marlin/src/lcd/lcdprint.h index c701a59568..d716d035ca 100644 --- a/Marlin/src/lcd/lcdprint.h +++ b/Marlin/src/lcd/lcdprint.h @@ -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); } diff --git a/Marlin/src/lcd/menu/menu.h b/Marlin/src/lcd/menu/menu.h index 72826262f4..b111236d69 100644 --- a/Marlin/src/lcd/menu/menu.h +++ b/Marlin/src/lcd/menu/menu.h @@ -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