diff options
author | Ulf Lilleengen <lulf@carrot.studby.ntnu.no> | 2008-08-09 16:19:57 +0200 |
---|---|---|
committer | Ulf Lilleengen <lulf@carrot.studby.ntnu.no> | 2008-08-09 16:19:57 +0200 |
commit | 5fabb4d6e75806729a710673b7657df2b440c801 (patch) | |
tree | a51171927490b5b0b9d7bd5428480d3d77eb33c8 | |
parent | 64e1a2a9e5cc03d234fa4cf1a3577dcf84e5e22e (diff) |
- Change lookup_fn to return values, so we can stop the lookup_finish loop on
the SQL results.
-rw-r--r-- | include/mp3fs.h | 3 | ||||
-rw-r--r-- | src/mp3_subr.c | 23 |
2 files changed, 18 insertions, 8 deletions
diff --git a/include/mp3fs.h b/include/mp3fs.h index 4966aee..847f047 100644 --- a/include/mp3fs.h +++ b/include/mp3fs.h @@ -35,7 +35,8 @@ struct file_data { #define LIST_DATATYPE_STRING 1 #define LIST_DATATYPE_INT 2 -typedef void lookup_fn_t(void *, const char *); +/* A lookup functions returns 0 if it's finished. */ +typedef int lookup_fn_t(void *, const char *); /* Lookup function listing each row. */ lookup_fn_t mp3_lookup_list; /* Lookup function opening the first file match. */ diff --git a/src/mp3_subr.c b/src/mp3_subr.c index 814888d..72f2994 100644 --- a/src/mp3_subr.c +++ b/src/mp3_subr.c @@ -300,7 +300,7 @@ mp3_lookup_finish(struct lookuphandle *lh) { char buf[1024]; const unsigned char *value; - int ret, type, val; + int ret, type, val, finished; if (lh == NULL) return; @@ -311,15 +311,20 @@ mp3_lookup_finish(struct lookuphandle *lh) case SQLITE_INTEGER: val = sqlite3_column_int(lh->st, lh->field); snprintf(buf, sizeof(buf), "%d", val); - lh->lookup(lh->priv, (const char *)buf); + finished = lh->lookup(lh->priv, (const char *)buf); break; case SQLITE_TEXT: value = sqlite3_column_text(lh->st, lh->field); - lh->lookup(lh->priv, (const char *)value); + finished = lh->lookup(lh->priv, (const char *)value); + break; + default: + finished = 0; break; // default: // lh->filler(lh->buf, "UNKNOWN TYPE", NULL, 0); } + if (finished) + break; ret = sqlite3_step(lh->st); } // XXX: Check for errors too. @@ -488,19 +493,20 @@ mp3_lookup_genre(const char *path, struct filler_data *fd) /* * Lookup function for filling given data into a filler. */ -void +int mp3_lookup_list(void *data, const char *str) { struct filler_data *fd; fd = (struct filler_data *)data; fd->filler(fd->buf, str, NULL, 0); + return (1); } /* * Lookup a file and open it if found. */ -void +int mp3_lookup_open(void *data, const char *str) { struct file_data *fd; @@ -509,19 +515,22 @@ mp3_lookup_open(void *data, const char *str) if (!fd->found) { fd->fd = open(str, O_RDONLY); fd->found = 1; + return (0); } + return (1); } /* * Stat a file. * XXX: watch out for duplicates, we might stat more than once. */ -void +int mp3_lookup_stat(void *data, const char *str) { struct stat *st; st = (struct stat *)data; if (stat(str, st) < 0) - return; + return (-1); + return (0); } |