001 package com.croftsoft.apps.src;
002
003 import java.io.DataInputStream;
004 import java.io.File;
005 import java.io.FileInputStream;
006 import java.io.FileOutputStream;
007 import java.io.PrintStream;
008 import java.util.StringTokenizer;
009
010 /*********************************************************************
011 * <P>
012 * This java application searches through all of the *.java files
013 * in the current directory and counts the number of lines.
014 * Ignores blank lines.
015 * <P>
016 * @version
017 * 1997-01-03
018 * @author
019 * <A HREF="http://www.alumni.caltech.edu/~croft">David W. Croft</A>
020 *********************************************************************/
021
022 public class LineCount {
023 //////////////////////////////////////////////////////////////////////
024 //////////////////////////////////////////////////////////////////////
025
026 public static void main ( String [ ] args ) {
027 //////////////////////////////////////////////////////////////////////
028 // if ( args.length != 2 ) {
029 // System.out.println ( "java LineCount" );
030 // return;
031 // }
032 String path = ".";
033 File dir = new File ( path );
034 String [ ] file_list = dir.list ( );
035 long lineCount = 0;
036 for ( int i = 0; i < file_list.length; i++ ) {
037 File file = new File ( dir, file_list [ i ] );
038 if ( !file.isFile ( ) ) continue;
039 StringTokenizer tokens
040 = new StringTokenizer ( file_list [ i ], "." );
041 if ( tokens.countTokens ( ) != 2 ) continue;
042 String filename = tokens.nextToken ( );
043 String extension = tokens.nextToken ( );
044 if ( !extension.equals ( "java" ) ) continue;
045 System.out.println ( file_list [ i ] );
046 FileInputStream fileInputStream;
047 DataInputStream dataInputStream;
048 String line;
049 try {
050 fileInputStream = new FileInputStream ( file );
051 dataInputStream = new DataInputStream ( fileInputStream );
052 while ( ( line = dataInputStream.readLine ( ) ) != null ) {
053 if ( line.trim ( ).length ( ) > 0 ) {
054 ++lineCount;
055 }
056 }
057 } catch ( Exception e ) { continue; }
058 System.err.println ( lineCount );
059 /*
060 tokens = new StringTokenizer ( line );
061 if ( tokens.countTokens ( ) != 2 ) continue;
062 String tokenStr = tokens.nextToken ( );
063 if ( !tokenStr.equals ( "package" ) ) continue;
064 int index = line.lastIndexOf ( args [ 0 ] );
065 System.out.println ( "" + index );
066 if ( index < 0 ) continue;
067 String new_line = line.substring ( 0, index )
068 + args [ 1 ] + line.substring ( index + args [ 0 ].length ( ) );
069 FileOutputStream fileOutputStream;
070 PrintStream printStream;
071 try {
072 fileOutputStream
073 = new FileOutputStream ( file_list [ i ] + ".new" );
074 printStream = new PrintStream ( fileOutputStream );
075 } catch ( Exception e ) { continue; }
076 line = new_line;
077 try {
078 do {
079 printStream.println ( line );
080 line = dataInputStream.readLine ( );
081 } while ( line != null );
082 }
083 catch ( Exception e ) { }
084 printStream.close ( );
085 */
086 }
087 }
088
089 //////////////////////////////////////////////////////////////////////
090 //////////////////////////////////////////////////////////////////////
091 }