// Profile.java
// based on joi/9/copy/Copy2.java                         
//
// Ethan Bolker, April 2004 for cs110 hw10
                                                            
import java.io.*;

/**
 * Profile Java source code.
 *
 * Usage: java Classname
 */

public class Profile
{
    /**
     * All work is done here.
     *
     * @param args Class name
     */

    public static void main( String[] args ) 
    {
        BufferedReader inStream  = null;
	String className = null;
        String line;
	int lineCount = 0;
	int blankLines = 0;
	int errorLines = 0;
	int commentLines = 0;
        try {
	    className = args[0];

            // open the file
            inStream =  new BufferedReader(new FileReader(className+".java"));

            // parse
            while ((line = inStream.readLine()) != null) {
		line = line.trim();
		lineCount++;
		if ( line.length() == 0 ) {
		    blankLines++;
		    continue;
		}
		if ( line.startsWith("*") 
		     || line.startsWith("/*")
		     || line.startsWith("//")) {
		    commentLines++;
		}
		if (line.indexOf("EEE") >= 0) {
		    errorLines++;
		}
            }
        }
        catch (IndexOutOfBoundsException e) {
            System.err.println( "usage: java Profile Classname" );
	    System.exit(0);
        }
        catch (FileNotFoundException e) {
            System.err.println( e );  // rely on e's toString()
	    System.exit(0);
        }
        catch (IOException e) {
            System.err.println( e );
	    System.exit(0);
        }
        finally { // close the file
            try {
		inStream.close();
            }
            catch (Exception e) {
                System.err.println("Unable to close input stream.");
            }
        }
	System.out.println( "Class " + className );
	System.out.println( "lines:                " + lineCount);
	System.out.println( "blank lines:          " + blankLines);
	System.out.println( "comment lines:        " + commentLines);
	System.out.println( "code lines:           " + 
			    (lineCount - blankLines - commentLines));
	System.out.println( "error handling lines: " + errorLines);
	
			    
    }
}

