X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/08c6402af6c3eb12f3d0d5d37a95904c838f9b60..e1e1272f2020447bc26e10fc2cb2809e0b8eb856:/utils/tex2rtf/src/texutils.cpp?ds=sidebyside diff --git a/utils/tex2rtf/src/texutils.cpp b/utils/tex2rtf/src/texutils.cpp index 35ff57107e..be0c83a28c 100644 --- a/utils/tex2rtf/src/texutils.cpp +++ b/utils/tex2rtf/src/texutils.cpp @@ -24,7 +24,11 @@ #include "wx/wx.h" #endif -#include +#include "wx/hash.h" + +#ifdef new +#undef new +#endif #if wxUSE_IOSTREAMH #include @@ -32,6 +36,7 @@ #else #include #include +using namespace std; #endif #include @@ -146,7 +151,7 @@ void ResetTopicCounter(void) static char *forceTopicName = NULL; -void ForceTopicName(char *name) +void ForceTopicName(const char *name) { if (forceTopicName) delete[] forceTopicName; @@ -378,7 +383,7 @@ void AddTexRef(char *name, char *file, char *sectionName, void WriteTexReferences(char *filename) { - ofstream ostr(filename); + wxSTD ofstream ostr(filename); if (ostr.bad()) return; char buf[200]; @@ -405,7 +410,7 @@ void ReadTexReferences(char *filename) if (!wxFileExists(filename)) return; - ifstream istr(filename, ios::in); + wxSTD ifstream istr(filename, wxSTD ios::in); if (istr.bad()) return; @@ -432,7 +437,14 @@ void ReadTexReferences(char *filename) istr.get(ch); } section[i] = 0; + + // 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 + // created here, as that is destroyed elsewhere. Without doing this, there + // were massive memory leaks + TexReferences.DeleteContents(TRUE); TexReferences.Put(label, new TexRef(label, file, section, sectionName)); + TexReferences.DeleteContents(FALSE); } } } @@ -443,7 +455,7 @@ void ReadTexReferences(char *filename) * */ -void BibEatWhiteSpace(istream& str) +void BibEatWhiteSpace(wxSTD istream& str) { char ch = str.peek(); @@ -471,7 +483,7 @@ void BibEatWhiteSpace(istream& str) } // Read word up to { or , or space -void BibReadWord(istream& istr, char *buffer) +void BibReadWord(wxSTD istream& istr, char *buffer) { int i = 0; buffer[i] = 0; @@ -488,7 +500,7 @@ void BibReadWord(istream& istr, char *buffer) } // Read string (double-quoted or not) to end quote or EOL -void BibReadToEOL(istream& istr, char *buffer) +void BibReadToEOL(wxSTD istream& istr, char *buffer) { int i = 0; buffer[i] = 0; @@ -517,7 +529,7 @@ void BibReadToEOL(istream& istr, char *buffer) } // Read }-terminated value, taking nested braces into account. -void BibReadValue(istream& istr, char *buffer, bool ignoreBraces = TRUE, +void BibReadValue(wxSTD istream& istr, char *buffer, bool ignoreBraces = TRUE, bool quotesMayTerminate = TRUE) { int braceCount = 1; @@ -531,8 +543,9 @@ void BibReadValue(istream& istr, char *buffer, bool ignoreBraces = TRUE, if (i >= 4000) { char buf[100]; - sprintf(buf, "Sorry, value > 4000 chars in bib file at line %ld, terminating.", BibLine); - wxFatalError(buf, "Tex2RTF Fatal Error"); + sprintf(buf, "Sorry, value > 4000 chars in bib file at line %ld.", BibLine); + wxLogError(buf, "Tex2RTF Fatal Error"); + return; } istr.get(ch); @@ -573,7 +586,7 @@ bool ReadBib(char *filename) return FALSE; char buf[300]; - ifstream istr(filename, ios::in); + wxSTD ifstream istr(filename, wxSTD ios::in); if (istr.bad()) return FALSE; BibLine = 1; @@ -1131,7 +1144,7 @@ char *RegisterSetting(char *settingName, char *settingValue, bool interactive) else if (StringMatch(settingName, "authorFontSize", FALSE, TRUE)) StringToInt(settingValue, &authorFont); else if (StringMatch(settingName, "ignoreInput", FALSE, TRUE)) - IgnorableInputFiles.Add(FileNameFromPath(settingValue)); + IgnorableInputFiles.Add(wxFileNameFromPath(settingValue)); else if (StringMatch(settingName, "mirrorMargins", FALSE, TRUE)) mirrorMargins = StringTobool(settingValue); else if (StringMatch(settingName, "runTwice", FALSE, TRUE)) @@ -1170,8 +1183,20 @@ char *RegisterSetting(char *settingName, char *settingValue, bool interactive) htmlWorkshopFiles = StringTobool(settingValue); else if (StringMatch(settingName, "htmlFrameContents", FALSE, TRUE)) htmlFrameContents = StringTobool(settingValue); + else if (StringMatch(settingName, "htmlStylesheet", FALSE, TRUE)) + { + if (htmlStylesheet) delete[] htmlStylesheet; + htmlStylesheet = copystring(settingValue); + } else if (StringMatch(settingName, "upperCaseNames", FALSE, TRUE)) upperCaseNames = StringTobool(settingValue); + else if (StringMatch(settingName, "ignoreBadRefs", FALSE, TRUE)) + ignoreBadRefs = StringTobool(settingValue); + else if (StringMatch(settingName, "htmlFaceName", FALSE, TRUE)) + { + delete[] htmlFaceName; + htmlFaceName = copystring(settingValue); + } else if (StringMatch(settingName, "winHelpTitle", FALSE, TRUE)) { if (winHelpTitle) @@ -1295,7 +1320,7 @@ bool ReadCustomMacros(char *filename) if (!wxFileExists(filename)) return FALSE; - ifstream istr(filename, ios::in); + wxSTD ifstream istr(filename, wxSTD ios::in); if (istr.bad()) return FALSE; @@ -1452,7 +1477,7 @@ char *ParseMultifieldString(char *allFields, int *pos) * */ -ColourTableEntry::ColourTableEntry(char *theName, unsigned int r, unsigned int g, unsigned int b) +ColourTableEntry::ColourTableEntry(const char *theName, unsigned int r, unsigned int g, unsigned int b) { name = copystring(theName); red = r; @@ -1465,7 +1490,7 @@ ColourTableEntry::~ColourTableEntry(void) delete[] name; } -void AddColour(char *theName, unsigned int r, unsigned int g, unsigned int b) +void AddColour(const char *theName, unsigned int r, unsigned int g, unsigned int b) { wxNode *node = ColourTable.Find(theName); if (node) @@ -1556,24 +1581,24 @@ void InitialiseColourTable(void) * The purpose of this is to reduce the number of times wxYield is * called, since under Windows this can slow things down. */ - -static int yieldCount = 0; void Tex2RTFYield(bool force) { #ifdef __WXMSW__ - if (isSync) - return; + static int yieldCount = 0; - if (force) - yieldCount = 0; - if (yieldCount == 0) - { - if (wxTheApp) - wxYield(); - yieldCount = 10; - } - yieldCount --; + if (isSync) + return; + + if (force) + yieldCount = 0; + if (yieldCount == 0) + { + if (wxTheApp) + wxYield(); + yieldCount = 10; + } + yieldCount --; #endif } @@ -1647,3 +1672,25 @@ char *ConvertCase(char *s) buf[i] = 0; return buf; } + +#if !WXWIN_COMPATIBILITY_2 +// if substring is TRUE, search for str1 in str2 +bool StringMatch(const wxChar *str1, const wxChar *str2, bool subString, + bool exact) +{ + if (subString) + { + wxString Sstr1(str1); + wxString Sstr2(str2); + if (!exact) + { + Sstr1.MakeUpper(); + Sstr2.MakeUpper(); + } + return Sstr2.Index(Sstr1) != wxNOT_FOUND; + } + else + return exact ? wxString(str2).Cmp(str1) == 0 : + wxString(str2).CmpNoCase(str1) == 0; +} +#endif