commit ab239cb5ba1e3e72d53a55ca2a2e97469c29e884 from: rsc date: Fri May 26 00:53:07 2006 UTC oops commit - f3b8bf7f4ee326d9de31947584c6e9dbbfa75ce6 commit + ab239cb5ba1e3e72d53a55ca2a2e97469c29e884 blob - 74697eb543ef6fbeb68ab1fcb7efc7bd374d1bf8 blob + e4e32bf4590c32a0df3f3a76c916dc6ec22c8999 --- src/lib9/fmt/dofmt.c +++ src/lib9/fmt/dofmt.c @@ -252,9 +252,17 @@ fmtstrcpy(Fmt *f, char *s) return __fmtcpy(f, "", 5, 5); /* if precision is specified, make sure we don't wander off the end */ if(f->flags & FmtPrec){ +#ifdef PLAN9PORT i = 0; for(j=0; jprec && s[i]; j++) i += chartorune(&r, s+i); +#else + /* ANSI requires precision in bytes, not Runes */ + for(i=0; iprec; i++) + if(s[i] == 0) + break; + j = utfnlen(s, i); /* won't print partial at end */ +#endif return __fmtcpy(f, s, j, i); } return __fmtcpy(f, s, utflen(s), strlen(s)); blob - 5b8f9fd4616c3de8dd4d49b66b666c175cab8de2 blob + 8c8daaee9d7e48e46e817fd97309bf566a86af6a --- src/lib9/fmt/fmtquote.c +++ src/lib9/fmt/fmtquote.c @@ -91,6 +91,11 @@ __quotesetup(char *s, Rune *r, int nin, int nout, Quot /* advance output */ q->nbytesout += w; q->nrunesout++; + +#ifndef PLAN9PORT + /* ANSI requires precision in bytes, not Runes. */ + nin-= w-1; /* and then n-- in the loop */ +#endif } } blob - d789cbe7d62951a412c8397d779fab76313d79bb blob + 24e2f178f505f714266de6b689cb176826639ff4 --- src/lib9/fmt/runevseprint.c +++ src/lib9/fmt/runevseprint.c @@ -20,6 +20,7 @@ runevseprint(Rune *buf, Rune *e, char *fmt, va_list ar 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'; blob - 0f7ba9dbfa027a3a56cb0bd456b4a442c6ad9b6e blob + 1b92d2a9b2c12f204885b68342807ad4cfa39ce3 --- src/lib9/fmt/vseprint.c +++ src/lib9/fmt/vseprint.c @@ -19,6 +19,7 @@ vseprint(char *buf, char *e, 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';