Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3584 sourcerer 1
/*
2
 * Copyright 2010 Vincent Sanders 
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 .
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 
28
 
29
 
30
/** Create a normalised file name.
31
 *
32
 * If the file described by the format exists and is accessible the
33
 * normalised path is placed in str and a pointer to str returned
34
 * otherwise NULL is returned. The string in str is always modified.
35
 *
36
 * @param str A buffer to contain the normalised file name must be at
37
 *            least PATH_MAX bytes long.
38
 * @param format A printf format for the filename.
39
 * @param ap The list of arguments for the format.
40
 * @return A pointer to the expanded filename or NULL if the file is
41
 *         not present or accessible.
42
 */
43
char *filepath_vsfindfile(char *str, const char *format, va_list ap);
44
 
45
 
46
/** Create a normalised file name.
47
 *
48
 * Similar to vsfindfile but takes variadic (printf like) parameters
49
 */
50
char *filepath_sfindfile(char *str, const char *format, ...);
51
 
52
 
53
/** Create a normalised file name.
54
 *
55
 * Similar to sfindfile but allocates its own storage for the
56
 * returned string. The caller must free this sorage.
57
 */
58
char *filepath_findfile(const char *format, ...);
59
 
60
 
61
/** Searches an array of resource paths for a file.
62
 *
63
 * Iterates through a vector of resource paths and returns the
64
 * normalised file name of the first acessible file or NULL if no file
65
 * can be found in any of the resource paths.
66
 *
67
 * @param respathv The resource path vector to iterate.
68
 * @param filepath The buffer to place the result in.
69
 * @param filename The filename of the resource to search for.
70
 * @return A pointer to filepath if a target is found or NULL if not.
71
 */
72
char *filepath_sfind(char **respathv, char *filepath, const char *filename);
73
 
74
 
75
/** Searches an array of resource paths for a file.
76
 *
77
 * Similar to filepath_sfind except it allocates its own storage for
78
 * the returned string. The caller must free this sorage.
79
 */
80
char *filepath_find(char **respathv, const char *filename);
81
 
82
 
83
/** Searches an array of resource paths for a file optionally forcing a default.
84
 *
85
 * Similar to filepath_sfind except if no resource is found the default
86
 * is used as an additional path element to search, if that still
87
 * fails the returned path is set to the concatination of the default
88
 * path and the filename.
89
 */
90
char *filepath_sfinddef(char **respathv, char *filepath, const char *filename,
91
		const char *def);
92
 
93
 
94
/** Merge two string vectors into a resource search path vector.
95
 *
96
 * @param pathv A string vector containing path elemets to scan.
97
 * @param langv A string vector containing language names to enumerate.
98
 * @return A pointer to a NULL terminated string vector of valid
99
 *         resource directories.
100
 */
101
char **filepath_generate(char * const *pathv, const char * const *langv);
102
 
103
 
104
/** Convert a colon separated list of path elements into a string vector.
105
 *
106
 * @param path A colon separated path.
107
 * @return A pointer to a NULL terminated string vector of valid
108
 *         resource directories.
109
 */
110
char **filepath_path_to_strvec(const char *path);
111
 
112
 
113
/** Free a string vector
114
 *
115
 * Free a string vector allocated by filepath_path_to_strvec
116
 */
117
void filepath_free_strvec(char **pathv);
118
 
119
#endif /* _NETSURF_UTILS_FILEPATH_H_ */