From 8a8bd7565b5ae8f1447099d672d7097adba64864 Mon Sep 17 00:00:00 2001 From: "lulf@carrot.studby.ntnu.no" Date: Fri, 25 Apr 2008 15:14:50 +0200 Subject: - Merge. --- include/mnode.h | 5 ++++- include/mp3fs.h | 2 ++ src/mp3_subr.c | 40 +++++++++++++++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/include/mnode.h b/include/mnode.h index c805e64..3508395 100644 --- a/include/mnode.h +++ b/include/mnode.h @@ -3,7 +3,10 @@ struct ID3Tag; struct mnode { - ID3Tag *cached_tag; char *path; + ID3Tag *tag; + + /* Entry in search structure. */ + LIST_ENTRY(mnode) next; }; #endif diff --git a/include/mp3fs.h b/include/mp3fs.h index 50bdbee..4313cd1 100644 --- a/include/mp3fs.h +++ b/include/mp3fs.h @@ -2,6 +2,7 @@ #define _MP3FS_H_ struct fuse_args; int mp3_run(int, char **); +void mp3_initscan(void); /* @@ -16,4 +17,5 @@ typedef void traverse_fn_t(char *, void *); void traverse_hierarchy(char *, traverse_fn_t, void *); traverse_fn_t mp3_artist; +traverse_fn_t mp3_scan; #endif diff --git a/src/mp3_subr.c b/src/mp3_subr.c index 85eb03c..e8d7ed5 100644 --- a/src/mp3_subr.c +++ b/src/mp3_subr.c @@ -13,12 +13,17 @@ #include #include +/* Simple list containing our nodes. */ +LIST_HEAD(, mnode) music; + +traverse_fn_t mp3_scan; + /* * Traverse a hierarchy given a directory path. Perform fileoperations on the * files in the directory giving data as arguments, as well as recursing on * sub-directories. */ -void +struct musiclist * traverse_hierarchy(char *dirpath, traverse_fn_t fileop, void *data) { DIR *dirp; @@ -57,11 +62,37 @@ traverse_hierarchy(char *dirpath, traverse_fn_t fileop, void *data) closedir(dirp); } +void +mp3_initscan(void) +{ + LIST_INIT(&music); +} + +/* Scan the music initially. */ +void +mp3_scan(char *filepath, void *data) +{ + struct mnode *mp_new; + + mp_new = malloc(sizeof(struct mnode)); + if (mp_new == NULL) + err(1, "malloc"); + mp_new->tag = ID3Tag_New(); + if (mp_new->tag == NULL) + err(1, "ID3Tag_New"); + mp_new->path = strdup(filepath); + if (mp_new->path == NULL) + err(1, "strdup"); + ID3Tag_Link(mp_new->tag, mp_new->path); + + /* Insert node into music list. */ + LIST_INSERT_HEAD(&music, mp, next); +} + /* - * Retrieve artist name given a file, and put in a buffer with a passed filler - * function + * Retrieve artist name given a file. */ -void +struct mnode * mp3_artist(char *filepath, void *data) { struct filler_data *fd; @@ -90,6 +121,5 @@ mp3_artist(char *filepath, void *data) taglib_tag_free_strings(); taglib_file_free(tagfile); - return; } -- cgit v1.2.3