aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dbUtils.c14
-rw-r--r--src/directory.c61
-rw-r--r--src/directory.h24
-rw-r--r--src/dirvec.c17
-rw-r--r--src/dirvec.h8
-rw-r--r--src/song.c4
-rw-r--r--src/song.h6
-rw-r--r--src/song_save.c2
-rw-r--r--src/song_save.h2
-rw-r--r--src/update.c47
-rw-r--r--src/update.h4
11 files changed, 102 insertions, 87 deletions
diff --git a/src/dbUtils.c b/src/dbUtils.c
index 3b5d896b6..fb32769ae 100644
--- a/src/dbUtils.c
+++ b/src/dbUtils.c
@@ -46,8 +46,8 @@ 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;
@@ -56,7 +56,8 @@ static int countSongsInDirectory(Directory * directory,
return 0;
}
-static int printDirectoryInDirectory(Directory * directory, void *data)
+static int
+printDirectoryInDirectory(struct directory *directory, void *data)
{
struct client *client = data;
if (directory->path) {
@@ -356,15 +357,16 @@ int listAllUniqueTags(struct client *client, 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 b5c5e67c2..75dae22dd 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -40,11 +40,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)
{
@@ -56,12 +56,12 @@ 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);
@@ -71,7 +71,7 @@ newDirectory(const char *dirname, Directory * parent)
}
void
-freeDirectory(Directory * directory)
+freeDirectory(struct directory * directory)
{
dirvec_destroy(&directory->children);
songvec_destroy(&directory->songs);
@@ -82,7 +82,7 @@ freeDirectory(Directory * directory)
/*getDirectoryPath(NULL); */
}
-static void deleteEmptyDirectoriesInDirectory(Directory * directory)
+static void deleteEmptyDirectoriesInDirectory(struct directory * directory)
{
int i;
struct dirvec *dv = &directory->children;
@@ -106,7 +106,7 @@ int isRootDirectory(const char *name)
return (!name || name[0] == '\0' || !strcmp(name, "/"));
}
-Directory *
+struct directory *
directory_get_root(void)
{
assert(music_root != NULL);
@@ -114,10 +114,11 @@ directory_get_root(void)
return music_root;
}
-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;
@@ -144,7 +145,7 @@ static Directory *getSubDirectory(Directory * directory, const char *name)
return found;
}
-Directory *
+struct directory *
getDirectory(const char *name)
{
return getSubDirectory(music_root, name);
@@ -164,7 +165,7 @@ static int printDirectoryList(struct client *client, struct dirvec *dv)
int printDirectoryInfo(struct client *client, const char *name)
{
- Directory *directory;
+ struct directory *directory;
if ((directory = getDirectory(name)) == NULL)
return -1;
@@ -176,7 +177,8 @@ int printDirectoryInfo(struct client *client, const char *name)
}
/* TODO error checking */
-static int writeDirectoryInfo(FILE * fp, Directory * directory)
+static int
+writeDirectoryInfo(FILE * fp, struct directory * directory)
{
struct dirvec *children = &directory->children;
size_t i;
@@ -190,7 +192,7 @@ static int writeDirectoryInfo(FILE * fp, Directory * directory)
}
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);
retv = fprintf(fp, DIRECTORY_DIR "%s\n", base);
@@ -209,7 +211,8 @@ static int writeDirectoryInfo(FILE * fp, 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;
@@ -219,7 +222,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))
@@ -248,7 +251,7 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
}
void
-sortDirectory(Directory * directory)
+sortDirectory(struct directory * directory)
{
int i;
struct dirvec *dv = &directory->children;
@@ -443,10 +446,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;
@@ -468,11 +472,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;
@@ -497,7 +502,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 e197600d1..f33d854c6 100644
--- a/src/directory.h
+++ b/src/directory.h
@@ -26,19 +26,19 @@
#include <stdbool.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);
@@ -46,26 +46,26 @@ void directory_finish(void);
int isRootDirectory(const char *name);
-Directory *
+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);
+freeDirectory(struct directory * directory);
static inline bool
-directory_is_empty(Directory *directory)
+directory_is_empty(struct directory *directory)
{
return directory->children.nr == 0 && directory->songs.nr == 0;
}
-Directory *
+struct directory *
getDirectory(const char *name);
void
-sortDirectory(Directory * directory);
+sortDirectory(struct directory * directory);
int printDirectoryInfo(struct client *client, const char *dirname);
@@ -81,7 +81,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 f125cf2df..014490eca 100644
--- a/src/song.c
+++ b/src/song.c
@@ -29,7 +29,7 @@
#include "os_compat.h"
Song *
-song_alloc(const char *url, struct _Directory *parent)
+song_alloc(const char *url, struct directory *parent)
{
size_t urllen;
Song *song;
@@ -46,7 +46,7 @@ song_alloc(const char *url, struct _Directory *parent)
return song;
}
-Song *newSong(const char *url, Directory * parentDir)
+Song *newSong(const char *url, struct directory *parentDir)
{
Song *song;
assert(*url);
diff --git a/src/song.h b/src/song.h
index cb8ba188f..fc50e70c1 100644
--- a/src/song.h
+++ b/src/song.h
@@ -32,15 +32,15 @@ struct client;
typedef struct _Song {
struct tag *tag;
- struct _Directory *parentDir;
+ struct directory *parentDir;
time_t mtime;
char url[sizeof(size_t)];
} Song;
Song *
-song_alloc(const char *url, struct _Directory *parent);
+song_alloc(const char *url, struct directory *parent);
-Song *newSong(const char *url, struct _Directory *parentDir);
+Song *newSong(const char *url, struct directory *parentDir);
void freeJustSong(Song *);
diff --git a/src/song_save.c b/src/song_save.c
index c29ee86a8..14bce4ce0 100644
--- a/src/song_save.c
+++ b/src/song_save.c
@@ -98,7 +98,7 @@ static int matchesAnMpdTagItemKey(char *buffer, int *itemType)
}
void readSongInfoIntoList(FILE *fp, struct songvec *sv,
- Directory *parentDir)
+ struct directory *parentDir)
{
char buffer[MPD_PATH_MAX + 1024];
int bufferSize = MPD_PATH_MAX + 1024;
diff --git a/src/song_save.h b/src/song_save.h
index 748a2696c..f77ff8fa7 100644
--- a/src/song_save.h
+++ b/src/song_save.h
@@ -26,6 +26,6 @@ struct songvec;
void songvec_save(FILE *fp, struct songvec *sv);
void readSongInfoIntoList(FILE * fp, struct songvec *sv,
- struct _Directory *parent);
+ struct directory *parent);
#endif
diff --git a/src/update.c b/src/update.c
index 2317ff31e..13228d6ac 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,16 @@ 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 +82,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 +102,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 +133,8 @@ 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 +146,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 +163,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 +185,7 @@ addSubDirectoryToDirectory(Directory * directory,
}
static enum update_return
-addToDirectory(Directory * directory, const char *name)
+addToDirectory(struct directory *directory, const char *name)
{
struct stat st;
@@ -209,7 +214,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;
@@ -230,7 +235,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);
@@ -250,7 +255,7 @@ static int skip_path(const char *path)
}
enum update_return
-updateDirectory(Directory * directory)
+updateDirectory(struct directory *directory)
{
bool was_empty = directory_is_empty(directory);
DIR *dir;
@@ -301,12 +306,13 @@ 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);
@@ -342,11 +348,12 @@ 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);
@@ -358,13 +365,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;
char *path = sanitizePathDup(utf8path);
time_t mtime;
diff --git a/src/update.h b/src/update.h
index 86baecbf1..5edf62a57 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,
@@ -31,7 +31,7 @@ enum update_return {
int isUpdatingDB(void);
enum update_return
-updateDirectory(Directory * directory);
+updateDirectory(struct directory *directory);
/*
* returns the non-negative update job ID on success,