X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1b392b3a6846e7cc3272b95de5a7cc2c05bfb8d5..3903f408241aedc3b2f5e24349d0ac939ba9164c:/utils/tex2rtf/src/tex2any.cpp diff --git a/utils/tex2rtf/src/tex2any.cpp b/utils/tex2rtf/src/tex2any.cpp index 8b1ef42b5d..33466d1a93 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" @@ -305,81 +301,84 @@ void ForbidWarning(TexMacroDef *def) TexMacroDef *MatchMacro(wxChar *buffer, int *pos, wxChar **env, bool *parseToBrace) { - *parseToBrace = true; - int i = (*pos); - TexMacroDef *def = NULL; - wxChar macroBuf[40]; + *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; - - 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) @@ -430,7 +429,7 @@ bool readInVerbatim = false; // Within a verbatim, but not nec. verbatiminput unsigned long leftCurly = 0; unsigned long rightCurly = 0; -static wxString currentFileName = _T(""); +static wxString currentFileName = wxEmptyString; bool read_a_line(wxChar *buf) { @@ -693,7 +692,7 @@ bool read_a_line(wxChar *buf) wxString actualFile = TexPathList.FindValidPath(fileName); currentFileName = actualFile; - if (actualFile == _T("")) + if (actualFile.empty()) { wxString errBuf; errBuf.Printf(_T("Could not find file: %s"),fileName); @@ -767,7 +766,7 @@ bool read_a_line(wxChar *buf) 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,7 +774,7 @@ 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); @@ -813,7 +812,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) @@ -1222,7 +1221,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha pos ++; // Find the delimiter character - int ch = buffer[pos]; + wxChar ch = buffer[pos]; pos ++; // Now at start of verbatim text int j = pos; @@ -1275,16 +1274,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) @@ -1663,34 +1666,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); + 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); + TexPathList.EnsureFileAccessible(filename); - if (line_buffer) - delete line_buffer; + if (line_buffer) + delete line_buffer; - line_buffer = new wxChar[MAX_LINE_BUFFER_SIZE]; + 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; - } + 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; + return false; } TexMacroDef::TexMacroDef(int the_id, const wxChar *the_name, int n, bool ig, bool forbidLevel) @@ -2620,11 +2623,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) @@ -2859,10 +2872,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")); @@ -2881,10 +2906,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")); @@ -2966,22 +3005,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")); @@ -3460,12 +3535,12 @@ 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)) { @@ -3714,4 +3789,3 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) } return true; } -