static void Main(string[] args) { // // Get the streams // var StdOut = new StreamWriter(Console.OpenStandardOutput()); StreamReader StdIn; if (args.Length == 0) { StdIn = new StreamReader(Console.OpenStandardInput()); } else { StdIn = new StreamReader(args[0]); } // // Set MySQL to not escape backslashes in strings // StdOut.WriteLine("SET sql_mode='NO_BACKSLASH_ESCAPES';"); // // Now read all text from the input and output it // // Strings can span multiple lines, so we need to keep track // of when we're in one for quote replacement // Char[] Buffer = new Char[1024]; Boolean InString = false; List <Char> Characters = new List <Char>(1024); while (!StdIn.EndOfStream) { // // Read and process the next line // // We need to maintain line endings as lines // in strings can be terminated by both \r\n and // \n so we just look for \n then process the line // Int32 Count = StdIn.Read(Buffer, 0, Buffer.Length); for (Int32 i = 0; i < Count; ++i) { // // Lines can be terminated by both \r\n and \n, so look for // just the '\n' // Characters.Add(Buffer[i]); if (Buffer[i] == '\n') { String Line = new String(Characters.ToArray()); Characters.Clear(); ProcessLine(Line, StdOut, ref InString); } } } // // Flush the output stream // StdOut.Flush(); }