changeset 388:3f878ae15050

Prepare to handle variable width and precision given as arguments.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 03 Mar 2016 13:44:25 +0200
parents 56ec224421a6
children 0e5511015bd2
files th_string.c
diffstat 1 files changed, 25 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/th_string.c	Thu Mar 03 13:17:40 2016 +0200
+++ b/th_string.c	Thu Mar 03 13:44:25 2016 +0200
@@ -411,17 +411,36 @@
             }
 
             // Get field width
-            while (th_isdigit(*fmt))
-                f_width = f_width * 10 + (*fmt++ - '0');
+            if (*fmt == '*')
+            {
+                f_width = va_arg(ap, int);
+                if (f_width < 0)
+                {
+                    f_flags |= TH_PF_LEFT;
+                    f_width = -f_width;
+                }
+            }
+            else
+            {
+                while (th_isdigit(*fmt))
+                    f_width = f_width * 10 + (*fmt++ - '0');
+            }
 
             // Check for field precision
             if (*fmt == '.')
             {
                 fmt++;
-                // If no digit after '.', precision is to be 0
-                f_prec = 0;
-                while (th_isdigit(*fmt))
-                    f_prec = f_prec * 10 + (*fmt++ - '0');
+                if (*fmt == '*')
+                {
+                    f_prec = va_arg(ap, int);
+                }
+                else
+                {
+                    // If no digit after '.', precision is to be 0
+                    f_prec = 0;
+                    while (th_isdigit(*fmt))
+                        f_prec = f_prec * 10 + (*fmt++ - '0');
+                }
             }
 
             // Check for length modifiers (NOT SUPPORTED CURRENTLY)