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:
parent
ed32fb5b21
commit
8715875f72
@ -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,95 +387,79 @@ void AddTexRef(wxChar *name, wxChar *file, wxChar *sectionName,
|
|||||||
|
|
||||||
void WriteTexReferences(wxChar *filename)
|
void WriteTexReferences(wxChar *filename)
|
||||||
{
|
{
|
||||||
wxString converter;
|
wxString name = filename;
|
||||||
wxString name = filename;
|
wxTextFile file;
|
||||||
wxSTD ofstream ostr((char const *)name.fn_str());
|
|
||||||
if (ostr.bad()) return;
|
|
||||||
|
|
||||||
TexReferences.BeginFind();
|
if (!(wxFileExists(name)?file.Open(name):file.Create(name)))
|
||||||
wxHashTable::Node *node = TexReferences.Next();
|
return;
|
||||||
while (node)
|
|
||||||
{
|
file.Clear();
|
||||||
Tex2RTFYield();
|
|
||||||
TexRef *ref = (TexRef *)node->GetData();
|
TexReferences.BeginFind();
|
||||||
converter = ref->refLabel;
|
wxHashTable::Node *node = TexReferences.Next();
|
||||||
ostr << converter.mb_str();
|
while (node)
|
||||||
ostr << " ";
|
|
||||||
converter = (ref->refFile ? ref->refFile : _T("??"));
|
|
||||||
ostr << converter.mb_str();
|
|
||||||
ostr << " ";
|
|
||||||
converter = (ref->sectionName ? ref->sectionName : _T("??")) ;
|
|
||||||
ostr << converter.mb_str();
|
|
||||||
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))
|
|
||||||
{
|
{
|
||||||
wxChar buf[200];
|
Tex2RTFYield();
|
||||||
wxSnprintf(buf, sizeof(buf), _T("Warning: reference %s not resolved."), ref->refLabel);
|
TexRef *ref = (TexRef *)node->GetData();
|
||||||
OnInform(buf);
|
wxString converter = ref->refLabel;
|
||||||
|
converter << wxT(" ");
|
||||||
|
converter << (ref->refFile ? ref->refFile : _T("??"));
|
||||||
|
converter << wxT(" ");
|
||||||
|
converter << (ref->sectionName ? ref->sectionName : _T("??")) ;
|
||||||
|
converter << wxT(" ");
|
||||||
|
converter << (ref->sectionNumber ? ref->sectionNumber : _T("??")) ;
|
||||||
|
file.AddLine(converter);
|
||||||
|
|
||||||
|
if (!ref->sectionNumber || (wxStrcmp(ref->sectionNumber, _T("??")) == 0 && wxStrcmp(ref->sectionName, _T("??")) == 0))
|
||||||
|
{
|
||||||
|
wxChar buf[200];
|
||||||
|
wxSnprintf(buf, sizeof(buf), _T("Warning: reference %s not resolved."), ref->refLabel);
|
||||||
|
OnInform(buf);
|
||||||
|
}
|
||||||
|
node = TexReferences.Next();
|
||||||
}
|
}
|
||||||
node = TexReferences.Next();
|
|
||||||
}
|
file.Write();
|
||||||
|
file.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadTexReferences(wxChar *filename)
|
void ReadTexReferences(wxChar *filename)
|
||||||
{
|
{
|
||||||
if (!wxFileExists(filename))
|
wxString name = filename;
|
||||||
return;
|
|
||||||
|
|
||||||
wxString name = filename;
|
if (!wxFileExists(name))
|
||||||
wxSTD ifstream istr((char const *)name.fn_str(), wxSTD ios::in);
|
return;
|
||||||
|
|
||||||
if (istr.bad()) return;
|
wxTextFile file;
|
||||||
|
if (!file.Open(name))
|
||||||
|
return;
|
||||||
|
|
||||||
char label[100];
|
wxString line;
|
||||||
char file[400];
|
for ( line = file.GetFirstLine(); !file.Eof(); line = file.GetNextLine() )
|
||||||
char section[100];
|
|
||||||
char sectionName[100];
|
|
||||||
|
|
||||||
while (!istr.eof())
|
|
||||||
{
|
|
||||||
istr >> label;
|
|
||||||
if (!istr.eof())
|
|
||||||
{
|
{
|
||||||
istr >> file;
|
wxString labelStr = line.BeforeFirst(wxT(' '));
|
||||||
istr >> sectionName;
|
line = line.AfterFirst(wxT(' '));
|
||||||
char ch;
|
wxString fileStr = line.BeforeFirst(wxT(' '));
|
||||||
istr.get(ch); // Read past space
|
line = line.AfterFirst(wxT(' '));
|
||||||
istr.get(ch);
|
wxString sectionNameStr = line.BeforeFirst(wxT(' '));
|
||||||
int i = 0;
|
wxString sectionStr = line.AfterFirst(wxT(' '));
|
||||||
while (ch != '\n' && !istr.eof())
|
|
||||||
{
|
|
||||||
section[i] = ch;
|
|
||||||
i ++;
|
|
||||||
istr.get(ch);
|
|
||||||
}
|
|
||||||
section[i] = 0;
|
|
||||||
|
|
||||||
wxString label_string = wxString::FromAscii(label);
|
// gt - needed to trick the hash table "TexReferences" into deleting the key
|
||||||
wxString file_string = wxString::FromAscii(file);
|
// strings it creates in the Put() function, but not the item that is
|
||||||
wxString sectionName_string = wxString::FromAscii(sectionName);
|
// created here, as that is destroyed elsewhere. Without doing this, there
|
||||||
wxString section_string = wxString::FromAscii(section);
|
// were massive memory leaks
|
||||||
|
TexReferences.DeleteContents(true);
|
||||||
// gt - needed to trick the hash table "TexReferences" into deleting the key
|
TexReferences.Put(
|
||||||
// strings it creates in the Put() function, but not the item that is
|
labelStr.c_str(),
|
||||||
// created here, as that is destroyed elsewhere. Without doing this, there
|
new TexRef(
|
||||||
// were massive memory leaks
|
labelStr.c_str(),
|
||||||
TexReferences.DeleteContents(true);
|
fileStr.c_str(),
|
||||||
TexReferences.Put(
|
sectionStr.c_str(),
|
||||||
label_string.c_str(),
|
sectionNameStr.c_str()
|
||||||
new TexRef(
|
)
|
||||||
label_string.c_str(),
|
);
|
||||||
file_string.c_str(),
|
TexReferences.DeleteContents(false);
|
||||||
section_string.c_str(),
|
|
||||||
sectionName_string.c_str()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
TexReferences.DeleteContents(false);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user