X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e6a0295cdda5045864b4bdccf29cf692cc9389cd..15d83f726c215b06f2fdd15ece40d66d2f16a01d:/utils/tex2rtf/src/htmlutil.cpp diff --git a/utils/tex2rtf/src/htmlutil.cpp b/utils/tex2rtf/src/htmlutil.cpp index a04e88baa7..5b357eda1a 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 +1477,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
@@ -1627,6 +1651,11 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
{
if (start)
{
+ // NB: if this is uncommented, the table of contents
+ // completely disappears. If left commented, it's in the wrong
+ // place.
+ //fflush(Titlepage);
+
FILE *fd = wxFopen(ContentsName, _T("r"));
if (fd)
{
@@ -1637,6 +1666,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
ch = getc(fd);
}
fclose(fd);
+ fflush(Titlepage);
}
else
{
@@ -1682,18 +1712,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 +1750,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 +1787,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 +1912,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 +1932,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 +1952,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
{
@@ -1949,15 +1979,15 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
// If a filename is supplied, use it, otherwise try to
// use the filename associated with the reference (from this document).
if (helpRefFilename)
- {
+ {
TraverseChildrenFromChunk(helpRefFilename);
TexOutput(_T("#"));
- }
+ }
else if (refFilename)
- {
+ {
TexOutput(ConvertCase(refFilename));
TexOutput(_T("#"));
- }
+ }
TexOutput(refName);
TexOutput(_T("\">"));
if (helpRefText)
@@ -1977,7 +2007,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
}
else TexOutput(_T("??"));
}
- return FALSE;
+ return false;
}
break;
}
@@ -2037,7 +2067,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
// If we have found the existing filename, make the inline
// image point to the original file (could be PS, for example)
if (originalFilename && (wxStrcmp(inlineFilename, originalFilename) != 0))
- {
+ {
TexOutput(_T(""));
@@ -2046,17 +2076,17 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
TexOutput(_T("\""));
TexOutput(alignment);
TexOutput(_T(">"));
- }
+ }
else
#endif
- {
+ {
TexOutput(_T("
"));
delete[] inlineFilename;
- }
+ }
}
else
{
@@ -2064,12 +2094,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 +2126,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 +2170,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 +2186,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:
@@ -2173,31 +2203,40 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
{
if ( start ) {
// DHS
- if (TwoColWidthA > -1) {
+ if (TwoColWidthA > -1)
+ {
wxChar buf[100];
- wxSprintf(buf,_T("\n\n"),TwoColWidthA);
+ wxSnprintf(buf, sizeof(buf), _T("\n \n"),TwoColWidthA);
TexOutput(buf);
- } else
+ }
+ else
+ {
TexOutput(_T("\n \n"));
- OutputFont();
+ }
+ OutputFont();
} else
TexOutput(_T("\n \n"));
}
if (arg_no == 2)
{
// DHS
- if ( start ) {
- if (TwoColWidthB > -1) {
+ 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"));
- OutputFont();
+ }
+ else
+ {
+ TexOutput(_T("\n \n"));
+ }
+ OutputFont();
} else
TexOutput(_T("\n \n"));
}
- return TRUE;
+ return true;
}
case ltNUMBEREDBIBITEM:
{
@@ -2219,18 +2258,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")); - return TRUE; + return true; } case ltMARGINPAR: case ltMARGINPARODD: @@ -2241,7 +2280,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (start) { TexOutput(_T("
\n")); @@ -2256,7 +2295,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 +2306,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 +2356,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_ACUTE: { @@ -2369,7 +2408,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_CARET: { @@ -2415,7 +2454,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_TILDE: { @@ -2452,7 +2491,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_UMLAUT: { @@ -2504,7 +2543,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_DOT: { @@ -2526,7 +2565,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltBACKGROUND: { @@ -2535,7 +2574,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 +2590,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltBACKGROUNDIMAGE: { @@ -2565,7 +2604,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) backgroundImageString = copystring(val); } } - return FALSE; + return false; } case ltBACKGROUNDCOLOUR: { @@ -2579,7 +2618,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) backgroundColourString = copystring(val); } } - return FALSE; + return false; } case ltTEXTCOLOUR: { @@ -2593,7 +2632,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) textColourString = copystring(val); } } - return FALSE; + return false; } case ltLINKCOLOUR: { @@ -2607,7 +2646,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) linkColourString = copystring(val); } } - return FALSE; + return false; } case ltFOLLOWEDLINKCOLOUR: { @@ -2621,7 +2660,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) followedLinkColourString = copystring(val); } } - return FALSE; + return false; } case ltACCENT_CADILLA: { @@ -2643,16 +2682,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 +2703,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); @@ -2679,12 +2718,12 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (compatibilityMode) { TexOutput(_T("