Improved string display handling

should fix #344 for good
This commit is contained in:
d0k3 2018-04-17 23:44:53 +02:00
parent 2a6d5c79c0
commit b0997fa687
2 changed files with 13 additions and 13 deletions

View File

@ -277,7 +277,7 @@ void DrawStringCenter(u8* screen, int color, int bgcolor, const char *format, ..
int x = (w >= SCREEN_WIDTH(screen)) ? 0 : (SCREEN_WIDTH(screen) - w) >> 1;
int y = (h >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - h) >> 1;
DrawStringF(screen, x, y, color, bgcolor, str);
DrawStringF(screen, x, y, color, bgcolor, "%s", str);
}
u32 GetDrawStringHeight(const char* str) {
@ -388,7 +388,7 @@ void ShowString(const char *format, ...)
va_end(va);
ClearScreenF(true, false, COLOR_STD_BG);
DrawStringCenter(MAIN_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, str);
DrawStringCenter(MAIN_SCREEN, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
} else ClearScreenF(true, false, COLOR_STD_BG);
}
@ -416,7 +416,7 @@ void ShowIconString(u8* icon, int w, int h, const char *format, ...)
y_bmp = (tot_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - tot_height) / 2;
DrawBitmap(MAIN_SCREEN, x_bmp, y_bmp, w, h, icon);
DrawStringF(MAIN_SCREEN, x_str, y_str, COLOR_STD_FONT, COLOR_STD_BG, str);
DrawStringF(MAIN_SCREEN, x_str, y_str, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
}
bool ShowPrompt(bool ask, const char *format, ...)
@ -486,7 +486,7 @@ bool ShowUnlockSequence(u32 seqlvl, const char *format, ...) {
}
ClearScreenF(true, false, color_bg);
DrawStringF(MAIN_SCREEN, x, y, color_font, color_bg, str);
DrawStringF(MAIN_SCREEN, x, y, color_font, color_bg, "%s", str);
#ifndef TIMER_UNLOCK
DrawStringF(MAIN_SCREEN, x, y + str_height - 28, color_font, color_bg, "To proceed, enter this:");
@ -577,7 +577,7 @@ u32 ShowSelectPrompt(u32 n, const char** options, const char *format, ...) {
yopt = y + GetDrawStringHeight(str) + 8;
ClearScreenF(true, false, COLOR_STD_BG);
DrawStringF(MAIN_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, str);
DrawStringF(MAIN_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
DrawStringF(MAIN_SCREEN, x, yopt + (n*(line_height+2)) + line_height, COLOR_STD_FONT, COLOR_STD_BG, "(<A> select, <B> cancel)");
while (true) {
for (u32 i = 0; i < n; i++) {
@ -624,7 +624,7 @@ bool ShowInputPrompt(char* inputstr, u32 max_size, u32 resize, const char* alpha
y = (str_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - str_height) / 2;
ClearScreenF(true, false, COLOR_STD_BG);
DrawStringF(MAIN_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, str);
DrawStringF(MAIN_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
DrawStringF(MAIN_SCREEN, x + 8, y + str_height - 40, COLOR_STD_FONT, COLOR_STD_BG,
"R - (\x18\x19) fast scroll\nL - clear data%s", resize ? "\nX - remove char\nY - insert char" : "");
@ -843,7 +843,7 @@ bool ShowRtcSetterPrompt(void* time, const char *format, ...) {
y = (str_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - str_height) / 2;
ClearScreenF(true, false, COLOR_STD_BG);
DrawStringF(MAIN_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, str);
DrawStringF(MAIN_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, "%s", str);
int cursor = 0;
bool ret = false;

View File

@ -476,7 +476,7 @@ bool expand_arg(char* argex, const char* arg, u32 len) {
u32 out_len = out - argex;
if (out_len >= (_ARG_MAX_LEN-1)) return false; // maximum arglen reached
if (*in == '\\') { // escape line breaks (no other escape is handled)
if (*in == '\\') { // escape line breaks
if (*(++in) == 'n') *(out++) = '\n';
else {
*(out++) = '\\';
@ -938,14 +938,14 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) {
if (++n_opt >= _CHOICE_MAX_N) break;
}
u32 result = ShowSelectPrompt(n_opt, options, argv[0]);
u32 result = ShowSelectPrompt(n_opt, options, "%s", argv[0]);
if (!result) {
ret = false;
if (err_str) snprintf(err_str, _ERR_STR_LEN, "user abort");
} else jump_ptr = options_jmp[result-1];
}
else if (id == CMD_ID_ECHO) {
ShowPrompt(false, argv[0]);
ShowPrompt(false, "%s", argv[0]);
}
else if (id == CMD_ID_QR) {
const u32 screen_size = SCREEN_SIZE(ALT_SCREEN);
@ -957,20 +957,20 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) {
if (ret) {
memcpy(screen_copy, ALT_SCREEN, screen_size);
DrawQrCode(ALT_SCREEN, qrcode);
ShowPrompt(false, argv[0]);
ShowPrompt(false, "%s", argv[0]);
memcpy(ALT_SCREEN, screen_copy, screen_size);
} else if (err_str) snprintf(err_str, _ERR_STR_LEN, "out of memory");
free(screen_copy);
}
else if (id == CMD_ID_ASK) {
ret = ShowPrompt(true, argv[0]);
ret = ShowPrompt(true, "%s", argv[0]);
if (err_str) snprintf(err_str, _ERR_STR_LEN, "user abort");
}
else if (id == CMD_ID_INPUT) {
char input[_VAR_CNT_LEN] = { 0 };
char* var = get_var(argv[1], NULL);
strncpy(input, var, _VAR_CNT_LEN);
ret = ShowStringPrompt(input, _VAR_CNT_LEN, argv[0]);
ret = ShowStringPrompt(input, _VAR_CNT_LEN, "%s", argv[0]);
if (ret) set_var(argv[1], "");
if (err_str) snprintf(err_str, _ERR_STR_LEN, "user abort");
if (ret) {