X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e6a0295cdda5045864b4bdccf29cf692cc9389cd..c61fb03543e0288830bbf39651eea19e9e003088:/utils/tex2rtf/src/htmlutil.cpp diff --git a/utils/tex2rtf/src/htmlutil.cpp b/utils/tex2rtf/src/htmlutil.cpp index a04e88baa7..1e8def80c6 100644 --- a/utils/tex2rtf/src/htmlutil.cpp +++ b/utils/tex2rtf/src/htmlutil.cpp @@ -2,7 +2,8 @@ // Name: htmlutil.cpp // Purpose: Converts Latex to HTML // Author: Julian Smart -// Modified by: +// Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support +// Ron Lee // Created: 7.9.93 // RCS-ID: $Id$ // Copyright: (c) Julian Smart @@ -69,18 +70,18 @@ FILE *FrameContents = NULL; FILE *Titlepage = NULL; // FILE *FrameTitlepage = NULL; int fileId = 0; -bool subsectionStarted = FALSE; +bool subsectionStarted = false; // Which column of a row are we in? (Assumes no nested tables, of course) int currentColumn = 0; // Are we in verbatim mode? If so, format differently. -static bool inVerbatim = FALSE; +static bool inVerbatim = false; // Need to know whether we're in a table or figure for benefit // of listoffigures/listoftables -static bool inFigure = FALSE; -static bool inTable = FALSE; +static bool inFigure = false; +static bool inTable = false; // This is defined in the Tex2Any library. extern wxChar *BigBuffer; @@ -198,13 +199,13 @@ void ReopenFile(FILE **fd, wxChar **fileName, const wxChar *label) wxChar buf[400]; if (truncateFilenames) { - wxSprintf(buf, _T("%s%d.htm"), FileRoot, fileId); + wxSnprintf(buf, sizeof(buf), _T("%s%d.htm"), FileRoot, fileId); } else { if (fileId == 1) gs_filenames.Add(wxEmptyString); - wxSprintf(buf, _T("%s_%s.html"), FileRoot, label); + wxSnprintf(buf, sizeof(buf), _T("%s_%s.html"), FileRoot, label); gs_filenames.Add(buf); } if (*fileName) delete[] *fileName; @@ -254,7 +255,7 @@ void ReopenSectionContentsFile(void) void ProcessText2HTML(TexChunk *chunk) { - bool changed = FALSE; + bool changed = false; int ptr = 0; int i = 0; char ch = 1; @@ -270,19 +271,19 @@ void ProcessText2HTML(TexChunk *chunk) { BigBuffer[ptr] = 0; wxStrcat(BigBuffer, _T("
\n\n")); ptr += 5; i += 2; - changed = TRUE; + changed = true; } else if (!inVerbatim && ch == '`' && (len >= i+1 && chunk->value[i+1] == '`')) { BigBuffer[ptr] = '"'; ptr ++; i += 2; - changed = TRUE; + changed = true; } else if (!inVerbatim && ch == '`') // Change ` to ' { BigBuffer[ptr] = 39; ptr ++; i += 1; - changed = TRUE; + changed = true; } else if (ch == '<') // Change < to < { @@ -290,7 +291,7 @@ void ProcessText2HTML(TexChunk *chunk) wxStrcat(BigBuffer, _T("<")); ptr += 4; i += 1; - changed = TRUE; + changed = true; } else if (ch == '>') // Change > to > { @@ -298,7 +299,7 @@ void ProcessText2HTML(TexChunk *chunk) wxStrcat(BigBuffer, _T(">")); ptr += 4; i += 1; - changed = TRUE; + changed = true; } else { @@ -339,7 +340,7 @@ void Text2HTML(TexChunk *chunk) return; if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB || def->macroId == ltSPECIAL)) - inVerbatim = TRUE; + inVerbatim = true; wxNode *node = chunk->children.GetFirst(); while (node) @@ -350,7 +351,7 @@ void Text2HTML(TexChunk *chunk) } if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB || def->macroId == ltSPECIAL)) - inVerbatim = FALSE; + inVerbatim = false; break; } @@ -398,7 +399,9 @@ void AddBrowseButtons(wxChar *upLabel, wxChar *upFilename, { // contentsReference = ""; contentsReference = contentsReferenceBuf; - wxSprintf(contentsReference, _T(""), ConvertCase(_T("contents.gif"))); + wxSnprintf(contentsReference, sizeof(contentsReferenceBuf), + _T(""), + ConvertCase(_T("contents.gif"))); } wxChar *upReference; // no need to initialize because always assigned below @@ -408,7 +411,9 @@ void AddBrowseButtons(wxChar *upLabel, wxChar *upFilename, { // upReference = ""; upReference = upReferenceBuf; - wxSprintf(upReference, _T(""), ConvertCase(_T("up.gif"))); + wxSnprintf(upReference, sizeof(upReferenceBuf), + _T(""), + ConvertCase(_T("up.gif"))); } wxChar *backReference; // no need to initialize because always assigned below @@ -418,7 +423,9 @@ void AddBrowseButtons(wxChar *upLabel, wxChar *upFilename, { // backReference = ""; backReference = backReferenceBuf; - wxSprintf(backReference, _T(""), ConvertCase(_T("back.gif"))); + wxSnprintf(backReference, sizeof(backReferenceBuf), + _T(""), + ConvertCase(_T("back.gif"))); } wxChar *forwardReference; // no need to initialize because always assigned below @@ -428,7 +435,9 @@ void AddBrowseButtons(wxChar *upLabel, wxChar *upFilename, { // forwardReference = ""; forwardReference = forwardReferenceBuf; - wxSprintf(forwardReference, _T(""), ConvertCase(_T("forward.gif"))); + wxSnprintf(forwardReference, sizeof(forwardReferenceBuf), + _T(""), + ConvertCase(_T("forward.gif"))); } TexOutput(_T("
\n")); + wxSnprintf(buf, sizeof(buf), _T("\n")); TexOutput(buf); } else TexOutput(_T("\n")); @@ -1453,13 +1475,13 @@ void HTMLOnMacro(int macroId, int no_args, bool start) case ltCOPYRIGHT: { if (start) - TexOutput(_T("©"), TRUE); + TexOutput(_T("©"), true); break; } case ltREGISTERED: { if (start) - TexOutput(_T("®"), TRUE); + TexOutput(_T("®"), true); break; } // Arrows @@ -1682,18 +1704,18 @@ void HTMLOnMacro(int macroId, int no_args, bool start) figureNo ++; if (DocumentStyle != LATEX_ARTICLE) - wxSprintf(figBuf, _T("%s %d.%d: "), FigureNameString, chapterNo, figureNo); + wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d.%d: "), FigureNameString, chapterNo, figureNo); else - wxSprintf(figBuf, _T("%s %d: "), FigureNameString, figureNo); + wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d: "), FigureNameString, figureNo); } else { tableNo ++; if (DocumentStyle != LATEX_ARTICLE) - wxSprintf(figBuf, _T("%s %d.%d: "), TableNameString, chapterNo, tableNo); + wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d.%d: "), TableNameString, chapterNo, tableNo); else - wxSprintf(figBuf, _T("%s %d: "), TableNameString, tableNo); + wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d: "), TableNameString, tableNo); } TexOutput(figBuf); @@ -1720,14 +1742,14 @@ void HTMLOnMacro(int macroId, int no_args, bool start) } case ltFIGURE: { - if (start) inFigure = TRUE; - else inFigure = FALSE; + if (start) inFigure = true; + else inFigure = false; break; } case ltTABLE: { - if (start) inTable = TRUE; - else inTable = FALSE; + if (start) inTable = true; + else inTable = false; break; } default: @@ -1757,7 +1779,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) { if (!start && (arg_no == 1)) currentSection = GetArgChunk(); - return FALSE; + return false; } case ltFUNC: { @@ -1882,19 +1904,19 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) { TexOutput(sec); } - return FALSE; + return false; } break; } case ltURLREF: { if (IsArgOptional()) - return FALSE; + return false; else if ((GetNoArgs() - arg_no) == 1) { if (start) helpRefText = GetArgChunk(); - return FALSE; + return false; } else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional { @@ -1902,15 +1924,15 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) { TexChunk *ref = GetArgChunk(); TexOutput(_T("")); if (helpRefText) TraverseChildrenFromChunk(helpRefText); TexOutput(_T("")); } - return FALSE; + return false; } break; } @@ -1922,13 +1944,13 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) { if (start) helpRefFilename = GetArgChunk(); - return FALSE; + return false; } if ((GetNoArgs() - arg_no) == 1) { if (start) helpRefText = GetArgChunk(); - return FALSE; + return false; } else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional { @@ -1977,7 +1999,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } else TexOutput(_T("??")); } - return FALSE; + return false; } break; } @@ -2064,12 +2086,12 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) TexOutput(_T("Picture\n")); - wxSprintf(buf, _T("Warning: could not find an inline XBM/GIF for %s."), filename); + wxSnprintf(buf, sizeof(buf), _T("Warning: could not find an inline XBM/GIF for %s."), filename); OnInform(buf); } } } - return FALSE; + return false; } // First arg is PSBOX spec (ignored), second is image file, third is map name. case ltIMAGEMAP: @@ -2096,7 +2118,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (f == _T("")) { wxChar buf[300]; - wxSprintf(buf, _T("Warning: could not find an inline XBM/GIF for %s."), filename); + wxSnprintf(buf, sizeof(buf), _T("Warning: could not find an inline XBM/GIF for %s."), filename); OnInform(buf); } delete[] filename; @@ -2140,15 +2162,15 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) imageFile = NULL; } } - return FALSE; + return false; } case ltINDENTED : { if ( arg_no == 1 ) - return FALSE; + return false; else { - return TRUE; + return true; } } case ltITEM: @@ -2156,9 +2178,9 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (start) { descriptionItemArg = GetArgChunk(); - return FALSE; + return false; } - return TRUE; + return true; } case ltTWOCOLITEM: case ltTWOCOLITEMRULED: @@ -2175,7 +2197,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) // DHS if (TwoColWidthA > -1) { wxChar buf[100]; - wxSprintf(buf,_T("\n\n"),TwoColWidthA); + wxSnprintf(buf, sizeof(buf), _T("\n \n"),TwoColWidthA); TexOutput(buf); } else TexOutput(_T("\n \n")); } - return TRUE; + return true; } case ltNUMBEREDBIBITEM: { @@ -2219,18 +2241,18 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (ref) { if (ref->sectionNumber) delete[] ref->sectionNumber; - wxSprintf(buf, _T("[%d]"), citeCount); + wxSnprintf(buf, sizeof(buf), _T("[%d]"), citeCount); ref->sectionNumber = copystring(buf); } - wxSprintf(buf, _T("\n \n")); @@ -2189,7 +2211,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if ( start ) { if (TwoColWidthB > -1) { wxChar buf[100]; - wxSprintf(buf,_T("\n \n"),TwoColWidthB); + wxSnprintf(buf, sizeof(buf), _T("\n \n"),TwoColWidthB); TexOutput(buf); } else TexOutput(_T("\n \n")); @@ -2197,7 +2219,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } else TexOutput(_T("\n
\n")); - return TRUE; + return true; } case ltMARGINPAR: case ltMARGINPARODD: @@ -2241,7 +2263,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (start) { TexOutput(_T("
\n")); @@ -2256,7 +2278,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) float points = ParseUnitArgument(val); TwoColWidthA = (int)((points * 100.0) / 72.0); } - return FALSE; + return false; } // DHS case ltTWOCOLWIDTHB: @@ -2267,7 +2289,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) float points = ParseUnitArgument(val); TwoColWidthB = (int)((points * 100.0) / 72.0); } - return FALSE; + return false; } /* * Accents @@ -2317,7 +2339,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_ACUTE: { @@ -2369,7 +2391,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_CARET: { @@ -2415,7 +2437,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_TILDE: { @@ -2452,7 +2474,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_UMLAUT: { @@ -2504,7 +2526,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_DOT: { @@ -2526,7 +2548,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltBACKGROUND: { @@ -2535,7 +2557,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) wxChar *val = GetArgData(); if (val) { - bool isPicture = FALSE; + bool isPicture = false; ParseColourString(val, &isPicture); if (isPicture) { @@ -2551,7 +2573,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltBACKGROUNDIMAGE: { @@ -2565,7 +2587,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) backgroundImageString = copystring(val); } } - return FALSE; + return false; } case ltBACKGROUNDCOLOUR: { @@ -2579,7 +2601,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) backgroundColourString = copystring(val); } } - return FALSE; + return false; } case ltTEXTCOLOUR: { @@ -2593,7 +2615,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) textColourString = copystring(val); } } - return FALSE; + return false; } case ltLINKCOLOUR: { @@ -2607,7 +2629,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) linkColourString = copystring(val); } } - return FALSE; + return false; } case ltFOLLOWEDLINKCOLOUR: { @@ -2621,7 +2643,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) followedLinkColourString = copystring(val); } } - return FALSE; + return false; } case ltACCENT_CADILLA: { @@ -2643,16 +2665,16 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } /* case ltFOOTNOTE: case ltFOOTNOTEPOPUP: { if (arg_no == 1) - return TRUE; + return true; else - return FALSE; + return false; break; } */ @@ -2664,10 +2686,10 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (start) { currentRowNumber = 0; - inTabular = TRUE; - startRows = TRUE; - tableVerticalLineLeft = FALSE; - tableVerticalLineRight = FALSE; + inTabular = true; + startRows = true; + tableVerticalLineLeft = false; + tableVerticalLineRight = false; wxChar *alignString = copystring(GetArgData()); ParseTableArgument(alignString); @@ -2684,7 +2706,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) for (int i = 0; i < noColumns; i++) { currentWidth += TableData[i].width; - wxSprintf(buf, _T("\\cellx%d"), currentWidth); + wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth); TexOutput(buf); } TexOutput(_T("\\pard\\intbl\n")); @@ -2692,13 +2714,13 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } delete[] alignString; - return FALSE; + return false; } } else if (arg_no == 2 && !start) { TexOutput(_T("\n")); - inTabular = FALSE; + inTabular = false; } break; } @@ -2716,9 +2738,9 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) wxChar titleBuf[150]; if (truncateFilenames) - wxSprintf(titleBuf, _T("%s.htm"), wxFileNameFromPath(FileRoot)); + wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s.htm"), wxFileNameFromPath(FileRoot)); else - wxSprintf(titleBuf, _T("%s_contents.html"), wxFileNameFromPath(FileRoot)); + wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s_contents.html"), wxFileNameFromPath(FileRoot)); HTMLHead(); TexOutput(_T("