2010-07-28 19:22:44 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Vincent Sanders <vince@kyllikki.org>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-03-17 14:26:30 +03:00
|
|
|
/** \file Utility routines to obtain paths to file resources. */
|
2011-02-24 01:27:55 +03:00
|
|
|
|
2011-03-17 14:26:30 +03:00
|
|
|
#ifndef _NETSURF_UTILS_FILEPATH_H_
|
|
|
|
#define _NETSURF_UTILS_FILEPATH_H_
|
2010-07-28 19:22:44 +04:00
|
|
|
|
2011-03-12 18:08:07 +03:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2011-03-17 14:26:30 +03:00
|
|
|
|
2010-07-28 19:22:44 +04:00
|
|
|
/** Create a normalised file name.
|
|
|
|
*
|
|
|
|
* If the file described by the format exists and is accessible the
|
|
|
|
* normalised path is placed in str and a pointer to str returned
|
|
|
|
* otherwise NULL is returned. The string in str is always modified.
|
|
|
|
*
|
|
|
|
* @param str A buffer to contain the normalised file name must be at
|
|
|
|
* least PATH_MAX bytes long.
|
|
|
|
* @param format A printf format for the filename.
|
|
|
|
* @param ap The list of arguments for the format.
|
|
|
|
* @return A pointer to the expanded filename or NULL if the file is
|
|
|
|
* not present or accessible.
|
|
|
|
*/
|
2011-03-17 14:26:30 +03:00
|
|
|
char *filepath_vsfindfile(char *str, const char *format, va_list ap);
|
|
|
|
|
2010-07-28 19:22:44 +04:00
|
|
|
|
|
|
|
/** Create a normalised file name.
|
|
|
|
*
|
|
|
|
* Similar to vsfindfile but takes variadic (printf like) parameters
|
|
|
|
*/
|
2011-03-17 14:26:30 +03:00
|
|
|
char *filepath_sfindfile(char *str, const char *format, ...);
|
|
|
|
|
2010-07-28 19:22:44 +04:00
|
|
|
|
|
|
|
/** Create a normalised file name.
|
|
|
|
*
|
|
|
|
* Similar to sfindfile but allocates its own storage for the
|
|
|
|
* returned string. The caller must free this sorage.
|
|
|
|
*/
|
2011-03-17 14:26:30 +03:00
|
|
|
char *filepath_findfile(const char *format, ...);
|
|
|
|
|
2010-07-28 19:22:44 +04:00
|
|
|
|
|
|
|
/** Searches an array of resource paths for a file.
|
|
|
|
*
|
|
|
|
* Iterates through a vector of resource paths and returns the
|
|
|
|
* normalised file name of the first acessible file or NULL if no file
|
|
|
|
* can be found in any of the resource paths.
|
|
|
|
*
|
|
|
|
* @param respathv The resource path vector to iterate.
|
|
|
|
* @param filepath The buffer to place the result in.
|
|
|
|
* @param filename The filename of the resource to search for.
|
|
|
|
* @return A pointer to filepath if a target is found or NULL if not.
|
|
|
|
*/
|
2011-03-17 14:26:30 +03:00
|
|
|
char *filepath_sfind(char **respathv, char *filepath, const char *filename);
|
|
|
|
|
2010-07-28 19:22:44 +04:00
|
|
|
|
|
|
|
/** Searches an array of resource paths for a file.
|
|
|
|
*
|
2011-03-17 14:26:30 +03:00
|
|
|
* Similar to filepath_sfind except it allocates its own storage for
|
2010-07-28 19:22:44 +04:00
|
|
|
* the returned string. The caller must free this sorage.
|
|
|
|
*/
|
2011-03-17 14:26:30 +03:00
|
|
|
char *filepath_find(char **respathv, const char *filename);
|
|
|
|
|
2010-07-28 19:22:44 +04:00
|
|
|
|
|
|
|
/** Searches an array of resource paths for a file optionally forcing a default.
|
|
|
|
*
|
2011-03-17 14:26:30 +03:00
|
|
|
* Similar to filepath_sfind except if no resource is found the default
|
2010-07-28 19:22:44 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
2011-03-17 14:26:30 +03:00
|
|
|
char *filepath_sfinddef(char **respathv, char *filepath, const char *filename,
|
|
|
|
const char *def);
|
|
|
|
|
2010-07-28 19:22:44 +04:00
|
|
|
|
|
|
|
/** Merge two string vectors into a resource search path vector.
|
|
|
|
*
|
|
|
|
* @param pathv A string vector containing path elemets to scan.
|
|
|
|
* @param langv A string vector containing language names to enumerate.
|
|
|
|
* @return A pointer to a NULL terminated string vector of valid
|
|
|
|
* resource directories.
|
|
|
|
*/
|
2011-03-17 14:26:30 +03:00
|
|
|
char **filepath_generate(char * const *pathv, const char * const *langv);
|
2011-02-24 01:27:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
/** Convert a colon separated list of path elements into a string vector.
|
|
|
|
*
|
|
|
|
* @param path A colon separated path.
|
|
|
|
* @return A pointer to a NULL terminated string vector of valid
|
|
|
|
* resource directories.
|
|
|
|
*/
|
2011-03-17 14:26:30 +03:00
|
|
|
char **filepath_path_to_strvec(const char *path);
|
|
|
|
|
2011-02-24 01:27:55 +03:00
|
|
|
|
|
|
|
/** Free a string vector
|
|
|
|
*
|
2011-03-17 14:26:30 +03:00
|
|
|
* Free a string vector allocated by filepath_path_to_strvec
|
2011-02-24 01:27:55 +03:00
|
|
|
*/
|
2011-03-17 14:26:30 +03:00
|
|
|
void filepath_free_strvec(char **pathv);
|
2010-07-28 19:22:44 +04:00
|
|
|
|
2011-03-17 14:26:30 +03:00
|
|
|
#endif /* _NETSURF_UTILS_FILEPATH_H_ */
|