From 37da2899f40661e3e9631e497da8dc59b971cbd0 Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Fri, 22 Dec 2006 17:07:39 +0000 Subject: 20060303a --- libdraw/subfontname.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 libdraw/subfontname.c (limited to 'libdraw/subfontname.c') diff --git a/libdraw/subfontname.c b/libdraw/subfontname.c new file mode 100644 index 00000000..ceaaa4a0 --- /dev/null +++ b/libdraw/subfontname.c @@ -0,0 +1,45 @@ +#include "lib9.h" +#include "draw.h" + +/* + * Default version: convert to file name + */ + +char* +subfontname(char *cfname, char *fname, int maxdepth) +{ + char *t, *u, tmp1[128], tmp2[128]; + int i; + + if(strcmp(cfname, "*default*") == 0) + return strdup(cfname); + t = cfname; + if(t[0] != '/'){ + snprint(tmp2, sizeof tmp2, "%s", fname); + u = utfrrune(tmp2, '/'); + if(u) + u[0] = 0; + else + strcpy(tmp2, "."); + snprint(tmp1, sizeof tmp1, "%s/%s", tmp2, t); + t = tmp1; + } + + if(maxdepth > 8) + maxdepth = 8; + + for(i=3; i>=0; i--){ + if((1< maxdepth) + continue; + /* try i-bit grey */ + snprint(tmp2, sizeof tmp2, "%s.%d", t, i); + if(access(tmp2, AREAD) == 0) + return strdup(tmp2); + } + + /* try default */ + if(access(t, AREAD) == 0) + return strdup(t); + + return nil; +} -- cgit v1.2.3