static thing_th *inner_dup(thing_th *head) { if(!head) return NULL; if(Car(head)) set_car(head, dup_cell(Car(head))); if(Cdr(head)) set_cdr(head, dup_cell(Cdr(head))); inner_dup(Car(head)); inner_dup(Cdr(head)); return head; }
tree_cell * dup_cell (const tree_cell * tc) { tree_cell *r; int i; if (tc == NULL) return NULL; else if (tc == FAKE_CELL) return FAKE_CELL; r = alloc_tree_cell (tc->line_nb, NULL); r->type = tc->type; r->size = tc->size; switch (tc->type) { case CONST_STR: case CONST_DATA: r->x.str_val = emalloc (tc->size); memcpy (r->x.str_val, tc->x.str_val, tc->size); break; default: r->x = tc->x; break; } for (i = 0; i < 4; i++) r->link[i] = dup_cell (tc->link[i]); return r; }
thing_th *duplicate(thing_th *head) { return inner_dup(dup_cell(head)); }