Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <draw.h>
5 /*
6 * Default version: convert to file name
7 */
9 char*
10 subfontname(char *cfname, char *fname, int maxdepth)
11 {
12 char *t, *u, tmp1[64], tmp2[64];
13 int i;
15 if(strcmp(cfname, "*default*") == 0)
16 return strdup(cfname);
17 t = cfname;
18 if(t[0] != '/'){
19 snprint(tmp2, sizeof tmp2, "%s", fname);
20 u = utfrrune(tmp2, '/');
21 if(u)
22 u[0] = 0;
23 else
24 strcpy(tmp2, ".");
25 snprint(tmp1, sizeof tmp1, "%s/%s", tmp2, t);
26 t = tmp1;
27 }
29 if(maxdepth > 8)
30 maxdepth = 8;
32 for(i=log2[maxdepth]; i>=0; i--){
33 /* try i-bit grey */
34 snprint(tmp2, sizeof tmp2, "%s.%d", t, i);
35 if(access(tmp2, AREAD) == 0)
36 return strdup(tmp2);
37 }
39 /* try default */
40 if(access(t, AREAD) == 0)
41 return strdup(t);
43 return nil;
44 }