#include "tex2rtf.h"
#include "table.h"
+
+extern wxHashTable TexReferences;
+
+
extern void DecToHex(int, char *);
void GenerateHTMLIndexFile(char *fname);
extern char *RTFCharset;
// This is defined in the Tex2Any library and isn't in use after parsing
extern char *BigBuffer;
+
+
+extern wxHashTable TexReferences;
+
+
// Are we in verbatim mode? If so, format differently.
static bool inVerbatim = FALSE;
// Convert points to TWIPS (1 twip = 1/20th of point)
imageWidth = (int)(20*(tok1 ? ParseUnitArgument(tok1) : 0));
imageHeight = (int)(20*(tok2 ? ParseUnitArgument(tok2) : 0));
+ if (imageDimensions) // glt
+ delete [] imageDimensions;
return FALSE;
}
else if (start && (arg_no == 2 ))
sprintf(buf, "Warning: could not find a BMP or WMF equivalent for %s.", filename);
OnInform(buf);
}
+ if (filename) // glt
+ delete [] filename;
}
else // linear RTF
{
{
wxConcatFiles("header.rtf", "chapters.rtf", "tmp1.rtf");
Tex2RTFYield(TRUE);
- if (FileExists(OutputFile)) wxRemoveFile(OutputFile);
- wxString cwdStr, outputDirStr;
+ if (FileExists(OutputFile))
+ wxRemoveFile(OutputFile);
+
+ char *cwdStr;
cwdStr = wxGetWorkingDirectory();
+
+ wxString outputDirStr;
outputDirStr = wxPathOnly(OutputFile);
+
// Determine if the temp file and the output file are in the same directory,
// and if they are, then just rename the temp file rather than copying
// it, as this is much faster when working with large (multi-megabyte files)
- if ((wxStrcmp(wxPathOnly(OutputFile),"") == 0) || // no path specified on output file
- (wxStrcmp(wxGetWorkingDirectory(),wxPathOnly(OutputFile)) == 0)) // paths do not match
+ if ((wxStrcmp(outputDirStr.c_str(),"") == 0) || // no path specified on output file
+ (wxStrcmp(cwdStr,outputDirStr.c_str()) == 0)) // paths do not match
{
wxRenameFile("tmp1.rtf", OutputFile);
}
{
wxCopyFile("tmp1.rtf", OutputFile);
}
+ delete [] cwdStr;
Tex2RTFYield(TRUE);
wxRemoveFile("tmp1.rtf");
}
bool combineSubSections = FALSE;
bool htmlWorkshopFiles = FALSE;
+extern int passNumber;
+
+extern wxHashTable TexReferences;
+
/*
* International support
*/
#define IncrementLineNumber() LineNumbers[CurrentInputIndex] ++
+
+TexRef::TexRef(char *label, char *file, char *section, char *sectionN)
+{
+ refLabel = copystring(label);
+ refFile = file ? copystring(file) : (char*) NULL;
+ sectionNumber = section ? copystring(section) : copystring("??");
+ sectionName = sectionN ? copystring(sectionN) : copystring("??");
+}
+
+TexRef::~TexRef(void)
+{
+ delete [] refLabel; refLabel = NULL;
+ delete [] refFile; refFile = NULL;
+ delete [] sectionNumber; sectionNumber = NULL;
+ delete [] sectionName; sectionName = NULL;
+}
+
+
+CustomMacro::~CustomMacro()
+{
+ if (macroName)
+ delete [] macroName;
+ if (macroBody)
+ delete [] macroBody;
+}
+
void TexOutput(char *s, bool ordinaryText)
{
int len = strlen(s);
// Switched this off because e.g. \verb${$ causes it to fail. There is no
// detection of \verb yet.
-#define CHECK_BRACES 0
+#define CHECK_BRACES 1
unsigned long leftCurly = 0;
unsigned long rightCurly = 0;
if (rightCurly > leftCurly)
{
wxString errBuf;
- errBuf.Printf("An extra right Curly brace ('}') was detected at line %l inside file %s",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
+ errBuf.Printf("An extra right Curly brace ('}') was detected at line %lu inside file %s",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
OnError((char *)errBuf.c_str());
// Reduce the count of right curly braces, so the mismatched count
bool TexLoadFile(char *filename)
{
+ static char *line_buffer;
stopRunning = FALSE;
strcpy(TexFileRoot, filename);
StripExtension(TexFileRoot);
TexPathList.EnsureFileAccessible(filename);
+ if (line_buffer)
+ delete line_buffer;
#ifdef __WXMSW__
- static char *line_buffer = new char[600];
+ line_buffer = new char[600];
#else
- static char *line_buffer = new char[11000];
+ line_buffer = new char[11000];
#endif
Inputs[0] = fopen(filename, "r");
BibliographyStyleString = copystring("plain");
DocumentStyleString = copystring("report");
MinorDocumentStyleString = NULL;
-/* Don't want to remove custom macros after each pass.
- SetFontSizes(10);
- wxNode *node = CustomMacroList.First();
- while (node)
- {
- CustomMacro *macro = (CustomMacro *)node->Data();
- delete macro;
- delete node;
- node = CustomMacroList.First();
+
+ // gt - Changed this so if this is the final pass
+ // then we DO want to remove these macros, so that
+ // memory is not MASSIVELY leaked if the user
+ // does not exit the program, but instead runs
+ // the program again
+ if ((passNumber == 1 && !runTwice) ||
+ (passNumber == 2 && runTwice))
+ {
+/* Don't want to remove custom macros after each pass.*/
+ SetFontSizes(10);
+ wxNode *node = CustomMacroList.First();
+ while (node)
+ {
+ CustomMacro *macro = (CustomMacro *)node->Data();
+ delete macro;
+ delete node;
+ node = CustomMacroList.First();
+ }
}
-*/
+/**/
TexReferences.BeginFind();
wxNode *node = TexReferences.Next();
while (node)
char *refFile; // Reference filename (can be NULL)
char *sectionNumber; // Section or figure number (as a string)
char *sectionName; // name e.g. 'section'
- TexRef(char *label, char *file, char *section, char *sectionN = NULL)
- {
- refLabel = copystring(label);
- refFile = file ? copystring(file) : (char*) NULL;
- sectionNumber = section ? copystring(section) : copystring("??");
- sectionName = sectionN ? copystring(sectionN) : copystring("??");
- }
- ~TexRef(void)
- {
- delete[] refLabel; delete[] refFile; delete[] sectionNumber; delete[] sectionName;
- }
+ TexRef(char *label, char *file, char *section, char *sectionN = NULL);
+ ~TexRef(void);
};
-extern wxHashTable TexReferences;
-
/*
* Add a reference
*
else
macroBody = NULL;
}
+ ~CustomMacro();
};
bool ReadCustomMacros(char *filename);
extern char *TexTmpBibName; // Temporary bibliography output file name
extern wxList ColourTable;
extern TexChunk *TopLevel;
+extern char *PageStyle;
+extern char *BibliographyStyleString;
+extern char *DocumentStyleString;
+extern char *bitmapMethod;
+extern char *backgroundColourString;
+extern char *ContentsNameString;
+extern char *AbstractNameString;
+extern char *GlossaryNameString;
+extern char *ReferencesNameString;
+extern char *FiguresNameString;
+extern char *TablesNameString;
+extern char *FigureNameString;
+extern char *TableNameString;
+extern char *IndexNameString;
+extern char *ChapterNameString;
+extern char *SectionNameString;
+extern char *SubsectionNameString;
+extern char *SubsubsectionNameString;
+extern char *UpNameString;
+
+
#if wxUSE_HELP
wxHelpController *HelpInstance = NULL;
ReadCustomMacros((char*) (const char*) path);
Go();
- if (runTwice) Go();
+ if (runTwice)
+ {
+ Go();
+ }
#ifdef NO_GUI
return 0;
#else
RTFCharset = NULL;
}
+ delete [] PageStyle;
+ delete [] BibliographyStyleString;
+ delete [] DocumentStyleString;
+ delete [] bitmapMethod;
+ delete [] backgroundColourString;
+ delete [] ContentsNameString;
+ delete [] AbstractNameString;
+ delete [] GlossaryNameString;
+ delete [] ReferencesNameString;
+ delete [] FiguresNameString;
+ delete [] TablesNameString;
+ delete [] FigureNameString;
+ delete [] TableNameString;
+ delete [] IndexNameString;
+ delete [] ChapterNameString;
+ delete [] SectionNameString;
+ delete [] SubsectionNameString;
+ delete [] SubsubsectionNameString;
+ delete [] UpNameString;
+ if (winHelpTitle)
+ delete[] winHelpTitle;
+
// TODO: this simulates zero-memory leaks!
// Otherwise there are just too many...
#ifndef __WXGTK__
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);
}
}
}
wxList hyperLabels(wxKEY_STRING);
FILE *Index = NULL;
+
+extern wxHashTable TexReferences;
+
+
void PadToTab(int tabPos)
{
int currentCol = GetCurrentColumn();