various little changes.

also pick up latest fltfmt from plan 9
This commit is contained in:
rsc 2004-12-26 22:36:12 +00:00
parent 5f8fa94796
commit 3f1a219769

View file

@ -252,18 +252,18 @@ __runefmt(Fmt *f)
int int
fmtstrcpy(Fmt *f, char *s) fmtstrcpy(Fmt *f, char *s)
{ {
int p, i; int i, j;
Rune r;
if(!s) if(!s)
return __fmtcpy(f, "<nil>", 5, 5); return __fmtcpy(f, "<nil>", 5, 5);
/* if precision is specified, make sure we don't wander off the end */ /* if precision is specified, make sure we don't wander off the end */
if(f->flags & FmtPrec){ if(f->flags & FmtPrec){
p = f->prec; i = 0;
for(i = 0; i < p; i++) for(j=0; j<f->prec && s[i]; j++)
if(s[i] == 0) i += chartorune(&r, s+i);
break; return __fmtcpy(f, s, j, i);
return __fmtcpy(f, s, utfnlen(s, i), i); /* BUG?: won't print a partial rune at end */
} }
return __fmtcpy(f, s, utflen(s), strlen(s)); return __fmtcpy(f, s, utflen(s), strlen(s));
} }
@ -335,19 +335,21 @@ __ifmt(Fmt *f)
isv = 0; isv = 0;
vu = 0; vu = 0;
u = 0; u = 0;
#ifndef PLAN9PORT
/* /*
* Unsigned verbs * Unsigned verbs for ANSI C
*/ */
switch(f->r){ switch(f->r){
/* unsigned by default only on Unix
case 'x': case 'x':
case 'X': case 'X':
*/
case 'o': case 'o':
case 'u': case 'u':
case 'p':
fl |= FmtUnsigned; fl |= FmtUnsigned;
fl &= ~(FmtSign|FmtSpace);
break; break;
} }
#endif
if(f->r == 'p'){ if(f->r == 'p'){
u = (ulong)va_arg(f->args, void*); u = (ulong)va_arg(f->args, void*);
f->r = 'x'; f->r = 'x';
@ -383,8 +385,6 @@ __ifmt(Fmt *f)
switch(f->r){ switch(f->r){
case 'd': case 'd':
case 'i': case 'i':
base = 10;
break;
case 'u': case 'u':
base = 10; base = 10;
break; break;
@ -404,9 +404,7 @@ __ifmt(Fmt *f)
default: default:
return -1; return -1;
} }
if(fl & FmtUnsigned) if(!(fl & FmtUnsigned)){
fl &= ~(FmtSign|FmtSpace);
else{
if(isv && (vlong)vu < 0){ if(isv && (vlong)vu < 0){
vu = -(vlong)vu; vu = -(vlong)vu;
neg = 1; neg = 1;
@ -441,11 +439,9 @@ __ifmt(Fmt *f)
} }
} }
if(n == 0){ if(n == 0){
if(!(fl & FmtPrec) || f->prec != 0){
*p-- = '0'; *p-- = '0';
n = 1; n = 1;
} }
}
for(w = f->prec; n < w && p > buf+3; n++) for(w = f->prec; n < w && p > buf+3; n++)
*p-- = '0'; *p-- = '0';
if(neg || (fl & (FmtSign|FmtSpace))) if(neg || (fl & (FmtSign|FmtSpace)))
@ -530,9 +526,11 @@ __flagfmt(Fmt *f)
f->flags |= FmtByte; f->flags |= FmtByte;
f->flags |= FmtShort; f->flags |= FmtShort;
break; break;
#ifndef PLAN9PORT
case 'L': case 'L':
f->flags |= FmtLDouble; f->flags |= FmtLDouble;
break; break;
#endif
case 'l': case 'l':
if(f->flags & FmtLong) if(f->flags & FmtLong)
f->flags |= FmtVLong; f->flags |= FmtVLong;