import java.io.*;
import java.util.*;

public class SLOC {
	private static String[] defaultExtensions = new String[] {
			"java", "c", "h", "cpp", "cs", "pas", "bas", "hs", "php", "py",
			"pl", "cgi", "html", "css", "js", "bat", "sh", "f", "for", "asm"};

	private static boolean notBlank(String line) {
		for (char c : line.toCharArray())
			if (!Character.isWhitespace(c))
				return true;
		return false;
	}

	public static void main(String[] args) throws IOException {
		String[] extensions = args.length == 0 ? defaultExtensions : args;
		Map<String, int[]> linesByExtension = new HashMap<String, int[]>();

		Stack<File> searchStack = new Stack<File>();
		searchStack.push(new File(System.getProperty("user.dir")));

		while (!searchStack.isEmpty()) {
			File dir = searchStack.pop();
			try {
				for (File child : dir.listFiles())
					if (child.isDirectory())
						searchStack.push(child);
					else for (String ext : extensions)
						if (child.getName().endsWith("." + ext)) {
							if (!linesByExtension.containsKey(ext))
								linesByExtension.put(ext, new int[2]);
							int[] counters = linesByExtension.get(ext);

							FileReader fr = new FileReader(child);
							BufferedReader br = new BufferedReader(fr);

							String line;
							while ((line = br.readLine()) != null) {
								++counters[0];
								if (notBlank(line))
									++counters[1];
							}
						}
			} catch (Exception e) {
				System.err.printf("%s involving file %s: %s\n",
				                  e.getClass().getCanonicalName(),
				                  dir, e.getMessage());
			}
		}

		for (Map.Entry<String, int[]> e : linesByExtension.entrySet())
			System.out.printf(".%s: %d physical lines, %d nonblank\n",
			                  e.getKey(), e.getValue()[0], e.getValue()[1]);
	}
}

