X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7cbe4e7973df5fc04e87fda87bdc28c416cf7fbd..5d35dca95fed224817455e65e70f9f52ca3e293c:/utils/tex2rtf/src/tex2any.cpp diff --git a/utils/tex2rtf/src/tex2any.cpp b/utils/tex2rtf/src/tex2any.cpp index bc2e66c153..8109c52f12 100644 --- a/utils/tex2rtf/src/tex2any.cpp +++ b/utils/tex2rtf/src/tex2any.cpp @@ -144,6 +144,8 @@ char *linkColourString = NULL; char *followedLinkColourString = NULL; bool combineSubSections = FALSE; bool htmlWorkshopFiles = FALSE; +bool ignoreBadRefs = FALSE; +char *htmlFaceName = copystring("Times New Roman"); extern int passNumber; @@ -218,7 +220,8 @@ TexMacroDef *VerbatimMacroDef = NULL; #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; @@ -243,7 +246,7 @@ CustomMacro::~CustomMacro() delete [] macroBody; } -void TexOutput(char *s, bool ordinaryText) +void TexOutput(const char *s, bool ordinaryText) { int len = strlen(s); @@ -274,19 +277,19 @@ void TexOutput(char *s, bool ordinaryText) 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: @@ -581,31 +584,34 @@ bool read_a_line(char *buf) break; } - if (readInVerbatim) + if (checkSyntax) { - // There should NOT be a '\' before the '_' - if ((bufIndex > 0 && (buf[bufIndex-1] == '\\')) && (buf[0] != '%')) + if (readInVerbatim) { - 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()); + // 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 - { - // There should be a '\' before the '_' - if (bufIndex == 0) + 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()); - } - 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()); + // 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; @@ -938,6 +944,14 @@ void MacroError(char *buffer) 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; + } } /* @@ -1248,6 +1262,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, char *buffer, int pos, char *e 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; @@ -1539,7 +1554,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, char *buffer, int pos, char *e * */ -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) @@ -1604,6 +1619,19 @@ int ParseMacroBody(char *macro_name, TexChunk *parent, 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; @@ -1661,7 +1689,7 @@ bool TexLoadFile(char *filename) 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; @@ -1853,14 +1881,16 @@ void TraverseFromChunk(TexChunk *chunk, wxNode *thisNode, bool childrenOnly) 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); @@ -1888,7 +1918,8 @@ void TraverseFromChunk(TexChunk *chunk, wxNode *thisNode, bool childrenOnly) 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; @@ -1906,7 +1937,9 @@ void TraverseFromChunk(TexChunk *chunk, wxNode *thisNode, bool childrenOnly) // 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; @@ -1931,7 +1964,7 @@ void SetCurrentOutputs(FILE *fd1, FILE *fd2) 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)); } @@ -3136,10 +3169,9 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) } 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); @@ -3298,9 +3330,9 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) 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);