subfontname.c 789 B

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