diff options
Diffstat (limited to 'framebuffer/findfile.c')
-rw-r--r-- | framebuffer/findfile.c | 97 |
1 files changed, 39 insertions, 58 deletions
diff --git a/framebuffer/findfile.c b/framebuffer/findfile.c index caa910005..130804eed 100644 --- a/framebuffer/findfile.c +++ b/framebuffer/findfile.c @@ -27,9 +27,45 @@ #include "utils/log.h" #include "utils/url.h" +#include "utils/resource.h" +#include "content/fetchers/resource.h" #include "framebuffer/findfile.h" +char **respaths; /** resource search path vector */ + +/** Create an array of valid paths to search for resources. + * + * The idea is that all the complex path computation to find resources + * is performed here, once, rather than every time a resource is + * searched for. + */ +char ** +fb_init_resource(const char *resource_path) +{ + char **pathv; /* resource path string vector */ + char **respath; /* resource paths vector */ + const char *lang = NULL; + char *foo; + int bar=0; + fprintf(stderr, "fb_init_resource:%s\n",resource_path); + + pathv = resource_path_to_strvec(resource_path); + + respath = resource_generate(pathv, &lang); + + resource_free_strvec(pathv); + + foo = respath[bar]; + while (foo != NULL) { + fprintf(stderr, "%s\n",foo); + bar++; + foo = respath[bar]; + } + return respath; +} + + char *path_to_url(const char *path) { int urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; @@ -65,67 +101,12 @@ char *url_to_path(const char *url) return respath; } -/** - * Locate a shared resource file by searching known places in order. - * - * \param buf buffer to write to. must be at least PATH_MAX chars - * \param filename file to look for - * \param def default to return if file not found - * \return buf - * - * Search order is: ~/.netsurf/, $NETSURFRES/ (where NETSURFRES is an - * environment variable), and finally the path specified by NETSURF_FB_RESPATH - * from the Makefile - */ - -char *fb_find_resource(char *buf, const char *filename, const char *def) +char* gui_find_resource(const char *filename) { - char *cdir = getenv("HOME"); - char t[PATH_MAX]; - - if (cdir != NULL) { - strcpy(t, cdir); - strcat(t, "/.netsurf/"); - strcat(t, filename); - if (realpath(t, buf) != NULL) { - if (access(buf, R_OK) == 0) - return buf; - } - } - - cdir = getenv("NETSURFRES"); - - if (cdir != NULL) { - if (realpath(cdir, buf) != NULL) { - strcat(buf, "/"); - strcat(buf, filename); - if (access(buf, R_OK) == 0) - return buf; - } - } - - strcpy(t, NETSURF_FB_RESPATH); - strcat(t, filename); - if (realpath(t, buf) != NULL) { - if (access(buf, R_OK) == 0) - return buf; - } - - if (def[0] == '~') { - snprintf(t, PATH_MAX, "%s%s", getenv("HOME"), def + 1); - if (realpath(t, buf) == NULL) { - strcpy(buf, t); - } - } else { - if (realpath(def, buf) == NULL) { - strcpy(buf, def); - } - } - - return buf; + char buf[PATH_MAX]; + return path_to_url(resource_sfind(respaths, buf, filename)); } - /* * Local Variables: * c-basic-offset: 8 |