diff options
-rw-r--r-- | src/database.c | 19 | ||||
-rw-r--r-- | src/dbUtils.c | 4 | ||||
-rw-r--r-- | src/directory.c | 46 | ||||
-rw-r--r-- | src/directory.h | 25 | ||||
-rw-r--r-- | src/dirvec.c | 2 | ||||
-rw-r--r-- | src/song.c | 4 | ||||
-rw-r--r-- | src/song_print.c | 2 | ||||
-rw-r--r-- | src/song_save.c | 2 | ||||
-rw-r--r-- | src/update.c | 12 |
9 files changed, 58 insertions, 58 deletions
diff --git a/src/database.c b/src/database.c index 78ae8ab06..46d5a6352 100644 --- a/src/database.c +++ b/src/database.c @@ -39,7 +39,7 @@ static time_t directory_dbModTime; void db_init(void) { - music_root = newDirectory(NULL, NULL); + music_root = directory_new(NULL, NULL); updateDirectory(music_root); stats.numberOfSongs = countSongsIn(NULL); stats.dbPlayTime = sumSongTimesIn(NULL); @@ -48,7 +48,7 @@ db_init(void) void db_finish(void) { - freeDirectory(music_root); + directory_free(music_root); } struct directory * @@ -65,7 +65,7 @@ db_get_directory(const char *name) if (name == NULL) return music_root; - return getSubDirectory(music_root, name); + return directory_get_directory(music_root, name); } struct song * @@ -113,8 +113,7 @@ db_walk(const char *name, return -1; } - return traverseAllInSubDirectory(directory, forEachSong, forEachDir, - data); + return directory_walk(directory, forEachSong, forEachDir, data); } static char * @@ -197,11 +196,11 @@ db_save(void) struct stat st; DEBUG("removing empty directories from DB\n"); - deleteEmptyDirectoriesInDirectory(music_root); + directory_prune_empty(music_root); DEBUG("sorting DB\n"); - sortDirectory(music_root); + directory_sort(music_root); DEBUG("writing DB\n"); @@ -218,7 +217,7 @@ db_save(void) fprintf(fp, "%s%s\n", DIRECTORY_FS_CHARSET, getFsCharset()); fprintf(fp, "%s\n", DIRECTORY_INFO_END); - if (writeDirectoryInfo(fp, music_root) < 0) { + if (directory_save(fp, music_root) < 0) { ERROR("Failed to write to database file: %s\n", strerror(errno)); while (fclose(fp) && errno == EINTR); @@ -241,7 +240,7 @@ db_load(void) struct stat st; if (!music_root) - music_root = newDirectory(NULL, NULL); + music_root = directory_new(NULL, NULL); while (!(fp = fopen(dbFile, "r")) && errno == EINTR) ; if (fp == NULL) { ERROR("unable to open db file \"%s\": %s\n", @@ -302,7 +301,7 @@ db_load(void) DEBUG("reading DB\n"); - readDirectoryInfo(fp, music_root); + directory_load(fp, music_root); while (fclose(fp) && errno == EINTR) ; stats.numberOfSongs = countSongsIn(NULL); diff --git a/src/dbUtils.c b/src/dbUtils.c index 6a803f621..f7a495501 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -62,7 +62,7 @@ printDirectoryInDirectory(struct directory *directory, void *data) { struct client *client = data; if (directory->path) { - client_printf(client, "directory: %s\n", getDirectoryPath(directory)); + client_printf(client, "directory: %s\n", directory_get_path(directory)); } return 0; } @@ -374,7 +374,7 @@ sumSavedFilenameMemoryInDirectory(struct directory *dir, void *data) if (!dir->path) return 0; - *sum += (strlen(getDirectoryPath(dir)) + 1 + *sum += (strlen(directory_get_path(dir)) + 1 - sizeof(struct directory *)) * dir->songs.nr; return 0; diff --git a/src/directory.c b/src/directory.c index f5ee8693c..af278664c 100644 --- a/src/directory.c +++ b/src/directory.c @@ -28,7 +28,7 @@ #include "dirvec.h" struct directory * -newDirectory(const char *dirname, struct directory * parent) +directory_new(const char *dirname, struct directory *parent) { struct directory *directory; @@ -42,7 +42,7 @@ newDirectory(const char *dirname, struct directory * parent) } void -freeDirectory(struct directory * directory) +directory_free(struct directory *directory) { dirvec_destroy(&directory->children); songvec_destroy(&directory->songs); @@ -50,17 +50,17 @@ freeDirectory(struct directory * directory) free(directory->path); free(directory); /* this resets last dir returned */ - /*getDirectoryPath(NULL); */ + /*directory_get_path(NULL); */ } void -deleteEmptyDirectoriesInDirectory(struct directory *directory) +directory_prune_empty(struct directory *directory) { int i; struct dirvec *dv = &directory->children; for (i = dv->nr; --i >= 0; ) { - deleteEmptyDirectoriesInDirectory(dv->base[i]); + directory_prune_empty(dv->base[i]); if (directory_is_empty(dv->base[i])) dirvec_delete(dv, dv->base[i]); } @@ -69,7 +69,7 @@ deleteEmptyDirectoriesInDirectory(struct directory *directory) } struct directory * -getSubDirectory(struct directory * directory, const char *name) +directory_get_directory(struct directory *directory, const char *name) { struct directory *cur = directory; struct directory *found = NULL; @@ -102,13 +102,13 @@ getSubDirectory(struct directory * directory, const char *name) } static int -printDirectoryList(struct client *client, const struct dirvec *dv) +dirvec_print(struct client *client, const struct dirvec *dv) { size_t i; for (i = 0; i < dv->nr; ++i) { client_printf(client, DIRECTORY_DIR "%s\n", - getDirectoryPath(dv->base[i])); + directory_get_path(dv->base[i])); } return 0; @@ -117,7 +117,7 @@ printDirectoryList(struct client *client, const struct dirvec *dv) int directory_print(struct client *client, const struct directory *directory) { - printDirectoryList(client, &directory->children); + dirvec_print(client, &directory->children); songvec_print(client, &directory->songs); return 0; @@ -125,7 +125,7 @@ directory_print(struct client *client, const struct directory *directory) /* TODO error checking */ int -writeDirectoryInfo(FILE * fp, struct directory * directory) +directory_save(FILE *fp, struct directory *directory) { struct dirvec *children = &directory->children; size_t i; @@ -133,7 +133,7 @@ writeDirectoryInfo(FILE * fp, struct directory * directory) if (directory->path) { retv = fprintf(fp, "%s%s\n", DIRECTORY_BEGIN, - getDirectoryPath(directory)); + directory_get_path(directory)); if (retv < 0) return -1; } @@ -145,7 +145,7 @@ writeDirectoryInfo(FILE * fp, struct directory * directory) retv = fprintf(fp, DIRECTORY_DIR "%s\n", base); if (retv < 0) return -1; - if (writeDirectoryInfo(fp, cur) < 0) + if (directory_save(fp, cur) < 0) return -1; } @@ -153,13 +153,13 @@ writeDirectoryInfo(FILE * fp, struct directory * directory) if (directory->path && fprintf(fp, DIRECTORY_END "%s\n", - getDirectoryPath(directory)) < 0) + directory_get_path(directory)) < 0) return -1; return 0; } void -readDirectoryInfo(FILE * fp, struct directory * directory) +directory_load(FILE *fp, struct directory *directory) { char buffer[MPD_PATH_MAX * 2]; int bufferSize = MPD_PATH_MAX * 2; @@ -185,10 +185,10 @@ readDirectoryInfo(FILE * fp, struct directory * directory) if ((subdir = db_get_directory(name))) { assert(subdir->parent == directory); } else { - subdir = newDirectory(name, directory); + subdir = directory_new(name, directory); dirvec_add(&directory->children, subdir); } - readDirectoryInfo(fp, subdir); + directory_load(fp, subdir); } else if (!prefixcmp(buffer, SONG_BEGIN)) { readSongInfoIntoList(fp, &directory->songs, directory); } else { @@ -198,7 +198,7 @@ readDirectoryInfo(FILE * fp, struct directory * directory) } void -sortDirectory(struct directory * directory) +directory_sort(struct directory *directory) { int i; struct dirvec *dv = &directory->children; @@ -207,14 +207,14 @@ sortDirectory(struct directory * directory) songvec_sort(&directory->songs); for (i = dv->nr; --i >= 0; ) - sortDirectory(dv->base[i]); + directory_sort(dv->base[i]); } int -traverseAllInSubDirectory(struct directory * directory, - int (*forEachSong) (struct song *, void *), - int (*forEachDir) (struct directory *, void *), - void *data) +directory_walk(struct directory *directory, + int (*forEachSong)(struct song *, void *), + int (*forEachDir)(struct directory *, void *), + void *data) { struct dirvec *dv = &directory->children; int err = 0; @@ -230,7 +230,7 @@ traverseAllInSubDirectory(struct directory * directory, } for (j = 0; err >= 0 && j < dv->nr; ++j) - err = traverseAllInSubDirectory(dv->base[j], forEachSong, + err = directory_walk(dv->base[j], forEachSong, forEachDir, data); return err; diff --git a/src/directory.h b/src/directory.h index 90f84f9b6..b378a93f1 100644 --- a/src/directory.h +++ b/src/directory.h @@ -59,10 +59,10 @@ isRootDirectory(const char *name) } struct directory * -newDirectory(const char *dirname, struct directory * parent); +directory_new(const char *dirname, struct directory *parent); void -freeDirectory(struct directory * directory); +directory_free(struct directory *directory); static inline bool directory_is_empty(struct directory *directory) @@ -71,28 +71,29 @@ directory_is_empty(struct directory *directory) } void -deleteEmptyDirectoriesInDirectory(struct directory *directory); +directory_prune_empty(struct directory *directory); struct directory * -getSubDirectory(struct directory *directory, const char *name); +directory_get_directory(struct directory *directory, const char *name); int directory_print(struct client *client, const struct directory *directory); int -writeDirectoryInfo(FILE *fp, struct directory *directory); +directory_save(FILE *fp, struct directory *directory); void -readDirectoryInfo(FILE *fp, struct directory *directory); +directory_load(FILE *fp, struct directory *directory); void -sortDirectory(struct directory * directory); +directory_sort(struct directory *directory); + int -traverseAllInSubDirectory(struct directory * directory, - int (*forEachSong) (struct song *, void *), - int (*forEachDir) (struct directory *, void *), - void *data); +directory_walk(struct directory *directory, + int (*forEachSong)(struct song *, void *), + int (*forEachDir)(struct directory *, void *), + void *data); -#define getDirectoryPath(dir) ((dir && dir->path) ? dir->path : "") +#define directory_get_path(dir) ((dir && dir->path) ? dir->path : "") #endif diff --git a/src/dirvec.c b/src/dirvec.c index 589e8d0fe..de2380e91 100644 --- a/src/dirvec.c +++ b/src/dirvec.c @@ -39,7 +39,7 @@ int dirvec_delete(struct dirvec *dv, struct directory *del) for (i = dv->nr; --i >= 0; ) { if (dv->base[i] != del) continue; - /* we _don't_ call freeDirectory() here */ + /* we _don't_ call directory_free() here */ if (!--dv->nr) { free(dv->base); dv->base = NULL; diff --git a/src/song.c b/src/song.c index 5653e045d..9cecbf815 100644 --- a/src/song.c +++ b/src/song.c @@ -128,7 +128,7 @@ song_get_url(struct song *song, char *path_max_tmp) strcpy(path_max_tmp, song->url); else pfx_dir(path_max_tmp, song->url, strlen(song->url), - getDirectoryPath(song->parent), - strlen(getDirectoryPath(song->parent))); + directory_get_path(song->parent), + strlen(directory_get_path(song->parent))); return path_max_tmp; } diff --git a/src/song_print.c b/src/song_print.c index e646f23de..879cf48ea 100644 --- a/src/song_print.c +++ b/src/song_print.c @@ -28,7 +28,7 @@ song_print_url(struct client *client, struct song *song) { if (song->parent && song->parent->path) { client_printf(client, "%s%s/%s\n", SONG_FILE, - getDirectoryPath(song->parent), song->url); + directory_get_path(song->parent), song->url); } else { client_printf(client, "%s%s\n", SONG_FILE, song->url); } diff --git a/src/song_save.c b/src/song_save.c index 1afac0979..41e694611 100644 --- a/src/song_save.c +++ b/src/song_save.c @@ -33,7 +33,7 @@ song_save_url(FILE *fp, struct song *song) { if (song->parent != NULL && song->parent->path != NULL) fprintf(fp, SONG_FILE "%s/%s\n", - getDirectoryPath(song->parent), song->url); + directory_get_path(song->parent), song->url); else fprintf(fp, SONG_FILE "%s\n", song->url); diff --git a/src/update.c b/src/update.c index 2bab75398..8bbb76eb1 100644 --- a/src/update.c +++ b/src/update.c @@ -141,7 +141,7 @@ statDirectory(struct directory *dir) { struct stat st; - if (myStat(getDirectoryPath(dir), &st) < 0) + if (myStat(directory_get_path(dir), &st) < 0) return -1; directory_set_stat(dir, &st); @@ -174,11 +174,11 @@ addSubDirectoryToDirectory(struct directory *directory, if (inodeFoundInParent(directory, st->st_ino, st->st_dev)) return UPDATE_RETURN_NOUPDATE; - subDirectory = newDirectory(name, directory); + subDirectory = directory_new(name, directory); directory_set_stat(subDirectory, st); if (updateDirectory(subDirectory) != UPDATE_RETURN_UPDATED) { - freeDirectory(subDirectory); + directory_free(subDirectory); return UPDATE_RETURN_NOUPDATE; } @@ -262,7 +262,7 @@ updateDirectory(struct directory *directory) { bool was_empty = directory_is_empty(directory); DIR *dir; - const char *dirname = getDirectoryPath(directory); + const char *dirname = directory_get_path(directory); struct dirent *ent; char path_max_tmp[MPD_PATH_MAX]; enum update_return ret = UPDATE_RETURN_NOUPDATE; @@ -336,7 +336,7 @@ addDirectoryPathToDB(const char *utf8path) inodeFoundInParent(parentDirectory, st.st_ino, st.st_dev)) return NULL; else { - directory = newDirectory(utf8path, parentDirectory); + directory = directory_new(utf8path, parentDirectory); dirvec_add(&parentDirectory->children, directory); } } @@ -392,7 +392,7 @@ static enum update_return updatePath(const char *utf8path) ret = updateDirectory(directory); if (ret != UPDATE_RETURN_ERROR) { free(path); - sortDirectory(directory); + directory_sort(directory); return ret; } /* we don't want to delete the root directory */ |