// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#include "wx/app.h"
#include "wx/hash.h"
+#include "wx/textfile.h"
#ifdef new
#undef new
#include <ctype.h>
#include "tex2any.h"
-#if !WXWIN_COMPATIBILITY_2_4
static inline wxChar* copystring(const wxChar* s)
{ return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
-static inline void StringToInt (const wxChar *s, int *number)
-{
- if (s && *s && number)
- *number = (int) wxStrtol (s, (wxChar **) NULL, 10);
-}
-#endif
wxHashTable TexReferences(wxKEY_STRING);
wxList BibList(wxKEY_STRING);
*
*/
-void StartSimulateArgument(wxChar *data)
+void StartSimulateArgument(const wxChar *data)
{
wxStrcpy(currentArgData, data);
haveArgData = true;
*
*/
-int ParseUnitArgument(wxChar *unitArg)
+int ParseUnitArgument(const wxChar *unitArg_)
{
+ wxWxCharBuffer unitBuf(unitArg_);
+ wxChar *unitArg = unitBuf.data();
+
float conversionFactor = 1.0;
float unitValue = 0.0;
int len = wxStrlen(unitArg);
void WriteTexReferences(wxChar *filename)
{
- wxString converter;
- wxString name = filename;
- wxSTD ofstream ostr((char const *)name.fn_str());
- if (ostr.bad()) return;
+ wxString name = filename;
+ wxTextFile file;
- TexReferences.BeginFind();
- wxHashTable::Node *node = TexReferences.Next();
- while (node)
- {
- Tex2RTFYield();
- TexRef *ref = (TexRef *)node->GetData();
- converter = ref->refLabel;
- ostr << converter.mb_str();
- 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];
- wxSnprintf(buf, sizeof(buf), _T("Warning: reference %s not resolved."), ref->refLabel);
- OnInform(buf);
+ if (!(wxFileExists(name)?file.Open(name):file.Create(name)))
+ return;
+
+ file.Clear();
+
+ TexReferences.BeginFind();
+ wxHashTable::Node *node = TexReferences.Next();
+ while (node)
+ {
+ Tex2RTFYield();
+ TexRef *ref = (TexRef *)node->GetData();
+ 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)
{
- if (!wxFileExists(filename))
- return;
+ wxString name = filename;
- wxString name = filename;
- wxSTD ifstream istr((char const *)name.fn_str(), wxSTD ios::in);
-
- if (istr.bad()) return;
+ if (!wxFileExists(name))
+ return;
- char label[100];
- char file[400];
- char section[100];
- char sectionName[100];
+ wxTextFile file;
+ if (!file.Open(name))
+ return;
- while (!istr.eof())
- {
- istr >> label;
- if (!istr.eof())
+ wxString line;
+ for ( line = file.GetFirstLine(); !file.Eof(); line = file.GetNextLine() )
{
- istr >> file;
- istr >> sectionName;
- char ch;
- 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
- // 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_string.c_str(),
- new TexRef(
- label_string.c_str(),
- file_string.c_str(),
- section_string.c_str(),
- sectionName_string.c_str()
- )
- );
- TexReferences.DeleteContents(false);
+ wxString labelStr = line.BeforeFirst(wxT(' '));
+ line = line.AfterFirst(wxT(' '));
+ wxString fileStr = line.BeforeFirst(wxT(' '));
+ line = line.AfterFirst(wxT(' '));
+ wxString sectionNameStr = line.BeforeFirst(wxT(' '));
+ wxString sectionStr = line.AfterFirst(wxT(' '));
+
+ // 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(
+ labelStr,
+ new TexRef(
+ labelStr.c_str(),
+ fileStr.c_str(),
+ sectionStr.c_str(),
+ sectionNameStr.c_str()
+ )
+ );
+ TexReferences.DeleteContents(false);
}
- }
}
*
*/
+void BibEatWhiteSpace(wxString& line)
+{
+ while(!line.empty() && (line[0] == _T(' ') || line[0] == _T('\t') || line[0] == (wxChar)EOF))
+ {
+ if (line[0] == '\r')
+ BibLine ++;
+ line = line.substr(1);
+ }
+
+ // Ignore end-of-line comments
+ if ( !line.empty() && (line[0] == _T('%') || line[0] == _T(';') || line[0] == _T('#')))
+ {
+ line.clear();
+ }
+}
+
void BibEatWhiteSpace(wxSTD istream& str)
{
char ch = (char)str.peek();
}
// Read word up to { or , or space
+wxString BibReadWord(wxString& line)
+{
+ wxString val;
+
+ while (!line.empty() &&
+ line[0] != _T('\t') &&
+ line[0] != _T(' ') &&
+ line[0] != _T('{') &&
+ line[0] != _T('(') &&
+ line[0] != _T(',') &&
+ line[0] != _T('='))
+ {
+ val << line[0];
+ line = line.substr(1);
+ }
+ return val;
+}
+
void BibReadWord(wxSTD istream& istr, wxChar *buffer)
{
int i = 0;
}
// Read string (double-quoted or not) to end quote or EOL
-void BibReadToEOL(wxSTD istream& istr, wxChar *buffer)
+wxString BibReadToEOL(wxString& line)
{
- int i = 0;
- buffer[i] = 0;
- char ch = (char)istr.peek();
- bool inQuotes = false;
- if (ch == '"')
- {
- istr.get(ch);
- ch = (char)istr.peek();
- inQuotes = true;
- }
- // If in quotes, read white space too. If not,
- // stop at white space or comment.
- while (!istr.eof() && ch != 13 && ch != 10 && ch != _T('"') &&
- (inQuotes || ((ch != _T(' ')) && (ch != 9) &&
- (ch != _T(';')) && (ch != _T('%')) && (ch != _T('#')))))
- {
- istr.get(ch);
- buffer[i] = ch;
- i ++;
- ch = (char)istr.peek();
- }
- if (ch == '"')
- istr.get(ch);
- buffer[i] = 0;
+ if(line.empty())
+ return wxEmptyString;
+
+ wxString val;
+ bool inQuotes = false;
+ if (line[0] == _T('"'))
+ {
+ line = line.substr(1);
+ inQuotes = true;
+ }
+ // If in quotes, read white space too. If not,
+ // stop at white space or comment.
+ while (!line.empty() && line[0] != _T('"') &&
+ (inQuotes || ((line[0] != _T(' ')) && (line[0] != '\t') &&
+ (line[0] != _T(';')) && (line[0] != _T('%')) && (line[0] != _T('#')))))
+ {
+ val << line[0];
+ line = line.substr(1);
+ }
+ if (!line.empty() && line[0] == '"')
+ line = line.substr(1);
+
+ return val;
}
-// Read }-terminated value, taking nested braces into account.
-void BibReadValue(wxSTD istream& istr, wxChar *buffer, bool ignoreBraces = true,
- bool quotesMayTerminate = true)
+void BibReadToEOL(wxSTD istream& istr, wxChar *buffer)
{
- int braceCount = 1;
- int i = 0;
- buffer[i] = 0;
- char ch = (char)istr.peek();
- bool stopping = false;
- while (!istr.eof() && !stopping)
- {
-// i ++;
- if (i >= 4000)
+ int i = 0;
+ buffer[i] = 0;
+ char ch = (char)istr.peek();
+ bool inQuotes = false;
+ if (ch == '"')
{
- wxChar buf[100];
- wxSnprintf(buf, sizeof(buf), _T("Sorry, value > 4000 chars in bib file at line %ld."), BibLine);
- wxLogError(buf, "Tex2RTF Fatal Error");
- return;
+ istr.get(ch);
+ ch = (char)istr.peek();
+ inQuotes = true;
}
- istr.get(ch);
+ // If in quotes, read white space too. If not,
+ // stop at white space or comment.
+ while (!istr.eof() && ch != 13 && ch != 10 && ch != _T('"') &&
+ (inQuotes || ((ch != _T(' ')) && (ch != 9) &&
+ (ch != _T(';')) && (ch != _T('%')) && (ch != _T('#')))))
+ {
+ istr.get(ch);
+ buffer[i] = ch;
+ i ++;
+ ch = (char)istr.peek();
+ }
+ if (ch == '"')
+ istr.get(ch);
+ buffer[i] = 0;
+}
- if (ch == '{')
- braceCount ++;
+// Read }-terminated value, taking nested braces into account.
+wxString BibReadValue(wxString& line,
+ bool ignoreBraces = true,
+ bool quotesMayTerminate = true)
+{
+ wxString val;
+ int braceCount = 1;
+ bool stopping = false;
- if (ch == '}')
+ if (line.length() >= 4000)
{
- braceCount --;
- if (braceCount == 0)
- {
- stopping = true;
- break;
- }
+ wxChar buf[100];
+ wxSnprintf(buf, sizeof(buf), _T("Sorry, value > 4000 chars in bib file at line %ld."), BibLine);
+ wxLogError(buf, "Tex2RTF Fatal Error");
+ return wxEmptyString;
}
- else if (quotesMayTerminate && ch == '"')
+
+ while (!line.empty() && !stopping)
{
- stopping = true;
- break;
+ wxChar ch = line[0];
+ line = line.substr(1);
+
+ if (ch == _T('{'))
+ braceCount ++;
+
+ if (ch == _T('}'))
+ {
+ braceCount --;
+ if (braceCount == 0)
+ {
+ stopping = true;
+ break;
+ }
+ }
+ else if (quotesMayTerminate && ch == _T('"'))
+ {
+ stopping = true;
+ break;
+ }
+
+ if (!stopping)
+ {
+ if (!ignoreBraces || (ch != _T('{') && ch != _T('}')))
+ {
+ val << ch;
+ }
+ }
}
- if (!stopping)
+
+ return val;
+}
+
+void BibReadValue(wxSTD istream& istr, wxChar *buffer, bool ignoreBraces = true,
+ bool quotesMayTerminate = true)
+{
+ int braceCount = 1;
+ int i = 0;
+ buffer[i] = 0;
+ char ch = (char)istr.peek();
+ bool stopping = false;
+ while (!istr.eof() && !stopping)
{
- if (!ignoreBraces || (ch != '{' && ch != '}'))
- {
- buffer[i] = ch;
- i ++;
- }
+// i ++;
+ if (i >= 4000)
+ {
+ wxChar buf[100];
+ wxSnprintf(buf, sizeof(buf), _T("Sorry, value > 4000 chars in bib file at line %ld."), BibLine);
+ wxLogError(buf, "Tex2RTF Fatal Error");
+ return;
+ }
+ istr.get(ch);
+
+ if (ch == '{')
+ braceCount ++;
+
+ if (ch == '}')
+ {
+ braceCount --;
+ if (braceCount == 0)
+ {
+ stopping = true;
+ break;
+ }
+ }
+ else if (quotesMayTerminate && ch == '"')
+ {
+ stopping = true;
+ break;
+ }
+ if (!stopping)
+ {
+ if (!ignoreBraces || (ch != '{' && ch != '}'))
+ {
+ buffer[i] = ch;
+ i ++;
+ }
+ }
+ if (ch == 10)
+ BibLine ++;
}
- if (ch == 10)
- BibLine ++;
- }
- buffer[i] = 0;
- wxUnusedVar(stopping);
+ buffer[i] = 0;
+ wxUnusedVar(stopping);
}
-bool ReadBib(wxChar *filename)
+bool ReadBib(const wxChar *filename)
{
if (!wxFileExists(filename))
return false;
}
// Remember we need to resolve this citation
-void AddCitation(wxChar *citeKey)
+void AddCitation(const wxChar *citeKey)
{
if (!CitationList.Member(citeKey))
CitationList.Add(citeKey);
}
}
-TexRef *FindReference(wxChar *key)
+TexRef *FindReference(const wxChar *key)
{
return (TexRef *)TexReferences.Get(key);
}
*
*/
-bool StringTobool(wxChar *val)
+bool StringTobool(const wxString& val)
{
- if (wxStrncmp(val, _T("yes"), 3) == 0 || wxStrncmp(val, _T("YES"), 3) == 0 ||
- wxStrncmp(val, _T("on"), 2) == 0 || wxStrncmp(val, _T("ON"), 2) == 0 ||
- wxStrncmp(val, _T("true"), 4) == 0 || wxStrncmp(val, _T("true"), 4) == 0 ||
- wxStrncmp(val, _T("ok"), 2) == 0 || wxStrncmp(val, _T("OK"), 2) == 0 ||
- wxStrncmp(val, _T("1"), 1) == 0)
- return true;
- else
+ wxString up(val);
+ up.MakeUpper();
+
+ if (up.IsSameAs(_T("YES")) ||
+ up.IsSameAs(_T("TRUE")) ||
+ up.IsSameAs(_T("ON")) ||
+ up.IsSameAs(_T("OK")) |
+ up.IsSameAs(_T("1")))
+ return true;
+
return false;
}
+void RegisterIntSetting (const wxString& s, int *number)
+{
+ if (number)
+ {
+ long val;
+ s.ToLong(&val);
+ *number = (int)val;
+ }
+}
+
// Define a variable value from the .ini file
-wxChar *RegisterSetting(wxChar *settingName, wxChar *settingValue, bool interactive)
+wxChar *RegisterSetting(const wxString& settingName, const wxString& settingValue, bool interactive)
{
- static wxChar errorCode[100];
- wxStrcpy(errorCode, _T("OK"));
- if (StringMatch(settingName, _T("chapterName"), false, true))
- {
- delete[] ChapterNameString;
- ChapterNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("sectionName"), false, true))
- {
- delete[] SectionNameString;
- SectionNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("subsectionName"), false, true))
- {
- delete[] SubsectionNameString;
- SubsectionNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("subsubsectionName"), false, true))
- {
- delete[] SubsubsectionNameString;
- SubsubsectionNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("indexName"), false, true))
- {
- delete[] IndexNameString;
- IndexNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("contentsName"), false, true))
- {
- delete[] ContentsNameString;
- ContentsNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("glossaryName"), false, true))
- {
- delete[] GlossaryNameString;
- GlossaryNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("referencesName"), false, true))
- {
- delete[] ReferencesNameString;
- ReferencesNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("tablesName"), false, true))
- {
- delete[] TablesNameString;
- TablesNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("figuresName"), false, true))
- {
- delete[] FiguresNameString;
- FiguresNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("tableName"), false, true))
- {
- delete[] TableNameString;
- TableNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("figureName"), false, true))
- {
- delete[] FigureNameString;
- FigureNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("abstractName"), false, true))
- {
- delete[] AbstractNameString;
- AbstractNameString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("chapterFontSize"), false, true))
- StringToInt(settingValue, &chapterFont);
- else if (StringMatch(settingName, _T("sectionFontSize"), false, true))
- StringToInt(settingValue, §ionFont);
- else if (StringMatch(settingName, _T("subsectionFontSize"), false, true))
- StringToInt(settingValue, &subsectionFont);
- else if (StringMatch(settingName, _T("titleFontSize"), false, true))
- StringToInt(settingValue, &titleFont);
- else if (StringMatch(settingName, _T("authorFontSize"), false, true))
- StringToInt(settingValue, &authorFont);
- else if (StringMatch(settingName, _T("ignoreInput"), false, true))
- IgnorableInputFiles.Add(wxFileNameFromPath(settingValue));
- else if (StringMatch(settingName, _T("mirrorMargins"), false, true))
- mirrorMargins = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("runTwice"), false, true))
- runTwice = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("isInteractive"), false, true))
- isInteractive = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("headerRule"), false, true))
- headerRule = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("footerRule"), false, true))
- footerRule = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("combineSubSections"), false, true))
- combineSubSections = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("listLabelIndent"), false, true))
- StringToInt(settingValue, &labelIndentTab);
- else if (StringMatch(settingName, _T("listItemIndent"), false, true))
- StringToInt(settingValue, &itemIndentTab);
- else if (StringMatch(settingName, _T("useUpButton"), false, true))
- useUpButton = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("useHeadingStyles"), false, true))
- useHeadingStyles = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("useWord"), false, true))
- useWord = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("contentsDepth"), false, true))
- StringToInt(settingValue, &contentsDepth);
- else if (StringMatch(settingName, _T("generateHPJ"), false, true))
- generateHPJ = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("truncateFilenames"), false, true))
- truncateFilenames = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("winHelpVersion"), false, true))
- StringToInt(settingValue, &winHelpVersion);
- else if (StringMatch(settingName, _T("winHelpContents"), false, true))
- winHelpContents = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("htmlIndex"), false, true))
- htmlIndex = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("htmlWorkshopFiles"), false, true))
- htmlWorkshopFiles = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("htmlFrameContents"), false, true))
- htmlFrameContents = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("htmlStylesheet"), false, true))
- {
- if (htmlStylesheet) delete[] htmlStylesheet;
- htmlStylesheet = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("upperCaseNames"), false, true))
- upperCaseNames = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("ignoreBadRefs"), false, true))
- ignoreBadRefs = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("htmlFaceName"), false, true))
- {
- delete[] htmlFaceName;
- htmlFaceName = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("winHelpTitle"), false, true))
- {
- if (winHelpTitle)
- delete[] winHelpTitle;
- winHelpTitle = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("indexSubsections"), false, true))
- indexSubsections = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("compatibility"), false, true))
- compatibilityMode = StringTobool(settingValue);
- else if (StringMatch(settingName, _T("defaultColumnWidth"), false, true))
- {
- StringToInt(settingValue, &defaultTableColumnWidth);
- defaultTableColumnWidth = 20*defaultTableColumnWidth;
- }
- else if (StringMatch(settingName, _T("bitmapMethod"), false, true))
- {
- if ((wxStrcmp(settingValue, _T("includepicture")) != 0) && (wxStrcmp(settingValue, _T("hex")) != 0) &&
- (wxStrcmp(settingValue, _T("import")) != 0))
+ wxString settingValueStr( settingValue );
+
+ static wxChar errorCode[100];
+ wxStrcpy(errorCode, _T("OK"));
+ if (StringMatch(settingName, _T("chapterName"), false, true))
{
- if (interactive)
- OnError(_T("Unknown bitmapMethod"));
- wxStrcpy(errorCode, _T("Unknown bitmapMethod"));
+ delete[] ChapterNameString;
+ ChapterNameString = copystring(settingValue);
}
- else
+ else if (StringMatch(settingName, _T("sectionName"), false, true))
{
- delete[] bitmapMethod;
- bitmapMethod = copystring(settingValue);
+ delete[] SectionNameString;
+ SectionNameString = copystring(settingValue);
}
- }
- else if (StringMatch(settingName, _T("htmlBrowseButtons"), false, true))
- {
- if (wxStrcmp(settingValue, _T("none")) == 0)
- htmlBrowseButtons = HTML_BUTTONS_NONE;
- else if (wxStrcmp(settingValue, _T("bitmap")) == 0)
- htmlBrowseButtons = HTML_BUTTONS_BITMAP;
- else if (wxStrcmp(settingValue, _T("text")) == 0)
- htmlBrowseButtons = HTML_BUTTONS_TEXT;
- else
+ else if (StringMatch(settingName, _T("subsectionName"), false, true))
{
- if (interactive)
- OnInform(_T("Initialisation file error: htmlBrowseButtons must be one of none, bitmap, or text."));
- wxStrcpy(errorCode, _T("Initialisation file error: htmlBrowseButtons must be one of none, bitmap, or text."));
+ delete[] SubsectionNameString;
+ SubsectionNameString = copystring(settingValue);
}
- }
- else if (StringMatch(settingName, _T("backgroundImage"), false, true))
- {
- backgroundImageString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("backgroundColour"), false, true))
- {
- delete[] backgroundColourString;
- backgroundColourString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("textColour"), false, true))
- {
- textColourString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("linkColour"), false, true))
- {
- linkColourString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("followedLinkColour"), false, true))
- {
- followedLinkColourString = copystring(settingValue);
- }
- else if (StringMatch(settingName, _T("conversionMode"), false, true))
- {
- if (StringMatch(settingValue, _T("RTF"), false, true))
+ else if (StringMatch(settingName, _T("subsubsectionName"), false, true))
{
- winHelp = false; convertMode = TEX_RTF;
+ delete[] SubsubsectionNameString;
+ SubsubsectionNameString = copystring(settingValue);
}
- else if (StringMatch(settingValue, _T("WinHelp"), false, true))
+ else if (StringMatch(settingName, _T("indexName"), false, true))
{
- winHelp = true; convertMode = TEX_RTF;
+ delete[] IndexNameString;
+ IndexNameString = copystring(settingValue);
}
- else if (StringMatch(settingValue, _T("XLP"), false, true) ||
- StringMatch(settingValue, _T("wxHelp"), false, true))
+ else if (StringMatch(settingName, _T("contentsName"), false, true))
{
- convertMode = TEX_XLP;
+ delete[] ContentsNameString;
+ ContentsNameString = copystring(settingValue);
}
- else if (StringMatch(settingValue, _T("HTML"), false, true))
+ else if (StringMatch(settingName, _T("glossaryName"), false, true))
{
- convertMode = TEX_HTML;
+ delete[] GlossaryNameString;
+ GlossaryNameString = copystring(settingValue);
}
- else
+ else if (StringMatch(settingName, _T("referencesName"), false, true))
{
- if (interactive)
- OnInform(_T("Initialisation file error: conversionMode must be one of\nRTF, WinHelp, XLP (or wxHelp), HTML."));
- wxStrcpy(errorCode, _T("Initialisation file error: conversionMode must be one of\nRTF, WinHelp, XLP (or wxHelp), HTML."));
+ delete[] ReferencesNameString;
+ ReferencesNameString = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("tablesName"), false, true))
+ {
+ delete[] TablesNameString;
+ TablesNameString = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("figuresName"), false, true))
+ {
+ delete[] FiguresNameString;
+ FiguresNameString = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("tableName"), false, true))
+ {
+ delete[] TableNameString;
+ TableNameString = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("figureName"), false, true))
+ {
+ delete[] FigureNameString;
+ FigureNameString = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("abstractName"), false, true))
+ {
+ delete[] AbstractNameString;
+ AbstractNameString = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("chapterFontSize"), false, true))
+ RegisterIntSetting(settingValueStr, &chapterFont);
+ else if (StringMatch(settingName, _T("sectionFontSize"), false, true))
+ RegisterIntSetting(settingValueStr, §ionFont);
+ else if (StringMatch(settingName, _T("subsectionFontSize"), false, true))
+ RegisterIntSetting(settingValueStr, &subsectionFont);
+ else if (StringMatch(settingName, _T("titleFontSize"), false, true))
+ RegisterIntSetting(settingValueStr, &titleFont);
+ else if (StringMatch(settingName, _T("authorFontSize"), false, true))
+ RegisterIntSetting(settingValueStr, &authorFont);
+ else if (StringMatch(settingName, _T("ignoreInput"), false, true))
+ IgnorableInputFiles.Add(wxFileNameFromPath(settingValue));
+ else if (StringMatch(settingName, _T("mirrorMargins"), false, true))
+ mirrorMargins = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("runTwice"), false, true))
+ runTwice = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("isInteractive"), false, true))
+ isInteractive = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("headerRule"), false, true))
+ headerRule = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("footerRule"), false, true))
+ footerRule = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("combineSubSections"), false, true))
+ combineSubSections = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("listLabelIndent"), false, true))
+ RegisterIntSetting(settingValueStr, &labelIndentTab);
+ else if (StringMatch(settingName, _T("listItemIndent"), false, true))
+ RegisterIntSetting(settingValueStr, &itemIndentTab);
+ else if (StringMatch(settingName, _T("useUpButton"), false, true))
+ useUpButton = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("useHeadingStyles"), false, true))
+ useHeadingStyles = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("useWord"), false, true))
+ useWord = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("contentsDepth"), false, true))
+ RegisterIntSetting(settingValueStr, &contentsDepth);
+ else if (StringMatch(settingName, _T("generateHPJ"), false, true))
+ generateHPJ = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("truncateFilenames"), false, true))
+ truncateFilenames = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("winHelpVersion"), false, true))
+ RegisterIntSetting(settingValueStr, &winHelpVersion);
+ else if (StringMatch(settingName, _T("winHelpContents"), false, true))
+ winHelpContents = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("htmlIndex"), false, true))
+ htmlIndex = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("htmlWorkshopFiles"), false, true))
+ htmlWorkshopFiles = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("htmlFrameContents"), false, true))
+ htmlFrameContents = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("htmlStylesheet"), false, true))
+ {
+ if (htmlStylesheet)
+ delete[] htmlStylesheet;
+ htmlStylesheet = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("upperCaseNames"), false, true))
+ upperCaseNames = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("ignoreBadRefs"), false, true))
+ ignoreBadRefs = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("htmlFaceName"), false, true))
+ {
+ delete[] htmlFaceName;
+ htmlFaceName = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("winHelpTitle"), false, true))
+ {
+ if (winHelpTitle)
+ delete[] winHelpTitle;
+ winHelpTitle = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("indexSubsections"), false, true))
+ indexSubsections = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("compatibility"), false, true))
+ compatibilityMode = StringTobool(settingValue);
+ else if (StringMatch(settingName, _T("defaultColumnWidth"), false, true))
+ {
+ RegisterIntSetting(settingValueStr, &defaultTableColumnWidth);
+ defaultTableColumnWidth = 20*defaultTableColumnWidth;
+ }
+ else if (StringMatch(settingName, _T("bitmapMethod"), false, true))
+ {
+ if ((wxStrcmp(settingValue, _T("includepicture")) != 0) && (wxStrcmp(settingValue, _T("hex")) != 0) &&
+ (wxStrcmp(settingValue, _T("import")) != 0))
+ {
+ if (interactive)
+ OnError(_T("Unknown bitmapMethod"));
+ wxStrcpy(errorCode, _T("Unknown bitmapMethod"));
+ }
+ else
+ {
+ delete[] bitmapMethod;
+ bitmapMethod = copystring(settingValue);
+ }
+ }
+ else if (StringMatch(settingName, _T("htmlBrowseButtons"), false, true))
+ {
+ if (wxStrcmp(settingValue, _T("none")) == 0)
+ htmlBrowseButtons = HTML_BUTTONS_NONE;
+ else if (wxStrcmp(settingValue, _T("bitmap")) == 0)
+ htmlBrowseButtons = HTML_BUTTONS_BITMAP;
+ else if (wxStrcmp(settingValue, _T("text")) == 0)
+ htmlBrowseButtons = HTML_BUTTONS_TEXT;
+ else
+ {
+ if (interactive)
+ OnInform(_T("Initialisation file error: htmlBrowseButtons must be one of none, bitmap, or text."));
+ wxStrcpy(errorCode, _T("Initialisation file error: htmlBrowseButtons must be one of none, bitmap, or text."));
+ }
+ }
+ else if (StringMatch(settingName, _T("backgroundImage"), false, true))
+ {
+ backgroundImageString = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("backgroundColour"), false, true))
+ {
+ delete[] backgroundColourString;
+ backgroundColourString = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("textColour"), false, true))
+ {
+ textColourString = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("linkColour"), false, true))
+ {
+ linkColourString = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("followedLinkColour"), false, true))
+ {
+ followedLinkColourString = copystring(settingValue);
+ }
+ else if (StringMatch(settingName, _T("conversionMode"), false, true))
+ {
+ if (StringMatch(settingValue, _T("RTF"), false, true))
+ {
+ winHelp = false; convertMode = TEX_RTF;
+ }
+ else if (StringMatch(settingValue, _T("WinHelp"), false, true))
+ {
+ winHelp = true; convertMode = TEX_RTF;
+ }
+ else if (StringMatch(settingValue, _T("XLP"), false, true) ||
+ StringMatch(settingValue, _T("wxHelp"), false, true))
+ {
+ convertMode = TEX_XLP;
+ }
+ else if (StringMatch(settingValue, _T("HTML"), false, true))
+ {
+ convertMode = TEX_HTML;
+ }
+ else
+ {
+ if (interactive)
+ OnInform(_T("Initialisation file error: conversionMode must be one of\nRTF, WinHelp, XLP (or wxHelp), HTML."));
+ wxStrcpy(errorCode, _T("Initialisation file error: conversionMode must be one of\nRTF, WinHelp, XLP (or wxHelp), HTML."));
+ }
+ }
+ else if (StringMatch(settingName, _T("documentFontSize"), false, true))
+ {
+ int n;
+ RegisterIntSetting(settingValueStr, &n);
+ if (n == 10 || n == 11 || n == 12)
+ SetFontSizes(n);
+ else
+ {
+ wxChar buf[200];
+ wxSnprintf(buf, sizeof(buf), _T("Initialisation file error: nonstandard document font size %d."), n);
+ if (interactive)
+ OnInform(buf);
+ wxStrcpy(errorCode, buf);
+ }
}
- }
- else if (StringMatch(settingName, _T("documentFontSize"), false, true))
- {
- int n;
- StringToInt(settingValue, &n);
- if (n == 10 || n == 11 || n == 12)
- SetFontSizes(n);
else
{
- wxChar buf[200];
- wxSnprintf(buf, sizeof(buf), _T("Initialisation file error: nonstandard document font size %d."), n);
- if (interactive)
- OnInform(buf);
- wxStrcpy(errorCode, buf);
+ wxChar buf[200];
+ wxSnprintf(buf, sizeof(buf), _T("Initialisation file error: unrecognised setting %s."), settingName.c_str());
+ if (interactive)
+ OnInform(buf);
+ wxStrcpy(errorCode, buf);
}
- }
- else
- {
- wxChar buf[200];
- wxSnprintf(buf, sizeof(buf), _T("Initialisation file error: unrecognised setting %s."), settingName);
- if (interactive)
- OnInform(buf);
- wxStrcpy(errorCode, buf);
- }
- return errorCode;
+ return errorCode;
}
-bool ReadCustomMacros(wxChar *filename)
+bool ReadCustomMacros(const wxString& filename)
{
- if (!wxFileExists(filename))
- return false;
+ if (!wxFileExists(filename))
+ return false;
- wxString name = filename;
- wxSTD ifstream istr((char const *)name.fn_str(), wxSTD ios::in);
+ wxFileInputStream input( filename );
+ if(!input.Ok()) return false;
+ wxTextInputStream ini( input );
- if (istr.bad()) return false;
+ CustomMacroList.Clear();
- CustomMacroList.Clear();
- char ch;
- wxChar macroName[100];
- wxChar macroBody[1000];
- int noArgs;
+ while (!input.Eof())
+ {
+ wxString line = ini.ReadLine();
+ BibEatWhiteSpace(line);
+ if (line.empty()) continue;
- while (!istr.eof())
- {
- BibEatWhiteSpace(istr);
- istr.get(ch);
- if (istr.eof())
- break;
+ if (line[0] != _T('\\')) // Not a macro definition, so must be NAME=VALUE
+ {
+ wxString settingName = BibReadWord(line);
+ BibEatWhiteSpace(line);
+ if (line.empty() || line[0] != _T('='))
+ {
+ OnError(_T("Expected = following name: malformed tex2rtf.ini file."));
+ return false;
+ }
+ else
+ {
+ line = line.substr(1);
+ BibEatWhiteSpace(line);
+ wxString settingValue = BibReadToEOL(line);
+ RegisterSetting(settingName, settingValue);
+ }
+ }
+ else
+ {
+ line = line.substr(1);
+ wxString macroName = BibReadWord(line);
+ BibEatWhiteSpace(line);
+ if (line[0] != _T('['))
+ {
+ OnError(_T("Expected [ followed by number of arguments: malformed tex2rtf.ini file."));
+ return false;
+ }
+ line = line.substr(1);
+ wxString noAargStr = line.BeforeFirst(_T(']'));
+ line = line.AfterFirst(_T(']'));
+ long noArgs;
+ if (!noAargStr.ToLong(&noArgs) || line.empty())
+ {
+ OnError(_T("Expected ] following number of arguments: malformed tex2rtf.ini file."));
+ return false;
+ }
+ BibEatWhiteSpace(line);
+ if (line[0] != _T('{'))
+ {
+ OnError(_T("Expected { followed by macro body: malformed tex2rtf.ini file."));
+ return false;
+ }
- if (ch != '\\') // Not a macro definition, so must be NAME=VALUE
- {
- wxChar settingName[100];
- settingName[0] = ch;
- BibReadWord(istr, (settingName+1));
- BibEatWhiteSpace(istr);
- istr.get(ch);
- if (ch != '=')
- {
- OnError(_T("Expected = following name: malformed tex2rtf.ini file."));
- return false;
- }
- else
- {
- wxChar settingValue[200];
- BibEatWhiteSpace(istr);
- BibReadToEOL(istr, settingValue);
- RegisterSetting(settingName, settingValue);
- }
- }
- else
- {
- BibReadWord(istr, macroName);
- BibEatWhiteSpace(istr);
- istr.get(ch);
- if (ch != '[')
- {
- OnError(_T("Expected [ followed by number of arguments: malformed tex2rtf.ini file."));
- return false;
- }
- istr >> noArgs;
- istr.get(ch);
- if (ch != ']')
- {
- OnError(_T("Expected ] following number of arguments: malformed tex2rtf.ini file."));
- return false;
- }
- BibEatWhiteSpace(istr);
- istr.get(ch);
- if (ch != '{')
- {
- OnError(_T("Expected { followed by macro body: malformed tex2rtf.ini file."));
- return false;
- }
- CustomMacro *macro = new CustomMacro(macroName, noArgs, NULL);
- BibReadValue(istr, macroBody, false, false); // Don't ignore extra braces
- if (wxStrlen(macroBody) > 0)
- macro->macroBody = copystring(macroBody);
+ CustomMacro *macro = new CustomMacro(macroName.c_str(), noArgs, NULL);
+ wxString macroBody = BibReadValue(line, false, false); // Don't ignore extra braces
+ if (!macroBody.empty())
+ macro->macroBody = copystring(macroBody.c_str());
+
+ BibEatWhiteSpace(line);
+ CustomMacroList.Append(macroName, macro);
+ AddMacroDef(ltCUSTOM_MACRO, macroName.c_str(), noArgs);
+ }
- BibEatWhiteSpace(istr);
- CustomMacroList.Append(macroName, macro);
- AddMacroDef(ltCUSTOM_MACRO, macroName, noArgs);
}
- }
- wxChar mbuf[200];
- wxSnprintf(mbuf, sizeof(mbuf), _T("Read initialization file %s."), filename);
- OnInform(mbuf);
- return true;
+ wxChar mbuf[200];
+ wxSnprintf(mbuf, sizeof(mbuf), _T("Read initialization file %s."), filename.c_str());
+ OnInform(mbuf);
+ return true;
}
CustomMacro *FindCustomMacro(wxChar *name)
void Tex2RTFYield(bool force)
{
-#ifdef __WXMSW__
+#ifdef __WINDOWS__
static int yieldCount = 0;
if (isSync)
yieldCount = 10;
}
yieldCount --;
+#else
+ wxUnusedVar(force);
#endif
}
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)
return exact ? wxString(str2).Cmp(str1) == 0 :
wxString(str2).CmpNoCase(str1) == 0;
}
-#endif