NetSurf
filepath.h
Go to the documentation of this file.
1/*
2 * Copyright 2010 Vincent Sanders <vince@kyllikki.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * @file utils/filepath.h
21 * @brief Utility routines to obtain paths to file resources.
22 */
23
24#ifndef _NETSURF_UTILS_FILEPATH_H_
25#define _NETSURF_UTILS_FILEPATH_H_
26
27#include <stdarg.h>
28
29#include "utils/errors.h"
30
31/**
32 * Create a normalised file name.
33 *
34 * If the file described by the format exists and is accessible the
35 * normalised path is placed in str and a pointer to str returned
36 * otherwise NULL is returned. The string in str is always modified.
37 *
38 * @param str A buffer to contain the normalised file name must be at
39 * least PATH_MAX bytes long.
40 * @param format A printf format for the filename.
41 * @param ap The list of arguments for the format.
42 * @return A pointer to the expanded filename or NULL if the file is
43 * not present or accessible.
44 */
45char *filepath_vsfindfile(char *str, const char *format, va_list ap);
46
47
48/**
49 * Create a normalised file name.
50 *
51 * Similar to vsfindfile but takes variadic (printf like) parameters
52 */
53char *filepath_sfindfile(char *str, const char *format, ...);
54
55
56/**
57 * Create a normalised file name.
58 *
59 * Similar to sfindfile but allocates its own storage for the
60 * returned string. The caller must free this sorage.
61 */
62char *filepath_findfile(const char *format, ...);
63
64
65/**
66 * Searches an array of resource paths for a file.
67 *
68 * Iterates through a vector of resource paths and returns the
69 * normalised file name of the first acessible file or NULL if no file
70 * can be found in any of the resource paths.
71 *
72 * \param respathv The resource path vector to iterate.
73 * \param filepath The buffer to place the result in.
74 * \param filename The filename of the resource to search for.
75 * \return A pointer to filepath if a target is found or NULL if not.
76 */
77char *filepath_sfind(char **respathv, char *filepath, const char *filename);
78
79
80/**
81 * Searches an array of resource paths for a file.
82 *
83 * Similar to filepath_sfind except it allocates its own storage for
84 * the returned string. The caller must free this sorage.
85 */
86char *filepath_find(char **respathv, const char *filename);
87
88
89/**
90 * Searches an array of resource paths for a file optionally forcing a default.
91 *
92 * Similar to filepath_sfind except if no resource is found the default
93 * is used as an additional path element to search, if that still
94 * fails the returned path is set to the concatination of the default
95 * path and the filename.
96 *
97 * \param respathv The resource path vector to iterate.
98 * \param filepath The buffer to place the result in. Must have space for PATH_MAX bytes.
99 * \param filename The filename of the resource to search for.
100 * \param def The default path to use
101 * \return A pointer to filepath if a target is found or the default if not
102 */
103char *filepath_sfinddef(char **respathv, char *filepath, const char *filename,
104 const char *def);
105
106
107/**
108 * Merge two string vectors into a resource search path vector.
109 *
110 * @param pathv A string vector containing path elemets to scan.
111 * @param langv A string vector containing language names to enumerate.
112 * @return A pointer to a NULL terminated string vector of valid
113 * resource directories.
114 */
115char **filepath_generate(char * const *pathv, const char * const *langv);
116
117
118/**
119 * Convert a colon separated list of path elements into a string vector.
120 *
121 * @param path A colon separated path.
122 * @return A pointer to a NULL terminated string vector of valid
123 * resource directories.
124 */
125char **filepath_path_to_strvec(const char *path);
126
127
128/**
129 * Free a string vector.
130 *
131 * Free a string vector allocated by filepath_path_to_strvec
132 */
133void filepath_free_strvec(char **pathv);
134
135
136
137#endif /* _NETSURF_UTILS_FILEPATH_H_ */
Error codes.
char ** filepath_path_to_strvec(const char *path)
Convert a colon separated list of path elements into a string vector.
Definition: filepath.c:313
char * filepath_sfind(char **respathv, char *filepath, const char *filename)
Searches an array of resource paths for a file.
Definition: filepath.c:109
char * filepath_sfindfile(char *str, const char *format,...)
Create a normalised file name.
Definition: filepath.c:82
char * filepath_find(char **respathv, const char *filename)
Searches an array of resource paths for a file.
Definition: filepath.c:129
char * filepath_vsfindfile(char *str, const char *format, va_list ap)
Create a normalised file name.
Definition: filepath.c:45
char * filepath_sfinddef(char **respathv, char *filepath, const char *filename, const char *def)
Searches an array of resource paths for a file optionally forcing a default.
Definition: filepath.c:152
char * filepath_findfile(const char *format,...)
Create a normalised file name.
Definition: filepath.c:96
void filepath_free_strvec(char **pathv)
Free a string vector.
Definition: filepath.c:356
char ** filepath_generate(char *const *pathv, const char *const *langv)
Merge two string vectors into a resource search path vector.
Definition: filepath.c:184
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
Definition: plot.c:821