diff --git a/resources/eez-framework-amalgamation/eez-flow.cpp b/resources/eez-framework-amalgamation/eez-flow.cpp index 47168588..223cbaed 100644 --- a/resources/eez-framework-amalgamation/eez-flow.cpp +++ b/resources/eez-framework-amalgamation/eez-flow.cpp @@ -1,4 +1,4 @@ -/* Autogenerated on November 17, 2024 10:35:13 AM from eez-framework commit 3dee6f40927c74568901c8c97f3e16b4ecbb6051 */ +/* Autogenerated on November 19, 2024 2:46:06 PM from eez-framework commit 4b8ceca59dc6b0b34fefb219390e79e89c719da2 */ /* * eez-framework * @@ -9145,6 +9145,59 @@ void do_OPERATION_TYPE_STRING_FIND(EvalStack &stack) { } stack.push(Value(-1, VALUE_TYPE_INT32)); } +#if !defined(EEZ_DASHBOARD_API) +typedef enum { + type_int, + type_signed_char, + type_short_int, + type_long_int, + type_long_long_int, + type_intmax_t, + type_size_t, + type_unsigned_int, + type_unsigned_char, + type_unsigned_short_int, + type_unsigned_long_int, + type_unsigned_long_long_int, + type_uintmax_t, + type_double, + type_string +} FormatType; +typedef enum { + length_none, + length_hh, + length_h, + length_l, + length_ll, + length_j, + length_z, + length_t, + length_L +} FormatLength; +size_t do_string_format(FormatType type, const Value& b, char *result, size_t result_size, const char *format) { + if (type == type_int) return snprintf(result, result_size, format, (int)b.getInt()); + if (type == type_signed_char) return snprintf(result, result_size, format, (signed char)b.getInt32()); + if (type == type_short_int) return snprintf(result, result_size, format, (short int)b.getInt32()); + if (type == type_long_int) return snprintf(result, result_size, format, (long int)b.getInt64()); + if (type == type_long_long_int) return snprintf(result, result_size, format, (long long int)b.getInt64()); + if (type == type_intmax_t) return snprintf(result, result_size, format, (intmax_t)b.getInt64()); + if (type == type_size_t) return snprintf(result, result_size, format, (size_t)b.getInt64()); + if (type == type_unsigned_int) return snprintf(result, result_size, format, (unsigned int)b.getUInt32()); + if (type == type_unsigned_char) return snprintf(result, result_size, format, (unsigned char)b.getUInt32()); + if (type == type_unsigned_short_int) return snprintf(result, result_size, format, (unsigned short int)b.getUInt32()); + if (type == type_unsigned_long_int) return snprintf(result, result_size, format, (unsigned long int)b.getUInt64()); + if (type == type_unsigned_long_long_int) return snprintf(result, result_size, format, (unsigned long long int)b.getUInt64()); + if (type == type_uintmax_t) return snprintf(result, result_size, format, (uintmax_t)b.getUInt64()); + if (type == type_double) { + if (b.isDouble()) { + return snprintf(result, result_size, format, b.getDouble()); + } + float f = b.toFloat(); + return snprintf(result, result_size, format, f); + } + return snprintf(result, result_size, format, b.getString()); +} +#endif void do_OPERATION_TYPE_STRING_FORMAT(EvalStack &stack) { auto a = stack.pop().getValue(); if (a.isError()) { @@ -9172,17 +9225,7 @@ void do_OPERATION_TYPE_STRING_FORMAT(EvalStack &stack) { char specifier = format[formatLength-1]; char l1 = formatLength > 1 ? format[formatLength-2] : 0; char l2 = formatLength > 2 ? format[formatLength-3] : 0; - enum { - length_none, - length_hh, - length_h, - length_l, - length_ll, - length_j, - length_z, - length_t, - length_L - } length = length_none; + FormatLength length = length_none; if (l1 == 'h' && l2 == 'h') length = length_hh; else if (l1 == 'h') length = length_h; else if (l1 == 'l') length = length_l; @@ -9191,27 +9234,11 @@ void do_OPERATION_TYPE_STRING_FORMAT(EvalStack &stack) { else if (l1 == 'z') length = length_z; else if (l1 == 't') length = length_t; else if (l1 == 'L') length = length_L; - enum { - type_int, - type_signed_char, - type_short_int, - type_long_int, - type_long_long_int, - type_intmax_t, - type_size_t, - type_unsigned_int, - type_unsigned_char, - type_unsigned_short_int, - type_unsigned_long_int, - type_unsigned_long_long_int, - type_uintmax_t, - type_double, - type_string - } type = type_int; + FormatType type = type_int; if (specifier == 'd' || specifier == 'i') { if (length == length_none) { type = type_int; - } if (length == length_hh) { + } else if (length == length_hh) { type = type_signed_char; } else if (length == length_h) { type = type_short_int; @@ -9230,7 +9257,7 @@ void do_OPERATION_TYPE_STRING_FORMAT(EvalStack &stack) { } else if (specifier == 'u' || specifier == 'o' || specifier == 'x' || specifier == 'X') { if (length == length_none) { type = type_unsigned_int; - } if (length == length_hh) { + } else if (length == length_hh) { type = type_unsigned_char; } else if (length == length_h) { type = type_unsigned_short_int; @@ -9256,34 +9283,11 @@ void do_OPERATION_TYPE_STRING_FORMAT(EvalStack &stack) { stack.push(Value::makeError()); return; } - //char result[1024]; - char result[64]; - if (type == type_int) snprintf(result, sizeof(result), format, (int)b.getInt()); - else if (type == type_signed_char) snprintf(result, sizeof(result), format, (signed char)b.getInt32()); - else if (type == type_short_int) snprintf(result, sizeof(result), format, (short int)b.getInt32()); - else if (type == type_long_int) snprintf(result, sizeof(result), format, (long int)b.getInt64()); - else if (type == type_long_long_int) snprintf(result, sizeof(result), format, (long long int)b.getInt64()); - else if (type == type_intmax_t) snprintf(result, sizeof(result), format, (intmax_t)b.getInt64()); - else if (type == type_size_t) snprintf(result, sizeof(result), format, (size_t)b.getInt64()); - else if (type == type_unsigned_int) snprintf(result, sizeof(result), format, (unsigned int)b.getUInt32()); - else if (type == type_unsigned_char) snprintf(result, sizeof(result), format, (unsigned char)b.getUInt32()); - else if (type == type_unsigned_short_int) snprintf(result, sizeof(result), format, (unsigned short int)b.getUInt32()); - else if (type == type_unsigned_long_int) snprintf(result, sizeof(result), format, (unsigned long int)b.getUInt64()); - else if (type == type_unsigned_long_long_int) snprintf(result, sizeof(result), format, (unsigned long long int)b.getUInt64()); - else if (type == type_uintmax_t) snprintf(result, sizeof(result), format, (uintmax_t)b.getUInt64()); - else if (type == type_double) { - if (b.isDouble()) { - snprintf(result, sizeof(result), format, b.getDouble()); - } else { - float f = b.toFloat(); - snprintf(result, sizeof(result), format, f); - } - } - else { - snprintf(result, sizeof(result), format, b.getString()); - } - result[sizeof(result) - 1] = 0; - stack.push(Value::makeStringRef(result, -1, 0x1e1227fd)); + int resultStrLen = do_string_format(type, b, NULL, 0, format); + char *resultStr = (char *)eez::alloc(resultStrLen + 1, 0x987ee4eb); + do_string_format(type, b, resultStr, resultStrLen + 1, format); + stack.push(Value::makeStringRef(resultStr, -1, 0x1e1227fd)); + eez::free(resultStr); #endif } void do_OPERATION_TYPE_STRING_FORMAT_PREFIX(EvalStack &stack) { diff --git a/resources/eez-framework-amalgamation/eez-flow.h b/resources/eez-framework-amalgamation/eez-flow.h index 13df6e4b..9c399bfe 100644 --- a/resources/eez-framework-amalgamation/eez-flow.h +++ b/resources/eez-framework-amalgamation/eez-flow.h @@ -1,4 +1,4 @@ -/* Autogenerated on November 17, 2024 10:35:13 AM from eez-framework commit 3dee6f40927c74568901c8c97f3e16b4ecbb6051 */ +/* Autogenerated on November 19, 2024 2:46:06 PM from eez-framework commit 4b8ceca59dc6b0b34fefb219390e79e89c719da2 */ /* * eez-framework *