Index: Debug.cpp =================================================================== --- Debug.cpp (revision 1270) +++ Debug.cpp (working copy) @@ -189,7 +189,7 @@ { if(!susrlog) return NilStream(); - return UsrLogStream() << line << "\r\n"; + return UsrLogStream() << line << EOL; } Stream& UsrLogT(int indent, const char *line) @@ -202,7 +202,7 @@ Stream& s = UsrLogStream() << h; while(indent--) s << " "; - s << line << "\r\n"; + s << line << EOL; return s; } @@ -294,7 +294,7 @@ TimingInspector::~TimingInspector() { Mutex::Lock __(mutex); if(this == &s_zero()) return; - StdLog() << Dump() << "\r\n"; + StdLog() << Dump() << EOL; } void TimingInspector::Start() { @@ -349,11 +349,11 @@ void HexDump(Stream& s, const void *ptr, int size, int maxsize) { char h[256]; - sprintf(h, "Memory at %p, size 0x%X = %d\n", ptr, size, size); + sprintf(h, "Memory at %p, size 0x%X = %d" EOL_STR, ptr, size, size); s.Put(h); #ifdef PLATFORM_WIN32 if(IsBadReadPtr(ptr, size)) { - s.Put(" \n"); + s << " " << EOL; return; } #endif @@ -384,7 +384,7 @@ else s.Put(' '); a += 16; - s << '\n'; + s << EOL; } } @@ -449,7 +449,7 @@ er->ExceptionCode, er->ExceptionAddress); UsrLogT("============ CRASH ================================================"); UsrLogT(h); - BugLog() << h << "\r\n"; + BugLog() << h << EOL; return sPrev ? (*sPrev)(ep) : 0 /*EXCEPTION_CONTINUE_SEARCH*/; } Index: Defs.h =================================================================== --- Defs.h (revision 1270) +++ Defs.h (working copy) @@ -549,3 +549,14 @@ #else inline void __LOGF__(const char *format, ...); #endif + +enum EOLenum { EOL }; + +const word WinEOL = MAKEWORD('\r', '\n'); +const byte LinEOL = '\n'; + +#ifdef PLATFORM_WIN32 +# define EOL_STR "\r\n" +#else +# define EOL_STR "\n" +#endif Index: heapdbg.cpp =================================================================== --- heapdbg.cpp (revision 1270) +++ heapdbg.cpp (working copy) @@ -174,14 +174,14 @@ while(p != &dbg_live) { if(p->serial) { if(!leaks) { - BugLog() << "\n\nHeap leaks detected:\n"; - VppLog() << "\n\nHeap leaks detected:\n"; + BugLog() << EOL << EOL << "Heap leaks detected:" << EOL; + VppLog() << EOL << EOL << "Heap leaks detected:" << EOL; } leaks = true; char b[100]; DbgFormat(b, p); - BugLog() << '\n' << b; - VppLog() << '\n' << b << ": "; + BugLog() << EOL << b; + VppLog() << EOL << b << ": "; HexDump(VppLog(), p + 1, (int)(uintptr_t)p->size, 64); } p = p->next; Index: heaputil.cpp =================================================================== --- heaputil.cpp (revision 1270) +++ heaputil.cpp (working copy) @@ -125,7 +125,7 @@ void HeapPanic(const char *text, void *pos, int size) { - RLOG("\n\n" << text << "\n"); + RLOG(EOL_STR EOL_STR << text << EOL); HexDump(VppLog(), pos, size, 64); Panic(text); } @@ -241,17 +241,17 @@ sum += stat[i]; sum += bigstat; int total = 0; - VppLog() << Sprintf("Allocation statistics: (total allocations: %d)\n", sum); + VppLog() << Sprintf("Allocation statistics: (total allocations: %d)", sum) << EOL; for(int i = 0; i < 65536; i++) if(stat[i]) { total += stat[i]; - VppLog() << Sprintf("%5d %8dx %2d%%, total %8dx %2d%%\n", - i, stat[i], 100 * stat[i] / sum, total, 100 * total / sum); + VppLog() << Sprintf("%5d %8dx %2d%%, total %8dx %2d%%", + i, stat[i], 100 * stat[i] / sum, total, 100 * total / sum) << EOL; } if(bigstat) { total += bigstat; - VppLog() << Sprintf(">64KB %8dx %2d%%, total %8dx %2d%%\n", - bigstat, 100 * bigstat / sum, total, 100 * total / sum); + VppLog() << Sprintf(">64KB %8dx %2d%%, total %8dx %2d%%", + bigstat, 100 * bigstat / sum, total, 100 * total / sum) << EOL; } } #endif Index: Lang.cpp =================================================================== --- Lang.cpp (revision 1270) +++ Lang.cpp (working copy) @@ -520,24 +520,24 @@ String LanguageInfo::ToString() const { String out; - out << "LANGUAGE={" << LNGAsText(language) << "}\n" + out << "LANGUAGE={" << LNGAsText(language) << "}" << EOL #ifdef PLATFORM_WIN32 - << NFormat("LCID={%08x}\n", (int)GetLanguageLCID(language)) + << NFormat("LCID={%08x}", (int)GetLanguageLCID(language)) << EOL #endif - << "ENGLISH_NAME={" << english_name << "}\n" - "NATIVE_NAME={" << FromUnicode(native_name) << "}\n" - "CHARSET={" << charset << "}\n" - "THOUSAND_SEPARATOR={" << thousand_separator << "}\n" - "DECIMAL_POINT={" << decimal_point << "}\n" - "MONTH_NAMES={\n"; + << "ENGLISH_NAME={" << english_name << "}" << EOL + << "NATIVE_NAME={" << FromUnicode(native_name) << "}" << EOL + << "CHARSET={" << charset << "}" << EOL + << "THOUSAND_SEPARATOR={" << thousand_separator << "}" << EOL + << "DECIMAL_POINT={" << decimal_point << "}" << EOL + << "MONTH_NAMES={" << EOL; int i; for(i = 0; i < __countof(month_names); i++) - out << " {" << FromUnicode(month_names[i]) << "} / {" << FromUnicode(short_month_names[i]) << "}\n"; - out << "}\n" - "DAY_NAMES={\n"; + out << " {" << FromUnicode(month_names[i]) << "} / {" << FromUnicode(short_month_names[i]) << "}" << EOL; + out << "}" << EOL + << "DAY_NAMES={" << EOL; for(i = 0; i < __countof(day_names); i++) - out << " {" << FromUnicode(day_names[i]) << "} / {" << FromUnicode(short_day_names[i]) << "}\n"; - out << "}\n"; + out << " {" << FromUnicode(day_names[i]) << "} / {" << FromUnicode(short_day_names[i]) << "}" << EOL; + out << "}" << EOL; return out; } Index: LocalProcess.cpp =================================================================== --- LocalProcess.cpp (revision 1270) +++ LocalProcess.cpp (working copy) @@ -39,7 +39,7 @@ } #endif #ifdef PLATFORM_POSIX - LLOG("\nLocalProcess::Free, pid = " << (int)getpid()); + LLOG(EOL_STR "LocalProcess::Free, pid = " << (int)getpid()); LLOG("rpipe[" << rpipe[0] << ", " << rpipe[1] << "]"); LLOG("wpipe[" << wpipe[0] << ", " << wpipe[1] << "]"); if(rpipe[0] >= 0) { close(rpipe[0]); rpipe[0] = -1; } @@ -106,7 +106,7 @@ else { Free(); return false; -// throw Exc(NFormat("Error running process: %s\nCommand: %s", GetErrorMessage(GetLastError()), command)); +// throw Exc(NFormat("Error running process: %s" EOL_STR "Command: %s", GetErrorMessage(GetLastError()), command)); } return true; #endif @@ -158,13 +158,13 @@ String app_full = GetFileOnPath(app, getenv("PATH"), true); if(IsNull(app_full)) return false; -// throw Exc(Format("Cannot find executable '%s'\n", app)); +// throw Exc(Format("Cannot find executable '%s'" EOL_STR, app)); if(pipe(rpipe) || pipe(wpipe)) return false; // throw Exc(NFormat(t_("pipe() error; error code = %d"), errno)); - LLOG("\nLocalProcess::Start"); + LLOG(EOL_STR "LocalProcess::Start"); LLOG("rpipe[" << rpipe[0] << ", " << rpipe[1] << "]"); LLOG("wpipe[" << wpipe[0] << ", " << wpipe[1] << "]"); @@ -204,7 +204,7 @@ else execv(app_full, args.Begin()); LLOG("execve failed, errno = " << errno); -// printf("Error running '%s', error code %d\n", command, errno); +// printf("Error running '%s', error code %d" EOL_STR, command, errno); exit(-errno); return true; #endif @@ -238,14 +238,14 @@ int sig = (WIFSIGNALED(status) ? WTERMSIG(status) : WSTOPSIG(status)); exit_code = (WIFSIGNALED(status) ? 1000 : 2000) + sig; - exit_string << "\nProcess " << (WIFSIGNALED(status) ? "terminated" : "stopped") << " on signal " << sig; + exit_string << EOL << "Process " << (WIFSIGNALED(status) ? "terminated" : "stopped") << " on signal " << sig; for(int i = 0; i < __countof(signal_map); i++) if(signal_map[i].code == sig) { exit_string << " (" << signal_map[i].name << ")"; break; } - exit_string << "\n"; + exit_string << EOL; return true; } return false; @@ -261,14 +261,14 @@ #endif #ifdef PLATFORM_POSIX if(IsRunning()) { - LLOG("\nLocalProcess::Kill, pid = " << (int)pid); + LLOG(EOL_STR "LocalProcess::Kill, pid = " << (int)pid); exit_code = 255; kill(pid, SIGTERM); GetExitCode(); int status; if(pid && waitpid(pid, &status, 0) == pid) DecodeExitCode(status); - exit_string = "Child process has been killed.\n"; + exit_string = "Child process has been killed." EOL_STR; } #endif Free(); Index: Log.cpp =================================================================== --- Log.cpp (revision 1270) +++ Log.cpp (working copy) @@ -143,7 +143,7 @@ #endif char h[1000]; - sprintf(h, "* %s %02d.%02d.%04d %02d:%02d:%02d, user: %s\n", + sprintf(h, "* %s %02d.%02d.%04d %02d:%02d:%02d, user: %s" EOL_STR, FromSysChrSet(exe), t.day, t.month, t.year, t.hour, t.minute, t.second, user); #ifdef PLATFORM_WIN32 @@ -153,14 +153,14 @@ sprintf(h, ", #%d", part); WriteFile(hfile, h, (dword)strlen(h) , &n, NULL); } - WriteFile(hfile, "\r\n", 2, &n, NULL); + WriteFile(hfile, EOL_STR, 2, &n, NULL); #else write(hfile, h, strlen(h)); if(part) { sprintf(h, ", #%d", part); write(hfile, h, strlen(h)); } - write(hfile, "\r\n", 2); + write(hfile, EOL_STR, 1); #endif } @@ -253,9 +253,9 @@ while(i < n && large[i] == q) i++; nn = i - nn; if(q < 10000) - text << Format("%4d B, %5d %s (%6d KB)\r\n", (int)(uintptr_t)q, nn, txt, (int)(uintptr_t)((nn * q) >> 10)); + text << Format("%4d B, %5d %s (%6d KB)", (int)(uintptr_t)q, nn, txt, (int)(uintptr_t)((nn * q) >> 10)) << EOL; else - text << Format("%4d`KB, %5d %s (%6d KB)\r\n", (int)(uintptr_t)(q >> 10), nn, txt, (int)(uintptr_t)((nn * q) >> 10)); + text << Format("%4d`KB, %5d %s (%6d KB)", (int)(uintptr_t)(q >> 10), nn, txt, (int)(uintptr_t)((nn * q) >> 10)) << EOL; } } @@ -269,22 +269,22 @@ for(int i = 0; i < 1024; i++) if(mem.allocated[i]) { int sz = 4 * i; - text << Format("%4d B, %6d allocated (%5d KB), %6d fragmented (%5d KB)\n", + text << Format("%4d B, %6d allocated (%5d KB), %6d fragmented (%5d KB)", sz, mem.allocated[i], (mem.allocated[i] * sz) >> 10, - mem.fragmented[i], (mem.fragmented[i] * sz) >> 10); + mem.fragmented[i], (mem.fragmented[i] * sz) >> 10) << EOL; acount += mem.allocated[i]; asize += mem.allocated[i] * sz; fcount += mem.fragmented[i]; fsize += mem.fragmented[i] * sz; } - text << Format(" TOTAL, %6d allocated (%5d KB), %6d fragmented (%5d KB)\n", - acount, int(asize >> 10), fcount, int(fsize >> 10)); - text << "Free pages " << mem.freepages << " (" << mem.freepages * 4 << " KB)\n"; + text << Format(" TOTAL, %6d allocated (%5d KB), %6d fragmented (%5d KB)", + acount, int(asize >> 10), fcount, int(fsize >> 10)) << EOL; + text << "Free pages " << mem.freepages << " (" << mem.freepages * 4 << " KB)" << EOL; text << "Large block count " << mem.large_count - << ", total size " << (mem.large_total >> 10) << " KB\n"; + << ", total size " << (mem.large_total >> 10) << " KB" << EOL; // sLarge(text, mem.large_size, mem.large_count, "allocated"); text << "Large fragments count " << mem.large_free_count - << ", total size " << (mem.large_free_total >> 10) << " KB\n"; + << ", total size " << (mem.large_free_total >> 10) << " KB" << EOL; // sLarge(text, mem.large_free_size, mem.large_free_count, "fragments"); return text; } Index: parser.cpp =================================================================== --- parser.cpp (revision 1270) +++ parser.cpp (working copy) @@ -393,7 +393,7 @@ inline void NextCStringLine(String& t, const char *linepfx, int& pl) { - t << "\"\r\n" << (linepfx ? linepfx : "") << "\""; + t << "\"" EOL_STR << (linepfx ? linepfx : "") << "\""; pl = t.GetLength(); } Index: Parser.h =================================================================== --- Parser.h (revision 1270) +++ Parser.h (working copy) @@ -67,7 +67,7 @@ Pos(const char *ptr = NULL, int line = 1, String fn = Null) : ptr(ptr), line(line), fn(fn) {} }; - const char *GetPtr() { return (const char *)term; } + const char *GetPtr() const { return (const char *)term; } Pos GetPos(); void SetPos(const Pos& pos); Index: Stream.cpp =================================================================== --- Stream.cpp (revision 1270) +++ Stream.cpp (working copy) @@ -398,6 +398,11 @@ } } +void Stream::PutEol() +{ + *this << EOL; +} + void Stream::PutLine(const char *s) { Put(s); PutEol(); Index: Stream.h =================================================================== --- Stream.h (revision 1270) +++ Stream.h (working copy) @@ -17,8 +17,6 @@ struct StreamError {}; struct LoadingError : StreamError {}; -enum EOLenum { EOL }; - class Stream { protected: int64 pos; @@ -155,16 +153,8 @@ void Put(const char *s); void Put(int c, int count); void Put0(int count) { Put(0, count); } + void PutEol(); - void PutCrLf() { Put16(MAKEWORD('\r', '\n')); } -#ifdef PLATFORM_WIN32 - void PutEol() { PutCrLf(); } -#else - void PutEol() { Put('\n'); } -#endif - - Stream& operator<<(EOLenum) { PutEol(); return *this; } - void PutLine(const char *s); void PutLine(const String& s); @@ -631,6 +621,16 @@ return s; } +inline Stream& operator<<(Stream& s, EOLenum) +{ +#ifdef PLATFORM_WIN32 + s.Put16(WinEOL); + return s; +#else + return s << LinEOL; +#endif +} + inline Stream& operator<<(Stream& s, const void *x) { s << FormatPtr(x); Index: String.h =================================================================== --- String.h (revision 1270) +++ String.h (working copy) @@ -428,6 +428,16 @@ return s; } +inline String& operator<<(String& s, EOLenum) +{ +#ifdef PLATFORM_WIN32 + s.Cat((char*)&WinEOL, 2); + return s; +#else + return s << LinEOL; +#endif +} + inline String& operator<<(String& s, const void *x) { s << FormatPtr(x); @@ -513,6 +523,16 @@ return s; } +inline StringBuffer& operator<<(StringBuffer& s, EOLenum) +{ +#ifdef PLATFORM_WIN32 + s.Cat((char*)&WinEOL, 2); + return s; +#else + return s << LinEOL; +#endif +} + inline StringBuffer& operator<<(StringBuffer& s, const void *x) { s << FormatPtr(x); Index: t.cpp =================================================================== --- t.cpp (revision 1270) +++ t.cpp (working copy) @@ -302,16 +302,16 @@ void SaveLngFile(FileOut& out, int lang) { CriticalSection::Lock __(slng); - out << "LANGUAGE " << AsCString(LNGAsText(lang)) << ";\r\n"; + out << "LANGUAGE " << AsCString(LNGAsText(lang)) << ";" << EOL; Array& ma = sMod(); for(int i = 0; i < ma.GetCount(); i++) { LngModule& m = ma[i]; - out << "// " << m.name << "\r\n"; + out << "// " << m.name << EOL; for(int j = 0; j < m.map.GetCount(); j++) { String id = m.map.GetKey(j).s; - out << AsCString(id, 70) << ",\r\n" + out << AsCString(id, 70) << "," << EOL << "\t" << AsCString(GetLngString_(lang, id), 60, "\t", ASCSTRING_SMART) - << ";\r\n\r\n"; + << ";" << EOL << EOL; } } } Index: Util.cpp =================================================================== --- Util.cpp (revision 1270) +++ Util.cpp (working copy) @@ -46,7 +46,7 @@ PanicMode = true; LOG(msg); LOG(GetLastErrorMessage()); - BugLog() << "PANIC: " << msg << "\n"; + BugLog() << "PANIC: " << msg << EOL; UsrLogT("===== PANIC ================================================"); UsrLogT(msg); PanicMessageBox("Fatal error", msg); @@ -87,12 +87,12 @@ return; PanicMode = true; char s[2048]; - sprintf(s, "Assertion failed in %s, line %d\n%s\n", file, line, cond); + sprintf(s, "Assertion failed in %s, line %d" EOL_STR "%s" EOL_STR, file, line, cond); LOG(s); LOG(GetLastErrorMessage()); if(s_assert_hook) (*s_assert_hook)(s); - BugLog() << "ASSERT FAILED: " << s << "\n"; + BugLog() << "ASSERT FAILED: " << s << EOL; UsrLogT("===== ASSERT FAILED ================================================"); UsrLogT(s); Index: XML.cpp =================================================================== --- XML.cpp (revision 1270) +++ XML.cpp (working copy) @@ -25,21 +25,21 @@ { StringBuffer r; r << "\n"; + << standalone << "\" ?>" << EOL; return r; } String XmlPI(const char *text) { StringBuffer r; - r << "\n"; + r << "" << EOL; return r; } String XmlDecl(const char *text) { StringBuffer r; - r << "\n"; + r << "" << EOL; return r; } @@ -56,7 +56,7 @@ String XmlComment(const char *text) { StringBuffer out; - out << "\n"; + out << "" << EOL; return out; } @@ -65,13 +65,13 @@ tag.Clear(); end.Clear(); tag << '<' << s; - end << "\n"; + end << "" << EOL; return *this; } String XmlTag::operator()() { - return tag + "/>\n"; + return tag + "/>" << EOL; } String XmlTag::operator()(const char* text) @@ -79,7 +79,7 @@ StringBuffer r; r << tag << '>'; if(strchr(text, '\n')) { - r << '\n'; + r << EOL; bool tab = true; while(*text) { if(tab) @@ -754,13 +754,13 @@ style &= ~(XML_HEADER|XML_DOCTYPE); switch(node.GetType()) { case XML_PI: - r << "\n"; + r << "" << EOL; break; case XML_DECL: - r << "\n"; + r << "" << EOL; break; case XML_COMMENT: - r << "\n"; + r << "" << EOL; break; case XML_DOC: for(int i = 0; i < node.GetCount(); i++)