Blob
1 #include <u.h>2 #include <libc.h>3 #include <draw.h>5 /*6 * Default version: convert to file name7 */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 else24 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=3; i>=0; i--){33 if((1<<i) > maxdepth)34 continue;35 /* try i-bit grey */36 snprint(tmp2, sizeof tmp2, "%s.%d", t, i);37 if(access(tmp2, AREAD) == 0)38 return strdup(tmp2);39 }41 /* try default */42 if(access(t, AREAD) == 0)43 return strdup(t);45 return nil;46 }