1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Converts Latex to HTML
4 // Author: Julian Smart
5 // Modified by: Wlodzimierz ABX Skiba 2003/2004 Unicode support
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
23 #include "wx/arrstr.h"
29 #define HTML_FILENAME_PATTERN _T("%s_%s.html")
31 #if !WXWIN_COMPATIBILITY_2_4
32 static inline wxChar
* copystring(const wxChar
* s
)
33 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
36 extern wxHashTable TexReferences
;
38 extern int passNumber
;
40 extern void DecToHex(int, wxChar
*);
41 void GenerateHTMLIndexFile(wxChar
*fname
);
43 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
);
45 void GenerateHTMLWorkshopFiles(wxChar
*fname
);
46 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
);
47 void HTMLWorkshopStartContents();
48 void HTMLWorkshopEndContents();
50 void OutputContentsFrame(void);
52 #include "readshg.h" // Segmented hypergraphics parsing
54 wxChar
*ChaptersName
= NULL
;
55 wxChar
*SectionsName
= NULL
;
56 wxChar
*SubsectionsName
= NULL
;
57 wxChar
*SubsubsectionsName
= NULL
;
58 wxChar
*TitlepageName
= NULL
;
59 wxChar
*lastFileName
= NULL
;
60 wxChar
*lastTopic
= NULL
;
61 wxChar
*currentFileName
= NULL
;
62 wxChar
*contentsFrameName
= NULL
;
64 static TexChunk
*descriptionItemArg
= NULL
;
65 static TexChunk
*helpRefFilename
= NULL
;
66 static TexChunk
*helpRefText
= NULL
;
67 static int indentLevel
= 0;
68 static int citeCount
= 1;
69 extern FILE *Contents
;
70 FILE *FrameContents
= NULL
;
71 FILE *Titlepage
= NULL
;
72 // FILE *FrameTitlepage = NULL;
74 bool subsectionStarted
= false;
76 // Which column of a row are we in? (Assumes no nested tables, of course)
77 int currentColumn
= 0;
79 // Are we in verbatim mode? If so, format differently.
80 static bool inVerbatim
= false;
82 // Need to know whether we're in a table or figure for benefit
83 // of listoffigures/listoftables
84 static bool inFigure
= false;
85 static bool inTable
= false;
87 // This is defined in the Tex2Any library.
88 extern wxChar
*BigBuffer
;
90 // DHS Two-column table dimensions.
91 static int TwoColWidthA
= -1;
92 static int TwoColWidthB
= -1;
95 class HyperReference
: public wxObject
100 HyperReference(wxChar
*name
, wxChar
*file
)
102 if (name
) refName
= copystring(name
);
103 if (file
) refFile
= copystring(file
);
107 class TexNextPage
: public wxObject
112 TexNextPage(wxChar
*theLabel
, wxChar
*theFile
)
114 label
= copystring(theLabel
);
115 filename
= copystring(theFile
);
117 virtual ~TexNextPage(void)
124 wxHashTable
TexNextPages(wxKEY_STRING
);
126 static wxChar
*CurrentChapterName
= NULL
;
127 static wxChar
*CurrentChapterFile
= NULL
;
128 static wxChar
*CurrentSectionName
= NULL
;
129 static wxChar
*CurrentSectionFile
= NULL
;
130 static wxChar
*CurrentSubsectionName
= NULL
;
131 static wxChar
*CurrentSubsectionFile
= NULL
;
132 static wxChar
*CurrentSubsubsectionName
= NULL
;
133 static wxChar
*CurrentSubsubsectionFile
= NULL
;
134 static wxChar
*CurrentTopic
= NULL
;
136 static void SetCurrentTopic(wxChar
*s
)
138 if (CurrentTopic
) delete[] CurrentTopic
;
139 CurrentTopic
= copystring(s
);
142 void SetCurrentChapterName(wxChar
*s
, wxChar
*file
)
144 if (CurrentChapterName
) delete[] CurrentChapterName
;
145 CurrentChapterName
= copystring(s
);
146 if (CurrentChapterFile
) delete[] CurrentChapterFile
;
147 CurrentChapterFile
= copystring(file
);
149 currentFileName
= CurrentChapterFile
;
153 void SetCurrentSectionName(wxChar
*s
, wxChar
*file
)
155 if (CurrentSectionName
) delete[] CurrentSectionName
;
156 CurrentSectionName
= copystring(s
);
157 if (CurrentSectionFile
) delete[] CurrentSectionFile
;
158 CurrentSectionFile
= copystring(file
);
160 currentFileName
= CurrentSectionFile
;
163 void SetCurrentSubsectionName(wxChar
*s
, wxChar
*file
)
165 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
166 CurrentSubsectionName
= copystring(s
);
167 if (CurrentSubsectionFile
) delete[] CurrentSubsectionFile
;
168 CurrentSubsectionFile
= copystring(file
);
169 currentFileName
= CurrentSubsectionFile
;
172 void SetCurrentSubsubsectionName(wxChar
*s
, wxChar
*file
)
174 if (CurrentSubsubsectionName
) delete[] CurrentSubsubsectionName
;
175 CurrentSubsubsectionName
= copystring(s
);
176 if (CurrentSubsubsectionFile
) delete[] CurrentSubsubsectionFile
;
177 CurrentSubsubsectionFile
= copystring(file
);
178 currentFileName
= CurrentSubsubsectionFile
;
183 // mapping between fileId and filenames if truncateFilenames=false:
184 static wxArrayString gs_filenames
;
188 * Close former filedescriptor and reopen using another filename.
192 void ReopenFile(FILE **fd
, wxChar
**fileName
, const wxChar
*label
)
196 wxFprintf(*fd
, _T("\n</FONT></BODY></HTML>\n"));
201 if (truncateFilenames
)
203 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), FileRoot
, fileId
);
208 gs_filenames
.Add(wxEmptyString
);
209 wxSnprintf(buf
, sizeof(buf
), HTML_FILENAME_PATTERN
, FileRoot
, label
);
210 gs_filenames
.Add(buf
);
212 if (*fileName
) delete[] *fileName
;
213 *fileName
= copystring(wxFileNameFromPath(buf
));
214 *fd
= wxFopen(buf
, _T("w"));
215 wxFprintf(*fd
, _T("<HTML>\n"));
219 * Reopen section contents file, i.e. the index appended to each section
220 * in subsectionCombine mode
223 static wxChar
*SectionContentsFilename
= NULL
;
224 static FILE *SectionContentsFD
= NULL
;
226 void ReopenSectionContentsFile(void)
228 if ( SectionContentsFD
)
230 fclose(SectionContentsFD
);
232 if ( SectionContentsFilename
)
233 delete[] SectionContentsFilename
;
234 SectionContentsFD
= NULL
;
235 SectionContentsFilename
= NULL
;
237 // Create the name from the current section filename
238 if ( CurrentSectionFile
)
241 wxStrcpy(buf
, CurrentSectionFile
);
242 wxStripExtension(buf
);
243 wxStrcat(buf
, _T(".con"));
244 SectionContentsFilename
= copystring(buf
);
246 SectionContentsFD
= wxFopen(SectionContentsFilename
, _T("w"));
261 #define tr(x,y) {x, sizeof(x)-1, y, sizeof(y)-1}
263 static textreplace notverb_array
[] =
265 tr(_T("\r\n\r\n"), _T("<P>\n\n")), // unix
266 tr(_T("\n\n"), _T("<P>\n\n")), // dos
267 tr(_T("\r\r"), _T("<P>\n\n")), // mac
268 tr(_T("``"), _T("“")),
269 tr(_T("''"), _T("”")),
270 tr(_T("`"), _T("‘")),
271 tr(_T("'"), _T("’")),
272 tr(_T("---"), _T("—")),
273 tr(_T("--"), _T("–")),
279 * Given a TexChunk with a string value, scans through the string
280 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
284 void ProcessText2HTML(TexChunk
*chunk
)
286 bool changed
= false;
290 int len
= wxStrlen(chunk
->value
);
293 ch
= chunk
->value
[i
];
295 if (ch
== _T('<')) // Change < to <
298 wxStrcat(BigBuffer
, _T("<"));
304 else if (ch
== _T('>')) // Change > to >
307 wxStrcat(BigBuffer
, _T(">"));
315 bool replaced
= false;
319 for (x
= 0; x
< sizeof (notverb_array
) / sizeof(textreplace
); x
++)
321 textreplace
& tr
= notverb_array
[x
];
322 if (ch
!= tr
.text
[0]) continue;
323 if (len
< tr
.text_length
) continue;
325 for (y
= 1; y
< tr
.text_length
; y
++)
327 if (chunk
->value
[y
] != tr
.text
[y
]) break;
329 if (y
!= tr
.text_length
) continue;
331 // can now copy it over.
332 for (y
= 0; y
< tr
.replace_length
; y
++)
334 BigBuffer
[ptr
++] = tr
.replace
[y
];
336 len
-= tr
.text_length
;
358 chunk
->value
= copystring(BigBuffer
);
363 * Scan through all chunks starting from the given one,
364 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
365 * This should be called after Tex2Any has parsed the file,
366 * and before TraverseDocument is called.
370 void Text2HTML(TexChunk
*chunk
)
373 if (stopRunning
) return;
377 case CHUNK_TYPE_MACRO
:
379 TexMacroDef
*def
= chunk
->def
;
381 if (def
&& def
->ignore
)
384 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
387 wxNode
*node
= chunk
->children
.GetFirst();
390 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
391 Text2HTML(child_chunk
);
392 node
= node
->GetNext();
395 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
402 wxNode
*node
= chunk
->children
.GetFirst();
405 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
406 Text2HTML(child_chunk
);
407 node
= node
->GetNext();
412 case CHUNK_TYPE_STRING
:
415 ProcessText2HTML(chunk
);
422 * Add appropriate browse buttons to this page.
426 void AddBrowseButtons(wxChar
*upLabel
, wxChar
*upFilename
,
427 wxChar
*previousLabel
, wxChar
*previousFilename
,
428 wxChar
*thisLabel
, wxChar
*thisFilename
)
430 wxChar contentsReferenceBuf
[80];
431 wxChar upReferenceBuf
[80];
432 wxChar backReferenceBuf
[80];
433 wxChar forwardReferenceBuf
[80];
434 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
437 wxChar
*contentsReference
; // no need to initialize because always assigned below
438 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
439 contentsReference
= ContentsNameString
;
442 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
443 contentsReference
= contentsReferenceBuf
;
444 wxSnprintf(contentsReference
, sizeof(contentsReferenceBuf
),
445 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">"),
446 ConvertCase(_T("contents.gif")));
449 wxChar
*upReference
; // no need to initialize because always assigned below
450 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
451 upReference
= UpNameString
;
454 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
455 upReference
= upReferenceBuf
;
456 wxSnprintf(upReference
, sizeof(upReferenceBuf
),
457 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">"),
458 ConvertCase(_T("up.gif")));
461 wxChar
*backReference
; // no need to initialize because always assigned below
462 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
463 backReference
= _T("<<");
466 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
467 backReference
= backReferenceBuf
;
468 wxSnprintf(backReference
, sizeof(backReferenceBuf
),
469 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">"),
470 ConvertCase(_T("back.gif")));
473 wxChar
*forwardReference
; // no need to initialize because always assigned below
474 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
475 forwardReference
= _T(">>");
478 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
479 forwardReference
= forwardReferenceBuf
;
480 wxSnprintf(forwardReference
, sizeof(forwardReferenceBuf
),
481 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">"),
482 ConvertCase(_T("forward.gif")));
485 TexOutput(_T("<CENTER>"));
494 if (truncateFilenames
)
497 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
498 wxSnprintf(buf
, sizeof(buf
),
499 _T("\n<A HREF=\"%s.%s\">%s</A> "),
500 buf1
, ConvertCase(_T("htm")), contentsReference
);
505 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
506 wxSnprintf(buf
, sizeof(buf
),
507 _T("\n<A HREF=\"%s%s\">%s</A> "),
508 buf1
, ConvertCase(_T("_contents.html")), contentsReference
);
510 // TexOutput(_T("<NOFRAMES>"));
512 // TexOutput(_T("</NOFRAMES>"));
519 if (upLabel
&& upFilename
)
521 if ( (wxStrlen(upLabel
) > 0) && !PrimaryAnchorOfTheFile(upFilename
, upLabel
) )
522 wxSnprintf(buf
, sizeof(buf
),
523 _T("<A HREF=\"%s#%s\">%s</A> "),
524 ConvertCase(upFilename
), upLabel
, upReference
);
526 wxSnprintf(buf
, sizeof(buf
),
527 _T("<A HREF=\"%s\">%s</A> "),
528 ConvertCase(upFilename
), upReference
);
529 if (wxStrcmp(upLabel
, _T("contents")) == 0)
531 // TexOutput(_T("<NOFRAMES>"));
533 // TexOutput(_T("</NOFRAMES>"));
544 if (previousLabel
&& previousFilename
)
546 if (PrimaryAnchorOfTheFile(previousFilename
, previousLabel
))
547 wxSnprintf(buf
, sizeof(buf
),
548 _T("<A HREF=\"%s\">%s</A> "),
549 ConvertCase(previousFilename
), backReference
);
551 wxSnprintf(buf
, sizeof(buf
),
552 _T("<A HREF=\"%s#%s\">%s</A> "),
553 ConvertCase(previousFilename
), previousLabel
, backReference
);
554 if (wxStrcmp(previousLabel
, _T("contents")) == 0)
556 // TexOutput(_T("<NOFRAMES>"));
558 // TexOutput(_T("</NOFRAMES>"));
565 // A placeholder so the buttons don't keep moving position
566 wxSnprintf(buf
, sizeof(buf
), _T("%s "), backReference
);
570 wxChar
*nextLabel
= NULL
;
571 wxChar
*nextFilename
= NULL
;
573 // Get the next page, and record the previous page's 'next' page
575 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
578 nextLabel
= nextPage
->label
;
579 nextFilename
= nextPage
->filename
;
581 if (previousLabel
&& previousFilename
)
583 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
587 TexNextPages
.Delete(previousLabel
);
589 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
590 TexNextPages
.Put(previousLabel
, newNextPage
);
598 if (nextLabel
&& nextFilename
)
600 if (PrimaryAnchorOfTheFile(nextFilename
, nextLabel
))
601 wxSnprintf(buf
, sizeof(buf
),
602 _T("<A HREF=\"%s\">%s</A> "),
603 ConvertCase(nextFilename
), forwardReference
);
605 wxSnprintf(buf
, sizeof(buf
),
606 _T("<A HREF=\"%s#%s\">%s</A> "),
607 ConvertCase(nextFilename
), nextLabel
, forwardReference
);
612 // A placeholder so the buttons don't keep moving position
613 wxSnprintf(buf
, sizeof(buf
), _T("%s "), forwardReference
);
618 * Horizontal rule to finish it off nicely.
621 TexOutput(_T("</CENTER>"));
622 TexOutput(_T("<HR>\n"));
624 // Update last topic/filename
626 delete[] lastFileName
;
627 lastFileName
= copystring(thisFilename
);
630 lastTopic
= copystring(thisLabel
);
633 // A colour string is either 3 numbers separated by semicolons (RGB),
634 // or a reference to a GIF. Return the filename or a hex string like #934CE8
635 wxChar
*ParseColourString(wxChar
*bkStr
, bool *isPicture
)
637 static wxChar resStr
[300];
638 wxStrcpy(resStr
, bkStr
);
639 wxStringTokenizer
tok(resStr
, _T(";"), wxTOKEN_STRTOK
);
640 if (tok
.HasMoreTokens())
642 wxString token1
= tok
.GetNextToken();
643 if (!tok
.HasMoreTokens())
650 wxString token2
= tok
.GetNextToken();
652 if (tok
.HasMoreTokens())
654 wxString token3
= tok
.GetNextToken();
656 // Now convert 3 strings into decimal numbers, and then hex numbers.
657 int red
= wxAtoi(token1
.c_str());
658 int green
= wxAtoi(token2
.c_str());
659 int blue
= wxAtoi(token3
.c_str());
661 wxStrcpy(resStr
, _T("#"));
665 wxStrcat(resStr
, buf
);
666 DecToHex(green
, buf
);
667 wxStrcat(resStr
, buf
);
669 wxStrcat(resStr
, buf
);
678 void OutputFont(void)
680 // Only output <font face> if explicitly requested by htmlFaceName= directive in
681 // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's
685 // Output <FONT FACE=...>
686 TexOutput(_T("<FONT FACE=\""));
687 TexOutput(htmlFaceName
);
688 TexOutput(_T("\">\n"));
692 // Output start of <BODY> block
693 void OutputBodyStart(void)
695 TexOutput(_T("\n<BODY"));
696 if (backgroundImageString
)
698 bool isPicture
= false;
699 wxChar
*s
= ParseColourString(backgroundImageString
, &isPicture
);
702 TexOutput(_T(" BACKGROUND=\""));
707 if (backgroundColourString
)
709 bool isPicture
= false;
710 wxChar
*s
= ParseColourString(backgroundColourString
, &isPicture
);
713 TexOutput(_T(" BGCOLOR="));
718 // Set foreground text colour, if one is specified
719 if (textColourString
)
721 bool isPicture
= false;
722 wxChar
*s
= ParseColourString(textColourString
, &isPicture
);
725 TexOutput(_T(" TEXT=")); TexOutput(s
);
728 // Set link text colour, if one is specified
729 if (linkColourString
)
731 bool isPicture
= false;
732 wxChar
*s
= ParseColourString(linkColourString
, &isPicture
);
735 TexOutput(_T(" LINK=")); TexOutput(s
);
738 // Set followed link text colour, if one is specified
739 if (followedLinkColourString
)
741 bool isPicture
= false;
742 wxChar
*s
= ParseColourString(followedLinkColourString
, &isPicture
);
745 TexOutput(_T(" VLINK=")); TexOutput(s
);
748 TexOutput(_T(">\n"));
755 TexOutput(_T("<head>"));
756 if (htmlStylesheet
) {
757 TexOutput(_T("<link rel=stylesheet type=\"text/css\" href=\""));
758 TexOutput(htmlStylesheet
);
759 TexOutput(_T("\">"));
763 void HTMLHeadTo(FILE* f
)
766 wxFprintf(f
,_T("<head><link rel=stylesheet type=\"text/css\" href=\"%s\">"),htmlStylesheet
);
768 wxFprintf(f
,_T("<head>"));
771 // Called on start/end of macro examination
772 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
778 case ltCHAPTERHEADING
:
786 if (macroId
!= ltCHAPTERSTAR
)
789 SetCurrentOutput(NULL
);
790 startedSections
= true;
792 wxChar
*topicName
= FindTopicName(GetNextChunk());
793 ReopenFile(&Chapters
, &ChaptersName
, topicName
);
794 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
796 SetCurrentChapterName(topicName
, ChaptersName
);
797 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
799 SetCurrentOutput(Chapters
);
802 TexOutput(_T("<title>"));
803 OutputCurrentSection(); // Repeat section header
804 TexOutput(_T("</title></head>\n"));
807 wxChar titleBuf
[200];
808 if (truncateFilenames
)
809 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
811 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
813 wxFprintf(Chapters
, _T("<A NAME=\"%s\"></A>"), topicName
);
815 AddBrowseButtons(_T(""), titleBuf
, // Up
816 lastTopic
, lastFileName
, // Last topic
817 topicName
, ChaptersName
); // This topic
819 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
820 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
822 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), topicName
);
824 if (htmlFrameContents
&& FrameContents
)
826 SetCurrentOutput(FrameContents
);
827 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
828 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
));
830 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
), topicName
);
831 OutputCurrentSection();
832 wxFprintf(FrameContents
, _T("</A>\n"));
835 SetCurrentOutputs(Contents
, Chapters
);
836 wxFprintf(Chapters
, _T("\n<H2>"));
837 OutputCurrentSection();
838 wxFprintf(Contents
, _T("</A>\n"));
839 wxFprintf(Chapters
, _T("</H2>\n"));
841 SetCurrentOutput(Chapters
);
843 // Add this section title to the list of keywords
846 OutputCurrentSectionToString(wxTex2RTFBuffer
);
847 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, ConvertCase(currentFileName
));
854 case ltSECTIONHEADING
:
861 subsectionStarted
= false;
863 if (macroId
!= ltSECTIONSTAR
)
866 SetCurrentOutput(NULL
);
867 startedSections
= true;
869 wxChar
*topicName
= FindTopicName(GetNextChunk());
870 ReopenFile(&Sections
, &SectionsName
, topicName
);
871 AddTexRef(topicName
, SectionsName
, SectionNameString
);
873 SetCurrentSectionName(topicName
, SectionsName
);
874 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
876 SetCurrentOutput(Sections
);
878 TexOutput(_T("<title>"));
879 OutputCurrentSection();
880 TexOutput(_T("</title></head>\n"));
883 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
884 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
885 lastTopic
, lastFileName
, // Last topic
886 topicName
, SectionsName
); // This topic
888 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
890 SetCurrentOutputs(jumpFrom
, Sections
);
891 if (DocumentStyle
== LATEX_ARTICLE
)
893 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
894 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(SectionsName
));
896 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(SectionsName
), topicName
);
900 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
901 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SectionsName
));
903 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SectionsName
), topicName
);
906 wxFprintf(Sections
, _T("\n<H2>"));
907 OutputCurrentSection();
909 if (DocumentStyle
== LATEX_ARTICLE
)
910 wxFprintf(jumpFrom
, _T("</A>\n"));
912 wxFprintf(jumpFrom
, _T("</B></A><BR>\n"));
913 wxFprintf(Sections
, _T("</H2>\n"));
915 SetCurrentOutput(Sections
);
916 // Add this section title to the list of keywords
919 OutputCurrentSectionToString(wxTex2RTFBuffer
);
920 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
926 case ltSUBSECTIONSTAR
:
927 case ltMEMBERSECTION
:
928 case ltFUNCTIONSECTION
:
934 OnError(_T("You cannot have a subsection before a section!"));
940 if (macroId
!= ltSUBSECTIONSTAR
)
943 if ( combineSubSections
&& !subsectionStarted
)
947 // Read old .con file in at this point
949 wxStrcpy(buf
, CurrentSectionFile
);
950 wxStripExtension(buf
);
951 wxStrcat(buf
, _T(".con"));
952 FILE *fd
= wxFopen(buf
, _T("r"));
958 wxPutc(ch
, Sections
);
963 wxFprintf(Sections
, _T("<P>\n"));
965 // Close old file, create a new file for the sub(sub)section contents entries
966 ReopenSectionContentsFile();
969 startedSections
= true;
970 subsectionStarted
= true;
972 wxChar
*topicName
= FindTopicName(GetNextChunk());
974 if ( !combineSubSections
)
976 SetCurrentOutput(NULL
);
977 ReopenFile(&Subsections
, &SubsectionsName
, topicName
);
978 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
979 SetCurrentSubsectionName(topicName
, SubsectionsName
);
980 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
981 SetCurrentOutput(Subsections
);
984 TexOutput(_T("<title>"));
985 OutputCurrentSection();
986 TexOutput(_T("</title></head>\n"));
989 wxFprintf(Subsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
990 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
991 lastTopic
, lastFileName
, // Last topic
992 topicName
, SubsectionsName
); // This topic
994 SetCurrentOutputs(Sections
, Subsections
);
995 if(PrimaryAnchorOfTheFile(SubsectionsName
, topicName
))
996 wxFprintf(Sections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsectionsName
));
998 wxFprintf(Sections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName
), topicName
);
1000 wxFprintf(Subsections
, _T("\n<H3>"));
1001 OutputCurrentSection();
1002 wxFprintf(Sections
, _T("</B></A><BR>\n"));
1003 wxFprintf(Subsections
, _T("</H3>\n"));
1005 SetCurrentOutput(Subsections
);
1009 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
1010 SetCurrentSubsectionName(topicName
, SectionsName
);
1012 // if ( subsectionNo != 0 )
1013 wxFprintf(Sections
, _T("\n<HR>\n"));
1015 // We're putting everything into the section file
1016 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1017 wxFprintf(Sections
, _T("\n<H3>"));
1018 OutputCurrentSection();
1019 wxFprintf(Sections
, _T("</H3>\n"));
1021 SetCurrentOutput(SectionContentsFD
);
1022 wxFprintf(SectionContentsFD
, _T("<A HREF=\"#%s\">"), topicName
);
1023 OutputCurrentSection();
1024 TexOutput(_T("</A><BR>\n"));
1026 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
1027 SetCurrentOutput(Sections
);
1029 // Add this section title to the list of keywords
1032 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1033 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1040 case ltSUBSUBSECTION
:
1041 case ltSUBSUBSECTIONSTAR
:
1045 if (!Subsections
&& !combineSubSections
)
1047 OnError(_T("You cannot have a subsubsection before a subsection!"));
1051 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1054 startedSections
= true;
1056 wxChar
*topicName
= FindTopicName(GetNextChunk());
1058 if ( !combineSubSections
)
1060 SetCurrentOutput(NULL
);
1061 ReopenFile(&Subsubsections
, &SubsubsectionsName
, topicName
);
1062 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
1063 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
1064 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
1066 SetCurrentOutput(Subsubsections
);
1068 TexOutput(_T("<title>"));
1069 OutputCurrentSection();
1070 TexOutput(_T("</title></head>\n"));
1073 wxFprintf(Subsubsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1075 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
1076 lastTopic
, lastFileName
, // Last topic
1077 topicName
, SubsubsectionsName
); // This topic
1079 SetCurrentOutputs(Subsections
, Subsubsections
);
1080 if(PrimaryAnchorOfTheFile(SubsubsectionsName
, topicName
))
1081 wxFprintf(Subsections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsubsectionsName
));
1083 wxFprintf(Subsections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName
), topicName
);
1085 wxFprintf(Subsubsections
, _T("\n<H3>"));
1086 OutputCurrentSection();
1087 wxFprintf(Subsections
, _T("</B></A><BR>\n"));
1088 wxFprintf(Subsubsections
, _T("</H3>\n"));
1092 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
1093 SetCurrentSubsectionName(topicName
, SectionsName
);
1094 wxFprintf(Sections
, _T("\n<HR>\n"));
1096 // We're putting everything into the section file
1097 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1098 wxFprintf(Sections
, _T("\n<H3>"));
1099 OutputCurrentSection();
1100 wxFprintf(Sections
, _T("</H3>\n"));
1101 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
1102 SetCurrentOutput(SectionContentsFD);
1103 wxFprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
1104 OutputCurrentSection();
1105 TexOutput(_T("</A><BR>"));
1107 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
1108 SetCurrentOutput(Sections
);
1111 // Add this section title to the list of keywords
1114 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1115 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1124 if ( !combineSubSections
)
1125 SetCurrentOutput(Subsections
);
1127 SetCurrentOutput(Sections
);
1138 if ( !combineSubSections
)
1139 SetCurrentOutput(Subsections
);
1141 SetCurrentOutput(Sections
);
1152 if ( !combineSubSections
)
1153 SetCurrentOutput(Subsections
);
1155 SetCurrentOutput(Sections
);
1166 // TexOutput(_T("<B>void</B>"));
1170 TexOutput(_T("HARDY"));
1174 TexOutput(_T("wxCLIPS"));
1178 TexOutput(_T("&"));
1180 case ltSPECIALAMPERSAND
:
1186 // End cell, start cell
1188 TexOutput(_T("</FONT></TD>"));
1190 // Start new row and cell, setting alignment for the first cell.
1191 if (currentColumn
< noColumns
)
1195 if (TableData
[currentColumn
].justification
== 'c')
1196 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=CENTER>"));
1197 else if (TableData
[currentColumn
].justification
== 'r')
1198 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=RIGHT>"));
1199 else if (TableData
[currentColumn
].absWidth
)
1201 // Convert from points * 20 into pixels.
1202 int points
= TableData
[currentColumn
].width
/ 20;
1204 // Say the display is 100 DPI (dots/pixels per inch).
1205 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1206 int pixels
= (int)(points
* 100.0 / 72.0);
1207 wxSnprintf(buf
, sizeof(buf
), _T("<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1210 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=LEFT>"));
1215 TexOutput(_T("&"));
1219 case ltBACKSLASHCHAR
:
1225 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1226 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1227 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1228 TexOutput(_T("</TR>\n"));
1231 TexOutput(_T("<BR>\n"));
1242 // Start new row and cell, setting alignment for the first cell.
1244 if (TableData
[currentColumn
].justification
== 'c')
1245 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER>"));
1246 else if (TableData
[currentColumn
].justification
== 'r')
1247 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=RIGHT>"));
1248 else if (TableData
[currentColumn
].absWidth
)
1250 // Convert from points * 20 into pixels.
1251 int points
= TableData
[currentColumn
].width
/ 20;
1253 // Say the display is 100 DPI (dots/pixels per inch).
1254 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1255 int pixels
= (int)(points
* 100.0 / 72.0);
1256 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1259 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=LEFT>"));
1266 // Start new row and cell
1267 TexOutput(_T("</FONT></TD>\n</TR>\n"));
1271 // HTML-only: break until the end of the picture (both margins are clear).
1275 TexOutput(_T("<BR CLEAR=ALL>"));
1278 case ltRTFSP
: // Explicit space, RTF only
1280 case ltSPECIALTILDE
:
1284 #if (1) // if(inVerbatim)
1295 TexOutput(_T("<UL><UL>\n"));
1297 TexOutput(_T("</UL></UL>\n"));
1303 // case ltTWOCOLLIST:
1310 if (macroId
== ltENUMERATE
)
1311 listType
= LATEX_ENUMERATE
;
1312 else if (macroId
== ltITEMIZE
)
1313 listType
= LATEX_ITEMIZE
;
1315 listType
= LATEX_DESCRIPTION
;
1317 itemizeStack
.Insert(new ItemizeStruc(listType
));
1321 TexOutput(_T("<UL>\n"));
1323 case LATEX_ENUMERATE
:
1324 TexOutput(_T("<OL>\n"));
1326 case LATEX_DESCRIPTION
:
1328 TexOutput(_T("<DL>\n"));
1335 if (itemizeStack
.GetFirst())
1337 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
1338 switch (struc
->listType
)
1341 TexOutput(_T("</UL>\n"));
1343 case LATEX_ENUMERATE
:
1344 TexOutput(_T("</OL>\n"));
1346 case LATEX_DESCRIPTION
:
1348 TexOutput(_T("</DL>\n"));
1353 delete itemizeStack
.GetFirst();
1361 TexOutput(_T("\n<TABLE>\n"));
1363 TexOutput(_T("\n</TABLE>\n"));
1373 TexOutput(_T("<P>\n"));
1376 /* For footnotes we need to output the text at the bottom of the page and
1377 * insert a reference to it. Is it worth the trouble...
1379 case ltFOOTNOTEPOPUP:
1383 TexOutput(_T("<FN>"));
1385 else TexOutput(_T("</FN>"));
1392 TexOutput(_T("<TT>"));
1393 else TexOutput(_T("</TT>"));
1401 wxSnprintf(buf
, sizeof(buf
), _T("<PRE>\n"));
1404 else TexOutput(_T("</PRE>\n"));
1412 TexOutput(_T("<CENTER>"));
1414 else TexOutput(_T("</CENTER>"));
1422 TexOutput(_T("{\\ql "));
1424 else TexOutput(_T("}\\par\\pard\n"));
1433 TexOutput(_T("{\\qr "));
1435 else TexOutput(_T("}\\par\\pard\n"));
1443 // Netscape extension
1444 TexOutput(_T("<FONT SIZE=2>"));
1446 else TexOutput(_T("</FONT>"));
1453 // Netscape extension
1454 TexOutput(_T("<FONT SIZE=1>"));
1456 else TexOutput(_T("</FONT>"));
1463 // Netscape extension
1464 TexOutput(_T("<FONT SIZE=3>"));
1466 else TexOutput(_T("</FONT>"));
1473 // Netscape extension
1474 TexOutput(_T("<FONT SIZE=4>"));
1476 else TexOutput(_T("</FONT>"));
1483 // Netscape extension
1484 TexOutput(_T("<FONT SIZE=5>"));
1486 else TexOutput(_T("</FONT>"));
1493 // Netscape extension
1494 TexOutput(_T("<FONT SIZE=6>"));
1496 else TexOutput(_T("</FONT>"));
1505 TexOutput(_T("<B>"));
1507 else TexOutput(_T("</B>"));
1516 TexOutput(_T("<I>"));
1518 else TexOutput(_T("</I>"));
1526 TexOutput(_T("<EM>"));
1528 else TexOutput(_T("</EM>"));
1535 TexOutput(_T("<UL>"));
1537 else TexOutput(_T("</UL>"));
1546 TexOutput(_T("<TT>"));
1548 else TexOutput(_T("</TT>"));
1554 TexOutput(_T("©"), true);
1560 TexOutput(_T("®"), true);
1566 if (start
) TexOutput(_T("<--"));
1571 if (start
) TexOutput(_T("<=="));
1576 if (start
) TexOutput(_T("-->"));
1581 if (start
) TexOutput(_T("==>"));
1584 case ltLEFTRIGHTARROW
:
1586 if (start
) TexOutput(_T("<-->"));
1589 case ltLEFTRIGHTARROW2
:
1591 if (start
) TexOutput(_T("<==>"));
1604 wxNode
*node
= itemizeStack
.GetFirst();
1607 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
1608 struc
->currentItem
+= 1;
1609 if (struc
->listType
== LATEX_DESCRIPTION
)
1611 if (descriptionItemArg
)
1613 TexOutput(_T("<DT> "));
1614 TraverseChildrenFromChunk(descriptionItemArg
);
1615 TexOutput(_T("\n"));
1616 descriptionItemArg
= NULL
;
1618 TexOutput(_T("<DD>"));
1621 TexOutput(_T("<LI>"));
1628 if (start
&& DocumentTitle
&& DocumentAuthor
)
1630 // Add a special label for the contents page.
1631 // TexOutput(_T("<CENTER>\n"));
1632 TexOutput(_T("<A NAME=\"contents\">"));
1633 TexOutput(_T("<H2 ALIGN=CENTER>\n"));
1634 TraverseChildrenFromChunk(DocumentTitle
);
1635 TexOutput(_T("</H2>"));
1636 TexOutput(_T("<P>"));
1637 TexOutput(_T("</A>\n"));
1638 TexOutput(_T("<P>\n\n"));
1639 TexOutput(_T("<H3 ALIGN=CENTER>"));
1640 TraverseChildrenFromChunk(DocumentAuthor
);
1641 TexOutput(_T("</H3><P>\n\n"));
1644 TexOutput(_T("<H3 ALIGN=CENTER>"));
1645 TraverseChildrenFromChunk(DocumentDate
);
1646 TexOutput(_T("</H3><P>\n\n"));
1648 // TexOutput(_T("\n</CENTER>\n"));
1649 TexOutput(_T("\n<P><HR><P>\n"));
1652 // Now do optional frame contents page
1653 if (htmlFrameContents && FrameContents)
1655 SetCurrentOutput(FrameContents);
1657 // Add a special label for the contents page.
1658 TexOutput(_T("<CENTER>\n"));
1659 TexOutput(_T("<H3>\n"));
1660 TraverseChildrenFromChunk(DocumentTitle);
1661 TexOutput(_T("</H3>"));
1662 TexOutput(_T("<P>"));
1663 TexOutput(_T("</A>\n"));
1664 TexOutput(_T("<P>\n\n"));
1665 TexOutput(_T("<H3>"));
1666 TraverseChildrenFromChunk(DocumentAuthor);
1667 TexOutput(_T("</H3><P>\n\n"));
1670 TexOutput(_T("<H4>"));
1671 TraverseChildrenFromChunk(DocumentDate);
1672 TexOutput(_T("</H4><P>\n\n"));
1674 TexOutput(_T("\n</CENTER>\n"));
1675 TexOutput(_T("<P><HR><P>\n"));
1677 SetCurrentOutput(Titlepage);
1690 helpRefFilename
= NULL
;
1695 case ltBIBLIOGRAPHY
:
1699 DefaultOnMacro(macroId
, no_args
, start
);
1703 DefaultOnMacro(macroId
, no_args
, start
);
1704 TexOutput(_T("</DL>\n"));
1712 TexOutput(_T("<HR>\n"));
1720 TexOutput(_T("<HR>\n"));
1724 case ltTABLEOFCONTENTS
:
1728 // NB: if this is uncommented, the table of contents
1729 // completely disappears. If left commented, it's in the wrong
1731 //fflush(Titlepage);
1733 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1739 wxPutc(ch
, Titlepage
);
1747 TexOutput(_T("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n"));
1748 OnInform(_T("Run Tex2RTF again to include contents page."));
1756 TexOutput(_T("<"));
1762 TexOutput(_T(">"));
1769 TexOutput(_T("<BLOCKQUOTE>"));
1771 TexOutput(_T("</BLOCKQUOTE>"));
1780 TexOutput(_T("\n<CAPTION>"));
1788 if (DocumentStyle
!= LATEX_ARTICLE
)
1789 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1791 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), FigureNameString
, figureNo
);
1797 if (DocumentStyle
!= LATEX_ARTICLE
)
1798 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1800 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), TableNameString
, tableNo
);
1808 TexOutput(_T("\n</CAPTION>\n"));
1810 wxChar
*topicName
= FindTopicName(GetNextChunk());
1812 int n
= inFigure
? figureNo
: tableNo
;
1814 AddTexRef(topicName
, NULL
, NULL
,
1815 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1816 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1822 if (start
) TexOutput(_T("ß"));
1827 if (start
) inFigure
= true;
1828 else inFigure
= false;
1833 if (start
) inTable
= true;
1834 else inTable
= false;
1838 DefaultOnMacro(macroId
, no_args
, start
);
1844 should be called at of argument which usually is
1845 type declaration which propably contains name of
1854 checks: GetArgData() if contains Type Declaration
1855 and can be referenced to some file
1857 before<a href="xxx&yyy">type</a>after
1860 false - if no reference was found
1861 true - if reference was found and HREF printed
1863 static bool CheckTypeRef()
1865 wxString typeDecl
= GetArgData();
1866 if( !typeDecl
.empty() ) {
1867 typeDecl
.Replace(wxT("\\"),wxT(""));
1868 wxString label
= typeDecl
;
1869 label
.Replace(wxT("const"),wxT(""));
1870 label
.Replace(wxT("virtual"),wxT(""));
1871 label
.Replace(wxT("static"),wxT(""));
1872 label
.Replace(wxT("extern"),wxT(""));
1873 label
= label
.BeforeFirst('&');
1874 label
= label
.BeforeFirst(wxT('*'));
1875 label
= label
.BeforeFirst(wxT('\\'));
1876 label
.Trim(true); label
.Trim(false);
1877 wxString typeName
= label
;
1879 TexRef
*texRef
= FindReference((wxChar
*)label
.c_str());
1881 if (texRef
&& texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0) {
1882 int a
= typeDecl
.Find(typeName
);
1883 wxString before
= typeDecl
.Mid( 0, a
);
1884 wxString after
= typeDecl
.Mid( a
+typeName
.Length() );
1885 //wxFprintf(stderr,wxT("%s <%s> %s to ... %s#%s !!!!\n"),
1887 // typeName.c_str(),
1889 // texRef->refFile,label.c_str());
1891 TexOutput(_T("<A HREF=\""));
1892 TexOutput(texRef
->refFile
);
1895 TexOutput(wxT("\">"));
1896 TexOutput(typeName
);
1897 TexOutput(wxT("</A>"));
1901 //wxFprintf(stderr,wxT("'%s' from (%s) -> label %s NOT FOUND\n"),
1902 // typeName.c_str(),
1903 // typeDecl.c_str(),
1910 // Called on start/end of argument examination
1911 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1917 case ltCHAPTERHEADING
:
1920 case ltSECTIONHEADING
:
1922 case ltSUBSECTIONSTAR
:
1923 case ltSUBSUBSECTION
:
1924 case ltSUBSUBSECTIONSTAR
:
1926 case ltMEMBERSECTION
:
1927 case ltFUNCTIONSECTION
:
1929 if (!start
&& (arg_no
== 1))
1930 currentSection
= GetArgChunk();
1935 if (start
&& (arg_no
== 1)) {
1936 TexOutput(_T("<B>"));
1937 if( CheckTypeRef() ) {
1938 TexOutput(_T("</B> "));
1943 if (!start
&& (arg_no
== 1))
1944 TexOutput(_T("</B> "));
1946 if (start
&& (arg_no
== 2))
1948 if (!suppressNameDecoration
) TexOutput(_T("<B>"));
1949 currentMember
= GetArgChunk();
1951 if (!start
&& (arg_no
== 2))
1953 if (!suppressNameDecoration
) TexOutput(_T("</B>"));
1956 if (start
&& (arg_no
== 3))
1958 if (!start
&& (arg_no
== 3))
1964 if (start
&& (arg_no
== 1))
1965 TexOutput(_T("<B>"));
1966 if (!start
&& (arg_no
== 1))
1967 TexOutput(_T("</B> "));
1969 if (start
&& (arg_no
== 2))
1971 if (!suppressNameDecoration
) TexOutput(_T("( "));
1972 currentMember
= GetArgChunk();
1974 if (!start
&& (arg_no
== 2))
1978 if (!start
&& (arg_no
== 3))
1984 if (!start
&& (arg_no
== 1))
1987 if (start
&& (arg_no
== 2))
1988 TexOutput(_T("(*"));
1989 if (!start
&& (arg_no
== 2))
1992 if (start
&& (arg_no
== 2))
1993 currentMember
= GetArgChunk();
1995 if (start
&& (arg_no
== 3))
1997 if (!start
&& (arg_no
== 3))
2004 const wxChar
* pend
= macroId
== ltCPARAM
?
2005 _T("</B> ") : _T("</B>");
2008 TexOutput(_T("<B>"));
2009 if( CheckTypeRef() ) {
2017 if (start
&& (arg_no
== 2))
2019 TexOutput(_T("<I>"));
2021 if (!start
&& (arg_no
== 2))
2023 TexOutput(_T("</I>"));
2029 if (!start
&& (arg_no
== 1))
2032 if (start
&& (arg_no
== 2))
2033 currentMember
= GetArgChunk();
2042 wxChar
*refName
= GetArgData();
2045 TexRef
*texRef
= FindReference(refName
);
2048 sec
= texRef
->sectionNumber
;
2061 if (IsArgOptional())
2063 else if ((GetNoArgs() - arg_no
) == 1)
2066 helpRefText
= GetArgChunk();
2069 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2073 TexChunk
*ref
= GetArgChunk();
2074 TexOutput(_T("<A HREF=\""));
2076 TraverseChildrenFromChunk(ref
);
2078 TexOutput(_T("\">"));
2080 TraverseChildrenFromChunk(helpRefText
);
2081 TexOutput(_T("</A>"));
2092 if (IsArgOptional())
2095 helpRefFilename
= GetArgChunk();
2098 if ((GetNoArgs() - arg_no
) == 1)
2101 helpRefText
= GetArgChunk();
2104 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2108 wxChar
*refName
= GetArgData();
2109 wxChar
*refFilename
= NULL
;
2113 TexRef
*texRef
= FindReference(refName
);
2116 if (texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0)
2117 refFilename
= texRef
->refFile
;
2119 TexOutput(_T("<A HREF=\""));
2120 // If a filename is supplied, use it, otherwise try to
2121 // use the filename associated with the reference (from this document).
2122 if (helpRefFilename
)
2124 TraverseChildrenFromChunk(helpRefFilename
);
2128 else if (refFilename
)
2130 TexOutput(ConvertCase(refFilename
));
2131 if(!PrimaryAnchorOfTheFile(texRef
->refFile
, refName
))
2137 TexOutput(_T("\">"));
2139 TraverseChildrenFromChunk(helpRefText
);
2140 TexOutput(_T("</A>"));
2145 TraverseChildrenFromChunk(helpRefText
);
2147 TexOutput(_T(" (REF NOT FOUND)"));
2149 // for launching twice do not warn in preparation pass
2150 if ((passNumber
== 1 && !runTwice
) ||
2151 (passNumber
== 2 && runTwice
))
2154 errBuf
.Printf(_T("Warning: unresolved reference '%s'"), refName
);
2155 OnInform((wxChar
*)errBuf
.c_str());
2159 else TexOutput(_T("??"));
2174 wxChar
*alignment
= _T("");
2175 if (macroId
== ltIMAGEL
)
2176 alignment
= _T(" align=left");
2177 else if (macroId
== ltIMAGER
)
2178 alignment
= _T(" align=right");
2180 // Try to find an XBM or GIF image first.
2181 wxChar
*filename
= copystring(GetArgData());
2184 wxStrcpy(buf
, filename
);
2185 StripExtension(buf
);
2186 wxStrcat(buf
, _T(".xbm"));
2187 wxString f
= TexPathList
.FindValidPath(buf
);
2189 if (f
== _T("")) // Try for a GIF instead
2191 wxStrcpy(buf
, filename
);
2192 StripExtension(buf
);
2193 wxStrcat(buf
, _T(".gif"));
2194 f
= TexPathList
.FindValidPath(buf
);
2197 if (f
== _T("")) // Try for a JPEG instead
2199 wxStrcpy(buf
, filename
);
2200 StripExtension(buf
);
2201 wxStrcat(buf
, _T(".jpg"));
2202 f
= TexPathList
.FindValidPath(buf
);
2205 if (f
== _T("")) // Try for a PNG instead
2207 wxStrcpy(buf
, filename
);
2208 StripExtension(buf
);
2209 wxStrcat(buf
, _T(".png"));
2210 f
= TexPathList
.FindValidPath(buf
);
2215 wxChar
*inlineFilename
= copystring(f
);
2217 wxChar
*originalFilename
= TexPathList
.FindValidPath(filename
);
2218 // If we have found the existing filename, make the inline
2219 // image point to the original file (could be PS, for example)
2220 if (originalFilename
&& (wxStrcmp(inlineFilename
, originalFilename
) != 0))
2222 TexOutput(_T("<A HREF=\""));
2223 TexOutput(ConvertCase(originalFilename
));
2224 TexOutput(_T("\">"));
2225 TexOutput(_T("<img src=\""));
2226 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2227 TexOutput(_T("\""));
2228 TexOutput(alignment
);
2229 TexOutput(_T("></A>"));
2234 TexOutput(_T("<img src=\""));
2235 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2236 TexOutput(_T("\""));
2237 TexOutput(alignment
);
2239 delete[] inlineFilename
;
2244 // Last resort - a link to a PS file.
2245 TexOutput(_T("<A HREF=\""));
2246 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
2247 TexOutput(_T("\">Picture</A>\n"));
2248 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2255 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2258 static wxChar
*imageFile
= NULL
;
2259 if (start
&& (arg_no
== 2))
2261 // Try to find an XBM or GIF image first.
2262 wxChar
*filename
= copystring(GetArgData());
2265 wxStrcpy(buf
, filename
);
2266 StripExtension(buf
);
2267 wxStrcat(buf
, _T(".xbm"));
2268 wxString f
= TexPathList
.FindValidPath(buf
);
2270 if (f
== _T("")) // Try for a GIF instead
2272 wxStrcpy(buf
, filename
);
2273 StripExtension(buf
);
2274 wxStrcat(buf
, _T(".gif"));
2275 f
= TexPathList
.FindValidPath(buf
);
2280 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2289 imageFile
= copystring(f
);
2292 else if (start
&& (arg_no
== 3))
2296 // First, try to find a .shg (segmented hypergraphics file)
2297 // that we can convert to a map file
2299 wxStrcpy(buf
, imageFile
);
2300 StripExtension(buf
);
2301 wxStrcat(buf
, _T(".shg"));
2302 wxString f
= TexPathList
.FindValidPath(buf
);
2306 // The default HTML file to go to is THIS file (so a no-op)
2307 SHGToMap((wxChar
*)f
.c_str(), currentFileName
);
2310 wxChar
*mapName
= GetArgData();
2311 TexOutput(_T("<A HREF=\"/cgi-bin/imagemap/"));
2315 TexOutput(_T("unknown"));
2316 TexOutput(_T("\">"));
2317 TexOutput(_T("<img src=\""));
2318 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2319 TexOutput(_T("\" ISMAP></A><P>"));
2339 descriptionItemArg
= GetArgChunk();
2345 case ltTWOCOLITEMRULED
:
2348 if (start && (arg_no == 1))
2349 TexOutput(_T("\n<DT> "));
2350 if (start && (arg_no == 2))
2351 TexOutput(_T("<DD> "));
2357 if (TwoColWidthA
> -1)
2360 wxSnprintf(buf
, sizeof(buf
), _T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA
);
2365 TexOutput(_T("\n<TR><TD VALIGN=TOP>\n"));
2369 TexOutput(_T("\n</FONT></TD>\n"));
2376 if (TwoColWidthB
> -1)
2379 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB
);
2384 TexOutput(_T("\n<TD VALIGN=TOP>\n"));
2388 TexOutput(_T("\n</FONT></TD></TR>\n"));
2392 case ltNUMBEREDBIBITEM
:
2394 if (arg_no
== 1 && start
)
2396 TexOutput(_T("\n<DT> "));
2398 if (arg_no
== 2 && !start
)
2399 TexOutput(_T("<P>\n"));
2405 if (arg_no
== 1 && start
)
2407 wxChar
*citeKey
= GetArgData();
2408 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2411 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2412 wxSnprintf(buf
, sizeof(buf
), _T("[%d]"), citeCount
);
2413 ref
->sectionNumber
= copystring(buf
);
2416 wxSnprintf(buf
, sizeof(buf
), _T("\n<DT> [%d] "), citeCount
);
2421 if (arg_no
== 2 && !start
)
2422 TexOutput(_T("<P>\n"));
2426 case ltMARGINPARODD
:
2427 case ltMARGINPAREVEN
:
2433 TexOutput(_T("<HR>\n"));
2437 TexOutput(_T("<HR><P>\n"));
2441 case ltTWOCOLWIDTHA
:
2445 wxChar
*val
= GetArgData();
2446 float points
= ParseUnitArgument(val
);
2447 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2452 case ltTWOCOLWIDTHB
:
2456 wxChar
*val
= GetArgData();
2457 float points
= ParseUnitArgument(val
);
2458 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2466 case ltACCENT_GRAVE
:
2470 wxChar
*val
= GetArgData();
2476 TexOutput(_T("à"));
2479 TexOutput(_T("è"));
2482 TexOutput(_T("ì"));
2485 TexOutput(_T("ò"));
2488 TexOutput(_T("ù"));
2491 TexOutput(_T("À"));
2494 TexOutput(_T("È"));
2497 TexOutput(_T("Ì"));
2500 TexOutput(_T("Ò"));
2503 TexOutput(_T("Ì"));
2512 case ltACCENT_ACUTE
:
2516 wxChar
*val
= GetArgData();
2522 TexOutput(_T("á"));
2525 TexOutput(_T("é"));
2528 TexOutput(_T("í"));
2531 TexOutput(_T("ó"));
2534 TexOutput(_T("ú"));
2537 TexOutput(_T("ý"));
2540 TexOutput(_T("Á"));
2543 TexOutput(_T("É"));
2546 TexOutput(_T("Í"));
2549 TexOutput(_T("Ó"));
2552 TexOutput(_T("Ú"));
2555 TexOutput(_T("Ý"));
2564 case ltACCENT_CARET
:
2568 wxChar
*val
= GetArgData();
2574 TexOutput(_T("â"));
2577 TexOutput(_T("ê"));
2580 TexOutput(_T("î"));
2583 TexOutput(_T("ô"));
2586 TexOutput(_T("û"));
2589 TexOutput(_T("Â"));
2592 TexOutput(_T("Ê"));
2595 TexOutput(_T("Î"));
2598 TexOutput(_T("Ô"));
2601 TexOutput(_T("Î"));
2610 case ltACCENT_TILDE
:
2614 wxChar
*val
= GetArgData();
2623 TexOutput(_T("ã"));
2626 TexOutput(_T("ñ"));
2629 TexOutput(_T("õ"));
2632 TexOutput(_T("Ã"));
2635 TexOutput(_T("Ñ"));
2638 TexOutput(_T("Õ"));
2647 case ltACCENT_UMLAUT
:
2651 wxChar
*val
= GetArgData();
2657 TexOutput(_T("ä"));
2660 TexOutput(_T("ë"));
2663 TexOutput(_T("ï"));
2666 TexOutput(_T("ö"));
2669 TexOutput(_T("ü"));
2672 TexOutput(_T("ÿ"));
2675 TexOutput(_T("Ä"));
2678 TexOutput(_T("Ë"));
2681 TexOutput(_T("Ï"));
2684 TexOutput(_T("Ö"));
2687 TexOutput(_T("Ü"));
2690 TexOutput(_T("Ÿ"));
2703 wxChar
*val
= GetArgData();
2709 TexOutput(_T("å"));
2712 TexOutput(_T("Å"));
2725 wxChar
*val
= GetArgData();
2728 bool isPicture
= false;
2729 ParseColourString(val
, &isPicture
);
2732 if (backgroundImageString
)
2733 delete[] backgroundImageString
;
2734 backgroundImageString
= copystring(val
);
2738 if (backgroundColourString
)
2739 delete[] backgroundColourString
;
2740 backgroundColourString
= copystring(val
);
2746 case ltBACKGROUNDIMAGE
:
2750 wxChar
*val
= GetArgData();
2753 if (backgroundImageString
)
2754 delete[] backgroundImageString
;
2755 backgroundImageString
= copystring(val
);
2760 case ltBACKGROUNDCOLOUR
:
2764 wxChar
*val
= GetArgData();
2767 if (backgroundColourString
)
2768 delete[] backgroundColourString
;
2769 backgroundColourString
= copystring(val
);
2778 wxChar
*val
= GetArgData();
2781 if (textColourString
)
2782 delete[] textColourString
;
2783 textColourString
= copystring(val
);
2792 wxChar
*val
= GetArgData();
2795 if (linkColourString
)
2796 delete[] linkColourString
;
2797 linkColourString
= copystring(val
);
2802 case ltFOLLOWEDLINKCOLOUR
:
2806 wxChar
*val
= GetArgData();
2809 if (followedLinkColourString
)
2810 delete[] followedLinkColourString
;
2811 followedLinkColourString
= copystring(val
);
2816 case ltACCENT_CADILLA
:
2820 wxChar
*val
= GetArgData();
2826 TexOutput(_T("ç"));
2829 TexOutput(_T("Ç"));
2840 case ltFOOTNOTEPOPUP:
2850 case ltSUPERTABULAR
:
2856 currentRowNumber
= 0;
2859 tableVerticalLineLeft
= false;
2860 tableVerticalLineRight
= false;
2862 wxChar
*alignString
= copystring(GetArgData());
2863 ParseTableArgument(alignString
);
2865 TexOutput(_T("<TABLE BORDER>\n"));
2867 // Write the first row formatting for compatibility
2868 // with standard Latex
2869 if (compatibilityMode
)
2871 TexOutput(_T("<TR>\n<TD>"));
2874 for (int i = 0; i < noColumns; i++)
2876 currentWidth += TableData[i].width;
2877 wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth);
2880 TexOutput(_T("\\pard\\intbl\n"));
2883 delete[] alignString
;
2888 else if (arg_no
== 2 && !start
)
2890 TexOutput(_T("</TABLE>\n"));
2895 case ltTHEBIBLIOGRAPHY
:
2897 if (start
&& (arg_no
== 1))
2899 ReopenFile(&Chapters
, &ChaptersName
, _T("bibliography"));
2900 AddTexRef(_T("bibliography"), ChaptersName
, _T("bibliography"));
2901 SetCurrentSubsectionName(_T("bibliography"), ChaptersName
);
2905 SetCurrentOutput(Chapters
);
2907 wxChar titleBuf
[150];
2908 if (truncateFilenames
)
2909 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
2911 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
2914 TexOutput(_T("<title>"));
2915 TexOutput(ReferencesNameString
);
2916 TexOutput(_T("</title></head>\n"));
2919 wxFprintf(Chapters
, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString
);
2920 AddBrowseButtons(_T("contents"), titleBuf
, // Up
2921 lastTopic
, lastFileName
, // Last topic
2922 _T("bibliography"), ChaptersName
); // This topic
2924 SetCurrentOutputs(Contents
, Chapters
);
2925 if(PrimaryAnchorOfTheFile(ChaptersName
, _T("bibliography")))
2926 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
2928 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), _T("bibliography"));
2930 wxFprintf(Contents
, _T("%s</A>\n"), ReferencesNameString
);
2931 wxFprintf(Chapters
, _T("</H2>\n</A>\n"));
2933 SetCurrentOutput(Chapters
);
2936 if (!start
&& (arg_no
== 2))
2943 /* Build up list of keywords associated with topics */
2946 // wxChar *entry = GetArgData();
2948 OutputChunkToString(GetArgChunk(), buf
);
2951 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2965 wxChar
*name
= GetArgData();
2967 if (!FindColourHTMLString(name
, buf2
))
2969 wxStrcpy(buf2
, _T("#000000"));
2971 wxSnprintf(buf
, sizeof(buf
), _T("Could not find colour name %s"), name
);
2974 TexOutput(_T("<FONT COLOR=\""));
2976 TexOutput(_T("\">"));
2989 if (arg_no
== 2) TexOutput(_T("</FONT>"));
2993 case ltINSERTATLEVEL
:
2995 // This macro allows you to insert text at a different level
2996 // from the current level, e.g. into the Sections from within a subsubsection.
2999 static int currentLevelNo
= 1;
3000 static FILE* oldLevelFile
= Chapters
;
3007 oldLevelFile
= CurrentOutput1
;
3009 wxChar
*str
= GetArgData();
3010 currentLevelNo
= wxAtoi(str
);
3012 // TODO: cope with article style (no chapters)
3013 switch (currentLevelNo
)
3017 outputFile
= Chapters
;
3022 outputFile
= Sections
;
3027 outputFile
= Subsections
;
3032 outputFile
= Subsubsections
;
3042 CurrentOutput1
= outputFile
;
3058 CurrentOutput1
= oldLevelFile
;
3064 return DefaultOnArgument(macroId
, arg_no
, start
);
3076 tableVerticalLineLeft
= false;
3077 tableVerticalLineRight
= false;
3080 if (!InputFile
.empty() && !OutputFile
.empty())
3082 // Do some HTML-specific transformations on all the strings,
3084 Text2HTML(GetTopLevelChunk());
3087 if (truncateFilenames
)
3088 wxSnprintf(buf
, sizeof(buf
), _T("%s.htm"), FileRoot
);
3090 wxSnprintf(buf
, sizeof(buf
), _T("%s_contents.html"), FileRoot
);
3091 if (TitlepageName
) delete[] TitlepageName
;
3092 TitlepageName
= copystring(buf
);
3093 Titlepage
= wxFopen(buf
, _T("w"));
3095 if (truncateFilenames
)
3096 wxSnprintf(buf
, sizeof(buf
), _T("%s_fc.htm"), FileRoot
);
3098 wxSnprintf(buf
, sizeof(buf
), _T("%s_fcontents.html"), FileRoot
);
3100 contentsFrameName
= copystring(buf
);
3102 Contents
= wxFopen(TmpContentsName
, _T("w"));
3104 if (htmlFrameContents
)
3106 // FrameContents = wxFopen(TmpFrameContentsName, _T("w"));
3107 FrameContents
= wxFopen(contentsFrameName
, _T("w"));
3108 wxFprintf(FrameContents
, _T("<HTML>\n<UL>\n"));
3111 if (!Titlepage
|| !Contents
)
3113 OnError(_T("Cannot open output file!"));
3116 AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName
), ContentsNameString
);
3118 wxFprintf(Contents
, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString
);
3120 wxFprintf(Contents
, _T("<UL>\n"));
3122 SetCurrentOutput(Titlepage
);
3123 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
3124 OnInform(_T("Converting..."));
3127 wxFprintf(Contents
, _T("</UL>\n\n"));
3129 // SetCurrentOutput(Titlepage);
3134 // wxFprintf(Titlepage, _T("\n</BODY></HTML>\n"));
3141 wxFprintf(FrameContents
, _T("\n</UL>\n"));
3142 wxFprintf(FrameContents
, _T("</HTML>\n"));
3143 fclose(FrameContents
);
3144 FrameContents
= NULL
;
3149 wxFprintf(Chapters
, _T("\n</FONT></BODY></HTML>\n"));
3155 wxFprintf(Sections
, _T("\n</FONT></BODY></HTML>\n"));
3159 if (Subsections
&& !combineSubSections
)
3161 wxFprintf(Subsections
, _T("\n</FONT></BODY></HTML>\n"));
3162 fclose(Subsections
);
3165 if (Subsubsections
&& !combineSubSections
)
3167 wxFprintf(Subsubsections
, _T("\n</FONT></BODY></HTML>\n"));
3168 fclose(Subsubsections
);
3169 Subsubsections
= NULL
;
3171 if ( SectionContentsFD
)
3173 fclose(SectionContentsFD
);
3174 SectionContentsFD
= NULL
;
3177 // Create a temporary file for the title page header, add some info,
3178 // and concat the titlepage just generated.
3179 // This is necessary in order to put the title of the document
3180 // at the TOP of the file within <HEAD>, even though we only find out
3181 // what it is later on.
3182 FILE *tmpTitle
= wxFopen(_T("title.tmp"), _T("w"));
3187 SetCurrentOutput(tmpTitle
);
3189 TexOutput(_T("\n<TITLE>"));
3190 TraverseChildrenFromChunk(DocumentTitle
);
3191 TexOutput(_T("</TITLE></HEAD>\n"));
3195 SetCurrentOutput(tmpTitle
);
3196 HTMLHeadTo(tmpTitle
);
3198 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), contentsString
);
3200 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), wxFileNameFromPath(FileRoot
));
3203 // Output frame information
3204 if (htmlFrameContents
)
3206 wxChar firstFileName
[300];
3207 if (truncateFilenames
)
3208 wxSnprintf(firstFileName
, sizeof(firstFileName
), _T("%s1.htm"), FileRoot
);
3210 wxStrcpy(firstFileName
, gs_filenames
[1].c_str());
3212 wxFprintf(tmpTitle
, _T("<FRAMESET COLS=\"30%%,70%%\">\n"));
3214 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName
)));
3215 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName
)));
3216 wxFprintf(tmpTitle
, _T("</FRAMESET>\n"));
3218 wxFprintf(tmpTitle
, _T("<NOFRAMES>\n"));
3221 // Output <BODY...> to temporary title page
3226 FILE *fd
= wxFopen(TitlepageName
, _T("r"));
3232 wxPutc(ch
, tmpTitle
);
3238 wxFprintf(tmpTitle
, _T("\n</FONT></BODY>\n"));
3240 if (htmlFrameContents
)
3242 wxFprintf(tmpTitle
, _T("\n</NOFRAMES>\n"));
3244 wxFprintf(tmpTitle
, _T("\n</HTML>\n"));
3247 if (wxFileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3248 if (!wxRenameFile(_T("title.tmp"), TitlepageName
))
3250 wxCopyFile(_T("title.tmp"), TitlepageName
);
3251 wxRemoveFile(_T("title.tmp"));
3255 if (lastFileName
) delete[] lastFileName
;
3256 lastFileName
= NULL
;
3257 if (lastTopic
) delete[] lastTopic
;
3260 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3262 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3264 wxCopyFile(TmpContentsName
, ContentsName
);
3265 wxRemoveFile(TmpContentsName
);
3268 // Generate .htx file if requested
3271 wxChar htmlIndexName
[300];
3272 wxSnprintf(htmlIndexName
, sizeof(htmlIndexName
), _T("%s.htx"), FileRoot
);
3273 GenerateHTMLIndexFile(htmlIndexName
);
3276 // Generate HTML Help Workshop files if requested
3277 if (htmlWorkshopFiles
)
3279 HTMLWorkshopEndContents();
3280 GenerateHTMLWorkshopFiles(FileRoot
);
3289 // Output .htx index file
3290 void GenerateHTMLIndexFile(wxChar
*fname
)
3292 FILE *fd
= wxFopen(fname
, _T("w"));
3296 TopicTable
.BeginFind();
3297 wxHashTable::Node
*node
= TopicTable
.Next();
3300 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3301 const wxChar
*topicName
= node
->GetKeyString();
3302 if (texTopic
->filename
&& texTopic
->keywords
)
3304 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3307 wxChar
*s
= (wxChar
*)node1
->GetData();
3308 wxFprintf(fd
, _T("%s|%s|%s\n"), topicName
, texTopic
->filename
, s
);
3309 node1
= node1
->GetNext();
3312 node
= TopicTable
.Next();
3323 // output .hpp, .hhc and .hhk files:
3326 void GenerateHTMLWorkshopFiles(wxChar
*fname
)
3331 /* Generate project file : */
3333 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhp"), fname
);
3334 f
= wxFopen(buf
, _T("wt"));
3337 _T("Compatibility=1.1\n")
3338 _T("Full-text search=Yes\n")
3339 _T("Contents file=%s.hhc\n")
3340 _T("Compiled file=%s.chm\n")
3341 _T("Default Window=%sHelp\n")
3342 _T("Default topic=%s\n")
3343 _T("Index file=%s.hhk\n")
3345 wxFileNameFromPath(fname
),
3346 wxFileNameFromPath(fname
),
3347 wxFileNameFromPath(fname
),
3348 wxFileNameFromPath(TitlepageName
),
3349 wxFileNameFromPath(fname
)
3352 if (DocumentTitle
) {
3353 SetCurrentOutput(f
);
3354 TraverseChildrenFromChunk(DocumentTitle
);
3356 else wxFprintf(f
, _T("(unknown)"));
3358 wxFprintf(f
, _T("\n\n[WINDOWS]\n")
3359 _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"),
3360 wxFileNameFromPath(fname
),
3361 wxFileNameFromPath(fname
),
3362 wxFileNameFromPath(fname
),
3363 wxFileNameFromPath(TitlepageName
));
3366 wxFprintf(f
, _T("\n\n[FILES]\n"));
3367 wxFprintf(f
, _T("%s\n"), wxFileNameFromPath(TitlepageName
));
3368 for (int i
= 1; i
<= fileId
; i
++) {
3369 if (truncateFilenames
)
3370 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), wxFileNameFromPath(FileRoot
), i
);
3372 wxStrcpy(buf
, wxFileNameFromPath(gs_filenames
[i
].c_str()));
3373 wxFprintf(f
, _T("%s\n"), buf
);
3377 /* Generate index file : */
3379 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhk"), fname
);
3380 f
= wxFopen(buf
, _T("wt"));
3383 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3388 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3389 _T("<!-- Sitemap 1.0 -->\n")
3390 _T("</HEAD><BODY>\n")
3391 _T("<OBJECT type=\"text/site properties\">\n")
3392 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3396 TopicTable
.BeginFind();
3397 wxHashTable::Node
*node
= TopicTable
.Next();
3400 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3401 const wxChar
*topicName
= node
->GetKeyString();
3402 if (texTopic
->filename
&& texTopic
->keywords
)
3404 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3407 wxChar
*s
= (wxChar
*)node1
->GetData();
3409 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3410 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3411 _T(" <param name=\"Name\" value=\"%s\">\n")
3413 texTopic
->filename
, topicName
, s
);
3414 node1
= node1
->GetNext();
3417 node
= TopicTable
.Next();
3420 wxFprintf(f
, _T("</UL>\n"));
3426 static FILE *HTMLWorkshopContents
= NULL
;
3427 static int HTMLWorkshopLastLevel
= 0;
3429 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
)
3433 if (level
> HTMLWorkshopLastLevel
)
3434 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3435 wxFprintf(HTMLWorkshopContents
, _T("<UL>"));
3436 if (level
< HTMLWorkshopLastLevel
)
3437 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3438 wxFprintf(HTMLWorkshopContents
, _T("</UL>"));
3440 SetCurrentOutput(HTMLWorkshopContents
);
3441 wxFprintf(HTMLWorkshopContents
,
3442 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3443 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3444 _T(" <param name=\"Name\" value=\""),
3446 OutputCurrentSection();
3447 wxFprintf(HTMLWorkshopContents
,
3449 _T(" </OBJECT>\n"));
3450 HTMLWorkshopLastLevel
= level
;
3454 void HTMLWorkshopStartContents()
3457 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhc"), FileRoot
);
3458 HTMLWorkshopContents
= wxFopen(buf
, _T("wt"));
3459 HTMLWorkshopLastLevel
= 0;
3461 wxFprintf(HTMLWorkshopContents
,
3462 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3464 HTMLHeadTo(HTMLWorkshopContents
);
3465 wxFprintf(HTMLWorkshopContents
,
3467 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3468 _T("<!-- Sitemap 1.0 -->\n")
3469 _T("</HEAD><BODY>\n")
3470 _T("<OBJECT type=\"text/site properties\">\n")
3471 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3474 _T("<LI> <OBJECT type=\"text/sitemap\">\n")
3475 _T("<param name=\"Local\" value=\"%s\">\n")
3476 _T("<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n"),
3477 wxFileNameFromPath(TitlepageName
)
3483 void HTMLWorkshopEndContents()
3485 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3486 wxFprintf(HTMLWorkshopContents
, _T("</UL>\n"));
3487 fclose(HTMLWorkshopContents
);
3491 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
)
3493 wxString file_label
;
3494 file_label
.Printf( HTML_FILENAME_PATTERN
, FileRoot
, label
);
3495 return file_label
.IsSameAs( file
, false );