X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d9ade1df2f02bbb86987487ae35f0eaa0eee4517..f20e3df6d3a2c69d2941dddd4e815d4ceea29abe:/src/common/textfile.cpp diff --git a/src/common/textfile.cpp b/src/common/textfile.cpp index 6a82fa5860..8a47c35e39 100644 --- a/src/common/textfile.cpp +++ b/src/common/textfile.cpp @@ -6,17 +6,13 @@ // Created: 03.04.98 // RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin -// Licence: wxWindows license +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ // headers // ============================================================================ -#ifdef __GNUG__ - #pragma implementation "textfile.h" -#endif - #include "wx/wxprec.h" #ifdef __BORLANDC__ @@ -97,30 +93,30 @@ bool wxTextFile::OnRead(wxMBConv& conv) char *strBuf, *strPtr, *strEnd; char ch, chLast = '\0'; char buf[1024]; - int n, nRead; + size_t nRead; strPtr = strBuf = new char[1024]; strEnd = strBuf + 1024; - do + do { nRead = m_file.Read(buf, WXSIZEOF(buf)); - if ( nRead == wxInvalidOffset ) + if ( nRead == (size_t)wxInvalidOffset ) { // read error (error message already given in wxFile::Read) delete[] strBuf; - return FALSE; + return false; } - for (n = 0; n < nRead; n++) + for (size_t n = 0; n < nRead; n++) { ch = buf[n]; - switch ( ch ) + switch ( ch ) { case '\n': // Dos/Unix line termination *strPtr = '\0'; - AddLine(wxString(strBuf, conv), + AddLine(wxString(strBuf, conv), chLast == '\r' ? wxTextFileType_Dos : wxTextFileType_Unix); strPtr = strBuf; @@ -128,7 +124,7 @@ bool wxTextFile::OnRead(wxMBConv& conv) break; case '\r': - if ( chLast == '\r' ) + if ( chLast == '\r' ) { // Mac empty line AddLine(wxEmptyString, wxTextFileType_Mac); @@ -147,7 +143,7 @@ bool wxTextFile::OnRead(wxMBConv& conv) strPtr = strBuf; *(strPtr++) = ch; } - else + else { // add to the current line *(strPtr++) = ch; @@ -168,29 +164,33 @@ bool wxTextFile::OnRead(wxMBConv& conv) } while ( nRead == WXSIZEOF(buf) ); // anything in the last line? - if ( strPtr != strBuf ) + if ( strPtr != strBuf ) { *strPtr = '\0'; - AddLine(wxString(strBuf, conv), + AddLine(wxString(strBuf, conv), wxTextFileType_None); // no line terminator } delete[] strBuf; - return TRUE; + return true; } bool wxTextFile::OnWrite(wxTextFileType typeNew, wxMBConv& conv) { wxFileName fn = m_strBufferName; + + // We do NOT want wxPATH_NORM_CASE here, or the case will not + // be preserved. if ( !fn.IsAbsolute() ) - fn.Normalize(); + fn.Normalize(wxPATH_NORM_ENV_VARS | wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | + wxPATH_NORM_ABSOLUTE | wxPATH_NORM_LONG); wxTempFile fileTmp(fn.GetFullPath()); if ( !fileTmp.IsOpened() ) { wxLogError(_("can't write buffer '%s' to disk."), m_strBufferName.c_str()); - return FALSE; + return false; } size_t nCount = GetLineCount();