static Type* indchar;
static uchar flagbits[512];
-static char fmtbuf[100];
+static char* lastfmt;
static int lastadj;
static int lastverb;
static int nstar;
{
Bits flag;
int f;
- char *fmt;
+ Fmt fmt;
Rune c;
- fmt = fmtbuf;
flag = zbits;
nstar = 0;
+ fmtstrinit(&fmt);
for(;;) {
s += chartorune(&c, s);
if(c == 0 || c >= nelem(flagbits))
break;
- fmt += runetochar(fmt, &c);
+ fmtrune(&fmt, c);
f = flagbits[c];
switch(f) {
case Fnone:
if(f >= Fverb)
break;
}
- *fmt = 0;
+ free(lastfmt);
+ lastfmt = fmtstrflush(&fmt);
return flag;
}
getquoted(void)
{
int c;
- char *t;
Rune r;
+ Fmt fmt;
c = getnsc();
if(c != '"')
return nil;
- t = fmtbuf;
+ fmtstrinit(&fmt);
for(;;) {
r = getr();
- if(r == ' ' || r == '\n')
+ if(r == ' ' || r == '\n') {
+ free(fmtstrflush(&fmt));
return nil;
+ }
if(r == '"')
break;
- t += runetochar(t, &r);
+ fmtrune(&fmt, r);
}
- *t = 0;
- return strdup(fmtbuf);
+ free(lastfmt);
+ lastfmt = fmtstrflush(&fmt);
+ return strdup(lastfmt);
}
void
nstar--;
if(a == Z) {
warn(nn, "more format than arguments %s",
- fmtbuf);
+ lastfmt);
return;
}
if(a->type == T)
if(!sametype(types[TINT], a->type) &&
!sametype(types[TUINT], a->type))
warn(nn, "format mismatch '*' in %s %T, arg %d",
- fmtbuf, a->type, pos);
+ lastfmt, a->type, pos);
}
for(l=tprot; l; l=l->link)
if(sametype(types[TVOID], l->type)) {
pos++;
if(a == Z) {
warn(nn, "more format than arguments %s",
- fmtbuf);
+ lastfmt);
return;
}
if(a->type == 0)
if(beq(flag, l->flag))
goto loop;
}
- warn(nn, "format mismatch %s %T, arg %d", fmtbuf, a->type, pos);
+ warn(nn, "format mismatch %s %T, arg %d", lastfmt, a->type, pos);
loop:;
}
}
int
compile(char *file, char **defs, int ndef)
{
- char ofile[400], incfile[20];
+ char *ofile, incfile[20];
char *p, *av[100], opt[256];
int i, c, fd[2];
static int first = 1;
- strcpy(ofile, file);
+ ofile = strdup(file);
p = utfrrune(ofile, pathchar());
if(p) {
*p++ = 0;
sprint(opt, "-+");
av[i++] = strdup(opt);
}
- for(c = 0; c < ndef; c++) {
- sprint(opt, "-D%s", defs[c]);
- av[i++] = strdup(opt);
- }
- for(c = 0; c < ninclude; c++) {
- sprint(opt, "-I%s", include[c]);
- av[i++] = strdup(opt);
- }
+ for(c = 0; c < ndef; c++)
+ av[i++] = smprint("-D%s", defs[c]);
+ for(c = 0; c < ninclude; c++)
+ av[i++] = smprint("-I%s", include[c]);
if(strcmp(file, "stdin") != 0)
av[i++] = file;
av[i] = 0;