X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6c155d33875eb3641bf845fbac186c1b5470708e..15d83f726c215b06f2fdd15ece40d66d2f16a01d:/utils/tex2rtf/src/htmlutil.cpp?ds=inline diff --git a/utils/tex2rtf/src/htmlutil.cpp b/utils/tex2rtf/src/htmlutil.cpp index a286f46279..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 @@ -23,6 +24,8 @@ #ifndef WX_PRECOMP #endif +#include "wx/arrstr.h" + #include "tex2any.h" #include "tex2rtf.h" #include "table.h" @@ -67,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; @@ -175,12 +178,17 @@ void SetCurrentSubsubsectionName(wxChar *s, wxChar *file) SetCurrentTopic(s); } + +// mapping between fileId and filenames if truncateFilenames=false: +static wxArrayString gs_filenames; + + /* * Close former filedescriptor and reopen using another filename. * */ -void ReopenFile(FILE **fd, wxChar **fileName) +void ReopenFile(FILE **fd, wxChar **fileName, const wxChar *label) { if (*fd) { @@ -190,9 +198,16 @@ void ReopenFile(FILE **fd, wxChar **fileName) fileId ++; wxChar buf[400]; if (truncateFilenames) - wxSprintf(buf, _T("%s%d.htm"), FileRoot, fileId); + { + wxSnprintf(buf, sizeof(buf), _T("%s%d.htm"), FileRoot, fileId); + } else - wxSprintf(buf, _T("%s%d.html"), FileRoot, fileId); + { + if (fileId == 1) + gs_filenames.Add(wxEmptyString); + wxSnprintf(buf, sizeof(buf), _T("%s_%s.html"), FileRoot, label); + gs_filenames.Add(buf); + } if (*fileName) delete[] *fileName; *fileName = copystring(wxFileNameFromPath(buf)); *fd = wxFopen(buf, _T("w")); @@ -240,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; @@ -256,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 <
{
@@ -276,7 +291,7 @@ void ProcessText2HTML(TexChunk *chunk)
wxStrcat(BigBuffer, _T("<"));
ptr += 4;
i += 1;
- changed = TRUE;
+ changed = true;
}
else if (ch == '>') // Change > to >
{
@@ -284,7 +299,7 @@ void ProcessText2HTML(TexChunk *chunk)
wxStrcat(BigBuffer, _T(">"));
ptr += 4;
i += 1;
- changed = TRUE;
+ changed = true;
}
else
{
@@ -325,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)
@@ -336,7 +351,7 @@ void Text2HTML(TexChunk *chunk)
}
if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB || def->macroId == ltSPECIAL))
- inVerbatim = FALSE;
+ inVerbatim = false;
break;
}
@@ -384,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
@@ -394,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
@@ -404,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
@@ -414,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"));
@@ -1439,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
@@ -1613,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)
{
@@ -1623,6 +1666,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start)
ch = getc(fd);
}
fclose(fd);
+ fflush(Titlepage);
}
else
{
@@ -1668,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);
@@ -1706,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:
@@ -1743,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:
{
@@ -1868,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
{
@@ -1888,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;
}
@@ -1908,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
{
@@ -1935,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)
@@ -1963,7 +2007,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start)
}
else TexOutput(_T("??"));
}
- return FALSE;
+ return false;
}
break;
}
@@ -2023,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(""));
@@ -2032,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
{
@@ -2050,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:
@@ -2082,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;
@@ -2126,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:
@@ -2142,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:
@@ -2159,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:
{
@@ -2205,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: @@ -2227,7 +2280,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (start) { TexOutput(_T("
\n")); @@ -2242,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: @@ -2253,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 @@ -2303,7 +2356,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_ACUTE: { @@ -2355,7 +2408,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_CARET: { @@ -2401,7 +2454,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_TILDE: { @@ -2438,7 +2491,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_UMLAUT: { @@ -2490,7 +2543,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltACCENT_DOT: { @@ -2512,7 +2565,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltBACKGROUND: { @@ -2521,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) { @@ -2537,7 +2590,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) } } } - return FALSE; + return false; } case ltBACKGROUNDIMAGE: { @@ -2551,7 +2604,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) backgroundImageString = copystring(val); } } - return FALSE; + return false; } case ltBACKGROUNDCOLOUR: { @@ -2565,7 +2618,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) backgroundColourString = copystring(val); } } - return FALSE; + return false; } case ltTEXTCOLOUR: { @@ -2579,7 +2632,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) textColourString = copystring(val); } } - return FALSE; + return false; } case ltLINKCOLOUR: { @@ -2593,7 +2646,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) linkColourString = copystring(val); } } - return FALSE; + return false; } case ltFOLLOWEDLINKCOLOUR: { @@ -2607,7 +2660,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) followedLinkColourString = copystring(val); } } - return FALSE; + return false; } case ltACCENT_CADILLA: { @@ -2629,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; } */ @@ -2650,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); @@ -2665,12 +2718,12 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (compatibilityMode) { TexOutput(_T("