changeset 229:38a0719359ef

Add some comments.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 16 Feb 2016 14:03:51 +0200
parents ca9cd98dbcff
children 0b243bc5ffd6
files th_string.c
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/th_string.c	Tue Feb 16 13:59:51 2016 +0200
+++ b/th_string.c	Tue Feb 16 14:03:51 2016 +0200
@@ -120,12 +120,14 @@
     if (radix > 16)
         return 0;
 
+    // Check for negative value
     if (val < 0)
     {
         neg = TRUE;
         val = -val;
     }
 
+    // Render the value to a string in buf (reversed)
     do
     {
         int digit = val % radix;
@@ -139,6 +141,7 @@
     while (val > 0 && pos < sizeof(buf) - 1);
     buf[pos] = 0;
 
+    // Do we want a sign prefix? Not for unsigned values
     if (!unsig)
     {
         char ch = sign ? (neg ? '-' : '+') : (neg ? '-' : 0);
@@ -146,8 +149,10 @@
             goto out;
     }
 
+    // Calculate necessary padding, if any
     int nwidth = width - pos;
 
+    // Suffix padding?
     if (nwidth > 0 && padMode != '-')
     {
         while (nwidth--)
@@ -155,12 +160,14 @@
                 goto out;
     }
 
+    // Output the value
     while (pos--)
     {
         if ((ret = vputch(ctx, buf[pos])) == EOF)
             goto out;
     }
 
+    // Postfix padding?
     if (nwidth > 0 && padMode == '-')
     {
         while (nwidth--)
@@ -277,7 +284,7 @@
                     goto out;
 
                 case 's':
-                    if (padMode != '-' && padMode != ' ')
+                    if ((padMode != '-' && padMode != ' ') || sign)
                         goto out;
 
                     if ((ret = th_vput_str(ctx, vputch, va_arg(ap, char *), padMode, width)) == EOF)