X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7e9968f70242bde7240927593f8e9af0dd2a8d53..0ffc92133bd05ff86fa5947e14c211f75fec9b2b:/utils/tex2rtf/src/htmlutil.cpp diff --git a/utils/tex2rtf/src/htmlutil.cpp b/utils/tex2rtf/src/htmlutil.cpp index 380c837ea2..b68d0b5b2f 100644 --- a/utils/tex2rtf/src/htmlutil.cpp +++ b/utils/tex2rtf/src/htmlutil.cpp @@ -10,10 +10,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -1826,7 +1822,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) static bool CheckTypeRef() { wxString typeDecl = GetArgData(); - if( !typeDecl.IsEmpty() ) { + if( !typeDecl.empty() ) { typeDecl.Replace(wxT("\\"),wxT("")); wxString label = typeDecl; label.Replace(wxT("const"),wxT("")); @@ -2247,7 +2243,7 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) if (imageFile) delete[] imageFile; imageFile = NULL; - if (!f.IsEmpty()) + if (!f.empty()) { imageFile = copystring(f); } @@ -3031,223 +3027,222 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) bool HTMLGo(void) { - fileId = 0; - inVerbatim = false; - indentLevel = 0; - inTabular = false; - startRows = false; - tableVerticalLineLeft = false; - tableVerticalLineRight = false; - noColumns = 0; - - if (InputFile && OutputFile) - { - // Do some HTML-specific transformations on all the strings, - // recursively - Text2HTML(GetTopLevelChunk()); - - wxChar buf[300]; - if (truncateFilenames) - wxSnprintf(buf, sizeof(buf), _T("%s.htm"), FileRoot); - else - wxSnprintf(buf, sizeof(buf), _T("%s_contents.html"), FileRoot); - if (TitlepageName) delete[] TitlepageName; - TitlepageName = copystring(buf); - Titlepage = wxFopen(buf, _T("w")); + fileId = 0; + inVerbatim = false; + indentLevel = 0; + inTabular = false; + startRows = false; + tableVerticalLineLeft = false; + tableVerticalLineRight = false; + noColumns = 0; - if (truncateFilenames) - wxSnprintf(buf, sizeof(buf), _T("%s_fc.htm"), FileRoot); - else - wxSnprintf(buf, sizeof(buf), _T("%s_fcontents.html"), FileRoot); + if (!InputFile.empty() && !OutputFile.empty()) + { + // Do some HTML-specific transformations on all the strings, + // recursively + Text2HTML(GetTopLevelChunk()); - contentsFrameName = copystring(buf); + wxChar buf[300]; + if (truncateFilenames) + wxSnprintf(buf, sizeof(buf), _T("%s.htm"), FileRoot); + else + wxSnprintf(buf, sizeof(buf), _T("%s_contents.html"), FileRoot); + if (TitlepageName) delete[] TitlepageName; + TitlepageName = copystring(buf); + Titlepage = wxFopen(buf, _T("w")); - Contents = wxFopen(TmpContentsName, _T("w")); + if (truncateFilenames) + wxSnprintf(buf, sizeof(buf), _T("%s_fc.htm"), FileRoot); + else + wxSnprintf(buf, sizeof(buf), _T("%s_fcontents.html"), FileRoot); - if (htmlFrameContents) - { -// FrameContents = wxFopen(TmpFrameContentsName, _T("w")); - FrameContents = wxFopen(contentsFrameName, _T("w")); - wxFprintf(FrameContents, _T("\n\n")); + wxFprintf(FrameContents, _T("\n")); + fclose(FrameContents); + FrameContents = NULL; + } - // Output frame information - if (htmlFrameContents) - { - wxChar firstFileName[300]; - if (truncateFilenames) - wxSnprintf(firstFileName, sizeof(firstFileName), _T("%s1.htm"), FileRoot); - else - wxStrcpy(firstFileName, gs_filenames[1].c_str()); + if (Chapters) + { + wxFprintf(Chapters, _T("\n\n")); + fclose(Chapters); + Chapters = NULL; + } + if (Sections) + { + wxFprintf(Sections, _T("\n\n")); + fclose(Sections); + Sections = NULL; + } + if (Subsections && !combineSubSections) + { + wxFprintf(Subsections, _T("\n\n")); + fclose(Subsections); + Subsections = NULL; + } + if (Subsubsections && !combineSubSections) + { + wxFprintf(Subsubsections, _T("\n\n")); + fclose(Subsubsections); + Subsubsections = NULL; + } + if ( SectionContentsFD ) + { + fclose(SectionContentsFD); + SectionContentsFD = NULL; + } - wxFprintf(tmpTitle, _T("\n")); + // Create a temporary file for the title page header, add some info, + // and concat the titlepage just generated. + // This is necessary in order to put the title of the document + // at the TOP of the file within , even though we only find out + // what it is later on. + FILE *tmpTitle = wxFopen(_T("title.tmp"), _T("w")); + if (tmpTitle) + { + if (DocumentTitle) + { + SetCurrentOutput(tmpTitle); + HTMLHead(); + TexOutput(_T("\n")); + TraverseChildrenFromChunk(DocumentTitle); + TexOutput(_T("\n")); + } + else + { + SetCurrentOutput(tmpTitle); + HTMLHeadTo(tmpTitle); + if (contentsString) + wxFprintf(tmpTitle, _T("%s\n\n"), contentsString); + else + wxFprintf(tmpTitle, _T("%s\n\n"), wxFileNameFromPath(FileRoot)); + } - wxFprintf(tmpTitle, _T("\n"), ConvertCase(wxFileNameFromPath(contentsFrameName))); - wxFprintf(tmpTitle, _T("\n"), ConvertCase(wxFileNameFromPath(firstFileName))); - wxFprintf(tmpTitle, _T("\n")); + // Output frame information + if (htmlFrameContents) + { + wxChar firstFileName[300]; + if (truncateFilenames) + wxSnprintf(firstFileName, sizeof(firstFileName), _T("%s1.htm"), FileRoot); + else + wxStrcpy(firstFileName, gs_filenames[1].c_str()); - wxFprintf(tmpTitle, _T("\n")); - } + wxFprintf(tmpTitle, _T("<FRAMESET COLS=\"30%%,70%%\">\n")); - // Output <BODY...> to temporary title page - OutputBodyStart(); - fflush(tmpTitle); + wxFprintf(tmpTitle, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName))); + wxFprintf(tmpTitle, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName))); + wxFprintf(tmpTitle, _T("</FRAMESET>\n")); - // Concat titlepage - FILE *fd = wxFopen(TitlepageName, _T("r")); - if (fd) - { - int ch = getc(fd); - while (ch != EOF) - { - wxPutc(ch, tmpTitle); - ch = getc(fd); - } - fclose(fd); - } + wxFprintf(tmpTitle, _T("<NOFRAMES>\n")); + } - wxFprintf(tmpTitle, _T("\n</FONT></BODY>\n")); + // Output <BODY...> to temporary title page + OutputBodyStart(); + fflush(tmpTitle); - if (htmlFrameContents) - { - wxFprintf(tmpTitle, _T("\n\n")); - } - wxFprintf(tmpTitle, _T("\n\n")); + // Concat titlepage + FILE *fd = wxFopen(TitlepageName, _T("r")); + if (fd) + { + int ch = getc(fd); + while (ch != EOF) + { + wxPutc(ch, tmpTitle); + ch = getc(fd); + } + fclose(fd); + } - fclose(tmpTitle); - if (wxFileExists(TitlepageName)) wxRemoveFile(TitlepageName); - if (!wxRenameFile(_T("title.tmp"), TitlepageName)) - { - wxCopyFile(_T("title.tmp"), TitlepageName); - wxRemoveFile(_T("title.tmp")); - } - } + wxFprintf(tmpTitle, _T("\n\n")); - if (lastFileName) delete[] lastFileName; - lastFileName = NULL; - if (lastTopic) delete[] lastTopic; - lastTopic = NULL; + if (htmlFrameContents) + { + wxFprintf(tmpTitle, _T("\n\n")); + } + wxFprintf(tmpTitle, _T("\n\n")); - if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName); + fclose(tmpTitle); + if (wxFileExists(TitlepageName)) wxRemoveFile(TitlepageName); + if (!wxRenameFile(_T("title.tmp"), TitlepageName)) + { + wxCopyFile(_T("title.tmp"), TitlepageName); + wxRemoveFile(_T("title.tmp")); + } + } - if (!wxRenameFile(TmpContentsName, ContentsName)) - { - wxCopyFile(TmpContentsName, ContentsName); - wxRemoveFile(TmpContentsName); - } + if (lastFileName) delete[] lastFileName; + lastFileName = NULL; + if (lastTopic) delete[] lastTopic; + lastTopic = NULL; - // Generate .htx file if requested - if (htmlIndex) - { - wxChar htmlIndexName[300]; - wxSnprintf(htmlIndexName, sizeof(htmlIndexName), _T("%s.htx"), FileRoot); - GenerateHTMLIndexFile(htmlIndexName); - } + if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName); - // Generate HTML Help Workshop files if requested - if (htmlWorkshopFiles) - { - HTMLWorkshopEndContents(); - GenerateHTMLWorkshopFiles(FileRoot); - } + if (!wxRenameFile(TmpContentsName, ContentsName)) + { + wxCopyFile(TmpContentsName, ContentsName); + wxRemoveFile(TmpContentsName); + } + // Generate .htx file if requested + if (htmlIndex) + { + wxChar htmlIndexName[300]; + wxSnprintf(htmlIndexName, sizeof(htmlIndexName), _T("%s.htx"), FileRoot); + GenerateHTMLIndexFile(htmlIndexName); + } - return true; - } + // Generate HTML Help Workshop files if requested + if (htmlWorkshopFiles) + { + HTMLWorkshopEndContents(); + GenerateHTMLWorkshopFiles(FileRoot); + } - return false; + return true; + } + + return false; } // Output .htx index file