diff options
author | rsc <devnull@localhost> | 2006-05-21 20:49:16 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2006-05-21 20:49:16 +0000 |
commit | 85231fd8cdf32d861e196d7dfa827b7239157817 (patch) | |
tree | 467cd12c69cbb79e90e28a9750a4397cc3b80143 /src/lib9/fmt | |
parent | 8d7133308db580d2356d5d1dd30f0b9a1f0a7417 (diff) | |
download | plan9port-85231fd8cdf32d861e196d7dfa827b7239157817.tar.gz plan9port-85231fd8cdf32d861e196d7dfa827b7239157817.tar.bz2 plan9port-85231fd8cdf32d861e196d7dfa827b7239157817.zip |
fmt changes from Google
Diffstat (limited to 'src/lib9/fmt')
38 files changed, 211 insertions, 504 deletions
diff --git a/src/lib9/fmt/LICENSE b/src/lib9/fmt/LICENSE index 5dc21cb5..f9ae4fcc 100644 --- a/src/lib9/fmt/LICENSE +++ b/src/lib9/fmt/LICENSE @@ -1,6 +1,8 @@ /* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. + * 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. * 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 @@ -10,10 +12,9 @@ * 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. -*/ + */ This is a Unix port of the Plan 9 formatted I/O package. -Please send comments about the packaging -to Russ Cox <rsc@post.harvard.edu>. +Please send comments about the packaging to Russ Cox <rsc@swtch.com>. diff --git a/src/lib9/fmt/charstod.c b/src/lib9/fmt/charstod.c index cbe6d3dd..6ff57676 100644 --- a/src/lib9/fmt/charstod.c +++ b/src/lib9/fmt/charstod.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" diff --git a/src/lib9/fmt/dofmt.c b/src/lib9/fmt/dofmt.c index 97bbc928..06f0a3d9 100644 --- a/src/lib9/fmt/dofmt.c +++ b/src/lib9/fmt/dofmt.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" @@ -97,7 +85,7 @@ __fmtflush(Fmt *f, void *t, int len) /* * put a formatted block of memory sz bytes long of n runes into the output buffer, - * left/right justified in a field of at least f->width charactes + * left/right justified in a field of at least f->width characters (if FmtWidth is set) */ int __fmtpad(Fmt *f, int n) @@ -139,8 +127,10 @@ __fmtcpy(Fmt *f, const void *vm, int n, int sz) m = (char*)vm; me = m + sz; - w = f->width; fl = f->flags; + w = 0; + if(fl & FmtWidth) + w = f->width; if((fl & FmtPrec) && n > f->prec) n = f->prec; if(f->runes){ @@ -194,8 +184,10 @@ __fmtrcpy(Fmt *f, const void *vm, int n) int w; m = (Rune*)vm; - w = f->width; fl = f->flags; + w = 0; + if(fl & FmtWidth) + w = f->width; if((fl & FmtPrec) && n > f->prec) n = f->prec; if(f->runes){ @@ -324,10 +316,14 @@ __percentfmt(Fmt *f) int __ifmt(Fmt *f) { - char buf[70], *p, *conv; + char buf[140], *p, *conv; + /* 140: for 64 bits of binary + 3-byte sep every 4 digits */ uvlong vu; ulong u; int neg, base, i, n, fl, w, isv; + int ndig, len, excess, bytelen; + char *grouping; + char *thousands; neg = 0; fl = f->flags; @@ -339,11 +335,11 @@ __ifmt(Fmt *f) * Unsigned verbs for ANSI C */ switch(f->r){ - case 'x': - case 'X': case 'o': - case 'u': case 'p': + case 'u': + case 'x': + case 'X': fl |= FmtUnsigned; fl &= ~(FmtSign|FmtSpace); break; @@ -381,21 +377,25 @@ __ifmt(Fmt *f) u = va_arg(f->args, int); } conv = "0123456789abcdef"; + grouping = "\4"; /* for hex, octal etc. (undefined by spec but nice) */ + thousands = f->thousands; switch(f->r){ case 'd': case 'i': case 'u': base = 10; - break; - case 'x': - base = 16; + grouping = f->grouping; break; case 'X': - base = 16; conv = "0123456789ABCDEF"; + /* fall through */ + case 'x': + base = 16; + thousands = ":"; break; case 'b': base = 2; + thousands = ":"; break; case 'o': base = 8; @@ -413,7 +413,11 @@ __ifmt(Fmt *f) } } p = buf + sizeof buf - 1; - n = 0; + n = 0; /* in runes */ + excess = 0; /* number of bytes > number runes */ + ndig = 0; + len = utflen(thousands); + bytelen = strlen(thousands); if(isv){ while(vu){ i = vu % base; @@ -422,6 +426,12 @@ __ifmt(Fmt *f) *p-- = ','; n++; } + if((fl & FmtApost) && __needsep(&ndig, &grouping)){ + n += len; + excess += bytelen - len; + p -= bytelen; + memmove(p+1, thousands, bytelen); + } *p-- = conv[i]; n++; } @@ -433,6 +443,12 @@ __ifmt(Fmt *f) *p-- = ','; n++; } + if((fl & FmtApost) && __needsep(&ndig, &grouping)){ + n += len; + excess += bytelen - len; + p -= bytelen; + memmove(p+1, thousands, bytelen); + } *p-- = conv[i]; n++; } @@ -440,9 +456,19 @@ __ifmt(Fmt *f) if(n == 0){ *p-- = '0'; n = 1; + if(fl & FmtApost) + __needsep(&ndig, &grouping); + 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)){ + n += len; + excess += bytelen - len; + p -= bytelen; + memmove(p+1, thousands, bytelen); + } *p-- = '0'; + } if(neg || (fl & (FmtSign|FmtSpace))) n++; if(fl & FmtSharp){ @@ -456,9 +482,19 @@ __ifmt(Fmt *f) } } if((fl & FmtZero) && !(fl & (FmtLeft|FmtPrec))){ - for(w = f->width; n < w && p > buf+3; n++) + w = 0; + if(fl & FmtWidth) + w = f->width; + for(; n < w && p > buf+3; n++){ + if((fl & FmtApost) && __needsep(&ndig, &grouping)){ + n += len; + excess += bytelen - len; + p -= bytelen; + memmove(p+1, thousands, bytelen); + } *p-- = '0'; - f->width = 0; + } + f->flags &= ~FmtWidth; } if(fl & FmtSharp){ if(base == 16) @@ -473,7 +509,7 @@ __ifmt(Fmt *f) else if(fl & FmtSpace) *p-- = ' '; f->flags &= ~FmtPrec; - return __fmtcpy(f, p + 1, n, n); + return __fmtcpy(f, p + 1, n, n + excess); } int @@ -514,6 +550,9 @@ __flagfmt(Fmt *f) case '#': f->flags |= FmtSharp; break; + case '\'': + f->flags |= FmtApost; + break; case ' ': f->flags |= FmtSpace; break; diff --git a/src/lib9/fmt/dorfmt.c b/src/lib9/fmt/dorfmt.c index 034dea14..21e42ebc 100644 --- a/src/lib9/fmt/dorfmt.c +++ b/src/lib9/fmt/dorfmt.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" @@ -19,6 +7,7 @@ /* format the output into f->to and return the number of characters fmted */ +/* BUG: THIS FILE IS NOT UPDATED TO THE NEW SPEC */ int dorfmt(Fmt *f, const Rune *fmt) { @@ -30,8 +19,8 @@ dorfmt(Fmt *f, const Rune *fmt) nfmt = f->nfmt; for(;;){ if(f->runes){ - rt = f->to; - rs = f->stop; + rt = (Rune*)f->to; + rs = (Rune*)f->stop; while((r = *fmt++) && r != '%'){ FMTRCHAR(f, rt, rs, r); } @@ -41,8 +30,8 @@ dorfmt(Fmt *f, const Rune *fmt) return f->nfmt - nfmt; f->stop = rs; }else{ - t = f->to; - s = f->stop; + t = (char*)f->to; + s = (char*)f->stop; while((r = *fmt++) && r != '%'){ FMTRUNE(f, t, f->stop, r); } @@ -53,7 +42,7 @@ dorfmt(Fmt *f, const Rune *fmt) f->stop = s; } - fmt = __fmtdispatch(f, (Rune*)fmt, 1); + fmt = (Rune*)__fmtdispatch(f, (Rune*)fmt, 1); if(fmt == nil) return -1; } diff --git a/src/lib9/fmt/errfmt.c b/src/lib9/fmt/errfmt.c index b0eae735..7d194705 100644 --- a/src/lib9/fmt/errfmt.c +++ b/src/lib9/fmt/errfmt.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <errno.h> #include <string.h> diff --git a/src/lib9/fmt/fltfmt.c b/src/lib9/fmt/fltfmt.c index 9c94f156..8288a966 100644 --- a/src/lib9/fmt/fltfmt.c +++ b/src/lib9/fmt/fltfmt.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdio.h> #include <math.h> #include <float.h> diff --git a/src/lib9/fmt/fmt.c b/src/lib9/fmt/fmt.c index 642de8c7..66093fd0 100644 --- a/src/lib9/fmt/fmt.c +++ b/src/lib9/fmt/fmt.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" @@ -29,7 +17,7 @@ struct Convfmt volatile Fmts fmt; /* for spin lock in fmtfmt; avoids race due to write order */ }; -struct +static struct { /* lock by calling __fmtlock, __fmtunlock */ int nfmt; @@ -40,6 +28,7 @@ static Convfmt knownfmt[] = { ' ', __flagfmt, '#', __flagfmt, '%', __percentfmt, + '\'', __flagfmt, '+', __flagfmt, ',', __flagfmt, '-', __flagfmt, diff --git a/src/lib9/fmt/fmtdef.h b/src/lib9/fmt/fmtdef.h index 5a63f9be..13d7f81e 100644 --- a/src/lib9/fmt/fmtdef.h +++ b/src/lib9/fmt/fmtdef.h @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ /* * dofmt -- format to a buffer @@ -66,9 +54,9 @@ int __strfmt(Fmt *f); #define FMTCHAR(f, t, s, c)\ do{\ if(t + 1 > (char*)s){\ - t = __fmtflush(f, t, 1);\ + t = (char*)__fmtflush(f, t, 1);\ if(t != nil)\ - s = f->stop;\ + s = (char*)f->stop;\ else\ return -1;\ }\ @@ -78,9 +66,9 @@ int __strfmt(Fmt *f); #define FMTRCHAR(f, t, s, c)\ do{\ if(t + 1 > (Rune*)s){\ - t = __fmtflush(f, t, sizeof(Rune));\ + t = (Rune*)__fmtflush(f, t, sizeof(Rune));\ if(t != nil)\ - s = f->stop;\ + s = (Rune*)f->stop;\ else\ return -1;\ }\ @@ -92,9 +80,9 @@ int __strfmt(Fmt *f); Rune _rune;\ int _runelen;\ if(t + UTFmax > (char*)s && t + (_runelen = runelen(r)) > (char*)s){\ - t = __fmtflush(f, t, _runelen);\ + t = (char*)__fmtflush(f, t, _runelen);\ if(t != nil)\ - s = f->stop;\ + s = (char*)f->stop;\ else\ return -1;\ }\ diff --git a/src/lib9/fmt/fmtfd.c b/src/lib9/fmt/fmtfd.c index 9f35f02a..1e7998b0 100644 --- a/src/lib9/fmt/fmtfd.c +++ b/src/lib9/fmt/fmtfd.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" @@ -41,6 +29,8 @@ fmtfdinit(Fmt *f, int fd, char *buf, int size) f->stop = buf + size; f->flush = __fmtFdFlush; f->farg = (void*)(uintptr_t)fd; + f->flags = 0; f->nfmt = 0; + fmtlocaleinit(f, nil, nil, nil); return 0; } diff --git a/src/lib9/fmt/fmtfdflush.c b/src/lib9/fmt/fmtfdflush.c index b615416a..7abb982a 100644 --- a/src/lib9/fmt/fmtfdflush.c +++ b/src/lib9/fmt/fmtfdflush.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <unistd.h> #include "plan9.h" diff --git a/src/lib9/fmt/fmtlocale.c b/src/lib9/fmt/fmtlocale.c new file mode 100644 index 00000000..f354efc8 --- /dev/null +++ b/src/lib9/fmt/fmtlocale.c @@ -0,0 +1,56 @@ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ +#include <stdarg.h> +#include <string.h> +#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: + * decimal is a period + * thousands separator is a comma + * thousands are marked every three digits + */ +void +fmtlocaleinit(Fmt *f, char *decimal, char *thousands, char *grouping) +{ + if(decimal == nil || decimal[0] == '\0') + decimal = "."; + if(thousands == nil) + thousands = ","; + if(grouping == nil) + grouping = "\3"; + f->decimal = decimal; + f->thousands = thousands; + f->grouping = grouping; +} + +/* + * We are about to emit a digit in e.g. %'d. If that digit would + * overflow a thousands (e.g.) grouping, tell the caller to emit + * the thousands separator. Always advance the digit counter + * and pointer into the grouping descriptor. + */ +int +__needsep(int *ndig, const char **grouping) +{ + int group; + + (*ndig)++; + group = *(unsigned char*)*grouping; + /* CHAR_MAX means no further grouping. \0 means we got the empty string */ + if(group == 0xFF || group == 0x7f || group == 0x00) + return 0; + if(*ndig > group){ + /* if we're at end of string, continue with this grouping; else advance */ + if((*grouping)[1] != '\0') + (*grouping)++; + *ndig = 1; + return 1; + } + return 0; +} + diff --git a/src/lib9/fmt/fmtlock.c b/src/lib9/fmt/fmtlock.c index 5c7afbc0..cabe05f4 100644 --- a/src/lib9/fmt/fmtlock.c +++ b/src/lib9/fmt/fmtlock.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include "plan9.h" #include "fmt.h" diff --git a/src/lib9/fmt/fmtprint.c b/src/lib9/fmt/fmtprint.c index 5ba59d34..868127e0 100644 --- a/src/lib9/fmt/fmtprint.c +++ b/src/lib9/fmt/fmtprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" diff --git a/src/lib9/fmt/fmtquote.c b/src/lib9/fmt/fmtquote.c index 2304c4e5..5b8f9fd4 100644 --- a/src/lib9/fmt/fmtquote.c +++ b/src/lib9/fmt/fmtquote.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" @@ -120,8 +108,10 @@ qstrfmt(char *sin, Rune *rin, Quoteinfo *q, Fmt *f) rm = rin; rme = rm + q->nrunesin; - w = f->width; fl = f->flags; + w = 0; + if(fl & FmtWidth) + w = f->width; if(f->runes){ if(!(fl & FmtLeft) && __rfmtpad(f, w - q->nrunesout) < 0) return -1; diff --git a/src/lib9/fmt/fmtrune.c b/src/lib9/fmt/fmtrune.c index b1ddd3b6..fa424687 100644 --- a/src/lib9/fmt/fmtrune.c +++ b/src/lib9/fmt/fmtrune.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" diff --git a/src/lib9/fmt/fmtstr.c b/src/lib9/fmt/fmtstr.c index a5f8f8d7..34d4a588 100644 --- a/src/lib9/fmt/fmtstr.c +++ b/src/lib9/fmt/fmtstr.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdlib.h> #include <stdarg.h> #include "plan9.h" @@ -23,5 +11,6 @@ fmtstrflush(Fmt *f) if(f->start == nil) return nil; *(char*)f->to = '\0'; + f->to = f->start; return (char*)f->start; } diff --git a/src/lib9/fmt/fmtvprint.c b/src/lib9/fmt/fmtvprint.c index cb7ffbe8..66d3929f 100644 --- a/src/lib9/fmt/fmtvprint.c +++ b/src/lib9/fmt/fmtvprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" diff --git a/src/lib9/fmt/fprint.c b/src/lib9/fmt/fprint.c index 043202c8..43b07af3 100644 --- a/src/lib9/fmt/fprint.c +++ b/src/lib9/fmt/fprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include "plan9.h" #include "fmt.h" diff --git a/src/lib9/fmt/pow10.c b/src/lib9/fmt/pow10.c index 5d578f92..7e2cde2a 100644 --- a/src/lib9/fmt/pow10.c +++ b/src/lib9/fmt/pow10.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" diff --git a/src/lib9/fmt/print.c b/src/lib9/fmt/print.c index d038cee7..c0b08344 100644 --- a/src/lib9/fmt/print.c +++ b/src/lib9/fmt/print.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include "plan9.h" #include "fmt.h" diff --git a/src/lib9/fmt/runefmtstr.c b/src/lib9/fmt/runefmtstr.c index e17bc166..52ee96a0 100644 --- a/src/lib9/fmt/runefmtstr.c +++ b/src/lib9/fmt/runefmtstr.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <stdlib.h> #include "plan9.h" @@ -23,5 +11,6 @@ runefmtstrflush(Fmt *f) if(f->start == nil) return nil; *(Rune*)f->to = '\0'; + f->to = f->start; return f->start; } diff --git a/src/lib9/fmt/runeseprint.c b/src/lib9/fmt/runeseprint.c index 8e01c079..ffc72cb9 100644 --- a/src/lib9/fmt/runeseprint.c +++ b/src/lib9/fmt/runeseprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" diff --git a/src/lib9/fmt/runesmprint.c b/src/lib9/fmt/runesmprint.c index 03143a94..5ddb2ba6 100644 --- a/src/lib9/fmt/runesmprint.c +++ b/src/lib9/fmt/runesmprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" diff --git a/src/lib9/fmt/runesnprint.c b/src/lib9/fmt/runesnprint.c index 2e6ad6c6..50b4813d 100644 --- a/src/lib9/fmt/runesnprint.c +++ b/src/lib9/fmt/runesnprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" diff --git a/src/lib9/fmt/runesprint.c b/src/lib9/fmt/runesprint.c index 1dad4df7..f7f4d29a 100644 --- a/src/lib9/fmt/runesprint.c +++ b/src/lib9/fmt/runesprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" diff --git a/src/lib9/fmt/runevseprint.c b/src/lib9/fmt/runevseprint.c index 2359c817..d789cbe7 100644 --- a/src/lib9/fmt/runevseprint.c +++ b/src/lib9/fmt/runevseprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" diff --git a/src/lib9/fmt/runevsmprint.c b/src/lib9/fmt/runevsmprint.c index f83dce29..ef273752 100644 --- a/src/lib9/fmt/runevsmprint.c +++ b/src/lib9/fmt/runevsmprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ /* * Plan 9 port version must include libc.h in order to * get Plan 9 debugging malloc, which sometimes returns @@ -69,6 +57,7 @@ runefmtstrinit(Fmt *f) f->flush = runeFmtStrFlush; f->farg = (void*)(uintptr)n; f->nfmt = 0; + fmtlocaleinit(f, nil, nil, nil); return 0; } diff --git a/src/lib9/fmt/runevsnprint.c b/src/lib9/fmt/runevsnprint.c index 431868a3..f1e28e74 100644 --- a/src/lib9/fmt/runevsnprint.c +++ b/src/lib9/fmt/runevsnprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <string.h> #include "plan9.h" @@ -32,6 +20,7 @@ runevsnprint(Rune *buf, int len, char *fmt, va_list args) f.farg = nil; f.nfmt = 0; VA_COPY(f.args,args); + fmtlocaleinit(&f, nil, nil, nil); dofmt(&f, fmt); VA_END(f.args); *(Rune*)f.to = '\0'; diff --git a/src/lib9/fmt/seprint.c b/src/lib9/fmt/seprint.c index 38bdf5f5..0729b4d7 100644 --- a/src/lib9/fmt/seprint.c +++ b/src/lib9/fmt/seprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include "plan9.h" #include "fmt.h" diff --git a/src/lib9/fmt/smprint.c b/src/lib9/fmt/smprint.c index f46c964d..8640a5fd 100644 --- a/src/lib9/fmt/smprint.c +++ b/src/lib9/fmt/smprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include "plan9.h" #include "fmt.h" diff --git a/src/lib9/fmt/snprint.c b/src/lib9/fmt/snprint.c index 17ce0e2d..64d2da43 100644 --- a/src/lib9/fmt/snprint.c +++ b/src/lib9/fmt/snprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include "plan9.h" #include "fmt.h" diff --git a/src/lib9/fmt/sprint.c b/src/lib9/fmt/sprint.c index 1ab5ce62..9e3cb63e 100644 --- a/src/lib9/fmt/sprint.c +++ b/src/lib9/fmt/sprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include <fmt.h> #include "plan9.h" diff --git a/src/lib9/fmt/strtod.c b/src/lib9/fmt/strtod.c index c19c2849..1dfd1b07 100644 --- a/src/lib9/fmt/strtod.c +++ b/src/lib9/fmt/strtod.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdlib.h> #include <math.h> #include <ctype.h> @@ -239,7 +227,7 @@ fmtstrtod(const char *as, char **aas) /* close approx by naive conversion */ mid[0] = 0; mid[1] = 1; - for(i=0; c=a[i]; i++) { + for(i=0; (c=a[i]) != '\0'; i++) { mid[0] = mid[0]*10 + (c-'0'); mid[1] = mid[1]*10; if(i >= 8) @@ -521,7 +509,7 @@ xcmp(char *a, char *b) { int c1, c2; - while(c1 = *b++) { + while((c1 = *b++) != '\0') { c2 = *a++; if(isupper(c2)) c2 = tolower(c2); diff --git a/src/lib9/fmt/test.c b/src/lib9/fmt/test.c index 04296e21..146692e5 100644 --- a/src/lib9/fmt/test.c +++ b/src/lib9/fmt/test.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdio.h> #include <stdarg.h> #include <utf.h> @@ -40,5 +28,24 @@ main(int argc, char *argv[]) print("%d\n", 23); print("%i\n", 23); print("%0.10d\n", 12345); + + /* test %4$d formats */ + print("%3$d %4$06d %2$d %1$d\n", 444, 333, 111, 222); + print("%3$d %4$06d %2$d %1$d\n", 444, 333, 111, 222); + print("%3$d %4$*5$06d %2$d %1$d\n", 444, 333, 111, 222, 20); + print("%3$hd %4$*5$06d %2$d %1$d\n", 444, 333, (short)111, 222, 20); + print("%3$lld %4$*5$06d %2$d %1$d\n", 444, 333, 111LL, 222, 20); + + /* test %'d formats */ + print("%'d %'d %'d\n", 1, 2222, 33333333); + print("%'019d\n", 0); + print("%08d %08d %08d\n", 1, 2222, 33333333); + print("%'08d %'08d %'08d\n", 1, 2222, 33333333); + print("%'x %'X %'b\n", 0x11111111, 0xabcd1234, 12345); + print("%'lld %'lld %'lld\n", 1LL, 222222222LL, 3333333333333LL); + print("%019lld %019lld %019lld\n", 1LL, 222222222LL, 3333333333333LL); + print("%'019lld %'019lld %'019lld\n", 1LL, 222222222LL, 3333333333333LL); + print("%'020lld %'020lld %'020lld\n", 1LL, 222222222LL, 3333333333333LL); + print("%'llx %'llX %'llb\n", 0x111111111111LL, 0xabcd12345678LL, 112342345LL); return 0; } diff --git a/src/lib9/fmt/vfprint.c b/src/lib9/fmt/vfprint.c index e5a7da3a..a75e224f 100644 --- a/src/lib9/fmt/vfprint.c +++ b/src/lib9/fmt/vfprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include "plan9.h" #include "fmt.h" diff --git a/src/lib9/fmt/vseprint.c b/src/lib9/fmt/vseprint.c index b6dfee63..0f7ba9db 100644 --- a/src/lib9/fmt/vseprint.c +++ b/src/lib9/fmt/vseprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdarg.h> #include "plan9.h" #include "fmt.h" diff --git a/src/lib9/fmt/vsmprint.c b/src/lib9/fmt/vsmprint.c index 6f493733..9576f800 100644 --- a/src/lib9/fmt/vsmprint.c +++ b/src/lib9/fmt/vsmprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ /* * Plan 9 port version must include libc.h in order to * get Plan 9 debugging malloc, which sometimes returns @@ -69,6 +57,7 @@ fmtstrinit(Fmt *f) f->flush = fmtStrFlush; f->farg = (void*)(uintptr)n; f->nfmt = 0; + fmtlocaleinit(f, nil, nil, nil); return 0; } diff --git a/src/lib9/fmt/vsnprint.c b/src/lib9/fmt/vsnprint.c index ed703250..1859265b 100644 --- a/src/lib9/fmt/vsnprint.c +++ b/src/lib9/fmt/vsnprint.c @@ -1,16 +1,4 @@ -/* - * The authors of this software are Rob Pike and Ken Thompson. - * Copyright (c) 2002 by Lucent Technologies. - * 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. - */ +/* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */ #include <stdlib.h> #include <stdarg.h> #include "plan9.h" @@ -32,6 +20,7 @@ vsnprint(char *buf, int len, char *fmt, va_list args) f.farg = nil; f.nfmt = 0; VA_COPY(f.args,args); + fmtlocaleinit(&f, nil, nil, nil); dofmt(&f, fmt); VA_END(f.args); *(char*)f.to = '\0'; |