buildfont(Display *d, char *buf, char *name)
{
Font *fnt;
- Cachefont *c;
+ Cachefont *c, **sub;
char *s, *t;
ulong min, max;
int offset;
s = buf;
fnt = malloc(sizeof(Font));
- if(fnt == 0)
- return 0;
+ if(fnt == nil)
+ return nil;
memset(fnt, 0, sizeof(Font));
fnt->display = d;
fnt->name = strdup(name);
fnt->nsubf = NFSUBF;
fnt->cache = malloc(fnt->ncache * sizeof(fnt->cache[0]));
fnt->subf = malloc(fnt->nsubf * sizeof(fnt->subf[0]));
- if(fnt->name==0 || fnt->cache==0 || fnt->subf==0){
+ if(fnt->name==nil || fnt->cache==nil || fnt->subf==nil){
Err2:
free(fnt->name);
free(fnt->cache);
free(fnt->subf);
free(fnt->sub);
free(fnt);
- return 0;
+ return nil;
}
fnt->height = strtol(s, &s, 0);
s = skip(s);
}
fnt->width = 0;
fnt->nsub = 0;
- fnt->sub = 0;
+ fnt->sub = nil;
memset(fnt->subf, 0, fnt->nsubf * sizeof(fnt->subf[0]));
memset(fnt->cache, 0, fnt->ncache*sizeof(fnt->cache[0]));
}
max = strtol(s, &s, 0);
s = skip(s);
- if(*s==0 || min>=65536 || max>=65536 || min>max){
+ if(*s==0 || min>Runemax || max>Runemax || min>max){
werrstr("illegal subfont range");
Err3:
freefont(fnt);
s = skip(t);
else
offset = 0;
- fnt->sub = realloc(fnt->sub, (fnt->nsub+1)*sizeof(Cachefont*));
- if(fnt->sub == 0){
- /* realloc manual says fnt->sub may have been destroyed */
- fnt->nsub = 0;
+ sub = realloc(fnt->sub, (fnt->nsub+1)*sizeof(Cachefont*));
+ if(sub == nil)
goto Err3;
- }
+ fnt->sub = sub;
c = malloc(sizeof(Cachefont));
- if(c == 0)
+ if(c == nil)
goto Err3;
- fnt->sub[fnt->nsub] = c;
c->min = min;
c->max = max;
c->offset = offset;
while(*s && *s!=' ' && *s!='\n' && *s!='\t')
s++;
*s++ = 0;
- c->subfontname = 0;
+ c->subfontname = nil;
c->name = strdup(t);
- if(c->name == 0){
+ if(c->name == nil){
free(c);
goto Err3;
}
+ sub[fnt->nsub++] = c;
s = skip(s);
- fnt->nsub++;
}while(*s);
return fnt;
}
Cachefont *c;
Subfont *s;
- if(f == 0)
+ if(f == nil)
return;
for(i=0; i<f->nsub; i++){
}
for(i=0; i<f->nsubf; i++){
s = f->subf[i].f;
- if(s && s!=display->defaultsubfont)
- freesubfont(s);
+ if(s != nil){
+ if(f->display == nil || s != f->display->defaultsubfont)
+ freesubfont(s);
+ }
}
freeimage(f->cacheimage);
free(f->name);