import java.io.*;
import java.util.Hashtable;	// contain Hashtable
import myutil.*;
import ccj.*;

class PUData 
{
    String name;
    String dept;
    String email;
    String phone;
    String addr;
}

public class PUHasher4
{
    static Hashtable ht;

    static void readData()
    {
	int i;
	String line=null;

	BufferedReader in;
	try { in = new BufferedReader(new FileReader("pu_names.dat")); }
	catch (FileNotFoundException fe) 
	{ System.err.println("File not found"); return; }

	PUData    p  = new PUData();
	for (i=0; ; i++) {
	    if (i%500 == 0) {System.out.println(i);}

	    try { line = in.readLine(); } 
	    catch (IOException e) {System.err.println("IO Error");}

	    if (line == null) break;

	    int j = line.indexOf(":")+2;
	    int k = line.length();

	    if (line.startsWith("            name: ")) {
		p.name = line.substring(j,k);
	    } else
	    if (line.startsWith("           phone: ")) {
		p.phone = line.substring(j,k);
	    } else
	    if (line.startsWith("         address: ")) {
		p.addr = line.substring(j,k);
	    } else
	    if (line.startsWith("      department: ")) {
		p.dept = line.substring(j,k);
	    } else
	    if (line.startsWith("           email: ")) {
		p.email = line.substring(j,k);
	    } else
	    if (line.startsWith("------------------")) {
		if (p.name != null) {
		    if (ht.get(p.name) == null) {ht.put(p.name, p);}
		    p = new PUData();
		}
	    } 
	}
    }

    static void searchNames()
    {
	String name;

        while (true) {
	    name = Console.in.readLine("Enter a name: ");
	    if (name.equals("quit")) break;
    
	    PUData p2 = (PUData) ht.get(name);

            if ( p2 != null ) {                             
                Console.out.println("Found it  "+p2.name);
                Console.out.println("          "+p2.dept);
                Console.out.println("          "+p2.addr);
                Console.out.println("          "+p2.phone);
                Console.out.println("          "+p2.email);
            } else {
                Console.out.println("Not found");       
            }
        }
    }

    public static void main(String[] args)
    {

	ht = new Hashtable(3000);

	readData();
    
	searchNames();
    
    }
} 
