incorporate changes from Google

This commit is contained in:
rsc 2006-05-22 14:54:34 +00:00
parent f8955f181e
commit e17e1a71c2
6 changed files with 67 additions and 13 deletions

View file

@ -2,16 +2,18 @@
* The authors of this software are Rob Pike and Ken Thompson, * The authors of this software are Rob Pike and Ken Thompson,
* with contributions from Mike Burrows and Sean Dorward. * 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 * Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice * 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 * 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 * or modification of this software and in all copies of the supporting
* documentation for such software. * documentation for such software.
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. * 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. This is a Unix port of the Plan 9 formatted I/O package.

View file

@ -1,4 +1,6 @@
/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ /* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */
/* Copyright (c) 2004 Google Inc.; see LICENSE */
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include "plan9.h" #include "plan9.h"
@ -454,11 +456,26 @@ __ifmt(Fmt *f)
} }
} }
if(n == 0){ if(n == 0){
*p-- = '0'; /*
n = 1; * "The result of converting a zero value with
if(fl & FmtApost) * a precision of zero is no characters." - ANSI
__needsep(&ndig, &grouping); *
fl &= ~FmtSharp; /* ??? */ * "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++){ for(w = f->prec; n < w && p > buf+3; n++){
if((fl & FmtApost) && __needsep(&ndig, &grouping)){ if((fl & FmtApost) && __needsep(&ndig, &grouping)){

View file

@ -41,6 +41,7 @@ void __fmtunlock(void);
int __ifmt(Fmt *f); int __ifmt(Fmt *f);
int __isInf(double d, int sign); int __isInf(double d, int sign);
int __isNaN(double d); int __isNaN(double d);
int __needsep(int*, char**);
int __needsquotes(char *s, int *quotelenp); int __needsquotes(char *s, int *quotelenp);
int __percentfmt(Fmt *f); int __percentfmt(Fmt *f);
void __quotesetup(char *s, Rune *r, int nin, int nout, Quoteinfo *q, int sharp, int runesout); void __quotesetup(char *s, Rune *r, int nin, int nout, Quoteinfo *q, int sharp, int runesout);

View file

@ -1,12 +1,11 @@
/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ /* Copyright (c) 2004 Google Inc.; see LICENSE */
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include "plan9.h" #include "plan9.h"
#include "fmt.h" #include "fmt.h"
#include "fmtdef.h" #include "fmtdef.h"
/* XXX GOOGLE COPYRIGHT */
/* /*
* Fill in the internationalization stuff in the State structure. * Fill in the internationalization stuff in the State structure.
* For nil arguments, provide the sensible defaults: * 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. * and pointer into the grouping descriptor.
*/ */
int int
__needsep(int *ndig, const char **grouping) __needsep(int *ndig, char **grouping)
{ {
int group; int group;

33
src/lib9/fmt/fmtnull.c Normal file
View file

@ -0,0 +1,33 @@
/* Copyright (c) 2004 Google Inc.; see LICENSE */
#include <stdarg.h>
#include <string.h>
#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;
}

View file

@ -1,4 +1,6 @@
/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ /* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */
/* Copyright (c) 2004 Google Inc.; see LICENSE */
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <utf.h> #include <utf.h>