#include "pipeline.h" #include int pipeline_add_stage_after(struct pipeline_t *pl, struct pipeline_stage_t *stage, const char *name) { if (!name) { /* name == NULL: insert at end of pipeline */ stage->next = NULL; #if 0 if (pl->first) { struct pipeline_stage_t *tail = pl->first; for (; tail->next; tail = tail->next); tail->next = stage; } else { /* corner case: pipeline is empty */ pl->first = stage; } #else /* i like this implementation because it's pretty */ struct pipeline_stage_t **ptail = &pl->first; for (; *ptail; ptail = &(*ptail)->next); *ptail = stage; #endif return 1; } for (struct pipeline_stage_t *cur = pl->first; cur; cur = cur->next) { if (name == cur->name || !strcmp(name, cur->name)) { stage->next = cur->next; cur->next = stage; return 1; } } return 0; } int pipeline_add_stage_before(struct pipeline_t *pl, struct pipeline_stage_t *stage, const char *name) { if (!name || !pl->first || name == pl->first->name || !strcmp(name, pl->first->name)) { stage->next = pl->first; pl->first = stage; return 1; } /* note that it's okay we don't properly check if prev->first->name equals name here, since that was done above. */ for (struct pipeline_stage_t *cur = pl->first->next, *prev = pl->first; cur; prev = cur, cur = cur->next) { if (name == cur->name || !strcmp(name, cur->name)) { prev->next = stage; stage->next = cur; return 1; } } return 0; }