From df05d35899ff3a44e620e7a6e5afe4f8af60276c Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Thu, 6 Jan 2000 06:32:43 +0000 Subject: [PATCH] search path for font mroe sanely SVN revision: 1863 --- src/font.c | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/font.c b/src/font.c index 1004b79..31f74b8 100644 --- a/src/font.c +++ b/src/font.c @@ -168,36 +168,58 @@ __imlib_load_font(char *fontname) memcpy(name, fontname, j); name[j] = 0; /* find file if it exists */ - for (j = 0; (j < fpath_num) && (!file); j++) + tmp = malloc(strlen(name) + 4 + 1); + if (!tmp) { - tmp = malloc(strlen(fpath[j]) + 1 + strlen(name) + 4 + 1); - if (!tmp) - { - free(name); - return NULL; - } - sprintf(tmp, "%s.ttf", name); + free(name); + return NULL; + } + sprintf(tmp, "%s.ttf", name); + if (__imlib_FileIsFile(tmp)) + file = strdup(tmp); + else + { + sprintf(tmp, "%s.TTF", name); if (__imlib_FileIsFile(tmp)) file = strdup(tmp); else { - sprintf(tmp, "%s/%s.ttf", fpath[j], name); + sprintf(tmp, "%s", name); if (__imlib_FileIsFile(tmp)) file = strdup(tmp); + } + } + free(tmp); + if (!file) + { + for (j = 0; (j < fpath_num) && (!file); j++) + { + tmp = malloc(strlen(fpath[j]) + 1 + strlen(name) + 4 + 1); + if (!tmp) + { + free(name); + return NULL; + } else { - sprintf(tmp, "%s/%s.TTF", fpath[j], name); + sprintf(tmp, "%s/%s.ttf", fpath[j], name); if (__imlib_FileIsFile(tmp)) file = strdup(tmp); else { - sprintf(tmp, "%s/%s", fpath[j], name); + sprintf(tmp, "%s/%s.TTF", fpath[j], name); if (__imlib_FileIsFile(tmp)) file = strdup(tmp); + else + { + sprintf(tmp, "%s/%s", fpath[j], name); + if (__imlib_FileIsFile(tmp)) + file = strdup(tmp); + } } } + free(tmp); } - free(tmp); } free(name); /* didnt find a file? abort */