From e6f4b2e311cd461dd2d8380ba21ab113e5c8c072 Mon Sep 17 00:00:00 2001 From: rsc Date: Mon, 13 Oct 2003 17:16:15 +0000 Subject: Rewrite /lib/font/bit to $PLAN9/font when open fails. --- src/libdraw/openfont.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/libdraw/openfont.c b/src/libdraw/openfont.c index e9fa3f84..a1ff278a 100644 --- a/src/libdraw/openfont.c +++ b/src/libdraw/openfont.c @@ -9,9 +9,27 @@ openfont(Display *d, char *name) { Font *fnt; int fd, i, n; - char *buf; + char *buf, *nambuf, *root; + nambuf = 0; fd = open(name, OREAD); + + if(fd < 0 && strncmp(name, "/lib/font/bit/", 14) == 0){ + root = getenv("PLAN9"); + if(root == nil) + return 0; + nambuf = malloc(strlen(root)+5+strlen(name+13)+1); + if(nambuf == nil) + return 0; + strcpy(nambuf, root); + strcat(nambuf, "/font"); + strcat(nambuf, name+13); + if((fd = open(nambuf, OREAD)) < 0){ + free(nambuf); + return 0; + } + name = nambuf; + } if(fd < 0) return 0; @@ -19,6 +37,7 @@ openfont(Display *d, char *name) buf = malloc(n+1); if(buf == 0){ close(fd); + free(nambuf); return 0; } buf[n] = 0; @@ -26,9 +45,11 @@ openfont(Display *d, char *name) close(fd); if(i != n){ free(buf); + free(nambuf); return 0; } fnt = buildfont(d, buf, name); free(buf); + free(nambuf); return fnt; } -- cgit v1.2.3