#endif
#ifndef WX_PRECOMP
-#include "wx/wx.h"
#endif
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
+#if !WXWIN_COMPATIBILITY_2_4
+static inline wxChar* copystring(const wxChar* s)
+ { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
+#endif
+
/*
* Variables accessible from clients
*
// All of these tokens MUST be found on a line by themselves (no other
// text) and must start at the first character of the line, or tex2rtf
// will fail to process them correctly (a limitation of tex2rtf, not TeX)
-wxString syntaxTokens[] =
+static const wxString syntaxTokens[] =
{ "\\begin{verbatim}",
"\\begin{toocomplex}",
"\\end{verbatim}",
"\\begin{comment}",
"\\end{comment}",
"\\verbatiminput",
- "\\par",
+// "\\par",
"\\input",
"\\helpinput",
"\\include",
bool winHelpContents = FALSE; // Generate .cnt file for WinHelp 4
bool htmlIndex = FALSE; // Generate .htx file for HTML
bool htmlFrameContents = FALSE; // Use frames for HTML contents page
+char *htmlStylesheet = NULL; // Use this CSS stylesheet for HTML pages
bool useHeadingStyles = TRUE; // Insert \s1, s2 etc.
bool useWord = TRUE; // Insert proper Word table of contents, etc etc
int contentsDepth = 4; // Depth of Word table of contents
char *followedLinkColourString = NULL;
bool combineSubSections = FALSE;
bool htmlWorkshopFiles = FALSE;
+bool ignoreBadRefs = FALSE;
+char *htmlFaceName = NULL;
extern int passNumber;
FILE *CurrentOutput1 = NULL;
FILE *CurrentOutput2 = NULL;
FILE *Inputs[15];
-int LineNumbers[15];
+unsigned long LineNumbers[15];
char *FileNames[15];
int CurrentInputIndex = 0;
#define IncrementLineNumber() LineNumbers[CurrentInputIndex] ++
-TexRef::TexRef(char *label, char *file, char *section, char *sectionN)
+TexRef::TexRef(const char *label, const char *file,
+ const char *section, const char *sectionN)
{
refLabel = copystring(label);
refFile = file ? copystring(file) : (char*) NULL;
delete [] macroBody;
}
-void TexOutput(char *s, bool ordinaryText)
+void TexOutput(const char *s, bool ordinaryText)
{
int len = strlen(s);
void ForbidWarning(TexMacroDef *def)
{
- char buf[100];
+ wxString informBuf;
switch (def->forbidden)
{
case FORBID_WARN:
{
- sprintf(buf, "Warning: it is recommended that command %s is not used.", def->name);
- OnInform(buf);
+ informBuf.Printf("Warning: it is recommended that command %s is not used.", def->name);
+ OnInform((char *)informBuf.c_str());
break;
}
case FORBID_ABSOLUTELY:
{
- sprintf(buf, "Error: command %s cannot be used and will lead to errors.", def->name);
- OnInform(buf);
+ informBuf.Printf("Error: command %s cannot be used and will lead to errors.", def->name);
+ OnInform((char *)informBuf.c_str());
break;
}
default:
// detection of \verb yet.
// #define CHECK_BRACES 1
-unsigned long leftCurly = 0;
-unsigned long rightCurly = 0;
+unsigned long leftCurley = 0;
+unsigned long rightCurley = 0;
static wxString currentFileName = "";
bool read_a_line(char *buf)
}
int ch = -2;
- int bufIndex = 0;
+ unsigned long bufIndex = 0;
buf[0] = 0;
while (ch != EOF && ch != 10)
{
wxString errBuf;
errBuf.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
- LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
+ LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str(), MAX_LINE_BUFFER_SIZE);
OnError((char *)errBuf.c_str());
return FALSE;
}
if (checkCurleyBraces)
{
if (ch == '{' && !readInVerbatim)
- leftCurly++;
+ leftCurley++;
if (ch == '}' && !readInVerbatim)
{
- rightCurly++;
- if (rightCurly > leftCurly)
+ rightCurley++;
+ if (rightCurley > leftCurley)
{
wxString errBuf;
- errBuf.Printf("An extra right curly brace ('}') was detected at line %lu inside file %s",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
+ errBuf.Printf("An extra right Curley 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
+ // Reduce the count of right Curley braces, so the mismatched count
// isn't reported on every line that has a '}' after the first mismatch
- rightCurly--;
+ rightCurley--;
}
}
}
break;
}
- if (readInVerbatim)
- {
- // There should NOT be a '\' before the '_'
- if ((bufIndex > 0 && (buf[bufIndex-1] == '\\')) && (buf[0] != '%'))
- {
- wxString errBuf;
- errBuf.Printf("An underscore ('_') was detected at line %lu inside file %s that should NOT have a '\\' before it.",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
- OnError((char *)errBuf.c_str());
- }
- }
- else
+ if (checkSyntax)
{
- // There should be a '\' before the '_'
- if (bufIndex == 0)
+ if (readInVerbatim)
{
- wxString errBuf;
- errBuf.Printf("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it.",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
- OnError((char *)errBuf.c_str());
+ // There should NOT be a '\' before the '_'
+ if ((bufIndex > 0 && (buf[bufIndex-1] == '\\')) && (buf[0] != '%'))
+ {
+ wxString errBuf;
+ errBuf.Printf("An underscore ('_') was detected at line %lu inside file %s that should NOT have a '\\' before it.",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
+ OnError((char *)errBuf.c_str());
+ }
}
- else if ((buf[bufIndex-1] != '\\') && (buf[0] != '%')) // If it is a comment line, then no warnings
+ else
{
- wxString errBuf;
- errBuf.Printf("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it.",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
- OnError((char *)errBuf.c_str());
+ // There should be a '\' before the '_'
+ if (bufIndex == 0)
+ {
+ wxString errBuf;
+ errBuf.Printf("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it.",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
+ OnError((char *)errBuf.c_str());
+ }
+ else if ((buf[bufIndex-1] != '\\') && (buf[0] != '%') && // If it is a comment line, then no warnings
+ (strncmp(buf, "\\input", 6))) // do not report filenames that have underscores in them
+ {
+ wxString errBuf;
+ errBuf.Printf("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it.",LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
+ OnError((char *)errBuf.c_str());
+ }
}
}
buf[bufIndex++] = ch;
if (checkCurleyBraces)
{
- if (leftCurly != rightCurly)
+ if (leftCurley != rightCurley)
{
wxString errBuf;
- errBuf.Printf("Curly braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName.c_str(),leftCurly,rightCurly);
+ errBuf.Printf("Curley braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName.c_str(),leftCurley,rightCurley);
OnError((char *)errBuf.c_str());
}
- leftCurly = 0;
- rightCurly = 0;
+ leftCurley = 0;
+ rightCurley = 0;
}
if (readingVerbatim)
fileNameStr.Replace("\\", "");
// Ignore some types of input files (e.g. macro definition files)
- char *fileOnly = FileNameFromPath((char*) (const char*) fileNameStr);
+ char *fileOnly = wxFileNameFromPath((char*) (const char*) fileNameStr);
currentFileName = fileOnly;
if (IgnorableInputFiles.Member(fileOnly))
return read_a_line(buf);
if (syntaxTokens[index] == "\\verb")
{
errBuf.Printf("'%s$....$' was detected at line %lu inside file %s. Please replace this form with \\tt{....}",
- syntaxTokens[index], LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
+ syntaxTokens[index].c_str(),
+ LineNumbers[CurrentInputIndex],
+ currentFileName.c_str());
}
else
{
errBuf.Printf("'%s' was detected at line %lu inside file %s that is not the only text on the line, starting at column one.",
- syntaxTokens[index], LineNumbers[CurrentInputIndex], (const char*) currentFileName.c_str());
+ syntaxTokens[index].c_str(),
+ LineNumbers[CurrentInputIndex],
+ currentFileName.c_str());
}
OnError((char *)errBuf.c_str());
}
if (checkCurleyBraces)
{
- if (ch == EOF && leftCurly != rightCurly)
+ if (ch == EOF && leftCurley != rightCurley)
{
wxString errBuf;
- errBuf.Printf("Curly braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName.c_str(),leftCurly,rightCurly);
+ errBuf.Printf("Curley braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName.c_str(),leftCurley,rightCurley);
OnError((char *)errBuf.c_str());
}
}
errBuf.Printf("Could not find macro: %s at line %d, file %s",
macroBuf, (int)(LineNumbers[CurrentInputIndex]-1), FileNames[CurrentInputIndex]);
OnError((char *)errBuf.c_str());
+
+ if (wxStrcmp(macroBuf,"\\end{document}") == 0)
+ {
+ wxString buf;
+ buf = "Halted build due to unrecoverable error.";
+ OnInform((char *)buf.c_str());
+ stopRunning = TRUE;
+ }
}
/*
pos ++;
int noBraces = 1;
- wxBuffer[0] = 0;
+ wxTex2RTFBuffer[0] = 0;
int i = 0;
bool end = FALSE;
while (!end)
noBraces --;
if (noBraces == 0)
{
- wxBuffer[i] = 0;
+ wxTex2RTFBuffer[i] = 0;
end = TRUE;
}
else
{
- wxBuffer[i] = '}';
+ wxTex2RTFBuffer[i] = '}';
i ++;
}
pos ++;
}
else if (ch == '{')
{
- wxBuffer[i] = '{';
+ wxTex2RTFBuffer[i] = '{';
i ++;
pos ++;
}
else if (ch == '\\' && buffer[pos+1] == '}')
{
- wxBuffer[i] = '}';
+ wxTex2RTFBuffer[i] = '}';
pos += 2;
i++;
}
else if (ch == '\\' && buffer[pos+1] == '{')
{
- wxBuffer[i] = '{';
+ wxTex2RTFBuffer[i] = '{';
pos += 2;
i++;
}
else
{
- wxBuffer[i] = ch;
+ wxTex2RTFBuffer[i] = ch;
pos ++;
i ++;
if (ch == 0)
TexChunk *argValue = new TexChunk(CHUNK_TYPE_STRING);
arg->children.Append((wxObject *)argValue);
argValue->argn = 1;
- argValue->value = copystring(wxBuffer);
+ argValue->value = copystring(wxTex2RTFBuffer);
children.Append((wxObject *)chunk);
}
CustomMacro *customMacro = FindCustomMacro(def->name);
TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO, def);
+
chunk->no_args = def->no_args;
// chunk->name = copystring(def->name);
chunk->macroId = def->macroId;
*
*/
-int ParseMacroBody(char *macro_name, TexChunk *parent,
+int ParseMacroBody(const char *macro_name, TexChunk *parent,
int no_args, char *buffer, int pos,
char *environment, bool parseToBrace,
TexChunk *customMacroArgs)
isOptional = TRUE;
pos += 2;
}
+ else if (i > 0)
+ {
+ wxString errBuf;
+ wxString tmpBuffer(buffer);
+ if (tmpBuffer.length() > 4)
+ {
+ if (tmpBuffer.Right(4) == "\\par")
+ tmpBuffer = tmpBuffer.Mid(0,tmpBuffer.length()-4);
+ }
+ errBuf.Printf("Missing macro argument in the line:\n\t%s\n",tmpBuffer.c_str());
+ OnError((char *)errBuf.c_str());
+ }
+
}
arg->optional = isOptional;
return FALSE;
}
-TexMacroDef::TexMacroDef(int the_id, char *the_name, int n, bool ig, bool forbidLevel)
+TexMacroDef::TexMacroDef(int the_id, const char *the_name, int n, bool ig, bool forbidLevel)
{
name = copystring(the_name);
no_args = n;
OnMacro(chunk->macroId, chunk->no_args, TRUE);
wxNode *node = chunk->children.First();
+ TexChunk *child_chunk = NULL;
while (node)
{
- TexChunk *child_chunk = (TexChunk *)node->Data();
+ child_chunk = (TexChunk *)node->Data();
TraverseFromChunk(child_chunk, node);
node = node->Next();
}
- if (thisNode && thisNode->Next()) nextChunk = (TexChunk *)thisNode->Next()->Data();
+ if (thisNode && thisNode->Next())
+ nextChunk = (TexChunk *)thisNode->Next()->Data();
if (!childrenOnly)
OnMacro(chunk->macroId, chunk->no_args, FALSE);
currentArgument = chunk;
- if (thisNode && thisNode->Next()) nextChunk = (TexChunk *)thisNode->Next()->Data();
+ if (thisNode && thisNode->Next())
+ nextChunk = (TexChunk *)thisNode->Next()->Data();
isArgOptional = chunk->optional;
noArgs = chunk->no_args;
// If non-whitespace text, we no longer have a new paragraph.
if (issuedNewParagraph && !((chunk->value[0] == 10 || chunk->value[0] == 13 || chunk->value[0] == 32)
&& chunk->value[1] == 0))
+ {
issuedNewParagraph = FALSE;
+ }
TexOutput(chunk->value, TRUE);
}
break;
CurrentOutput2 = fd2;
}
-void AddMacroDef(int the_id, char *name, int n, bool ignore, bool forbid)
+void AddMacroDef(int the_id, const char *name, int n, bool ignore, bool forbid)
{
MacroDefs.Put(name, new TexMacroDef(the_id, name, n, ignore, forbid));
}
}
else
{
- char buf[300];
- TexOutput("??", TRUE);
- sprintf(buf, "Warning: unresolved reference %s.", refName);
- OnInform(buf);
+ wxString informBuf;
+ informBuf.Printf("Warning: unresolved reference '%s'", refName);
+ OnInform((char *)informBuf.c_str());
}
}
else TexOutput("??", TRUE);
TexOutput(ref->sectionNumber, TRUE);
if (strcmp(ref->sectionNumber, "??") == 0)
{
- char buf[300];
- sprintf(buf, "Warning: unresolved citation %s.", citeKey);
- OnInform(buf);
+ wxString informBuf;
+ informBuf.Printf("Warning: unresolved citation %s.", citeKey);
+ OnInform((char *)informBuf.c_str());
}
}
citeKey = ParseMultifieldString(citeKeys, &pos);