Fixed unicode reference file writing under some builds.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39352 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Włodzimierz Skiba
2006-05-26 17:27:22 +00:00
parent ed32fb5b21
commit 8715875f72

View File

@@ -23,6 +23,7 @@
#include "wx/app.h" #include "wx/app.h"
#include "wx/hash.h" #include "wx/hash.h"
#include "wx/textfile.h"
#ifdef new #ifdef new
#undef new #undef new
@@ -386,10 +387,13 @@ void AddTexRef(wxChar *name, wxChar *file, wxChar *sectionName,
void WriteTexReferences(wxChar *filename) void WriteTexReferences(wxChar *filename)
{ {
wxString converter;
wxString name = filename; wxString name = filename;
wxSTD ofstream ostr((char const *)name.fn_str()); wxTextFile file;
if (ostr.bad()) return;
if (!(wxFileExists(name)?file.Open(name):file.Create(name)))
return;
file.Clear();
TexReferences.BeginFind(); TexReferences.BeginFind();
wxHashTable::Node *node = TexReferences.Next(); wxHashTable::Node *node = TexReferences.Next();
@@ -397,18 +401,15 @@ void WriteTexReferences(wxChar *filename)
{ {
Tex2RTFYield(); Tex2RTFYield();
TexRef *ref = (TexRef *)node->GetData(); TexRef *ref = (TexRef *)node->GetData();
converter = ref->refLabel; wxString converter = ref->refLabel;
ostr << converter.mb_str(); converter << wxT(" ");
ostr << " "; converter << (ref->refFile ? ref->refFile : _T("??"));
converter = (ref->refFile ? ref->refFile : _T("??")); converter << wxT(" ");
ostr << converter.mb_str(); converter << (ref->sectionName ? ref->sectionName : _T("??")) ;
ostr << " "; converter << wxT(" ");
converter = (ref->sectionName ? ref->sectionName : _T("??")) ; converter << (ref->sectionNumber ? ref->sectionNumber : _T("??")) ;
ostr << converter.mb_str(); file.AddLine(converter);
ostr << " ";
converter = (ref->sectionNumber ? ref->sectionNumber : _T("??")) ;
ostr << converter.mb_str();
ostr << "\n";
if (!ref->sectionNumber || (wxStrcmp(ref->sectionNumber, _T("??")) == 0 && wxStrcmp(ref->sectionName, _T("??")) == 0)) if (!ref->sectionNumber || (wxStrcmp(ref->sectionNumber, _T("??")) == 0 && wxStrcmp(ref->sectionName, _T("??")) == 0))
{ {
wxChar buf[200]; wxChar buf[200];
@@ -417,46 +418,31 @@ void WriteTexReferences(wxChar *filename)
} }
node = TexReferences.Next(); node = TexReferences.Next();
} }
file.Write();
file.Close();
} }
void ReadTexReferences(wxChar *filename) void ReadTexReferences(wxChar *filename)
{ {
if (!wxFileExists(filename)) wxString name = filename;
if (!wxFileExists(name))
return; return;
wxString name = filename; wxTextFile file;
wxSTD ifstream istr((char const *)name.fn_str(), wxSTD ios::in); if (!file.Open(name))
return;
if (istr.bad()) return; wxString line;
for ( line = file.GetFirstLine(); !file.Eof(); line = file.GetNextLine() )
char label[100];
char file[400];
char section[100];
char sectionName[100];
while (!istr.eof())
{ {
istr >> label; wxString labelStr = line.BeforeFirst(wxT(' '));
if (!istr.eof()) line = line.AfterFirst(wxT(' '));
{ wxString fileStr = line.BeforeFirst(wxT(' '));
istr >> file; line = line.AfterFirst(wxT(' '));
istr >> sectionName; wxString sectionNameStr = line.BeforeFirst(wxT(' '));
char ch; wxString sectionStr = line.AfterFirst(wxT(' '));
istr.get(ch); // Read past space
istr.get(ch);
int i = 0;
while (ch != '\n' && !istr.eof())
{
section[i] = ch;
i ++;
istr.get(ch);
}
section[i] = 0;
wxString label_string = wxString::FromAscii(label);
wxString file_string = wxString::FromAscii(file);
wxString sectionName_string = wxString::FromAscii(sectionName);
wxString section_string = wxString::FromAscii(section);
// gt - needed to trick the hash table "TexReferences" into deleting the key // gt - needed to trick the hash table "TexReferences" into deleting the key
// strings it creates in the Put() function, but not the item that is // strings it creates in the Put() function, but not the item that is
@@ -464,18 +450,17 @@ void ReadTexReferences(wxChar *filename)
// were massive memory leaks // were massive memory leaks
TexReferences.DeleteContents(true); TexReferences.DeleteContents(true);
TexReferences.Put( TexReferences.Put(
label_string.c_str(), labelStr.c_str(),
new TexRef( new TexRef(
label_string.c_str(), labelStr.c_str(),
file_string.c_str(), fileStr.c_str(),
section_string.c_str(), sectionStr.c_str(),
sectionName_string.c_str() sectionNameStr.c_str()
) )
); );
TexReferences.DeleteContents(false); TexReferences.DeleteContents(false);
} }
} }
}
/* /*