X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/eb7aa89b04707bc5334f78f5ab357fe96866e476..92209a39661334baa1552f50cdbf9698053c34de:/utils/tex2rtf/src/texutils.cpp diff --git a/utils/tex2rtf/src/texutils.cpp b/utils/tex2rtf/src/texutils.cpp index ea888383fe..7aec24bfc4 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 @@ -146,7 +150,7 @@ void ResetTopicCounter(void) static char *forceTopicName = NULL; -void ForceTopicName(char *name) +void ForceTopicName(const char *name) { if (forceTopicName) delete[] forceTopicName; @@ -239,9 +243,9 @@ int ParseUnitArgument(char *unitArg) if (strcmp(units, "in") == 0) conversionFactor = 72.0; else if (strcmp(units, "cm") == 0) - conversionFactor = 72.0/2.51; + conversionFactor = (float)72.0/(float)2.51; else if (strcmp(units, "mm") == 0) - conversionFactor = 72.0/25.1; + conversionFactor = (float)72.0/(float)25.1; else if (strcmp(units, "pt") == 0) conversionFactor = 1; } @@ -378,7 +382,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]; @@ -402,11 +406,11 @@ void WriteTexReferences(char *filename) void ReadTexReferences(char *filename) { -#if !wxUSE_IOSTREAMH && __WXMSW__ - ifstream istr(filename, ios::in); -#else - ifstream istr(filename, ios::nocreate | ios::in); -#endif + if (!wxFileExists(filename)) + return; + + wxSTD ifstream istr(filename, ios::in); + if (istr.bad()) return; char label[100]; @@ -432,7 +436,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 +454,7 @@ void ReadTexReferences(char *filename) * */ -void BibEatWhiteSpace(istream& str) +void BibEatWhiteSpace(wxSTD istream& str) { char ch = str.peek(); @@ -471,7 +482,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 +499,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 +528,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; @@ -528,10 +539,10 @@ void BibReadValue(istream& istr, char *buffer, bool ignoreBraces = TRUE, while (!istr.eof() && !stopping) { // i ++; - if (i >= 2000) + if (i >= 4000) { char buf[100]; - sprintf(buf, "Sorry, value > 2000 chars in bib file at line %ld, terminating.", BibLine); + sprintf(buf, "Sorry, value > 4000 chars in bib file at line %ld, terminating.", BibLine); wxFatalError(buf, "Tex2RTF Fatal Error"); } istr.get(ch); @@ -569,12 +580,11 @@ void BibReadValue(istream& istr, char *buffer, bool ignoreBraces = TRUE, bool ReadBib(char *filename) { + if (!wxFileExists(filename)) + return FALSE; + char buf[300]; -#if !wxUSE_IOSTREAMH && __WXMSW__ - ifstream istr(filename, ios::in); -#else - ifstream istr(filename, ios::nocreate | ios::in); -#endif + wxSTD ifstream istr(filename, ios::in); if (istr.bad()) return FALSE; BibLine = 1; @@ -582,7 +592,7 @@ bool ReadBib(char *filename) OnInform("Reading .bib file..."); char ch; - char fieldValue[2000]; + char fieldValue[4000]; char recordType[100]; char recordKey[100]; char recordField[100]; @@ -1167,6 +1177,8 @@ char *RegisterSetting(char *settingName, char *settingValue, bool interactive) winHelpContents = StringTobool(settingValue); else if (StringMatch(settingName, "htmlIndex", FALSE, TRUE)) htmlIndex = StringTobool(settingValue); + else if (StringMatch(settingName, "htmlWorkshopFiles", FALSE, TRUE)) + htmlWorkshopFiles = StringTobool(settingValue); else if (StringMatch(settingName, "htmlFrameContents", FALSE, TRUE)) htmlFrameContents = StringTobool(settingValue); else if (StringMatch(settingName, "upperCaseNames", FALSE, TRUE)) @@ -1291,11 +1303,11 @@ char *RegisterSetting(char *settingName, char *settingValue, bool interactive) bool ReadCustomMacros(char *filename) { -#if !wxUSE_IOSTREAMH && __WXMSW__ - ifstream istr(filename, ios::in); -#else - ifstream istr(filename, ios::nocreate | ios::in); -#endif + if (!wxFileExists(filename)) + return FALSE; + + wxSTD ifstream istr(filename, ios::in); + if (istr.bad()) return FALSE; CustomMacroList.Clear(); @@ -1451,7 +1463,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; @@ -1464,7 +1476,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) @@ -1568,7 +1580,8 @@ void Tex2RTFYield(bool force) yieldCount = 0; if (yieldCount == 0) { - wxYield(); + if (wxTheApp) + wxYield(); yieldCount = 10; } yieldCount --; @@ -1638,10 +1651,10 @@ char *ConvertCase(char *s) int i; if (upperCaseNames) for (i = 0; i < len; i ++) - buf[i] = wxToUpper(s[i]); + buf[i] = toupper(s[i]); else for (i = 0; i < len; i ++) - buf[i] = wxToLower(s[i]); + buf[i] = tolower(s[i]); buf[i] = 0; return buf; }