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, *tmp2;
13 int i;
15 t = strdup(cfname); /* t is the return string */
16 if(strcmp(cfname, "*default*") == 0)
17 return t;
18 if(t[0] != '/'){
19 tmp2 = strdup(fname);
20 u = utfrrune(tmp2, '/');
21 if(u)
22 u[0] = 0;
23 else
24 strcpy(tmp2, ".");
25 tmp1 = smprint("%s/%s", tmp2, t);
26 free(tmp2);
27 free(t);
28 t = tmp1;
29 }
31 if(maxdepth > 8)
32 maxdepth = 8;
34 for(i=3; i>=0; i--){
35 if((1<<i) > maxdepth)
36 continue;
37 /* try i-bit grey */
38 tmp2 = smprint("%s.%d", t, i);
39 if(access(tmp2, AREAD) == 0) {
40 free(t);
41 return tmp2;
42 }
43 }
45 /* try default */
46 if(access(t, AREAD) == 0)
47 return t;
49 return nil;
50 }