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 static inline wxChar
* copystring(const wxChar
* s
)
32 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
34 extern wxHashTable TexReferences
;
36 extern int passNumber
;
38 extern void DecToHex(int, wxChar
*);
39 void GenerateHTMLIndexFile(wxChar
*fname
);
41 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
);
43 void GenerateHTMLWorkshopFiles(wxChar
*fname
);
44 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
);
45 void HTMLWorkshopStartContents();
46 void HTMLWorkshopEndContents();
48 void OutputContentsFrame(void);
50 #include "readshg.h" // Segmented hypergraphics parsing
52 wxChar
*ChaptersName
= NULL
;
53 wxChar
*SectionsName
= NULL
;
54 wxChar
*SubsectionsName
= NULL
;
55 wxChar
*SubsubsectionsName
= NULL
;
56 wxChar
*TitlepageName
= NULL
;
57 wxChar
*lastFileName
= NULL
;
58 wxChar
*lastTopic
= NULL
;
59 wxChar
*currentFileName
= NULL
;
60 wxChar
*contentsFrameName
= NULL
;
62 static TexChunk
*descriptionItemArg
= NULL
;
63 static TexChunk
*helpRefFilename
= NULL
;
64 static TexChunk
*helpRefText
= NULL
;
65 static int indentLevel
= 0;
66 static int citeCount
= 1;
67 extern FILE *Contents
;
68 FILE *FrameContents
= NULL
;
69 FILE *Titlepage
= NULL
;
70 // FILE *FrameTitlepage = NULL;
72 bool subsectionStarted
= false;
74 // Which column of a row are we in? (Assumes no nested tables, of course)
75 int currentColumn
= 0;
77 // Are we in verbatim mode? If so, format differently.
78 static bool inVerbatim
= false;
80 // Need to know whether we're in a table or figure for benefit
81 // of listoffigures/listoftables
82 static bool inFigure
= false;
83 static bool inTable
= false;
85 // This is defined in the Tex2Any library.
86 extern wxChar
*BigBuffer
;
88 // DHS Two-column table dimensions.
89 static int TwoColWidthA
= -1;
90 static int TwoColWidthB
= -1;
93 class HyperReference
: public wxObject
98 HyperReference(wxChar
*name
, wxChar
*file
)
100 if (name
) refName
= copystring(name
);
101 if (file
) refFile
= copystring(file
);
105 class TexNextPage
: public wxObject
110 TexNextPage(wxChar
*theLabel
, wxChar
*theFile
)
112 label
= copystring(theLabel
);
113 filename
= copystring(theFile
);
115 virtual ~TexNextPage(void)
122 wxHashTable
TexNextPages(wxKEY_STRING
);
124 static wxChar
*CurrentChapterName
= NULL
;
125 static wxChar
*CurrentChapterFile
= NULL
;
126 static wxChar
*CurrentSectionName
= NULL
;
127 static wxChar
*CurrentSectionFile
= NULL
;
128 static wxChar
*CurrentSubsectionName
= NULL
;
129 static wxChar
*CurrentSubsectionFile
= NULL
;
130 static wxChar
*CurrentSubsubsectionName
= NULL
;
131 static wxChar
*CurrentSubsubsectionFile
= NULL
;
132 static wxChar
*CurrentTopic
= NULL
;
134 static void SetCurrentTopic(wxChar
*s
)
136 if (CurrentTopic
) delete[] CurrentTopic
;
137 CurrentTopic
= copystring(s
);
140 void SetCurrentChapterName(wxChar
*s
, wxChar
*file
)
142 if (CurrentChapterName
) delete[] CurrentChapterName
;
143 CurrentChapterName
= copystring(s
);
144 if (CurrentChapterFile
) delete[] CurrentChapterFile
;
145 CurrentChapterFile
= copystring(file
);
147 currentFileName
= CurrentChapterFile
;
151 void SetCurrentSectionName(wxChar
*s
, wxChar
*file
)
153 if (CurrentSectionName
) delete[] CurrentSectionName
;
154 CurrentSectionName
= copystring(s
);
155 if (CurrentSectionFile
) delete[] CurrentSectionFile
;
156 CurrentSectionFile
= copystring(file
);
158 currentFileName
= CurrentSectionFile
;
161 void SetCurrentSubsectionName(wxChar
*s
, wxChar
*file
)
163 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
164 CurrentSubsectionName
= copystring(s
);
165 if (CurrentSubsectionFile
) delete[] CurrentSubsectionFile
;
166 CurrentSubsectionFile
= copystring(file
);
167 currentFileName
= CurrentSubsectionFile
;
170 void SetCurrentSubsubsectionName(wxChar
*s
, wxChar
*file
)
172 if (CurrentSubsubsectionName
) delete[] CurrentSubsubsectionName
;
173 CurrentSubsubsectionName
= copystring(s
);
174 if (CurrentSubsubsectionFile
) delete[] CurrentSubsubsectionFile
;
175 CurrentSubsubsectionFile
= copystring(file
);
176 currentFileName
= CurrentSubsubsectionFile
;
181 // mapping between fileId and filenames if truncateFilenames=false:
182 static wxArrayString gs_filenames
;
186 * Close former filedescriptor and reopen using another filename.
190 void ReopenFile(FILE **fd
, wxChar
**fileName
, const wxChar
*label
)
194 wxFprintf(*fd
, _T("\n</FONT></BODY></HTML>\n"));
199 if (truncateFilenames
)
201 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), FileRoot
, fileId
);
206 gs_filenames
.Add(wxEmptyString
);
207 wxSnprintf(buf
, sizeof(buf
), HTML_FILENAME_PATTERN
, FileRoot
, label
);
208 gs_filenames
.Add(buf
);
210 if (*fileName
) delete[] *fileName
;
211 *fileName
= copystring(wxFileNameFromPath(buf
));
212 *fd
= wxFopen(buf
, _T("w"));
213 wxFprintf(*fd
, _T("<HTML>\n"));
217 * Reopen section contents file, i.e. the index appended to each section
218 * in subsectionCombine mode
221 static wxChar
*SectionContentsFilename
= NULL
;
222 static FILE *SectionContentsFD
= NULL
;
224 void ReopenSectionContentsFile(void)
226 if ( SectionContentsFD
)
228 fclose(SectionContentsFD
);
230 if ( SectionContentsFilename
)
231 delete[] SectionContentsFilename
;
232 SectionContentsFD
= NULL
;
233 SectionContentsFilename
= NULL
;
235 // Create the name from the current section filename
236 if ( CurrentSectionFile
)
239 wxStrcpy(buf
, CurrentSectionFile
);
240 wxStripExtension(buf
);
241 wxStrcat(buf
, _T(".con"));
242 SectionContentsFilename
= copystring(buf
);
244 SectionContentsFD
= wxFopen(SectionContentsFilename
, _T("w"));
256 size_t replace_length
;
259 #define tr(x,y) {x, sizeof(x)-1, y, sizeof(y)-1}
261 static textreplace notverb_array
[] =
263 tr(_T("``"), _T("“")),
264 tr(_T("''"), _T("”")),
265 tr(_T("`"), _T("‘")),
266 tr(_T("'"), _T("’")),
267 tr(_T("---"), _T("—")),
268 tr(_T("--"), _T("–")),
274 * Given a TexChunk with a string value, scans through the string
275 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
279 void ProcessText2HTML(TexChunk
*chunk
)
281 bool changed
= false;
285 size_t len
= wxStrlen(chunk
->value
);
288 ch
= chunk
->value
[i
];
290 if (ch
== _T('<')) // Change < to <
293 wxStrcat(BigBuffer
, _T("<"));
299 else if (ch
== _T('>')) // Change > to >
302 wxStrcat(BigBuffer
, _T(">"));
310 bool replaced
= false;
313 for (size_t x
= 0; x
< WXSIZEOF(notverb_array
); x
++)
315 textreplace
& tr
= notverb_array
[x
];
316 if (ch
!= tr
.text
[0])
318 if (len
< tr
.text_length
)
322 for (y
= 1; y
< tr
.text_length
; y
++)
324 if (chunk
->value
[y
] != tr
.text
[y
])
328 if (y
!= tr
.text_length
)
331 // can now copy it over.
332 for (y
= 0; y
< tr
.replace_length
; y
++)
334 BigBuffer
[ptr
++] = tr
.replace
[y
];
337 len
-= tr
.text_length
;
359 chunk
->value
= copystring(BigBuffer
);
364 * Scan through all chunks starting from the given one,
365 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
366 * This should be called after Tex2Any has parsed the file,
367 * and before TraverseDocument is called.
371 void Text2HTML(TexChunk
*chunk
)
374 if (stopRunning
) return;
378 case CHUNK_TYPE_MACRO
:
380 TexMacroDef
*def
= chunk
->def
;
382 if (def
&& def
->ignore
)
385 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
388 wxNode
*node
= chunk
->children
.GetFirst();
391 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
392 Text2HTML(child_chunk
);
393 node
= node
->GetNext();
396 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
403 wxNode
*node
= chunk
->children
.GetFirst();
406 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
407 Text2HTML(child_chunk
);
408 node
= node
->GetNext();
413 case CHUNK_TYPE_STRING
:
416 ProcessText2HTML(chunk
);
423 * Add appropriate browse buttons to this page.
427 void AddBrowseButtons(wxChar
*upLabel
, wxChar
*upFilename
,
428 wxChar
*previousLabel
, wxChar
*previousFilename
,
429 wxChar
*thisLabel
, wxChar
*thisFilename
)
431 wxChar contentsReferenceBuf
[80];
432 wxChar upReferenceBuf
[80];
433 wxChar backReferenceBuf
[80];
434 wxChar forwardReferenceBuf
[80];
435 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
438 wxChar
*contentsReference
; // no need to initialize because always assigned below
439 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
440 contentsReference
= ContentsNameString
;
443 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
444 contentsReference
= contentsReferenceBuf
;
445 wxSnprintf(contentsReference
, sizeof(contentsReferenceBuf
),
446 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">"),
447 ConvertCase(_T("contents.gif")));
450 wxChar
*upReference
; // no need to initialize because always assigned below
451 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
452 upReference
= UpNameString
;
455 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
456 upReference
= upReferenceBuf
;
457 wxSnprintf(upReference
, sizeof(upReferenceBuf
),
458 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">"),
459 ConvertCase(_T("up.gif")));
462 wxChar
*backReference
; // no need to initialize because always assigned below
463 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
464 backReference
= _T("<<");
467 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
468 backReference
= backReferenceBuf
;
469 wxSnprintf(backReference
, sizeof(backReferenceBuf
),
470 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">"),
471 ConvertCase(_T("back.gif")));
474 wxChar
*forwardReference
; // no need to initialize because always assigned below
475 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
476 forwardReference
= _T(">>");
479 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
480 forwardReference
= forwardReferenceBuf
;
481 wxSnprintf(forwardReference
, sizeof(forwardReferenceBuf
),
482 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">"),
483 ConvertCase(_T("forward.gif")));
486 TexOutput(_T("<CENTER>"));
495 if (truncateFilenames
)
498 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
499 wxSnprintf(buf
, sizeof(buf
),
500 _T("\n<A HREF=\"%s.%s\">%s</A> "),
501 buf1
, ConvertCase(_T("htm")), contentsReference
);
506 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
507 wxSnprintf(buf
, sizeof(buf
),
508 _T("\n<A HREF=\"%s%s\">%s</A> "),
509 buf1
, ConvertCase(_T("_contents.html")), contentsReference
);
511 // TexOutput(_T("<NOFRAMES>"));
513 // TexOutput(_T("</NOFRAMES>"));
520 if (upLabel
&& upFilename
)
522 if ( (wxStrlen(upLabel
) > 0) && !PrimaryAnchorOfTheFile(upFilename
, upLabel
) )
523 wxSnprintf(buf
, sizeof(buf
),
524 _T("<A HREF=\"%s#%s\">%s</A> "),
525 ConvertCase(upFilename
), upLabel
, upReference
);
527 wxSnprintf(buf
, sizeof(buf
),
528 _T("<A HREF=\"%s\">%s</A> "),
529 ConvertCase(upFilename
), upReference
);
530 if (wxStrcmp(upLabel
, _T("contents")) == 0)
532 // TexOutput(_T("<NOFRAMES>"));
534 // TexOutput(_T("</NOFRAMES>"));
545 if (previousLabel
&& previousFilename
)
547 if (PrimaryAnchorOfTheFile(previousFilename
, previousLabel
))
548 wxSnprintf(buf
, sizeof(buf
),
549 _T("<A HREF=\"%s\">%s</A> "),
550 ConvertCase(previousFilename
), backReference
);
552 wxSnprintf(buf
, sizeof(buf
),
553 _T("<A HREF=\"%s#%s\">%s</A> "),
554 ConvertCase(previousFilename
), previousLabel
, backReference
);
555 if (wxStrcmp(previousLabel
, _T("contents")) == 0)
557 // TexOutput(_T("<NOFRAMES>"));
559 // TexOutput(_T("</NOFRAMES>"));
566 // A placeholder so the buttons don't keep moving position
567 wxSnprintf(buf
, sizeof(buf
), _T("%s "), backReference
);
571 wxChar
*nextLabel
= NULL
;
572 wxChar
*nextFilename
= NULL
;
574 // Get the next page, and record the previous page's 'next' page
576 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
579 nextLabel
= nextPage
->label
;
580 nextFilename
= nextPage
->filename
;
582 if (previousLabel
&& previousFilename
)
584 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
588 TexNextPages
.Delete(previousLabel
);
590 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
591 TexNextPages
.Put(previousLabel
, newNextPage
);
599 if (nextLabel
&& nextFilename
)
601 if (PrimaryAnchorOfTheFile(nextFilename
, nextLabel
))
602 wxSnprintf(buf
, sizeof(buf
),
603 _T("<A HREF=\"%s\">%s</A> "),
604 ConvertCase(nextFilename
), forwardReference
);
606 wxSnprintf(buf
, sizeof(buf
),
607 _T("<A HREF=\"%s#%s\">%s</A> "),
608 ConvertCase(nextFilename
), nextLabel
, forwardReference
);
613 // A placeholder so the buttons don't keep moving position
614 wxSnprintf(buf
, sizeof(buf
), _T("%s "), forwardReference
);
619 * Horizontal rule to finish it off nicely.
622 TexOutput(_T("</CENTER>"));
623 TexOutput(_T("<HR>\n"));
625 // Update last topic/filename
627 delete[] lastFileName
;
628 lastFileName
= copystring(thisFilename
);
631 lastTopic
= copystring(thisLabel
);
634 // A colour string is either 3 numbers separated by semicolons (RGB),
635 // or a reference to a GIF. Return the filename or a hex string like #934CE8
636 wxChar
*ParseColourString(wxChar
*bkStr
, bool *isPicture
)
638 static wxChar resStr
[300];
639 wxStrcpy(resStr
, bkStr
);
640 wxStringTokenizer
tok(resStr
, _T(";"), wxTOKEN_STRTOK
);
641 if (tok
.HasMoreTokens())
643 wxString token1
= tok
.GetNextToken();
644 if (!tok
.HasMoreTokens())
651 wxString token2
= tok
.GetNextToken();
653 if (tok
.HasMoreTokens())
655 wxString token3
= tok
.GetNextToken();
657 // Now convert 3 strings into decimal numbers, and then hex numbers.
658 int red
= wxAtoi(token1
.c_str());
659 int green
= wxAtoi(token2
.c_str());
660 int blue
= wxAtoi(token3
.c_str());
662 wxStrcpy(resStr
, _T("#"));
666 wxStrcat(resStr
, buf
);
667 DecToHex(green
, buf
);
668 wxStrcat(resStr
, buf
);
670 wxStrcat(resStr
, buf
);
679 void OutputFont(void)
681 // Only output <font face> if explicitly requested by htmlFaceName= directive in
682 // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's
686 // Output <FONT FACE=...>
687 TexOutput(_T("<FONT FACE=\""));
688 TexOutput(htmlFaceName
);
689 TexOutput(_T("\">\n"));
693 // Output start of <BODY> block
694 void OutputBodyStart(void)
696 TexOutput(_T("\n<BODY"));
697 if (backgroundImageString
)
699 bool isPicture
= false;
700 wxChar
*s
= ParseColourString(backgroundImageString
, &isPicture
);
703 TexOutput(_T(" BACKGROUND=\""));
708 if (backgroundColourString
)
710 bool isPicture
= false;
711 wxChar
*s
= ParseColourString(backgroundColourString
, &isPicture
);
714 TexOutput(_T(" BGCOLOR="));
719 // Set foreground text colour, if one is specified
720 if (textColourString
)
722 bool isPicture
= false;
723 wxChar
*s
= ParseColourString(textColourString
, &isPicture
);
726 TexOutput(_T(" TEXT=")); TexOutput(s
);
729 // Set link text colour, if one is specified
730 if (linkColourString
)
732 bool isPicture
= false;
733 wxChar
*s
= ParseColourString(linkColourString
, &isPicture
);
736 TexOutput(_T(" LINK=")); TexOutput(s
);
739 // Set followed link text colour, if one is specified
740 if (followedLinkColourString
)
742 bool isPicture
= false;
743 wxChar
*s
= ParseColourString(followedLinkColourString
, &isPicture
);
746 TexOutput(_T(" VLINK=")); TexOutput(s
);
749 TexOutput(_T(">\n"));
756 TexOutput(_T("<head>"));
757 if (htmlStylesheet
) {
758 TexOutput(_T("<link rel=stylesheet type=\"text/css\" href=\""));
759 TexOutput(htmlStylesheet
);
760 TexOutput(_T("\">"));
764 void HTMLHeadTo(FILE* f
)
767 wxFprintf(f
,_T("<head><link rel=stylesheet type=\"text/css\" href=\"%s\">"),htmlStylesheet
);
769 wxFprintf(f
,_T("<head>"));
772 // Called on start/end of macro examination
773 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
779 case ltCHAPTERHEADING
:
787 if (macroId
!= ltCHAPTERSTAR
)
790 SetCurrentOutput(NULL
);
791 startedSections
= true;
793 wxChar
*topicName
= FindTopicName(GetNextChunk());
794 ReopenFile(&Chapters
, &ChaptersName
, topicName
);
795 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
797 SetCurrentChapterName(topicName
, ChaptersName
);
798 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
800 SetCurrentOutput(Chapters
);
803 TexOutput(_T("<title>"));
804 OutputCurrentSection(); // Repeat section header
805 TexOutput(_T("</title></head>\n"));
808 wxChar titleBuf
[200];
809 if (truncateFilenames
)
810 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
812 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
814 wxFprintf(Chapters
, _T("<A NAME=\"%s\"></A>"), topicName
);
816 AddBrowseButtons(_T(""), titleBuf
, // Up
817 lastTopic
, lastFileName
, // Last topic
818 topicName
, ChaptersName
); // This topic
820 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
821 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
823 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), topicName
);
825 if (htmlFrameContents
&& FrameContents
)
827 SetCurrentOutput(FrameContents
);
828 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
829 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
));
831 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
), topicName
);
832 OutputCurrentSection();
833 wxFprintf(FrameContents
, _T("</A>\n"));
836 SetCurrentOutputs(Contents
, Chapters
);
837 wxFprintf(Chapters
, _T("\n<H2>"));
838 OutputCurrentSection();
839 wxFprintf(Contents
, _T("</A>\n"));
840 wxFprintf(Chapters
, _T("</H2>\n"));
842 SetCurrentOutput(Chapters
);
844 // Add this section title to the list of keywords
847 OutputCurrentSectionToString(wxTex2RTFBuffer
);
848 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, ConvertCase(currentFileName
));
855 case ltSECTIONHEADING
:
862 subsectionStarted
= false;
864 if (macroId
!= ltSECTIONSTAR
)
867 SetCurrentOutput(NULL
);
868 startedSections
= true;
870 wxChar
*topicName
= FindTopicName(GetNextChunk());
871 ReopenFile(&Sections
, &SectionsName
, topicName
);
872 AddTexRef(topicName
, SectionsName
, SectionNameString
);
874 SetCurrentSectionName(topicName
, SectionsName
);
875 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
877 SetCurrentOutput(Sections
);
879 TexOutput(_T("<title>"));
880 OutputCurrentSection();
881 TexOutput(_T("</title></head>\n"));
884 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
885 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
886 lastTopic
, lastFileName
, // Last topic
887 topicName
, SectionsName
); // This topic
889 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
891 SetCurrentOutputs(jumpFrom
, Sections
);
892 if (DocumentStyle
== LATEX_ARTICLE
)
894 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
895 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(SectionsName
));
897 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(SectionsName
), topicName
);
901 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
902 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SectionsName
));
904 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SectionsName
), topicName
);
907 wxFprintf(Sections
, _T("\n<H2>"));
908 OutputCurrentSection();
910 if (DocumentStyle
== LATEX_ARTICLE
)
911 wxFprintf(jumpFrom
, _T("</A>\n"));
913 wxFprintf(jumpFrom
, _T("</B></A><BR>\n"));
914 wxFprintf(Sections
, _T("</H2>\n"));
916 SetCurrentOutput(Sections
);
917 // Add this section title to the list of keywords
920 OutputCurrentSectionToString(wxTex2RTFBuffer
);
921 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
927 case ltSUBSECTIONSTAR
:
928 case ltMEMBERSECTION
:
929 case ltFUNCTIONSECTION
:
935 OnError(_T("You cannot have a subsection before a section!"));
941 if (macroId
!= ltSUBSECTIONSTAR
)
944 if ( combineSubSections
&& !subsectionStarted
)
948 // Read old .con file in at this point
950 wxStrcpy(buf
, CurrentSectionFile
);
951 wxStripExtension(buf
);
952 wxStrcat(buf
, _T(".con"));
953 FILE *fd
= wxFopen(buf
, _T("r"));
959 wxPutc(ch
, Sections
);
964 wxFprintf(Sections
, _T("<P>\n"));
966 // Close old file, create a new file for the sub(sub)section contents entries
967 ReopenSectionContentsFile();
970 startedSections
= true;
971 subsectionStarted
= true;
973 wxChar
*topicName
= FindTopicName(GetNextChunk());
975 if ( !combineSubSections
)
977 SetCurrentOutput(NULL
);
978 ReopenFile(&Subsections
, &SubsectionsName
, topicName
);
979 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
980 SetCurrentSubsectionName(topicName
, SubsectionsName
);
981 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
982 SetCurrentOutput(Subsections
);
985 TexOutput(_T("<title>"));
986 OutputCurrentSection();
987 TexOutput(_T("</title></head>\n"));
990 wxFprintf(Subsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
991 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
992 lastTopic
, lastFileName
, // Last topic
993 topicName
, SubsectionsName
); // This topic
995 SetCurrentOutputs(Sections
, Subsections
);
996 if(PrimaryAnchorOfTheFile(SubsectionsName
, topicName
))
997 wxFprintf(Sections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsectionsName
));
999 wxFprintf(Sections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName
), topicName
);
1001 wxFprintf(Subsections
, _T("\n<H3>"));
1002 OutputCurrentSection();
1003 wxFprintf(Sections
, _T("</B></A><BR>\n"));
1004 wxFprintf(Subsections
, _T("</H3>\n"));
1006 SetCurrentOutput(Subsections
);
1010 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
1011 SetCurrentSubsectionName(topicName
, SectionsName
);
1013 // if ( subsectionNo != 0 )
1014 wxFprintf(Sections
, _T("\n<HR>\n"));
1016 // We're putting everything into the section file
1017 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1018 wxFprintf(Sections
, _T("\n<H3>"));
1019 OutputCurrentSection();
1020 wxFprintf(Sections
, _T("</H3>\n"));
1022 SetCurrentOutput(SectionContentsFD
);
1023 wxFprintf(SectionContentsFD
, _T("<A HREF=\"#%s\">"), topicName
);
1024 OutputCurrentSection();
1025 TexOutput(_T("</A><BR>\n"));
1027 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
1028 SetCurrentOutput(Sections
);
1030 // Add this section title to the list of keywords
1033 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1034 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1041 case ltSUBSUBSECTION
:
1042 case ltSUBSUBSECTIONSTAR
:
1046 if (!Subsections
&& !combineSubSections
)
1048 OnError(_T("You cannot have a subsubsection before a subsection!"));
1052 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1055 startedSections
= true;
1057 wxChar
*topicName
= FindTopicName(GetNextChunk());
1059 if ( !combineSubSections
)
1061 SetCurrentOutput(NULL
);
1062 ReopenFile(&Subsubsections
, &SubsubsectionsName
, topicName
);
1063 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
1064 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
1065 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
1067 SetCurrentOutput(Subsubsections
);
1069 TexOutput(_T("<title>"));
1070 OutputCurrentSection();
1071 TexOutput(_T("</title></head>\n"));
1074 wxFprintf(Subsubsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1076 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
1077 lastTopic
, lastFileName
, // Last topic
1078 topicName
, SubsubsectionsName
); // This topic
1080 SetCurrentOutputs(Subsections
, Subsubsections
);
1081 if(PrimaryAnchorOfTheFile(SubsubsectionsName
, topicName
))
1082 wxFprintf(Subsections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsubsectionsName
));
1084 wxFprintf(Subsections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName
), topicName
);
1086 wxFprintf(Subsubsections
, _T("\n<H3>"));
1087 OutputCurrentSection();
1088 wxFprintf(Subsections
, _T("</B></A><BR>\n"));
1089 wxFprintf(Subsubsections
, _T("</H3>\n"));
1093 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
1094 SetCurrentSubsectionName(topicName
, SectionsName
);
1095 wxFprintf(Sections
, _T("\n<HR>\n"));
1097 // We're putting everything into the section file
1098 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1099 wxFprintf(Sections
, _T("\n<H3>"));
1100 OutputCurrentSection();
1101 wxFprintf(Sections
, _T("</H3>\n"));
1102 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
1103 SetCurrentOutput(SectionContentsFD);
1104 wxFprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
1105 OutputCurrentSection();
1106 TexOutput(_T("</A><BR>"));
1108 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
1109 SetCurrentOutput(Sections
);
1112 // Add this section title to the list of keywords
1115 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1116 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1125 if ( !combineSubSections
)
1126 SetCurrentOutput(Subsections
);
1128 SetCurrentOutput(Sections
);
1139 if ( !combineSubSections
)
1140 SetCurrentOutput(Subsections
);
1142 SetCurrentOutput(Sections
);
1153 if ( !combineSubSections
)
1154 SetCurrentOutput(Subsections
);
1156 SetCurrentOutput(Sections
);
1167 // TexOutput(_T("<B>void</B>"));
1171 TexOutput(_T("HARDY"));
1175 TexOutput(_T("wxCLIPS"));
1179 TexOutput(_T("&"));
1181 case ltSPECIALAMPERSAND
:
1187 // End cell, start cell
1189 TexOutput(_T("</FONT></TD>"));
1191 // Start new row and cell, setting alignment for the first cell.
1192 if (currentColumn
< noColumns
)
1196 if (TableData
[currentColumn
].justification
== 'c')
1197 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=CENTER>"));
1198 else if (TableData
[currentColumn
].justification
== 'r')
1199 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=RIGHT>"));
1200 else if (TableData
[currentColumn
].absWidth
)
1202 // Convert from points * 20 into pixels.
1203 int points
= TableData
[currentColumn
].width
/ 20;
1205 // Say the display is 100 DPI (dots/pixels per inch).
1206 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1207 int pixels
= (int)(points
* 100.0 / 72.0);
1208 wxSnprintf(buf
, sizeof(buf
), _T("<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1211 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=LEFT>"));
1216 TexOutput(_T("&"));
1220 case ltBACKSLASHCHAR
:
1226 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1227 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1228 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1229 TexOutput(_T("</TR>\n"));
1232 TexOutput(_T("<BR>\n"));
1243 // Start new row and cell, setting alignment for the first cell.
1245 if (TableData
[currentColumn
].justification
== 'c')
1246 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER>"));
1247 else if (TableData
[currentColumn
].justification
== 'r')
1248 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=RIGHT>"));
1249 else if (TableData
[currentColumn
].absWidth
)
1251 // Convert from points * 20 into pixels.
1252 int points
= TableData
[currentColumn
].width
/ 20;
1254 // Say the display is 100 DPI (dots/pixels per inch).
1255 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1256 int pixels
= (int)(points
* 100.0 / 72.0);
1257 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1260 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=LEFT>"));
1267 // Start new row and cell
1268 TexOutput(_T("</FONT></TD>\n</TR>\n"));
1272 // HTML-only: break until the end of the picture (both margins are clear).
1276 TexOutput(_T("<BR CLEAR=ALL>"));
1279 case ltRTFSP
: // Explicit space, RTF only
1281 case ltSPECIALTILDE
:
1285 #if (1) // if(inVerbatim)
1296 TexOutput(_T("<UL><UL>\n"));
1298 TexOutput(_T("</UL></UL>\n"));
1304 // case ltTWOCOLLIST:
1311 if (macroId
== ltENUMERATE
)
1312 listType
= LATEX_ENUMERATE
;
1313 else if (macroId
== ltITEMIZE
)
1314 listType
= LATEX_ITEMIZE
;
1316 listType
= LATEX_DESCRIPTION
;
1318 itemizeStack
.Insert(new ItemizeStruc(listType
));
1322 TexOutput(_T("<UL>\n"));
1324 case LATEX_ENUMERATE
:
1325 TexOutput(_T("<OL>\n"));
1327 case LATEX_DESCRIPTION
:
1329 TexOutput(_T("<DL>\n"));
1336 if (itemizeStack
.GetFirst())
1338 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
1339 switch (struc
->listType
)
1342 TexOutput(_T("</UL>\n"));
1344 case LATEX_ENUMERATE
:
1345 TexOutput(_T("</OL>\n"));
1347 case LATEX_DESCRIPTION
:
1349 TexOutput(_T("</DL>\n"));
1354 delete itemizeStack
.GetFirst();
1362 TexOutput(_T("\n<TABLE>\n"));
1364 TexOutput(_T("\n</TABLE>\n"));
1374 TexOutput(_T("<P>\n"));
1377 /* For footnotes we need to output the text at the bottom of the page and
1378 * insert a reference to it. Is it worth the trouble...
1380 case ltFOOTNOTEPOPUP:
1384 TexOutput(_T("<FN>"));
1386 else TexOutput(_T("</FN>"));
1393 TexOutput(_T("<TT>"));
1394 else TexOutput(_T("</TT>"));
1402 wxSnprintf(buf
, sizeof(buf
), _T("<PRE>\n"));
1405 else TexOutput(_T("</PRE>\n"));
1413 TexOutput(_T("<CENTER>"));
1415 else TexOutput(_T("</CENTER>"));
1423 TexOutput(_T("{\\ql "));
1425 else TexOutput(_T("}\\par\\pard\n"));
1434 TexOutput(_T("{\\qr "));
1436 else TexOutput(_T("}\\par\\pard\n"));
1444 // Netscape extension
1445 TexOutput(_T("<FONT SIZE=2>"));
1447 else TexOutput(_T("</FONT>"));
1454 // Netscape extension
1455 TexOutput(_T("<FONT SIZE=1>"));
1457 else TexOutput(_T("</FONT>"));
1464 // Netscape extension
1465 TexOutput(_T("<FONT SIZE=3>"));
1467 else TexOutput(_T("</FONT>"));
1474 // Netscape extension
1475 TexOutput(_T("<FONT SIZE=4>"));
1477 else TexOutput(_T("</FONT>"));
1484 // Netscape extension
1485 TexOutput(_T("<FONT SIZE=5>"));
1487 else TexOutput(_T("</FONT>"));
1494 // Netscape extension
1495 TexOutput(_T("<FONT SIZE=6>"));
1497 else TexOutput(_T("</FONT>"));
1506 TexOutput(_T("<B>"));
1508 else TexOutput(_T("</B>"));
1517 TexOutput(_T("<I>"));
1519 else TexOutput(_T("</I>"));
1527 TexOutput(_T("<EM>"));
1529 else TexOutput(_T("</EM>"));
1536 TexOutput(_T("<UL>"));
1538 else TexOutput(_T("</UL>"));
1547 TexOutput(_T("<TT>"));
1549 else TexOutput(_T("</TT>"));
1555 TexOutput(_T("©"), true);
1561 TexOutput(_T("®"), true);
1567 if (start
) TexOutput(_T("<--"));
1572 if (start
) TexOutput(_T("<=="));
1577 if (start
) TexOutput(_T("-->"));
1582 if (start
) TexOutput(_T("==>"));
1585 case ltLEFTRIGHTARROW
:
1587 if (start
) TexOutput(_T("<-->"));
1590 case ltLEFTRIGHTARROW2
:
1592 if (start
) TexOutput(_T("<==>"));
1605 wxNode
*node
= itemizeStack
.GetFirst();
1608 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
1609 struc
->currentItem
+= 1;
1610 if (struc
->listType
== LATEX_DESCRIPTION
)
1612 if (descriptionItemArg
)
1614 TexOutput(_T("<DT> "));
1615 TraverseChildrenFromChunk(descriptionItemArg
);
1616 TexOutput(_T("\n"));
1617 descriptionItemArg
= NULL
;
1619 TexOutput(_T("<DD>"));
1622 TexOutput(_T("<LI>"));
1629 if (start
&& DocumentTitle
&& DocumentAuthor
)
1631 // Add a special label for the contents page.
1632 // TexOutput(_T("<CENTER>\n"));
1633 TexOutput(_T("<A NAME=\"contents\">"));
1634 TexOutput(_T("<H2 ALIGN=CENTER>\n"));
1635 TraverseChildrenFromChunk(DocumentTitle
);
1636 TexOutput(_T("</H2>"));
1637 TexOutput(_T("<P>"));
1638 TexOutput(_T("</A>\n"));
1639 TexOutput(_T("<P>\n\n"));
1640 TexOutput(_T("<H3 ALIGN=CENTER>"));
1641 TraverseChildrenFromChunk(DocumentAuthor
);
1642 TexOutput(_T("</H3><P>\n\n"));
1645 TexOutput(_T("<H3 ALIGN=CENTER>"));
1646 TraverseChildrenFromChunk(DocumentDate
);
1647 TexOutput(_T("</H3><P>\n\n"));
1649 // TexOutput(_T("\n</CENTER>\n"));
1650 TexOutput(_T("\n<P><HR><P>\n"));
1653 // Now do optional frame contents page
1654 if (htmlFrameContents && FrameContents)
1656 SetCurrentOutput(FrameContents);
1658 // Add a special label for the contents page.
1659 TexOutput(_T("<CENTER>\n"));
1660 TexOutput(_T("<H3>\n"));
1661 TraverseChildrenFromChunk(DocumentTitle);
1662 TexOutput(_T("</H3>"));
1663 TexOutput(_T("<P>"));
1664 TexOutput(_T("</A>\n"));
1665 TexOutput(_T("<P>\n\n"));
1666 TexOutput(_T("<H3>"));
1667 TraverseChildrenFromChunk(DocumentAuthor);
1668 TexOutput(_T("</H3><P>\n\n"));
1671 TexOutput(_T("<H4>"));
1672 TraverseChildrenFromChunk(DocumentDate);
1673 TexOutput(_T("</H4><P>\n\n"));
1675 TexOutput(_T("\n</CENTER>\n"));
1676 TexOutput(_T("<P><HR><P>\n"));
1678 SetCurrentOutput(Titlepage);
1691 helpRefFilename
= NULL
;
1696 case ltBIBLIOGRAPHY
:
1700 DefaultOnMacro(macroId
, no_args
, start
);
1704 DefaultOnMacro(macroId
, no_args
, start
);
1705 TexOutput(_T("</DL>\n"));
1713 TexOutput(_T("<HR>\n"));
1721 TexOutput(_T("<HR>\n"));
1725 case ltTABLEOFCONTENTS
:
1729 // NB: if this is uncommented, the table of contents
1730 // completely disappears. If left commented, it's in the wrong
1732 //fflush(Titlepage);
1734 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1740 wxPutc(ch
, Titlepage
);
1748 TexOutput(_T("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n"));
1749 OnInform(_T("Run Tex2RTF again to include contents page."));
1757 TexOutput(_T("<"));
1763 TexOutput(_T(">"));
1770 TexOutput(_T("<BLOCKQUOTE>"));
1772 TexOutput(_T("</BLOCKQUOTE>"));
1781 TexOutput(_T("\n<CAPTION>"));
1789 if (DocumentStyle
!= LATEX_ARTICLE
)
1790 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1792 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), FigureNameString
, figureNo
);
1798 if (DocumentStyle
!= LATEX_ARTICLE
)
1799 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1801 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), TableNameString
, tableNo
);
1809 TexOutput(_T("\n</CAPTION>\n"));
1811 wxChar
*topicName
= FindTopicName(GetNextChunk());
1813 int n
= inFigure
? figureNo
: tableNo
;
1815 AddTexRef(topicName
, NULL
, NULL
,
1816 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1817 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1823 if (start
) TexOutput(_T("ß"));
1828 if (start
) inFigure
= true;
1829 else inFigure
= false;
1834 if (start
) inTable
= true;
1835 else inTable
= false;
1839 DefaultOnMacro(macroId
, no_args
, start
);
1845 should be called at of argument which usually is
1846 type declaration which propably contains name of
1855 checks: GetArgData() if contains Type Declaration
1856 and can be referenced to some file
1858 before<a href="xxx&yyy">type</a>after
1861 false - if no reference was found
1862 true - if reference was found and HREF printed
1864 static bool CheckTypeRef()
1866 wxString typeDecl
= GetArgData();
1867 if( !typeDecl
.empty() ) {
1868 typeDecl
.Replace(wxT("\\"),wxT(""));
1869 wxString label
= typeDecl
;
1870 label
.Replace(wxT("const"),wxT(""));
1871 label
.Replace(wxT("virtual"),wxT(""));
1872 label
.Replace(wxT("static"),wxT(""));
1873 label
.Replace(wxT("extern"),wxT(""));
1874 label
= label
.BeforeFirst('&');
1875 label
= label
.BeforeFirst(wxT('*'));
1876 label
= label
.BeforeFirst(wxT('\\'));
1877 label
.Trim(true); label
.Trim(false);
1878 wxString typeName
= label
;
1880 TexRef
*texRef
= FindReference(label
);
1882 if (texRef
&& texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0) {
1883 int a
= typeDecl
.Find(typeName
);
1884 wxString before
= typeDecl
.Mid( 0, a
);
1885 wxString after
= typeDecl
.Mid( a
+typeName
.Length() );
1886 //wxFprintf(stderr,wxT("%s <%s> %s to ... %s#%s !!!!\n"),
1888 // typeName.c_str(),
1890 // texRef->refFile,label.c_str());
1892 TexOutput(_T("<A HREF=\""));
1893 TexOutput(texRef
->refFile
);
1896 TexOutput(wxT("\">"));
1897 TexOutput(typeName
);
1898 TexOutput(wxT("</A>"));
1902 //wxFprintf(stderr,wxT("'%s' from (%s) -> label %s NOT FOUND\n"),
1903 // typeName.c_str(),
1904 // typeDecl.c_str(),
1911 // Called on start/end of argument examination
1912 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1918 case ltCHAPTERHEADING
:
1921 case ltSECTIONHEADING
:
1923 case ltSUBSECTIONSTAR
:
1924 case ltSUBSUBSECTION
:
1925 case ltSUBSUBSECTIONSTAR
:
1927 case ltMEMBERSECTION
:
1928 case ltFUNCTIONSECTION
:
1930 if (!start
&& (arg_no
== 1))
1931 currentSection
= GetArgChunk();
1936 if (start
&& (arg_no
== 1)) {
1937 TexOutput(_T("<B>"));
1938 if( CheckTypeRef() ) {
1939 TexOutput(_T("</B> "));
1944 if (!start
&& (arg_no
== 1))
1945 TexOutput(_T("</B> "));
1947 if (start
&& (arg_no
== 2))
1949 if (!suppressNameDecoration
) TexOutput(_T("<B>"));
1950 currentMember
= GetArgChunk();
1952 if (!start
&& (arg_no
== 2))
1954 if (!suppressNameDecoration
) TexOutput(_T("</B>"));
1957 if (start
&& (arg_no
== 3))
1959 if (!start
&& (arg_no
== 3))
1965 if (start
&& (arg_no
== 1))
1966 TexOutput(_T("<B>"));
1967 if (!start
&& (arg_no
== 1))
1968 TexOutput(_T("</B> "));
1970 if (start
&& (arg_no
== 2))
1972 if (!suppressNameDecoration
) TexOutput(_T("( "));
1973 currentMember
= GetArgChunk();
1975 if (!start
&& (arg_no
== 2))
1979 if (!start
&& (arg_no
== 3))
1985 if (!start
&& (arg_no
== 1))
1988 if (start
&& (arg_no
== 2))
1989 TexOutput(_T("(*"));
1990 if (!start
&& (arg_no
== 2))
1993 if (start
&& (arg_no
== 2))
1994 currentMember
= GetArgChunk();
1996 if (start
&& (arg_no
== 3))
1998 if (!start
&& (arg_no
== 3))
2005 const wxChar
* pend
= macroId
== ltCPARAM
?
2006 _T("</B> ") : _T("</B>");
2009 TexOutput(_T("<B>"));
2010 if( CheckTypeRef() ) {
2018 if (start
&& (arg_no
== 2))
2020 TexOutput(_T("<I>"));
2022 if (!start
&& (arg_no
== 2))
2024 TexOutput(_T("</I>"));
2030 if (!start
&& (arg_no
== 1))
2033 if (start
&& (arg_no
== 2))
2034 currentMember
= GetArgChunk();
2043 wxChar
*refName
= GetArgData();
2046 TexRef
*texRef
= FindReference(refName
);
2049 sec
= texRef
->sectionNumber
;
2062 if (IsArgOptional())
2064 else if ((GetNoArgs() - arg_no
) == 1)
2067 helpRefText
= GetArgChunk();
2070 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2074 TexChunk
*ref
= GetArgChunk();
2075 TexOutput(_T("<A HREF=\""));
2077 TraverseChildrenFromChunk(ref
);
2079 TexOutput(_T("\">"));
2081 TraverseChildrenFromChunk(helpRefText
);
2082 TexOutput(_T("</A>"));
2093 if (IsArgOptional())
2096 helpRefFilename
= GetArgChunk();
2099 if ((GetNoArgs() - arg_no
) == 1)
2102 helpRefText
= GetArgChunk();
2105 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2109 wxChar
*refName
= GetArgData();
2110 wxChar
*refFilename
= NULL
;
2114 TexRef
*texRef
= FindReference(refName
);
2117 if (texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0)
2118 refFilename
= texRef
->refFile
;
2120 TexOutput(_T("<A HREF=\""));
2121 // If a filename is supplied, use it, otherwise try to
2122 // use the filename associated with the reference (from this document).
2123 if (helpRefFilename
)
2125 TraverseChildrenFromChunk(helpRefFilename
);
2129 else if (refFilename
)
2131 TexOutput(ConvertCase(refFilename
));
2132 if(!PrimaryAnchorOfTheFile(texRef
->refFile
, refName
))
2138 TexOutput(_T("\">"));
2140 TraverseChildrenFromChunk(helpRefText
);
2141 TexOutput(_T("</A>"));
2146 TraverseChildrenFromChunk(helpRefText
);
2148 TexOutput(_T(" (REF NOT FOUND)"));
2150 // for launching twice do not warn in preparation pass
2151 if ((passNumber
== 1 && !runTwice
) ||
2152 (passNumber
== 2 && runTwice
))
2155 errBuf
.Printf(_T("Warning: unresolved reference '%s'"), refName
);
2160 else TexOutput(_T("??"));
2175 wxChar
*alignment
= _T("");
2176 if (macroId
== ltIMAGEL
)
2177 alignment
= _T(" align=left");
2178 else if (macroId
== ltIMAGER
)
2179 alignment
= _T(" align=right");
2181 // Try to find an XBM or GIF image first.
2182 wxChar
*filename
= copystring(GetArgData());
2185 wxStrcpy(buf
, filename
);
2186 StripExtension(buf
);
2187 wxStrcat(buf
, _T(".xbm"));
2188 wxString f
= TexPathList
.FindValidPath(buf
);
2190 if (f
== _T("")) // Try for a GIF instead
2192 wxStrcpy(buf
, filename
);
2193 StripExtension(buf
);
2194 wxStrcat(buf
, _T(".gif"));
2195 f
= TexPathList
.FindValidPath(buf
);
2198 if (f
== _T("")) // Try for a JPEG instead
2200 wxStrcpy(buf
, filename
);
2201 StripExtension(buf
);
2202 wxStrcat(buf
, _T(".jpg"));
2203 f
= TexPathList
.FindValidPath(buf
);
2206 if (f
== _T("")) // Try for a PNG instead
2208 wxStrcpy(buf
, filename
);
2209 StripExtension(buf
);
2210 wxStrcat(buf
, _T(".png"));
2211 f
= TexPathList
.FindValidPath(buf
);
2216 wxChar
*inlineFilename
= copystring(f
);
2218 wxChar
*originalFilename
= TexPathList
.FindValidPath(filename
);
2219 // If we have found the existing filename, make the inline
2220 // image point to the original file (could be PS, for example)
2221 if (originalFilename
&& (wxStrcmp(inlineFilename
, originalFilename
) != 0))
2223 TexOutput(_T("<A HREF=\""));
2224 TexOutput(ConvertCase(originalFilename
));
2225 TexOutput(_T("\">"));
2226 TexOutput(_T("<img src=\""));
2227 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2228 TexOutput(_T("\""));
2229 TexOutput(alignment
);
2230 TexOutput(_T("></A>"));
2235 TexOutput(_T("<img src=\""));
2236 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2237 TexOutput(_T("\""));
2238 TexOutput(alignment
);
2240 delete[] inlineFilename
;
2245 // Last resort - a link to a PS file.
2246 TexOutput(_T("<A HREF=\""));
2247 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
2248 TexOutput(_T("\">Picture</A>\n"));
2249 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2256 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2259 static wxChar
*imageFile
= NULL
;
2260 if (start
&& (arg_no
== 2))
2262 // Try to find an XBM or GIF image first.
2263 wxChar
*filename
= copystring(GetArgData());
2266 wxStrcpy(buf
, filename
);
2267 StripExtension(buf
);
2268 wxStrcat(buf
, _T(".xbm"));
2269 wxString f
= TexPathList
.FindValidPath(buf
);
2271 if (f
== _T("")) // Try for a GIF instead
2273 wxStrcpy(buf
, filename
);
2274 StripExtension(buf
);
2275 wxStrcat(buf
, _T(".gif"));
2276 f
= TexPathList
.FindValidPath(buf
);
2281 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2290 imageFile
= copystring(f
);
2293 else if (start
&& (arg_no
== 3))
2297 // First, try to find a .shg (segmented hypergraphics file)
2298 // that we can convert to a map file
2300 wxStrcpy(buf
, imageFile
);
2301 StripExtension(buf
);
2302 wxStrcat(buf
, _T(".shg"));
2303 wxString f
= TexPathList
.FindValidPath(buf
);
2307 // The default HTML file to go to is THIS file (so a no-op)
2308 SHGToMap(f
, currentFileName
);
2311 wxChar
*mapName
= GetArgData();
2312 TexOutput(_T("<A HREF=\"/cgi-bin/imagemap/"));
2316 TexOutput(_T("unknown"));
2317 TexOutput(_T("\">"));
2318 TexOutput(_T("<img src=\""));
2319 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2320 TexOutput(_T("\" ISMAP></A><P>"));
2340 descriptionItemArg
= GetArgChunk();
2346 case ltTWOCOLITEMRULED
:
2349 if (start && (arg_no == 1))
2350 TexOutput(_T("\n<DT> "));
2351 if (start && (arg_no == 2))
2352 TexOutput(_T("<DD> "));
2358 if (TwoColWidthA
> -1)
2361 wxSnprintf(buf
, sizeof(buf
), _T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA
);
2366 TexOutput(_T("\n<TR><TD VALIGN=TOP>\n"));
2370 TexOutput(_T("\n</FONT></TD>\n"));
2377 if (TwoColWidthB
> -1)
2380 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB
);
2385 TexOutput(_T("\n<TD VALIGN=TOP>\n"));
2389 TexOutput(_T("\n</FONT></TD></TR>\n"));
2393 case ltNUMBEREDBIBITEM
:
2395 if (arg_no
== 1 && start
)
2397 TexOutput(_T("\n<DT> "));
2399 if (arg_no
== 2 && !start
)
2400 TexOutput(_T("<P>\n"));
2406 if (arg_no
== 1 && start
)
2408 wxChar
*citeKey
= GetArgData();
2409 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2412 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2413 wxSnprintf(buf
, sizeof(buf
), _T("[%d]"), citeCount
);
2414 ref
->sectionNumber
= copystring(buf
);
2417 wxSnprintf(buf
, sizeof(buf
), _T("\n<DT> [%d] "), citeCount
);
2422 if (arg_no
== 2 && !start
)
2423 TexOutput(_T("<P>\n"));
2427 case ltMARGINPARODD
:
2428 case ltMARGINPAREVEN
:
2434 TexOutput(_T("<HR>\n"));
2438 TexOutput(_T("<HR><P>\n"));
2442 case ltTWOCOLWIDTHA
:
2446 wxChar
*val
= GetArgData();
2447 float points
= ParseUnitArgument(val
);
2448 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2453 case ltTWOCOLWIDTHB
:
2457 wxChar
*val
= GetArgData();
2458 float points
= ParseUnitArgument(val
);
2459 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2467 case ltACCENT_GRAVE
:
2471 wxChar
*val
= GetArgData();
2477 TexOutput(_T("à"));
2480 TexOutput(_T("è"));
2483 TexOutput(_T("ì"));
2486 TexOutput(_T("ò"));
2489 TexOutput(_T("ù"));
2492 TexOutput(_T("À"));
2495 TexOutput(_T("È"));
2498 TexOutput(_T("Ì"));
2501 TexOutput(_T("Ò"));
2504 TexOutput(_T("Ì"));
2513 case ltACCENT_ACUTE
:
2517 wxChar
*val
= GetArgData();
2523 TexOutput(_T("á"));
2526 TexOutput(_T("é"));
2529 TexOutput(_T("í"));
2532 TexOutput(_T("ó"));
2535 TexOutput(_T("ú"));
2538 TexOutput(_T("ý"));
2541 TexOutput(_T("Á"));
2544 TexOutput(_T("É"));
2547 TexOutput(_T("Í"));
2550 TexOutput(_T("Ó"));
2553 TexOutput(_T("Ú"));
2556 TexOutput(_T("Ý"));
2565 case ltACCENT_CARET
:
2569 wxChar
*val
= GetArgData();
2575 TexOutput(_T("â"));
2578 TexOutput(_T("ê"));
2581 TexOutput(_T("î"));
2584 TexOutput(_T("ô"));
2587 TexOutput(_T("û"));
2590 TexOutput(_T("Â"));
2593 TexOutput(_T("Ê"));
2596 TexOutput(_T("Î"));
2599 TexOutput(_T("Ô"));
2602 TexOutput(_T("Î"));
2611 case ltACCENT_TILDE
:
2615 wxChar
*val
= GetArgData();
2624 TexOutput(_T("ã"));
2627 TexOutput(_T("ñ"));
2630 TexOutput(_T("õ"));
2633 TexOutput(_T("Ã"));
2636 TexOutput(_T("Ñ"));
2639 TexOutput(_T("Õ"));
2648 case ltACCENT_UMLAUT
:
2652 wxChar
*val
= GetArgData();
2658 TexOutput(_T("ä"));
2661 TexOutput(_T("ë"));
2664 TexOutput(_T("ï"));
2667 TexOutput(_T("ö"));
2670 TexOutput(_T("ü"));
2673 TexOutput(_T("ÿ"));
2676 TexOutput(_T("Ä"));
2679 TexOutput(_T("Ë"));
2682 TexOutput(_T("Ï"));
2685 TexOutput(_T("Ö"));
2688 TexOutput(_T("Ü"));
2691 TexOutput(_T("Ÿ"));
2704 wxChar
*val
= GetArgData();
2710 TexOutput(_T("å"));
2713 TexOutput(_T("Å"));
2726 wxChar
*val
= GetArgData();
2729 bool isPicture
= false;
2730 ParseColourString(val
, &isPicture
);
2733 if (backgroundImageString
)
2734 delete[] backgroundImageString
;
2735 backgroundImageString
= copystring(val
);
2739 if (backgroundColourString
)
2740 delete[] backgroundColourString
;
2741 backgroundColourString
= copystring(val
);
2747 case ltBACKGROUNDIMAGE
:
2751 wxChar
*val
= GetArgData();
2754 if (backgroundImageString
)
2755 delete[] backgroundImageString
;
2756 backgroundImageString
= copystring(val
);
2761 case ltBACKGROUNDCOLOUR
:
2765 wxChar
*val
= GetArgData();
2768 if (backgroundColourString
)
2769 delete[] backgroundColourString
;
2770 backgroundColourString
= copystring(val
);
2779 wxChar
*val
= GetArgData();
2782 if (textColourString
)
2783 delete[] textColourString
;
2784 textColourString
= copystring(val
);
2793 wxChar
*val
= GetArgData();
2796 if (linkColourString
)
2797 delete[] linkColourString
;
2798 linkColourString
= copystring(val
);
2803 case ltFOLLOWEDLINKCOLOUR
:
2807 wxChar
*val
= GetArgData();
2810 if (followedLinkColourString
)
2811 delete[] followedLinkColourString
;
2812 followedLinkColourString
= copystring(val
);
2817 case ltACCENT_CADILLA
:
2821 wxChar
*val
= GetArgData();
2827 TexOutput(_T("ç"));
2830 TexOutput(_T("Ç"));
2841 case ltFOOTNOTEPOPUP:
2851 case ltSUPERTABULAR
:
2857 currentRowNumber
= 0;
2860 tableVerticalLineLeft
= false;
2861 tableVerticalLineRight
= false;
2863 wxChar
*alignString
= copystring(GetArgData());
2864 ParseTableArgument(alignString
);
2866 TexOutput(_T("<TABLE BORDER>\n"));
2868 // Write the first row formatting for compatibility
2869 // with standard Latex
2870 if (compatibilityMode
)
2872 TexOutput(_T("<TR>\n<TD>"));
2875 for (int i = 0; i < noColumns; i++)
2877 currentWidth += TableData[i].width;
2878 wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth);
2881 TexOutput(_T("\\pard\\intbl\n"));
2884 delete[] alignString
;
2889 else if (arg_no
== 2 && !start
)
2891 TexOutput(_T("</TABLE>\n"));
2896 case ltTHEBIBLIOGRAPHY
:
2898 if (start
&& (arg_no
== 1))
2900 ReopenFile(&Chapters
, &ChaptersName
, _T("bibliography"));
2901 AddTexRef(_T("bibliography"), ChaptersName
, _T("bibliography"));
2902 SetCurrentSubsectionName(_T("bibliography"), ChaptersName
);
2906 SetCurrentOutput(Chapters
);
2908 wxChar titleBuf
[150];
2909 if (truncateFilenames
)
2910 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
2912 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
2915 TexOutput(_T("<title>"));
2916 TexOutput(ReferencesNameString
);
2917 TexOutput(_T("</title></head>\n"));
2920 wxFprintf(Chapters
, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString
);
2921 AddBrowseButtons(_T("contents"), titleBuf
, // Up
2922 lastTopic
, lastFileName
, // Last topic
2923 _T("bibliography"), ChaptersName
); // This topic
2925 SetCurrentOutputs(Contents
, Chapters
);
2926 if(PrimaryAnchorOfTheFile(ChaptersName
, _T("bibliography")))
2927 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
2929 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), _T("bibliography"));
2931 wxFprintf(Contents
, _T("%s</A>\n"), ReferencesNameString
);
2932 wxFprintf(Chapters
, _T("</H2>\n</A>\n"));
2934 SetCurrentOutput(Chapters
);
2937 if (!start
&& (arg_no
== 2))
2944 /* Build up list of keywords associated with topics */
2947 // wxChar *entry = GetArgData();
2949 OutputChunkToString(GetArgChunk(), buf
);
2952 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2966 wxChar
*name
= GetArgData();
2968 if (!FindColourHTMLString(name
, buf2
))
2970 wxStrcpy(buf2
, _T("#000000"));
2972 wxSnprintf(buf
, sizeof(buf
), _T("Could not find colour name %s"), name
);
2975 TexOutput(_T("<FONT COLOR=\""));
2977 TexOutput(_T("\">"));
2990 if (arg_no
== 2) TexOutput(_T("</FONT>"));
2994 case ltINSERTATLEVEL
:
2996 // This macro allows you to insert text at a different level
2997 // from the current level, e.g. into the Sections from within a subsubsection.
3000 static int currentLevelNo
= 1;
3001 static FILE* oldLevelFile
= Chapters
;
3008 oldLevelFile
= CurrentOutput1
;
3010 wxChar
*str
= GetArgData();
3011 currentLevelNo
= wxAtoi(str
);
3013 // TODO: cope with article style (no chapters)
3014 switch (currentLevelNo
)
3018 outputFile
= Chapters
;
3023 outputFile
= Sections
;
3028 outputFile
= Subsections
;
3033 outputFile
= Subsubsections
;
3043 CurrentOutput1
= outputFile
;
3059 CurrentOutput1
= oldLevelFile
;
3065 return DefaultOnArgument(macroId
, arg_no
, start
);
3077 tableVerticalLineLeft
= false;
3078 tableVerticalLineRight
= false;
3081 if (!InputFile
.empty() && !OutputFile
.empty())
3083 // Do some HTML-specific transformations on all the strings,
3085 Text2HTML(GetTopLevelChunk());
3088 if (truncateFilenames
)
3089 wxSnprintf(buf
, sizeof(buf
), _T("%s.htm"), FileRoot
);
3091 wxSnprintf(buf
, sizeof(buf
), _T("%s_contents.html"), FileRoot
);
3092 if (TitlepageName
) delete[] TitlepageName
;
3093 TitlepageName
= copystring(buf
);
3094 Titlepage
= wxFopen(buf
, _T("w"));
3096 if (truncateFilenames
)
3097 wxSnprintf(buf
, sizeof(buf
), _T("%s_fc.htm"), FileRoot
);
3099 wxSnprintf(buf
, sizeof(buf
), _T("%s_fcontents.html"), FileRoot
);
3101 contentsFrameName
= copystring(buf
);
3103 Contents
= wxFopen(TmpContentsName
, _T("w"));
3105 if (htmlFrameContents
)
3107 // FrameContents = wxFopen(TmpFrameContentsName, _T("w"));
3108 FrameContents
= wxFopen(contentsFrameName
, _T("w"));
3109 wxFprintf(FrameContents
, _T("<HTML>\n<UL>\n"));
3112 if (!Titlepage
|| !Contents
)
3114 OnError(_T("Cannot open output file!"));
3117 AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName
), ContentsNameString
);
3119 wxFprintf(Contents
, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString
);
3121 wxFprintf(Contents
, _T("<UL>\n"));
3123 SetCurrentOutput(Titlepage
);
3124 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
3125 OnInform(_T("Converting..."));
3128 wxFprintf(Contents
, _T("</UL>\n\n"));
3130 // SetCurrentOutput(Titlepage);
3135 // wxFprintf(Titlepage, _T("\n</BODY></HTML>\n"));
3142 wxFprintf(FrameContents
, _T("\n</UL>\n"));
3143 wxFprintf(FrameContents
, _T("</HTML>\n"));
3144 fclose(FrameContents
);
3145 FrameContents
= NULL
;
3150 wxFprintf(Chapters
, _T("\n</FONT></BODY></HTML>\n"));
3156 wxFprintf(Sections
, _T("\n</FONT></BODY></HTML>\n"));
3160 if (Subsections
&& !combineSubSections
)
3162 wxFprintf(Subsections
, _T("\n</FONT></BODY></HTML>\n"));
3163 fclose(Subsections
);
3166 if (Subsubsections
&& !combineSubSections
)
3168 wxFprintf(Subsubsections
, _T("\n</FONT></BODY></HTML>\n"));
3169 fclose(Subsubsections
);
3170 Subsubsections
= NULL
;
3172 if ( SectionContentsFD
)
3174 fclose(SectionContentsFD
);
3175 SectionContentsFD
= NULL
;
3178 // Create a temporary file for the title page header, add some info,
3179 // and concat the titlepage just generated.
3180 // This is necessary in order to put the title of the document
3181 // at the TOP of the file within <HEAD>, even though we only find out
3182 // what it is later on.
3183 FILE *tmpTitle
= wxFopen(_T("title.tmp"), _T("w"));
3188 SetCurrentOutput(tmpTitle
);
3190 TexOutput(_T("\n<TITLE>"));
3191 TraverseChildrenFromChunk(DocumentTitle
);
3192 TexOutput(_T("</TITLE></HEAD>\n"));
3196 SetCurrentOutput(tmpTitle
);
3197 HTMLHeadTo(tmpTitle
);
3199 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), contentsString
);
3201 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), wxFileNameFromPath(FileRoot
));
3204 // Output frame information
3205 if (htmlFrameContents
)
3207 wxChar firstFileName
[300];
3208 if (truncateFilenames
)
3209 wxSnprintf(firstFileName
, sizeof(firstFileName
), _T("%s1.htm"), FileRoot
);
3211 wxStrcpy(firstFileName
, gs_filenames
[1].c_str());
3213 wxFprintf(tmpTitle
, _T("<FRAMESET COLS=\"30%%,70%%\">\n"));
3215 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName
)));
3216 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName
)));
3217 wxFprintf(tmpTitle
, _T("</FRAMESET>\n"));
3219 wxFprintf(tmpTitle
, _T("<NOFRAMES>\n"));
3222 // Output <BODY...> to temporary title page
3227 FILE *fd
= wxFopen(TitlepageName
, _T("r"));
3233 wxPutc(ch
, tmpTitle
);
3239 wxFprintf(tmpTitle
, _T("\n</FONT></BODY>\n"));
3241 if (htmlFrameContents
)
3243 wxFprintf(tmpTitle
, _T("\n</NOFRAMES>\n"));
3245 wxFprintf(tmpTitle
, _T("\n</HTML>\n"));
3248 if (wxFileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3249 if (!wxRenameFile(_T("title.tmp"), TitlepageName
))
3251 wxCopyFile(_T("title.tmp"), TitlepageName
);
3252 wxRemoveFile(_T("title.tmp"));
3256 if (lastFileName
) delete[] lastFileName
;
3257 lastFileName
= NULL
;
3258 if (lastTopic
) delete[] lastTopic
;
3261 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3263 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3265 wxCopyFile(TmpContentsName
, ContentsName
);
3266 wxRemoveFile(TmpContentsName
);
3269 // Generate .htx file if requested
3272 wxChar htmlIndexName
[300];
3273 wxSnprintf(htmlIndexName
, sizeof(htmlIndexName
), _T("%s.htx"), FileRoot
);
3274 GenerateHTMLIndexFile(htmlIndexName
);
3277 // Generate HTML Help Workshop files if requested
3278 if (htmlWorkshopFiles
)
3280 HTMLWorkshopEndContents();
3281 GenerateHTMLWorkshopFiles(FileRoot
);
3290 // Output .htx index file
3291 void GenerateHTMLIndexFile(wxChar
*fname
)
3293 FILE *fd
= wxFopen(fname
, _T("w"));
3297 TopicTable
.BeginFind();
3298 wxHashTable::Node
*node
= TopicTable
.Next();
3301 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3302 const wxChar
*topicName
= node
->GetKeyString();
3303 if (texTopic
->filename
&& texTopic
->keywords
)
3305 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3308 wxChar
*s
= (wxChar
*)node1
->GetData();
3309 wxFprintf(fd
, _T("%s|%s|%s\n"), topicName
, texTopic
->filename
, s
);
3310 node1
= node1
->GetNext();
3313 node
= TopicTable
.Next();
3324 // output .hpp, .hhc and .hhk files:
3327 void GenerateHTMLWorkshopFiles(wxChar
*fname
)
3332 /* Generate project file : */
3334 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhp"), fname
);
3335 f
= wxFopen(buf
, _T("wt"));
3338 _T("Compatibility=1.1\n")
3339 _T("Full-text search=Yes\n")
3340 _T("Contents file=%s.hhc\n")
3341 _T("Compiled file=%s.chm\n")
3342 _T("Default Window=%sHelp\n")
3343 _T("Default topic=%s\n")
3344 _T("Index file=%s.hhk\n")
3346 wxFileNameFromPath(fname
),
3347 wxFileNameFromPath(fname
),
3348 wxFileNameFromPath(fname
),
3349 wxFileNameFromPath(TitlepageName
),
3350 wxFileNameFromPath(fname
)
3353 if (DocumentTitle
) {
3354 SetCurrentOutput(f
);
3355 TraverseChildrenFromChunk(DocumentTitle
);
3357 else wxFprintf(f
, _T("(unknown)"));
3359 wxFprintf(f
, _T("\n\n[WINDOWS]\n")
3360 _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"),
3361 wxFileNameFromPath(fname
),
3362 wxFileNameFromPath(fname
),
3363 wxFileNameFromPath(fname
),
3364 wxFileNameFromPath(TitlepageName
));
3367 wxFprintf(f
, _T("\n\n[FILES]\n"));
3368 wxFprintf(f
, _T("%s\n"), wxFileNameFromPath(TitlepageName
));
3369 for (int i
= 1; i
<= fileId
; i
++) {
3370 if (truncateFilenames
)
3371 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), wxFileNameFromPath(FileRoot
), i
);
3373 wxStrcpy(buf
, wxFileNameFromPath(gs_filenames
[i
].c_str()));
3374 wxFprintf(f
, _T("%s\n"), buf
);
3378 /* Generate index file : */
3380 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhk"), fname
);
3381 f
= wxFopen(buf
, _T("wt"));
3384 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3389 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3390 _T("<!-- Sitemap 1.0 -->\n")
3391 _T("</HEAD><BODY>\n")
3392 _T("<OBJECT type=\"text/site properties\">\n")
3393 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3397 TopicTable
.BeginFind();
3398 wxHashTable::Node
*node
= TopicTable
.Next();
3401 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3402 const wxChar
*topicName
= node
->GetKeyString();
3403 if (texTopic
->filename
&& texTopic
->keywords
)
3405 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3408 wxChar
*s
= (wxChar
*)node1
->GetData();
3410 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3411 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3412 _T(" <param name=\"Name\" value=\"%s\">\n")
3414 texTopic
->filename
, topicName
, s
);
3415 node1
= node1
->GetNext();
3418 node
= TopicTable
.Next();
3421 wxFprintf(f
, _T("</UL>\n"));
3427 static FILE *HTMLWorkshopContents
= NULL
;
3428 static int HTMLWorkshopLastLevel
= 0;
3430 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
)
3434 if (level
> HTMLWorkshopLastLevel
)
3435 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3436 wxFprintf(HTMLWorkshopContents
, _T("<UL>"));
3437 if (level
< HTMLWorkshopLastLevel
)
3438 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3439 wxFprintf(HTMLWorkshopContents
, _T("</UL>"));
3441 SetCurrentOutput(HTMLWorkshopContents
);
3442 wxFprintf(HTMLWorkshopContents
,
3443 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3444 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3445 _T(" <param name=\"Name\" value=\""),
3447 OutputCurrentSection();
3448 wxFprintf(HTMLWorkshopContents
,
3450 _T(" </OBJECT>\n"));
3451 HTMLWorkshopLastLevel
= level
;
3455 void HTMLWorkshopStartContents()
3458 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhc"), FileRoot
);
3459 HTMLWorkshopContents
= wxFopen(buf
, _T("wt"));
3460 HTMLWorkshopLastLevel
= 0;
3462 wxFprintf(HTMLWorkshopContents
,
3463 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3465 HTMLHeadTo(HTMLWorkshopContents
);
3466 wxFprintf(HTMLWorkshopContents
,
3468 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3469 _T("<!-- Sitemap 1.0 -->\n")
3470 _T("</HEAD><BODY>\n")
3471 _T("<OBJECT type=\"text/site properties\">\n")
3472 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3475 _T("<LI> <OBJECT type=\"text/sitemap\">\n")
3476 _T("<param name=\"Local\" value=\"%s\">\n")
3477 _T("<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n"),
3478 wxFileNameFromPath(TitlepageName
)
3484 void HTMLWorkshopEndContents()
3486 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3487 wxFprintf(HTMLWorkshopContents
, _T("</UL>\n"));
3488 fclose(HTMLWorkshopContents
);
3492 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
)
3494 wxString file_label
;
3495 file_label
.Printf( HTML_FILENAME_PATTERN
, FileRoot
, label
);
3496 return file_label
.IsSameAs( file
, false );