Procházet zdrojové kódy

🩹 Fix FSTR / PSTR usage

Scott Lahteine před 2 roky
rodič
revize
e354cd15b2

+ 5
- 8
Marlin/src/lcd/e3v2/jyersui/dwin.cpp Zobrazit soubor

@@ -958,8 +958,8 @@ void CrealityDWINClass::Update_Status_Bar(bool refresh/*=false*/) {
958 958
   static bool new_msg;
959 959
   static uint8_t msgscrl = 0;
960 960
   static char lastmsg[64];
961
-  if (strcmp_P(lastmsg, statusmsg) != 0 || refresh) {
962
-    strcpy_P(lastmsg, statusmsg);
961
+  if (strcmp(lastmsg, statusmsg) != 0 || refresh) {
962
+    strcpy(lastmsg, statusmsg);
963 963
     msgscrl = 0;
964 964
     new_msg = true;
965 965
   }
@@ -4695,10 +4695,7 @@ void CrealityDWINClass::Modify_Option(uint8_t value, const char * const * option
4695 4695
 /* Main Functions */
4696 4696
 
4697 4697
 void CrealityDWINClass::Update_Status(const char * const text) {
4698
-  char header[4];
4699
-  LOOP_L_N(i, 3) header[i] = text[i];
4700
-  header[3] = '\0';
4701
-  if (strcmp_P(header, PSTR("<F>")) == 0) {
4698
+  if (strncmp_P(text, PSTR("<F>"), 3) == 0) {
4702 4699
     LOOP_L_N(i, _MIN((size_t)LONG_FILENAME_LENGTH, strlen(text))) filename[i] = text[i + 3];
4703 4700
     filename[_MIN((size_t)LONG_FILENAME_LENGTH - 1, strlen(text))] = '\0';
4704 4701
     Draw_Print_Filename(true);
@@ -4722,10 +4719,10 @@ void CrealityDWINClass::Start_Print(bool sd) {
4722 4719
           card.selectFileByName(fname);
4723 4720
         }
4724 4721
       #endif
4725
-      strcpy_P(filename, card.longest_filename());
4722
+      strcpy(filename, card.longest_filename());
4726 4723
     }
4727 4724
     else
4728
-      strcpy_P(filename, "Host Print");
4725
+      strcpy_P(filename, PSTR("Host Print"));
4729 4726
     TERN_(LCD_SET_PROGRESS_MANUALLY, ui.set_progress(0));
4730 4727
     TERN_(USE_M73_REMAINING_TIME, ui.set_remaining_time(0));
4731 4728
     Draw_Print_Screen();

+ 1
- 1
Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/flash_storage.cpp Zobrazit soubor

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

+ 2
- 2
Marlin/src/lcd/extui/ftdi_eve_touch_ui/bioprinter/printing_dialog_box.cpp Zobrazit soubor

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

+ 3
- 3
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/command_processor.h Zobrazit soubor

@@ -242,10 +242,10 @@ class CommandProcessor : public CLCD::CommandFifo {
242 242
     }
243 243
 
244 244
     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) {
245
-      char text[strlen_P((const char *)no) + strlen_P((const char *)yes) + 2];
246
-      strcpy_P(text, (const char *)no);
245
+      char text[strlen_P(FTOP(no)) + strlen_P(FTOP(yes)) + 2];
246
+      strcpy_P(text, FTOP(no));
247 247
       strcat(text, "\xFF");
248
-      strcat_P(text, (const char *)yes);
248
+      strcat_P(text, FTOP(yes));
249 249
       return toggle(x, y, w, h, text, state, options);
250 250
     }
251 251
 

+ 3
- 3
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_box.cpp Zobrazit soubor

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

+ 13
- 16
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/text_ellipsis.cpp Zobrazit soubor

@@ -33,6 +33,7 @@ namespace FTDI {
33 33
       const bool use_utf8 = has_utf8_chars(str);
34 34
       #define CHAR_WIDTH(c) use_utf8 ? utf8_fm.get_char_width(c) : clcd_fm.char_widths[(uint8_t)c]
35 35
     #else
36
+      constexpr bool use_utf8 = false;
36 37
       #define CHAR_WIDTH(c) utf8_fm.get_char_width(c)
37 38
     #endif
38 39
     FontMetrics utf8_fm(font);
@@ -53,21 +54,17 @@ namespace FTDI {
53 54
         breakPoint = (char*)next;
54 55
     }
55 56
 
56
-    if (lineWidth > w) {
57
-      *breakPoint = '\0';
58
-      strcpy_P(breakPoint,PSTR("..."));
59
-    }
57
+    if (lineWidth > w)
58
+      strcpy_P(breakPoint, PSTR("..."));
60 59
 
61 60
     cmd.apply_text_alignment(x, y, w, h, options);
62
-    #if ENABLED(TOUCH_UI_USE_UTF8)
63
-      if (use_utf8) {
64
-        draw_utf8_text(cmd, x, y, str, font_size_t::from_romfont(font), options);
65
-      } else
66
-    #endif
67
-      {
68
-        cmd.CLCD::CommandFifo::text(x, y, font, options);
69
-        cmd.CLCD::CommandFifo::str(str);
70
-      }
61
+    if (use_utf8) {
62
+      TERN_(TOUCH_UI_USE_UTF8, draw_utf8_text(cmd, x, y, str, font_size_t::from_romfont(font), options));
63
+    }
64
+    else {
65
+      cmd.CLCD::CommandFifo::text(x, y, font, options);
66
+      cmd.CLCD::CommandFifo::str(str);
67
+    }
71 68
   }
72 69
 
73 70
   /**
@@ -80,9 +77,9 @@ namespace FTDI {
80 77
     _draw_text_with_ellipsis(cmd, x, y, w, h, tmp, options, font);
81 78
   }
82 79
 
83
-  void draw_text_with_ellipsis(CommandProcessor& cmd, int x, int y, int w, int h, FSTR_P pstr, uint16_t options, uint8_t font) {
84
-    char tmp[strlen_P((const char*)pstr) + 3];
85
-    strcpy_P(tmp, (const char*)pstr);
80
+  void draw_text_with_ellipsis(CommandProcessor& cmd, int x, int y, int w, int h, FSTR_P fstr, uint16_t options, uint8_t font) {
81
+    char tmp[strlen_P(FTOP(fstr)) + 3];
82
+    strcpy_P(tmp, FTOP(fstr));
86 83
     _draw_text_with_ellipsis(cmd, x, y, w, h, tmp, options, font);
87 84
   }
88 85
 } // namespace FTDI

+ 6
- 6
Marlin/src/lcd/extui/ftdi_eve_touch_ui/ftdi_eve_lib/extended/unicode/unicode.cpp Zobrazit soubor

@@ -191,9 +191,9 @@
191 191
     return render_utf8_text(nullptr, 0, 0, str, fs, maxlen);
192 192
   }
193 193
 
194
-  uint16_t FTDI::get_utf8_text_width(FSTR_P pstr, font_size_t fs) {
195
-    char str[strlen_P((const char*)pstr) + 1];
196
-    strcpy_P(str, (const char*)pstr);
194
+  uint16_t FTDI::get_utf8_text_width(FSTR_P fstr, font_size_t fs) {
195
+    char str[strlen_P(FTOP(fstr)) + 1];
196
+    strcpy_P(str, FTOP(fstr));
197 197
     return get_utf8_text_width(str, fs);
198 198
   }
199 199
 
@@ -234,9 +234,9 @@
234 234
     cmd.cmd(RESTORE_CONTEXT());
235 235
   }
236 236
 
237
-  void FTDI::draw_utf8_text(CommandProcessor& cmd, int x, int y, FSTR_P pstr, font_size_t fs, uint16_t options) {
238
-    char str[strlen_P((const char*)pstr) + 1];
239
-    strcpy_P(str, (const char*)pstr);
237
+  void FTDI::draw_utf8_text(CommandProcessor& cmd, int x, int y, FSTR_P fstr, font_size_t fs, uint16_t options) {
238
+    char str[strlen_P(FTOP(fstr)) + 1];
239
+    strcpy_P(str, FTOP(fstr));
240 240
     draw_utf8_text(cmd, x, y, (const char*) str, fs, options);
241 241
   }
242 242
 

+ 2
- 2
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/base_numeric_adjustment_screen.cpp Zobrazit soubor

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

+ 2
- 2
Marlin/src/lcd/extui/ftdi_eve_touch_ui/generic/status_screen.cpp Zobrazit soubor

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

+ 1
- 0
Marlin/src/lcd/fontutils.h Zobrazit soubor

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

+ 3
- 0
Marlin/src/lcd/lcdprint.h Zobrazit soubor

@@ -190,6 +190,9 @@ inline lcd_uint_t lcd_put_u8str_ind_P(const lcd_uint_t col, const lcd_uint_t row
190 190
   lcd_moveto(col, row);
191 191
   return lcd_put_u8str_ind_P(pstr, ind, inStr, maxlen);
192 192
 }
193
+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) {
194
+  return lcd_put_u8str_ind_P(FTOP(fstr), ind, FTOP(inFstr), maxlen);
195
+}
193 196
 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) {
194 197
   return lcd_put_u8str_ind_P(col, row, FTOP(fstr), ind, FTOP(inFstr), maxlen);
195 198
 }

+ 2
- 2
Marlin/src/lcd/menu/menu.h Zobrazit soubor

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

Loading…
Zrušit
Uložit