~ft/fontsel

d12d18424997ed37819ef3832b25c25094e6ff1d — Sigrid Haflínudóttir a month ago 3f4f253 master
fix stack overflow; close file when not needed; fix alternative text file reading
1 files changed, 6 insertions(+), 4 deletions(-)

M fontsel.c
M fontsel.c => fontsel.c +6 -4
@@ 61,6 61,7 @@ static Font *f;
static Fontdir *dirs, *cdir;
static int ndirs, idir;
static char lasterr[256];
int mainstacksize = 32768;

static void
redraw(void)


@@ 120,7 121,7 @@ fontdir(char *t, int f, Fontdir *fdir)
	long i, n;

	k = strlen(t);
	if(k > 4 && strcmp(&t[k-4], ".ttf") == 0){
	if(k > 4 && (cistrcmp(&t[k-4], ".ttf") == 0 || cistrcmp(&t[k-4], ".otf") == 0)){
		fdir->nfonts = 1;
		fdir->sz = Ttfdefsz;
		fdir->isttf = 1;


@@ 165,7 166,7 @@ findfonts(char *prefix)
	long i, n;
	char t[1024];

	doff = sprint(t, prefix);
	doff = sprint(t, "%s", prefix);
	t[doff++] = '/';
	t[doff] = 0;
	if((f = open(t, OREAD)) < 0){


@@ 177,8 178,9 @@ findfonts(char *prefix)
		close(f);
		return;
	}
	close(f);
	for(i = 0; i < n; i++){
		sprint(t+doff, d[i].name);
		strcpy(t+doff, d[i].name);
		if((fin = open(t, OREAD)) < 0)
			continue;
		if((din = dirfstat(fin)) != nil){


@@ 276,7 278,7 @@ threadmain(int argc, char **argv)
	if(argc > 1)
		usage();
	else if(argc == 1)
		loadtext(strcmp(argv[0], "-") == 0 ? 0 : open(argv[1], OREAD));
		loadtext(strcmp(argv[0], "-") == 0 ? 0 : open(argv[0], OREAD));

	for(n = 0; n < nelem(prefixes); n++)
		findfonts(prefixes[n]);