void copypars(struct pars *p1, struct pars *p2) { int i; /* Delete existing parameters */ clearpars(p2); /* Copy the current p1 set to p2 */ p2->npars = p1->npars; if (p2->npars > 0) mallocnpars(p2); for (i=0;i<p2->npars;i++) { if ((p2->name[i] = (char *)malloc((strlen(p1->name[i])+1)*sizeof(char))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__); strcpy(p2->name[i],p1->name[i]); /* Copy values from p1 to p2 */ copyvalues(p1,i,p2,i); } }
pathNode& operator=(const pathNode &other) { copyvalues(other); };
//pathNode(const pathNode &other):node(other.node) { pathNode(const pathNode &other):Twnode(other) { copyvalues(other); };
void cppar(char *par1,struct pars *p1,char *par2,struct pars *p2) { int i; int ix; struct pars p3; /* Find the index of par1 in the p1 set otherwise return */ ix=parindex(par1,p1); if (ix<0) return; /* Search for par2 in the p2 set to modify an exisiting parameter */ for (i=0;i<p2->npars;i++) { if (!strcmp(p2->name[i],par2)) { /* There is a match */ /* Free existing values */ switch(p2->type[i]) { case 0: free(p2->i[i]); break; case 1: free(p2->d[i]); break; case 2: free(p2->s[i]); break; } /* end p->type switch */ /* Copy values from p1 to p2 */ copyvalues(p1,ix,p2,i); return; } } /* If we have not already returned then add the parameter */ /* Copy the current p2 set to p3 */ p3.npars = p2->npars; if (p3.npars > 0) mallocnpars(&p3); for (i=0;i<p3.npars;i++) { if ((p3.name[i] = (char *)malloc((strlen(p2->name[i])+1)*sizeof(char))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__); strcpy(p3.name[i],p2->name[i]); /* Copy values from p2 to p3 */ copyvalues(p2,i,&p3,i); } /* Clear the current p2 set */ clearpars(p2); /* Restore the p2 set but allocate for an extra parameter */ p2->npars = p3.npars+1; mallocnpars(p2); for (i=0;i<p3.npars;i++) { if ((p2->name[i] = (char *)malloc((strlen(p3.name[i])+1)*sizeof(char))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__); strcpy(p2->name[i],p3.name[i]); /* Copy values back from p3 to p2 */ copyvalues(&p3,i,p2,i); } /* Clear the p3 set */ clearpars(&p3); /* Now add the parameter */ if ((p2->name[i] = (char *)malloc((strlen(par2)+1)*sizeof(char))) == NULL) nomem(__FILE__,__FUNCTION__,__LINE__); strcpy(p2->name[i],par2); /* Copy values from p1 to p2 */ copyvalues(p1,ix,p2,i); }