diff -r 9905b0ae4088 -r 68483503c990 src/base/cprintf.hh --- a/src/base/cprintf.hh Wed Oct 24 17:22:26 2012 -0400 +++ b/src/base/cprintf.hh Wed Oct 24 17:22:59 2012 -0400 @@ -59,6 +59,7 @@ Format fmt; void process(); + void process_flag(); public: Print(std::ostream &stream, const std::string &format); diff -r 9905b0ae4088 -r 68483503c990 src/base/cprintf.cc --- a/src/base/cprintf.cc Wed Oct 24 17:22:26 2012 -0400 +++ b/src/base/cprintf.cc Wed Oct 24 17:22:59 2012 -0400 @@ -69,9 +69,10 @@ while (*ptr) { switch (*ptr) { case '%': - if (ptr[1] != '%') - goto processing; - + if (ptr[1] != '%') { + process_flag(); + return; + } stream.put('%'); ptr += 2; break; @@ -93,10 +94,11 @@ break; } } +} - return; - - processing: +void +Print::process_flag() +{ bool done = false; bool end_number = false; bool have_precision = false; @@ -248,7 +250,20 @@ end_number = false; number = 0; } - } + + if (done) { + if ((fmt.format == Format::integer) && have_precision) { + // specified a . but not a float, set width + fmt.width = fmt.precision; + // precision requries digits for width, must fill with 0 + fmt.fill_zero = true; + } else if ((fmt.format == Format::floating) && !have_precision && + fmt.fill_zero) { + // ambiguous case, matching printf + fmt.precision = fmt.width; + } + } + } // end while ++ptr; }