Implement %0*X in diagnosticvf().
authorChristoph Mallon <christoph.mallon@gmx.de>
Wed, 23 May 2012 07:44:42 +0000 (09:44 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Wed, 23 May 2012 07:44:42 +0000 (09:44 +0200)
diagnostic.c

index a0b40e6..0afda37 100644 (file)
@@ -61,10 +61,21 @@ static void diagnosticvf(const char *const fmt, va_list ap)
                if (*f == '%') {
                        ++f;
 
-                       bool extended = false;
-                       if (*f == '#') {
-                               extended = true;
+                       bool extended  = false;
+                       bool flag_zero = false;
+                       for (;; ++f) {
+                               switch (*f) {
+                               case '#': extended  = true; break;
+                               case '0': flag_zero = true; break;
+                               default:  goto done_flags;
+                               }
+                       }
+done_flags:;
+
+                       int field_width = 0;
+                       if (*f == '*') {
                                ++f;
+                               field_width = va_arg(ap, int);
                        }
 
                        switch (*f) {
@@ -104,6 +115,13 @@ static void diagnosticvf(const char *const fmt, va_list ap)
                                        break;
                                }
 
+                               case 'X': {
+                                       unsigned int const val = va_arg(ap, unsigned int);
+                                       char const  *const fmt = flag_zero ? "%0*X" : "%*X";
+                                       fprintf(stderr, fmt, field_width, val);
+                                       break;
+                               }
+
                                case 'Y': {
                                        const symbol_t *const symbol = va_arg(ap, const symbol_t*);
                                        if (symbol == NULL)