// Introduction to Software Testing // Authors: Paul Ammann & Jeff Offutt // Chapter 2, section 2.5, page 80 /** ***************************************************** // Stutter checks for repeat words in a text file. // It prints a list of repeat words, by line number. // Stutter will accept standard input or a list // of file names. * Jeff Offutt, June 1989 (in C), Java version March 2003 ********************************************************* */ import java.io.*; class Stutter { // Class variables used in multiple methods. private static boolean lastdelimit = true; private static String curWord = "", prevWord = ""; private static char delimits [] = {' ', ' ', ',', '.', '!', '-', '+', '=', ';', ':', '?', '&', '{', '}', '\\'}; // First char in list is a tab //************************************************ // main parses the arguments, decides if stdin // or a file name, and calls Stut(). //************************************************ public static void main (String[] args) throws IOException { String fileName; FileReader myFile; BufferedReader inFile = null; if (args.length == 0) { // no file, use stdin inFile = new BufferedReader (new InputStreamReader (System.in)); } else { fileName = args [0]; if (fileName == null) { // no file name, use stdin inFile = new BufferedReader (new InputStreamReader (System.in)); } else { // file name, open the file. myFile = new FileReader (fileName); inFile = new BufferedReader (myFile); } } stut (inFile); } //************************************************ // Stut() reads all lines in the input stream, and // finds words. Words are defined as being surrounded // by delimiters as defined in the delimits[] array. // Every time an end of word is found, checkDupes() // is called to see if it is the same as the // previous word. //************************************************ private static void stut (BufferedReader inFile) throws IOException { String inLine; char c; int linecnt = 1; while ((inLine = inFile.readLine()) != null) { // For each line for (int i=0; i