static bool ReadFile(string FileName, WordMaker word, LineMaker line) { bool fileExists = OpenFile(FileName, out StreamReader Reader); if (!fileExists) { return(false); } word.FileToRead = Reader; int input = word.FileToRead.Read(); //initialize input variable, if read char is non-white, is passed from EatSpaces fun. to ReadWord fun word.EatSpaces(ref input); //eat eventual whitespaces at the begining of file, not taking into account columns at the beggining while (input != -1) { word.Clear(); word.ReadWord(ref input); word.EatSpaces(ref input); line.BuildLine(word); } line.FlushToFile(); word.FileToRead.Close(); return(true); }
public static void Main(string[] args) { bool check = InitialCheck(args, out bool HiglightSpace, out StreamWriter Output, out int WidhtOfLine); if (check == false) //problem with arguments or output file { return; } LineMaker line = new LineMaker(WidhtOfLine, Output, HiglightSpace); WordMaker word = new WordMaker(); int i = 0; int flawedFiles = 0; //counter of input files that cannot be opened if (HiglightSpace) //is arg0 file name or --HighlightSpaces? { i = 1; flawedFiles = 1; } for (; i < args.Length - 2; i++) { if (i == (args.Length - 3)) { word.FinalFile = true; } if (!ReadFile(args[i], word, line)) { flawedFiles++; } } if (flawedFiles == (args.Length - 2)) // all input files are flawed { line.LineInEmptyFile(); line.FlushToFile(); } line.PushToWriter(); line.FlushToFile(); line.CloseWriter(); }