| ---
tsubfontname.c (1158B)
---
1 #include
2 #include
3 #include
4
5 /*
6 * Default version: convert to file name
7 */
8
9 char*
10 subfontname(char *cfname, char *fname, int maxdepth)
11 {
12 char *t, *u, *tmp1, *tmp2, *base;
13 int i, scale;
14
15 scale = parsefontscale(fname, &base);
16
17 t = strdup(cfname); /* t is the return string */
18 if(strcmp(cfname, "*default*") == 0) {
19 if(scale > 1) {
20 free(t);
21 return smprint("%d*%s", scale, cfname);
22 }
23 return t;
24 }
25 if(t[0] != '/'){
26 tmp2 = strdup(base);
27 u = utfrrune(tmp2, '/');
28 if(u)
29 u[0] = 0;
30 else
31 strcpy(tmp2, ".");
32 tmp1 = smprint("%s/%s", tmp2, t);
33 free(tmp2);
34 free(t);
35 t = tmp1;
36 }
37
38 if(maxdepth > 8)
39 maxdepth = 8;
40
41 for(i=3; i>=0; i--){
42 if((1< maxdepth)
43 continue;
44 /* try i-bit grey */
45 tmp2 = smprint("%s.%d", t, i);
46 if(access(tmp2, AREAD) == 0) {
47 free(t);
48 if(scale > 1) {
49 t = smprint("%d*%s", scale, tmp2);
50 free(tmp2);
51 tmp2 = t;
52 }
53 return tmp2;
54 }
55 free(tmp2);
56 }
57
58 /* try default */
59 if(strncmp(t, "/mnt/font/", 10) == 0 || access(t, AREAD) == 0) {
60 if(scale > 1) {
61 tmp2 = smprint("%d*%s", scale, t);
62 free(t);
63 t = tmp2;
64 }
65 return t;
66 }
67
68 return nil;
69 } |