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 /////////////////////////////////////////////////////////////////////////////
14 #pragma implementation
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
27 #include "wx/arrstr.h"
33 #define HTML_FILENAME_PATTERN _T("%s_%s.html")
35 #if !WXWIN_COMPATIBILITY_2_4
36 static inline wxChar
* copystring(const wxChar
* s
)
37 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
40 extern wxHashTable TexReferences
;
42 extern int passNumber
;
44 extern void DecToHex(int, wxChar
*);
45 void GenerateHTMLIndexFile(wxChar
*fname
);
47 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
);
49 void GenerateHTMLWorkshopFiles(wxChar
*fname
);
50 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
);
51 void HTMLWorkshopStartContents();
52 void HTMLWorkshopEndContents();
54 void OutputContentsFrame(void);
56 #include "readshg.h" // Segmented hypergraphics parsing
58 wxChar
*ChaptersName
= NULL
;
59 wxChar
*SectionsName
= NULL
;
60 wxChar
*SubsectionsName
= NULL
;
61 wxChar
*SubsubsectionsName
= NULL
;
62 wxChar
*TitlepageName
= NULL
;
63 wxChar
*lastFileName
= NULL
;
64 wxChar
*lastTopic
= NULL
;
65 wxChar
*currentFileName
= NULL
;
66 wxChar
*contentsFrameName
= NULL
;
68 static TexChunk
*descriptionItemArg
= NULL
;
69 static TexChunk
*helpRefFilename
= NULL
;
70 static TexChunk
*helpRefText
= NULL
;
71 static int indentLevel
= 0;
72 static int citeCount
= 1;
73 extern FILE *Contents
;
74 FILE *FrameContents
= NULL
;
75 FILE *Titlepage
= NULL
;
76 // FILE *FrameTitlepage = NULL;
78 bool subsectionStarted
= false;
80 // Which column of a row are we in? (Assumes no nested tables, of course)
81 int currentColumn
= 0;
83 // Are we in verbatim mode? If so, format differently.
84 static bool inVerbatim
= false;
86 // Need to know whether we're in a table or figure for benefit
87 // of listoffigures/listoftables
88 static bool inFigure
= false;
89 static bool inTable
= false;
91 // This is defined in the Tex2Any library.
92 extern wxChar
*BigBuffer
;
94 // DHS Two-column table dimensions.
95 static int TwoColWidthA
= -1;
96 static int TwoColWidthB
= -1;
99 class HyperReference
: public wxObject
104 HyperReference(wxChar
*name
, wxChar
*file
)
106 if (name
) refName
= copystring(name
);
107 if (file
) refFile
= copystring(file
);
111 class TexNextPage
: public wxObject
116 TexNextPage(wxChar
*theLabel
, wxChar
*theFile
)
118 label
= copystring(theLabel
);
119 filename
= copystring(theFile
);
128 wxHashTable
TexNextPages(wxKEY_STRING
);
130 static wxChar
*CurrentChapterName
= NULL
;
131 static wxChar
*CurrentChapterFile
= NULL
;
132 static wxChar
*CurrentSectionName
= NULL
;
133 static wxChar
*CurrentSectionFile
= NULL
;
134 static wxChar
*CurrentSubsectionName
= NULL
;
135 static wxChar
*CurrentSubsectionFile
= NULL
;
136 static wxChar
*CurrentSubsubsectionName
= NULL
;
137 static wxChar
*CurrentSubsubsectionFile
= NULL
;
138 static wxChar
*CurrentTopic
= NULL
;
140 static void SetCurrentTopic(wxChar
*s
)
142 if (CurrentTopic
) delete[] CurrentTopic
;
143 CurrentTopic
= copystring(s
);
146 void SetCurrentChapterName(wxChar
*s
, wxChar
*file
)
148 if (CurrentChapterName
) delete[] CurrentChapterName
;
149 CurrentChapterName
= copystring(s
);
150 if (CurrentChapterFile
) delete[] CurrentChapterFile
;
151 CurrentChapterFile
= copystring(file
);
153 currentFileName
= CurrentChapterFile
;
157 void SetCurrentSectionName(wxChar
*s
, wxChar
*file
)
159 if (CurrentSectionName
) delete[] CurrentSectionName
;
160 CurrentSectionName
= copystring(s
);
161 if (CurrentSectionFile
) delete[] CurrentSectionFile
;
162 CurrentSectionFile
= copystring(file
);
164 currentFileName
= CurrentSectionFile
;
167 void SetCurrentSubsectionName(wxChar
*s
, wxChar
*file
)
169 if (CurrentSubsectionName
) delete[] CurrentSubsectionName
;
170 CurrentSubsectionName
= copystring(s
);
171 if (CurrentSubsectionFile
) delete[] CurrentSubsectionFile
;
172 CurrentSubsectionFile
= copystring(file
);
173 currentFileName
= CurrentSubsectionFile
;
176 void SetCurrentSubsubsectionName(wxChar
*s
, wxChar
*file
)
178 if (CurrentSubsubsectionName
) delete[] CurrentSubsubsectionName
;
179 CurrentSubsubsectionName
= copystring(s
);
180 if (CurrentSubsubsectionFile
) delete[] CurrentSubsubsectionFile
;
181 CurrentSubsubsectionFile
= copystring(file
);
182 currentFileName
= CurrentSubsubsectionFile
;
187 // mapping between fileId and filenames if truncateFilenames=false:
188 static wxArrayString gs_filenames
;
192 * Close former filedescriptor and reopen using another filename.
196 void ReopenFile(FILE **fd
, wxChar
**fileName
, const wxChar
*label
)
200 wxFprintf(*fd
, _T("\n</FONT></BODY></HTML>\n"));
205 if (truncateFilenames
)
207 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), FileRoot
, fileId
);
212 gs_filenames
.Add(wxEmptyString
);
213 wxSnprintf(buf
, sizeof(buf
), HTML_FILENAME_PATTERN
, FileRoot
, label
);
214 gs_filenames
.Add(buf
);
216 if (*fileName
) delete[] *fileName
;
217 *fileName
= copystring(wxFileNameFromPath(buf
));
218 *fd
= wxFopen(buf
, _T("w"));
219 wxFprintf(*fd
, _T("<HTML>\n"));
223 * Reopen section contents file, i.e. the index appended to each section
224 * in subsectionCombine mode
227 static wxChar
*SectionContentsFilename
= NULL
;
228 static FILE *SectionContentsFD
= NULL
;
230 void ReopenSectionContentsFile(void)
232 if ( SectionContentsFD
)
234 fclose(SectionContentsFD
);
236 if ( SectionContentsFilename
)
237 delete[] SectionContentsFilename
;
238 SectionContentsFD
= NULL
;
239 SectionContentsFilename
= NULL
;
241 // Create the name from the current section filename
242 if ( CurrentSectionFile
)
245 wxStrcpy(buf
, CurrentSectionFile
);
246 wxStripExtension(buf
);
247 wxStrcat(buf
, _T(".con"));
248 SectionContentsFilename
= copystring(buf
);
250 SectionContentsFD
= wxFopen(SectionContentsFilename
, _T("w"));
256 * Given a TexChunk with a string value, scans through the string
257 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
261 void ProcessText2HTML(TexChunk
*chunk
)
263 bool changed
= false;
267 int len
= wxStrlen(chunk
->value
);
270 ch
= chunk
->value
[i
];
272 // 2 newlines means \par
273 if (!inVerbatim
&& chunk
->value
[i
] == 10 && ((len
> i
+1 && chunk
->value
[i
+1] == 10) ||
274 ((len
> i
+1 && chunk
->value
[i
+1] == 13) &&
275 (len
> i
+2 && chunk
->value
[i
+2] == 10))))
277 BigBuffer
[ptr
] = 0; wxStrcat(BigBuffer
, _T("<P>\n\n")); ptr
+= 5;
281 else if (!inVerbatim
&& ch
== _T('`') && (len
>= i
+1 && chunk
->value
[i
+1] == '`'))
283 BigBuffer
[ptr
] = '"'; ptr
++;
287 else if (!inVerbatim
&& ch
== _T('`')) // Change ` to '
289 BigBuffer
[ptr
] = 39; ptr
++;
293 else if (ch
== _T('<')) // Change < to <
296 wxStrcat(BigBuffer
, _T("<"));
301 else if (ch
== _T('>')) // Change > to >
304 wxStrcat(BigBuffer
, _T(">"));
321 chunk
->value
= copystring(BigBuffer
);
326 * Scan through all chunks starting from the given one,
327 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
328 * This should be called after Tex2Any has parsed the file,
329 * and before TraverseDocument is called.
333 void Text2HTML(TexChunk
*chunk
)
336 if (stopRunning
) return;
340 case CHUNK_TYPE_MACRO
:
342 TexMacroDef
*def
= chunk
->def
;
344 if (def
&& def
->ignore
)
347 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
350 wxNode
*node
= chunk
->children
.GetFirst();
353 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
354 Text2HTML(child_chunk
);
355 node
= node
->GetNext();
358 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
365 wxNode
*node
= chunk
->children
.GetFirst();
368 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
369 Text2HTML(child_chunk
);
370 node
= node
->GetNext();
375 case CHUNK_TYPE_STRING
:
378 ProcessText2HTML(chunk
);
385 * Add appropriate browse buttons to this page.
389 void AddBrowseButtons(wxChar
*upLabel
, wxChar
*upFilename
,
390 wxChar
*previousLabel
, wxChar
*previousFilename
,
391 wxChar
*thisLabel
, wxChar
*thisFilename
)
393 wxChar contentsReferenceBuf
[80];
394 wxChar upReferenceBuf
[80];
395 wxChar backReferenceBuf
[80];
396 wxChar forwardReferenceBuf
[80];
397 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
400 wxChar
*contentsReference
; // no need to initialize because always assigned below
401 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
402 contentsReference
= ContentsNameString
;
405 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
406 contentsReference
= contentsReferenceBuf
;
407 wxSnprintf(contentsReference
, sizeof(contentsReferenceBuf
),
408 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">"),
409 ConvertCase(_T("contents.gif")));
412 wxChar
*upReference
; // no need to initialize because always assigned below
413 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
414 upReference
= UpNameString
;
417 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
418 upReference
= upReferenceBuf
;
419 wxSnprintf(upReference
, sizeof(upReferenceBuf
),
420 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">"),
421 ConvertCase(_T("up.gif")));
424 wxChar
*backReference
; // no need to initialize because always assigned below
425 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
426 backReference
= _T("<<");
429 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
430 backReference
= backReferenceBuf
;
431 wxSnprintf(backReference
, sizeof(backReferenceBuf
),
432 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">"),
433 ConvertCase(_T("back.gif")));
436 wxChar
*forwardReference
; // no need to initialize because always assigned below
437 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
438 forwardReference
= _T(">>");
441 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
442 forwardReference
= forwardReferenceBuf
;
443 wxSnprintf(forwardReference
, sizeof(forwardReferenceBuf
),
444 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">"),
445 ConvertCase(_T("forward.gif")));
448 TexOutput(_T("<CENTER>"));
457 if (truncateFilenames
)
460 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
461 wxSnprintf(buf
, sizeof(buf
),
462 _T("\n<A HREF=\"%s.%s\">%s</A> "),
463 buf1
, ConvertCase(_T("htm")), contentsReference
);
468 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
469 wxSnprintf(buf
, sizeof(buf
),
470 _T("\n<A HREF=\"%s%s\">%s</A> "),
471 buf1
, ConvertCase(_T("_contents.html")), contentsReference
);
473 // TexOutput(_T("<NOFRAMES>"));
475 // TexOutput(_T("</NOFRAMES>"));
482 if (upLabel
&& upFilename
)
484 if ( (wxStrlen(upLabel
) > 0) && !PrimaryAnchorOfTheFile(upFilename
, upLabel
) )
485 wxSnprintf(buf
, sizeof(buf
),
486 _T("<A HREF=\"%s#%s\">%s</A> "),
487 ConvertCase(upFilename
), upLabel
, upReference
);
489 wxSnprintf(buf
, sizeof(buf
),
490 _T("<A HREF=\"%s\">%s</A> "),
491 ConvertCase(upFilename
), upReference
);
492 if (wxStrcmp(upLabel
, _T("contents")) == 0)
494 // TexOutput(_T("<NOFRAMES>"));
496 // TexOutput(_T("</NOFRAMES>"));
507 if (previousLabel
&& previousFilename
)
509 if (PrimaryAnchorOfTheFile(previousFilename
, previousLabel
))
510 wxSnprintf(buf
, sizeof(buf
),
511 _T("<A HREF=\"%s\">%s</A> "),
512 ConvertCase(previousFilename
), backReference
);
514 wxSnprintf(buf
, sizeof(buf
),
515 _T("<A HREF=\"%s#%s\">%s</A> "),
516 ConvertCase(previousFilename
), previousLabel
, backReference
);
517 if (wxStrcmp(previousLabel
, _T("contents")) == 0)
519 // TexOutput(_T("<NOFRAMES>"));
521 // TexOutput(_T("</NOFRAMES>"));
528 // A placeholder so the buttons don't keep moving position
529 wxSnprintf(buf
, sizeof(buf
), _T("%s "), backReference
);
533 wxChar
*nextLabel
= NULL
;
534 wxChar
*nextFilename
= NULL
;
536 // Get the next page, and record the previous page's 'next' page
538 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
541 nextLabel
= nextPage
->label
;
542 nextFilename
= nextPage
->filename
;
544 if (previousLabel
&& previousFilename
)
546 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
550 TexNextPages
.Delete(previousLabel
);
552 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
553 TexNextPages
.Put(previousLabel
, newNextPage
);
561 if (nextLabel
&& nextFilename
)
563 if (PrimaryAnchorOfTheFile(nextFilename
, nextLabel
))
564 wxSnprintf(buf
, sizeof(buf
),
565 _T("<A HREF=\"%s\">%s</A> "),
566 ConvertCase(nextFilename
), forwardReference
);
568 wxSnprintf(buf
, sizeof(buf
),
569 _T("<A HREF=\"%s#%s\">%s</A> "),
570 ConvertCase(nextFilename
), nextLabel
, forwardReference
);
575 // A placeholder so the buttons don't keep moving position
576 wxSnprintf(buf
, sizeof(buf
), _T("%s "), forwardReference
);
581 * Horizontal rule to finish it off nicely.
584 TexOutput(_T("</CENTER>"));
585 TexOutput(_T("<HR>\n"));
587 // Update last topic/filename
589 delete[] lastFileName
;
590 lastFileName
= copystring(thisFilename
);
593 lastTopic
= copystring(thisLabel
);
596 // A colour string is either 3 numbers separated by semicolons (RGB),
597 // or a reference to a GIF. Return the filename or a hex string like #934CE8
598 wxChar
*ParseColourString(wxChar
*bkStr
, bool *isPicture
)
600 static wxChar resStr
[300];
601 wxStrcpy(resStr
, bkStr
);
602 wxStringTokenizer
tok(resStr
, _T(";"), wxTOKEN_STRTOK
);
603 if (tok
.HasMoreTokens())
605 wxString token1
= tok
.GetNextToken();
606 if (!tok
.HasMoreTokens())
613 wxString token2
= tok
.GetNextToken();
615 if (tok
.HasMoreTokens())
617 wxString token3
= tok
.GetNextToken();
619 // Now convert 3 strings into decimal numbers, and then hex numbers.
620 int red
= wxAtoi(token1
.c_str());
621 int green
= wxAtoi(token2
.c_str());
622 int blue
= wxAtoi(token3
.c_str());
624 wxStrcpy(resStr
, _T("#"));
628 wxStrcat(resStr
, buf
);
629 DecToHex(green
, buf
);
630 wxStrcat(resStr
, buf
);
632 wxStrcat(resStr
, buf
);
641 void OutputFont(void)
643 // Only output <font face> if explicitly requested by htmlFaceName= directive in
644 // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's
648 // Output <FONT FACE=...>
649 TexOutput(_T("<FONT FACE=\""));
650 TexOutput(htmlFaceName
);
651 TexOutput(_T("\">\n"));
655 // Output start of <BODY> block
656 void OutputBodyStart(void)
658 TexOutput(_T("\n<BODY"));
659 if (backgroundImageString
)
661 bool isPicture
= false;
662 wxChar
*s
= ParseColourString(backgroundImageString
, &isPicture
);
665 TexOutput(_T(" BACKGROUND=\""));
670 if (backgroundColourString
)
672 bool isPicture
= false;
673 wxChar
*s
= ParseColourString(backgroundColourString
, &isPicture
);
676 TexOutput(_T(" BGCOLOR="));
681 // Set foreground text colour, if one is specified
682 if (textColourString
)
684 bool isPicture
= false;
685 wxChar
*s
= ParseColourString(textColourString
, &isPicture
);
688 TexOutput(_T(" TEXT=")); TexOutput(s
);
691 // Set link text colour, if one is specified
692 if (linkColourString
)
694 bool isPicture
= false;
695 wxChar
*s
= ParseColourString(linkColourString
, &isPicture
);
698 TexOutput(_T(" LINK=")); TexOutput(s
);
701 // Set followed link text colour, if one is specified
702 if (followedLinkColourString
)
704 bool isPicture
= false;
705 wxChar
*s
= ParseColourString(followedLinkColourString
, &isPicture
);
708 TexOutput(_T(" VLINK=")); TexOutput(s
);
711 TexOutput(_T(">\n"));
718 TexOutput(_T("<head>"));
719 if (htmlStylesheet
) {
720 TexOutput(_T("<link rel=stylesheet type=\"text/css\" href=\""));
721 TexOutput(htmlStylesheet
);
722 TexOutput(_T("\">"));
726 void HTMLHeadTo(FILE* f
)
729 wxFprintf(f
,_T("<head><link rel=stylesheet type=\"text/css\" href=\"%s\">"),htmlStylesheet
);
731 wxFprintf(f
,_T("<head>"));
734 // Called on start/end of macro examination
735 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
741 case ltCHAPTERHEADING
:
749 if (macroId
!= ltCHAPTERSTAR
)
752 SetCurrentOutput(NULL
);
753 startedSections
= true;
755 wxChar
*topicName
= FindTopicName(GetNextChunk());
756 ReopenFile(&Chapters
, &ChaptersName
, topicName
);
757 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
759 SetCurrentChapterName(topicName
, ChaptersName
);
760 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
762 SetCurrentOutput(Chapters
);
765 TexOutput(_T("<title>"));
766 OutputCurrentSection(); // Repeat section header
767 TexOutput(_T("</title></head>\n"));
770 wxChar titleBuf
[200];
771 if (truncateFilenames
)
772 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
774 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
776 wxFprintf(Chapters
, _T("<A NAME=\"%s\"></A>"), topicName
);
778 AddBrowseButtons(_T(""), titleBuf
, // Up
779 lastTopic
, lastFileName
, // Last topic
780 topicName
, ChaptersName
); // This topic
782 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
783 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
785 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), topicName
);
787 if (htmlFrameContents
&& FrameContents
)
789 SetCurrentOutput(FrameContents
);
790 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
791 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
));
793 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
), topicName
);
794 OutputCurrentSection();
795 wxFprintf(FrameContents
, _T("</A>\n"));
798 SetCurrentOutputs(Contents
, Chapters
);
799 wxFprintf(Chapters
, _T("\n<H2>"));
800 OutputCurrentSection();
801 wxFprintf(Contents
, _T("</A>\n"));
802 wxFprintf(Chapters
, _T("</H2>\n"));
804 SetCurrentOutput(Chapters
);
806 // Add this section title to the list of keywords
809 OutputCurrentSectionToString(wxTex2RTFBuffer
);
810 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, ConvertCase(currentFileName
));
817 case ltSECTIONHEADING
:
824 subsectionStarted
= false;
826 if (macroId
!= ltSECTIONSTAR
)
829 SetCurrentOutput(NULL
);
830 startedSections
= true;
832 wxChar
*topicName
= FindTopicName(GetNextChunk());
833 ReopenFile(&Sections
, &SectionsName
, topicName
);
834 AddTexRef(topicName
, SectionsName
, SectionNameString
);
836 SetCurrentSectionName(topicName
, SectionsName
);
837 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
839 SetCurrentOutput(Sections
);
841 TexOutput(_T("<title>"));
842 OutputCurrentSection();
843 TexOutput(_T("</title></head>\n"));
846 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
847 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
848 lastTopic
, lastFileName
, // Last topic
849 topicName
, SectionsName
); // This topic
851 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
853 SetCurrentOutputs(jumpFrom
, Sections
);
854 if (DocumentStyle
== LATEX_ARTICLE
)
856 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
857 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(SectionsName
));
859 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(SectionsName
), topicName
);
863 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
864 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SectionsName
));
866 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SectionsName
), topicName
);
869 wxFprintf(Sections
, _T("\n<H2>"));
870 OutputCurrentSection();
872 if (DocumentStyle
== LATEX_ARTICLE
)
873 wxFprintf(jumpFrom
, _T("</A>\n"));
875 wxFprintf(jumpFrom
, _T("</B></A><BR>\n"));
876 wxFprintf(Sections
, _T("</H2>\n"));
878 SetCurrentOutput(Sections
);
879 // Add this section title to the list of keywords
882 OutputCurrentSectionToString(wxTex2RTFBuffer
);
883 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
889 case ltSUBSECTIONSTAR
:
890 case ltMEMBERSECTION
:
891 case ltFUNCTIONSECTION
:
897 OnError(_T("You cannot have a subsection before a section!"));
903 if (macroId
!= ltSUBSECTIONSTAR
)
906 if ( combineSubSections
&& !subsectionStarted
)
910 // Read old .con file in at this point
912 wxStrcpy(buf
, CurrentSectionFile
);
913 wxStripExtension(buf
);
914 wxStrcat(buf
, _T(".con"));
915 FILE *fd
= wxFopen(buf
, _T("r"));
921 wxPutc(ch
, Sections
);
926 wxFprintf(Sections
, _T("<P>\n"));
928 // Close old file, create a new file for the sub(sub)section contents entries
929 ReopenSectionContentsFile();
932 startedSections
= true;
933 subsectionStarted
= true;
935 wxChar
*topicName
= FindTopicName(GetNextChunk());
937 if ( !combineSubSections
)
939 SetCurrentOutput(NULL
);
940 ReopenFile(&Subsections
, &SubsectionsName
, topicName
);
941 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
942 SetCurrentSubsectionName(topicName
, SubsectionsName
);
943 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
944 SetCurrentOutput(Subsections
);
947 TexOutput(_T("<title>"));
948 OutputCurrentSection();
949 TexOutput(_T("</title></head>\n"));
952 wxFprintf(Subsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
953 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
954 lastTopic
, lastFileName
, // Last topic
955 topicName
, SubsectionsName
); // This topic
957 SetCurrentOutputs(Sections
, Subsections
);
958 if(PrimaryAnchorOfTheFile(SubsectionsName
, topicName
))
959 wxFprintf(Sections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsectionsName
));
961 wxFprintf(Sections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName
), topicName
);
963 wxFprintf(Subsections
, _T("\n<H3>"));
964 OutputCurrentSection();
965 wxFprintf(Sections
, _T("</B></A><BR>\n"));
966 wxFprintf(Subsections
, _T("</H3>\n"));
968 SetCurrentOutput(Subsections
);
972 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
973 SetCurrentSubsectionName(topicName
, SectionsName
);
975 // if ( subsectionNo != 0 )
976 wxFprintf(Sections
, _T("\n<HR>\n"));
978 // We're putting everything into the section file
979 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
980 wxFprintf(Sections
, _T("\n<H3>"));
981 OutputCurrentSection();
982 wxFprintf(Sections
, _T("</H3>\n"));
984 SetCurrentOutput(SectionContentsFD
);
985 wxFprintf(SectionContentsFD
, _T("<A HREF=\"#%s\">"), topicName
);
986 OutputCurrentSection();
987 TexOutput(_T("</A><BR>\n"));
989 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
990 SetCurrentOutput(Sections
);
992 // Add this section title to the list of keywords
995 OutputCurrentSectionToString(wxTex2RTFBuffer
);
996 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1003 case ltSUBSUBSECTION
:
1004 case ltSUBSUBSECTIONSTAR
:
1008 if (!Subsections
&& !combineSubSections
)
1010 OnError(_T("You cannot have a subsubsection before a subsection!"));
1014 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1017 startedSections
= true;
1019 wxChar
*topicName
= FindTopicName(GetNextChunk());
1021 if ( !combineSubSections
)
1023 SetCurrentOutput(NULL
);
1024 ReopenFile(&Subsubsections
, &SubsubsectionsName
, topicName
);
1025 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
1026 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
1027 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
1029 SetCurrentOutput(Subsubsections
);
1031 TexOutput(_T("<title>"));
1032 OutputCurrentSection();
1033 TexOutput(_T("</title></head>\n"));
1036 wxFprintf(Subsubsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1038 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
1039 lastTopic
, lastFileName
, // Last topic
1040 topicName
, SubsubsectionsName
); // This topic
1042 SetCurrentOutputs(Subsections
, Subsubsections
);
1043 if(PrimaryAnchorOfTheFile(SubsubsectionsName
, topicName
))
1044 wxFprintf(Subsections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsubsectionsName
));
1046 wxFprintf(Subsections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName
), topicName
);
1048 wxFprintf(Subsubsections
, _T("\n<H3>"));
1049 OutputCurrentSection();
1050 wxFprintf(Subsections
, _T("</B></A><BR>\n"));
1051 wxFprintf(Subsubsections
, _T("</H3>\n"));
1055 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
1056 SetCurrentSubsectionName(topicName
, SectionsName
);
1057 wxFprintf(Sections
, _T("\n<HR>\n"));
1059 // We're putting everything into the section file
1060 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1061 wxFprintf(Sections
, _T("\n<H3>"));
1062 OutputCurrentSection();
1063 wxFprintf(Sections
, _T("</H3>\n"));
1064 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
1065 SetCurrentOutput(SectionContentsFD);
1066 wxFprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
1067 OutputCurrentSection();
1068 TexOutput(_T("</A><BR>"));
1070 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
1071 SetCurrentOutput(Sections
);
1074 // Add this section title to the list of keywords
1077 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1078 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1087 if ( !combineSubSections
)
1088 SetCurrentOutput(Subsections
);
1090 SetCurrentOutput(Sections
);
1101 if ( !combineSubSections
)
1102 SetCurrentOutput(Subsections
);
1104 SetCurrentOutput(Sections
);
1115 if ( !combineSubSections
)
1116 SetCurrentOutput(Subsections
);
1118 SetCurrentOutput(Sections
);
1129 // TexOutput(_T("<B>void</B>"));
1133 TexOutput(_T("HARDY"));
1137 TexOutput(_T("wxCLIPS"));
1141 TexOutput(_T("&"));
1143 case ltSPECIALAMPERSAND
:
1149 // End cell, start cell
1151 TexOutput(_T("</FONT></TD>"));
1153 // Start new row and cell, setting alignment for the first cell.
1154 if (currentColumn
< noColumns
)
1158 if (TableData
[currentColumn
].justification
== 'c')
1159 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=CENTER>"));
1160 else if (TableData
[currentColumn
].justification
== 'r')
1161 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=RIGHT>"));
1162 else if (TableData
[currentColumn
].absWidth
)
1164 // Convert from points * 20 into pixels.
1165 int points
= TableData
[currentColumn
].width
/ 20;
1167 // Say the display is 100 DPI (dots/pixels per inch).
1168 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1169 int pixels
= (int)(points
* 100.0 / 72.0);
1170 wxSnprintf(buf
, sizeof(buf
), _T("<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1173 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=LEFT>"));
1178 TexOutput(_T("&"));
1182 case ltBACKSLASHCHAR
:
1188 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1189 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1190 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1191 TexOutput(_T("</TR>\n"));
1194 TexOutput(_T("<BR>\n"));
1205 // Start new row and cell, setting alignment for the first cell.
1207 if (TableData
[currentColumn
].justification
== 'c')
1208 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER>"));
1209 else if (TableData
[currentColumn
].justification
== 'r')
1210 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=RIGHT>"));
1211 else if (TableData
[currentColumn
].absWidth
)
1213 // Convert from points * 20 into pixels.
1214 int points
= TableData
[currentColumn
].width
/ 20;
1216 // Say the display is 100 DPI (dots/pixels per inch).
1217 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1218 int pixels
= (int)(points
* 100.0 / 72.0);
1219 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1222 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=LEFT>"));
1229 // Start new row and cell
1230 TexOutput(_T("</FONT></TD>\n</TR>\n"));
1234 // HTML-only: break until the end of the picture (both margins are clear).
1238 TexOutput(_T("<BR CLEAR=ALL>"));
1241 case ltRTFSP
: // Explicit space, RTF only
1243 case ltSPECIALTILDE
:
1247 #if (1) // if(inVerbatim)
1258 TexOutput(_T("<UL><UL>\n"));
1260 TexOutput(_T("</UL></UL>\n"));
1266 // case ltTWOCOLLIST:
1273 if (macroId
== ltENUMERATE
)
1274 listType
= LATEX_ENUMERATE
;
1275 else if (macroId
== ltITEMIZE
)
1276 listType
= LATEX_ITEMIZE
;
1278 listType
= LATEX_DESCRIPTION
;
1280 itemizeStack
.Insert(new ItemizeStruc(listType
));
1284 TexOutput(_T("<UL>\n"));
1286 case LATEX_ENUMERATE
:
1287 TexOutput(_T("<OL>\n"));
1289 case LATEX_DESCRIPTION
:
1291 TexOutput(_T("<DL>\n"));
1298 if (itemizeStack
.GetFirst())
1300 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
1301 switch (struc
->listType
)
1304 TexOutput(_T("</UL>\n"));
1306 case LATEX_ENUMERATE
:
1307 TexOutput(_T("</OL>\n"));
1309 case LATEX_DESCRIPTION
:
1311 TexOutput(_T("</DL>\n"));
1316 delete itemizeStack
.GetFirst();
1324 TexOutput(_T("\n<TABLE>\n"));
1326 TexOutput(_T("\n</TABLE>\n"));
1336 TexOutput(_T("<P>\n"));
1339 /* For footnotes we need to output the text at the bottom of the page and
1340 * insert a reference to it. Is it worth the trouble...
1342 case ltFOOTNOTEPOPUP:
1346 TexOutput(_T("<FN>"));
1348 else TexOutput(_T("</FN>"));
1355 TexOutput(_T("<TT>"));
1356 else TexOutput(_T("</TT>"));
1364 wxSnprintf(buf
, sizeof(buf
), _T("<PRE>\n"));
1367 else TexOutput(_T("</PRE>\n"));
1375 TexOutput(_T("<CENTER>"));
1377 else TexOutput(_T("</CENTER>"));
1385 TexOutput(_T("{\\ql "));
1387 else TexOutput(_T("}\\par\\pard\n"));
1396 TexOutput(_T("{\\qr "));
1398 else TexOutput(_T("}\\par\\pard\n"));
1406 // Netscape extension
1407 TexOutput(_T("<FONT SIZE=2>"));
1409 else TexOutput(_T("</FONT>"));
1416 // Netscape extension
1417 TexOutput(_T("<FONT SIZE=1>"));
1419 else TexOutput(_T("</FONT>"));
1426 // Netscape extension
1427 TexOutput(_T("<FONT SIZE=3>"));
1429 else TexOutput(_T("</FONT>"));
1436 // Netscape extension
1437 TexOutput(_T("<FONT SIZE=4>"));
1439 else TexOutput(_T("</FONT>"));
1446 // Netscape extension
1447 TexOutput(_T("<FONT SIZE=5>"));
1449 else TexOutput(_T("</FONT>"));
1456 // Netscape extension
1457 TexOutput(_T("<FONT SIZE=6>"));
1459 else TexOutput(_T("</FONT>"));
1468 TexOutput(_T("<B>"));
1470 else TexOutput(_T("</B>"));
1479 TexOutput(_T("<I>"));
1481 else TexOutput(_T("</I>"));
1489 TexOutput(_T("<EM>"));
1491 else TexOutput(_T("</EM>"));
1498 TexOutput(_T("<UL>"));
1500 else TexOutput(_T("</UL>"));
1509 TexOutput(_T("<TT>"));
1511 else TexOutput(_T("</TT>"));
1517 TexOutput(_T("©"), true);
1523 TexOutput(_T("®"), true);
1529 if (start
) TexOutput(_T("<--"));
1534 if (start
) TexOutput(_T("<=="));
1539 if (start
) TexOutput(_T("-->"));
1544 if (start
) TexOutput(_T("==>"));
1547 case ltLEFTRIGHTARROW
:
1549 if (start
) TexOutput(_T("<-->"));
1552 case ltLEFTRIGHTARROW2
:
1554 if (start
) TexOutput(_T("<==>"));
1567 wxNode
*node
= itemizeStack
.GetFirst();
1570 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
1571 struc
->currentItem
+= 1;
1572 if (struc
->listType
== LATEX_DESCRIPTION
)
1574 if (descriptionItemArg
)
1576 TexOutput(_T("<DT> "));
1577 TraverseChildrenFromChunk(descriptionItemArg
);
1578 TexOutput(_T("\n"));
1579 descriptionItemArg
= NULL
;
1581 TexOutput(_T("<DD>"));
1584 TexOutput(_T("<LI>"));
1591 if (start
&& DocumentTitle
&& DocumentAuthor
)
1593 // Add a special label for the contents page.
1594 // TexOutput(_T("<CENTER>\n"));
1595 TexOutput(_T("<A NAME=\"contents\">"));
1596 TexOutput(_T("<H2 ALIGN=CENTER>\n"));
1597 TraverseChildrenFromChunk(DocumentTitle
);
1598 TexOutput(_T("</H2>"));
1599 TexOutput(_T("<P>"));
1600 TexOutput(_T("</A>\n"));
1601 TexOutput(_T("<P>\n\n"));
1602 TexOutput(_T("<H3 ALIGN=CENTER>"));
1603 TraverseChildrenFromChunk(DocumentAuthor
);
1604 TexOutput(_T("</H3><P>\n\n"));
1607 TexOutput(_T("<H3 ALIGN=CENTER>"));
1608 TraverseChildrenFromChunk(DocumentDate
);
1609 TexOutput(_T("</H3><P>\n\n"));
1611 // TexOutput(_T("\n</CENTER>\n"));
1612 TexOutput(_T("\n<P><HR><P>\n"));
1615 // Now do optional frame contents page
1616 if (htmlFrameContents && FrameContents)
1618 SetCurrentOutput(FrameContents);
1620 // Add a special label for the contents page.
1621 TexOutput(_T("<CENTER>\n"));
1622 TexOutput(_T("<H3>\n"));
1623 TraverseChildrenFromChunk(DocumentTitle);
1624 TexOutput(_T("</H3>"));
1625 TexOutput(_T("<P>"));
1626 TexOutput(_T("</A>\n"));
1627 TexOutput(_T("<P>\n\n"));
1628 TexOutput(_T("<H3>"));
1629 TraverseChildrenFromChunk(DocumentAuthor);
1630 TexOutput(_T("</H3><P>\n\n"));
1633 TexOutput(_T("<H4>"));
1634 TraverseChildrenFromChunk(DocumentDate);
1635 TexOutput(_T("</H4><P>\n\n"));
1637 TexOutput(_T("\n</CENTER>\n"));
1638 TexOutput(_T("<P><HR><P>\n"));
1640 SetCurrentOutput(Titlepage);
1653 helpRefFilename
= NULL
;
1658 case ltBIBLIOGRAPHY
:
1662 DefaultOnMacro(macroId
, no_args
, start
);
1666 DefaultOnMacro(macroId
, no_args
, start
);
1667 TexOutput(_T("</DL>\n"));
1675 TexOutput(_T("<HR>\n"));
1683 TexOutput(_T("<HR>\n"));
1687 case ltTABLEOFCONTENTS
:
1691 // NB: if this is uncommented, the table of contents
1692 // completely disappears. If left commented, it's in the wrong
1694 //fflush(Titlepage);
1696 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1702 wxPutc(ch
, Titlepage
);
1710 TexOutput(_T("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n"));
1711 OnInform(_T("Run Tex2RTF again to include contents page."));
1719 TexOutput(_T("<"));
1725 TexOutput(_T(">"));
1732 TexOutput(_T("<BLOCKQUOTE>"));
1734 TexOutput(_T("</BLOCKQUOTE>"));
1743 TexOutput(_T("\n<CAPTION>"));
1751 if (DocumentStyle
!= LATEX_ARTICLE
)
1752 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1754 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), FigureNameString
, figureNo
);
1760 if (DocumentStyle
!= LATEX_ARTICLE
)
1761 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1763 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), TableNameString
, tableNo
);
1771 TexOutput(_T("\n</CAPTION>\n"));
1773 wxChar
*topicName
= FindTopicName(GetNextChunk());
1775 int n
= inFigure
? figureNo
: tableNo
;
1777 AddTexRef(topicName
, NULL
, NULL
,
1778 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1779 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1785 if (start
) TexOutput(_T("ß"));
1790 if (start
) inFigure
= true;
1791 else inFigure
= false;
1796 if (start
) inTable
= true;
1797 else inTable
= false;
1801 DefaultOnMacro(macroId
, no_args
, start
);
1807 should be called at of argument which usually is
1808 type declaration which propably contains name of
1817 checks: GetArgData() if contains Type Declaration
1818 and can be referenced to some file
1820 before<a href="xxx&yyy">type</a>after
1823 false - if no reference was found
1824 true - if reference was found and HREF printed
1826 static bool CheckTypeRef()
1828 wxString typeDecl
= GetArgData();
1829 if( !typeDecl
.empty() ) {
1830 typeDecl
.Replace(wxT("\\"),wxT(""));
1831 wxString label
= typeDecl
;
1832 label
.Replace(wxT("const"),wxT(""));
1833 label
.Replace(wxT("virtual"),wxT(""));
1834 label
.Replace(wxT("static"),wxT(""));
1835 label
.Replace(wxT("extern"),wxT(""));
1836 label
= label
.BeforeFirst('&');
1837 label
= label
.BeforeFirst(wxT('*'));
1838 label
= label
.BeforeFirst(wxT('\\'));
1839 label
.Trim(true); label
.Trim(false);
1840 wxString typeName
= label
;
1842 TexRef
*texRef
= FindReference((wxChar
*)label
.c_str());
1844 if (texRef
&& texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0) {
1845 int a
= typeDecl
.Find(typeName
);
1846 wxString before
= typeDecl
.Mid( 0, a
);
1847 wxString after
= typeDecl
.Mid( a
+typeName
.Length() );
1848 //wxFprintf(stderr,wxT("%s <%s> %s to ... %s#%s !!!!\n"),
1850 // typeName.c_str(),
1852 // texRef->refFile,label.c_str());
1854 TexOutput(_T("<A HREF=\""));
1855 TexOutput(texRef
->refFile
);
1858 TexOutput(wxT("\">"));
1859 TexOutput(typeName
);
1860 TexOutput(wxT("</A>"));
1864 //wxFprintf(stderr,wxT("'%s' from (%s) -> label %s NOT FOUND\n"),
1865 // typeName.c_str(),
1866 // typeDecl.c_str(),
1873 // Called on start/end of argument examination
1874 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1880 case ltCHAPTERHEADING
:
1883 case ltSECTIONHEADING
:
1885 case ltSUBSECTIONSTAR
:
1886 case ltSUBSUBSECTION
:
1887 case ltSUBSUBSECTIONSTAR
:
1889 case ltMEMBERSECTION
:
1890 case ltFUNCTIONSECTION
:
1892 if (!start
&& (arg_no
== 1))
1893 currentSection
= GetArgChunk();
1898 if (start
&& (arg_no
== 1)) {
1899 TexOutput(_T("<B>"));
1900 if( CheckTypeRef() ) {
1901 TexOutput(_T("</B> "));
1906 if (!start
&& (arg_no
== 1))
1907 TexOutput(_T("</B> "));
1909 if (start
&& (arg_no
== 2))
1911 if (!suppressNameDecoration
) TexOutput(_T("<B>"));
1912 currentMember
= GetArgChunk();
1914 if (!start
&& (arg_no
== 2))
1916 if (!suppressNameDecoration
) TexOutput(_T("</B>"));
1919 if (start
&& (arg_no
== 3))
1921 if (!start
&& (arg_no
== 3))
1927 if (start
&& (arg_no
== 1))
1928 TexOutput(_T("<B>"));
1929 if (!start
&& (arg_no
== 1))
1930 TexOutput(_T("</B> "));
1932 if (start
&& (arg_no
== 2))
1934 if (!suppressNameDecoration
) TexOutput(_T("( "));
1935 currentMember
= GetArgChunk();
1937 if (!start
&& (arg_no
== 2))
1941 if (!start
&& (arg_no
== 3))
1947 if (!start
&& (arg_no
== 1))
1950 if (start
&& (arg_no
== 2))
1951 TexOutput(_T("(*"));
1952 if (!start
&& (arg_no
== 2))
1955 if (start
&& (arg_no
== 2))
1956 currentMember
= GetArgChunk();
1958 if (start
&& (arg_no
== 3))
1960 if (!start
&& (arg_no
== 3))
1967 const wxChar
* pend
= macroId
== ltCPARAM
?
1968 _T("</B> ") : _T("</B>");
1971 TexOutput(_T("<B>"));
1972 if( CheckTypeRef() ) {
1980 if (start
&& (arg_no
== 2))
1982 TexOutput(_T("<I>"));
1984 if (!start
&& (arg_no
== 2))
1986 TexOutput(_T("</I>"));
1992 if (!start
&& (arg_no
== 1))
1995 if (start
&& (arg_no
== 2))
1996 currentMember
= GetArgChunk();
2005 wxChar
*refName
= GetArgData();
2008 TexRef
*texRef
= FindReference(refName
);
2011 sec
= texRef
->sectionNumber
;
2024 if (IsArgOptional())
2026 else if ((GetNoArgs() - arg_no
) == 1)
2029 helpRefText
= GetArgChunk();
2032 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2036 TexChunk
*ref
= GetArgChunk();
2037 TexOutput(_T("<A HREF=\""));
2039 TraverseChildrenFromChunk(ref
);
2041 TexOutput(_T("\">"));
2043 TraverseChildrenFromChunk(helpRefText
);
2044 TexOutput(_T("</A>"));
2055 if (IsArgOptional())
2058 helpRefFilename
= GetArgChunk();
2061 if ((GetNoArgs() - arg_no
) == 1)
2064 helpRefText
= GetArgChunk();
2067 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2071 wxChar
*refName
= GetArgData();
2072 wxChar
*refFilename
= NULL
;
2076 TexRef
*texRef
= FindReference(refName
);
2079 if (texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0)
2080 refFilename
= texRef
->refFile
;
2082 TexOutput(_T("<A HREF=\""));
2083 // If a filename is supplied, use it, otherwise try to
2084 // use the filename associated with the reference (from this document).
2085 if (helpRefFilename
)
2087 TraverseChildrenFromChunk(helpRefFilename
);
2091 else if (refFilename
)
2093 TexOutput(ConvertCase(refFilename
));
2094 if(!PrimaryAnchorOfTheFile(texRef
->refFile
, refName
))
2100 TexOutput(_T("\">"));
2102 TraverseChildrenFromChunk(helpRefText
);
2103 TexOutput(_T("</A>"));
2108 TraverseChildrenFromChunk(helpRefText
);
2110 TexOutput(_T(" (REF NOT FOUND)"));
2112 // for launching twice do not warn in preparation pass
2113 if ((passNumber
== 1 && !runTwice
) ||
2114 (passNumber
== 2 && runTwice
))
2117 errBuf
.Printf(_T("Warning: unresolved reference '%s'"), refName
);
2118 OnInform((wxChar
*)errBuf
.c_str());
2122 else TexOutput(_T("??"));
2137 wxChar
*alignment
= _T("");
2138 if (macroId
== ltIMAGEL
)
2139 alignment
= _T(" align=left");
2140 else if (macroId
== ltIMAGER
)
2141 alignment
= _T(" align=right");
2143 // Try to find an XBM or GIF image first.
2144 wxChar
*filename
= copystring(GetArgData());
2147 wxStrcpy(buf
, filename
);
2148 StripExtension(buf
);
2149 wxStrcat(buf
, _T(".xbm"));
2150 wxString f
= TexPathList
.FindValidPath(buf
);
2152 if (f
== _T("")) // Try for a GIF instead
2154 wxStrcpy(buf
, filename
);
2155 StripExtension(buf
);
2156 wxStrcat(buf
, _T(".gif"));
2157 f
= TexPathList
.FindValidPath(buf
);
2160 if (f
== _T("")) // Try for a JPEG instead
2162 wxStrcpy(buf
, filename
);
2163 StripExtension(buf
);
2164 wxStrcat(buf
, _T(".jpg"));
2165 f
= TexPathList
.FindValidPath(buf
);
2168 if (f
== _T("")) // Try for a PNG instead
2170 wxStrcpy(buf
, filename
);
2171 StripExtension(buf
);
2172 wxStrcat(buf
, _T(".png"));
2173 f
= TexPathList
.FindValidPath(buf
);
2178 wxChar
*inlineFilename
= copystring(f
);
2180 wxChar
*originalFilename
= TexPathList
.FindValidPath(filename
);
2181 // If we have found the existing filename, make the inline
2182 // image point to the original file (could be PS, for example)
2183 if (originalFilename
&& (wxStrcmp(inlineFilename
, originalFilename
) != 0))
2185 TexOutput(_T("<A HREF=\""));
2186 TexOutput(ConvertCase(originalFilename
));
2187 TexOutput(_T("\">"));
2188 TexOutput(_T("<img src=\""));
2189 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2190 TexOutput(_T("\""));
2191 TexOutput(alignment
);
2192 TexOutput(_T("></A>"));
2197 TexOutput(_T("<img src=\""));
2198 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2199 TexOutput(_T("\""));
2200 TexOutput(alignment
);
2202 delete[] inlineFilename
;
2207 // Last resort - a link to a PS file.
2208 TexOutput(_T("<A HREF=\""));
2209 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
2210 TexOutput(_T("\">Picture</A>\n"));
2211 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2218 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2221 static wxChar
*imageFile
= NULL
;
2222 if (start
&& (arg_no
== 2))
2224 // Try to find an XBM or GIF image first.
2225 wxChar
*filename
= copystring(GetArgData());
2228 wxStrcpy(buf
, filename
);
2229 StripExtension(buf
);
2230 wxStrcat(buf
, _T(".xbm"));
2231 wxString f
= TexPathList
.FindValidPath(buf
);
2233 if (f
== _T("")) // Try for a GIF instead
2235 wxStrcpy(buf
, filename
);
2236 StripExtension(buf
);
2237 wxStrcat(buf
, _T(".gif"));
2238 f
= TexPathList
.FindValidPath(buf
);
2243 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2252 imageFile
= copystring(f
);
2255 else if (start
&& (arg_no
== 3))
2259 // First, try to find a .shg (segmented hypergraphics file)
2260 // that we can convert to a map file
2262 wxStrcpy(buf
, imageFile
);
2263 StripExtension(buf
);
2264 wxStrcat(buf
, _T(".shg"));
2265 wxString f
= TexPathList
.FindValidPath(buf
);
2269 // The default HTML file to go to is THIS file (so a no-op)
2270 SHGToMap((wxChar
*)f
.c_str(), currentFileName
);
2273 wxChar
*mapName
= GetArgData();
2274 TexOutput(_T("<A HREF=\"/cgi-bin/imagemap/"));
2278 TexOutput(_T("unknown"));
2279 TexOutput(_T("\">"));
2280 TexOutput(_T("<img src=\""));
2281 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2282 TexOutput(_T("\" ISMAP></A><P>"));
2302 descriptionItemArg
= GetArgChunk();
2308 case ltTWOCOLITEMRULED
:
2311 if (start && (arg_no == 1))
2312 TexOutput(_T("\n<DT> "));
2313 if (start && (arg_no == 2))
2314 TexOutput(_T("<DD> "));
2320 if (TwoColWidthA
> -1)
2323 wxSnprintf(buf
, sizeof(buf
), _T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA
);
2328 TexOutput(_T("\n<TR><TD VALIGN=TOP>\n"));
2332 TexOutput(_T("\n</FONT></TD>\n"));
2339 if (TwoColWidthB
> -1)
2342 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB
);
2347 TexOutput(_T("\n<TD VALIGN=TOP>\n"));
2351 TexOutput(_T("\n</FONT></TD></TR>\n"));
2355 case ltNUMBEREDBIBITEM
:
2357 if (arg_no
== 1 && start
)
2359 TexOutput(_T("\n<DT> "));
2361 if (arg_no
== 2 && !start
)
2362 TexOutput(_T("<P>\n"));
2368 if (arg_no
== 1 && start
)
2370 wxChar
*citeKey
= GetArgData();
2371 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2374 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2375 wxSnprintf(buf
, sizeof(buf
), _T("[%d]"), citeCount
);
2376 ref
->sectionNumber
= copystring(buf
);
2379 wxSnprintf(buf
, sizeof(buf
), _T("\n<DT> [%d] "), citeCount
);
2384 if (arg_no
== 2 && !start
)
2385 TexOutput(_T("<P>\n"));
2389 case ltMARGINPARODD
:
2390 case ltMARGINPAREVEN
:
2396 TexOutput(_T("<HR>\n"));
2400 TexOutput(_T("<HR><P>\n"));
2404 case ltTWOCOLWIDTHA
:
2408 wxChar
*val
= GetArgData();
2409 float points
= ParseUnitArgument(val
);
2410 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2415 case ltTWOCOLWIDTHB
:
2419 wxChar
*val
= GetArgData();
2420 float points
= ParseUnitArgument(val
);
2421 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2429 case ltACCENT_GRAVE
:
2433 wxChar
*val
= GetArgData();
2439 TexOutput(_T("à"));
2442 TexOutput(_T("è"));
2445 TexOutput(_T("ì"));
2448 TexOutput(_T("ò"));
2451 TexOutput(_T("ù"));
2454 TexOutput(_T("À"));
2457 TexOutput(_T("È"));
2460 TexOutput(_T("Ì"));
2463 TexOutput(_T("Ò"));
2466 TexOutput(_T("Ì"));
2475 case ltACCENT_ACUTE
:
2479 wxChar
*val
= GetArgData();
2485 TexOutput(_T("á"));
2488 TexOutput(_T("é"));
2491 TexOutput(_T("í"));
2494 TexOutput(_T("ó"));
2497 TexOutput(_T("ú"));
2500 TexOutput(_T("ý"));
2503 TexOutput(_T("Á"));
2506 TexOutput(_T("É"));
2509 TexOutput(_T("Í"));
2512 TexOutput(_T("Ó"));
2515 TexOutput(_T("Ú"));
2518 TexOutput(_T("Ý"));
2527 case ltACCENT_CARET
:
2531 wxChar
*val
= GetArgData();
2537 TexOutput(_T("â"));
2540 TexOutput(_T("ê"));
2543 TexOutput(_T("î"));
2546 TexOutput(_T("ô"));
2549 TexOutput(_T("û"));
2552 TexOutput(_T("Â"));
2555 TexOutput(_T("Ê"));
2558 TexOutput(_T("Î"));
2561 TexOutput(_T("Ô"));
2564 TexOutput(_T("Î"));
2573 case ltACCENT_TILDE
:
2577 wxChar
*val
= GetArgData();
2586 TexOutput(_T("ã"));
2589 TexOutput(_T("ñ"));
2592 TexOutput(_T("õ"));
2595 TexOutput(_T("Ã"));
2598 TexOutput(_T("Ñ"));
2601 TexOutput(_T("Õ"));
2610 case ltACCENT_UMLAUT
:
2614 wxChar
*val
= GetArgData();
2620 TexOutput(_T("ä"));
2623 TexOutput(_T("ë"));
2626 TexOutput(_T("ï"));
2629 TexOutput(_T("ö"));
2632 TexOutput(_T("ü"));
2635 TexOutput(_T("ÿ"));
2638 TexOutput(_T("Ä"));
2641 TexOutput(_T("Ë"));
2644 TexOutput(_T("Ï"));
2647 TexOutput(_T("Ö"));
2650 TexOutput(_T("Ü"));
2653 TexOutput(_T("Ÿ"));
2666 wxChar
*val
= GetArgData();
2672 TexOutput(_T("å"));
2675 TexOutput(_T("Å"));
2688 wxChar
*val
= GetArgData();
2691 bool isPicture
= false;
2692 ParseColourString(val
, &isPicture
);
2695 if (backgroundImageString
)
2696 delete[] backgroundImageString
;
2697 backgroundImageString
= copystring(val
);
2701 if (backgroundColourString
)
2702 delete[] backgroundColourString
;
2703 backgroundColourString
= copystring(val
);
2709 case ltBACKGROUNDIMAGE
:
2713 wxChar
*val
= GetArgData();
2716 if (backgroundImageString
)
2717 delete[] backgroundImageString
;
2718 backgroundImageString
= copystring(val
);
2723 case ltBACKGROUNDCOLOUR
:
2727 wxChar
*val
= GetArgData();
2730 if (backgroundColourString
)
2731 delete[] backgroundColourString
;
2732 backgroundColourString
= copystring(val
);
2741 wxChar
*val
= GetArgData();
2744 if (textColourString
)
2745 delete[] textColourString
;
2746 textColourString
= copystring(val
);
2755 wxChar
*val
= GetArgData();
2758 if (linkColourString
)
2759 delete[] linkColourString
;
2760 linkColourString
= copystring(val
);
2765 case ltFOLLOWEDLINKCOLOUR
:
2769 wxChar
*val
= GetArgData();
2772 if (followedLinkColourString
)
2773 delete[] followedLinkColourString
;
2774 followedLinkColourString
= copystring(val
);
2779 case ltACCENT_CADILLA
:
2783 wxChar
*val
= GetArgData();
2789 TexOutput(_T("ç"));
2792 TexOutput(_T("Ç"));
2803 case ltFOOTNOTEPOPUP:
2813 case ltSUPERTABULAR
:
2819 currentRowNumber
= 0;
2822 tableVerticalLineLeft
= false;
2823 tableVerticalLineRight
= false;
2825 wxChar
*alignString
= copystring(GetArgData());
2826 ParseTableArgument(alignString
);
2828 TexOutput(_T("<TABLE BORDER>\n"));
2830 // Write the first row formatting for compatibility
2831 // with standard Latex
2832 if (compatibilityMode
)
2834 TexOutput(_T("<TR>\n<TD>"));
2837 for (int i = 0; i < noColumns; i++)
2839 currentWidth += TableData[i].width;
2840 wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth);
2843 TexOutput(_T("\\pard\\intbl\n"));
2846 delete[] alignString
;
2851 else if (arg_no
== 2 && !start
)
2853 TexOutput(_T("</TABLE>\n"));
2858 case ltTHEBIBLIOGRAPHY
:
2860 if (start
&& (arg_no
== 1))
2862 ReopenFile(&Chapters
, &ChaptersName
, _T("bibliography"));
2863 AddTexRef(_T("bibliography"), ChaptersName
, _T("bibliography"));
2864 SetCurrentSubsectionName(_T("bibliography"), ChaptersName
);
2868 SetCurrentOutput(Chapters
);
2870 wxChar titleBuf
[150];
2871 if (truncateFilenames
)
2872 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
2874 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
2877 TexOutput(_T("<title>"));
2878 TexOutput(ReferencesNameString
);
2879 TexOutput(_T("</title></head>\n"));
2882 wxFprintf(Chapters
, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString
);
2883 AddBrowseButtons(_T("contents"), titleBuf
, // Up
2884 lastTopic
, lastFileName
, // Last topic
2885 _T("bibliography"), ChaptersName
); // This topic
2887 SetCurrentOutputs(Contents
, Chapters
);
2888 if(PrimaryAnchorOfTheFile(ChaptersName
, _T("bibliography")))
2889 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
2891 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), _T("bibliography"));
2893 wxFprintf(Contents
, _T("%s</A>\n"), ReferencesNameString
);
2894 wxFprintf(Chapters
, _T("</H2>\n</A>\n"));
2896 SetCurrentOutput(Chapters
);
2899 if (!start
&& (arg_no
== 2))
2906 /* Build up list of keywords associated with topics */
2909 // wxChar *entry = GetArgData();
2911 OutputChunkToString(GetArgChunk(), buf
);
2914 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2928 wxChar
*name
= GetArgData();
2930 if (!FindColourHTMLString(name
, buf2
))
2932 wxStrcpy(buf2
, _T("#000000"));
2934 wxSnprintf(buf
, sizeof(buf
), _T("Could not find colour name %s"), name
);
2937 TexOutput(_T("<FONT COLOR=\""));
2939 TexOutput(_T("\">"));
2952 if (arg_no
== 2) TexOutput(_T("</FONT>"));
2956 case ltINSERTATLEVEL
:
2958 // This macro allows you to insert text at a different level
2959 // from the current level, e.g. into the Sections from within a subsubsection.
2962 static int currentLevelNo
= 1;
2963 static FILE* oldLevelFile
= Chapters
;
2970 oldLevelFile
= CurrentOutput1
;
2972 wxChar
*str
= GetArgData();
2973 currentLevelNo
= wxAtoi(str
);
2975 // TODO: cope with article style (no chapters)
2976 switch (currentLevelNo
)
2980 outputFile
= Chapters
;
2985 outputFile
= Sections
;
2990 outputFile
= Subsections
;
2995 outputFile
= Subsubsections
;
3005 CurrentOutput1
= outputFile
;
3021 CurrentOutput1
= oldLevelFile
;
3027 return DefaultOnArgument(macroId
, arg_no
, start
);
3039 tableVerticalLineLeft
= false;
3040 tableVerticalLineRight
= false;
3043 if (!InputFile
.empty() && !OutputFile
.empty())
3045 // Do some HTML-specific transformations on all the strings,
3047 Text2HTML(GetTopLevelChunk());
3050 if (truncateFilenames
)
3051 wxSnprintf(buf
, sizeof(buf
), _T("%s.htm"), FileRoot
);
3053 wxSnprintf(buf
, sizeof(buf
), _T("%s_contents.html"), FileRoot
);
3054 if (TitlepageName
) delete[] TitlepageName
;
3055 TitlepageName
= copystring(buf
);
3056 Titlepage
= wxFopen(buf
, _T("w"));
3058 if (truncateFilenames
)
3059 wxSnprintf(buf
, sizeof(buf
), _T("%s_fc.htm"), FileRoot
);
3061 wxSnprintf(buf
, sizeof(buf
), _T("%s_fcontents.html"), FileRoot
);
3063 contentsFrameName
= copystring(buf
);
3065 Contents
= wxFopen(TmpContentsName
, _T("w"));
3067 if (htmlFrameContents
)
3069 // FrameContents = wxFopen(TmpFrameContentsName, _T("w"));
3070 FrameContents
= wxFopen(contentsFrameName
, _T("w"));
3071 wxFprintf(FrameContents
, _T("<HTML>\n<UL>\n"));
3074 if (!Titlepage
|| !Contents
)
3076 OnError(_T("Cannot open output file!"));
3079 AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName
), ContentsNameString
);
3081 wxFprintf(Contents
, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString
);
3083 wxFprintf(Contents
, _T("<UL>\n"));
3085 SetCurrentOutput(Titlepage
);
3086 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
3087 OnInform(_T("Converting..."));
3090 wxFprintf(Contents
, _T("</UL>\n\n"));
3092 // SetCurrentOutput(Titlepage);
3097 // wxFprintf(Titlepage, _T("\n</BODY></HTML>\n"));
3104 wxFprintf(FrameContents
, _T("\n</UL>\n"));
3105 wxFprintf(FrameContents
, _T("</HTML>\n"));
3106 fclose(FrameContents
);
3107 FrameContents
= NULL
;
3112 wxFprintf(Chapters
, _T("\n</FONT></BODY></HTML>\n"));
3118 wxFprintf(Sections
, _T("\n</FONT></BODY></HTML>\n"));
3122 if (Subsections
&& !combineSubSections
)
3124 wxFprintf(Subsections
, _T("\n</FONT></BODY></HTML>\n"));
3125 fclose(Subsections
);
3128 if (Subsubsections
&& !combineSubSections
)
3130 wxFprintf(Subsubsections
, _T("\n</FONT></BODY></HTML>\n"));
3131 fclose(Subsubsections
);
3132 Subsubsections
= NULL
;
3134 if ( SectionContentsFD
)
3136 fclose(SectionContentsFD
);
3137 SectionContentsFD
= NULL
;
3140 // Create a temporary file for the title page header, add some info,
3141 // and concat the titlepage just generated.
3142 // This is necessary in order to put the title of the document
3143 // at the TOP of the file within <HEAD>, even though we only find out
3144 // what it is later on.
3145 FILE *tmpTitle
= wxFopen(_T("title.tmp"), _T("w"));
3150 SetCurrentOutput(tmpTitle
);
3152 TexOutput(_T("\n<TITLE>"));
3153 TraverseChildrenFromChunk(DocumentTitle
);
3154 TexOutput(_T("</TITLE></HEAD>\n"));
3158 SetCurrentOutput(tmpTitle
);
3159 HTMLHeadTo(tmpTitle
);
3161 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), contentsString
);
3163 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), wxFileNameFromPath(FileRoot
));
3166 // Output frame information
3167 if (htmlFrameContents
)
3169 wxChar firstFileName
[300];
3170 if (truncateFilenames
)
3171 wxSnprintf(firstFileName
, sizeof(firstFileName
), _T("%s1.htm"), FileRoot
);
3173 wxStrcpy(firstFileName
, gs_filenames
[1].c_str());
3175 wxFprintf(tmpTitle
, _T("<FRAMESET COLS=\"30%%,70%%\">\n"));
3177 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName
)));
3178 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName
)));
3179 wxFprintf(tmpTitle
, _T("</FRAMESET>\n"));
3181 wxFprintf(tmpTitle
, _T("<NOFRAMES>\n"));
3184 // Output <BODY...> to temporary title page
3189 FILE *fd
= wxFopen(TitlepageName
, _T("r"));
3195 wxPutc(ch
, tmpTitle
);
3201 wxFprintf(tmpTitle
, _T("\n</FONT></BODY>\n"));
3203 if (htmlFrameContents
)
3205 wxFprintf(tmpTitle
, _T("\n</NOFRAMES>\n"));
3207 wxFprintf(tmpTitle
, _T("\n</HTML>\n"));
3210 if (wxFileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3211 if (!wxRenameFile(_T("title.tmp"), TitlepageName
))
3213 wxCopyFile(_T("title.tmp"), TitlepageName
);
3214 wxRemoveFile(_T("title.tmp"));
3218 if (lastFileName
) delete[] lastFileName
;
3219 lastFileName
= NULL
;
3220 if (lastTopic
) delete[] lastTopic
;
3223 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3225 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3227 wxCopyFile(TmpContentsName
, ContentsName
);
3228 wxRemoveFile(TmpContentsName
);
3231 // Generate .htx file if requested
3234 wxChar htmlIndexName
[300];
3235 wxSnprintf(htmlIndexName
, sizeof(htmlIndexName
), _T("%s.htx"), FileRoot
);
3236 GenerateHTMLIndexFile(htmlIndexName
);
3239 // Generate HTML Help Workshop files if requested
3240 if (htmlWorkshopFiles
)
3242 HTMLWorkshopEndContents();
3243 GenerateHTMLWorkshopFiles(FileRoot
);
3252 // Output .htx index file
3253 void GenerateHTMLIndexFile(wxChar
*fname
)
3255 FILE *fd
= wxFopen(fname
, _T("w"));
3259 TopicTable
.BeginFind();
3260 wxHashTable::Node
*node
= TopicTable
.Next();
3263 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3264 const wxChar
*topicName
= node
->GetKeyString();
3265 if (texTopic
->filename
&& texTopic
->keywords
)
3267 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3270 wxChar
*s
= (wxChar
*)node1
->GetData();
3271 wxFprintf(fd
, _T("%s|%s|%s\n"), topicName
, texTopic
->filename
, s
);
3272 node1
= node1
->GetNext();
3275 node
= TopicTable
.Next();
3286 // output .hpp, .hhc and .hhk files:
3289 void GenerateHTMLWorkshopFiles(wxChar
*fname
)
3294 /* Generate project file : */
3296 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhp"), fname
);
3297 f
= wxFopen(buf
, _T("wt"));
3300 _T("Compatibility=1.1\n")
3301 _T("Full-text search=Yes\n")
3302 _T("Contents file=%s.hhc\n")
3303 _T("Compiled file=%s.chm\n")
3304 _T("Default Window=%sHelp\n")
3305 _T("Default topic=%s\n")
3306 _T("Index file=%s.hhk\n")
3308 wxFileNameFromPath(fname
),
3309 wxFileNameFromPath(fname
),
3310 wxFileNameFromPath(fname
),
3311 wxFileNameFromPath(TitlepageName
),
3312 wxFileNameFromPath(fname
)
3315 if (DocumentTitle
) {
3316 SetCurrentOutput(f
);
3317 TraverseChildrenFromChunk(DocumentTitle
);
3319 else wxFprintf(f
, _T("(unknown)"));
3321 wxFprintf(f
, _T("\n\n[WINDOWS]\n")
3322 _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"),
3323 wxFileNameFromPath(fname
),
3324 wxFileNameFromPath(fname
),
3325 wxFileNameFromPath(fname
),
3326 wxFileNameFromPath(TitlepageName
));
3329 wxFprintf(f
, _T("\n\n[FILES]\n"));
3330 wxFprintf(f
, _T("%s\n"), wxFileNameFromPath(TitlepageName
));
3331 for (int i
= 1; i
<= fileId
; i
++) {
3332 if (truncateFilenames
)
3333 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), wxFileNameFromPath(FileRoot
), i
);
3335 wxStrcpy(buf
, wxFileNameFromPath(gs_filenames
[i
].c_str()));
3336 wxFprintf(f
, _T("%s\n"), buf
);
3340 /* Generate index file : */
3342 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhk"), fname
);
3343 f
= wxFopen(buf
, _T("wt"));
3346 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3351 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3352 _T("<!-- Sitemap 1.0 -->\n")
3353 _T("</HEAD><BODY>\n")
3354 _T("<OBJECT type=\"text/site properties\">\n")
3355 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3359 TopicTable
.BeginFind();
3360 wxHashTable::Node
*node
= TopicTable
.Next();
3363 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3364 const wxChar
*topicName
= node
->GetKeyString();
3365 if (texTopic
->filename
&& texTopic
->keywords
)
3367 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3370 wxChar
*s
= (wxChar
*)node1
->GetData();
3372 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3373 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3374 _T(" <param name=\"Name\" value=\"%s\">\n")
3376 texTopic
->filename
, topicName
, s
);
3377 node1
= node1
->GetNext();
3380 node
= TopicTable
.Next();
3383 wxFprintf(f
, _T("</UL>\n"));
3389 static FILE *HTMLWorkshopContents
= NULL
;
3390 static int HTMLWorkshopLastLevel
= 0;
3392 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
)
3396 if (level
> HTMLWorkshopLastLevel
)
3397 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3398 wxFprintf(HTMLWorkshopContents
, _T("<UL>"));
3399 if (level
< HTMLWorkshopLastLevel
)
3400 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3401 wxFprintf(HTMLWorkshopContents
, _T("</UL>"));
3403 SetCurrentOutput(HTMLWorkshopContents
);
3404 wxFprintf(HTMLWorkshopContents
,
3405 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3406 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3407 _T(" <param name=\"Name\" value=\""),
3409 OutputCurrentSection();
3410 wxFprintf(HTMLWorkshopContents
,
3412 _T(" </OBJECT>\n"));
3413 HTMLWorkshopLastLevel
= level
;
3417 void HTMLWorkshopStartContents()
3420 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhc"), FileRoot
);
3421 HTMLWorkshopContents
= wxFopen(buf
, _T("wt"));
3422 HTMLWorkshopLastLevel
= 0;
3424 wxFprintf(HTMLWorkshopContents
,
3425 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3427 HTMLHeadTo(HTMLWorkshopContents
);
3428 wxFprintf(HTMLWorkshopContents
,
3430 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3431 _T("<!-- Sitemap 1.0 -->\n")
3432 _T("</HEAD><BODY>\n")
3433 _T("<OBJECT type=\"text/site properties\">\n")
3434 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3437 _T("<LI> <OBJECT type=\"text/sitemap\">\n")
3438 _T("<param name=\"Local\" value=\"%s\">\n")
3439 _T("<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n"),
3440 wxFileNameFromPath(TitlepageName
)
3446 void HTMLWorkshopEndContents()
3448 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3449 wxFprintf(HTMLWorkshopContents
, _T("</UL>\n"));
3450 fclose(HTMLWorkshopContents
);
3454 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
)
3456 wxString file_label
;
3457 file_label
.Printf( HTML_FILENAME_PATTERN
, FileRoot
, label
);
3458 return file_label
.IsSameAs( file
, false );