diff --git a/tools/preproc/asm_file.cpp b/tools/preproc/asm_file.cpp index a82354cb5f..69b412b24e 100644 --- a/tools/preproc/asm_file.cpp +++ b/tools/preproc/asm_file.cpp @@ -679,7 +679,7 @@ void AsmFile::RaiseWarning(const char* format, ...) int AsmFile::SkipWhitespaceAndEol() { int newlines = 0; - while (m_buffer[m_pos] == '\t' || m_buffer[m_pos] == ' ' || m_buffer[m_pos] == '\n') + while (m_buffer[m_pos] == '\t' || m_buffer[m_pos] == ' ' || m_buffer[m_pos] == '\r' || m_buffer[m_pos] == '\n') { if (m_buffer[m_pos] == '\n') newlines++; @@ -702,14 +702,14 @@ int AsmFile::FindLastLineNumber(std::string& filename) if (pos < 0) RaiseError("line indicator for header file not found before `enum`"); - + pos++; while (m_buffer[pos] == ' ' || m_buffer[pos] == '\t') pos++; if (!IsAsciiDigit(m_buffer[pos])) RaiseError("malformatted line indicator found before `enum`, expected line number"); - + unsigned n = 0; int digit = 0; while ((digit = ConvertDigit(m_buffer[pos++], 10)) != -1) @@ -744,7 +744,7 @@ int AsmFile::FindLastLineNumber(std::string& filename) filename += c; } - + return n + linebreaks - 1; } diff --git a/tools/preproc/preproc.cpp b/tools/preproc/preproc.cpp index 20c2de51b6..ac9496d701 100644 --- a/tools/preproc/preproc.cpp +++ b/tools/preproc/preproc.cpp @@ -26,6 +26,11 @@ #include "c_file.h" #include "charmap.h" +#ifdef _WIN32 +#include +#include +#endif + static void UsageAndExit(const char *program); Charmap* g_charmap; @@ -179,6 +184,11 @@ int main(int argc, char **argv) g_charmap = new Charmap(charmap); +#ifdef _WIN32 + // On Windows, piping from stdout can break newlines. Treat stdout as binary stream to avoid this. + _setmode(_fileno(stdout), _O_BINARY); +#endif + const char* extension = GetFileExtension(source); if (!extension)