commit e17e1a71c2923717723f7038d6e123b6452e0b13 from: rsc date: Mon May 22 14:54:34 2006 UTC incorporate changes from Google commit - f8955f181efa175573ccecc71a19464fdba50ef5 commit + e17e1a71c2923717723f7038d6e123b6452e0b13 blob - f9ae4fccc95fb497567b5c1cc0f580e3ce39cc27 blob + 560e4d720318a318f02ff2b5a86fb3a359509bad --- src/lib9/fmt/LICENSE +++ src/lib9/fmt/LICENSE @@ -2,16 +2,18 @@ * The authors of this software are Rob Pike and Ken Thompson, * with contributions from Mike Burrows and Sean Dorward. * - * Copyright (c) 2002-2006 by Lucent Technologies. + * Copyright (c) 2002-2006 by Lucent Technologies. + * Portions Copyright (c) 2004 Google Inc. + * * Permission to use, copy, modify, and distribute this software for any * purpose without fee is hereby granted, provided that this entire notice * is included in all copies of any software which is or includes a copy * or modification of this software and in all copies of the supporting * documentation for such software. * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY - * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY - * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. + * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES + * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING + * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. */ This is a Unix port of the Plan 9 formatted I/O package. blob - 06f0a3d93eb5c490e863120cb2afc2da7abef2b9 blob + 74697eb543ef6fbeb68ab1fcb7efc7bd374d1bf8 --- src/lib9/fmt/dofmt.c +++ 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)){ blob - 13d7f81ee2825f71123fe93e6b92a0d2bdd4d3fc blob + 1519ea42dd89e4ebb8c7f2642c1c41498aac79a6 --- src/lib9/fmt/fmtdef.h +++ src/lib9/fmt/fmtdef.h @@ -41,6 +41,7 @@ void __fmtunlock(void); int __ifmt(Fmt *f); int __isInf(double d, int sign); int __isNaN(double d); +int __needsep(int*, char**); int __needsquotes(char *s, int *quotelenp); int __percentfmt(Fmt *f); void __quotesetup(char *s, Rune *r, int nin, int nout, Quoteinfo *q, int sharp, int runesout); blob - f354efc8aca02c7a1aa3485084792a801b8d1384 blob + 9ebdced389b8010bfe149b69f88842324910e56e --- src/lib9/fmt/fmtlocale.c +++ src/lib9/fmt/fmtlocale.c @@ -1,12 +1,11 @@ -/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ +/* Copyright (c) 2004 Google Inc.; see LICENSE */ + #include #include #include "plan9.h" #include "fmt.h" #include "fmtdef.h" -/* XXX GOOGLE COPYRIGHT */ - /* * Fill in the internationalization stuff in the State structure. * For nil arguments, provide the sensible defaults: @@ -35,7 +34,7 @@ fmtlocaleinit(Fmt *f, char *decimal, char *thousands, * and pointer into the grouping descriptor. */ int -__needsep(int *ndig, const char **grouping) +__needsep(int *ndig, char **grouping) { int group; blob - /dev/null blob + a2f808ee61e6ed3bc83b71cf172edaa744db0549 (mode 644) --- /dev/null +++ src/lib9/fmt/fmtnull.c @@ -0,0 +1,33 @@ +/* Copyright (c) 2004 Google Inc.; see LICENSE */ +#include +#include +#include "plan9.h" +#include "fmt.h" +#include "fmtdef.h" + +/* + * Absorb output without using resources. + */ +static Rune nullbuf[32]; + +static int +__fmtnullflush(Fmt *f) +{ + f->to = nullbuf; + f->nfmt = 0; + return 0; +} + +int +fmtnullinit(Fmt *f) +{ + memset(&f, 0, sizeof *f); + f->runes = 1; + f->start = nullbuf; + f->to = nullbuf; + f->stop = nullbuf+nelem(nullbuf); + f->flush = __fmtnullflush; + fmtlocaleinit(f, nil, nil, nil); + return 0; +} + blob - 146692e50a8562fbfbaede597bd2f7ea40e67aad blob + 4e1b788013ddd34b39b58f826b9955507fcd9a3d --- src/lib9/fmt/test.c +++ src/lib9/fmt/test.c @@ -1,4 +1,6 @@ /* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ +/* Copyright (c) 2004 Google Inc.; see LICENSE */ + #include #include #include