From 55162445db4c8ea46be671c2abed4ad4e77e1dcd Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sun, 31 Jan 2010 00:36:02 +0000 Subject: Add Windows frontend svn path=/trunk/netsurf/; revision=9940 --- windows/findfile.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 windows/findfile.c (limited to 'windows/findfile.c') diff --git a/windows/findfile.c b/windows/findfile.c new file mode 100644 index 000000000..f47e49d03 --- /dev/null +++ b/windows/findfile.c @@ -0,0 +1,118 @@ +/* + * Copyright 2008 Daniel Silverstone + * Copyright 2009 Mark Benjamin + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include + +#include "utils/log.h" +#include "utils/utils.h" + +#include "windows/findfile.h" + +static char *realpath(const char *path, char *resolved_path) +{ + /* useless, but there we go */ + return strncpy(resolved_path, path, PATH_MAX); +} + +char *path_to_url(const char *path) +{ + char *r = malloc(strlen(path) + 7 + 1); + + strcpy(r, "file://"); + strcat(r, path); + + return r; +} + +/** + * 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), then the path specified in + NETSURF_WINDOWS_RESPATH in the Makefile then .\res\ [windows paths] + */ + +char *nsws_find_resource(char *buf, const char *filename, const char *def) +{ + char *cdir = getenv("HOME"); + char t[PATH_MAX]; + + if (cdir != NULL) { + LOG(("Found Home %s", cdir)); + strcpy(t, cdir); + strcat(t, "/.netsurf/"); + strcat(t, filename); + if ((realpath(t, buf) != NULL) && (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_WINDOWS_RESPATH); + strcat(t, filename); + if ((realpath(t, buf) != NULL) && (access(buf, R_OK) == 0)) + return buf; + + getcwd(t, PATH_MAX - SLEN("\\res\\") - strlen(filename)); + strcat(t, "\\res\\"); + strcat(t, filename); + LOG(("looking in %s", t)); + if ((realpath(t, buf) != NULL) && (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; +} + + +/* + * Local Variables: + * c-basic-offset: 8 + * End: + */ + -- cgit v1.2.3