X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=mware%2Fformatwr.c;h=6353e1f1347cdda23dd1e08389896b5d1c0dc130;hb=45add65abd59bd79f528501c85f3e5891a9c2c29;hp=070e12270c245dc87a1e781e7f1b555bd000134b;hpb=96f0ef786b54356c56cc3d4e4f0838df2505cfcc;p=bertos.git diff --git a/mware/formatwr.c b/mware/formatwr.c old mode 100755 new mode 100644 index 070e1227..6353e1f1 --- a/mware/formatwr.c +++ b/mware/formatwr.c @@ -1,8 +1,33 @@ -/*! +/** * \file * * * \version $Id$ @@ -10,16 +35,32 @@ * \brief Basic "printf", "sprintf" and "fprintf" formatter. * * This module is 100% reentrant and can be adapted to user-defined routines - * that needs formatters with special properties like different output chann- - * els or new format specifiers. + * that needs formatters with special properties like different output + * channels or new format specifiers. * * To reduce size in applications not using real numbers or long integers * the formatter may be compiled to exclude certain parts. This is - * controlled by giving a -D option a compilation time. + * controlled by giving a -D option a compilation time: + * + * \code + * -D CONFIG_PRINTF=PRINTF_FULL Full ANSI printf formatter + * -D CONFIG_PRINTF=PRINTF_NOFLOAT Exclude support for floats + * -D CONFIG_PRINTF=PRINTF_REDUCED Simplified formatter (see below) + * -D CONFIG_PRINTF=PRINTF_NOMODIFIERS Exclude 'l' and 'h' modifiers in reduced version + * -D CONFIG_PRINTF=PRINTF_DISABLED No formatter at all + * \endcode + * + * Code size on AVR4 with GCC 3.4.1 (-O2): + * PRINTF_FULL 2912byte (0xB60) + * PRINTF_NOFLOAT 1684byte (0x694) + * PRINTF_REDUCED 924byte (0x39C) + * PRINTF_NOMODIFIERS 416byte (0x1A0) * - * -DFLOAT_SUPPORT Full ANSI formatter - * -DNO_FLOATS Full ANSI except floats - * -DREDUCED_SUPPORT Reduced 'int' type of converter + * Code/data size in words on DSP56K with CodeWarrior 6.0: + * PRINTF_FULL 1493/45 + * PRINTF_NOFLOAT 795/45 + * PRINTF_REDUCED 482/0 + * PRINTF_NOMODIFIERS 301/0 * * The reduced version of formatter is suitable when program size is critical * rather than formatting power. This routine uses less than 20 bytes of @@ -33,67 +74,67 @@ * * It means that real variables are not supported as well as field * width and precision arguments. - * - * The last eight (h and l modifiers) can easily be removed by - * removing the line "#define MODIFIERS_IN_REDUCED". - */ - -/* - * $Log$ - * Revision 1.2 2004/06/03 11:27:09 bernie - * Add dual-license information. - * - * Revision 1.1 2004/05/23 15:43:16 bernie - * Import mware modules. - * */ -/* bernie */ -#define FLOAT_SUPPORT -#undef NO_FLOATS -#undef REDUCED_SUPPORT -#ifndef FLOAT_SUPPORT -#ifndef NO_FLOATS -#ifndef REDUCED_SUPPORT -#error -DFLOAT_SUPPORT, -DNO_FLOATS or -DREDUCED_SUPPORT missing -#endif +#include "formatwr.h" +#include +#include +#include /* ASSERT */ +#include /* CONFIG_ macros */ + +#ifndef CONFIG_PRINTF_N_FORMATTER + /** Disable the arcane %n formatter. */ + #define CONFIG_PRINTF_N_FORMATTER 0 #endif + +#ifndef CONFIG_PRINTF_OCTAL_FORMATTER + /** Disable the %o formatter. */ + #define CONFIG_PRINTF_OCTAL_FORMATTER 0 #endif -/* Make it easy for customers to disable h and l - modifiers in REDUCED_SUPPORT by removing the next #define */ -#define MODIFIERS_IN_REDUCED +/* True if we must keep a count of the number of characters we print. */ +#define CONFIG_PRINTF_COUNT_CHARS (CONFIG_PRINTF_RETURN_COUNT || CONFIG_PRINTF_N_FORMATTER) -#include "formatwr.h" -#include "compiler.h" /* progmem macros */ -#include +#if CONFIG_PRINTF + +#if CONFIG_PRINTF > PRINTF_NOFLOAT + #include -#ifndef FRMWRI_BUFSIZE -/*bernie: save some memory, who cares about floats with lots of decimals? */ -/*#define FRMWRI_BUFSIZE 134*/ -#define FRMWRI_BUFSIZE 32 + /* Maximum precision for floating point values */ + typedef long double max_float_t; + + /*bernie: save some memory, who cares about floats with lots of decimals? */ + #define FRMWRI_BUFSIZE 134 + #warning 134 is too much, the code must be fixed to have a lower precision limit +#else + /* + * Conservative estimate. Should be (probably) 12 (which is the size necessary + * to represent (2^32-1) in octal plus the sign bit. + */ + #define FRMWRI_BUFSIZE 16 #endif +/* Probably useful for fancy microcontrollers such as the PIC, nobody knows. */ #ifndef MEM_ATTRIBUTE #define MEM_ATTRIBUTE #endif -#ifdef MODIFIERS_IN_REDUCED -#define IS_SHORT (h_modifier || (sizeof(int) == 2 && !l_modifier)) +#if CONFIG_PRINTF > PRINTF_NOMODIFIERS + #define IS_SHORT (h_modifier || (sizeof(int) == 2 && !l_modifier)) #else -#define IS_SHORT (sizeof(int) == 2) -#endif + #define IS_SHORT (sizeof(int) == 2) +#endif /* CONFIG_PRINTF > PRINTF_NOMODIFIERS */ -#ifdef FLOAT_SUPPORT +#if CONFIG_PRINTF > PRINTF_NOFLOAT -static char *float_conversion(MEM_ATTRIBUTE long double value, +static char *float_conversion(MEM_ATTRIBUTE max_float_t value, MEM_ATTRIBUTE short nr_of_digits, MEM_ATTRIBUTE char *buf, MEM_ATTRIBUTE char format_flag, MEM_ATTRIBUTE char g_flag, - MEM_ATTRIBUTE char alternate_flag) + MEM_ATTRIBUTE bool alternate_flag) { MEM_ATTRIBUTE char *cp; MEM_ATTRIBUTE char *buf_pointer; @@ -137,15 +178,11 @@ static char *float_conversion(MEM_ATTRIBUTE long double value, } nr_of_digits--; if (alternate_flag) - { /* %#G - No removal of trailing zeros */ g_flag = 0; - } else - { /* %G - Removal of trailing zeros */ - alternate_flag = 1; - } + alternate_flag = true; } /* %e or %E */ @@ -160,9 +197,7 @@ static char *float_conversion(MEM_ATTRIBUTE long double value, { *buf_pointer++ = '0'; if ((n = nr_of_digits) || alternate_flag) - { *buf_pointer++ = '.'; - } i = 0; while (--i > integral_10_log && nr_of_digits) { @@ -170,10 +205,8 @@ static char *float_conversion(MEM_ATTRIBUTE long double value, nr_of_digits--; } if (integral_10_log < (-n - 1)) - { /* Nothing more to do */ goto CLEAN_UP; - } dec_point_pos = 1; } else @@ -185,13 +218,11 @@ static char *float_conversion(MEM_ATTRIBUTE long double value, i = dec_point_pos; while (i <= nr_of_digits ) { - value -= (long double)(n = (short)value); /* n=Digit value=Remainder */ + value -= (max_float_t)(n = (short)value); /* n=Digit value=Remainder */ value *= 10; /* Prepare for next shot */ *buf_pointer++ = n + '0'; if ( ! i++ && (nr_of_digits || alternate_flag)) - { *buf_pointer++ = '.'; - } } /* Rounding possible */ @@ -209,9 +240,7 @@ static char *float_conversion(MEM_ATTRIBUTE long double value, n = 1; } else - { n = 0; - } } } while (cp-- > buf); if (n) @@ -228,9 +257,7 @@ static char *float_conversion(MEM_ATTRIBUTE long double value, cp--; } else - { *cp = *(cp - 1); - } cp--; } integral_10_log++; @@ -253,13 +280,9 @@ CLEAN_UP: if (g_flag) { while (*(buf_pointer - 1) == '0') - { buf_pointer--; - } if (*(buf_pointer - 1) == '.') - { buf_pointer--; - } } /* %e or %E */ @@ -272,9 +295,7 @@ CLEAN_UP: integral_10_log = -integral_10_log; } else - { *buf_pointer++ = '+'; - } n = 0; buf_pointer +=10; do @@ -290,9 +311,9 @@ CLEAN_UP: return (buf_pointer); } -#endif /* FLOAT_SUPPORT */ +#endif /* CONFIG_PRINTF > PRINTF_NOFLOAT */ -/*! +/** * This routine forms the core and entry of the formatter. * * The conversion performed conforms to the ANSI specification for "printf". @@ -303,50 +324,91 @@ PGM_FUNC(_formatted_write)(const char * PGM_ATTR format, void *secret_pointer, va_list ap) { +#if CONFIG_PRINTF > PRINTF_REDUCED MEM_ATTRIBUTE static char bad_conversion[] = "???"; MEM_ATTRIBUTE static char null_pointer[] = ""; -#ifndef REDUCED_SUPPORT - MEM_ATTRIBUTE char format_flag; MEM_ATTRIBUTE int precision; MEM_ATTRIBUTE int n; - MEM_ATTRIBUTE int field_width, nr_of_chars; - MEM_ATTRIBUTE char plus_space_flag, left_adjust, l_L_modifier; - MEM_ATTRIBUTE char h_modifier, alternate_flag; - MEM_ATTRIBUTE char nonzero_value; - MEM_ATTRIBUTE unsigned long ulong, div_factor; - -#ifdef FLOAT_SUPPORT - MEM_ATTRIBUTE long double fvalue; +#if CONFIG_PRINTF_COUNT_CHARS + MEM_ATTRIBUTE int nr_of_chars; +#endif + MEM_ATTRIBUTE int field_width; + MEM_ATTRIBUTE char format_flag; + enum PLUS_SPACE_FLAGS { + PSF_NONE, PSF_PLUS, PSF_MINUS + }; + enum DIV_FACTOR { + DIV_DEC, DIV_HEX, +#if CONFIG_PRINTF_OCTAL_FORMATTER + DIV_OCT, +#endif + }; + MEM_ATTRIBUTE struct { + enum PLUS_SPACE_FLAGS plus_space_flag : 2; +#if CONFIG_PRINTF_OCTAL_FORMATTER + enum DIV_FACTOR div_factor : 2; +#else + enum DIV_FACTOR div_factor : 1; +#endif + bool left_adjust : 1; + bool l_L_modifier : 1; + bool h_modifier : 1; + bool alternate_flag : 1; + bool nonzero_value : 1; + bool zeropad : 1; +#if CPU_HARVARD + bool progmem : 1; +#endif + } flags; + MEM_ATTRIBUTE unsigned long ulong; + +#if CONFIG_PRINTF > PRINTF_NOFLOAT + MEM_ATTRIBUTE max_float_t fvalue; #endif MEM_ATTRIBUTE char *buf_pointer; MEM_ATTRIBUTE char *ptr; MEM_ATTRIBUTE const char *hex; - MEM_ATTRIBUTE char zeropad; MEM_ATTRIBUTE char buf[FRMWRI_BUFSIZE]; +#if CONFIG_PRINTF_COUNT_CHARS nr_of_chars = 0; +#endif for (;;) /* Until full format string read */ { while ((format_flag = PGM_READ_CHAR(format++)) != '%') /* Until '%' or '\0' */ { if (!format_flag) +#if CONFIG_PRINTF_RETURN_COUNT return (nr_of_chars); - put_one_char (format_flag, secret_pointer); +#else + return 0; +#endif + put_one_char(format_flag, secret_pointer); +#if CONFIG_PRINTF_COUNT_CHARS nr_of_chars++; +#endif } if (PGM_READ_CHAR(format) == '%') /* %% prints as % */ { format++; put_one_char('%', secret_pointer); +#if CONFIG_PRINTF_COUNT_CHARS nr_of_chars++; +#endif continue; } - plus_space_flag = left_adjust = alternate_flag = zeropad = 0; + flags.left_adjust = false; + flags.alternate_flag = false; + flags.plus_space_flag = PSF_NONE; + flags.zeropad = false; +#if CPU_HARVARD + flags.progmem = false; +#endif ptr = buf_pointer = &buf[0]; - hex = "0123456789ABCDEF"; + hex = HEX_tab; /* check for leading '-', '+', ' ','#' or '0' flags */ for (;;) @@ -354,19 +416,19 @@ PGM_FUNC(_formatted_write)(const char * PGM_ATTR format, switch (PGM_READ_CHAR(format)) { case ' ': - if (plus_space_flag) + if (flags.plus_space_flag) goto NEXT_FLAG; case '+': - plus_space_flag = PGM_READ_CHAR(format); + flags.plus_space_flag = PSF_PLUS; goto NEXT_FLAG; case '-': - left_adjust++; + flags.left_adjust = true; goto NEXT_FLAG; case '#': - alternate_flag++; + flags.alternate_flag = true; goto NEXT_FLAG; case '0': - zeropad++; + flags.zeropad = true; goto NEXT_FLAG; } break; @@ -381,7 +443,7 @@ NEXT_FLAG: if (field_width < 0) { field_width = -field_width; - left_adjust++; + flags.left_adjust = true; } format++; } @@ -392,8 +454,8 @@ NEXT_FLAG: field_width = field_width * 10 + (PGM_READ_CHAR(format++) - '0'); } - if (left_adjust) - zeropad = 0; + if (flags.left_adjust) + flags.zeropad = false; /* Optional precision (or '*') */ if (PGM_READ_CHAR(format) == '.') @@ -423,18 +485,20 @@ NEXT_FLAG: * decimal point, "precision" will be -1. */ - l_L_modifier = h_modifier = 0; + flags.l_L_modifier = false; + flags.h_modifier = false; - /* Optional 'l','L' r 'h' modifier? */ + /* Optional 'l','L','z' or 'h' modifier? */ switch (PGM_READ_CHAR(format)) { case 'l': case 'L': - l_L_modifier++; + case 'z': + flags.l_L_modifier = true; format++; break; case 'h': - h_modifier++; + flags.h_modifier = true; format++; break; } @@ -446,7 +510,7 @@ NEXT_FLAG: */ switch (format_flag = PGM_READ_CHAR(format++)) { -#if 0 /* bernie */ +#if CONFIG_PRINTF_N_FORMATTER case 'n': if (sizeof(short) != sizeof(int)) { @@ -454,7 +518,7 @@ NEXT_FLAG: { if (h_modifier) *va_arg(ap, short *) = nr_of_chars; - else if (l_L_modifier) + else if (flags.l_L_modifier) *va_arg(ap, long *) = nr_of_chars; else *va_arg(ap, int *) = nr_of_chars; @@ -469,7 +533,7 @@ NEXT_FLAG: } else { - if (l_L_modifier) + if (flags.l_L_modifier) *va_arg(ap, long *) = nr_of_chars; else *va_arg(ap, int *) = nr_of_chars; @@ -481,22 +545,43 @@ NEXT_FLAG: ptr++; break; + /* Custom formatter for strings in program memory. */ + case 'S': +#if CPU_HARVARD + flags.progmem = true; +#endif + /* Fall trough */ + case 's': if ( !(buf_pointer = va_arg(ap, char *)) ) buf_pointer = null_pointer; if (precision < 0) precision = 10000; - for (n=0; *buf_pointer++ && n < precision; n++) - ; - ptr = --buf_pointer; - buf_pointer -= n; + + /* + * Move `ptr' to the last character of the + * string that will be actually printed. + */ + ptr = buf_pointer; +#if CPU_HARVARD + if (flags.progmem) + { + for (n=0; pgm_read_char(ptr) && n < precision; n++) + ++ptr; + } + else +#endif + for (n=0; *ptr && n < precision; n++) + ++ptr; break; +#if CONFIG_PRINTF_OCTAL_FORMATTER case 'o': - if (alternate_flag && !precision) + if (flags.alternate_flag && !precision) precision++; +#endif case 'x': - hex = "0123456789abcdef"; + hex = hex_tab; case 'u': case 'p': case 'X': @@ -504,83 +589,95 @@ NEXT_FLAG: #if defined(__AVR__) || defined(__I196__) /* 16bit pointers */ ulong = (unsigned long)(unsigned short)va_arg(ap, char *); #else /* 32bit pointers */ - ulong = (unsigned long)va_arg(ap, char *); + ulong = (unsigned long)va_arg(ap, char *); #endif /* 32bit pointers */ - else if (sizeof(short) == sizeof(int)) - ulong = l_L_modifier ? - va_arg(ap, unsigned long) : (unsigned long)va_arg(ap, unsigned int); + else if (flags.l_L_modifier) + ulong = va_arg(ap, unsigned long); + else if (flags.h_modifier) + ulong = (unsigned long)(unsigned short)va_arg(ap, unsigned int); else - ulong = h_modifier ? - (unsigned long)(unsigned short) va_arg(ap, int) - : (unsigned long)va_arg(ap, int); - div_factor = (format_flag == 'o') ? - 8 : (format_flag == 'u') ? 10 : 16; - plus_space_flag = 0; + ulong = va_arg(ap, unsigned int); + + flags.div_factor = +#if CONFIG_PRINTF_OCTAL_FORMATTER + (format_flag == 'o') ? DIV_OCT : +#endif + (format_flag == 'u') ? DIV_DEC : DIV_HEX; + flags.plus_space_flag = PSF_NONE; goto INTEGRAL_CONVERSION; case 'd': case 'i': - if (sizeof(short) == sizeof(long)) - { - if ( (long)(ulong = va_arg(ap, unsigned long)) < 0) - { - plus_space_flag = '-'; - ulong = (unsigned long)(-((signed long)ulong)); - } - } - else if (sizeof(short) == sizeof(int)) - { - if ( (long)(ulong = l_L_modifier ? - va_arg(ap,unsigned long) : (unsigned long)va_arg(ap,int)) < 0) - { - plus_space_flag = '-'; - ulong = (unsigned long)(-((signed long)ulong)); - } - } + if (flags.l_L_modifier) + ulong = (unsigned long)(long)va_arg(ap, long); else + ulong = (unsigned long)(long)va_arg(ap, int); + + /* Extract sign */ + if ((signed long)ulong < 0) { - if ( (signed long)(ulong = (unsigned long) (h_modifier ? - (short) va_arg(ap, int) : va_arg(ap,int))) < 0) - { - plus_space_flag = '-'; - ulong = (unsigned long)(-((signed long)ulong)); - } + flags.plus_space_flag = PSF_MINUS; + ulong = (unsigned long)(-((signed long)ulong)); } - div_factor = 10; + + flags.div_factor = DIV_DEC; /* Now convert to digits */ INTEGRAL_CONVERSION: ptr = buf_pointer = &buf[FRMWRI_BUFSIZE - 1]; - nonzero_value = (ulong != 0); + flags.nonzero_value = (ulong != 0); /* No char if zero and zero precision */ - if (precision != 0 || nonzero_value) - do - *--buf_pointer = hex[ulong % div_factor]; - while (ulong /= div_factor); + if (precision != 0 || flags.nonzero_value) + { + switch (flags.div_factor) + { + case DIV_DEC: + do + *--buf_pointer = hex[ulong % 10]; + while (ulong /= 10); + break; + + case DIV_HEX: + do + *--buf_pointer = hex[ulong % 16]; + while (ulong /= 16); + break; +#if CONFIG_PRINTF_OCTAL_FORMATTER + case DIV_OCT: + do + *--buf_pointer = hex[ulong % 8]; + while (ulong /= 8); + break; +#endif + } + } /* "precision" takes precedence */ if (precision < 0) - if (zeropad) - precision = field_width - (plus_space_flag != 0); + if (flags.zeropad) + precision = field_width - (flags.plus_space_flag != PSF_NONE); while (precision > (int)(ptr - buf_pointer)) *--buf_pointer = '0'; - if (alternate_flag && nonzero_value) + if (flags.alternate_flag && flags.nonzero_value) { if (format_flag == 'x' || format_flag == 'X') { *--buf_pointer = format_flag; *--buf_pointer = '0'; } +#if CONFIG_PRINTF_OCTAL_FORMATTER else if ((format_flag == 'o') && (*buf_pointer != '0')) { *--buf_pointer = '0'; } +#endif } + ASSERT(buf_pointer >= buf); break; -#ifdef FLOAT_SUPPORT +#if CONFIG_PRINTF > PRINTF_NOFLOAT case 'g': case 'G': n = 1; @@ -600,18 +697,18 @@ FLOATING_CONVERSION: { precision = 6; } - if (sizeof(double) != sizeof(long double)) + + if (sizeof(double) != sizeof(max_float_t)) { - if ( (fvalue = l_L_modifier ? - va_arg(ap,long double) : va_arg(ap,double)) < 0) - { - plus_space_flag = '-'; - fvalue = -fvalue; - } + fvalue = flags.l_L_modifier ? + va_arg(ap,max_float_t) : va_arg(ap,double); } - else if ( (fvalue = va_arg(ap,long double)) < 0) + else + fvalue = va_arg(ap,max_float_t); + + if (fvalue < 0) { - plus_space_flag = '-'; + flags.plus_space_flag = PSF_MINUS; fvalue = -fvalue; } ptr = float_conversion (fvalue, @@ -619,26 +716,16 @@ FLOATING_CONVERSION: buf_pointer += field_width, format_flag, (char)n, - alternate_flag); - if (zeropad) + flags.alternate_flag); + if (flags.zeropad) { - precision = field_width - (plus_space_flag != 0); + precision = field_width - (flags.plus_space_flag != PSF_NONE); while (precision > ptr - buf_pointer) *--buf_pointer = '0'; } break; -#else /* !FLOAT_SUPPORT */ - case 'g': - case 'G': - case 'f': - case 'e': - case 'E': - ptr = buf_pointer = bad_conversion; - while (*ptr) - ptr++; - break; -#endif /* !FLOAT_SUPPORT */ +#endif /* CONFIG_PRINTF <= PRINTF_NOFLOAT */ case '\0': /* Really bad place to find NUL in */ format--; @@ -646,7 +733,7 @@ FLOATING_CONVERSION: default: /* Undefined conversion! */ ptr = buf_pointer = bad_conversion; - ptr += 3; + ptr += sizeof(bad_conversion) - 1; break; } @@ -664,48 +751,72 @@ FLOATING_CONVERSION: } else { - n = field_width - precision - (plus_space_flag != 0); + n = field_width - precision - (flags.plus_space_flag != PSF_NONE); } /* emit any leading pad characters */ - if (!left_adjust) + if (!flags.left_adjust) while (--n >= 0) { put_one_char(' ', secret_pointer); +#if CONFIG_PRINTF_COUNT_CHARS nr_of_chars++; +#endif } /* emit flag characters (if any) */ - if (plus_space_flag) + if (flags.plus_space_flag) { - put_one_char(plus_space_flag, secret_pointer); + put_one_char(flags.plus_space_flag == PSF_PLUS ? '+' : '-', secret_pointer); +#if CONFIG_PRINTF_COUNT_CHARS nr_of_chars++; +#endif } - /* emit the string itself */ - while (--precision >= 0) +#if CPU_HARVARD + if (flags.progmem) { - put_one_char(*buf_pointer++, secret_pointer); - nr_of_chars++; + while (--precision >= 0) + { + put_one_char(pgm_read_char(buf_pointer++), secret_pointer); +#if CONFIG_PRINTF_COUNT_CHARS + nr_of_chars++; +#endif + } + } + else +#endif /* CPU_HARVARD */ + { + /* emit the string itself */ + while (--precision >= 0) + { + put_one_char(*buf_pointer++, secret_pointer); +#if CONFIG_PRINTF_COUNT_CHARS + nr_of_chars++; +#endif + } } /* emit trailing space characters */ - if (left_adjust) + if (flags.left_adjust) while (--n >= 0) { put_one_char(' ', secret_pointer); +#if CONFIG_PRINTF_COUNT_CHARS nr_of_chars++; +#endif } } -#else /* REDUCED_SUPPORT STARTS HERE */ +#else /* PRINTF_REDUCED starts here */ -#ifdef MODIFIERS_IN_REDUCED - char l_modifier, h_modifier; +#if CONFIG_PRINTF > PRINTF_NOMODIFIERS + bool l_modifier, h_modifier; unsigned long u_val, div_val; #else unsigned int u_val, div_val; -#endif +#endif /* CONFIG_PRINTF > PRINTF_NOMODIFIERS */ + char format_flag; unsigned int nr_of_chars, base; char outChar; @@ -718,43 +829,43 @@ FLOATING_CONVERSION: { if (!format_flag) return (nr_of_chars); - put_one_char (format_flag, secret_pointer); + put_one_char(format_flag, secret_pointer); nr_of_chars++; } -#ifdef MODIFIERS_IN_REDUCED +#if CONFIG_PRINTF > PRINTF_NOMODIFIERS /*=================================*/ /* Optional 'l' or 'h' modifiers ? */ /*=================================*/ - l_modifier = h_modifier = 0; + l_modifier = h_modifier = false; switch (PGM_READ_CHAR(format)) { case 'l': - l_modifier = 1; + l_modifier = true; format++; break; case 'h': - h_modifier = 1; + h_modifier = true; format++; break; } -#endif +#endif /* CONFIG_PRINTF > PRINTF_NOMODIFIERS */ switch (format_flag = PGM_READ_CHAR(format++)) { case 'c': format_flag = va_arg(ap, int); default: - put_one_char (format_flag, secret_pointer); + put_one_char(format_flag, secret_pointer); nr_of_chars++; continue; case 's': ptr = va_arg(ap, char *); - while (format_flag = *ptr++) + while ((format_flag = *ptr++)) { - put_one_char (format_flag, secret_pointer); + put_one_char(format_flag, secret_pointer); nr_of_chars++; } continue; @@ -784,7 +895,7 @@ FLOATING_CONVERSION: div_val = 0x10000000; CONVERSION_LOOP: -#ifdef MODIFIERS_IN_REDUCED +#if CONFIG_PRINTF > PRINTF_NOMODIFIERS if (h_modifier) u_val = (format_flag == 'd') ? (short)va_arg(ap, int) : (unsigned short)va_arg(ap, int); @@ -793,15 +904,15 @@ CONVERSION_LOOP: else u_val = (format_flag == 'd') ? va_arg(ap,int) : va_arg(ap,unsigned int); -#else +#else /* CONFIG_PRINTF > PRINTF_NOMODIFIERS */ u_val = va_arg(ap,int); -#endif +#endif /* CONFIG_PRINTF > PRINTF_NOMODIFIERS */ if (format_flag == 'd') { if (((int)u_val) < 0) { u_val = - u_val; - put_one_char ('-', secret_pointer); + put_one_char('-', secret_pointer); nr_of_chars++; } } @@ -813,11 +924,13 @@ CONVERSION_LOOP: { outChar = (u_val / div_val) + '0'; if (outChar > '9') + { if (format_flag == 'x') outChar += 'a'-'9'-1; else outChar += 'A'-'9'-1; - put_one_char (outChar, secret_pointer); + } + put_one_char(outChar, secret_pointer); nr_of_chars++; u_val %= div_val; div_val /= base; @@ -826,5 +939,7 @@ CONVERSION_LOOP: } /* end switch(format_flag...) */ } -#endif +#endif /* CONFIG_PRINTF > PRINTF_REDUCED */ } + +#endif /* CONFIG_PRINTF */