Changes to catch macros that are missing arguments - not perfect, but it will work with all our current TEX files.

Added cleaner ABORT handling in some situations
If \\end{document} is not found, then program auto-aborts after first pass to avoid hanging in some endless loop until all system resources are exhausted and the program crashes.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10532 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
George Tasker 2001-06-11 12:54:38 +00:00
parent 36e67c5cfc
commit 04b9c5bb04
3 changed files with 61 additions and 17 deletions

View File

@ -5090,6 +5090,9 @@ bool RTFOnArgument(int macroId, int arg_no, bool start)
bool RTFGo(void) bool RTFGo(void)
{ {
if (stopRunning)
return FALSE;
// Reset variables // Reset variables
indentLevel = 0; indentLevel = 0;
forbidParindent = 0; forbidParindent = 0;
@ -5164,6 +5167,9 @@ bool RTFGo(void)
SetCurrentOutput(Chapters); SetCurrentOutput(Chapters);
if (stopRunning)
return FALSE;
OnInform("Converting..."); OnInform("Converting...");
TraverseDocument(); TraverseDocument();

View File

@ -274,19 +274,19 @@ void TexOutput(char *s, bool ordinaryText)
void ForbidWarning(TexMacroDef *def) void ForbidWarning(TexMacroDef *def)
{ {
char buf[100]; wxString informBuf;
switch (def->forbidden) switch (def->forbidden)
{ {
case FORBID_WARN: case FORBID_WARN:
{ {
sprintf(buf, "Warning: it is recommended that command %s is not used.", def->name); informBuf.Printf("Warning: it is recommended that command %s is not used.", def->name);
OnInform(buf); OnInform((char *)informBuf.c_str());
break; break;
} }
case FORBID_ABSOLUTELY: case FORBID_ABSOLUTELY:
{ {
sprintf(buf, "Error: command %s cannot be used and will lead to errors.", def->name); informBuf.Printf("Error: command %s cannot be used and will lead to errors.", def->name);
OnInform(buf); OnInform((char *)informBuf.c_str());
break; break;
} }
default: default:
@ -938,6 +938,14 @@ void MacroError(char *buffer)
errBuf.Printf("Could not find macro: %s at line %d, file %s", errBuf.Printf("Could not find macro: %s at line %d, file %s",
macroBuf, (int)(LineNumbers[CurrentInputIndex]-1), FileNames[CurrentInputIndex]); macroBuf, (int)(LineNumbers[CurrentInputIndex]-1), FileNames[CurrentInputIndex]);
OnError((char *)errBuf.c_str()); 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;
}
} }
/* /*
@ -1248,6 +1256,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, char *buffer, int pos, char *e
CustomMacro *customMacro = FindCustomMacro(def->name); CustomMacro *customMacro = FindCustomMacro(def->name);
TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO, def); TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO, def);
chunk->no_args = def->no_args; chunk->no_args = def->no_args;
// chunk->name = copystring(def->name); // chunk->name = copystring(def->name);
chunk->macroId = def->macroId; chunk->macroId = def->macroId;
@ -1604,6 +1613,19 @@ int ParseMacroBody(char *macro_name, TexChunk *parent,
isOptional = TRUE; isOptional = TRUE;
pos += 2; 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; arg->optional = isOptional;
@ -1853,14 +1875,16 @@ void TraverseFromChunk(TexChunk *chunk, wxNode *thisNode, bool childrenOnly)
OnMacro(chunk->macroId, chunk->no_args, TRUE); OnMacro(chunk->macroId, chunk->no_args, TRUE);
wxNode *node = chunk->children.First(); wxNode *node = chunk->children.First();
TexChunk *child_chunk = NULL;
while (node) while (node)
{ {
TexChunk *child_chunk = (TexChunk *)node->Data(); child_chunk = (TexChunk *)node->Data();
TraverseFromChunk(child_chunk, node); TraverseFromChunk(child_chunk, node);
node = node->Next(); node = node->Next();
} }
if (thisNode && thisNode->Next()) nextChunk = (TexChunk *)thisNode->Next()->Data(); if (thisNode && thisNode->Next())
nextChunk = (TexChunk *)thisNode->Next()->Data();
if (!childrenOnly) if (!childrenOnly)
OnMacro(chunk->macroId, chunk->no_args, FALSE); OnMacro(chunk->macroId, chunk->no_args, FALSE);
@ -1888,7 +1912,8 @@ void TraverseFromChunk(TexChunk *chunk, wxNode *thisNode, bool childrenOnly)
currentArgument = chunk; currentArgument = chunk;
if (thisNode && thisNode->Next()) nextChunk = (TexChunk *)thisNode->Next()->Data(); if (thisNode && thisNode->Next())
nextChunk = (TexChunk *)thisNode->Next()->Data();
isArgOptional = chunk->optional; isArgOptional = chunk->optional;
noArgs = chunk->no_args; noArgs = chunk->no_args;
@ -1906,7 +1931,9 @@ void TraverseFromChunk(TexChunk *chunk, wxNode *thisNode, bool childrenOnly)
// If non-whitespace text, we no longer have a new paragraph. // 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) if (issuedNewParagraph && !((chunk->value[0] == 10 || chunk->value[0] == 13 || chunk->value[0] == 32)
&& chunk->value[1] == 0)) && chunk->value[1] == 0))
{
issuedNewParagraph = FALSE; issuedNewParagraph = FALSE;
}
TexOutput(chunk->value, TRUE); TexOutput(chunk->value, TRUE);
} }
break; break;
@ -3136,10 +3163,9 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start)
} }
else else
{ {
char buf[300]; wxString informBuf;
TexOutput("??", TRUE); informBuf.Printf("Warning: unresolved reference '%s'", refName);
sprintf(buf, "Warning: unresolved reference '%s'", refName); OnInform((char *)informBuf.c_str());
OnInform(buf);
} }
} }
else TexOutput("??", TRUE); else TexOutput("??", TRUE);
@ -3298,9 +3324,9 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start)
TexOutput(ref->sectionNumber, TRUE); TexOutput(ref->sectionNumber, TRUE);
if (strcmp(ref->sectionNumber, "??") == 0) if (strcmp(ref->sectionNumber, "??") == 0)
{ {
char buf[300]; wxString informBuf;
sprintf(buf, "Warning: unresolved citation %s.", citeKey); informBuf.Printf("Warning: unresolved citation %s.", citeKey);
OnInform(buf); OnInform((char *)informBuf.c_str());
} }
} }
citeKey = ParseMultifieldString(citeKeys, &pos); citeKey = ParseMultifieldString(citeKeys, &pos);

View File

@ -665,7 +665,16 @@ void MyFrame::OnGo(wxCommandEvent& event)
Tex2RTFYield(TRUE); Tex2RTFYield(TRUE);
Go(); Go();
if (runTwice) if (stopRunning)
{
SetStatusText("Build aborted!");
wxString errBuf;
errBuf.Printf("\nErrors encountered during this pass: %lu\n", errorCount);
OnInform((char *)errBuf.c_str());
}
if (runTwice && !stopRunning)
{ {
Tex2RTFYield(TRUE); Tex2RTFYield(TRUE);
Go(); Go();
@ -907,7 +916,7 @@ bool Go(void)
ChooseOutputFile(); ChooseOutputFile();
#endif #endif
if (!InputFile || !OutputFile) if (!InputFile || !OutputFile || stopRunning)
return FALSE; return FALSE;
#ifndef NO_GUI #ifndef NO_GUI
@ -981,6 +990,9 @@ bool Go(void)
OnInform("Reading LaTeX file..."); OnInform("Reading LaTeX file...");
TexLoadFile(InputFile); TexLoadFile(InputFile);
if (stopRunning)
return FALSE;
switch (convertMode) switch (convertMode)
{ {
case TEX_RTF: case TEX_RTF: