X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/88fd7006f473d24685c36974315f6ff6e6f6d727..e0b15ca79530689420dff1928f15d2905a746b42:/utils/tex2rtf/src/tex2any.cpp diff --git a/utils/tex2rtf/src/tex2any.cpp b/utils/tex2rtf/src/tex2any.cpp index 8400d87a13..348ef99882 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" @@ -430,7 +426,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 +689,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 +763,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 +771,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 +809,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) @@ -901,7 +897,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 +938,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; @@ -1093,15 +1089,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 +1106,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 { @@ -1154,8 +1150,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,32 +1161,32 @@ 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++; } else { - wxTex2RTFBuffer[i] = (wxChar)ch; + wxTex2RTFBuffer[i] = ch; pos ++; i ++; if (ch == 0) @@ -1218,11 +1214,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]; + wxChar ch = buffer[pos]; pos ++; // Now at start of verbatim text int j = pos; @@ -1256,8 +1252,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); @@ -1310,10 +1306,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) { @@ -1363,7 +1359,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 +1392,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 +1408,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 +1427,7 @@ int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxCha } break; } - case '~': + case _T('~'): { if (buf_ptr > 0) { @@ -1450,7 +1446,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 +1482,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 +1501,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 +1512,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 +1530,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 +1538,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 ++; @@ -1663,34 +1659,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 +2616,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) @@ -2713,7 +2719,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 +2865,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 +2899,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 +2998,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")); @@ -3459,12 +3528,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)) { @@ -3713,4 +3782,3 @@ bool DefaultOnArgument(int macroId, int arg_no, bool start) } return true; } -