int main() { int a = 5; int b = 10; int c = 20; List* list = list_create(); Iterator* iterator = list_iterator(list); assert(false == iterator_has_next(iterator)); iterator_destroy(iterator); list_push(list, &a); list_push(list, &b); list_push(list, &c); iterator = list_iterator(list); assert(true == iterator_has_next(iterator)); assert(&a == iterator_next(iterator)); assert(&b == iterator_next(iterator)); assert(&c == iterator_next(iterator)); assert(false == iterator_has_next(iterator)); iterator_destroy(iterator); return 0; }
Style * new_style(const char *name, LList *spec) { Style *style; Iterator *it; StrBuf *prebuf; StrBuf *postbuf; style = xmalloc(sizeof(Style)); style->name = xstrdup(name); prebuf = strbuf_new(); postbuf = strbuf_new(); for (it = llist_iterator(spec); iterator_has_next(it); ) { StyleInfo *info = iterator_next(it); if (info->type == STYLEINFO_PRE) { strbuf_append(prebuf, info->value); } else if (info->type == STYLEINFO_POST) { strbuf_prepend(postbuf, info->value); } else if (info->type == STYLEINFO_STYLE) { const Style *add_style = info->value; strbuf_append(prebuf, add_style->pre_string); strbuf_prepend(postbuf, add_style->post_string); } } style->pre_string = strbuf_free_to_string(prebuf); style->post_string = strbuf_free_to_string(postbuf); style->refs = 1; return style; }
int lib_write(lib_t *lib) { int fd; iterator_t *it; fd=open(lib->dbfile, O_CREAT|O_WRONLY|O_TRUNC, S_IRWXU); if(fd) { write(fd, &lib->entries->size, sizeof(size_t)); it=chunked_list_iterator(lib->entries); while(iterator_has_next(it)) { lib_entry *e=iterator_next(it); size_t len=strlen(e->path)+e->group->len+e->album->len+strlen(e->name)+4; write(fd, &len, sizeof(size_t)); write(fd, e->path, strlen(e->path)+1); write(fd, e->group->str, e->group->len+1); write(fd, e->album->str, e->album->len+1); write(fd, e->name, strlen(e->name)+1); } free(it); close(fd); } debug(ll, "done writing libfile"); }
void lib_watch_event(struct inotify_event *e, const char *path, void *payload) { lib_entry entry; lib_t *lib=(lib_t*)payload; size_t l=strlen(path)+strlen(e->name)+1; char *f=malloc(l+1); strcpy(f, path); strcat(f, e->name); debug(ll, "watch_even '%s%s'", path, e->name); if(e->mask&IN_CLOSE_WRITE || e->mask&IN_CREATE || e->mask&IN_MOVED_TO) { struct stat buf; stat(f, &buf); if(S_ISDIR(buf.st_mode)) { f[l-1]='/'; f[l]=0; parse_dir(lib, &f, l, &entry); } else parse_file(lib, f, &entry); } else if(e->mask&IN_DELETE || e->mask&IN_DELETE_SELF || e->mask&IN_MOVED_FROM) { iterator_t *it=chunked_list_iterator(lib->entries); while(iterator_has_next(it)) { lib_entry *e=iterator_next(it); if(strncmp(f, e->path, l-1)==0) iterator_remove(it); } } }
void *check_lib(void *arg) { size_t l; char *n; lib_entry *entry; lib_t *lib=(lib_t *)arg; iterator_t *it=chunked_list_iterator(lib->entries); info(ll, "starting checker"); while(iterator_has_next(it)) { lib_entry *e=iterator_next(it); char *f=lib_canonize(lib, e->path); debug(ll, "cheking '%s'", f); if(access(f, R_OK)) iterator_remove(it); free(f); } l=lib->base_path_size+1; n=malloc(l); memcpy(n, lib->base_path, l); entry=malloc(sizeof(lib_entry)); parse_dir(lib, &n, l, entry); free(n); free(entry); }
void lib_str_reset(lib_t *lib) { chunked_string_clear(lib->lib_str); chunked_string_add(lib->lib_str, "{"); iterator_t *it=chunked_list_iterator(lib->entries); lib_entry *e=NULL; while(iterator_has_next(it)) { if(e!=NULL) chunked_string_add(lib->lib_str, ","); e=iterator_next(it); chunked_string_add(lib->lib_str, "\""); append(lib, e->path); chunked_string_add(lib->lib_str, "\":{\"title\":\""); append(lib, e->name); chunked_string_add(lib->lib_str, "\",\"group\":\""); append(lib, e->group->str); chunked_string_add(lib->lib_str, "\",\"album\":\""); append(lib, e->album->str); chunked_string_add(lib->lib_str, "\",\"track\":"); snprintf(buf, 5, "%d", e->track); chunked_string_add(lib->lib_str, buf); chunked_string_add(lib->lib_str, "}"); } chunked_string_add(lib->lib_str, "}"); iterator_dispose(it); }
lib_entry *find(lib_t *lib, char *path) { lib_entry *e=NULL; iterator_t *it=chunked_list_iterator(lib->entries); while(iterator_has_next(it)) { e=iterator_next(it); if(strcmp(e->path, path)==0) goto end; } e=NULL; end: free(it); return e; }
int _mpi_file_ntriples_node_iterator_has_next(void* s) { _mpi_file_ntriples_node_iterator_state_t state = (_mpi_file_ntriples_node_iterator_state_t) s; return state->ntriple != NULL || iterator_has_next(state->iter); }