summaryrefslogtreecommitdiffstats
path: root/src/libdraw/subfontname.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2003-09-30 17:47:42 +0000
committerrsc <devnull@localhost>2003-09-30 17:47:42 +0000
commit76193d7cb0457807b2f0b95f909ab5de19480cd7 (patch)
tree97e538c7e38181431e90289a0fe8b6b7ce1f8f3c /src/libdraw/subfontname.c
parented7c8e8d02c02bdbff1e88a6d8d1419f39af48ad (diff)
downloadplan9port-76193d7cb0457807b2f0b95f909ab5de19480cd7.tar.gz
plan9port-76193d7cb0457807b2f0b95f909ab5de19480cd7.zip
Initial revision
Diffstat (limited to 'src/libdraw/subfontname.c')
-rw-r--r--src/libdraw/subfontname.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/libdraw/subfontname.c b/src/libdraw/subfontname.c
new file mode 100644
index 00000000..bcb4e3a1
--- /dev/null
+++ b/src/libdraw/subfontname.c
@@ -0,0 +1,44 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+
+/*
+ * Default version: convert to file name
+ */
+
+char*
+subfontname(char *cfname, char *fname, int maxdepth)
+{
+ char *t, *u, tmp1[64], tmp2[64];
+ int i;
+
+ if(strcmp(cfname, "*default*") == 0)
+ return strdup(cfname);
+ t = cfname;
+ if(t[0] != '/'){
+ snprint(tmp2, sizeof tmp2, "%s", fname);
+ u = utfrrune(tmp2, '/');
+ if(u)
+ u[0] = 0;
+ else
+ strcpy(tmp2, ".");
+ snprint(tmp1, sizeof tmp1, "%s/%s", tmp2, t);
+ t = tmp1;
+ }
+
+ if(maxdepth > 8)
+ maxdepth = 8;
+
+ for(i=log2[maxdepth]; i>=0; i--){
+ /* try i-bit grey */
+ snprint(tmp2, sizeof tmp2, "%s.%d", t, i);
+ if(access(tmp2, AREAD) == 0)
+ return strdup(tmp2);
+ }
+
+ /* try default */
+ if(access(t, AREAD) == 0)
+ return strdup(t);
+
+ return nil;
+}