// The program entry point. public static int Main() { try { // Calculate the filenames of the input and output files. string inputFile = "CrstTypes.def"; string outputFile = "CrstTypes.h"; // A common error is to forget to check out the CrstTypes.h file first. Handle this case specially // so we can give a good error message. if (File.Exists(outputFile) && (File.GetAttributes(outputFile) & FileAttributes.ReadOnly) != 0) { Console.WriteLine(outputFile + " is read-only, you must check it out of TFS/SD first"); return(2); } // Create an instance of our application class to store state in (specifically the collection of // Crst type definitions). CrstTypeTool app = new CrstTypeTool(); // Create a parser for the CrstTypes.def file and run it over the input file (errors are signalled // via exception, in common with all the following steps except validation). new TypeFileParser().ParseFile(inputFile, app.m_crsts); // Validate the collection of Crst type definitions we built up during parsing for common logic // errors and the presence of dependency cycles. False is returned from ValidateCrsts if an error // was detected (an error message will have already been output to the console at this point). if (!app.ValidateCrsts()) { return(3); } // Perform a topological sort to map each Crst type to a numeric ranking. app.LevelCrsts(); // Emit the new header file containing Crst type definitions and ranking information. app.WriteHeaderFile(outputFile); // If we get here the transformation was successful; inform the user and we're done. Console.WriteLine(outputFile + " successfully updated"); return(0); } catch (TypeFileParser.ParseError pe) { // Syntax errors specific to parsing the input file. Console.WriteLine("ParseError: " + pe.Message); return(4); } catch (Exception e) { // Any other general errors (file I/O problems, out of memory etc.). Console.WriteLine("Unexpected exception:"); Console.WriteLine(e); return(5); } }
// The program entry point. public static int Main() { try { // Calculate the filenames of the input and output files. string inputFile = "CrstTypes.def"; string outputFile = "CrstTypes.h"; // A common error is to forget to check out the CrstTypes.h file first. Handle this case specially // so we can give a good error message. if (File.Exists(outputFile) && (File.GetAttributes(outputFile) & FileAttributes.ReadOnly) != 0) { Console.WriteLine(outputFile + " is read-only, you must check it out of TFS/SD first"); return 2; } // Create an instance of our application class to store state in (specifically the collection of // Crst type definitions). CrstTypeTool app = new CrstTypeTool(); // Create a parser for the CrstTypes.def file and run it over the input file (errors are signalled // via exception, in common with all the following steps except validation). new TypeFileParser().ParseFile(inputFile, app.m_crsts); // Validate the collection of Crst type definitions we built up during parsing for common logic // errors and the presence of dependency cycles. False is returned from ValidateCrsts if an error // was detected (an error message will have already been output to the console at this point). if (!app.ValidateCrsts()) return 3; // Perform a topological sort to map each Crst type to a numeric ranking. app.LevelCrsts(); // Emit the new header file containing Crst type definitions and ranking information. app.WriteHeaderFile(outputFile); // If we get here the transformation was successful; inform the user and we're done. Console.WriteLine(outputFile + " successfully updated"); return 0; } catch (TypeFileParser.ParseError pe) { // Syntax errors specific to parsing the input file. Console.WriteLine("ParseError: " + pe.Message); return 4; } catch (Exception e) { // Any other general errors (file I/O problems, out of memory etc.). Console.WriteLine("Unexpected exception:"); Console.WriteLine(e); return 5; } }