// translator.c 
// JR
//	4/7/96	Quick and dirty translator, to facilitate comparisons.		
// 		Read in a translation (list of edge-name substitutions)
// 		and a Homeo and translate the Homeo.

//#include <iostream.h>
#include <iostream>
using namespace std;

void Homeo::translate()
{
	istream& in(cin);
	cout << "How many names to be translated?" << endl;
	int nTranslations=0;
	in >> nTranslations;
	cout << "Input the translations (for example: -2 alpha), one per line." << endl;
	LinList<DE> L;
	LinList<char*> M;
	DE e;
	for(int it=0;it<nTranslations;it++)
	{
		in >> e;
		char c;
		while( in.get(c) )
		{
			if( !( c==' ' || c=='\t' ) )
			{
				in.putback(c);
				break;
			}
		}

		in.get(c);
		if(c=='-') e=e.bar();
		else in.putback(c);

		int count=0;
		char* buf=new char[500];
		while( in.get(c) )
		{
			assert(count<500);

			if(c==' ' || c=='\n' || c=='\t' ) break;
			else
			{
				buf[count++]=c;
			}
		}
		L.append(e);
		M.append(buf);
	}

	cout << L << endl;
	cout << M << endl;

	SetBrowser<Name> i(theNameManager.edges());
	cout << "Edges: {";
	for(i.init();i.ok();i.advance())
	{
		DE e(i.current(),0);
		if( L.has( e ) )	// substitution supplied for n
		{
			cout << " " << M[L.indexOf(e)];
		}
		else if( L.has( e.bar() ) ) // substitution supplied for nbar
		{
			cout << " " << M[L.indexOf(e.bar())];
		}
		else
		{
			cout << " " <<  i.current();
		}
	}
	cout << " }" << endl;

	SetBrowser<Name> ip(theNameManager.periphery());
	cout << "Periphery: {";
	for(ip.init();ip.ok();ip.advance())
	{
		DE e(ip.current(),0);
		if( L.has( e ) )	// substitution supplied for n
		{
			cout << " " << M[L.indexOf(e)];
		}
		else if( L.has( e.bar() ) ) // substitution supplied for nbar
		{
			cout << " " << M[L.indexOf(e.bar())];
		}
		else
		{
			cout << " " <<  ip.current();
		}
	}
	cout << " }" << endl;

	SetBrowser<Name> ipu(theNameManager.punctures());
	cout << "Punctures: {";
	for(ipu.init();ipu.ok();ipu.advance())
	{
		DE e(ipu.current(),0);
		if( L.has( e ) )	// substitution supplied for n
		{
			cout << " " << M[L.indexOf(e)];
		}
		else if( L.has( e.bar() ) ) // substitution supplied for nbar
		{
			cout << " " << M[L.indexOf(e.bar())];
		}
		else
		{
			cout << " " <<  ipu.current();
		}
	}
	cout << " }" << endl;

	SetBrowser<Vertex> ig(theGraph);
	cout << "Graph: {";
	for(ig.init();ig.ok();ig.advance())
	{
	CircListBrowser<DE> iv(ig.current());
	cout << " <";
	for(iv.init();iv.ok();++iv)
	{
		DE e(iv.ahead());
		if( L.has( e ) )	// substitution supplied for n
		{
			cout << " " << M[L.indexOf(e)];
		}
		else if( L.has( e.bar() ) ) // substitution supplied for nbar
		{
			cout << " -" << M[L.indexOf(e.bar())];
		}
		else
		{
			cout << " " <<  iv.ahead();
		}
	}
	cout << " >";
	}
	cout << " }" << endl;

	cout << "Map: {" << endl;
	SetBrowser<MapElement> im(theMap);
	for(im.init();im.ok();im.advance())
	{
		DE es(im.current().source());
		{
			if( L.has( es ) )	// substitution supplied for n
			{
				cout << endl << "  " << M[L.indexOf(es)];
			}
			else if( L.has( es.bar() ) ) // substitution supplied for nbar
			{
				cout << endl << "  " << M[L.indexOf(es.bar())];
				es=es.bar();
			}
			else
			{
				cout << endl << "  " <<  es;
			}
		}

		cout << " -> (";
		DELListBrowser id(theMap.imageOf(es));
		for(id.init();id.ok();++id)
		{
			DE e(id.ahead());
			if( L.has( e ) )	// substitution supplied for n
			{
				cout << " " << M[L.indexOf(e)];
			}
			else if( L.has( e.bar() ) ) // substitution supplied for nbar
			{
				cout << " -" << M[L.indexOf(e.bar())];
			}
			else
			{
					cout << " " <<  e;
			}
		}
		cout << " )";
	}
	cout << endl << "}" << endl;

	LinListBrowser<DE> ie(theEquator);
	cout << "Equator: (";
	for(ie.init();ie.ok();++ie)
	{
		DE e(ie.ahead());
		if( L.has( e ) )	// substitution supplied for n
		{
			cout << " " << M[L.indexOf(e)];
		}
		else if( L.has( e.bar() ) ) // substitution supplied for nbar
		{
			cout << " -" << M[L.indexOf(e.bar())];
		}
		else
		{
			cout << " " <<  e;
		}
	}
	cout << " )" << endl;
}
