First support for MSP430 CPU
[bertos.git] / bertos / mware / formatwr.c
index 3f11522e2c5e8daa63b3fa2156a824d3f7c1383d..0f3c00d18ee5f2dd354fef5d5ce43b22d2c0d7dd 100644 (file)
@@ -30,7 +30,6 @@
  *
  * -->
  *
- * \version $Id$
  *
  * \brief Basic "printf", "sprintf" and "fprintf" formatter.
  *
@@ -46,7 +45,7 @@
  *  -D CONFIG_PRINTF=PRINTF_FULL         Full ANSI printf formatter, with some C99 extensions
  *  -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', 'z' and 'h' modifiers in reduced version
+ *  -D CONFIG_PRINTF=PRINTF_NOMODIFIERS  Exclude "l", "z" and "h" modifiers in reduced version
  *  -D CONFIG_PRINTF=PRINTF_DISABLED     No formatter at all
  * \endcode
  *
        /* 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 FIXME:134 is too much, the code must be fixed to have a lower precision limit
+       #if CONFIG_FRMWRI_BUFSIZE
+               #define FRMWRI_BUFSIZE CONFIG_FRMWRI_BUFSIZE
+       #else
+               /* Conservative estimate. Max float is 3.40282e+038, so %f (but not %e or %g) must have
+                * space for: sign + all 38 digits + '.' + 6 decimal digits (default)
+                * Use a high value to avoid unexpected buffer overflows.
+                */
+               #define FRMWRI_BUFSIZE 134
+       #endif
 #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
+       #if CONFIG_FRMWRI_BUFSIZE
+               #define FRMWRI_BUFSIZE CONFIG_FRMWRI_BUFSIZE
+       #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
 #endif
 
 /* Probably useful for fancy microcontrollers such as the PIC, nobody knows. */
@@ -495,14 +504,21 @@ NEXT_FLAG:
                {
                        case 'l':
                        case 'L':
+               #if SIZEOF_SIZE_T == SIZEOF_LONG
                        case 'z':
                                flags.l_L_modifier = true;
+               #elif SIZEOF_SIZE_T == SIZEOF_INT
+                               flags.l_L_modifier = true;
+                       case 'z':
+               #endif
                                format++;
                                break;
+
                        case 'h':
                                flags.h_modifier = true;
                                format++;
                                break;
+
                }
 
                /*
@@ -588,7 +604,7 @@ NEXT_FLAG:
                        case 'p':
                        case 'X':
                                if (format_flag == 'p')
-#if defined(__AVR__) || defined(__I196__) /* 16bit pointers */
+#if defined(__AVR__) || defined(__I196__) || defined(__MSP430__) /* 16bit pointers */
                                        ulong = (unsigned long)(unsigned short)va_arg(ap, char *);
 #else /* 32bit pointers */
                                        ulong = (unsigned long)va_arg(ap, char *);
@@ -843,10 +859,13 @@ FLOATING_CONVERSION:
                switch (PGM_READ_CHAR(format))
                {
                        case 'l':
+               #if SIZEOF_SIZE_T == SIZEOF_LONG
                        case 'z':
-                               /* for the 'z' modifier, we make this assumption */
-                               STATIC_ASSERT(sizeof(size_t) == sizeof(long));
                                l_modifier = true;
+               #elif SIZEOF_SIZE_T == SIZEOF_INT
+                               l_modifier = true;
+                       case 'z':
+               #endif
                                format++;
                                break;