diff options
-rw-r--r-- | Makefile.sources | 2 | ||||
-rw-r--r-- | framebuffer/findfile.c | 10 | ||||
-rw-r--r-- | framebuffer/font_freetype.c | 4 | ||||
-rw-r--r-- | framebuffer/gui.c | 10 | ||||
-rw-r--r-- | gtk/gui.c | 46 | ||||
-rw-r--r-- | monkey/main.c | 16 | ||||
-rw-r--r-- | utils/filepath.c (renamed from utils/resource.c) | 48 | ||||
-rw-r--r-- | utils/filepath.h (renamed from utils/resource.h) | 41 |
8 files changed, 93 insertions, 84 deletions
diff --git a/Makefile.sources b/Makefile.sources index 6651f4943..ac4082d38 100644 --- a/Makefile.sources +++ b/Makefile.sources @@ -15,7 +15,7 @@ S_RENDER := box.c box_construct.c box_normalise.c favicon.c \ hubbub_binding.c imagemap.c layout.c list.c table.c textplain.c S_UTILS := base64.c filename.c hashtable.c http.c locale.c messages.c \ - talloc.c url.c utf8.c utils.c useragent.c resource.c log.c + talloc.c url.c utf8.c utils.c useragent.c filepath.c log.c S_DESKTOP := cookies.c history_global_core.c hotlist.c knockout.c \ mouse.c options.c plot_style.c print.c search.c searchweb.c \ diff --git a/framebuffer/findfile.c b/framebuffer/findfile.c index ba4f87218..b864b2ba5 100644 --- a/framebuffer/findfile.c +++ b/framebuffer/findfile.c @@ -25,9 +25,9 @@ #include <curl/curl.h> +#include "utils/filepath.h" #include "utils/log.h" #include "utils/url.h" -#include "utils/resource.h" #include "content/fetchers/resource.h" #include "framebuffer/findfile.h" @@ -47,11 +47,11 @@ fb_init_resource(const char *resource_path) char **respath; /* resource paths vector */ const char *lang = NULL; - pathv = resource_path_to_strvec(resource_path); + pathv = filepath_path_to_strvec(resource_path); - respath = resource_generate(pathv, &lang); + respath = filepath_generate(pathv, &lang); - resource_free_strvec(pathv); + filepath_free_strvec(pathv); return respath; } @@ -95,7 +95,7 @@ char *url_to_path(const char *url) char* gui_find_resource(const char *filename) { char buf[PATH_MAX]; - return path_to_url(resource_sfind(respaths, buf, filename)); + return path_to_url(filepath_sfind(respaths, buf, filename)); } /* diff --git a/framebuffer/font_freetype.c b/framebuffer/font_freetype.c index c1e5fcc3a..bd17d6366 100644 --- a/framebuffer/font_freetype.c +++ b/framebuffer/font_freetype.c @@ -26,9 +26,9 @@ #include "css/css.h" #include "css/utils.h" #include "render/font.h" +#include "utils/filepath.h" #include "utils/utf8.h" #include "utils/log.h" -#include "utils/resource.h" #include "desktop/options.h" #include "framebuffer/gui.h" @@ -126,7 +126,7 @@ fb_new_face(const char *option, const char *resname, const char *fontname) if (option != NULL) { newf->fontfile = strdup(option); } else { - resource_sfind(respaths, buf, fontname); + filepath_sfind(respaths, buf, fontname); newf->fontfile = strdup(buf); } diff --git a/framebuffer/gui.c b/framebuffer/gui.c index 078a2e760..128171695 100644 --- a/framebuffer/gui.c +++ b/framebuffer/gui.c @@ -37,7 +37,7 @@ #include "desktop/netsurf.h" #include "desktop/options.h" #include "desktop/shape.h" -#include "utils/resource.h" +#include "utils/filepath.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/schedule.h" @@ -457,12 +457,12 @@ gui_init(int argc, char** argv) LOG(("Using '%s' as AdBlock CSS URL", adblock_stylesheet_url)); if (option_cookie_file == NULL) { - option_cookie_file = resource_find(respaths, "Cookies"); + option_cookie_file = filepath_find(respaths, "Cookies"); LOG(("Using '%s' as Cookies file", option_cookie_file)); } if (option_cookie_jar == NULL) { - option_cookie_jar = resource_find(respaths, "Cookies"); + option_cookie_jar = filepath_find(respaths, "Cookies"); LOG(("Using '%s' as Cookie Jar file", option_cookie_jar)); } @@ -505,8 +505,8 @@ main(int argc, char** argv) respaths = fb_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"NETSURF_FB_RESPATH":./framebuffer/res:"NETSURF_FB_FONTPATH); - options = resource_find(respaths, "Choices"); - messages = resource_find(respaths, "messages"); + options = filepath_find(respaths, "Choices"); + messages = filepath_find(respaths, "messages"); netsurf_init(&argc, &argv, options, messages); @@ -74,12 +74,12 @@ #include "render/box.h" #include "render/form.h" +#include "utils/filepath.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/url.h" #include "utils/utf8.h" #include "utils/utils.h" -#include "utils/resource.h" char *default_stylesheet_url; char *quirks_stylesheet_url; @@ -138,13 +138,13 @@ nsgtk_init_resource(const char *resource_path) char **pathv; /* resource path string vector */ char **respath; /* resource paths vector */ - pathv = resource_path_to_strvec(resource_path); + pathv = filepath_path_to_strvec(resource_path); langv = g_get_language_names(); - respath = resource_generate(pathv, langv); + respath = filepath_generate(pathv, langv); - resource_free_strvec(pathv); + filepath_free_strvec(pathv); return respath; } @@ -165,7 +165,7 @@ static bool nsgtk_throbber_init(char **respath, int framec) for (frame_num = 0; frame_num < framec; frame_num++) { snprintf(targetname, PATH_MAX, "throbber/throbber%d.png", frame_num); - filenames[frame_num] = resource_find(respath, targetname); + filenames[frame_num] = filepath_find(respath, targetname); } ret = nsgtk_throbber_initialise_from_png(frame_num, filenames); @@ -191,7 +191,7 @@ nsgtk_new_glade(char **respath, const char *name, GladeXML **pglade) snprintf(resname, PATH_MAX, "%s.glade", name); - filepath = resource_find(respath, resname); + filepath = filepath_find(respath, resname); if (filepath == NULL) { snprintf(errorstr, NEW_GLADE_ERROR_SIZE, "Unable to locate %s glade template file.\n", name); @@ -268,12 +268,12 @@ static void check_options(char **respath) * values! */ if (!option_cookie_file) { - resource_sfinddef(respath, buf, "Cookies", "~/.netsurf/"); + filepath_sfinddef(respath, buf, "Cookies", "~/.netsurf/"); LOG(("Using '%s' as Cookies file", buf)); option_cookie_file = strdup(buf); } if (!option_cookie_jar) { - resource_sfinddef(respath, buf, "Cookies", "~/.netsurf/"); + filepath_sfinddef(respath, buf, "Cookies", "~/.netsurf/"); LOG(("Using '%s' as Cookie Jar file", buf)); option_cookie_jar = strdup(buf); } @@ -281,13 +281,13 @@ static void check_options(char **respath) die("Failed initialising cookie options"); if (!option_url_file) { - resource_sfinddef(respath, buf, "URLs", "~/.netsurf/"); + filepath_sfinddef(respath, buf, "URLs", "~/.netsurf/"); LOG(("Using '%s' as URL file", buf)); option_url_file = strdup(buf); } if (!option_ca_path) { - resource_sfinddef(respath, buf, "certs", "/etc/ssl/"); + filepath_sfinddef(respath, buf, "certs", "/etc/ssl/"); LOG(("Using '%s' as certificate path", buf)); option_ca_path = strdup(buf); } @@ -297,12 +297,12 @@ static void check_options(char **respath) option_downloads_directory = hdir; } - resource_sfinddef(respath, buf, "icons/", "~/.netsurf/"); + filepath_sfinddef(respath, buf, "icons/", "~/.netsurf/"); LOG(("Using '%s' as Tree icons dir", buf)); tree_set_icon_dir(strdup(buf)); if (!option_hotlist_path) { - resource_sfinddef(respath, buf, "Hotlist", "~/.netsurf/"); + filepath_sfinddef(respath, buf, "Hotlist", "~/.netsurf/"); LOG(("Using '%s' as Hotlist file", buf)); option_hotlist_path = strdup(buf); } @@ -310,7 +310,7 @@ static void check_options(char **respath) die("Failed initialising hotlist option"); - resource_sfinddef(respath, buf, "Print", "~/.netsurf/"); + filepath_sfinddef(respath, buf, "Print", "~/.netsurf/"); LOG(("Using '%s' as Print Settings file", buf)); print_options_file_location = strdup(buf); @@ -329,7 +329,7 @@ static void check_options(char **respath) char* gui_find_resource(const char *filename) { char buf[PATH_MAX]; - return path_to_url(resource_sfind(respaths, buf, filename)); + return path_to_url(filepath_sfind(respaths, buf, filename)); } @@ -353,33 +353,33 @@ static void gui_init(int argc, char** argv, char **respath) * however these may be translated which breaks things * relying on res_dir_location. */ - resource_filename = resource_find(respath, "languages"); + resource_filename = filepath_find(respath, "languages"); resource_filename[strlen(resource_filename) - 9] = 0; res_dir_location = resource_filename; /* languages file */ - languages_file_location = resource_find(respath, "languages"); + languages_file_location = filepath_find(respath, "languages"); /* initialise the glade templates */ nsgtk_init_glade(respath); /* set default icon if its available */ - resource_filename = resource_find(respath, "netsurf.xpm"); + resource_filename = filepath_find(respath, "netsurf.xpm"); if (resource_filename != NULL) { gtk_window_set_default_icon_from_file(resource_filename, NULL); free(resource_filename); } /* Search engine sources */ - search_engines_file_location = resource_find(respath, "SearchEngines"); + search_engines_file_location = filepath_find(respath, "SearchEngines"); LOG(("Using '%s' as Search Engines file", search_engines_file_location)); /* Default Icon */ - search_default_ico_location = resource_find(respath, "default.ico"); + search_default_ico_location = filepath_find(respath, "default.ico"); LOG(("Using '%s' as default search ico", search_default_ico_location)); /* Toolbar inicies file */ - toolbar_indices_file_location = resource_find(respath, "toolbarIndices"); + toolbar_indices_file_location = filepath_find(respath, "toolbarIndices"); LOG(("Using '%s' as custom toolbar settings file", toolbar_indices_file_location)); /* load throbber images */ @@ -389,7 +389,7 @@ static void gui_init(int argc, char** argv, char **respath) /* Initialise completions - cannot fail */ nsgtk_completion_init(); - resource_sfinddef(respath, buf, "mime.types", "/etc/"); + filepath_sfinddef(respath, buf, "mime.types", "/etc/"); gtk_fetch_filetype_init(buf); /* set up stylesheet urls */ @@ -482,8 +482,8 @@ int main(int argc, char** argv) /* set standard error to be non-buffering */ setbuf(stderr, NULL); - options = resource_find(respaths, "Choices"); - messages = resource_find(respaths, "Messages"); + options = filepath_find(respaths, "Choices"); + messages = filepath_find(respaths, "Messages"); netsurf_init(&argc, &argv, options, messages); diff --git a/monkey/main.c b/monkey/main.c index 168419926..ef38e47de 100644 --- a/monkey/main.c +++ b/monkey/main.c @@ -31,7 +31,7 @@ #include "desktop/gui.h" #include "desktop/netsurf.h" #include "desktop/sslcert.h" -#include "utils/resource.h" +#include "utils/filepath.h" #include "utils/url.h" char *default_stylesheet_url = NULL; @@ -48,13 +48,13 @@ nsmonkey_init_resource(const char *resource_path) char **pathv; /* resource path string vector */ char **respath; /* resource paths vector */ - pathv = resource_path_to_strvec(resource_path); + pathv = filepath_path_to_strvec(resource_path); langv = g_get_language_names(); - respath = resource_generate(pathv, langv); + respath = filepath_generate(pathv, langv); - resource_free_strvec(pathv); + filepath_free_strvec(pathv); return respath; } @@ -75,7 +75,7 @@ void gui_quit(void) char* gui_find_resource(const char *filename) { char buf[PATH_MAX]; - return path_to_url(resource_sfind(respaths, buf, filename)); + return path_to_url(filepath_sfind(respaths, buf, filename)); } void @@ -104,15 +104,15 @@ main(int argc, char **argv) /* Prep the search paths */ respaths = nsmonkey_init_resource("${HOME}/.netsurf/:${NETSURFRES}:"MONKEY_RESPATH":./monkey/res"); - options = resource_find(respaths, "Choices"); - messages = resource_find(respaths, "Messages"); + options = filepath_find(respaths, "Choices"); + messages = filepath_find(respaths, "Messages"); netsurf_init(&argc, &argv, options, messages); free(messages); free(options); - resource_sfinddef(respaths, buf, "mime.types", "/etc/"); + filepath_sfinddef(respaths, buf, "mime.types", "/etc/"); gtk_fetch_filetype_init(buf); default_stylesheet_url = strdup("resource:gtkdefault.css"); diff --git a/utils/resource.c b/utils/filepath.c index 80b1c8280..e2d90bbb7 100644 --- a/utils/resource.c +++ b/utils/filepath.c @@ -32,13 +32,13 @@ #include <string.h> #include "utils/config.h" -#include "utils/resource.h" +#include "utils/filepath.h" /** maximum number of elements in the resource vector */ #define MAX_RESPATH 128 -/* exported interface documented in findresource.h */ -char *resource_vsfindfile(char *str, const char *format, va_list ap) +/* exported interface documented in filepath.h */ +char *filepath_vsfindfile(char *str, const char *format, va_list ap) { char *realpathname; char *pathname; @@ -73,21 +73,21 @@ char *resource_vsfindfile(char *str, const char *format, va_list ap) return realpathname; } -/* exported interface documented in findresource.h */ -char *resource_sfindfile(char *str, const char *format, ...) +/* exported interface documented in filepath.h */ +char *filepath_sfindfile(char *str, const char *format, ...) { va_list ap; char *ret; va_start(ap, format); - ret = resource_vsfindfile(str, format, ap); + ret = filepath_vsfindfile(str, format, ap); va_end(ap); return ret; } -/* exported interface documented in findresource.h */ -char *resource_findfile(const char *format, ...) +/* exported interface documented in filepath.h */ +char *filepath_findfile(const char *format, ...) { char *str; char *ret; @@ -98,7 +98,7 @@ char *resource_findfile(const char *format, ...) return NULL; /* unable to allocate memory */ va_start(ap, format); - ret = resource_vsfindfile(str, format, ap); + ret = filepath_vsfindfile(str, format, ap); va_end(ap); if (ret == NULL) @@ -107,8 +107,8 @@ char *resource_findfile(const char *format, ...) return ret; } -/* exported interface documented in findresource.h */ -char *resource_sfind(char **respathv, char *filepath, const char *filename) +/* exported interface documented in filepath.h */ +char *filepath_sfind(char **respathv, char *filepath, const char *filename) { int respathc = 0; @@ -116,7 +116,7 @@ char *resource_sfind(char **respathv, char *filepath, const char *filename) return NULL; while (respathv[respathc] != NULL) { - if (resource_sfindfile(filepath, "%s/%s", respathv[respathc], filename) != NULL) + if (filepath_sfindfile(filepath, "%s/%s", respathv[respathc], filename) != NULL) return filepath; respathc++; @@ -125,8 +125,8 @@ char *resource_sfind(char **respathv, char *filepath, const char *filename) return NULL; } -/* exported interface documented in findresource.h */ -char *resource_find(char **respathv, const char *filename) +/* exported interface documented in filepath.h */ +char *filepath_find(char **respathv, const char *filename) { char *ret; char *filepath; @@ -138,7 +138,7 @@ char *resource_find(char **respathv, const char *filename) if (filepath == NULL) return NULL; - ret = resource_sfind(respathv, filepath, filename); + ret = filepath_sfind(respathv, filepath, filename); if (ret == NULL) free(filepath); @@ -146,8 +146,8 @@ char *resource_find(char **respathv, const char *filename) return ret; } -/* exported interface documented in findresource.h */ -char *resource_sfinddef(char **respathv, char *filepath, const char *filename, const char *def) +/* exported interface documented in filepath.h */ +char *filepath_sfinddef(char **respathv, char *filepath, const char *filename, const char *def) { char t[PATH_MAX]; char *ret; @@ -155,7 +155,7 @@ char *resource_sfinddef(char **respathv, char *filepath, const char *filename, c if ((respathv == NULL) || (respathv[0] == NULL) || (filepath == NULL)) return NULL; - ret = resource_sfind(respathv, filepath, filename); + ret = filepath_sfind(respathv, filepath, filename); if ((ret == NULL) && (def != NULL)) { /* search failed, return the path specified */ @@ -174,9 +174,9 @@ char *resource_sfinddef(char **respathv, char *filepath, const char *filename, c } -/* exported interface documented in resource.h */ +/* exported interface documented in filepath.h */ char ** -resource_generate(char * const *pathv, const char * const *langv) +filepath_generate(char * const *pathv, const char * const *langv) { char **respath; /* resource paths vector */ int pathc = 0; @@ -262,9 +262,9 @@ expand_path(const char *path) return exp; } -/* exported interface documented in resource.h */ +/* exported interface documented in filepath.h */ char ** -resource_path_to_strvec(const char *path) +filepath_path_to_strvec(const char *path) { char **strvec; int strc = 0; @@ -302,8 +302,8 @@ resource_path_to_strvec(const char *path) return strvec; } -/* exported interface documented in resource.h */ -void resource_free_strvec(char **pathv) +/* exported interface documented in filepath.h */ +void filepath_free_strvec(char **pathv) { free(pathv[0]); free(pathv); diff --git a/utils/resource.h b/utils/filepath.h index fb717cdea..08dd050d3 100644 --- a/utils/resource.h +++ b/utils/filepath.h @@ -16,13 +16,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/** \file Utility routines to locate file resources. */ +/** \file Utility routines to obtain paths to file resources. */ -#ifndef _NETSURF_UTILS_RESOURCE_H_ -#define _NETSURF_UTILS_RESOURCE_H_ +#ifndef _NETSURF_UTILS_FILEPATH_H_ +#define _NETSURF_UTILS_FILEPATH_H_ #include <stdarg.h> + /** Create a normalised file name. * * If the file described by the format exists and is accessible the @@ -36,20 +37,23 @@ * @return A pointer to the expanded filename or NULL if the file is * not present or accessible. */ -char *resource_vsfindfile(char *str, const char *format, va_list ap); +char *filepath_vsfindfile(char *str, const char *format, va_list ap); + /** Create a normalised file name. * * Similar to vsfindfile but takes variadic (printf like) parameters */ -char *resource_sfindfile(char *str, const char *format, ...); +char *filepath_sfindfile(char *str, const char *format, ...); + /** Create a normalised file name. * * Similar to sfindfile but allocates its own storage for the * returned string. The caller must free this sorage. */ -char *resource_findfile(const char *format, ...); +char *filepath_findfile(const char *format, ...); + /** Searches an array of resource paths for a file. * @@ -62,23 +66,27 @@ char *resource_findfile(const char *format, ...); * @param filename The filename of the resource to search for. * @return A pointer to filepath if a target is found or NULL if not. */ -char *resource_sfind(char **respathv, char *filepath, const char *filename); +char *filepath_sfind(char **respathv, char *filepath, const char *filename); + /** Searches an array of resource paths for a file. * - * Similar to resource_sfind except it allocates its own storage for + * Similar to filepath_sfind except it allocates its own storage for * the returned string. The caller must free this sorage. */ -char *resource_find(char **respathv, const char *filename); +char *filepath_find(char **respathv, const char *filename); + /** Searches an array of resource paths for a file optionally forcing a default. * - * Similar to resource_sfind except if no resource is found the default + * Similar to filepath_sfind except if no resource is found the default * is used as an additional path element to search, if that still * fails the returned path is set to the concatination of the default * path and the filename. */ -char *resource_sfinddef(char **respathv, char *filepath, const char *filename, const char *def); +char *filepath_sfinddef(char **respathv, char *filepath, const char *filename, + const char *def); + /** Merge two string vectors into a resource search path vector. * @@ -87,7 +95,7 @@ char *resource_sfinddef(char **respathv, char *filepath, const char *filename, c * @return A pointer to a NULL terminated string vector of valid * resource directories. */ -char **resource_generate(char * const *pathv, const char * const *langv); +char **filepath_generate(char * const *pathv, const char * const *langv); /** Convert a colon separated list of path elements into a string vector. @@ -96,12 +104,13 @@ char **resource_generate(char * const *pathv, const char * const *langv); * @return A pointer to a NULL terminated string vector of valid * resource directories. */ -char **resource_path_to_strvec(const char *path); +char **filepath_path_to_strvec(const char *path); + /** Free a string vector * - * Free a string vector allocated by resource_path_to_strvec + * Free a string vector allocated by filepath_path_to_strvec */ -void resource_free_strvec(char **pathv); +void filepath_free_strvec(char **pathv); -#endif /* _NETSURF_UTILS_RESOURCE_H_ */ +#endif /* _NETSURF_UTILS_FILEPATH_H_ */ |