diff options
author | Russ Cox <rsc@swtch.com> | 2009-07-08 21:43:14 -0700 |
---|---|---|
committer | Russ Cox <rsc@swtch.com> | 2009-07-08 21:43:14 -0700 |
commit | 9b4a2324d39a8c952c8184249d2b06b9349205a2 (patch) | |
tree | a721c194fb6772ffb668aeb548f9ceaef9f56dce /src/libdraw | |
parent | 4a18fa68b01bf8121a8660d3f5214e5927763251 (diff) | |
parent | 4a18fa68b01bf8121a8660d3f5214e5927763251 (diff) | |
download | plan9port-9b4a2324d39a8c952c8184249d2b06b9349205a2.tar.gz plan9port-9b4a2324d39a8c952c8184249d2b06b9349205a2.tar.bz2 plan9port-9b4a2324d39a8c952c8184249d2b06b9349205a2.zip |
merge
Diffstat (limited to 'src/libdraw')
-rw-r--r-- | src/libdraw/getsubfont.c | 6 | ||||
-rw-r--r-- | src/libdraw/openfont.c | 61 | ||||
-rw-r--r-- | src/libdraw/subfontname.c | 2 |
3 files changed, 63 insertions, 6 deletions
diff --git a/src/libdraw/getsubfont.c b/src/libdraw/getsubfont.c index 2cbec812..0d8be9ff 100644 --- a/src/libdraw/getsubfont.c +++ b/src/libdraw/getsubfont.c @@ -6,6 +6,8 @@ * Default version: treat as file name */ +int _fontpipe(char*); + Subfont* _getsubfont(Display *d, char *name) { @@ -13,7 +15,9 @@ _getsubfont(Display *d, char *name) Subfont *f; fd = open(name, OREAD); - + if(fd < 0 && strncmp(name, "/mnt/font/", 10) == 0) + fd = _fontpipe(name+10); + if(fd < 0){ fprint(2, "getsubfont: can't open %s: %r\n", name); return 0; diff --git a/src/libdraw/openfont.c b/src/libdraw/openfont.c index 05370eac..892f7f61 100644 --- a/src/libdraw/openfont.c +++ b/src/libdraw/openfont.c @@ -3,6 +3,7 @@ #include <draw.h> extern vlong _drawflength(int); +int _fontpipe(char*); Font* openfont(Display *d, char *name) @@ -27,26 +28,78 @@ openfont(Display *d, char *name) } name = nambuf; } + if(fd >= 0) + n = _drawflength(fd); + if(fd < 0 && strncmp(name, "/mnt/font/", 10) == 0) { + fd = _fontpipe(name+10); + n = 8192; + } if(fd < 0) return 0; - n = _drawflength(fd); buf = malloc(n+1); if(buf == 0){ close(fd); free(nambuf); return 0; } - buf[n] = 0; - i = read(fd, buf, n); + i = readn(fd, buf, n); close(fd); - if(i != n){ + if(i <= 0){ free(buf); free(nambuf); return 0; } + buf[i] = 0; fnt = buildfont(d, buf, name); free(buf); free(nambuf); return fnt; } + +int +_fontpipe(char *name) +{ + int p[2]; + char c; + char buf[1024], *argv[10]; + int nbuf, pid; + + if(pipe(p) < 0) + return -1; + pid = rfork(RFNOWAIT|RFFDG|RFPROC); + if(pid < 0) { + close(p[0]); + close(p[1]); + return -1; + } + if(pid == 0) { + close(p[0]); + dup(p[1], 1); + dup(p[1], 2); + if(p[1] > 2) + close(p[1]); + argv[0] = "fontsrv"; + argv[1] = "-pp"; + argv[2] = name; + argv[3] = nil; + execvp("fontsrv", argv); + print("exec fontsrv: %r\n"); + _exit(0); + } + close(p[1]); + + // success marked with leading \001. + // otherwise an error happened. + for(nbuf=0; nbuf<sizeof buf-1; nbuf++) { + if(read(p[0], &c, 1) < 1 || c == '\n') { + buf[nbuf] = '\0'; + werrstr(buf); + close(p[0]); + return -1; + } + if(c == '\001') + break; + } + return p[0]; +} diff --git a/src/libdraw/subfontname.c b/src/libdraw/subfontname.c index 1374ef31..874528be 100644 --- a/src/libdraw/subfontname.c +++ b/src/libdraw/subfontname.c @@ -43,7 +43,7 @@ subfontname(char *cfname, char *fname, int maxdepth) } /* try default */ - if(access(t, AREAD) == 0) + if(strncmp(t, "/mnt/font/", 10) == 0 || access(t, AREAD) == 0) return t; return nil; |