/*
  James Little
  Sat 17 March, Exercise 4, COSC 241
  Program reads a stream of texts and counts the 
  frequency of the words contained.

  UPDATED 3/4/01 James Little - for exercise 7
  It now reads in data and records characters.
*/

package jlittle_ex7;
import java.util.*;
import java.io.*;

/* UPDATED 3/4/01 James Little - for exercise 7
   It now reads in data and records characters.
   and now it is really different to the original
   thanks to a little/[close to none] communication about 
   how this was supposed to be implemented my work load
   on it has doubled.
*/ 

public class AppWord {
    
    private static Word [] list = new Word[67];
    private static Word w;
    private static int count=0;
    private static int totalwords=0; 

    public static void main(String [] args){
	// we have found a dataInputStream!!
	BufferedReader in =
	    new BufferedReader(new InputStreamReader(System.in));// get ready to read
	try{
	    // start reading input
	    int temp;
	    while((temp=in.read())!=-1) {
		boolean onlist=false;
		
		// the reject conditions:
		boolean reject = ((temp<32&&!(temp==13|| // exclude command char, but not carriage return
					      temp==10|| // don't exclude newline
					      temp==9|| // don't exclude horizontal tab
					      temp==11))|| // don't exclude vertical tab
				  (temp>122)|| // exclude punctuation and numbers over 127
				  (temp>32&&temp<48)|| // exclude punctuation
				  (temp>57&&temp<65)|| // exclude punctuation
				  (temp>90&&temp<97)); // exclude punctuation
		if(!reject){
		    for(int z=0; z<count; z++){
			if (temp==list[z].getWord()){
			    list[z].addOne(); 
			    totalwords++;
			    onlist=true;
			}//if
		    }//for
		    
		    if(!onlist){ 
			list[count]=new Word(temp);
			totalwords++;
			count++;
		    }//if
		}
	    } //while
	}catch(IOException e){ 
	    System.out.println("ERROR: " + e);
	}
	Sort s = new Sort(list, count, totalwords);
	s.quicksort(0,count-1);
	s.writeData();
	
	// ok thats it.. now for the shorts:
	System.out.println("END OF OUTPUT");
    } //main
}//AppWord

