X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c22287afb2711c424df0ba00bf6fbe2af736b433..c0cc7004a6ec1c53c0fd974898ef9ffd3739bef4:/utils/tex2rtf/src/tex2any.cpp diff --git a/utils/tex2rtf/src/tex2any.cpp b/utils/tex2rtf/src/tex2any.cpp index aa2f7ea449..4984789f8b 100644 --- a/utils/tex2rtf/src/tex2any.cpp +++ b/utils/tex2rtf/src/tex2any.cpp @@ -2,7 +2,7 @@ // Name: tex2any.cpp // Purpose: Utilities for Latex conversion. // Author: Julian Smart -// Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support +// Modified by: Wlodzimierz ABX Skiba 2003/2004 Unicode support // Ron Lee // Created: 01/01/99 // RCS-ID: $Id$ @@ -10,10 +10,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -29,16 +25,14 @@ #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 * */ - + TexChunk * DocumentTitle = NULL; TexChunk * DocumentAuthor = NULL; TexChunk * DocumentDate = NULL; @@ -109,15 +103,15 @@ int subsectionFont = 12; // largeFont1; int titleFont = LARGEFont3; int authorFont = LargeFont2; int mirrorMargins = true; -bool winHelp = false; // Output in Windows Help format if TRUE, linear otherwise +bool winHelp = false; // Output in Windows Help format if true, linear otherwise bool isInteractive = false; bool runTwice = false; int convertMode = TEX_RTF; -bool checkCurleyBraces = false; +bool checkCurlyBraces = false; bool checkSyntax = false; bool headerRule = false; bool footerRule = false; -bool compatibilityMode = false; // If TRUE, maximum Latex compatibility +bool compatibilityMode = false; // If true, maximum Latex compatibility // (Quality of RTF generation deteriorate) bool generateHPJ; // Generate WinHelp Help Project file wxChar *winHelpTitle = NULL; // Windows Help title @@ -151,7 +145,7 @@ wxChar *followedLinkColourString = NULL; bool combineSubSections = false; bool htmlWorkshopFiles = false; bool ignoreBadRefs = false; -wxChar *htmlFaceName = NULL; +wxChar *htmlFaceName = NULL; extern int passNumber; @@ -181,7 +175,7 @@ wxChar *UpNameString = copystring(_T("Up")); * Section numbering * */ - + int chapterNo = 0; int sectionNo = 0; int subsectionNo = 0; @@ -193,7 +187,7 @@ int tableNo = 0; * Other variables * */ - + FILE *CurrentOutput1 = NULL; FILE *CurrentOutput2 = NULL; FILE *Inputs[15]; @@ -204,12 +198,12 @@ int CurrentInputIndex = 0; wxChar *TexFileRoot = NULL; wxChar *TexBibName = NULL; // Bibliography output file name wxChar *TexTmpBibName = NULL; // Temporary bibliography output file name -bool isSync = false; // If TRUE, should not yield to other processes. -bool stopRunning = false; // If TRUE, should abort. +bool isSync = false; // If true, should not yield to other processes. +bool stopRunning = false; // If true, should abort. static int currentColumn = 0; wxChar *currentArgData = NULL; -bool haveArgData = false; // If TRUE, we're simulating the data. +bool haveArgData = false; // If true, we're simulating the data. TexChunk *currentArgument = NULL; TexChunk *nextChunk = NULL; bool isArgOptional = false; @@ -227,7 +221,7 @@ TexMacroDef *VerbatimMacroDef = NULL; TexRef::TexRef(const wxChar *label, const wxChar *file, - const wxChar *section, const wxChar *sectionN) + const wxChar *section, const wxChar *sectionN) { refLabel = copystring(label); refFile = file ? copystring(file) : (wxChar*) NULL; @@ -252,17 +246,15 @@ CustomMacro::~CustomMacro() delete [] macroBody; } -void TexOutput(const wxChar *s, bool ordinaryText) +void TexOutput(const wxString& s, bool ordinaryText) { - int len = wxStrlen(s); - // Update current column, but only if we're guaranteed to // be ordinary text (not mark-up stuff) int i; if (ordinaryText) - for (i = 0; i < len; i++) + for (wxString::const_iterator i = s.begin(); i != s.end(); ++i) { - if (s[i] == 13 || s[i] == 10) + if (*i == 13 || *i == 10) currentColumn = 0; else currentColumn ++; @@ -289,97 +281,100 @@ void ForbidWarning(TexMacroDef *def) case FORBID_WARN: { informBuf.Printf(_T("Warning: it is recommended that command %s is not used."), def->name); - OnInform((const wxChar *)informBuf.c_str()); + OnInform(informBuf); break; } case FORBID_ABSOLUTELY: { informBuf.Printf(_T("Error: command %s cannot be used and will lead to errors."), def->name); - OnInform((const wxChar *)informBuf.c_str()); + OnInform(informBuf); break; } default: break; } } - + TexMacroDef *MatchMacro(wxChar *buffer, int *pos, wxChar **env, bool *parseToBrace) { - *parseToBrace = true; - int i = (*pos); - TexMacroDef *def = NULL; - wxChar macroBuf[40]; - - // First, try to find begin{thing} - if (wxStrncmp(buffer+i, _T("begin{"), 6) == 0) - { - i += 6; + *parseToBrace = true; + int i = (*pos); + TexMacroDef *def = NULL; + wxChar macroBuf[40]; - int j = i; - while ((isalpha(buffer[j]) || buffer[j] == '*') && ((j - i) < 39)) + // First, try to find begin{thing} + if (wxStrncmp(buffer+i, _T("begin{"), 6) == 0) { - macroBuf[j-i] = buffer[j]; - j ++; - } - macroBuf[j-i] = 0; - def = (TexMacroDef *)MacroDefs.Get(macroBuf); + i += 6; - if (def) - { - *pos = j + 1; // BUGBUG Should this be + 1??? - *env = def->name; - ForbidWarning(def); - return def; + int j = i; + while ((isalpha(buffer[j]) || buffer[j] == '*') && ((j - i) < 39)) + { + macroBuf[j-i] = buffer[j]; + j ++; + } + macroBuf[j-i] = 0; + def = (TexMacroDef *)MacroDefs.Get(macroBuf); + + if (def) + { + *pos = j + 1; // BUGBUG Should this be + 1??? + *env = def->name; + ForbidWarning(def); + return def; + } + else + { + return NULL; + } } - else return NULL; - } - // Failed, so try to find macro from definition list - int j = i; + // Failed, so try to find macro from definition list + int j = i; - // First try getting a one-character macro, but ONLY - // if these TWO characters are not both alphabetical (could - // be a longer macro) - if (!(isalpha(buffer[i]) && isalpha(buffer[i+1]))) - { - macroBuf[0] = buffer[i]; - macroBuf[1] = 0; + // First try getting a one-character macro, but ONLY + // if these TWO characters are not both alphabetical (could + // be a longer macro) + if (!(isalpha(buffer[i]) && isalpha(buffer[i+1]))) + { + macroBuf[0] = buffer[i]; + macroBuf[1] = 0; - def = (TexMacroDef *)MacroDefs.Get(macroBuf); - if (def) j ++; - } + def = (TexMacroDef *)MacroDefs.Get(macroBuf); + if (def) j ++; + } - if (!def) - { - while ((isalpha(buffer[j]) || buffer[j] == '*') && ((j - i) < 39)) + if (!def) { - macroBuf[j-i] = buffer[j]; - j ++; + while ((isalpha(buffer[j]) || buffer[j] == '*') && ((j - i) < 39)) + { + macroBuf[j-i] = buffer[j]; + j ++; + } + macroBuf[j-i] = 0; + def = (TexMacroDef *)MacroDefs.Get(macroBuf); } - macroBuf[j-i] = 0; - def = (TexMacroDef *)MacroDefs.Get(macroBuf); - } - - if (def) - { - i = j; - - // We want to check whether this is a space-consuming macro - // (e.g. {\bf word}) - // No brace, e.g. \input thing.tex instead of \input{thing}; - // or a numeric argument, such as \parindent0pt - if ((def->no_args > 0) && ((buffer[i] == 32) || (buffer[i] == '=') || (isdigit(buffer[i])))) + + if (def) { - if ((buffer[i] == 32) || (buffer[i] == '=')) - i ++; + i = j; - *parseToBrace = false; + // We want to check whether this is a space-consuming macro + // (e.g. {\bf word}) + // No brace, e.g. \input thing.tex instead of \input{thing}; + // or a numeric argument, such as \parindent0pt + if ((def->no_args > 0) && ((buffer[i] == 32) || (buffer[i] == '=') || (isdigit(buffer[i])))) + { + if ((buffer[i] == 32) || (buffer[i] == '=')) + i ++; + + *parseToBrace = false; + } + *pos = i; + ForbidWarning(def); + return def; } - *pos = i; - ForbidWarning(def); - return def; - } - return NULL; + return NULL; } void EatWhiteSpace(wxChar *buffer, int *pos) @@ -428,9 +423,9 @@ bool readInVerbatim = false; // Within a verbatim, but not nec. verbatiminput // detection of \verb yet. // #define CHECK_BRACES 1 -unsigned long leftCurley = 0; -unsigned long rightCurley = 0; -static wxString currentFileName = _T(""); +unsigned long leftCurly = 0; +unsigned long rightCurly = 0; +static wxString currentFileName = wxEmptyString; bool read_a_line(wxChar *buf) { @@ -443,7 +438,7 @@ bool read_a_line(wxChar *buf) int ch = -2; unsigned long bufIndex = 0; buf[0] = 0; - char lastChar = _T(' '); + int lastChar; while (ch != EOF && ch != 10) { @@ -452,7 +447,7 @@ bool read_a_line(wxChar *buf) wxString errBuf; errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."), LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(), MAX_LINE_BUFFER_SIZE); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); return false; } @@ -463,22 +458,22 @@ bool read_a_line(wxChar *buf) lastChar = ch; ch = getc(Inputs[CurrentInputIndex]); - if (checkCurleyBraces) + if (checkCurlyBraces) { if (ch == '{' && !readInVerbatim && lastChar != _T('\\')) - leftCurley++; + leftCurly++; if (ch == '}' && !readInVerbatim && lastChar != _T('\\')) { - rightCurley++; - if (rightCurley > leftCurley) + rightCurly++; + if (rightCurly > leftCurly) { wxString errBuf; - errBuf.Printf(_T("An extra right Curley brace ('}') was detected at line %lu inside file %s"), LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str()); - OnError((wxChar *)errBuf.c_str()); + errBuf.Printf(_T("An extra right Curly brace ('}') was detected at line %lu inside file %s"), LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str()); + OnError(errBuf); - // Reduce the count of right Curley braces, so the mismatched count + // Reduce the count of right Curly braces, so the mismatched count // isn't reported on every line that has a '}' after the first mismatch - rightCurley--; + rightCurly--; } } } @@ -492,7 +487,7 @@ bool read_a_line(wxChar *buf) if ((ch1 == 10) || (ch1 == 13)) { // Eliminate newline (10) following DOS linefeed - if (ch1 == 13) + if (ch1 == 13) getc(Inputs[CurrentInputIndex]); buf[bufIndex] = 0; IncrementLineNumber(); @@ -503,7 +498,7 @@ bool read_a_line(wxChar *buf) wxString errBuf; errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."), LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); return false; } wxStrcat(buf, _T("\\par")); @@ -518,11 +513,11 @@ bool read_a_line(wxChar *buf) wxString errBuf; errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."), LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); return false; } - buf[bufIndex] = ch; + buf[bufIndex] = (wxChar)ch; bufIndex ++; } } @@ -537,13 +532,13 @@ bool read_a_line(wxChar *buf) case 0xfc: // ü case 0xd6: // Ö case 0xc4: // Ä - case 0xdc: // Ü + case 0xdc: // Ü if (bufIndex+5 >= MAX_LINE_BUFFER_SIZE) { wxString errBuf; errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."), LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); return false; } buf[bufIndex++]='\\'; @@ -556,17 +551,17 @@ bool read_a_line(wxChar *buf) case 0xfc:buf[bufIndex++]='u';break; // ü case 0xd6:buf[bufIndex++]='O';break; // Ö case 0xc4:buf[bufIndex++]='A';break; // Ä - case 0xdc:buf[bufIndex++]='U';break; // Ü - } + case 0xdc:buf[bufIndex++]='U';break; // Ü + } buf[bufIndex++]='}'; break; - case 0xdf: // ß + case 0xdf: // ß if (bufIndex+5 >= MAX_LINE_BUFFER_SIZE) { wxString errBuf; errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."), LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); return false; } buf[bufIndex++]='\\'; @@ -574,21 +569,21 @@ bool read_a_line(wxChar *buf) buf[bufIndex++]='s'; buf[bufIndex++]='\\'; buf[bufIndex++]='/'; - break; + break; default: if (bufIndex >= MAX_LINE_BUFFER_SIZE) { wxString errBuf; errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."), LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); return false; } - // If the current character read in is a '_', we need to check + // If the current character read in is a '_', we need to check // whether there should be a '\' before it or not if (ch != '_') { - buf[bufIndex++] = ch; + buf[bufIndex++] = (wxChar)ch; break; } @@ -602,7 +597,7 @@ bool read_a_line(wxChar *buf) // wxString errBuf; // errBuf.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that should NOT have a '\\' before it."), // LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str()); -// OnError((wxChar *)errBuf.c_str()); +// OnError(errBuf); } } else @@ -613,7 +608,7 @@ bool read_a_line(wxChar *buf) wxString errBuf; errBuf.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it."), LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str()); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); } else if ((buf[bufIndex-1] != '\\') && (buf[0] != '%') && // If it is a comment line, then no warnings (wxStrncmp(buf, _T("\\input"), 6))) // do not report filenames that have underscores in them @@ -621,11 +616,11 @@ bool read_a_line(wxChar *buf) wxString errBuf; errBuf.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it."), LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str()); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); } } } - buf[bufIndex++] = ch; + buf[bufIndex++] = (wxChar)ch; break; } // switch } // else @@ -635,21 +630,21 @@ bool read_a_line(wxChar *buf) buf[bufIndex] = 0; fclose(Inputs[CurrentInputIndex]); Inputs[CurrentInputIndex] = NULL; - if (CurrentInputIndex > 0) + if (CurrentInputIndex > 0) ch = ' '; // No real end of file CurrentInputIndex --; - if (checkCurleyBraces) + if (checkCurlyBraces) { - if (leftCurley != rightCurley) + if (leftCurly != rightCurly) { wxString errBuf; - errBuf.Printf(_T("Curley braces do not match inside file %s\n%lu opens, %lu closes"), - (const wxChar*) currentFileName.c_str(),leftCurley,rightCurley); - OnError((wxChar *)errBuf.c_str()); + errBuf.Printf(_T("Curly braces do not match inside file %s\n%lu opens, %lu closes"), + (const wxChar*) currentFileName.c_str(),leftCurly,rightCurly); + OnError(errBuf); } - leftCurley = 0; - rightCurley = 0; + leftCurly = 0; + rightCurly = 0; } if (readingVerbatim) @@ -687,23 +682,23 @@ bool read_a_line(wxChar *buf) j -= 5; buf[j] = 0; } - + if (buf[j-1] == '}') buf[j-1] = 0; // Ignore final brace wxString actualFile = TexPathList.FindValidPath(fileName); currentFileName = actualFile; - if (actualFile == _T("")) + if (actualFile.empty()) { wxString errBuf; errBuf.Printf(_T("Could not find file: %s"),fileName); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); } else { wxString informStr; informStr.Printf(_T("Processing: %s"),actualFile.c_str()); - OnInform((wxChar *)informStr.c_str()); + OnInform(informStr); CurrentInputIndex ++; Inputs[CurrentInputIndex] = wxFopen(actualFile, _T("r")); @@ -753,7 +748,7 @@ bool read_a_line(wxChar *buf) buf[j] = 0; } - if (buf[j-1] == _T('}')) + if (buf[j-1] == _T('}')) buf[j-1] = 0; // Ignore final brace // Remove backslashes from name @@ -761,13 +756,13 @@ bool read_a_line(wxChar *buf) fileNameStr.Replace(_T("\\"), _T("")); // Ignore some types of input files (e.g. macro definition files) - wxChar *fileOnly = wxFileNameFromPath((wxChar*) (const wxChar*) fileNameStr); + wxString fileOnly = wxFileNameFromPath(fileNameStr); currentFileName = fileOnly; if (IgnorableInputFiles.Member(fileOnly)) return read_a_line(buf); wxString actualFile = TexPathList.FindValidPath(fileNameStr); - if (actualFile == _T("")) + if (actualFile.empty()) { wxChar buf2[400]; wxSnprintf(buf2, sizeof(buf2), _T("%s.tex"), fileNameStr.c_str()); @@ -775,11 +770,11 @@ bool read_a_line(wxChar *buf) } currentFileName = actualFile; - if (actualFile == _T("")) + if (actualFile.empty()) { wxString errBuf; errBuf.Printf(_T("Could not find file: %s"),fileName); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); } else { @@ -789,7 +784,7 @@ bool read_a_line(wxChar *buf) wxString informStr; informStr.Printf(_T("Processing: %s"),actualFile.c_str()); - OnInform((wxChar *)informStr.c_str()); + OnInform(informStr); CurrentInputIndex ++; Inputs[CurrentInputIndex] = wxFopen(actualFile, _T("r")); @@ -803,7 +798,7 @@ bool read_a_line(wxChar *buf) wxString errBuf; errBuf.Printf(_T("Could not open include file %s"), (const wxChar*) actualFile); CurrentInputIndex --; - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); } } bool succ = read_a_line(buf); @@ -813,7 +808,7 @@ bool read_a_line(wxChar *buf) if (checkSyntax) { wxString bufStr = buf; - for (int index=0; syntaxTokens[index] != wxEmptyString; index++) + for (int index=0; !syntaxTokens[index].empty(); index++) { size_t pos = bufStr.find(syntaxTokens[index]); if (pos != wxString::npos && pos != 0) @@ -836,7 +831,7 @@ bool read_a_line(wxChar *buf) LineNumbers[CurrentInputIndex], currentFileName.c_str()); } - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); } } } @@ -849,14 +844,14 @@ bool read_a_line(wxChar *buf) wxStrncmp(buf, _T("\\end{toocomplex}"), 16) == 0) readInVerbatim = false; - if (checkCurleyBraces) + if (checkCurlyBraces) { - if (ch == EOF && leftCurley != rightCurley) + if (ch == EOF && leftCurly != rightCurly) { wxString errBuf; - errBuf.Printf(_T("Curley braces do not match inside file %s\n%lu opens, %lu closes"), - (const wxChar*) currentFileName.c_str(),leftCurley,rightCurley); - OnError((wxChar *)errBuf.c_str()); + errBuf.Printf(_T("Curly braces do not match inside file %s\n%lu opens, %lu closes"), + (const wxChar*) currentFileName.c_str(),leftCurly,rightCurly); + OnError(errBuf); } } @@ -901,7 +896,7 @@ bool ParseNewCommand(wxChar *buffer, int *pos) int braceCount = 0; while (!end) { - char ch = buffer[*pos]; + wxChar ch = buffer[*pos]; if (ch == _T('{')) braceCount ++; else if (ch == _T('}')) @@ -942,7 +937,7 @@ void MacroError(wxChar *buffer) wxChar macroBuf[200]; macroBuf[0] = '\\'; int i = 1; - char ch; + wxChar ch; while (((ch = buffer[i-1]) != '\n') && (ch != 0)) { macroBuf[i] = ch; @@ -954,7 +949,7 @@ void MacroError(wxChar *buffer) errBuf.Printf(_T("Could not find macro: %s at line %d, file %s"), macroBuf, (int)(LineNumbers[CurrentInputIndex]-1), FileNames[CurrentInputIndex]); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); if (wxStrcmp(macroBuf,_T("\\end{document}")) == 0) { @@ -967,7 +962,7 @@ void MacroError(wxChar *buffer) * Parse an argument. * 'environment' specifies the name of the macro IFF if we're looking for the end * of an environment, e.g. \end{itemize}. Otherwise it's NULL. - * 'parseToBrace' is TRUE if the argument should extend to the next right brace, + * 'parseToBrace' is true if the argument should extend to the next right brace, * e.g. in {\bf an argument} as opposed to \vskip 30pt * */ @@ -975,7 +970,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha { Tex2RTFYield(); if (stopRunning) return pos; - + bool eof = false; BigBuffer[0] = 0; int buf_ptr = 0; @@ -1005,7 +1000,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha } } */ - + // If not parsing to brace, just read the next word // (e.g. \vskip 20pt) if (!parseToBrace) @@ -1014,7 +1009,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha while (!eof && ch != 13 && ch != 32 && ch != 10 && ch != 0 && ch != '{') { - BigBuffer[buf_ptr] = ch; + BigBuffer[buf_ptr] = (wxChar)ch; buf_ptr ++; pos ++; ch = buffer[pos]; @@ -1093,15 +1088,15 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha } } - char ch = buffer[pos]; + wxChar wxCh = buffer[pos]; // End of optional argument -- pretend it's right brace for simplicity - if (thisArg->optional && (ch == ']')) - ch = '}'; + if (thisArg->optional && (wxCh == _T(']'))) + wxCh = _T('}'); - switch (ch) + switch (wxCh) { case 0: - case '}': // End of argument + case _T('}'): // End of argument { if (buf_ptr > 0) { @@ -1110,10 +1105,10 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha chunk->value = copystring(BigBuffer); children.Append((wxObject *)chunk); } - if (ch == '}') pos ++; + if (wxCh == _T('}')) pos ++; return pos; } - case '\\': + case _T('\\'): { if (buf_ptr > 0) // Finish off the string we've read so far { @@ -1124,7 +1119,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha children.Append((wxObject *)chunk); } pos ++; - + // Try matching \end{environment} if (environment && FindEndEnvironment(buffer, &pos, environment)) { @@ -1154,8 +1149,8 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha bool end = false; while (!end) { - int ch = buffer[pos]; - if (ch == '}') + wxChar ch = buffer[pos]; + if (ch == _T('}')) { noBraces --; if (noBraces == 0) @@ -1165,26 +1160,26 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha } else { - wxTex2RTFBuffer[i] = '}'; + wxTex2RTFBuffer[i] = _T('}'); i ++; } pos ++; } - else if (ch == '{') + else if (ch == _T('{')) { - wxTex2RTFBuffer[i] = '{'; + wxTex2RTFBuffer[i] = _T('{'); i ++; pos ++; } - else if (ch == '\\' && buffer[pos+1] == '}') + else if (ch == _T('\\') && buffer[pos+1] == _T('}')) { - wxTex2RTFBuffer[i] = '}'; + wxTex2RTFBuffer[i] = _T('}'); pos += 2; i++; } - else if (ch == '\\' && buffer[pos+1] == '{') + else if (ch == _T('\\') && buffer[pos+1] == _T('{')) { - wxTex2RTFBuffer[i] = '{'; + wxTex2RTFBuffer[i] = _T('{'); pos += 2; i++; } @@ -1218,11 +1213,11 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha else if (wxStrncmp(buffer+pos, _T("verb"), 4) == 0) { pos += 4; - if (buffer[pos] == '*') + if (buffer[pos] == _T('*')) pos ++; - // Find the delimiter character - int ch = buffer[pos]; + // Find the delimiter character + wxChar ch = buffer[pos]; pos ++; // Now at start of verbatim text int j = pos; @@ -1256,8 +1251,8 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha children.Append((wxObject *)chunk); } - else - { + else + { wxChar *env = NULL; bool tmpParseToBrace = true; TexMacroDef *def = MatchMacro(buffer, &pos, &env, &tmpParseToBrace); @@ -1275,16 +1270,20 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha children.Append((wxObject *)chunk); // Eliminate newline after a \begin{} or a \\ if possible - if (env || wxStrcmp(def->name, _T("\\")) == 0) - if (buffer[pos] == 13) - { + if ((env || wxStrcmp(def->name, _T("\\")) == 0) && (buffer[pos] == 13)) + { pos ++; if (buffer[pos] == 10) pos ++; - } + } - pos = ParseMacroBody(def->name, chunk, chunk->no_args, - buffer, pos, env, tmpParseToBrace, customMacroArgs); + pos = ParseMacroBody(def->name, + chunk, chunk->no_args, + buffer, + pos, + env, + tmpParseToBrace, + customMacroArgs); // If custom macro, parse the body substituting the above found args. if (customMacro) @@ -1297,7 +1296,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha wxStrcat(macroBuf, _T("}")); ParseArg(thisArg, children, macroBuf, 0, NULL, true, chunk); } - + // delete chunk; // Might delete children } } @@ -1310,10 +1309,10 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha } // Parse constructs like {\bf thing} as if they were // \bf{thing} - case '{': + case _T('{'): { pos ++; - if (buffer[pos] == '\\') + if (buffer[pos] == _T('\\')) { if (buf_ptr > 0) { @@ -1353,7 +1352,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha wxStrcat(macroBuf, _T("}")); ParseArg(thisArg, children, macroBuf, 0, NULL, true, chunk); } - + // delete chunk; // Might delete children } } @@ -1363,7 +1362,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha } } else - { + { /* * If all else fails, we assume that we have * a pair of braces on their own, so return a `dummy' macro @@ -1396,10 +1395,10 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha arg->macroId = chunk->macroId; pos = ParseArg(arg, arg->children, buffer, pos, NULL, true, customMacroArgs); - } + } break; } - case '$': + case _T('$'): { if (buf_ptr > 0) { @@ -1412,7 +1411,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha pos ++; - if (buffer[pos] == '$') + if (buffer[pos] == _T('$')) { TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO); chunk->no_args = 0; @@ -1431,7 +1430,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha } break; } - case '~': + case _T('~'): { if (buf_ptr > 0) { @@ -1450,7 +1449,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha children.Append((wxObject *)chunk); break; } - case '#': // Either treat as a special TeX character or as a macro arg + case _T('#'): // Either treat as a special TeX character or as a macro arg { if (buf_ptr > 0) { @@ -1486,12 +1485,12 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha } break; } - case '&': + case _T('&'): { // Remove white space before and after the ampersand, // since this is probably a table column separator with // some convenient -- but useless -- white space in the text. - while ((buf_ptr > 0) && ((BigBuffer[buf_ptr-1] == ' ') || (BigBuffer[buf_ptr-1] == 9))) + while ((buf_ptr > 0) && ((BigBuffer[buf_ptr-1] == _T(' ')) || (BigBuffer[buf_ptr-1] == 9))) buf_ptr --; if (buf_ptr > 0) @@ -1505,7 +1504,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha pos ++; - while (buffer[pos] == ' ' || buffer[pos] == 9) + while (buffer[pos] == _T(' ') || buffer[pos] == 9) pos ++; TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO); @@ -1516,13 +1515,13 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha break; } // Eliminate end-of-line comment - case '%': + case _T('%'): { - ch = buffer[pos]; - while (ch != 10 && ch != 13 && ch != 0) + wxCh = buffer[pos]; + while (wxCh != 10 && wxCh != 13 && wxCh != 0) { pos ++; - ch = buffer[pos]; + wxCh = buffer[pos]; } if (buffer[pos] == 10 || buffer[pos] == 13) { @@ -1534,7 +1533,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha // Eliminate tab case 9: { - BigBuffer[buf_ptr] = ' '; + BigBuffer[buf_ptr] = _T(' '); BigBuffer[buf_ptr+1] = 0; buf_ptr ++; pos ++; @@ -1542,7 +1541,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha } default: { - BigBuffer[buf_ptr] = ch; + BigBuffer[buf_ptr] = wxCh; BigBuffer[buf_ptr+1] = 0; buf_ptr ++; pos ++; @@ -1557,7 +1556,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha * Consume as many arguments as the macro definition specifies * */ - + int ParseMacroBody(const wxChar *WXUNUSED(macro_name), TexChunk *parent, int no_args, wxChar *buffer, int pos, wxChar *environment, bool parseToBrace, @@ -1633,7 +1632,7 @@ int ParseMacroBody(const wxChar *WXUNUSED(macro_name), TexChunk *parent, tmpBuffer = tmpBuffer.Mid(0,tmpBuffer.length()-4); } errBuf.Printf(_T("Missing macro argument in the line:\n\t%s\n"),tmpBuffer.c_str()); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); } } @@ -1663,34 +1662,34 @@ int ParseMacroBody(const wxChar *WXUNUSED(macro_name), TexChunk *parent, return pos; } -bool TexLoadFile(wxChar *filename) +bool TexLoadFile(const wxString& filename) { - static wxChar *line_buffer; - stopRunning = false; - wxStrcpy(TexFileRoot, filename); - StripExtension(TexFileRoot); - wxSnprintf(TexBibName, 300, _T("%s.bb"), TexFileRoot); - wxSnprintf(TexTmpBibName, 300, _T("%s.bb1"), TexFileRoot); - - TexPathList.EnsureFileAccessible(filename); - - if (line_buffer) - delete line_buffer; - - line_buffer = new wxChar[MAX_LINE_BUFFER_SIZE]; - - Inputs[0] = wxFopen(filename, _T("r")); - LineNumbers[0] = 1; - FileNames[0] = copystring(filename); - if (Inputs[0]) - { - read_a_line(line_buffer); - ParseMacroBody(_T("toplevel"), TopLevel, 1, line_buffer, 0, NULL, true); - if (Inputs[0]) fclose(Inputs[0]); - return true; - } + static wxChar *line_buffer; + stopRunning = false; + wxStrcpy(TexFileRoot, filename); + StripExtension(TexFileRoot); + wxSnprintf(TexBibName, 300, _T("%s.bb"), TexFileRoot); + wxSnprintf(TexTmpBibName, 300, _T("%s.bb1"), TexFileRoot); - return false; + TexPathList.EnsureFileAccessible(filename); + + if (line_buffer) + delete line_buffer; + + line_buffer = new wxChar[MAX_LINE_BUFFER_SIZE]; + + Inputs[0] = wxFopen(filename, _T("r")); + LineNumbers[0] = 1; + FileNames[0] = copystring(filename); + if (Inputs[0]) + { + read_a_line(line_buffer); + ParseMacroBody(_T("toplevel"), TopLevel, 1, line_buffer, 0, NULL, true); + if (Inputs[0]) fclose(Inputs[0]); + return true; + } + + return false; } TexMacroDef::TexMacroDef(int the_id, const wxChar *the_name, int n, bool ig, bool forbidLevel) @@ -1725,7 +1724,7 @@ TexChunk::TexChunk(TexChunk& toCopy) no_args = toCopy.no_args; argn = toCopy.argn; macroId = toCopy.macroId; - + // if (toCopy.name) // name = copystring(toCopy.name); // else @@ -1736,7 +1735,7 @@ TexChunk::TexChunk(TexChunk& toCopy) value = copystring(toCopy.value); else value = NULL; - + optional = toCopy.optional; wxNode *node = toCopy.children.GetFirst(); while (node) @@ -1776,7 +1775,7 @@ int GetNoArgs(void) // Number of args for this macro * only!) * */ - + void GetArgData1(TexChunk *chunk) { switch (chunk->type) @@ -2066,7 +2065,7 @@ void TexCleanUp(void) refNode = TexReferences.Next(); } TexReferences.Clear(); - + wxNode* bibNode = BibList.GetFirst(); while (bibNode) { @@ -2506,7 +2505,7 @@ void DefineDefaultMacros(void) AddMacroDef(ltUPSHAPE, _T("upshape"), 1); AddMacroDef(ltURLREF, _T("urlref"), 2); AddMacroDef(ltUSEPACKAGE, _T("usepackage"), 1); - + AddMacroDef(ltVAREPSILON, _T("varepsilon"), 0); AddMacroDef(ltVARPHI, _T("varphi"), 0); AddMacroDef(ltVARPI, _T("varpi"), 0); @@ -2570,7 +2569,7 @@ void DefineDefaultMacros(void) * Default behaviour, should be called by client if can't match locally. * */ - + // Called on start/end of macro examination void DefaultOnMacro(int macroId, int no_args, bool start) { @@ -2620,11 +2619,21 @@ void DefaultOnMacro(int macroId, int no_args, bool start) case ltCINSERT: if (start) - TexOutput(_T("<<"), true); + { + if (convertMode == TEX_HTML) + TexOutput(_T("<<")); + else + TexOutput(_T("<<"), true); + } break; case ltCEXTRACT: if (start) - TexOutput(_T(">>"), true); + { + if (convertMode == TEX_HTML) + TexOutput(_T(">>")); + else + TexOutput(_T(">>"), true); + } break; case ltDESTRUCT: if (start) @@ -2691,7 +2700,7 @@ void DefaultOnMacro(int macroId, int no_args, bool start) TexOutput(_T("(r)"), true); break; case ltBACKSLASH: - if (start) + if (start) TexOutput(_T("\\"), true); break; case ltLDOTS: @@ -2713,7 +2722,8 @@ void DefaultOnMacro(int macroId, int no_args, bool start) break; case ltPOUNDS: if (start) - TexOutput(_T("£"), true); + // FIXME: this is valid only if the output is iso-8859-1 + TexOutput(wxString::FromAscii("£"), true); break; case ltSPECIALDOUBLEDOLLAR: // Interpret as center OnMacro(ltCENTER, no_args, start); @@ -2858,10 +2868,22 @@ void DefaultOnMacro(int macroId, int no_args, bool start) // Binary operation symbols case ltLE: case ltLEQ: - if (start) TexOutput(_T("<=")); + if (start) + { + if (convertMode == TEX_HTML) + TexOutput(_T("<=")); + else + TexOutput(_T("<=")); + } break; case ltLL: - if (start) TexOutput(_T("<<")); + if (start) + { + if (convertMode == TEX_HTML) + TexOutput(_T("<<")); + else + TexOutput(_T("<<")); + } break; case ltSUBSET: if (start) TexOutput(_T("SUBSET")); @@ -2880,10 +2902,24 @@ void DefaultOnMacro(int macroId, int no_args, bool start) break; case ltGE: case ltGEQ: - if (start) TexOutput(_T(">=")); + { + if (start) + { + if (convertMode == TEX_HTML) + TexOutput(_T(">=")); + else + TexOutput(_T(">=")); + } break; + } case ltGG: - if (start) TexOutput(_T(">>")); + if (start) + { + if (convertMode == TEX_HTML) + TexOutput(_T(">>")); + else + TexOutput(_T(">>")); + } break; case ltSUPSET: if (start) TexOutput(_T("SUPSET")); @@ -2965,22 +3001,58 @@ void DefaultOnMacro(int macroId, int no_args, bool start) // Arrows case ltLEFTARROW: - if (start) TexOutput(_T("<--")); + if (start) + { + if (convertMode == TEX_HTML) + TexOutput(_T("<--")); + else + TexOutput(_T("<--")); + } break; case ltLEFTARROW2: - if (start) TexOutput(_T("<==")); + if (start) + { + if (convertMode == TEX_HTML) + TexOutput(_T("<==")); + else + TexOutput(_T("<==")); + } break; case ltRIGHTARROW: - if (start) TexOutput(_T("-->")); + if (start) + { + if (convertMode == TEX_HTML) + TexOutput(_T("-->")); + else + TexOutput(_T("-->")); + } break; case ltRIGHTARROW2: - if (start) TexOutput(_T("==>")); + if (start) + { + if (convertMode == TEX_HTML) + TexOutput(_T("==>")); + else + TexOutput(_T("==>")); + } break; case ltLEFTRIGHTARROW: - if (start) TexOutput(_T("<-->")); + if (start) + { + if (convertMode == TEX_HTML) + TexOutput(_T("<-->")); + else + TexOutput(_T("<-->")); + } break; case ltLEFTRIGHTARROW2: - if (start) TexOutput(_T("<==>")); + if (start) + { + if (convertMode == TEX_HTML) + TexOutput(_T("<==>")); + else + TexOutput(_T("<==>")); + } break; case ltUPARROW: if (start) TexOutput(_T("UPARROW")); @@ -3174,8 +3246,8 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) else { wxString informBuf; - informBuf.Printf(_T("Warning: unresolved reference '%s'"), refName); - OnInform((wxChar *)informBuf.c_str()); + informBuf.Printf(_T("Warning: unresolved reference '%s'"), refName); + OnInform(informBuf); } } else TexOutput(_T("??"), true); @@ -3222,7 +3294,7 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) DocumentStyle = LATEX_LETTER; else if (wxStrncmp(DocumentStyleString, _T("slides"), 6) == 0) DocumentStyle = LATEX_SLIDES; - + if (StringMatch(_T("10"), DocumentStyleString)) SetFontSizes(10); else if (StringMatch(_T("11"), DocumentStyleString)) @@ -3329,7 +3401,7 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) { wxString informBuf; informBuf.Printf(_T("Warning: unresolved citation %s."), citeKey); - OnInform((wxChar *)informBuf.c_str()); + OnInform(informBuf); } } citeKey = ParseMultifieldString(citeKeys, &pos); @@ -3436,12 +3508,12 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) if (fd) { ch = getc(fd); - smallBuf[0] = ch; + smallBuf[0] = (wxChar)ch; while (ch != EOF) { TexOutput(smallBuf); ch = getc(fd); - smallBuf[0] = ch; + smallBuf[0] = (wxChar)ch; } fclose(fd); } @@ -3459,25 +3531,25 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) wxChar fileBuf[300]; wxStrcpy(fileBuf, bibFile); wxString actualFile = TexPathList.FindValidPath(fileBuf); - if (actualFile == _T("")) + if (actualFile.empty()) { wxStrcat(fileBuf, _T(".bib")); actualFile = TexPathList.FindValidPath(fileBuf); } - if (actualFile != _T("")) + if (!actualFile.empty()) { if (!ReadBib((wxChar*) (const wxChar*) actualFile)) { wxString errBuf; errBuf.Printf(_T(".bib file %s not found or malformed"), (const wxChar*) actualFile); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); } } else { wxString errBuf; errBuf.Printf(_T(".bib file %s not found"), fileBuf); - OnError((wxChar *)errBuf.c_str()); + OnError(errBuf); } bibFile = ParseMultifieldString(allFiles, &pos); } @@ -3515,7 +3587,7 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) wxChar *s1 = copystring(s); int i; for (i = 0; i < (int)wxStrlen(s); i++) - s1[i] = wxToupper(s[i]); + s1[i] = (wxChar)wxToupper(s[i]); TexOutput(s1); delete[] s1; return false; @@ -3535,7 +3607,7 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) wxChar *s1 = copystring(s); int i; for (i = 0; i < (int)wxStrlen(s); i++) - s1[i] = wxTolower(s[i]); + s1[i] = (wxChar)wxTolower(s[i]); TexOutput(s1); delete[] s1; return false; @@ -3555,7 +3627,7 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) wxChar *s1 = copystring(s); int i; for (i = 0; i < (int)wxStrlen(s); i++) - s1[i] = wxToupper(s[i]); + s1[i] = (wxChar)wxToupper(s[i]); TexOutput(s1); delete[] s1; return false; @@ -3713,4 +3785,3 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) } return true; } -