From 7366191f0d0d5c50ee051a3b60fc31ad86bce721 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Oct 2008 19:36:33 +0200 Subject: mapper: moved musicDir initialization from path.c Moved the musicDir variable and its initialization code from path.c to mapper.c. --- src/mapper.c | 51 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) (limited to 'src/mapper.c') diff --git a/src/mapper.c b/src/mapper.c index 392211214..b1ac6f86c 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -24,13 +24,54 @@ #include "directory.h" #include "song.h" #include "path.h" +#include "conf.h" + +#include +#include +#include +#include + +static char *music_dir; +static size_t music_dir_length; + +void mapper_init(void) +{ + ConfigParam *music_dir_param = parseConfigFilePath(CONF_MUSIC_DIR, 1); + int ret; + struct stat st; + + music_dir = g_strdup(music_dir_param->value); + music_dir_length = strlen(music_dir); + + ret = stat(music_dir, &st); + if (ret < 0) + g_error("failed to stat music directory \"%s\" (config line %i): %s\n", + music_dir_param->value, music_dir_param->line, + strerror(errno)); + else if (!S_ISDIR(st.st_mode)) + g_error("music directory is not a directory: \"%s\" (config line %i)\n", + music_dir_param->value, music_dir_param->line); +} + +void mapper_finish(void) +{ + g_free(music_dir); +} + +static char * +rmp2amp_r(char *dst, const char *rel_path) +{ + pfx_dir(dst, rel_path, strlen(rel_path), + (const char *)music_dir, music_dir_length); + return dst; +} const char * map_directory_fs(const struct directory *directory, char *buffer) { const char *dirname = directory_get_path(directory); if (isRootDirectory(dirname)) - return musicDir; + return music_dir; return rmp2amp_r(buffer, utf8_to_fs_charset(buffer, dirname)); } @@ -63,12 +104,10 @@ map_song_fs(const struct song *song, char *buffer) const char * map_fs_to_utf8(const char *path_fs, char *buffer) { - size_t music_path_length = strlen(musicDir); - - if (strncmp(path_fs, musicDir, music_path_length) == 0 && - path_fs[music_path_length] == '/') + if (strncmp(path_fs, music_dir, music_dir_length) == 0 && + path_fs[music_dir_length] == '/') /* remove musicDir prefix */ - path_fs += music_path_length; + path_fs += music_dir_length; else if (path_fs[0] == '/') /* not within musicDir */ return NULL; -- cgit v1.2.3