static void pl_iterator_test(void) { printsln((Any)__func__); // various ways of iterating a list: List ac = pl_create(); pl_append(ac, "a"); pl_append(ac, "b"); pl_append(ac, "c"); ListIterator iter = l_iterator(ac); while (l_has_next(iter)) { Any s = pl_next(&iter); printsln(s); } // PointerListNode *first = (PointerListNode*)ac->first; for (PointerListNode *node = ac->first; node != NULL; node = node->next) { Any s = node->value; printsln(s); } #if 0 while (iter = pl_next(iter)) { Any d = pl_current(iter); printiln(d); } for (AnyListIterator iter = pl_iterator(ac); pl_has_current(iter); iter = pl_next(iter)) { Any d = pl_current(iter); printiln(d); } #endif l_free(ac); }
void fm_run(struct playlist *pl) { int status; /* make sure only one instance of play process */ if(playproc > 0) { signal(SIGCHLD, SIG_DFL); kill(playproc, SIGUSR1); while(playproc != waitpid(playproc, &status, 0)) { if(ESRCH == errno || ECHILD == errno) { break; } exit(EXIT_FAILURE); } if(WIFEXITED(status) && EXIT_SUCCESS == WEXITSTATUS(status)) { pl_history(list, ack, SID); ack = CMD_NEXT; fm_recording(); } else { pl_history(list, CMD_SKIP, SID); } } current = (struct hash **)pl_current(pl); list = pl; switch((playproc = fork())) { case -1: die("failed to fork process"); case 0: signal(SIGINT, SIG_IGN); signal(SIGUSR1, SIG_DFL); close(STDIN_FILENO); debug("PLAY: %s(%d) | %d / %d\n", value((const struct hash **)current, "title"), value((const struct hash **)current, "sid"), list->position, list->length); play(URL); exit(EXIT_SUCCESS); default: break; } signal(SIGCHLD, fm_next); }