int plumber_init(plumber_data *plumb) { plumb->mode = PLUMBER_CREATE; plumb->last = &plumb->root; plumb->npipes = 0; plumb->nchan = 1; sporth_stack_init(&plumb->sporth.stack); plumber_ftmap_init(plumb); plumb->seed = time(NULL); int pos; for(pos = 0; pos < 16; pos++) plumb->p[pos] = 0; for(pos = 0; pos < 16; pos++) plumb->f[pos] = sporth_f_default; return PLUMBER_OK; }
int plumbing_compute(plumber_data *plumb, plumbing *pipes, int mode) { plumb->mode = mode; plumber_pipe *pipe = pipes->root.next; uint32_t n; float *fval; char *sval; sporth_data *sporth = &plumb->sporth; /* swap out the current plumbing */ plumbing *prev = plumb->pipes; /* save top level next pipe */ plumber_pipe *top_next = plumb->next; plumb->pipes = pipes; /* save temp */ plumbing *tmp = plumb->tmp; if(mode == PLUMBER_DESTROY) { sporth_stack_init(&plumb->sporth.stack); } for(n = 0; n < pipes->npipes; n++) { plumb->next = pipe->next; switch(pipe->type) { case SPORTH_FLOAT: fval = pipe->ud; if(mode != PLUMBER_DESTROY) sporth_stack_push_float(&sporth->stack, *fval); break; case SPORTH_STRING: sval = pipe->ud; if(mode == PLUMBER_INIT) sporth_stack_push_string(&sporth->stack, &sval); break; default: plumb->last = pipe; sporth->flist[pipe->type - SPORTH_FOFFSET].func(&sporth->stack, sporth->flist[pipe->type - SPORTH_FOFFSET].ud); break; } pipe = plumb->next; } /* re-swap the main pipes */ plumb->pipes = prev; /* restore top level next pipe */ plumb->next = top_next; /* restore temp */ plumb->tmp = tmp; return PLUMBER_OK; }
int plumber_init(plumber_data *plumb) { plumb->mode = PLUMBER_CREATE; plumb->current_pipe = 0; plumb->ftmap = plumb->ft1; plumb->pipes= &plumb->main; plumb->tmp = &plumb->main; plumbing_init(plumb->pipes); plumb->nchan = 1; sporth_stack_init(&plumb->sporth.stack); plumber_ftmap_delete(plumb, 1); plumber_ftmap_init(plumb); plumb->seed = (int) time(NULL); plumb->fp = NULL; int pos; for(pos = 0; pos < 16; pos++) plumb->p[pos] = 0; for(pos = 0; pos < 16; pos++) plumb->f[pos] = sporth_f_default; return PLUMBER_OK; }