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/LICENSE | 10 ++++++---- src/lib9/fmt/dofmt.c | 27 ++++++++++++++++++++++----- src/lib9/fmt/fmtdef.h | 1 + src/lib9/fmt/fmtlocale.c | 7 +++---- src/lib9/fmt/fmtnull.c | 33 +++++++++++++++++++++++++++++++++ src/lib9/fmt/test.c | 2 ++ 6 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 src/lib9/fmt/fmtnull.c (limited to 'src/lib9') diff --git a/src/lib9/fmt/LICENSE b/src/lib9/fmt/LICENSE index f9ae4fcc..560e4d72 100644 --- a/src/lib9/fmt/LICENSE +++ b/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. 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)){ diff --git a/src/lib9/fmt/fmtdef.h b/src/lib9/fmt/fmtdef.h index 13d7f81e..1519ea42 100644 --- a/src/lib9/fmt/fmtdef.h +++ b/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); diff --git a/src/lib9/fmt/fmtlocale.c b/src/lib9/fmt/fmtlocale.c index f354efc8..9ebdced3 100644 --- a/src/lib9/fmt/fmtlocale.c +++ b/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, char *grouping) * and pointer into the grouping descriptor. */ int -__needsep(int *ndig, const char **grouping) +__needsep(int *ndig, char **grouping) { int group; diff --git a/src/lib9/fmt/fmtnull.c b/src/lib9/fmt/fmtnull.c new file mode 100644 index 00000000..a2f808ee --- /dev/null +++ b/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; +} + diff --git a/src/lib9/fmt/test.c b/src/lib9/fmt/test.c index 146692e5..4e1b7880 100644 --- a/src/lib9/fmt/test.c +++ b/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 -- cgit v1.2.3