src/gedlib/replace.c
/*===================================================================
 * replace_indi -- Replace a person in database with modified version
 *  indi1 = current record (copy from database, may or may not be in cache)
 *  indi2 = new data
 *  replaces all children nodes of indi1 with children nodes of indi2
 *  consumes indi2 (calls free_node on it)
 *=================================================================*/
- Replace a person in database with modified version
indi1 = current record (copy from database, may or may not be in cache)
indi2 = new data
replaces all children nodes of indi1 with children nodes of indi2
consumes indi2 (calls free_node on it)
- Replace a person in database with modified version indi1 = current record ( copy from database may or may not be in cache ) indi2 = new data replaces all children nodes of indi1 with children nodes of indi2 consumes indi2 ( calls free_node on it )
void
replace_indi (NODE indi1, NODE indi2)
{
	NODE name1, name2, refn1, refn2, sex, body, famc, fams;
	NODE node, namen, refnn, name1n, refn1n, indi0;
	STRING key;
	split_indi_old(indi1, &name1, &refn1, &sex, &body, &famc, &fams);
	indi0 = copy_node(indi1);
	join_indi(indi0, NULL, NULL, sex, body, famc, fams);
	free_nodes(indi0);
	split_indi_old(indi2, &name2, &refn2, &sex, &body, &famc, &fams);
	namen = copy_nodes(name2, TRUE, TRUE);
	refnn = copy_nodes(refn2, TRUE, TRUE);
	join_indi(indi1, name2, refn2, sex, body, famc, fams);
	free_node(indi2);
	nodechk(indi1, "replace_indi");
	indi_to_dbase(indi1);
	key = rmvat(nxref(indi1));
	classify_nodes(&name1, &namen, &name1n);
	classify_nodes(&refn1, &refnn, &refn1n);
	for (node = name1; node; node = nsibling(node))
		remove_name(nval(node), key);
	for (node = namen; node; node = nsibling(node))
		add_name(nval(node), key);
	rename_from_browse_lists(key);
	for (node = refn1; node; node = nsibling(node))
		if (nval(node)) remove_refn(nval(node), key);
	for (node = refnn; node; node = nsibling(node))
		if (nval(node)) add_refn(nval(node), key);
	free_nodes(name1);
	free_nodes(namen);
	free_nodes(name1n);
	free_nodes(refn1);
	free_nodes(refnn);
	free_nodes(refn1n);
}
void replace_indi ( NODE indi1 , NODE indi2 ) { NODE name1 , name2 , refn1 , refn2 , sex , body , famc , fams ; NODE node , namen , refnn , name1n , refn1n , indi0 ; STRING key ; split_indi_old ( indi1 , & name1 , & refn1 , & sex , & body , & famc , & fams ) ; indi0 = copy_node ( indi1 ) ; join_indi ( indi0 , NULL , NULL , sex , body , famc , fams ) ; free_nodes ( indi0 ) ; split_indi_old ( indi2 , & name2 , & refn2 , & sex , & body , & famc , & fams ) ; namen = copy_nodes ( name2 , TRUE , TRUE ) ; refnn = copy_nodes ( refn2 , TRUE , TRUE ) ; join_indi ( indi1 , name2 , refn2 , sex , body , famc , fams ) ; free_node ( indi2 ) ; nodechk ( indi1 , " " ) ; indi_to_dbase ( indi1 ) ; key = rmvat ( nxref ( indi1 ) ) ; classify_nodes ( & name1 , & namen , & name1n ) ; classify_nodes ( & refn1 , & refnn , & refn1n ) ; for ( node = name1 ; node ; node = nsibling ( node ) ) remove_name ( nval ( node ) , key ) ; for ( node = namen ; node ; node = nsibling ( node ) ) add_name ( nval ( node ) , key ) ; rename_from_browse_lists ( key ) ; for ( node = refn1 ; node ; node = nsibling ( node ) ) if ( nval ( node ) ) remove_refn ( nval ( node ) , key ) ; for ( node = refnn ; node ; node = nsibling ( node ) ) if ( nval ( node ) ) add_refn ( nval ( node ) , key ) ; free_nodes ( name1 ) ; free_nodes ( namen ) ; free_nodes ( name1n ) ; free_nodes ( refn1 ) ; free_nodes ( refnn ) ; free_nodes ( refn1n ) ; }
replace_indi -- Replace a person in database with modified version
  indi1 = current record (copy from database, may or may not be in cache)
  indi2 = new data
  replaces all children nodes of indi1 with children nodes of indi2
  consumes indi2 (calls free_node on it)
replace_indi -- Replace a person in database with modified version indi1 = current record ( copy from database may or may not be in cache ) indi2 = new data replaces all children nodes of indi1 with children nodes of indi2 consumes indi2 ( calls free_node on it )
/* Move indi1 data into indi0 & delete it (saving names & refns */ /* Move indi2 data into indi1, also copy out lists of names & refns */ /* Write data to database */ /* update name & refn info */ /* classify does a diff on its first two arguments, repopulating all three
	arguments -- first is left-only, second is right-only, third is shared */ /* Note: classify eliminates duplicates */ /* now cleanup (indi1 tree is now composed of indi2 data) */