Skip to content

Commit a3c3656

Browse files
committed
Removed mbed_minimal_formatted_string_character
mbed_minimal_formatted_string_character is no longer required since fputc does the new line conversion. This results in a small Flash saving.
1 parent 94acb5d commit a3c3656

File tree

1 file changed

+7
-48
lines changed

1 file changed

+7
-48
lines changed

platform/source/minimal-printf/mbed_printf_implementation.c

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,7 @@
2222
#include <stdint.h>
2323
#include <stddef.h>
2424

25-
/***************************/
26-
/* MBED */
27-
/***************************/
28-
#if TARGET_LIKE_MBED
29-
30-
#if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
31-
static char mbed_stdio_out_prev = 0;
32-
#endif
33-
34-
35-
/***************************/
36-
/* Linux */
37-
/***************************/
38-
#else
25+
#if !TARGET_LIKE_MBED
3926
/* Linux implementation is for debug only */
4027
#define MBED_CONF_PLATFORM_MINIMAL_PRINTF_ENABLE_FLOATING_POINT 1
4128
#define MBED_CONF_PLATFORM_MINIMAL_PRINTF_SET_FLOATING_POINT_MAX_DECIMALS 6
@@ -106,7 +93,6 @@ static void mbed_minimal_formatted_string_signed(char *buffer, size_t length, in
10693
static void mbed_minimal_formatted_string_unsigned(char *buffer, size_t length, int *result, MBED_UNSIGNED_STORAGE value, FILE *stream);
10794
static void mbed_minimal_formatted_string_hexadecimal(char *buffer, size_t length, int *result, MBED_UNSIGNED_STORAGE value, FILE *stream, bool upper);
10895
static void mbed_minimal_formatted_string_void_pointer(char *buffer, size_t length, int *result, const void *value, FILE *stream);
109-
static void mbed_minimal_formatted_string_character(char *buffer, size_t length, int *result, char character, FILE *stream);
11096
static void mbed_minimal_formatted_string_string(char *buffer, size_t length, int *result, const char *string, size_t precision, FILE *stream);
11197

11298

@@ -282,7 +268,7 @@ static void mbed_minimal_formatted_string_double(char *buffer, size_t length, in
282268
mbed_minimal_formatted_string_signed(buffer, length, result, integer, stream);
283269

284270
/* write decimal point */
285-
mbed_minimal_formatted_string_character(buffer, length, result, '.', stream);
271+
mbed_minimal_putchar(buffer, length, result, '.', stream);
286272

287273
/* get decimal part */
288274
double precision = 1.0;
@@ -327,33 +313,6 @@ static void mbed_minimal_formatted_string_double(char *buffer, size_t length, in
327313
}
328314
#endif
329315

330-
/**
331-
* @brief Print character.
332-
*
333-
* @param buffer The buffer to store output (NULL for stdout).
334-
* @param[in] length The length of the buffer.
335-
* @param result The current output location.
336-
* @param[in] value The character to be printed.
337-
*/
338-
static void mbed_minimal_formatted_string_character(char *buffer, size_t length, int *result, char character, FILE *stream)
339-
{
340-
/* write character */
341-
if (buffer) {
342-
mbed_minimal_putchar(buffer, length, result, character, stream);
343-
} else {
344-
/* convert \n to \r\n if enabled in platform configuration */
345-
#if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
346-
if (character == '\n' && mbed_stdio_out_prev != '\r') {
347-
mbed_minimal_putchar(buffer, length, result, '\r', stream);
348-
}
349-
350-
/* cache character */
351-
mbed_stdio_out_prev = character;
352-
#endif
353-
mbed_minimal_putchar(buffer, length, result, character, stream);
354-
}
355-
}
356-
357316
/**
358317
* @brief Print string with precision.
359318
*
@@ -513,7 +472,7 @@ int mbed_minimal_formatted_string(char *buffer, size_t length, const char *forma
513472
#else
514473
/* If 64 bit is not enabled, print %ll[di] rather than truncated value */
515474
if (length_modifier == LENGTH_LL) {
516-
mbed_minimal_formatted_string_character(buffer, length, &result, '%', stream);
475+
mbed_minimal_putchar(buffer, length, &result, '%', stream);
517476
if (next == '%') {
518477
// Continue printing loop after `%`
519478
index = next_index;
@@ -572,7 +531,7 @@ int mbed_minimal_formatted_string(char *buffer, size_t length, const char *forma
572531
#else
573532
/* If 64 bit is not enabled, print %ll[uxX] rather than truncated value */
574533
if (length_modifier == LENGTH_LL) {
575-
mbed_minimal_formatted_string_character(buffer, length, &result, '%', stream);
534+
mbed_minimal_putchar(buffer, length, &result, '%', stream);
576535
if (next == '%') {
577536
// Continue printing loop after `%`
578537
index = next_index;
@@ -638,7 +597,7 @@ int mbed_minimal_formatted_string(char *buffer, size_t length, const char *forma
638597
char value = va_arg(arguments, MBED_SIGNED_NATIVE_TYPE);
639598
index = next_index;
640599

641-
mbed_minimal_formatted_string_character(buffer, length, &result, value, stream);
600+
mbed_minimal_putchar(buffer, length, &result, value, stream);
642601
}
643602
/* string */
644603
else if (next == 's') {
@@ -655,7 +614,7 @@ int mbed_minimal_formatted_string(char *buffer, size_t length, const char *forma
655614
mbed_minimal_formatted_string_void_pointer(buffer, length, &result, value, stream);
656615
} else {
657616
// Unrecognised, or `%%`. Print the `%` that led us in.
658-
mbed_minimal_formatted_string_character(buffer, length, &result, '%', stream);
617+
mbed_minimal_putchar(buffer, length, &result, '%', stream);
659618
if (next == '%') {
660619
// Continue printing loop after `%%`
661620
index = next_index;
@@ -667,7 +626,7 @@ int mbed_minimal_formatted_string(char *buffer, size_t length, const char *forma
667626
/* not a format specifier */
668627
{
669628
/* write normal character */
670-
mbed_minimal_formatted_string_character(buffer, length, &result, format[index], stream);
629+
mbed_minimal_putchar(buffer, length, &result, format[index], stream);
671630
}
672631
}
673632

0 commit comments

Comments
 (0)