From e17e1a71c2923717723f7038d6e123b6452e0b13 Mon Sep 17 00:00:00 2001 From: rsc Date: Mon, 22 May 2006 14:54:34 +0000 Subject: incorporate changes from Google --- src/lib9/fmt/dofmt.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/lib9/fmt/dofmt.c') diff --git a/src/lib9/fmt/dofmt.c b/src/lib9/fmt/dofmt.c index 06f0a3d9..74697eb5 100644 --- a/src/lib9/fmt/dofmt.c +++ b/src/lib9/fmt/dofmt.c @@ -1,4 +1,6 @@ /* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ +/* Copyright (c) 2004 Google Inc.; see LICENSE */ + #include #include #include "plan9.h" @@ -454,11 +456,26 @@ __ifmt(Fmt *f) } } if(n == 0){ - *p-- = '0'; - n = 1; - if(fl & FmtApost) - __needsep(&ndig, &grouping); - fl &= ~FmtSharp; /* ??? */ + /* + * "The result of converting a zero value with + * a precision of zero is no characters." - ANSI + * + * "For o conversion, # increases the precision, if and only if + * necessary, to force the first digit of the result to be a zero + * (if the value and precision are both 0, a single 0 is printed)." - ANSI + */ + if(!(fl & FmtPrec) || f->prec != 0 || (f->r == 'o' && (fl & FmtSharp))){ + *p-- = '0'; + n = 1; + if(fl & FmtApost) + __needsep(&ndig, &grouping); + } + + /* + * Zero values don't get 0x. + */ + if(f->r == 'x' || f->r == 'X') + fl &= ~FmtSharp; } for(w = f->prec; n < w && p > buf+3; n++){ if((fl & FmtApost) && __needsep(&ndig, &grouping)){ -- cgit v1.2.3