void append_comb(combset *cs, comb c) { if (cs->comb == NULL) { // first comb init_comb(&(cs->comb)); copy_comb(c, &(cs->comb)); } else { // append combset *runner = cs; // find end while (runner->next != NULL) { runner = runner->next; } combset *newcombset = NULL; init_combset(&newcombset); init_comb(&(newcombset->comb)); copy_comb(c, &(newcombset->comb)); runner->next = newcombset; newcombset->prev = runner; } }
/** * recursively copy a tree of geometry */ static struct directory * copy_tree(struct db_i *_dbip, struct directory *dp, struct resource *resp, struct clone_state *state) { size_t i; union record *rp = (union record *)NULL; struct directory *mdp = (struct directory *)NULL; struct directory *copy = (struct directory *)NULL; struct bu_vls *copyname = NULL; struct bu_vls *nextname = NULL; /* get the name of what the object "should" get cloned to */ copyname = get_name(_dbip, dp, state, 0); /* copy the object */ if (dp->d_flags & RT_DIR_COMB) { if (db_version(_dbip) < 5) { /* A v4 method of peeking into a combination */ int errors = 0; /* get an in-memory record of this object */ if ((rp = db_getmrec(_dbip, dp)) == (union record *)0) { TCL_READ_ERR; goto done_copy_tree; } /* * if it is a combination/region, copy the objects that * make up the object. */ for (i = 1; i < dp->d_len; i++) { if ((mdp = db_lookup(_dbip, rp[i].M.m_instname, LOOKUP_NOISY)) == RT_DIR_NULL) { errors++; bu_log("WARNING: failed to locate \"%s\"\n", rp[i].M.m_instname); continue; } copy = copy_tree(_dbip, mdp, resp, state); if (!copy) { errors++; bu_log("WARNING: unable to fully clone \"%s\"\n", rp[i].M.m_instname); } } if (errors) { bu_log("WARNING: some elements of \"%s\" could not be cloned\n", dp->d_namep); } /* copy this combination itself */ copy_comb(_dbip, dp, (genptr_t)state); } else /* A v5 method of peeking into a combination */ db_functree(_dbip, dp, copy_comb, copy_solid, resp, (genptr_t)state); } else if (dp->d_flags & RT_DIR_SOLID) /* leaf node -- make a copy the object */ copy_solid(_dbip, dp, (genptr_t)state); else { Tcl_AppendResult(state->interp, "clone: ", dp->d_namep, " is neither a combination or a primitive?\n", (char *)NULL); goto done_copy_tree; } nextname = get_name(_dbip, dp, state, 0); if (bu_vls_strcmp(copyname, nextname) == 0) bu_log("ERROR: unable to successfully clone \"%s\" to \"%s\"\n", dp->d_namep, bu_vls_addr(copyname)); else copy = db_lookup(_dbip, bu_vls_addr(copyname), LOOKUP_QUIET); done_copy_tree: if (rp) bu_free((char *)rp, "copy_tree record[]"); if (copyname) bu_free((char *)copyname, "free get_name() copyname"); if (nextname) bu_free((char *)nextname, "free get_name() copyname"); return copy; }