backported Unicode compilation fixes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@19211 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-02-13 21:31:54 +00:00
parent c950107aa8
commit cd8b84f98e

View File

@@ -41,6 +41,7 @@
#include "wx/filedlg.h" #include "wx/filedlg.h"
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/log.h" #include "wx/log.h"
#include "wx/ffile.h"
#endif #endif
@@ -295,7 +296,7 @@ bool wxDocument::OnSaveDocument(const wxString& file)
msgTitle = wxString(_("File error")); msgTitle = wxString(_("File error"));
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
wxSTD ofstream store(wxString(file.fn_str()).mb_str()); // ????? wxSTD ofstream store(file.mb_str());
if (store.fail() || store.bad()) if (store.fail() || store.bad())
#else #else
wxFileOutputStream store(file); wxFileOutputStream store(file);
@@ -332,7 +333,7 @@ bool wxDocument::OnOpenDocument(const wxString& file)
msgTitle = wxString(_("File error")); msgTitle = wxString(_("File error"));
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
wxSTD ifstream store(wxString(file.fn_str()).mb_str()); // ???? wxSTD ifstream store(file.mb_str());
if (store.fail() || store.bad()) if (store.fail() || store.bad())
#else #else
wxFileInputStream store(file); wxFileInputStream store(file);
@@ -2163,77 +2164,99 @@ void wxFileHistory::AddFilesToMenu(wxMenu* menu)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if wxUSE_STD_IOSTREAM #if wxUSE_STD_IOSTREAM
bool wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream) bool wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream)
{ {
FILE *fd1; wxFFile file(filename, "rb");
int ch; if ( !file.IsOpened() )
if ((fd1 = wxFopen (filename.fn_str(), _T("rb"))) == NULL)
return FALSE; return FALSE;
while ((ch = getc (fd1)) != EOF) char buf[4096];
stream << (unsigned char)ch;
size_t nRead;
do
{
nRead = file.Read(buf, WXSIZEOF(buf));
if ( file.Error() )
return FALSE;
stream.write(buf, nRead);
if ( !stream )
return FALSE;
}
while ( !file.Eof() );
fclose (fd1);
return TRUE; return TRUE;
} }
bool wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename) bool wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename)
{ {
FILE *fd1; wxFFile file(filename, "wb");
int ch; if ( !file.IsOpened() )
return FALSE;
if ((fd1 = wxFopen (filename.fn_str(), _T("wb"))) == NULL) char buf[4096];
do
{ {
stream.read(buf, WXSIZEOF(buf));
if ( !stream.bad() ) // fail may be set on EOF, don't use operator!()
{
if ( !file.Write(buf, stream.gcount()) )
return FALSE; return FALSE;
} }
while (!stream.eof())
{
ch = stream.get();
if (!stream.eof())
putc (ch, fd1);
} }
fclose (fd1); while ( !stream.eof() );
return TRUE; return TRUE;
} }
#else
#else // !wxUSE_STD_IOSTREAM
bool wxTransferFileToStream(const wxString& filename, wxOutputStream& stream) bool wxTransferFileToStream(const wxString& filename, wxOutputStream& stream)
{ {
FILE *fd1; wxFFile file(filename, "rb");
int ch; if ( !file.IsOpened() )
if ((fd1 = wxFopen (filename, wxT("rb"))) == NULL)
return FALSE; return FALSE;
while ((ch = getc (fd1)) != EOF) char buf[4096];
stream.PutC((char) ch);
size_t nRead;
do
{
nRead = file.Read(buf, WXSIZEOF(buf));
if ( file.Error() )
return FALSE;
stream.Write(buf, nRead);
if ( !stream )
return FALSE;
}
while ( !file.Eof() );
fclose (fd1);
return TRUE; return TRUE;
} }
bool wxTransferStreamToFile(wxInputStream& stream, const wxString& filename) bool wxTransferStreamToFile(wxInputStream& stream, const wxString& filename)
{ {
FILE *fd1; wxFFile file(filename, "wb");
char ch; if ( !file.IsOpened() )
return FALSE;
if ((fd1 = wxFopen (filename, wxT("wb"))) == NULL) char buf[4096];
do
{ {
stream.Read(buf, WXSIZEOF(buf));
const size_t nRead = stream.LastRead();
if ( !nRead || !file.Write(buf, nRead) )
return FALSE; return FALSE;
} }
while ( !stream.Eof() );
int len = stream.GetSize();
// TODO: is this the correct test for EOF?
while (stream.TellI() < (len - 1))
{
ch = stream.GetC();
putc (ch, fd1);
}
fclose (fd1);
return TRUE; return TRUE;
} }
#endif
#endif // wxUSE_STD_IOSTREAM/!wxUSE_STD_IOSTREAM
#endif // wxUSE_DOC_VIEW_ARCHITECTURE #endif // wxUSE_DOC_VIEW_ARCHITECTURE