diff options
Diffstat (limited to '')
-rw-r--r-- | src/dbUtils.c | 11 | ||||
-rw-r--r-- | src/directory.c | 57 | ||||
-rw-r--r-- | src/directory.h | 22 | ||||
-rw-r--r-- | src/dirvec.c | 17 | ||||
-rw-r--r-- | src/dirvec.h | 8 | ||||
-rw-r--r-- | src/song.c | 6 | ||||
-rw-r--r-- | src/song.h | 6 | ||||
-rw-r--r-- | src/update.c | 42 | ||||
-rw-r--r-- | src/update.h | 4 |
9 files changed, 89 insertions, 84 deletions
diff --git a/src/dbUtils.c b/src/dbUtils.c index bd990e96d..4c52fffc2 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -45,8 +45,7 @@ typedef struct _SearchStats { unsigned long playTime; } SearchStats; -static int countSongsInDirectory(Directory * directory, - void *data) +static int countSongsInDirectory(struct directory *directory, void *data) { int *count = (int *)data; @@ -55,7 +54,7 @@ static int countSongsInDirectory(Directory * directory, return 0; } -static int printDirectoryInDirectory(Directory * directory, void *data) +static int printDirectoryInDirectory(struct directory *directory, void *data) { int fd = (int)(size_t)data; if (directory->path) { @@ -336,15 +335,15 @@ int listAllUniqueTags(int fd, int type, int numConditionals, return ret; } -static int sumSavedFilenameMemoryInDirectory(Directory * dir, void *data) +static int sumSavedFilenameMemoryInDirectory(struct directory *dir, void *data) { int *sum = data; if (!dir->path) return 0; - *sum += (strlen(getDirectoryPath(dir)) + 1 - sizeof(Directory *)) * - dir->songs.nr; + *sum += (strlen(getDirectoryPath(dir)) + 1 + - sizeof(struct directory *)) * dir->songs.nr; return 0; } diff --git a/src/directory.c b/src/directory.c index 83835c15a..2a49fe8ff 100644 --- a/src/directory.c +++ b/src/directory.c @@ -39,11 +39,11 @@ #define DIRECTORY_MPD_VERSION "mpd_version: " #define DIRECTORY_FS_CHARSET "fs_charset: " -static Directory *music_root; +static struct directory *music_root; static time_t directory_dbModTime; -static void deleteEmptyDirectoriesInDirectory(Directory * directory); +static void deleteEmptyDirectoriesInDirectory(struct directory * directory); static char *getDbFile(void) { @@ -55,11 +55,11 @@ static char *getDbFile(void) return param->value; } -Directory *newDirectory(const char *dirname, Directory * parent) +struct directory * newDirectory(const char *dirname, struct directory * parent) { - Directory *directory; + struct directory *directory; - directory = xcalloc(1, sizeof(Directory)); + directory = xcalloc(1, sizeof(*directory)); if (dirname && strlen(dirname)) directory->path = xstrdup(dirname); @@ -68,7 +68,7 @@ Directory *newDirectory(const char *dirname, Directory * parent) return directory; } -void freeDirectory(Directory * directory) +void freeDirectory(struct directory * directory) { dirvec_destroy(&directory->children); songvec_destroy(&directory->songs); @@ -79,7 +79,7 @@ void freeDirectory(Directory * directory) /*getDirectoryPath(NULL); */ } -static void deleteEmptyDirectoriesInDirectory(Directory * directory) +static void deleteEmptyDirectoriesInDirectory(struct directory * directory) { int i; struct dirvec *dv = &directory->children; @@ -98,7 +98,7 @@ void directory_finish(void) freeDirectory(music_root); } -Directory * directory_get_root(void) +struct directory * directory_get_root(void) { assert(music_root != NULL); @@ -110,10 +110,11 @@ int isRootDirectory(const char *name) return (!name || name[0] == '\0' || !strcmp(name, "/")); } -static Directory *getSubDirectory(Directory * directory, const char *name) +static struct directory * +getSubDirectory(struct directory * directory, const char *name) { - Directory *cur = directory; - Directory *found = NULL; + struct directory *cur = directory; + struct directory *found = NULL; char *duplicated; char *locate; @@ -140,7 +141,7 @@ static Directory *getSubDirectory(Directory * directory, const char *name) return found; } -Directory *getDirectory(const char *name) +struct directory * getDirectory(const char *name) { return getSubDirectory(music_root, name); } @@ -160,7 +161,7 @@ static int printDirectoryList(int fd, struct dirvec *dv) int printDirectoryInfo(int fd, const char *name) { - Directory *directory; + struct directory *directory; if ((directory = getDirectory(name)) == NULL) return -1; @@ -187,7 +188,7 @@ static int directory_song_write(Song *song, void *data) } /* TODO error checking */ -static int writeDirectoryInfo(int fd, Directory * directory) +static int writeDirectoryInfo(int fd, struct directory * directory) { struct dirvec *children = &directory->children; size_t i; @@ -198,7 +199,7 @@ static int writeDirectoryInfo(int fd, Directory * directory) return -1; for (i = 0; i < children->nr; ++i) { - Directory *cur = children->base[i]; + struct directory *cur = children->base[i]; const char *base = mpd_basename(cur->path); if (fdprintf(fd, DIRECTORY_DIR "%s\n", base) < 0) @@ -224,7 +225,7 @@ static int writeDirectoryInfo(int fd, Directory * directory) return 0; } -static void readDirectoryInfo(FILE * fp, Directory * directory) +static void readDirectoryInfo(FILE * fp, struct directory * directory) { char buffer[MPD_PATH_MAX * 2]; int bufferSize = MPD_PATH_MAX * 2; @@ -234,7 +235,7 @@ static void readDirectoryInfo(FILE * fp, Directory * directory) while (myFgets(buffer, bufferSize, fp) && prefixcmp(buffer, DIRECTORY_END)) { if (!prefixcmp(buffer, DIRECTORY_DIR)) { - Directory *subdir; + struct directory *subdir; strcpy(key, &(buffer[strlen(DIRECTORY_DIR)])); if (!myFgets(buffer, bufferSize, fp)) @@ -262,7 +263,7 @@ static void readDirectoryInfo(FILE * fp, Directory * directory) } } -void sortDirectory(Directory * directory) +void sortDirectory(struct directory * directory) { int i; struct dirvec *dv = &directory->children; @@ -460,10 +461,11 @@ int readDirectoryDB(void) return 0; } -static int traverseAllInSubDirectory(Directory * directory, - int (*forEachSong) (Song *, void *), - int (*forEachDir) (Directory *, void *), - void *data) +static int +traverseAllInSubDirectory(struct directory * directory, + int (*forEachSong) (Song *, void *), + int (*forEachDir) (struct directory *, void *), + void *data) { struct dirvec *dv = &directory->children; int err = 0; @@ -485,11 +487,12 @@ static int traverseAllInSubDirectory(Directory * directory, return err; } -int traverseAllIn(const char *name, - int (*forEachSong) (Song *, void *), - int (*forEachDir) (Directory *, void *), void *data) +int +traverseAllIn(const char *name, + int (*forEachSong) (Song *, void *), + int (*forEachDir) (struct directory *, void *), void *data) { - Directory *directory; + struct directory *directory; if ((directory = getDirectory(name)) == NULL) { Song *song; @@ -514,7 +517,7 @@ void directory_init(void) Song *getSongFromDB(const char *file) { Song *song = NULL; - Directory *directory; + struct directory *directory; char *dir = NULL; char *duplicated = xstrdup(file); char *shortname = strrchr(duplicated, '/'); diff --git a/src/directory.h b/src/directory.h index 552bbe28e..d604800e8 100644 --- a/src/directory.h +++ b/src/directory.h @@ -23,19 +23,19 @@ #include "songvec.h" struct dirvec { - struct _Directory **base; + struct directory **base; size_t nr; }; -typedef struct _Directory { +struct directory { char *path; struct dirvec children; struct songvec songs; - struct _Directory *parent; + struct directory *parent; ino_t inode; dev_t device; unsigned stat; /* not needed if ino_t == dev_t == 0 is impossible */ -} Directory; +}; void directory_init(void); @@ -43,20 +43,20 @@ void directory_finish(void); int isRootDirectory(const char *name); -Directory * directory_get_root(void); +struct directory * directory_get_root(void); -Directory * newDirectory(const char *dirname, Directory * parent); +struct directory * newDirectory(const char *dirname, struct directory *parent); -void freeDirectory(Directory * directory); +void freeDirectory(struct directory *directory); -static inline int directory_is_empty(Directory *directory) +static inline int directory_is_empty(struct directory *directory) { return directory->children.nr == 0 && directory->songs.nr == 0; } -Directory * getDirectory(const char *name); +struct directory * getDirectory(const char *name); -void sortDirectory(Directory * directory); +void sortDirectory(struct directory * directory); int printDirectoryInfo(int fd, const char *dirname); @@ -72,7 +72,7 @@ time_t getDbModTime(void); int traverseAllIn(const char *name, int (*forEachSong) (Song *, void *), - int (*forEachDir) (Directory *, void *), void *data); + int (*forEachDir) (struct directory *, void *), void *data); #define getDirectoryPath(dir) ((dir && dir->path) ? dir->path : "") diff --git a/src/dirvec.c b/src/dirvec.c index f84aa37fc..9226fca74 100644 --- a/src/dirvec.c +++ b/src/dirvec.c @@ -1,26 +1,27 @@ #include "dirvec.h" +#include "directory.h" #include "os_compat.h" #include "utils.h" static size_t dv_size(struct dirvec *dv) { - return dv->nr * sizeof(Directory *); + return dv->nr * sizeof(struct directory *); } /* Only used for sorting/searching a dirvec, not general purpose compares */ static int dirvec_cmp(const void *d1, const void *d2) { - const Directory *a = ((const Directory * const *)d1)[0]; - const Directory *b = ((const Directory * const *)d2)[0]; + const struct directory *a = ((const struct directory * const *)d1)[0]; + const struct directory *b = ((const struct directory * const *)d2)[0]; return strcmp(a->path, b->path); } void dirvec_sort(struct dirvec *dv) { - qsort(dv->base, dv->nr, sizeof(Directory *), dirvec_cmp); + qsort(dv->base, dv->nr, sizeof(struct directory *), dirvec_cmp); } -Directory *dirvec_find(struct dirvec *dv, const char *path) +struct directory *dirvec_find(struct dirvec *dv, const char *path) { int i; @@ -30,7 +31,7 @@ Directory *dirvec_find(struct dirvec *dv, const char *path) return NULL; } -int dirvec_delete(struct dirvec *dv, Directory *del) +int dirvec_delete(struct dirvec *dv, struct directory *del) { int i; @@ -43,7 +44,7 @@ int dirvec_delete(struct dirvec *dv, Directory *del) dv->base = NULL; } else { memmove(&dv->base[i], &dv->base[i + 1], - (dv->nr - i + 1) * sizeof(Directory *)); + (dv->nr - i + 1) * sizeof(struct directory *)); dv->base = xrealloc(dv->base, dv_size(dv)); } return i; @@ -52,7 +53,7 @@ int dirvec_delete(struct dirvec *dv, Directory *del) return -1; /* not found */ } -void dirvec_add(struct dirvec *dv, Directory *add) +void dirvec_add(struct dirvec *dv, struct directory *add) { ++dv->nr; dv->base = xrealloc(dv->base, dv_size(dv)); diff --git a/src/dirvec.h b/src/dirvec.h index 94abd681f..31719fcc8 100644 --- a/src/dirvec.h +++ b/src/dirvec.h @@ -1,15 +1,15 @@ #ifndef DIRVEC_H #define DIRVEC_H -#include "directory.h" +struct dirvec; void dirvec_sort(struct dirvec *dv); -Directory *dirvec_find(struct dirvec *dv, const char *path); +struct directory *dirvec_find(struct dirvec *dv, const char *path); -int dirvec_delete(struct dirvec *dv, Directory *del); +int dirvec_delete(struct dirvec *dv, struct directory *del); -void dirvec_add(struct dirvec *dv, Directory *add); +void dirvec_add(struct dirvec *dv, struct directory *add); void dirvec_destroy(struct dirvec *dv); diff --git a/src/song.c b/src/song.c index 03f65dd0d..f8a949578 100644 --- a/src/song.c +++ b/src/song.c @@ -29,7 +29,7 @@ #include "os_compat.h" -static Song * song_alloc(const char *url, Directory *parent) +static Song * song_alloc(const char *url, struct directory *parent) { size_t urllen; Song *song; @@ -46,7 +46,7 @@ static Song * song_alloc(const char *url, Directory *parent) return song; } -Song *newSong(const char *url, Directory * parentDir) +Song *newSong(const char *url, struct directory *parentDir) { Song *song; assert(*url); @@ -160,7 +160,7 @@ static int matchesAnMpdTagItemKey(char *buffer, int *itemType) return 0; } -void readSongInfoIntoList(FILE * fp, Directory * parentDir) +void readSongInfoIntoList(FILE * fp, struct directory * parentDir) { char buffer[MPD_PATH_MAX + 1024]; int bufferSize = MPD_PATH_MAX + 1024; diff --git a/src/song.h b/src/song.h index 46cf8f5cb..fcba961f0 100644 --- a/src/song.h +++ b/src/song.h @@ -35,12 +35,12 @@ typedef struct _Song { struct mpd_tag *tag; - struct _Directory *parentDir; + struct directory *parentDir; time_t mtime; char url[sizeof(size_t)]; } Song; -Song *newSong(const char *url, struct _Directory *parentDir); +Song *newSong(const char *url, struct directory *parentDir); void freeJustSong(Song *); @@ -49,7 +49,7 @@ ssize_t song_print_info(Song * song, int fd); /* like song_print_info, but casts data into an fd first */ int song_print_info_x(Song * song, void *data); -void readSongInfoIntoList(FILE * fp, struct _Directory *parent); +void readSongInfoIntoList(FILE * fp, struct directory *parent); int updateSongInfo(Song * song); diff --git a/src/update.c b/src/update.c index 4a2c11e94..00561cab1 100644 --- a/src/update.c +++ b/src/update.c @@ -18,6 +18,7 @@ */ #include "update.h" +#include "directory.h" #include "log.h" #include "ls.h" #include "path.h" @@ -53,14 +54,14 @@ int isUpdatingDB(void) return (progress != UPDATE_PROGRESS_IDLE) ? update_task_id : 0; } -static void directory_set_stat(Directory * dir, const struct stat *st) +static void directory_set_stat(struct directory *dir, const struct stat *st) { dir->inode = st->st_ino; dir->device = st->st_dev; dir->stat = 1; } -static void delete_song(Directory *dir, Song *del) +static void delete_song(struct directory *dir, Song *del) { /* first, prevent traversers in main task from getting this */ songvec_delete(&dir->songs, del); @@ -79,7 +80,7 @@ static void delete_song(Directory *dir, Song *del) struct delete_data { char *tmp; - Directory *dir; + struct directory *dir; enum update_return ret; }; @@ -99,7 +100,7 @@ static int delete_song_if_removed(Song *song, void *_data) } static enum update_return -removeDeletedFromDirectory(char *path_max_tmp, Directory * directory) +removeDeletedFromDirectory(char *path_max_tmp, struct directory *directory) { enum update_return ret = UPDATE_RETURN_NOUPDATE; int i; @@ -130,7 +131,7 @@ static const char *opendir_path(char *path_max_tmp, const char *dirname) return musicDir; } -static int statDirectory(Directory * dir) +static int statDirectory(struct directory *dir) { struct stat st; @@ -142,7 +143,8 @@ static int statDirectory(Directory * dir) return 0; } -static int inodeFoundInParent(Directory * parent, ino_t inode, dev_t device) +static int +inodeFoundInParent(struct directory *parent, ino_t inode, dev_t device) { while (parent) { if (!parent->stat && statDirectory(parent) < 0) @@ -158,10 +160,10 @@ static int inodeFoundInParent(Directory * parent, ino_t inode, dev_t device) } static enum update_return -addSubDirectoryToDirectory(Directory * directory, +addSubDirectoryToDirectory(struct directory *directory, const char *name, struct stat *st) { - Directory *subDirectory; + struct directory *subDirectory; if (inodeFoundInParent(directory, st->st_ino, st->st_dev)) return UPDATE_RETURN_NOUPDATE; @@ -180,7 +182,7 @@ addSubDirectoryToDirectory(Directory * directory, } static enum update_return -addToDirectory(Directory * directory, const char *name) +addToDirectory(struct directory *directory, const char *name) { struct stat st; @@ -208,7 +210,7 @@ addToDirectory(Directory * directory, const char *name) } static enum update_return -updateInDirectory(Directory * directory, const char *name) +updateInDirectory(struct directory *directory, const char *name) { Song *song; struct stat st; @@ -229,7 +231,7 @@ updateInDirectory(Directory * directory, const char *name) return UPDATE_RETURN_UPDATED; } } else if (S_ISDIR(st.st_mode)) { - Directory *subdir = dirvec_find(&directory->children, name); + struct directory *subdir = dirvec_find(&directory->children, name); if (subdir) { assert(directory == subdir->parent); directory_set_stat(subdir, &st); @@ -248,7 +250,7 @@ static int skip_path(const char *path) return (path[0] == '.' || strchr(path, '\n')) ? 1 : 0; } -enum update_return updateDirectory(Directory * directory) +enum update_return updateDirectory(struct directory *directory) { int was_empty = directory_is_empty(directory); DIR *dir; @@ -299,12 +301,12 @@ enum update_return updateDirectory(Directory * directory) return ret; } -static Directory *addDirectoryPathToDB(const char *utf8path) +static struct directory * addDirectoryPathToDB(const char *utf8path) { char path_max_tmp[MPD_PATH_MAX]; char *parent; - Directory *parentDirectory; - Directory *directory; + struct directory *parentDirectory; + struct directory *directory; Song *conflicting; parent = parent_path(path_max_tmp, utf8path); @@ -340,11 +342,11 @@ static Directory *addDirectoryPathToDB(const char *utf8path) return directory; } -static Directory *addParentPathToDB(const char *utf8path) +static struct directory * addParentPathToDB(const char *utf8path) { char *parent; char path_max_tmp[MPD_PATH_MAX]; - Directory *parentDirectory; + struct directory *parentDirectory; parent = parent_path(path_max_tmp, utf8path); @@ -356,13 +358,13 @@ static Directory *addParentPathToDB(const char *utf8path) if (!parentDirectory) return NULL; - return (Directory *) parentDirectory; + return (struct directory *) parentDirectory; } static enum update_return updatePath(const char *utf8path) { - Directory *directory; - Directory *parentDirectory; + struct directory *directory; + struct directory *parentDirectory; Song *song; time_t mtime; enum update_return ret = UPDATE_RETURN_NOUPDATE; diff --git a/src/update.h b/src/update.h index 4e59e39b1..65ffdc3bf 100644 --- a/src/update.h +++ b/src/update.h @@ -20,7 +20,7 @@ #ifndef UPDATE_H #define UPDATE_H -#include "directory.h" +struct directory; enum update_return { UPDATE_RETURN_ERROR = -1, @@ -30,7 +30,7 @@ enum update_return { int isUpdatingDB(void); -enum update_return updateDirectory(Directory * directory); +enum update_return updateDirectory(struct directory *directory); /* * returns the non-negative update job ID on success, |