diff options
author | Max Kellermann <max@duempel.org> | 2008-10-08 11:07:55 +0200 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-11 19:21:48 -0700 |
commit | 4629f646077109f7c6185aab92560da52c237412 (patch) | |
tree | af62c1fd2d29c53d137f8b390682492bf0ef102d /src | |
parent | 0576b8abf8b2fd25105f6e0190a93ddec298e9fb (diff) | |
download | mpd-4629f646077109f7c6185aab92560da52c237412.tar.gz mpd-4629f646077109f7c6185aab92560da52c237412.tar.xz mpd-4629f646077109f7c6185aab92560da52c237412.zip |
database: renamed functions, "db_" prefix and no CamelCase
Yet another CamelCase removal patch.
Diffstat (limited to 'src')
-rw-r--r-- | src/command.c | 2 | ||||
-rw-r--r-- | src/database.c | 34 | ||||
-rw-r--r-- | src/database.h | 20 | ||||
-rw-r--r-- | src/dbUtils.c | 22 | ||||
-rw-r--r-- | src/directory.c | 2 | ||||
-rw-r--r-- | src/directory.h | 4 | ||||
-rw-r--r-- | src/main.c | 12 | ||||
-rw-r--r-- | src/playlist.c | 6 | ||||
-rw-r--r-- | src/sig_handlers.c | 2 | ||||
-rw-r--r-- | src/stats.c | 4 | ||||
-rw-r--r-- | src/storedPlaylist.c | 2 | ||||
-rw-r--r-- | src/update.c | 14 |
12 files changed, 62 insertions, 62 deletions
diff --git a/src/command.c b/src/command.c index 7d1e2f306..0f9852592 100644 --- a/src/command.c +++ b/src/command.c @@ -564,7 +564,7 @@ static int handleLsInfo(int fd, mpd_unused int *permission, if (argc == 2) path = argv[1]; - if (!(directory = getDirectory(path))) { + if (!(directory = db_get_directory(path))) { commandError(fd, ACK_ERROR_NO_EXIST, "directory not found"); return -1; } diff --git a/src/database.c b/src/database.c index c0c03f3e4..bb6cfcd52 100644 --- a/src/database.c +++ b/src/database.c @@ -35,7 +35,7 @@ static struct directory *music_root; static time_t directory_dbModTime; -void directory_init(void) +void db_init(void) { music_root = newDirectory(NULL, NULL); updateDirectory(music_root); @@ -43,19 +43,19 @@ void directory_init(void) stats.dbPlayTime = sumSongTimesIn(NULL); } -void directory_finish(void) +void db_finish(void) { freeDirectory(music_root); } -struct directory * directory_get_root(void) +struct directory * db_get_root(void) { assert(music_root != NULL); return music_root; } -struct directory * getDirectory(const char *name) +struct directory * db_get_directory(const char *name) { if (name == NULL) return music_root; @@ -63,7 +63,7 @@ struct directory * getDirectory(const char *name) return getSubDirectory(music_root, name); } -struct mpd_song *getSongFromDB(const char *file) +struct mpd_song *db_get_song(const char *file) { struct mpd_song *song = NULL; struct directory *directory; @@ -81,7 +81,7 @@ struct mpd_song *getSongFromDB(const char *file) dir = duplicated; } - if (!(directory = getDirectory(dir))) + if (!(directory = db_get_directory(dir))) goto out; if (!(song = songvec_find(&directory->songs, shortname))) goto out; @@ -92,15 +92,15 @@ out: return song; } -int traverseAllIn(const char *name, +int db_walk(const char *name, int (*forEachSong) (struct mpd_song *, void *), int (*forEachDir) (struct directory *, void *), void *data) { struct directory *directory; - if ((directory = getDirectory(name)) == NULL) { + if ((directory = db_get_directory(name)) == NULL) { struct mpd_song *song; - if ((song = getSongFromDB(name)) && forEachSong) { + if ((song = db_get_song(name)) && forEachSong) { return forEachSong(song, data); } return -1; @@ -110,7 +110,7 @@ int traverseAllIn(const char *name, data); } -static char *getDbFile(void) +static char *db_get_file(void) { ConfigParam *param = parseConfigFilePath(CONF_DB_FILE, 1); @@ -120,10 +120,10 @@ static char *getDbFile(void) return param->value; } -int checkDirectoryDB(void) +int db_check(void) { struct stat st; - char *dbFile = getDbFile(); + char *dbFile = db_get_file(); /* Check if the file exists */ if (access(dbFile, F_OK)) { @@ -180,10 +180,10 @@ int checkDirectoryDB(void) return 0; } -int writeDirectoryDB(void) +int db_save(void) { int fd; - char *dbFile = getDbFile(); + char *dbFile = db_get_file(); struct stat st; DEBUG("removing empty directories from DB\n"); @@ -226,10 +226,10 @@ int writeDirectoryDB(void) return 0; } -int readDirectoryDB(void) +int db_load(void) { FILE *fp = NULL; - char *dbFile = getDbFile(); + char *dbFile = db_get_file(); struct stat st; if (!music_root) @@ -306,7 +306,7 @@ int readDirectoryDB(void) return 0; } -time_t getDbModTime(void) +time_t db_get_mtime(void) { return directory_dbModTime; } diff --git a/src/database.h b/src/database.h index f6f320002..0eb7d535d 100644 --- a/src/database.h +++ b/src/database.h @@ -23,26 +23,26 @@ #include "os_compat.h" #include "directory.h" -void directory_init(void); +void db_init(void); -void directory_finish(void); +void db_finish(void); -struct directory * directory_get_root(void); +struct directory * db_get_root(void); -struct directory * getDirectory(const char *name); +struct directory * db_get_directory(const char *name); -struct mpd_song * getSongFromDB(const char *file); +struct mpd_song * db_get_song(const char *file); -int traverseAllIn(const char *name, +int db_walk(const char *name, int (*forEachSong) (struct mpd_song *, void *), int (*forEachDir) (struct directory *, void *), void *data); -int checkDirectoryDB(void); +int db_check(void); -int writeDirectoryDB(void); +int db_save(void); -int readDirectoryDB(void); +int db_load(void); -time_t getDbModTime(void); +time_t db_get_mtime(void); #endif /* DATABASE_H */ diff --git a/src/dbUtils.c b/src/dbUtils.c index 7d1d185a3..5320c0dac 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -98,7 +98,7 @@ int searchForSongsIn(int fd, const char *name, int numItems, data.array.numItems = numItems; data.array.items = items; - ret = traverseAllIn(name, searchInDirectory, NULL, &data); + ret = db_walk(name, searchInDirectory, NULL, &data); for (i = 0; i < numItems; i++) { free(items[i].needle); @@ -130,7 +130,7 @@ int findSongsIn(int fd, const char *name, int numItems, LocateTagItem * items) data.array.numItems = numItems; data.array.items = items; - return traverseAllIn(name, findInDirectory, NULL, &data); + return db_walk(name, findInDirectory, NULL, &data); } static void printSearchStats(int fd, SearchStats *stats) @@ -164,7 +164,7 @@ int searchStatsForSongsIn(int fd, const char *name, int numItems, stats.numberOfSongs = 0; stats.playTime = 0; - ret = traverseAllIn(name, searchStatsInDirectory, NULL, &stats); + ret = db_walk(name, searchStatsInDirectory, NULL, &stats); if (ret == 0) printSearchStats(fd, &stats); @@ -173,7 +173,7 @@ int searchStatsForSongsIn(int fd, const char *name, int numItems, int printAllIn(int fd, const char *name) { - return traverseAllIn(name, song_print_url_x, + return db_walk(name, song_print_url_x, printDirectoryInDirectory, (void*)(size_t)fd); } @@ -198,7 +198,7 @@ static int directoryAddSongToStoredPlaylist(struct mpd_song *song, void *_data) int addAllIn(const char *name) { - return traverseAllIn(name, directoryAddSongToPlaylist, NULL, NULL); + return db_walk(name, directoryAddSongToPlaylist, NULL, NULL); } int addAllInToStoredPlaylist(const char *name, const char *utf8file) @@ -206,7 +206,7 @@ int addAllInToStoredPlaylist(const char *name, const char *utf8file) struct add_data data; data.path = utf8file; - return traverseAllIn(name, directoryAddSongToStoredPlaylist, NULL, + return db_walk(name, directoryAddSongToStoredPlaylist, NULL, &data); } @@ -222,7 +222,7 @@ static int sumSongTime(struct mpd_song * song, void *data) int printInfoForAllIn(int fd, const char *name) { - return traverseAllIn(name, song_print_info_x, + return db_walk(name, song_print_info_x, printDirectoryInDirectory, (void*)(size_t)fd); } @@ -231,7 +231,7 @@ int countSongsIn(const char *name) int count = 0; void *ptr = (void *)&count; - traverseAllIn(name, NULL, countSongsInDirectory, ptr); + db_walk(name, NULL, countSongsInDirectory, ptr); return count; } @@ -241,7 +241,7 @@ unsigned long sumSongTimesIn(const char *name) unsigned long dbPlayTime = 0; void *ptr = (void *)&dbPlayTime; - traverseAllIn(name, sumSongTime, NULL, ptr); + db_walk(name, sumSongTime, NULL, ptr); return dbPlayTime; } @@ -318,7 +318,7 @@ int listAllUniqueTags(int fd, int type, int numConditionals, data.set = strset_new(); } - ret = traverseAllIn(NULL, listUniqueTagsInDirectory, NULL, &data); + ret = db_walk(NULL, listUniqueTagsInDirectory, NULL, &data); if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) { const char *value; @@ -362,7 +362,7 @@ void printSavedMemoryFromFilenames(void) { int sum = 0; - traverseAllIn(NULL, sumSavedFilenameMemoryInSong, + db_walk(NULL, sumSavedFilenameMemoryInSong, sumSavedFilenameMemoryInDirectory, (void *)&sum); DEBUG("saved memory from filenames: %i\n", sum); diff --git a/src/directory.c b/src/directory.c index b38d3b52c..501bda275 100644 --- a/src/directory.c +++ b/src/directory.c @@ -195,7 +195,7 @@ void readDirectoryInfo(FILE * fp, struct directory * directory) if (prefixcmp(buffer, DIRECTORY_BEGIN)) FATAL("Error reading db at line: %s\n", buffer); name = &(buffer[strlen(DIRECTORY_BEGIN)]); - if ((subdir = getDirectory(name))) { + if ((subdir = db_get_directory(name))) { assert(subdir->parent == directory); } else { subdir = newDirectory(name, directory); diff --git a/src/directory.h b/src/directory.h index 84913c036..5401fc98c 100644 --- a/src/directory.h +++ b/src/directory.h @@ -70,7 +70,7 @@ getSubDirectory(struct directory *directory, const char *name); int directory_print(int fd, const struct directory *directory); -struct mpd_song *getSongFromDB(const char *file); +struct mpd_song *db_get_song(const char *file); int writeDirectoryInfo(int fd, struct directory *directory); @@ -78,7 +78,7 @@ void readDirectoryInfo(FILE *fp, struct directory *directory); void sortDirectory(struct directory * directory); -int traverseAllIn(const char *name, +int db_walk(const char *name, int (*forEachSong) (struct mpd_song *, void *), int (*forEachDir) (struct directory *, void *), void *data); diff --git a/src/main.c b/src/main.c index 5c6957f20..07f0f528a 100644 --- a/src/main.c +++ b/src/main.c @@ -269,17 +269,17 @@ static void changeToUser(void) static void openDB(Options * options, char *argv0) { - if (options->createDB > 0 || readDirectoryDB() < 0) { + if (options->createDB > 0 || db_load() < 0) { if (options->createDB < 0) { FATAL("can't open db file and using " "\"--no-create-db\" command line option\n" "try running \"%s --create-db\"\n", argv0); } flushWarningLog(); - if (checkDirectoryDB() < 0) + if (db_check() < 0) exit(EXIT_FAILURE); - directory_init(); - if (writeDirectoryDB() < 0) + db_init(); + if (db_save() < 0) exit(EXIT_FAILURE); if (options->createDB) exit(EXIT_SUCCESS); @@ -451,8 +451,8 @@ int main(int argc, char *argv[]) finishPlaylist(); start = clock(); - directory_finish(); - DEBUG("directory_finish took %f seconds\n", + db_finish(); + DEBUG("db_finish took %f seconds\n", ((float)(clock()-start))/CLOCKS_PER_SEC); finishNormalization(); diff --git a/src/playlist.c b/src/playlist.c index 118733543..8a7b5cf7f 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -575,7 +575,7 @@ enum playlist_result addToPlaylist(const char *url, int *added_id) DEBUG("add to playlist: %s\n", url); - if ((song = getSongFromDB(url))) { + if ((song = db_get_song(url))) { } else if (!(isValidRemoteUtf8Url(url) && (song = song_remote_new(url)))) { return PLAYLIST_RESULT_NO_SUCH_SONG; @@ -590,7 +590,7 @@ int addToStoredPlaylist(const char *url, const char *utf8file) DEBUG("add to stored playlist: %s\n", url); - if ((song = getSongFromDB(url))) + if ((song = db_get_song(url))) return appendSongToStoredPlaylistByPath(utf8file, song); if (!isValidRemoteUtf8Url(url)) @@ -1358,7 +1358,7 @@ int PlaylistInfo(int fd, const char *utf8file, int detail) int wrote = 0; if (detail) { - struct mpd_song *song = getSongFromDB(temp); + struct mpd_song *song = db_get_song(temp); if (song) { song_print_info(song, fd); wrote = 1; diff --git a/src/sig_handlers.c b/src/sig_handlers.c index 1c09eda5b..5a4ebe57d 100644 --- a/src/sig_handlers.c +++ b/src/sig_handlers.c @@ -36,7 +36,7 @@ int handlePendingSignals(void) DEBUG("got SIGHUP, rereading DB\n"); signal_clear(SIGHUP); if (!isUpdatingDB()) { - readDirectoryDB(); + db_load(); playlistVersionChange(); } if (cycle_log_files() < 0) diff --git a/src/stats.c b/src/stats.c index 61cdd1f92..abe03444a 100644 --- a/src/stats.c +++ b/src/stats.c @@ -65,7 +65,7 @@ static unsigned int getNumberOfTagItems(int type) data.type = type; data.set = strset_new(); - traverseAllIn(NULL, visit_tag_items, NULL, &data); + db_walk(NULL, visit_tag_items, NULL, &data); ret = strset_size(data.set); strset_free(data.set); @@ -88,6 +88,6 @@ int printStats(int fd) time(NULL) - stats.daemonStart, (long)(ob_get_total_time() + 0.5), stats.dbPlayTime, - getDbModTime()); + db_get_mtime()); return 0; } diff --git a/src/storedPlaylist.c b/src/storedPlaylist.c index c83f7115d..2e6828483 100644 --- a/src/storedPlaylist.c +++ b/src/storedPlaylist.c @@ -118,7 +118,7 @@ List *loadStoredPlaylist(const char *utf8path) !strncmp(s, musicDir, musicDir_len)) memmove(s, s + musicDir_len + 1, strlen(s + musicDir_len + 1) + 1); - if ((song = getSongFromDB(s))) { + if ((song = db_get_song(s))) { song_get_url(song, path_max_tmp); insertInListWithoutKey(list, xstrdup(path_max_tmp)); } else if (isValidRemoteUtf8Url(s)) diff --git a/src/update.c b/src/update.c index 8560dde38..52e61167d 100644 --- a/src/update.c +++ b/src/update.c @@ -312,7 +312,7 @@ static struct directory * addDirectoryPathToDB(const char *utf8path) parent = parent_path(path_max_tmp, utf8path); if (strlen(parent) == 0) - parentDirectory = directory_get_root(); + parentDirectory = db_get_root(); else parentDirectory = addDirectoryPathToDB(parent); @@ -351,7 +351,7 @@ static struct directory * addParentPathToDB(const char *utf8path) parent = parent_path(path_max_tmp, utf8path); if (strlen(parent) == 0) - parentDirectory = directory_get_root(); + parentDirectory = db_get_root(); else parentDirectory = addDirectoryPathToDB(parent); @@ -373,7 +373,7 @@ static enum update_return updatePath(const char *utf8path) assert(utf8path); /* if path is in the DB try to update it, or else delete it */ - if ((directory = getDirectory(utf8path))) { + if ((directory = db_get_directory(utf8path))) { parentDirectory = directory->parent; /* if this update directory is successfull, we are done */ @@ -382,7 +382,7 @@ static enum update_return updatePath(const char *utf8path) return ret; } /* we don't want to delete the root directory */ - else if (directory == directory_get_root()) { + else if (directory == db_get_root()) { return UPDATE_RETURN_NOUPDATE; } /* if updateDirectory fails, means we should delete it */ @@ -392,7 +392,7 @@ static enum update_return updatePath(const char *utf8path) ret = UPDATE_RETURN_UPDATED; /* don't return, path maybe a song now */ } - } else if ((song = getSongFromDB(utf8path))) { + } else if ((song = db_get_song(utf8path))) { parentDirectory = song->parent; if (!parentDirectory->stat && statDirectory(parentDirectory) < 0) { @@ -448,10 +448,10 @@ static void * update_task(void *_path) ret = updatePath((char *)_path); free(_path); } else { - ret = updateDirectory(directory_get_root()); + ret = updateDirectory(db_get_root()); } - if (ret == UPDATE_RETURN_UPDATED && writeDirectoryDB() < 0) + if (ret == UPDATE_RETURN_UPDATED && db_save() < 0) ret = UPDATE_RETURN_ERROR; progress = UPDATE_PROGRESS_DONE; wakeup_main_task(); |