10 typedef struct Convfmt Convfmt;
14 volatile Fmts fmt; /* for spin lock in fmtfmt; avoids race due to write order */
19 /* lock by calling _fmtlock, _fmtunlock */
24 static Convfmt knownfmt[] = {
58 * _fmtlock() must be set
61 _fmtinstall(int c, Fmts f)
70 ep = &fmtalloc.fmt[fmtalloc.nfmt];
71 for(p=fmtalloc.fmt; p<ep; p++)
75 if(p == &fmtalloc.fmt[Maxfmt])
79 if(p == ep){ /* installing a new format character */
88 fmtinstall(int c, Fmts f)
93 ret = _fmtinstall(c, f);
103 ep = &fmtalloc.fmt[fmtalloc.nfmt];
104 for(p=fmtalloc.fmt; p<ep; p++)
106 while(p->fmt == nil) /* loop until value is updated */
111 /* is this a predefined format char? */
113 for(p=knownfmt; p->c; p++)
115 _fmtinstall(p->c, p->fmt);
125 _fmtdispatch(Fmt *f, void *fmt, int isrunes)
131 f->width = f->prec = 0;
136 fmt = (Rune*)fmt + 1;
138 fmt = (char*)fmt + chartorune(&rune, fmt);
146 f->flags |= FmtWidth|FmtPrec;
149 if(!(f->flags & FmtWidth)){
154 case '1': case '2': case '3': case '4':
155 case '5': case '6': case '7': case '8': case '9':
157 while(r >= '0' && r <= '9'){
158 i = i * 10 + r - '0';
161 fmt = (Rune*)fmt + 1;
164 fmt = (char*)fmt + 1;
168 fmt = (Rune*)fmt - 1;
170 fmt = (char*)fmt - 1;
172 if(f->flags & FmtWidth){
176 f->flags |= FmtWidth;
181 i = va_arg(f->args, int);
184 * negative precision =>
185 * ignore the precision.
187 if(f->flags & FmtPrec){
188 f->flags &= ~FmtPrec;