aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-10-11 19:49:14 -0700
committerEric Wong <normalperson@yhbt.net>2008-10-11 23:34:36 -0700
commit6e2b0ca9edaed200f250ef487701ad161aa4a168 (patch)
treefda140c473d960546bc8123be4b85e72fbe9b1b8
parente71207440ebdf492e00fd5ac73b0833c82366ac6 (diff)
downloadmpd-6e2b0ca9edaed200f250ef487701ad161aa4a168.tar.gz
mpd-6e2b0ca9edaed200f250ef487701ad161aa4a168.tar.xz
mpd-6e2b0ca9edaed200f250ef487701ad161aa4a168.zip
directory: don't use identical struct and variable names
Duplicated tokens in close proximity takes too long for my head to parse; and "dir" is an easy and common abbreviation for "directory".
-rw-r--r--src/command.c6
-rw-r--r--src/database.c19
-rw-r--r--src/dbUtils.c10
-rw-r--r--src/directory.c44
-rw-r--r--src/directory.h30
-rw-r--r--src/directory_print.c6
-rw-r--r--src/directory_print.h2
-rw-r--r--src/directory_save.c30
-rw-r--r--src/directory_save.h4
-rw-r--r--src/update.c107
10 files changed, 128 insertions, 130 deletions
diff --git a/src/command.c b/src/command.c
index 541a71a50..e542683d8 100644
--- a/src/command.c
+++ b/src/command.c
@@ -560,17 +560,17 @@ static int handleLsInfo(int fd, mpd_unused int *permission,
int argc, char *argv[])
{
const char *path = "";
- const struct directory *directory;
+ const struct directory *dir;
if (argc == 2)
path = argv[1];
- if (!(directory = db_get_directory(path))) {
+ if (!(dir = db_get_directory(path))) {
commandError(fd, ACK_ERROR_NO_EXIST, "directory not found");
return -1;
}
- directory_print(fd, directory);
+ directory_print(fd, dir);
if (isRootDirectory(path))
return lsPlaylists(fd, path);
diff --git a/src/database.c b/src/database.c
index ea78940f8..dde57ce6a 100644
--- a/src/database.c
+++ b/src/database.c
@@ -75,8 +75,8 @@ struct directory * db_get_directory(const char *name)
struct mpd_song *db_get_song(const char *file)
{
struct mpd_song *song = NULL;
- struct directory *directory;
- char *dir = NULL;
+ struct directory *dir;
+ char *dirpath = NULL;
char *duplicated = xstrdup(file);
char *shortname = strrchr(duplicated, '/');
@@ -87,14 +87,14 @@ struct mpd_song *db_get_song(const char *file)
} else {
*shortname = '\0';
++shortname;
- dir = duplicated;
+ dirpath = duplicated;
}
- if (!(directory = db_get_directory(dir)))
+ if (!(dir = db_get_directory(dirpath)))
goto out;
- if (!(song = songvec_find(&directory->songs, shortname)))
+ if (!(song = songvec_find(&dir->songs, shortname)))
goto out;
- assert(song->parent == directory);
+ assert(song->parent == dir);
out:
free(duplicated);
@@ -105,9 +105,9 @@ int db_walk(const char *name,
int (*forEachSong) (struct mpd_song *, void *),
int (*forEachDir) (struct directory *, void *), void *data)
{
- struct directory *directory;
+ struct directory *dir;
- if ((directory = db_get_directory(name)) == NULL) {
+ if ((dir = db_get_directory(name)) == NULL) {
struct mpd_song *song;
if ((song = db_get_song(name)) && forEachSong) {
return forEachSong(song, data);
@@ -115,8 +115,7 @@ int db_walk(const char *name,
return -1;
}
- return directory_walk(directory, forEachSong, forEachDir,
- data);
+ return directory_walk(dir, forEachSong, forEachDir, data);
}
static char *db_get_file(void)
diff --git a/src/dbUtils.c b/src/dbUtils.c
index 9e307efc6..1fadb232e 100644
--- a/src/dbUtils.c
+++ b/src/dbUtils.c
@@ -45,20 +45,20 @@ typedef struct _SearchStats {
unsigned long playTime;
} SearchStats;
-static int countSongsInDirectory(struct directory *directory, void *data)
+static int countSongsInDirectory(struct directory *dir, void *data)
{
int *count = (int *)data;
- *count += directory->songs.nr;
+ *count += dir->songs.nr;
return 0;
}
-static int printDirectoryInDirectory(struct directory *directory, void *data)
+static int printDirectoryInDirectory(struct directory *dir, void *data)
{
int fd = (int)(size_t)data;
- if (!isRootDirectory(directory->path))
- fdprintf(fd, "directory: %s\n", directory_get_path(directory));
+ if (!isRootDirectory(dir->path))
+ fdprintf(fd, "directory: %s\n", directory_get_path(dir));
return 0;
}
diff --git a/src/directory.c b/src/directory.c
index 273515b91..b90b477fd 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -25,32 +25,32 @@
struct directory * directory_new(const char *dirname, struct directory * parent)
{
- struct directory *directory;
+ struct directory *dir;
assert(dirname != NULL);
assert((*dirname == 0) == (parent == NULL));
- directory = xcalloc(1, sizeof(*directory));
- directory->path = xstrdup(dirname);
- directory->parent = parent;
+ dir = xcalloc(1, sizeof(struct directory));
+ dir->path = xstrdup(dirname);
+ dir->parent = parent;
- return directory;
+ return dir;
}
-void directory_free(struct directory * directory)
+void directory_free(struct directory *dir)
{
- dirvec_destroy(&directory->children);
- songvec_destroy(&directory->songs);
- free(directory->path);
- free(directory);
+ dirvec_destroy(&dir->children);
+ songvec_destroy(&dir->songs);
+ free(dir->path);
+ free(dir);
/* this resets last dir returned */
/*directory_get_path(NULL); */
}
-void directory_prune_empty(struct directory * directory)
+void directory_prune_empty(struct directory *dir)
{
int i;
- struct dirvec *dv = &directory->children;
+ struct dirvec *dv = &dir->children;
for (i = dv->nr; --i >= 0; ) {
directory_prune_empty(dv->base[i]);
@@ -62,9 +62,9 @@ void directory_prune_empty(struct directory * directory)
}
struct directory *
-directory_get_subdir(struct directory * directory, const char *name)
+directory_get_subdir(struct directory *dir, const char *name)
{
- struct directory *cur = directory;
+ struct directory *cur = dir;
struct directory *found = NULL;
char *duplicated;
char *locate;
@@ -72,7 +72,7 @@ directory_get_subdir(struct directory * directory, const char *name)
assert(name != NULL);
if (isRootDirectory(name))
- return directory;
+ return dir;
duplicated = xstrdup(name);
locate = strchr(duplicated, '/');
@@ -94,33 +94,33 @@ directory_get_subdir(struct directory * directory, const char *name)
return found;
}
-void directory_sort(struct directory * directory)
+void directory_sort(struct directory *dir)
{
int i;
- struct dirvec *dv = &directory->children;
+ struct dirvec *dv = &dir->children;
dirvec_sort(dv);
- songvec_sort(&directory->songs);
+ songvec_sort(&dir->songs);
for (i = dv->nr; --i >= 0; )
directory_sort(dv->base[i]);
}
int
-directory_walk(struct directory * directory,
+directory_walk(struct directory *dir,
int (*forEachSong) (struct mpd_song *, void *),
int (*forEachDir) (struct directory *, void *),
void *data)
{
- struct dirvec *dv = &directory->children;
+ struct dirvec *dv = &dir->children;
int err = 0;
size_t j;
- if (forEachDir && (err = forEachDir(directory, data)) < 0)
+ if (forEachDir && (err = forEachDir(dir, data)) < 0)
return err;
if (forEachSong) {
- err = songvec_for_each(&directory->songs, forEachSong, data);
+ err = songvec_for_each(&dir->songs, forEachSong, data);
if (err < 0)
return err;
}
diff --git a/src/directory.h b/src/directory.h
index d8f86f50c..949df0c0e 100644
--- a/src/directory.h
+++ b/src/directory.h
@@ -50,11 +50,11 @@ static inline int isRootDirectory(const char *name)
struct directory * directory_new(const char *dirname, struct directory *parent);
-void directory_free(struct directory *directory);
+void directory_free(struct directory *dir);
-static inline int directory_is_empty(struct directory *directory)
+static inline int directory_is_empty(struct directory *dir)
{
- return directory->children.nr == 0 && directory->songs.nr == 0;
+ return dir->children.nr == 0 && dir->songs.nr == 0;
}
static inline const char * directory_get_path(struct directory *dir)
@@ -63,39 +63,39 @@ static inline const char * directory_get_path(struct directory *dir)
}
static inline struct directory *
-directory_get_child(const struct directory *directory, const char *name)
+directory_get_child(const struct directory *dir, const char *name)
{
- return dirvec_find(&directory->children, name);
+ return dirvec_find(&dir->children, name);
}
static inline struct directory *
-directory_new_child(struct directory *directory, const char *name)
+directory_new_child(struct directory *dir, const char *name)
{
- struct directory *subdir = directory_new(name, directory);
- dirvec_add(&directory->children, subdir);
+ struct directory *subdir = directory_new(name, dir);
+ dirvec_add(&dir->children, subdir);
return subdir;
}
-void directory_prune_empty(struct directory *directory);
+void directory_prune_empty(struct directory *dir);
struct directory *
-directory_get_subdir(struct directory *directory, const char *name);
+directory_get_subdir(struct directory *dir, const char *name);
-int directory_print(int fd, const struct directory *directory);
+int directory_print(int fd, const struct directory *dir);
struct mpd_song *db_get_song(const char *file);
-int directory_save(int fd, struct directory *directory);
+int directory_save(int fd, struct directory *dir);
-void directory_load(FILE *fp, struct directory *directory);
+void directory_load(FILE *fp, struct directory *dir);
-void directory_sort(struct directory * directory);
+void directory_sort(struct directory *dir);
int db_walk(const char *name,
int (*forEachSong) (struct mpd_song *, void *),
int (*forEachDir) (struct directory *, void *), void *data);
-int directory_walk(struct directory *directory,
+int directory_walk(struct directory *dir,
int (*forEachSong) (struct mpd_song *, void *),
int (*forEachDir) (struct directory *, void *), void *data);
diff --git a/src/directory_print.c b/src/directory_print.c
index ebf9a472d..1c30f1608 100644
--- a/src/directory_print.c
+++ b/src/directory_print.c
@@ -36,11 +36,11 @@ static int dirvec_print(int fd, const struct dirvec *dv)
return 0;
}
-int directory_print(int fd, const struct directory *directory)
+int directory_print(int fd, const struct directory *dir)
{
- if (dirvec_print(fd, &directory->children) < 0)
+ if (dirvec_print(fd, &dir->children) < 0)
return -1;
- if (songvec_for_each(&directory->songs, song_print_info_x,
+ if (songvec_for_each(&dir->songs, song_print_info_x,
(void *)(size_t)fd) < 0)
return -1;
return 0;
diff --git a/src/directory_print.h b/src/directory_print.h
index 54089e58d..a55c3672d 100644
--- a/src/directory_print.h
+++ b/src/directory_print.h
@@ -21,6 +21,6 @@
struct directory;
-int directory_print(int fd, const struct directory *directory);
+int directory_print(int fd, const struct directory *dir);
#endif
diff --git a/src/directory_save.c b/src/directory_save.c
index 76eace90b..c39ece58a 100644
--- a/src/directory_save.c
+++ b/src/directory_save.c
@@ -40,14 +40,14 @@ static int directory_song_write(struct mpd_song *song, void *data)
}
/* TODO error checking */
-int directory_save(int fd, struct directory * directory)
+int directory_save(int fd, struct directory *dir)
{
- struct dirvec *children = &directory->children;
+ struct dirvec *children = &dir->children;
size_t i;
- if (!isRootDirectory(directory->path) &&
+ if (!isRootDirectory(dir->path) &&
fdprintf(fd, DIRECTORY_BEGIN "%s\n",
- directory_get_path(directory)) < 0)
+ directory_get_path(dir)) < 0)
return -1;
for (i = 0; i < children->nr; ++i) {
@@ -63,21 +63,21 @@ int directory_save(int fd, struct directory * directory)
if (fdprintf(fd, SONG_BEGIN "\n") < 0)
return -1;
- if (songvec_for_each(&directory->songs,
+ if (songvec_for_each(&dir->songs,
directory_song_write, (void *)(size_t)fd) < 0)
return -1;
if (fdprintf(fd, SONG_END "\n") < 0)
return -1;
- if (!isRootDirectory(directory->path) &&
+ if (!isRootDirectory(dir->path) &&
fdprintf(fd, DIRECTORY_END "%s\n",
- directory_get_path(directory)) < 0)
+ directory_get_path(dir)) < 0)
return -1;
return 0;
}
-void directory_load(FILE * fp, struct directory * directory)
+void directory_load(FILE * fp, struct directory *dir)
{
char buffer[MPD_PATH_MAX * 2];
int bufferSize = MPD_PATH_MAX * 2;
@@ -100,19 +100,19 @@ void directory_load(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 (prefixcmp(name, directory->path) != 0)
+ if (prefixcmp(name, dir->path) != 0)
FATAL("Wrong path in database: '%s' in '%s'\n",
- name, directory->path);
+ name, dir->path);
- if ((subdir = directory_get_child(directory, name))) {
- assert(subdir->parent == directory);
+ if ((subdir = directory_get_child(dir, name))) {
+ assert(subdir->parent == dir);
} else {
- subdir = directory_new(name, directory);
- dirvec_add(&directory->children, subdir);
+ subdir = directory_new(name, dir);
+ dirvec_add(&dir->children, subdir);
}
directory_load(fp, subdir);
} else if (!prefixcmp(buffer, SONG_BEGIN)) {
- readSongInfoIntoList(fp, directory);
+ readSongInfoIntoList(fp, dir);
} else {
FATAL("Unknown line in db: %s\n", buffer);
}
diff --git a/src/directory_save.h b/src/directory_save.h
index 211c73cca..64364d82d 100644
--- a/src/directory_save.h
+++ b/src/directory_save.h
@@ -23,8 +23,8 @@
struct directory;
-int directory_save(int fd, struct directory *directory);
+int directory_save(int fd, struct directory *dir);
-void directory_load(FILE *, struct directory *directory);
+void directory_load(FILE *, struct directory *dir);
#endif /* DIRECTORY_SAVE_H */
diff --git a/src/update.c b/src/update.c
index 928aac5c5..ca3640b73 100644
--- a/src/update.c
+++ b/src/update.c
@@ -81,9 +81,9 @@ static void delete_song(struct directory *dir, struct mpd_song *del)
static int delete_each_song(struct mpd_song *song, mpd_unused void *data)
{
- struct directory *directory = data;
- assert(song->parent == directory);
- delete_song(directory, song);
+ struct directory *dir = data;
+ assert(song->parent == dir);
+ delete_song(dir, song);
return 0;
}
@@ -91,28 +91,27 @@ static int delete_each_song(struct mpd_song *song, mpd_unused void *data)
* Recursively remove all sub directories and songs from a directory,
* leaving an empty directory.
*/
-static void clear_directory(struct directory *directory)
+static void clear_directory(struct directory *dir)
{
int i;
- for (i = directory->children.nr; --i >= 0;)
- clear_directory(directory->children.base[i]);
- dirvec_clear(&directory->children);
+ for (i = dir->children.nr; --i >= 0;)
+ clear_directory(dir->children.base[i]);
+ dirvec_clear(&dir->children);
- songvec_for_each(&directory->songs, delete_each_song, directory);
+ songvec_for_each(&dir->songs, delete_each_song, dir);
}
/**
* Recursively free a directory and all its contents.
*/
-static void delete_directory(struct directory *directory)
+static void delete_directory(struct directory *dir)
{
- assert(directory->parent != NULL);
+ assert(dir->parent != NULL);
- clear_directory(directory);
-
- dirvec_delete(&directory->parent->children, directory);
- directory_free(directory);
+ clear_directory(dir);
+ dirvec_delete(&dir->parent->children, dir);
+ directory_free(dir);
}
struct delete_data {
@@ -137,11 +136,11 @@ static int delete_song_if_removed(struct mpd_song *song, void *_data)
static void delete_path(const char *path)
{
- struct directory *directory = db_get_directory(path);
+ struct directory *dir = db_get_directory(path);
struct mpd_song *song = db_get_song(path);
- if (directory) {
- delete_directory(directory);
+ if (dir) {
+ delete_directory(dir);
modified = 1;
}
if (song) {
@@ -151,10 +150,10 @@ static void delete_path(const char *path)
}
static void
-removeDeletedFromDirectory(char *path_max_tmp, struct directory *directory)
+removeDeletedFromDirectory(char *path_max_tmp, struct directory *dir)
{
int i;
- struct dirvec *dv = &directory->children;
+ struct dirvec *dv = &dir->children;
struct delete_data data;
for (i = dv->nr; --i >= 0; ) {
@@ -165,9 +164,9 @@ removeDeletedFromDirectory(char *path_max_tmp, struct directory *directory)
modified = 1;
}
- data.dir = directory;
+ data.dir = dir;
data.tmp = path_max_tmp;
- songvec_for_each(&directory->songs, delete_song_if_removed, &data);
+ songvec_for_each(&dir->songs, delete_song_if_removed, &data);
}
static const char *opendir_path(char *path_max_tmp, const char *dirname)
@@ -206,38 +205,38 @@ inodeFoundInParent(struct directory *parent, ino_t inode, dev_t device)
return 0;
}
-static int updateDirectory(struct directory *directory, const struct stat *st);
+static int updateDirectory(struct directory *dir, const struct stat *st);
static void
-updateInDirectory(struct directory *directory,
+updateInDirectory(struct directory *dir,
const char *name, const struct stat *st)
{
if (S_ISREG(st->st_mode) && hasMusicSuffix(name, 0)) {
const char *shortname = mpd_basename(name);
struct mpd_song *song;
- if (!(song = songvec_find(&directory->songs, shortname))) {
- if (!(song = song_file_load(shortname, directory)))
+ if (!(song = songvec_find(&dir->songs, shortname))) {
+ if (!(song = song_file_load(shortname, dir)))
return;
- songvec_add(&directory->songs, song);
+ songvec_add(&dir->songs, song);
modified = 1;
LOG("added %s\n", name);
} else if (st->st_mtime != song->mtime) {
LOG("updating %s\n", name);
if (!song_file_update(song))
- delete_song(directory, song);
+ delete_song(dir, song);
modified = 1;
}
} else if (S_ISDIR(st->st_mode)) {
struct directory *subdir;
- if (inodeFoundInParent(directory, st->st_ino, st->st_dev))
+ if (inodeFoundInParent(dir, st->st_ino, st->st_dev))
return;
- if (!(subdir = directory_get_child(directory, name)))
- subdir = directory_new_child(directory, name);
+ if (!(subdir = directory_get_child(dir, name)))
+ subdir = directory_new_child(dir, name);
- assert(directory == subdir->parent);
+ assert(dir == subdir->parent);
if (!updateDirectory(subdir, st))
delete_directory(subdir);
@@ -252,23 +251,23 @@ static int skip_path(const char *path)
return (path[0] == '.' || strchr(path, '\n')) ? 1 : 0;
}
-static int updateDirectory(struct directory *directory, const struct stat *st)
+static int updateDirectory(struct directory *dir, const struct stat *st)
{
- DIR *dir;
- const char *dirname = directory_get_path(directory);
+ DIR *fs_dir;
+ const char *dirname = directory_get_path(dir);
struct dirent *ent;
char path_max_tmp[MPD_PATH_MAX];
assert(S_ISDIR(st->st_mode));
- directory_set_stat(directory, st);
+ directory_set_stat(dir, st);
- if (!(dir = opendir(opendir_path(path_max_tmp, dirname))))
+ if (!(fs_dir = opendir(opendir_path(path_max_tmp, dirname))))
return 0;
- removeDeletedFromDirectory(path_max_tmp, directory);
+ removeDeletedFromDirectory(path_max_tmp, dir);
- while ((ent = readdir(dir))) {
+ while ((ent = readdir(fs_dir))) {
char *utf8;
struct stat st2;
@@ -279,17 +278,17 @@ static int updateDirectory(struct directory *directory, const struct stat *st)
if (!utf8)
continue;
- if (!isRootDirectory(directory->path))
+ if (!isRootDirectory(dir->path))
utf8 = pfx_dir(path_max_tmp, utf8, strlen(utf8),
dirname, strlen(dirname));
if (myStat(path_max_tmp, &st2) == 0)
- updateInDirectory(directory, path_max_tmp, &st2);
+ updateInDirectory(dir, path_max_tmp, &st2);
else
delete_path(path_max_tmp);
}
- closedir(dir);
+ closedir(fs_dir);
return 1;
}
@@ -297,12 +296,12 @@ static int updateDirectory(struct directory *directory, const struct stat *st)
static struct directory *
directory_make_child_checked(struct directory *parent, const char *path)
{
- struct directory *directory;
+ struct directory *dir;
struct stat st;
struct mpd_song *conflicting;
- if ((directory = directory_get_child(parent, path)))
- return directory;
+ if ((dir = directory_get_child(parent, path)))
+ return dir;
if (myStat(path, &st) < 0 ||
inodeFoundInParent(parent, st.st_ino, st.st_dev))
@@ -313,30 +312,30 @@ directory_make_child_checked(struct directory *parent, const char *path)
if ((conflicting = songvec_find(&parent->songs, mpd_basename(path))))
delete_song(parent, conflicting);
- directory = directory_new_child(parent, path);
- directory_set_stat(directory, &st);
- return directory;
+ dir = directory_new_child(parent, path);
+ directory_set_stat(dir, &st);
+ return dir;
}
static struct directory *
addParentPathToDB(const char *utf8path)
{
- struct directory *directory = db_get_root();
+ struct directory *dir = db_get_root();
char *duplicated = xstrdup(utf8path);
char *slash = duplicated;
while ((slash = strchr(slash, '/'))) {
*slash = 0;
- directory = directory_make_child_checked(directory, duplicated);
- if (!directory || !slash)
+ dir = directory_make_child_checked(dir, duplicated);
+ if (!dir || !slash)
break;
*slash++ = '/';
}
free(duplicated);
- return directory;
+ return dir;
}
static void updatePath(const char *utf8path)
@@ -355,11 +354,11 @@ static void * update_task(void *_path)
updatePath((char *)_path);
free(_path);
} else {
- struct directory *directory = db_get_root();
+ struct directory *dir = db_get_root();
struct stat st;
- if (myStat(directory_get_path(directory), &st) == 0)
- updateDirectory(directory, &st);
+ if (myStat(directory_get_path(dir), &st) == 0)
+ updateDirectory(dir, &st);
}
if (modified)