X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/04b9c5bb04bfa5470997667993f849e25fc5e869..be3dfc5dfa25e83ec09844027d47b9fbf9a46853:/utils/tex2rtf/src/tex2any.cpp diff --git a/utils/tex2rtf/src/tex2any.cpp b/utils/tex2rtf/src/tex2any.cpp index 7e8062f12a..2e5df17be9 100644 --- a/utils/tex2rtf/src/tex2any.cpp +++ b/utils/tex2rtf/src/tex2any.cpp @@ -21,7 +21,6 @@ #endif #ifndef WX_PRECOMP -#include "wx/wx.h" #endif #include @@ -29,6 +28,11 @@ #include #include +#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 * @@ -129,6 +133,7 @@ int winHelpVersion = 3; // WinHelp Version (3 for Windows 3.1, 4 for 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 @@ -144,6 +149,8 @@ char *linkColourString = NULL; char *followedLinkColourString = NULL; bool combineSubSections = FALSE; bool htmlWorkshopFiles = FALSE; +bool ignoreBadRefs = FALSE; +char *htmlFaceName = NULL; extern int passNumber; @@ -189,7 +196,7 @@ int tableNo = 0; FILE *CurrentOutput1 = NULL; FILE *CurrentOutput2 = NULL; FILE *Inputs[15]; -int LineNumbers[15]; +unsigned long LineNumbers[15]; char *FileNames[15]; int CurrentInputIndex = 0; @@ -218,7 +225,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 +251,7 @@ CustomMacro::~CustomMacro() delete [] macroBody; } -void TexOutput(char *s, bool ordinaryText) +void TexOutput(const char *s, bool ordinaryText) { int len = strlen(s); @@ -432,7 +440,7 @@ bool read_a_line(char *buf) } int ch = -2; - int bufIndex = 0; + unsigned long bufIndex = 0; buf[0] = 0; while (ch != EOF && ch != 10) @@ -441,7 +449,7 @@ bool read_a_line(char *buf) { 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; } @@ -462,7 +470,7 @@ bool read_a_line(char *buf) if (rightCurley > leftCurley) { wxString errBuf; - errBuf.Printf("An extra right Curley 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 Curley braces, so the mismatched count @@ -581,31 +589,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; @@ -743,7 +754,7 @@ bool read_a_line(char *buf) 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); @@ -1139,7 +1150,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, char *buffer, int pos, char *e pos ++; int noBraces = 1; - wxBuffer[0] = 0; + wxTex2RTFBuffer[0] = 0; int i = 0; bool end = FALSE; while (!end) @@ -1150,37 +1161,37 @@ int ParseArg(TexChunk *thisArg, wxList& children, char *buffer, int pos, char *e 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) @@ -1201,7 +1212,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, char *buffer, int pos, char *e 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); } @@ -1548,7 +1559,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) @@ -1683,7 +1694,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; @@ -1958,7 +1969,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)); }