// input.c
//	New input function: accepts the output format.
//	Old input format kept for compatibility with old
//	input files.
//	JR 4/7/96

istream& eatWhiteSpace(istream& i)  // space tab newline 
{
	char c;
	while( i.get(c) )
	{
		if( !(c==' ' || c=='\n' || c=='\t') )
		{
			i.putback(c);
			break;
		}
	}
	return i;
}

Homeo::Homeo(istream& in)	
{
	eatWhiteSpace(in);
			// See if new input style.
	char c;
	in.get(c);
	if(c=='E')	// New style.
	{
		in.putback(c);
		char str[50];		

			// Make set of names.

		in.get(str,50,':');
		char colon;
		in.get(colon);
		in >> theNameManager.edgs;

			// Make periphery.
		eatWhiteSpace(in);		
		in.get(str,50,':');
		in.get(colon);
		in >> theNameManager.perip;

			// Make puncture set.

		eatWhiteSpace(in);		
		in.get(str,50,':');
		in.get(colon);
		in >> theNameManager.puncs;

			// Make Graph.

		eatWhiteSpace(in);		
		in.get(str,50,':');
		in.get(colon);
		in >> theGraph;
		
			// Make Map.

		eatWhiteSpace(in);		
		in.get(str,50,':');
		in.get(colon);
		in >> theMap;

			// Make Equator.

		eatWhiteSpace(in);		
		in.get(str,50,':');
		in.get(colon);
		in >> theEquator;
	}
	else if(c=='(')	// Braid word (delimited by parentheses).
	{
	    in.putback(c);
	    BraidWord bw;
	    in >> bw;
	    cout << "Braid word is " << bw << endl;

	    (*this)=Homeo(bw);
	}
	else	// Old style.
	{

	in.putback(c);
	// make NameManager
	Set<Name> s;
	int n;
	in >> n; nextline(in);
//	cout << n << " edges : " ;
	int edgename;
	while(n--) { in >> edgename;
//		     cout << edgename << ", ";
		     s.add(edgename);
		   }
	nextline(in);
//	cout << endl << s;
	theNameManager.edgs=s;

	Set<Name> p;
	in >> n;  nextline(in);
//	cout << n << " peripheral edges : ";
	while(n--) { in >> edgename;
		     p.add(edgename);
		   }
	nextline(in);
//	cout << p;
	theNameManager.perip=p;

	Set<Name> pu;
	in >> n;  nextline(in);
//	cout << n << " punctures : ";
	while(n--) { in >> edgename;
		     pu.add(edgename);
		   }
	nextline(in);
//	cout << pu;
	theNameManager.puncs=pu;

	// make Graph
	int nv;
	int e;
	in >> nv; nextline(in);
//	cout << nv << " vertices : " << endl;	
	while(nv--)
	{
		Vertex v;
		int ninv;
		in >> ninv; nextline(in);
//		cout << ninv << " edges : " ;

		while(ninv--)
		{
		 	in >> e;
			if(e>0) v.pushb(DE(Name(e),0));
			else 	v.pushb(DE(Name(-e),1));
		}
		nextline(in);
//		cout << v << endl;
		theGraph.add(v);

	}	

	// make Equator
	int ne;
	Equator eqtr;
	in >> ne; nextline(in);
//	cout << ne << " edge-crossings : " << endl;	
	while(ne--)
	{
	  in >> e;
		if(e>0) eqtr.append(DE(Name(e),0));
		else 	eqtr.append(DE(Name(-e),1));
	}
	nextline(in);
//	cout << eqtr << endl;
	theEquator = eqtr;

	// make Map
	Map M;
	int nme;
	in >> nme; nextline(in);
//	cout << nme << " map elements :" << endl;

	while(nme--)
	{
		in >> e; nextline(in);
		MapElement me;
		if(e>0)  me.source()=DE(Name(e),0);
		else 	 me.source()=DE(Name(-e),1);

		int il;
		in >> il; nextline(in);
		while(il--)
		{
			in >> e;
			if(e>0) me.image().append(DE(Name(e),0));
			else 	me.image().append(DE(Name(-e),1));
		}
		nextline(in);
		M.add(me);
	}
//	cout << M << endl;
	theMap=M;

	}
}
