From 14204c7acc3f89b59b07580da7da3448fb49f23b Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 12 May 1999 17:49:33 +0000 Subject: [PATCH] HTML Help Workshop support git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2435 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- utils/tex2rtf/src/htmlutil.cpp | 189 +++++++++++++++++++++++++++++++++ utils/tex2rtf/src/tex2any.cpp | 1 + utils/tex2rtf/src/tex2any.h | 1 + utils/tex2rtf/src/texutils.cpp | 2 + 4 files changed, 193 insertions(+) diff --git a/utils/tex2rtf/src/htmlutil.cpp b/utils/tex2rtf/src/htmlutil.cpp index a67bc10be4..654b1d7a14 100644 --- a/utils/tex2rtf/src/htmlutil.cpp +++ b/utils/tex2rtf/src/htmlutil.cpp @@ -30,6 +30,12 @@ extern void DecToHex(int, char *); void GenerateHTMLIndexFile(char *fname); + +void GenerateHTMLWorkshopFiles(char *fname); +void HTMLWorkshopAddToContents(int level, char *s, char *file); +void HTMLWorkshopStartContents(); +void HTMLWorkshopEndContents(); + void OutputContentsFrame(void); #include "readshg.h" // Segmented hypergraphics parsing @@ -650,6 +656,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) AddTexRef(topicName, ChaptersName, ChapterNameString); SetCurrentChapterName(topicName, ChaptersName); + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(0, topicName, ChaptersName); SetCurrentOutput(Chapters); @@ -719,6 +726,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) AddTexRef(topicName, SectionsName, SectionNameString); SetCurrentSectionName(topicName, SectionsName); + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(1, topicName, SectionsName); SetCurrentOutput(Sections); TexOutput(""); @@ -811,6 +819,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) ReopenFile(&Subsections, &SubsectionsName); AddTexRef(topicName, SubsectionsName, SubsectionNameString); SetCurrentSubsectionName(topicName, SubsectionsName); + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SubsectionsName); SetCurrentOutput(Subsections); TexOutput("<head><title>"); @@ -837,6 +846,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) { AddTexRef(topicName, SectionsName, SubsectionNameString); SetCurrentSubsectionName(topicName, SectionsName); + // if ( subsectionNo != 0 ) fprintf(Sections, "\n<HR>\n"); @@ -851,6 +861,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) OutputCurrentSection(); TexOutput("</A><BR>\n"); + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName); SetCurrentOutput(Sections); } // Add this section title to the list of keywords @@ -888,6 +899,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) ReopenFile(&Subsubsections, &SubsubsectionsName); AddTexRef(topicName, SubsubsectionsName, SubsubsectionNameString); SetCurrentSubsubsectionName(topicName, SubsubsectionsName); + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(3, topicName, SubsubsectionsName); SetCurrentOutput(Subsubsections); TexOutput("<head><title>"); @@ -926,6 +938,7 @@ void HTMLOnMacro(int macroId, int no_args, bool start) OutputCurrentSection(); TexOutput("</A><BR>"); */ + if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName); SetCurrentOutput(Sections); } @@ -1920,6 +1933,23 @@ bool HTMLOnArgument(int macroId, int arg_no, bool start) strcat(buf, ".gif"); f = TexPathList.FindValidPath(buf); } + + if (f == "") // Try for a JPEG instead + { + strcpy(buf, filename); + StripExtension(buf); + strcat(buf, ".jpg"); + f = TexPathList.FindValidPath(buf); + } + + if (f == "") // Try for a PNG instead + { + strcpy(buf, filename); + StripExtension(buf); + strcat(buf, ".png"); + f = TexPathList.FindValidPath(buf); + } + if (f != "") { char *inlineFilename = copystring(f); @@ -2800,6 +2830,7 @@ bool HTMLGo(void) fprintf(Contents, "<UL>\n"); SetCurrentOutput(Titlepage); + if (htmlWorkshopFiles) HTMLWorkshopStartContents(); OnInform("Converting..."); TraverseDocument(); @@ -2949,8 +2980,17 @@ bool HTMLGo(void) GenerateHTMLIndexFile(htmlIndexName); } + // Generate HTML Help Workshop files if requested + if (htmlWorkshopFiles) + { + HTMLWorkshopEndContents(); + GenerateHTMLWorkshopFiles(FileRoot); + } + + return TRUE; } + return FALSE; } @@ -2980,3 +3020,152 @@ void GenerateHTMLIndexFile(char *fname) } fclose(fd); } + + + + + + + +// output .hpp, .hhc and .hhk files: + + +void GenerateHTMLWorkshopFiles(char *fname) +{ + FILE *f; + char buf[300]; + + /* Generate project file : */ + + sprintf(buf, "%s.hhp", fname); + f = fopen(buf, "wt"); + fprintf(f, + "[OPTIONS]\n" + "Compatibility=1.1 or later\n" + "Contents file=%s.hhc\n" + "Default topic=%s\n" + "Index file=%s.hhk\n" + "Title=", + FileNameFromPath(fname), + FileNameFromPath(TitlepageName), + FileNameFromPath(fname) + ); + + if (DocumentTitle) { + SetCurrentOutput(f); + TraverseChildrenFromChunk(DocumentTitle); + } + else fprintf(f, "(unknown)"); + + fprintf(f, "\n\n[FILES]\n"); + fprintf(f, "%s\n", FileNameFromPath(TitlepageName)); + for (int i = 1; i <= fileId; i++) { + if (truncateFilenames) + sprintf(buf, "%s%d.htm", FileNameFromPath(FileRoot), i); + else + sprintf(buf, "%s%d.html", FileNameFromPath(FileRoot), i); + fprintf(f, "%s\n", buf); + } + fclose(f); + + /* Generate index file : */ + + sprintf(buf, "%s.hhk", fname); + f = fopen(buf, "wt"); + + fprintf(f, + "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n" + "<HTML>\n" + "<HEAD>\n" + "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n" + "<!-- Sitemap 1.0 -->\n" + "</HEAD><BODY>\n" + "<OBJECT type=\"text/site properties\">\n" + " <param name=\"ImageType\" value=\"Folder\">\n" + "</OBJECT>\n" + "<UL>\n"); + + TopicTable.BeginFind(); + wxNode *node = NULL; + while ((node = TopicTable.Next())) + { + TexTopic *texTopic = (TexTopic *)node->Data(); + const char *topicName = node->GetKeyString(); + if (texTopic->filename && texTopic->keywords) + { + wxNode *node1 = texTopic->keywords->First(); + while (node1) + { + char *s = (char *)node1->Data(); + fprintf(f, + " <LI> <OBJECT type=\"text/sitemap\">\n" + " <param name=\"Local\" value=\"%s#%s\">\n" + " <param name=\"Name\" value=\"%s\">\n" + " </OBJECT>\n", + texTopic->filename, topicName, s); + node1 = node1->Next(); + } + } + } + + fprintf(f, "</UL>\n"); + fclose(f); +} + + + +static FILE *HTMLWorkshopContents = NULL; +static int HTMLWorkshopLastLevel = 0; + +void HTMLWorkshopAddToContents(int level, char *s, char *file) +{ + int i; + + if (level > HTMLWorkshopLastLevel) + for (i = HTMLWorkshopLastLevel; i < level; i++) + fprintf(HTMLWorkshopContents, "<UL>"); + if (level < HTMLWorkshopLastLevel) + for (i = level; i < HTMLWorkshopLastLevel; i++) + fprintf(HTMLWorkshopContents, "</UL>"); + + SetCurrentOutput(HTMLWorkshopContents); + fprintf(HTMLWorkshopContents, + " <LI> <OBJECT type=\"text/sitemap\">\n" + " <param name=\"Local\" value=\"%s#%s\">\n" + " <param name=\"Name\" value=\"", + file, s); + OutputCurrentSection(); + fprintf(HTMLWorkshopContents, + "\">\n" + " </OBJECT>\n"); + HTMLWorkshopLastLevel = level; +} + + +void HTMLWorkshopStartContents() +{ + char buf[300]; + sprintf(buf, "%s.hhc", FileRoot); + HTMLWorkshopContents = fopen(buf, "wt"); + HTMLWorkshopLastLevel = 0; + + fprintf(HTMLWorkshopContents, + "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n" + "<HTML>\n" + "<HEAD>\n" + "<meta name=\"GENERATOR\" content=\"tex2rtf\">\n" + "<!-- Sitemap 1.0 -->\n" + "</HEAD><BODY>\n" + "<OBJECT type=\"text/site properties\">\n" + " <param name=\"ImageType\" value=\"Folder\">\n" + "</OBJECT>\n" + "<UL>\n"); +} + + +void HTMLWorkshopEndContents() +{ + for (int i = HTMLWorkshopLastLevel; i >= 0; i--) + fprintf(HTMLWorkshopContents, "</UL>\n"); + fclose(HTMLWorkshopContents); +} diff --git a/utils/tex2rtf/src/tex2any.cpp b/utils/tex2rtf/src/tex2any.cpp index 6bdc76b38f..cefb10037e 100644 --- a/utils/tex2rtf/src/tex2any.cpp +++ b/utils/tex2rtf/src/tex2any.cpp @@ -121,6 +121,7 @@ char *textColourString = NULL; char *linkColourString = NULL; char *followedLinkColourString = NULL; bool combineSubSections = FALSE; +bool htmlWorkshopFiles = FALSE; /* * International support diff --git a/utils/tex2rtf/src/tex2any.h b/utils/tex2rtf/src/tex2any.h index db5b1914de..37d25fb7b8 100644 --- a/utils/tex2rtf/src/tex2any.h +++ b/utils/tex2rtf/src/tex2any.h @@ -238,6 +238,7 @@ extern char *textColourString; // HTML text colour extern char *linkColourString; // HTML link colour extern char *followedLinkColourString; // HTML followed link colour extern bool combineSubSections; // Stop splitting files below section +extern bool htmlWorkshopFiles; // generate HTML Help Workshop project files // Names to help with internationalisation extern char *ContentsNameString; diff --git a/utils/tex2rtf/src/texutils.cpp b/utils/tex2rtf/src/texutils.cpp index 2b61ddfc76..5746339422 100644 --- a/utils/tex2rtf/src/texutils.cpp +++ b/utils/tex2rtf/src/texutils.cpp @@ -1166,6 +1166,8 @@ char *RegisterSetting(char *settingName, char *settingValue, bool interactive) winHelpContents = StringTobool(settingValue); else if (StringMatch(settingName, "htmlIndex", FALSE, TRUE)) htmlIndex = StringTobool(settingValue); + else if (StringMatch(settingName, "htmlWorkshopFiles", FALSE, TRUE)) + htmlWorkshopFiles = StringTobool(settingValue); else if (StringMatch(settingName, "htmlFrameContents", FALSE, TRUE)) htmlFrameContents = StringTobool(settingValue); else if (StringMatch(settingName, "upperCaseNames", FALSE, TRUE)) -- 2.45.2