diff options
author | Max Kellermann <max@duempel.org> | 2008-10-08 11:07:58 +0200 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-11 19:21:48 -0700 |
commit | a76121ea81f452c0d5e21d6a2fb6f200a80faf7b (patch) | |
tree | e59b04f16d56532284747f99fb5631cfd6b24c70 | |
parent | 4629f646077109f7c6185aab92560da52c237412 (diff) | |
download | mpd-a76121ea81f452c0d5e21d6a2fb6f200a80faf7b.tar.gz mpd-a76121ea81f452c0d5e21d6a2fb6f200a80faf7b.tar.xz mpd-a76121ea81f452c0d5e21d6a2fb6f200a80faf7b.zip |
directory: eliminate CamelCase
CamelCase is ugly, rename the functions.
[ew: "directory_get_directory" was too confusing, using
"directory_get_subdir" instead (old function was named
"getSubDirectory")]
-rw-r--r-- | src/database.c | 18 | ||||
-rw-r--r-- | src/dbUtils.c | 4 | ||||
-rw-r--r-- | src/directory.c | 40 | ||||
-rw-r--r-- | src/directory.h | 18 | ||||
-rw-r--r-- | src/dirvec.c | 2 | ||||
-rw-r--r-- | src/song.c | 6 | ||||
-rw-r--r-- | src/update.c | 12 |
7 files changed, 50 insertions, 50 deletions
diff --git a/src/database.c b/src/database.c index bb6cfcd52..98e50ad87 100644 --- a/src/database.c +++ b/src/database.c @@ -37,7 +37,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); @@ -45,7 +45,7 @@ void db_init(void) void db_finish(void) { - freeDirectory(music_root); + directory_free(music_root); } struct directory * db_get_root(void) @@ -60,7 +60,7 @@ struct directory * db_get_directory(const char *name) if (name == NULL) return music_root; - return getSubDirectory(music_root, name); + return directory_get_subdir(music_root, name); } struct mpd_song *db_get_song(const char *file) @@ -106,7 +106,7 @@ int db_walk(const char *name, return -1; } - return traverseAllInSubDirectory(directory, forEachSong, forEachDir, + return directory_walk(directory, forEachSong, forEachDir, data); } @@ -187,11 +187,11 @@ int 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"); @@ -212,7 +212,7 @@ int db_save(void) DIRECTORY_FS_CHARSET "%s\n" DIRECTORY_INFO_END "\n", getFsCharset()); - if (writeDirectoryInfo(fd, music_root) < 0) { + if (directory_save(fd, music_root) < 0) { ERROR("Failed to write to database file: %s\n", strerror(errno)); xclose(fd); @@ -233,7 +233,7 @@ int 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", @@ -294,7 +294,7 @@ int 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 5320c0dac..aa7e639b7 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -58,7 +58,7 @@ static int printDirectoryInDirectory(struct directory *directory, void *data) { int fd = (int)(size_t)data; if (directory->path) { - fdprintf(fd, "directory: %s\n", getDirectoryPath(directory)); + fdprintf(fd, "directory: %s\n", directory_get_path(directory)); } return 0; } @@ -343,7 +343,7 @@ static int 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 501bda275..f79cc2dbc 100644 --- a/src/directory.c +++ b/src/directory.c @@ -26,7 +26,7 @@ #include "myfprintf.h" #include "dirvec.h" -struct directory * newDirectory(const char *dirname, struct directory * parent) +struct directory * directory_new(const char *dirname, struct directory * parent) { struct directory *directory; @@ -39,7 +39,7 @@ struct directory * newDirectory(const char *dirname, struct directory * parent) return directory; } -void freeDirectory(struct directory * directory) +void directory_free(struct directory * directory) { dirvec_destroy(&directory->children); songvec_destroy(&directory->songs); @@ -47,16 +47,16 @@ void 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) +void 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]); } @@ -65,7 +65,7 @@ void deleteEmptyDirectoriesInDirectory(struct directory * directory) } struct directory * -getSubDirectory(struct directory * directory, const char *name) +directory_get_subdir(struct directory * directory, const char *name) { struct directory *cur = directory; struct directory *found = NULL; @@ -97,13 +97,13 @@ getSubDirectory(struct directory * directory, const char *name) return found; } -static int printDirectoryList(int fd, const struct dirvec *dv) +static int dirvec_print(int fd, const struct dirvec *dv) { size_t i; for (i = 0; i < dv->nr; ++i) { if (fdprintf(fd, DIRECTORY_DIR "%s\n", - getDirectoryPath(dv->base[i])) < 0) + directory_get_path(dv->base[i])) < 0) return -1; } @@ -112,7 +112,7 @@ static int printDirectoryList(int fd, const struct dirvec *dv) int directory_print(int fd, const struct directory *directory) { - if (printDirectoryList(fd, &directory->children) < 0) + if (dirvec_print(fd, &directory->children) < 0) return -1; if (songvec_for_each(&directory->songs, song_print_info_x, (void *)(size_t)fd) < 0) @@ -135,14 +135,14 @@ static int directory_song_write(struct mpd_song *song, void *data) } /* TODO error checking */ -int writeDirectoryInfo(int fd, struct directory * directory) +int directory_save(int fd, struct directory * directory) { struct dirvec *children = &directory->children; size_t i; if (directory->path && fdprintf(fd, DIRECTORY_BEGIN "%s\n", - getDirectoryPath(directory)) < 0) + directory_get_path(directory)) < 0) return -1; for (i = 0; i < children->nr; ++i) { @@ -151,7 +151,7 @@ int writeDirectoryInfo(int fd, struct directory * directory) if (fdprintf(fd, DIRECTORY_DIR "%s\n", base) < 0) return -1; - if (writeDirectoryInfo(fd, cur) < 0) + if (directory_save(fd, cur) < 0) return -1; } @@ -167,12 +167,12 @@ int writeDirectoryInfo(int fd, struct directory * directory) if (directory->path && fdprintf(fd, DIRECTORY_END "%s\n", - getDirectoryPath(directory)) < 0) + directory_get_path(directory)) < 0) return -1; return 0; } -void readDirectoryInfo(FILE * fp, struct directory * directory) +void directory_load(FILE * fp, struct directory * directory) { char buffer[MPD_PATH_MAX * 2]; int bufferSize = MPD_PATH_MAX * 2; @@ -198,10 +198,10 @@ void 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); } else { @@ -210,7 +210,7 @@ void readDirectoryInfo(FILE * fp, struct directory * directory) } } -void sortDirectory(struct directory * directory) +void directory_sort(struct directory * directory) { int i; struct dirvec *dv = &directory->children; @@ -219,11 +219,11 @@ void 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, +directory_walk(struct directory * directory, int (*forEachSong) (struct mpd_song *, void *), int (*forEachDir) (struct directory *, void *), void *data) @@ -242,7 +242,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 5401fc98c..a95e0d7db 100644 --- a/src/directory.h +++ b/src/directory.h @@ -52,9 +52,9 @@ static inline int isRootDirectory(const char *name) return (!name || *name == '\0' || !strcmp(name, "/")); } -struct directory * newDirectory(const char *dirname, struct directory *parent); +struct directory * directory_new(const char *dirname, struct directory *parent); -void freeDirectory(struct directory *directory); +void directory_free(struct directory *directory); static inline int directory_is_empty(struct directory *directory) { @@ -63,29 +63,29 @@ static inline int directory_is_empty(struct directory *directory) int printDirectoryInfo(int fd, const char *dirname); -void deleteEmptyDirectoriesInDirectory(struct directory *directory); +void directory_prune_empty(struct directory *directory); struct directory * -getSubDirectory(struct directory *directory, const char *name); +directory_get_subdir(struct directory *directory, const char *name); int directory_print(int fd, const struct directory *directory); struct mpd_song *db_get_song(const char *file); -int writeDirectoryInfo(int fd, struct directory *directory); +int directory_save(int fd, struct directory *directory); -void readDirectoryInfo(FILE *fp, struct directory *directory); +void directory_load(FILE *fp, struct directory *directory); -void sortDirectory(struct directory * directory); +void directory_sort(struct directory * directory); int db_walk(const char *name, int (*forEachSong) (struct mpd_song *, void *), int (*forEachDir) (struct directory *, void *), void *data); -int traverseAllInSubDirectory(struct directory *directory, +int directory_walk(struct directory *directory, int (*forEachSong) (struct mpd_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 9226fca74..3ec5b7af1 100644 --- a/src/dirvec.c +++ b/src/dirvec.c @@ -38,7 +38,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 18f2bca21..aa6641020 100644 --- a/src/song.c +++ b/src/song.c @@ -87,7 +87,7 @@ ssize_t song_print_url(struct mpd_song *song, int fd) { if (song->parent && song->parent->path) return fdprintf(fd, "%s%s/%s\n", SONG_FILE, - getDirectoryPath(song->parent), song->url); + directory_get_path(song->parent), song->url); return fdprintf(fd, "%s%s\n", SONG_FILE, song->url); } @@ -244,7 +244,7 @@ char *song_get_url(struct mpd_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/update.c b/src/update.c index 52e61167d..989b8f943 100644 --- a/src/update.c +++ b/src/update.c @@ -135,7 +135,7 @@ static int 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); @@ -168,11 +168,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; } @@ -254,7 +254,7 @@ enum update_return updateDirectory(struct directory *directory) { int 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; @@ -327,7 +327,7 @@ static struct directory * 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); } } @@ -378,7 +378,7 @@ static enum update_return updatePath(const char *utf8path) /* if this update directory is successfull, we are done */ if ((ret = updateDirectory(directory)) >= 0) { - sortDirectory(directory); + directory_sort(directory); return ret; } /* we don't want to delete the root directory */ |