diff options
author | Max Kellermann <max@duempel.org> | 2008-10-08 11:07:55 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-08 11:07:55 +0200 |
commit | bb8a9533b1a2df4ea34be2c6f053f22fe49a60d0 (patch) | |
tree | 40fbdabccc553f9681753d2b4bc6b4aeb9760951 | |
parent | 7a023eb0b2d41ae0511c45449abada94df04dd7d (diff) | |
download | mpd-bb8a9533b1a2df4ea34be2c6f053f22fe49a60d0.tar.gz mpd-bb8a9533b1a2df4ea34be2c6f053f22fe49a60d0.tar.xz mpd-bb8a9533b1a2df4ea34be2c6f053f22fe49a60d0.zip |
database: renamed functions, "db_" prefix and no CamelCase
Yet another CamelCase removal patch.
-rw-r--r-- | src/command.c | 2 | ||||
-rw-r--r-- | src/database.c | 45 | ||||
-rw-r--r-- | src/database.h | 30 | ||||
-rw-r--r-- | src/dbUtils.c | 28 | ||||
-rw-r--r-- | src/directory.c | 2 | ||||
-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 |
11 files changed, 79 insertions, 68 deletions
diff --git a/src/command.c b/src/command.c index 489761b52..d985fd61b 100644 --- a/src/command.c +++ b/src/command.c @@ -579,7 +579,7 @@ static int handleLsInfo(struct client *client, if (argc == 2) path = argv[1]; - directory = getDirectory(path); + directory = db_get_directory(path); if (directory == NULL) { command_error(client, ACK_ERROR_NO_EXIST, "directory not found"); diff --git a/src/database.c b/src/database.c index 648d29c86..78ae8ab06 100644 --- a/src/database.c +++ b/src/database.c @@ -36,7 +36,8 @@ 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); @@ -44,13 +45,14 @@ 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) +db_get_root(void) { assert(music_root != NULL); @@ -58,7 +60,7 @@ directory_get_root(void) } struct directory * -getDirectory(const char *name) +db_get_directory(const char *name) { if (name == NULL) return music_root; @@ -67,7 +69,7 @@ getDirectory(const char *name) } struct song * -getSongFromDB(const char *file) +get_get_song(const char *file) { struct song *song = NULL; struct directory *directory; @@ -85,7 +87,7 @@ 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; @@ -97,15 +99,15 @@ out: } int -traverseAllIn(const char *name, - int (*forEachSong) (struct song *, void *), - int (*forEachDir) (struct directory *, void *), void *data) +db_walk(const char *name, + int (*forEachSong)(struct 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 song *song; - if ((song = getSongFromDB(name)) && forEachSong) { + if ((song = get_get_song(name)) && forEachSong) { return forEachSong(song, data); } return -1; @@ -115,7 +117,8 @@ traverseAllIn(const char *name, data); } -static char *getDbFile(void) +static char * +db_get_file(void) { ConfigParam *param = parseConfigFilePath(CONF_DB_FILE, 1); @@ -125,10 +128,11 @@ 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)) { @@ -185,10 +189,11 @@ int checkDirectoryDB(void) return 0; } -int writeDirectoryDB(void) +int +db_save(void) { FILE *fp; - char *dbFile = getDbFile(); + char *dbFile = db_get_file(); struct stat st; DEBUG("removing empty directories from DB\n"); @@ -228,10 +233,11 @@ 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) @@ -308,7 +314,8 @@ 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 03161683d..152baeb10 100644 --- a/src/database.h +++ b/src/database.h @@ -24,29 +24,35 @@ struct directory; -void directory_init(void); +void +db_init(void); -void directory_finish(void); +void +db_finish(void); struct directory * -directory_get_root(void); +db_get_root(void); struct directory * -getDirectory(const char *name); +db_get_directory(const char *name); struct song * -getSongFromDB(const char *file); +get_get_song(const char *file); -int traverseAllIn(const char *name, - int (*forEachSong) (struct song *, void *), - int (*forEachDir) (struct directory *, void *), void *data); +int db_walk(const char *name, + int (*forEachSong)(struct 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 diff --git a/src/dbUtils.c b/src/dbUtils.c index 02517d9ed..6a803f621 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -110,7 +110,7 @@ int searchForSongsIn(struct client *client, const char *name, 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); @@ -143,7 +143,7 @@ int findSongsIn(struct client *client, const char *name, data.array.numItems = numItems; data.array.items = items; - return traverseAllIn(name, findInDirectory, NULL, &data); + return db_walk(name, findInDirectory, NULL, &data); } static void printSearchStats(struct client *client, SearchStats *stats) @@ -178,7 +178,7 @@ int searchStatsForSongsIn(struct client *client, const char *name, stats.numberOfSongs = 0; stats.playTime = 0; - ret = traverseAllIn(name, searchStatsInDirectory, NULL, &stats); + ret = db_walk(name, searchStatsInDirectory, NULL, &stats); if (ret == 0) printSearchStats(client, &stats); @@ -187,8 +187,8 @@ int searchStatsForSongsIn(struct client *client, const char *name, int printAllIn(struct client *client, const char *name) { - return traverseAllIn(name, printSongInDirectory, - printDirectoryInDirectory, client); + return db_walk(name, printSongInDirectory, + printDirectoryInDirectory, client); } static int @@ -213,7 +213,7 @@ directoryAddSongToStoredPlaylist(struct 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) @@ -222,8 +222,7 @@ int addAllInToStoredPlaylist(const char *name, const char *utf8file) .path = utf8file, }; - return traverseAllIn(name, directoryAddSongToStoredPlaylist, NULL, - &data); + return db_walk(name, directoryAddSongToStoredPlaylist, NULL, &data); } static int @@ -247,7 +246,7 @@ sumSongTime(struct song *song, void *data) int printInfoForAllIn(struct client *client, const char *name) { - return traverseAllIn(name, directoryPrintSongInfo, + return db_walk(name, directoryPrintSongInfo, printDirectoryInDirectory, client); } @@ -256,7 +255,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; } @@ -266,7 +265,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; } @@ -347,8 +346,7 @@ int listAllUniqueTags(struct client *client, 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; @@ -396,8 +394,8 @@ void printSavedMemoryFromFilenames(void) { int sum = 0; - traverseAllIn(NULL, sumSavedFilenameMemoryInSong, - sumSavedFilenameMemoryInDirectory, (void *)&sum); + 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 c2fa229f5..f5ee8693c 100644 --- a/src/directory.c +++ b/src/directory.c @@ -182,7 +182,7 @@ 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/main.c b/src/main.c index 3e30e9d19..f0079e438 100644 --- a/src/main.c +++ b/src/main.c @@ -272,17 +272,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); @@ -456,8 +456,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); deinit_main_notify(); diff --git a/src/playlist.c b/src/playlist.c index f1d3ce24c..438eb473b 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -559,7 +559,7 @@ enum playlist_result addToPlaylist(const char *url, int *added_id) DEBUG("add to playlist: %s\n", url); - if ((song = getSongFromDB(url))) { + if ((song = get_get_song(url))) { } else if (!(isValidRemoteUtf8Url(url) && (song = song_remote_new(url)))) { return PLAYLIST_RESULT_NO_SUCH_SONG; @@ -574,7 +574,7 @@ int addToStoredPlaylist(const char *url, const char *utf8file) DEBUG("add to stored playlist: %s\n", url); - song = getSongFromDB(url); + song = get_get_song(url); if (song) return appendSongToStoredPlaylistByPath(utf8file, song); @@ -1360,7 +1360,7 @@ int PlaylistInfo(struct client *client, const char *utf8file, int detail) int wrote = 0; if (detail) { - struct song *song = getSongFromDB(temp); + struct song *song = get_get_song(temp); if (song) { song_print_info(client, song); wrote = 1; diff --git a/src/sig_handlers.c b/src/sig_handlers.c index 188952415..7db50c457 100644 --- a/src/sig_handlers.c +++ b/src/sig_handlers.c @@ -40,7 +40,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 a9e929e90..fe842a789 100644 --- a/src/stats.c +++ b/src/stats.c @@ -66,7 +66,7 @@ static unsigned int getNumberOfTagItems(int type) }; unsigned int ret; - traverseAllIn(NULL, visit_tag_items, NULL, &data); + db_walk(NULL, visit_tag_items, NULL, &data); ret = strset_size(data.set); strset_free(data.set); @@ -89,6 +89,6 @@ int printStats(struct client *client) time(NULL) - stats.daemonStart, (long)(getPlayerTotalPlayTime() + 0.5), stats.dbPlayTime, - getDbModTime()); + db_get_mtime()); return 0; } diff --git a/src/storedPlaylist.c b/src/storedPlaylist.c index f926e6eb3..ffb87cafc 100644 --- a/src/storedPlaylist.c +++ b/src/storedPlaylist.c @@ -116,7 +116,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 = get_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 843d9ae79..2bab75398 100644 --- a/src/update.c +++ b/src/update.c @@ -321,7 +321,7 @@ 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); @@ -361,7 +361,7 @@ 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); @@ -385,7 +385,7 @@ static enum update_return updatePath(const char *utf8path) return UPDATE_RETURN_ERROR; /* if path is in the DB try to update it, or else delete it */ - if ((directory = getDirectory(path))) { + if ((directory = db_get_directory(path))) { parentDirectory = directory->parent; /* if this update directory is successfull, we are done */ @@ -396,7 +396,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()) { free(path); return UPDATE_RETURN_NOUPDATE; } @@ -407,7 +407,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(path))) { + } else if ((song = get_get_song(path))) { parentDirectory = song->parent; if (!parentDirectory->stat && statDirectory(parentDirectory) < 0) { @@ -467,10 +467,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(); |