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"));
259 #define tr(x,y) {x, sizeof(x)-1, y, sizeof(y)-1}
261 static textreplace notverb_array
[] =
263 tr(_T("\r\n\r\n"), _T("<P>\n\n")), // unix
264 tr(_T("\n\n"), _T("<P>\n\n")), // dos
265 tr(_T("\r\r"), _T("<P>\n\n")), // mac
266 tr(_T("``"), _T("“")),
267 tr(_T("''"), _T("”")),
268 tr(_T("`"), _T("‘")),
269 tr(_T("'"), _T("’")),
270 tr(_T("---"), _T("—")),
271 tr(_T("--"), _T("–")),
277 * Given a TexChunk with a string value, scans through the string
278 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
282 void ProcessText2HTML(TexChunk
*chunk
)
284 bool changed
= false;
288 int len
= wxStrlen(chunk
->value
);
291 ch
= chunk
->value
[i
];
293 if (ch
== _T('<')) // Change < to <
296 wxStrcat(BigBuffer
, _T("<"));
302 else if (ch
== _T('>')) // Change > to >
305 wxStrcat(BigBuffer
, _T(">"));
313 bool replaced
= false;
317 for (x
= 0; x
< sizeof (notverb_array
) / sizeof(textreplace
); x
++)
319 textreplace
& tr
= notverb_array
[x
];
320 if (ch
!= tr
.text
[0]) continue;
321 if (len
< tr
.text_length
) continue;
323 for (y
= 1; y
< tr
.text_length
; y
++)
325 if (chunk
->value
[y
] != tr
.text
[y
]) break;
327 if (y
!= tr
.text_length
) continue;
329 // can now copy it over.
330 for (y
= 0; y
< tr
.replace_length
; y
++)
332 BigBuffer
[ptr
++] = tr
.replace
[y
];
334 len
-= tr
.text_length
;
356 chunk
->value
= copystring(BigBuffer
);
361 * Scan through all chunks starting from the given one,
362 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
363 * This should be called after Tex2Any has parsed the file,
364 * and before TraverseDocument is called.
368 void Text2HTML(TexChunk
*chunk
)
371 if (stopRunning
) return;
375 case CHUNK_TYPE_MACRO
:
377 TexMacroDef
*def
= chunk
->def
;
379 if (def
&& def
->ignore
)
382 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
385 wxNode
*node
= chunk
->children
.GetFirst();
388 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
389 Text2HTML(child_chunk
);
390 node
= node
->GetNext();
393 if (def
&& (def
->macroId
== ltVERBATIM
|| def
->macroId
== ltVERB
|| def
->macroId
== ltSPECIAL
))
400 wxNode
*node
= chunk
->children
.GetFirst();
403 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
404 Text2HTML(child_chunk
);
405 node
= node
->GetNext();
410 case CHUNK_TYPE_STRING
:
413 ProcessText2HTML(chunk
);
420 * Add appropriate browse buttons to this page.
424 void AddBrowseButtons(wxChar
*upLabel
, wxChar
*upFilename
,
425 wxChar
*previousLabel
, wxChar
*previousFilename
,
426 wxChar
*thisLabel
, wxChar
*thisFilename
)
428 wxChar contentsReferenceBuf
[80];
429 wxChar upReferenceBuf
[80];
430 wxChar backReferenceBuf
[80];
431 wxChar forwardReferenceBuf
[80];
432 if (htmlBrowseButtons
== HTML_BUTTONS_NONE
)
435 wxChar
*contentsReference
; // no need to initialize because always assigned below
436 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
437 contentsReference
= ContentsNameString
;
440 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
441 contentsReference
= contentsReferenceBuf
;
442 wxSnprintf(contentsReference
, sizeof(contentsReferenceBuf
),
443 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">"),
444 ConvertCase(_T("contents.gif")));
447 wxChar
*upReference
; // no need to initialize because always assigned below
448 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
449 upReference
= UpNameString
;
452 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
453 upReference
= upReferenceBuf
;
454 wxSnprintf(upReference
, sizeof(upReferenceBuf
),
455 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">"),
456 ConvertCase(_T("up.gif")));
459 wxChar
*backReference
; // no need to initialize because always assigned below
460 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
461 backReference
= _T("<<");
464 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
465 backReference
= backReferenceBuf
;
466 wxSnprintf(backReference
, sizeof(backReferenceBuf
),
467 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">"),
468 ConvertCase(_T("back.gif")));
471 wxChar
*forwardReference
; // no need to initialize because always assigned below
472 if (htmlBrowseButtons
== HTML_BUTTONS_TEXT
)
473 forwardReference
= _T(">>");
476 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
477 forwardReference
= forwardReferenceBuf
;
478 wxSnprintf(forwardReference
, sizeof(forwardReferenceBuf
),
479 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">"),
480 ConvertCase(_T("forward.gif")));
483 TexOutput(_T("<CENTER>"));
492 if (truncateFilenames
)
495 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
496 wxSnprintf(buf
, sizeof(buf
),
497 _T("\n<A HREF=\"%s.%s\">%s</A> "),
498 buf1
, ConvertCase(_T("htm")), contentsReference
);
503 wxStrcpy(buf1
, ConvertCase(wxFileNameFromPath(FileRoot
)));
504 wxSnprintf(buf
, sizeof(buf
),
505 _T("\n<A HREF=\"%s%s\">%s</A> "),
506 buf1
, ConvertCase(_T("_contents.html")), contentsReference
);
508 // TexOutput(_T("<NOFRAMES>"));
510 // TexOutput(_T("</NOFRAMES>"));
517 if (upLabel
&& upFilename
)
519 if ( (wxStrlen(upLabel
) > 0) && !PrimaryAnchorOfTheFile(upFilename
, upLabel
) )
520 wxSnprintf(buf
, sizeof(buf
),
521 _T("<A HREF=\"%s#%s\">%s</A> "),
522 ConvertCase(upFilename
), upLabel
, upReference
);
524 wxSnprintf(buf
, sizeof(buf
),
525 _T("<A HREF=\"%s\">%s</A> "),
526 ConvertCase(upFilename
), upReference
);
527 if (wxStrcmp(upLabel
, _T("contents")) == 0)
529 // TexOutput(_T("<NOFRAMES>"));
531 // TexOutput(_T("</NOFRAMES>"));
542 if (previousLabel
&& previousFilename
)
544 if (PrimaryAnchorOfTheFile(previousFilename
, previousLabel
))
545 wxSnprintf(buf
, sizeof(buf
),
546 _T("<A HREF=\"%s\">%s</A> "),
547 ConvertCase(previousFilename
), backReference
);
549 wxSnprintf(buf
, sizeof(buf
),
550 _T("<A HREF=\"%s#%s\">%s</A> "),
551 ConvertCase(previousFilename
), previousLabel
, backReference
);
552 if (wxStrcmp(previousLabel
, _T("contents")) == 0)
554 // TexOutput(_T("<NOFRAMES>"));
556 // TexOutput(_T("</NOFRAMES>"));
563 // A placeholder so the buttons don't keep moving position
564 wxSnprintf(buf
, sizeof(buf
), _T("%s "), backReference
);
568 wxChar
*nextLabel
= NULL
;
569 wxChar
*nextFilename
= NULL
;
571 // Get the next page, and record the previous page's 'next' page
573 TexNextPage
*nextPage
= (TexNextPage
*)TexNextPages
.Get(thisLabel
);
576 nextLabel
= nextPage
->label
;
577 nextFilename
= nextPage
->filename
;
579 if (previousLabel
&& previousFilename
)
581 TexNextPage
*oldNextPage
= (TexNextPage
*)TexNextPages
.Get(previousLabel
);
585 TexNextPages
.Delete(previousLabel
);
587 TexNextPage
*newNextPage
= new TexNextPage(thisLabel
, thisFilename
);
588 TexNextPages
.Put(previousLabel
, newNextPage
);
596 if (nextLabel
&& nextFilename
)
598 if (PrimaryAnchorOfTheFile(nextFilename
, nextLabel
))
599 wxSnprintf(buf
, sizeof(buf
),
600 _T("<A HREF=\"%s\">%s</A> "),
601 ConvertCase(nextFilename
), forwardReference
);
603 wxSnprintf(buf
, sizeof(buf
),
604 _T("<A HREF=\"%s#%s\">%s</A> "),
605 ConvertCase(nextFilename
), nextLabel
, forwardReference
);
610 // A placeholder so the buttons don't keep moving position
611 wxSnprintf(buf
, sizeof(buf
), _T("%s "), forwardReference
);
616 * Horizontal rule to finish it off nicely.
619 TexOutput(_T("</CENTER>"));
620 TexOutput(_T("<HR>\n"));
622 // Update last topic/filename
624 delete[] lastFileName
;
625 lastFileName
= copystring(thisFilename
);
628 lastTopic
= copystring(thisLabel
);
631 // A colour string is either 3 numbers separated by semicolons (RGB),
632 // or a reference to a GIF. Return the filename or a hex string like #934CE8
633 wxChar
*ParseColourString(wxChar
*bkStr
, bool *isPicture
)
635 static wxChar resStr
[300];
636 wxStrcpy(resStr
, bkStr
);
637 wxStringTokenizer
tok(resStr
, _T(";"), wxTOKEN_STRTOK
);
638 if (tok
.HasMoreTokens())
640 wxString token1
= tok
.GetNextToken();
641 if (!tok
.HasMoreTokens())
648 wxString token2
= tok
.GetNextToken();
650 if (tok
.HasMoreTokens())
652 wxString token3
= tok
.GetNextToken();
654 // Now convert 3 strings into decimal numbers, and then hex numbers.
655 int red
= wxAtoi(token1
.c_str());
656 int green
= wxAtoi(token2
.c_str());
657 int blue
= wxAtoi(token3
.c_str());
659 wxStrcpy(resStr
, _T("#"));
663 wxStrcat(resStr
, buf
);
664 DecToHex(green
, buf
);
665 wxStrcat(resStr
, buf
);
667 wxStrcat(resStr
, buf
);
676 void OutputFont(void)
678 // Only output <font face> if explicitly requested by htmlFaceName= directive in
679 // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's
683 // Output <FONT FACE=...>
684 TexOutput(_T("<FONT FACE=\""));
685 TexOutput(htmlFaceName
);
686 TexOutput(_T("\">\n"));
690 // Output start of <BODY> block
691 void OutputBodyStart(void)
693 TexOutput(_T("\n<BODY"));
694 if (backgroundImageString
)
696 bool isPicture
= false;
697 wxChar
*s
= ParseColourString(backgroundImageString
, &isPicture
);
700 TexOutput(_T(" BACKGROUND=\""));
705 if (backgroundColourString
)
707 bool isPicture
= false;
708 wxChar
*s
= ParseColourString(backgroundColourString
, &isPicture
);
711 TexOutput(_T(" BGCOLOR="));
716 // Set foreground text colour, if one is specified
717 if (textColourString
)
719 bool isPicture
= false;
720 wxChar
*s
= ParseColourString(textColourString
, &isPicture
);
723 TexOutput(_T(" TEXT=")); TexOutput(s
);
726 // Set link text colour, if one is specified
727 if (linkColourString
)
729 bool isPicture
= false;
730 wxChar
*s
= ParseColourString(linkColourString
, &isPicture
);
733 TexOutput(_T(" LINK=")); TexOutput(s
);
736 // Set followed link text colour, if one is specified
737 if (followedLinkColourString
)
739 bool isPicture
= false;
740 wxChar
*s
= ParseColourString(followedLinkColourString
, &isPicture
);
743 TexOutput(_T(" VLINK=")); TexOutput(s
);
746 TexOutput(_T(">\n"));
753 TexOutput(_T("<head>"));
754 if (htmlStylesheet
) {
755 TexOutput(_T("<link rel=stylesheet type=\"text/css\" href=\""));
756 TexOutput(htmlStylesheet
);
757 TexOutput(_T("\">"));
761 void HTMLHeadTo(FILE* f
)
764 wxFprintf(f
,_T("<head><link rel=stylesheet type=\"text/css\" href=\"%s\">"),htmlStylesheet
);
766 wxFprintf(f
,_T("<head>"));
769 // Called on start/end of macro examination
770 void HTMLOnMacro(int macroId
, int no_args
, bool start
)
776 case ltCHAPTERHEADING
:
784 if (macroId
!= ltCHAPTERSTAR
)
787 SetCurrentOutput(NULL
);
788 startedSections
= true;
790 wxChar
*topicName
= FindTopicName(GetNextChunk());
791 ReopenFile(&Chapters
, &ChaptersName
, topicName
);
792 AddTexRef(topicName
, ChaptersName
, ChapterNameString
);
794 SetCurrentChapterName(topicName
, ChaptersName
);
795 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(0, topicName
, ChaptersName
);
797 SetCurrentOutput(Chapters
);
800 TexOutput(_T("<title>"));
801 OutputCurrentSection(); // Repeat section header
802 TexOutput(_T("</title></head>\n"));
805 wxChar titleBuf
[200];
806 if (truncateFilenames
)
807 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
809 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
811 wxFprintf(Chapters
, _T("<A NAME=\"%s\"></A>"), topicName
);
813 AddBrowseButtons(_T(""), titleBuf
, // Up
814 lastTopic
, lastFileName
, // Last topic
815 topicName
, ChaptersName
); // This topic
817 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
818 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
820 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), topicName
);
822 if (htmlFrameContents
&& FrameContents
)
824 SetCurrentOutput(FrameContents
);
825 if(PrimaryAnchorOfTheFile(ChaptersName
, topicName
))
826 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
));
828 wxFprintf(FrameContents
, _T("\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName
), topicName
);
829 OutputCurrentSection();
830 wxFprintf(FrameContents
, _T("</A>\n"));
833 SetCurrentOutputs(Contents
, Chapters
);
834 wxFprintf(Chapters
, _T("\n<H2>"));
835 OutputCurrentSection();
836 wxFprintf(Contents
, _T("</A>\n"));
837 wxFprintf(Chapters
, _T("</H2>\n"));
839 SetCurrentOutput(Chapters
);
841 // Add this section title to the list of keywords
844 OutputCurrentSectionToString(wxTex2RTFBuffer
);
845 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, ConvertCase(currentFileName
));
852 case ltSECTIONHEADING
:
859 subsectionStarted
= false;
861 if (macroId
!= ltSECTIONSTAR
)
864 SetCurrentOutput(NULL
);
865 startedSections
= true;
867 wxChar
*topicName
= FindTopicName(GetNextChunk());
868 ReopenFile(&Sections
, &SectionsName
, topicName
);
869 AddTexRef(topicName
, SectionsName
, SectionNameString
);
871 SetCurrentSectionName(topicName
, SectionsName
);
872 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(1, topicName
, SectionsName
);
874 SetCurrentOutput(Sections
);
876 TexOutput(_T("<title>"));
877 OutputCurrentSection();
878 TexOutput(_T("</title></head>\n"));
881 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
882 AddBrowseButtons(CurrentChapterName
, CurrentChapterFile
, // Up
883 lastTopic
, lastFileName
, // Last topic
884 topicName
, SectionsName
); // This topic
886 FILE *jumpFrom
= ((DocumentStyle
== LATEX_ARTICLE
) ? Contents
: Chapters
);
888 SetCurrentOutputs(jumpFrom
, Sections
);
889 if (DocumentStyle
== LATEX_ARTICLE
)
891 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
892 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(SectionsName
));
894 wxFprintf(jumpFrom
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(SectionsName
), topicName
);
898 if(PrimaryAnchorOfTheFile(SectionsName
, topicName
))
899 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SectionsName
));
901 wxFprintf(jumpFrom
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SectionsName
), topicName
);
904 wxFprintf(Sections
, _T("\n<H2>"));
905 OutputCurrentSection();
907 if (DocumentStyle
== LATEX_ARTICLE
)
908 wxFprintf(jumpFrom
, _T("</A>\n"));
910 wxFprintf(jumpFrom
, _T("</B></A><BR>\n"));
911 wxFprintf(Sections
, _T("</H2>\n"));
913 SetCurrentOutput(Sections
);
914 // Add this section title to the list of keywords
917 OutputCurrentSectionToString(wxTex2RTFBuffer
);
918 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
924 case ltSUBSECTIONSTAR
:
925 case ltMEMBERSECTION
:
926 case ltFUNCTIONSECTION
:
932 OnError(_T("You cannot have a subsection before a section!"));
938 if (macroId
!= ltSUBSECTIONSTAR
)
941 if ( combineSubSections
&& !subsectionStarted
)
945 // Read old .con file in at this point
947 wxStrcpy(buf
, CurrentSectionFile
);
948 wxStripExtension(buf
);
949 wxStrcat(buf
, _T(".con"));
950 FILE *fd
= wxFopen(buf
, _T("r"));
956 wxPutc(ch
, Sections
);
961 wxFprintf(Sections
, _T("<P>\n"));
963 // Close old file, create a new file for the sub(sub)section contents entries
964 ReopenSectionContentsFile();
967 startedSections
= true;
968 subsectionStarted
= true;
970 wxChar
*topicName
= FindTopicName(GetNextChunk());
972 if ( !combineSubSections
)
974 SetCurrentOutput(NULL
);
975 ReopenFile(&Subsections
, &SubsectionsName
, topicName
);
976 AddTexRef(topicName
, SubsectionsName
, SubsectionNameString
);
977 SetCurrentSubsectionName(topicName
, SubsectionsName
);
978 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SubsectionsName
);
979 SetCurrentOutput(Subsections
);
982 TexOutput(_T("<title>"));
983 OutputCurrentSection();
984 TexOutput(_T("</title></head>\n"));
987 wxFprintf(Subsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
988 AddBrowseButtons(CurrentSectionName
, CurrentSectionFile
, // Up
989 lastTopic
, lastFileName
, // Last topic
990 topicName
, SubsectionsName
); // This topic
992 SetCurrentOutputs(Sections
, Subsections
);
993 if(PrimaryAnchorOfTheFile(SubsectionsName
, topicName
))
994 wxFprintf(Sections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsectionsName
));
996 wxFprintf(Sections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName
), topicName
);
998 wxFprintf(Subsections
, _T("\n<H3>"));
999 OutputCurrentSection();
1000 wxFprintf(Sections
, _T("</B></A><BR>\n"));
1001 wxFprintf(Subsections
, _T("</H3>\n"));
1003 SetCurrentOutput(Subsections
);
1007 AddTexRef(topicName
, SectionsName
, SubsectionNameString
);
1008 SetCurrentSubsectionName(topicName
, SectionsName
);
1010 // if ( subsectionNo != 0 )
1011 wxFprintf(Sections
, _T("\n<HR>\n"));
1013 // We're putting everything into the section file
1014 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1015 wxFprintf(Sections
, _T("\n<H3>"));
1016 OutputCurrentSection();
1017 wxFprintf(Sections
, _T("</H3>\n"));
1019 SetCurrentOutput(SectionContentsFD
);
1020 wxFprintf(SectionContentsFD
, _T("<A HREF=\"#%s\">"), topicName
);
1021 OutputCurrentSection();
1022 TexOutput(_T("</A><BR>\n"));
1024 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
1025 SetCurrentOutput(Sections
);
1027 // Add this section title to the list of keywords
1030 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1031 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1038 case ltSUBSUBSECTION
:
1039 case ltSUBSUBSECTIONSTAR
:
1043 if (!Subsections
&& !combineSubSections
)
1045 OnError(_T("You cannot have a subsubsection before a subsection!"));
1049 if (macroId
!= ltSUBSUBSECTIONSTAR
)
1052 startedSections
= true;
1054 wxChar
*topicName
= FindTopicName(GetNextChunk());
1056 if ( !combineSubSections
)
1058 SetCurrentOutput(NULL
);
1059 ReopenFile(&Subsubsections
, &SubsubsectionsName
, topicName
);
1060 AddTexRef(topicName
, SubsubsectionsName
, SubsubsectionNameString
);
1061 SetCurrentSubsubsectionName(topicName
, SubsubsectionsName
);
1062 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(3, topicName
, SubsubsectionsName
);
1064 SetCurrentOutput(Subsubsections
);
1066 TexOutput(_T("<title>"));
1067 OutputCurrentSection();
1068 TexOutput(_T("</title></head>\n"));
1071 wxFprintf(Subsubsections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1073 AddBrowseButtons(CurrentSubsectionName
, CurrentSubsectionFile
, // Up
1074 lastTopic
, lastFileName
, // Last topic
1075 topicName
, SubsubsectionsName
); // This topic
1077 SetCurrentOutputs(Subsections
, Subsubsections
);
1078 if(PrimaryAnchorOfTheFile(SubsubsectionsName
, topicName
))
1079 wxFprintf(Subsections
, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsubsectionsName
));
1081 wxFprintf(Subsections
, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName
), topicName
);
1083 wxFprintf(Subsubsections
, _T("\n<H3>"));
1084 OutputCurrentSection();
1085 wxFprintf(Subsections
, _T("</B></A><BR>\n"));
1086 wxFprintf(Subsubsections
, _T("</H3>\n"));
1090 AddTexRef(topicName
, SectionsName
, SubsubsectionNameString
);
1091 SetCurrentSubsectionName(topicName
, SectionsName
);
1092 wxFprintf(Sections
, _T("\n<HR>\n"));
1094 // We're putting everything into the section file
1095 wxFprintf(Sections
, _T("<A NAME=\"%s\"></A>"), topicName
);
1096 wxFprintf(Sections
, _T("\n<H3>"));
1097 OutputCurrentSection();
1098 wxFprintf(Sections
, _T("</H3>\n"));
1099 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
1100 SetCurrentOutput(SectionContentsFD);
1101 wxFprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
1102 OutputCurrentSection();
1103 TexOutput(_T("</A><BR>"));
1105 if (htmlWorkshopFiles
) HTMLWorkshopAddToContents(2, topicName
, SectionsName
);
1106 SetCurrentOutput(Sections
);
1109 // Add this section title to the list of keywords
1112 OutputCurrentSectionToString(wxTex2RTFBuffer
);
1113 AddKeyWordForTopic(topicName
, wxTex2RTFBuffer
, currentFileName
);
1122 if ( !combineSubSections
)
1123 SetCurrentOutput(Subsections
);
1125 SetCurrentOutput(Sections
);
1136 if ( !combineSubSections
)
1137 SetCurrentOutput(Subsections
);
1139 SetCurrentOutput(Sections
);
1150 if ( !combineSubSections
)
1151 SetCurrentOutput(Subsections
);
1153 SetCurrentOutput(Sections
);
1164 // TexOutput(_T("<B>void</B>"));
1168 TexOutput(_T("HARDY"));
1172 TexOutput(_T("wxCLIPS"));
1176 TexOutput(_T("&"));
1178 case ltSPECIALAMPERSAND
:
1184 // End cell, start cell
1186 TexOutput(_T("</FONT></TD>"));
1188 // Start new row and cell, setting alignment for the first cell.
1189 if (currentColumn
< noColumns
)
1193 if (TableData
[currentColumn
].justification
== 'c')
1194 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=CENTER>"));
1195 else if (TableData
[currentColumn
].justification
== 'r')
1196 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=RIGHT>"));
1197 else if (TableData
[currentColumn
].absWidth
)
1199 // Convert from points * 20 into pixels.
1200 int points
= TableData
[currentColumn
].width
/ 20;
1202 // Say the display is 100 DPI (dots/pixels per inch).
1203 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1204 int pixels
= (int)(points
* 100.0 / 72.0);
1205 wxSnprintf(buf
, sizeof(buf
), _T("<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1208 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD ALIGN=LEFT>"));
1213 TexOutput(_T("&"));
1217 case ltBACKSLASHCHAR
:
1223 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1224 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1225 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1226 TexOutput(_T("</TR>\n"));
1229 TexOutput(_T("<BR>\n"));
1240 // Start new row and cell, setting alignment for the first cell.
1242 if (TableData
[currentColumn
].justification
== 'c')
1243 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER>"));
1244 else if (TableData
[currentColumn
].justification
== 'r')
1245 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=RIGHT>"));
1246 else if (TableData
[currentColumn
].absWidth
)
1248 // Convert from points * 20 into pixels.
1249 int points
= TableData
[currentColumn
].width
/ 20;
1251 // Say the display is 100 DPI (dots/pixels per inch).
1252 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1253 int pixels
= (int)(points
* 100.0 / 72.0);
1254 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=CENTER WIDTH=%d>"), pixels
);
1257 wxSnprintf(buf
, sizeof(buf
), _T("<TR>\n<TD ALIGN=LEFT>"));
1264 // Start new row and cell
1265 TexOutput(_T("</FONT></TD>\n</TR>\n"));
1269 // HTML-only: break until the end of the picture (both margins are clear).
1273 TexOutput(_T("<BR CLEAR=ALL>"));
1276 case ltRTFSP
: // Explicit space, RTF only
1278 case ltSPECIALTILDE
:
1282 #if (1) // if(inVerbatim)
1293 TexOutput(_T("<UL><UL>\n"));
1295 TexOutput(_T("</UL></UL>\n"));
1301 // case ltTWOCOLLIST:
1308 if (macroId
== ltENUMERATE
)
1309 listType
= LATEX_ENUMERATE
;
1310 else if (macroId
== ltITEMIZE
)
1311 listType
= LATEX_ITEMIZE
;
1313 listType
= LATEX_DESCRIPTION
;
1315 itemizeStack
.Insert(new ItemizeStruc(listType
));
1319 TexOutput(_T("<UL>\n"));
1321 case LATEX_ENUMERATE
:
1322 TexOutput(_T("<OL>\n"));
1324 case LATEX_DESCRIPTION
:
1326 TexOutput(_T("<DL>\n"));
1333 if (itemizeStack
.GetFirst())
1335 ItemizeStruc
*struc
= (ItemizeStruc
*)itemizeStack
.GetFirst()->GetData();
1336 switch (struc
->listType
)
1339 TexOutput(_T("</UL>\n"));
1341 case LATEX_ENUMERATE
:
1342 TexOutput(_T("</OL>\n"));
1344 case LATEX_DESCRIPTION
:
1346 TexOutput(_T("</DL>\n"));
1351 delete itemizeStack
.GetFirst();
1359 TexOutput(_T("\n<TABLE>\n"));
1361 TexOutput(_T("\n</TABLE>\n"));
1371 TexOutput(_T("<P>\n"));
1374 /* For footnotes we need to output the text at the bottom of the page and
1375 * insert a reference to it. Is it worth the trouble...
1377 case ltFOOTNOTEPOPUP:
1381 TexOutput(_T("<FN>"));
1383 else TexOutput(_T("</FN>"));
1390 TexOutput(_T("<TT>"));
1391 else TexOutput(_T("</TT>"));
1399 wxSnprintf(buf
, sizeof(buf
), _T("<PRE>\n"));
1402 else TexOutput(_T("</PRE>\n"));
1410 TexOutput(_T("<CENTER>"));
1412 else TexOutput(_T("</CENTER>"));
1420 TexOutput(_T("{\\ql "));
1422 else TexOutput(_T("}\\par\\pard\n"));
1431 TexOutput(_T("{\\qr "));
1433 else TexOutput(_T("}\\par\\pard\n"));
1441 // Netscape extension
1442 TexOutput(_T("<FONT SIZE=2>"));
1444 else TexOutput(_T("</FONT>"));
1451 // Netscape extension
1452 TexOutput(_T("<FONT SIZE=1>"));
1454 else TexOutput(_T("</FONT>"));
1461 // Netscape extension
1462 TexOutput(_T("<FONT SIZE=3>"));
1464 else TexOutput(_T("</FONT>"));
1471 // Netscape extension
1472 TexOutput(_T("<FONT SIZE=4>"));
1474 else TexOutput(_T("</FONT>"));
1481 // Netscape extension
1482 TexOutput(_T("<FONT SIZE=5>"));
1484 else TexOutput(_T("</FONT>"));
1491 // Netscape extension
1492 TexOutput(_T("<FONT SIZE=6>"));
1494 else TexOutput(_T("</FONT>"));
1503 TexOutput(_T("<B>"));
1505 else TexOutput(_T("</B>"));
1514 TexOutput(_T("<I>"));
1516 else TexOutput(_T("</I>"));
1524 TexOutput(_T("<EM>"));
1526 else TexOutput(_T("</EM>"));
1533 TexOutput(_T("<UL>"));
1535 else TexOutput(_T("</UL>"));
1544 TexOutput(_T("<TT>"));
1546 else TexOutput(_T("</TT>"));
1552 TexOutput(_T("©"), true);
1558 TexOutput(_T("®"), true);
1564 if (start
) TexOutput(_T("<--"));
1569 if (start
) TexOutput(_T("<=="));
1574 if (start
) TexOutput(_T("-->"));
1579 if (start
) TexOutput(_T("==>"));
1582 case ltLEFTRIGHTARROW
:
1584 if (start
) TexOutput(_T("<-->"));
1587 case ltLEFTRIGHTARROW2
:
1589 if (start
) TexOutput(_T("<==>"));
1602 wxNode
*node
= itemizeStack
.GetFirst();
1605 ItemizeStruc
*struc
= (ItemizeStruc
*)node
->GetData();
1606 struc
->currentItem
+= 1;
1607 if (struc
->listType
== LATEX_DESCRIPTION
)
1609 if (descriptionItemArg
)
1611 TexOutput(_T("<DT> "));
1612 TraverseChildrenFromChunk(descriptionItemArg
);
1613 TexOutput(_T("\n"));
1614 descriptionItemArg
= NULL
;
1616 TexOutput(_T("<DD>"));
1619 TexOutput(_T("<LI>"));
1626 if (start
&& DocumentTitle
&& DocumentAuthor
)
1628 // Add a special label for the contents page.
1629 // TexOutput(_T("<CENTER>\n"));
1630 TexOutput(_T("<A NAME=\"contents\">"));
1631 TexOutput(_T("<H2 ALIGN=CENTER>\n"));
1632 TraverseChildrenFromChunk(DocumentTitle
);
1633 TexOutput(_T("</H2>"));
1634 TexOutput(_T("<P>"));
1635 TexOutput(_T("</A>\n"));
1636 TexOutput(_T("<P>\n\n"));
1637 TexOutput(_T("<H3 ALIGN=CENTER>"));
1638 TraverseChildrenFromChunk(DocumentAuthor
);
1639 TexOutput(_T("</H3><P>\n\n"));
1642 TexOutput(_T("<H3 ALIGN=CENTER>"));
1643 TraverseChildrenFromChunk(DocumentDate
);
1644 TexOutput(_T("</H3><P>\n\n"));
1646 // TexOutput(_T("\n</CENTER>\n"));
1647 TexOutput(_T("\n<P><HR><P>\n"));
1650 // Now do optional frame contents page
1651 if (htmlFrameContents && FrameContents)
1653 SetCurrentOutput(FrameContents);
1655 // Add a special label for the contents page.
1656 TexOutput(_T("<CENTER>\n"));
1657 TexOutput(_T("<H3>\n"));
1658 TraverseChildrenFromChunk(DocumentTitle);
1659 TexOutput(_T("</H3>"));
1660 TexOutput(_T("<P>"));
1661 TexOutput(_T("</A>\n"));
1662 TexOutput(_T("<P>\n\n"));
1663 TexOutput(_T("<H3>"));
1664 TraverseChildrenFromChunk(DocumentAuthor);
1665 TexOutput(_T("</H3><P>\n\n"));
1668 TexOutput(_T("<H4>"));
1669 TraverseChildrenFromChunk(DocumentDate);
1670 TexOutput(_T("</H4><P>\n\n"));
1672 TexOutput(_T("\n</CENTER>\n"));
1673 TexOutput(_T("<P><HR><P>\n"));
1675 SetCurrentOutput(Titlepage);
1688 helpRefFilename
= NULL
;
1693 case ltBIBLIOGRAPHY
:
1697 DefaultOnMacro(macroId
, no_args
, start
);
1701 DefaultOnMacro(macroId
, no_args
, start
);
1702 TexOutput(_T("</DL>\n"));
1710 TexOutput(_T("<HR>\n"));
1718 TexOutput(_T("<HR>\n"));
1722 case ltTABLEOFCONTENTS
:
1726 // NB: if this is uncommented, the table of contents
1727 // completely disappears. If left commented, it's in the wrong
1729 //fflush(Titlepage);
1731 FILE *fd
= wxFopen(ContentsName
, _T("r"));
1737 wxPutc(ch
, Titlepage
);
1745 TexOutput(_T("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n"));
1746 OnInform(_T("Run Tex2RTF again to include contents page."));
1754 TexOutput(_T("<"));
1760 TexOutput(_T(">"));
1767 TexOutput(_T("<BLOCKQUOTE>"));
1769 TexOutput(_T("</BLOCKQUOTE>"));
1778 TexOutput(_T("\n<CAPTION>"));
1786 if (DocumentStyle
!= LATEX_ARTICLE
)
1787 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), FigureNameString
, chapterNo
, figureNo
);
1789 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), FigureNameString
, figureNo
);
1795 if (DocumentStyle
!= LATEX_ARTICLE
)
1796 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d.%d: "), TableNameString
, chapterNo
, tableNo
);
1798 wxSnprintf(figBuf
, sizeof(figBuf
), _T("%s %d: "), TableNameString
, tableNo
);
1806 TexOutput(_T("\n</CAPTION>\n"));
1808 wxChar
*topicName
= FindTopicName(GetNextChunk());
1810 int n
= inFigure
? figureNo
: tableNo
;
1812 AddTexRef(topicName
, NULL
, NULL
,
1813 ((DocumentStyle
!= LATEX_ARTICLE
) ? chapterNo
: n
),
1814 ((DocumentStyle
!= LATEX_ARTICLE
) ? n
: 0));
1820 if (start
) TexOutput(_T("ß"));
1825 if (start
) inFigure
= true;
1826 else inFigure
= false;
1831 if (start
) inTable
= true;
1832 else inTable
= false;
1836 DefaultOnMacro(macroId
, no_args
, start
);
1842 should be called at of argument which usually is
1843 type declaration which propably contains name of
1852 checks: GetArgData() if contains Type Declaration
1853 and can be referenced to some file
1855 before<a href="xxx&yyy">type</a>after
1858 false - if no reference was found
1859 true - if reference was found and HREF printed
1861 static bool CheckTypeRef()
1863 wxString typeDecl
= GetArgData();
1864 if( !typeDecl
.empty() ) {
1865 typeDecl
.Replace(wxT("\\"),wxT(""));
1866 wxString label
= typeDecl
;
1867 label
.Replace(wxT("const"),wxT(""));
1868 label
.Replace(wxT("virtual"),wxT(""));
1869 label
.Replace(wxT("static"),wxT(""));
1870 label
.Replace(wxT("extern"),wxT(""));
1871 label
= label
.BeforeFirst('&');
1872 label
= label
.BeforeFirst(wxT('*'));
1873 label
= label
.BeforeFirst(wxT('\\'));
1874 label
.Trim(true); label
.Trim(false);
1875 wxString typeName
= label
;
1877 TexRef
*texRef
= FindReference((wxChar
*)label
.c_str());
1879 if (texRef
&& texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0) {
1880 int a
= typeDecl
.Find(typeName
);
1881 wxString before
= typeDecl
.Mid( 0, a
);
1882 wxString after
= typeDecl
.Mid( a
+typeName
.Length() );
1883 //wxFprintf(stderr,wxT("%s <%s> %s to ... %s#%s !!!!\n"),
1885 // typeName.c_str(),
1887 // texRef->refFile,label.c_str());
1889 TexOutput(_T("<A HREF=\""));
1890 TexOutput(texRef
->refFile
);
1893 TexOutput(wxT("\">"));
1894 TexOutput(typeName
);
1895 TexOutput(wxT("</A>"));
1899 //wxFprintf(stderr,wxT("'%s' from (%s) -> label %s NOT FOUND\n"),
1900 // typeName.c_str(),
1901 // typeDecl.c_str(),
1908 // Called on start/end of argument examination
1909 bool HTMLOnArgument(int macroId
, int arg_no
, bool start
)
1915 case ltCHAPTERHEADING
:
1918 case ltSECTIONHEADING
:
1920 case ltSUBSECTIONSTAR
:
1921 case ltSUBSUBSECTION
:
1922 case ltSUBSUBSECTIONSTAR
:
1924 case ltMEMBERSECTION
:
1925 case ltFUNCTIONSECTION
:
1927 if (!start
&& (arg_no
== 1))
1928 currentSection
= GetArgChunk();
1933 if (start
&& (arg_no
== 1)) {
1934 TexOutput(_T("<B>"));
1935 if( CheckTypeRef() ) {
1936 TexOutput(_T("</B> "));
1941 if (!start
&& (arg_no
== 1))
1942 TexOutput(_T("</B> "));
1944 if (start
&& (arg_no
== 2))
1946 if (!suppressNameDecoration
) TexOutput(_T("<B>"));
1947 currentMember
= GetArgChunk();
1949 if (!start
&& (arg_no
== 2))
1951 if (!suppressNameDecoration
) TexOutput(_T("</B>"));
1954 if (start
&& (arg_no
== 3))
1956 if (!start
&& (arg_no
== 3))
1962 if (start
&& (arg_no
== 1))
1963 TexOutput(_T("<B>"));
1964 if (!start
&& (arg_no
== 1))
1965 TexOutput(_T("</B> "));
1967 if (start
&& (arg_no
== 2))
1969 if (!suppressNameDecoration
) TexOutput(_T("( "));
1970 currentMember
= GetArgChunk();
1972 if (!start
&& (arg_no
== 2))
1976 if (!start
&& (arg_no
== 3))
1982 if (!start
&& (arg_no
== 1))
1985 if (start
&& (arg_no
== 2))
1986 TexOutput(_T("(*"));
1987 if (!start
&& (arg_no
== 2))
1990 if (start
&& (arg_no
== 2))
1991 currentMember
= GetArgChunk();
1993 if (start
&& (arg_no
== 3))
1995 if (!start
&& (arg_no
== 3))
2002 const wxChar
* pend
= macroId
== ltCPARAM
?
2003 _T("</B> ") : _T("</B>");
2006 TexOutput(_T("<B>"));
2007 if( CheckTypeRef() ) {
2015 if (start
&& (arg_no
== 2))
2017 TexOutput(_T("<I>"));
2019 if (!start
&& (arg_no
== 2))
2021 TexOutput(_T("</I>"));
2027 if (!start
&& (arg_no
== 1))
2030 if (start
&& (arg_no
== 2))
2031 currentMember
= GetArgChunk();
2040 wxChar
*refName
= GetArgData();
2043 TexRef
*texRef
= FindReference(refName
);
2046 sec
= texRef
->sectionNumber
;
2059 if (IsArgOptional())
2061 else if ((GetNoArgs() - arg_no
) == 1)
2064 helpRefText
= GetArgChunk();
2067 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2071 TexChunk
*ref
= GetArgChunk();
2072 TexOutput(_T("<A HREF=\""));
2074 TraverseChildrenFromChunk(ref
);
2076 TexOutput(_T("\">"));
2078 TraverseChildrenFromChunk(helpRefText
);
2079 TexOutput(_T("</A>"));
2090 if (IsArgOptional())
2093 helpRefFilename
= GetArgChunk();
2096 if ((GetNoArgs() - arg_no
) == 1)
2099 helpRefText
= GetArgChunk();
2102 else if ((GetNoArgs() - arg_no
) == 0) // Arg = 2, or 3 if first is optional
2106 wxChar
*refName
= GetArgData();
2107 wxChar
*refFilename
= NULL
;
2111 TexRef
*texRef
= FindReference(refName
);
2114 if (texRef
->refFile
&& wxStrcmp(texRef
->refFile
, _T("??")) != 0)
2115 refFilename
= texRef
->refFile
;
2117 TexOutput(_T("<A HREF=\""));
2118 // If a filename is supplied, use it, otherwise try to
2119 // use the filename associated with the reference (from this document).
2120 if (helpRefFilename
)
2122 TraverseChildrenFromChunk(helpRefFilename
);
2126 else if (refFilename
)
2128 TexOutput(ConvertCase(refFilename
));
2129 if(!PrimaryAnchorOfTheFile(texRef
->refFile
, refName
))
2135 TexOutput(_T("\">"));
2137 TraverseChildrenFromChunk(helpRefText
);
2138 TexOutput(_T("</A>"));
2143 TraverseChildrenFromChunk(helpRefText
);
2145 TexOutput(_T(" (REF NOT FOUND)"));
2147 // for launching twice do not warn in preparation pass
2148 if ((passNumber
== 1 && !runTwice
) ||
2149 (passNumber
== 2 && runTwice
))
2152 errBuf
.Printf(_T("Warning: unresolved reference '%s'"), refName
);
2153 OnInform((wxChar
*)errBuf
.c_str());
2157 else TexOutput(_T("??"));
2172 wxChar
*alignment
= _T("");
2173 if (macroId
== ltIMAGEL
)
2174 alignment
= _T(" align=left");
2175 else if (macroId
== ltIMAGER
)
2176 alignment
= _T(" align=right");
2178 // Try to find an XBM or GIF image first.
2179 wxChar
*filename
= copystring(GetArgData());
2182 wxStrcpy(buf
, filename
);
2183 StripExtension(buf
);
2184 wxStrcat(buf
, _T(".xbm"));
2185 wxString f
= TexPathList
.FindValidPath(buf
);
2187 if (f
== _T("")) // Try for a GIF instead
2189 wxStrcpy(buf
, filename
);
2190 StripExtension(buf
);
2191 wxStrcat(buf
, _T(".gif"));
2192 f
= TexPathList
.FindValidPath(buf
);
2195 if (f
== _T("")) // Try for a JPEG instead
2197 wxStrcpy(buf
, filename
);
2198 StripExtension(buf
);
2199 wxStrcat(buf
, _T(".jpg"));
2200 f
= TexPathList
.FindValidPath(buf
);
2203 if (f
== _T("")) // Try for a PNG instead
2205 wxStrcpy(buf
, filename
);
2206 StripExtension(buf
);
2207 wxStrcat(buf
, _T(".png"));
2208 f
= TexPathList
.FindValidPath(buf
);
2213 wxChar
*inlineFilename
= copystring(f
);
2215 wxChar
*originalFilename
= TexPathList
.FindValidPath(filename
);
2216 // If we have found the existing filename, make the inline
2217 // image point to the original file (could be PS, for example)
2218 if (originalFilename
&& (wxStrcmp(inlineFilename
, originalFilename
) != 0))
2220 TexOutput(_T("<A HREF=\""));
2221 TexOutput(ConvertCase(originalFilename
));
2222 TexOutput(_T("\">"));
2223 TexOutput(_T("<img src=\""));
2224 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2225 TexOutput(_T("\""));
2226 TexOutput(alignment
);
2227 TexOutput(_T("></A>"));
2232 TexOutput(_T("<img src=\""));
2233 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename
)));
2234 TexOutput(_T("\""));
2235 TexOutput(alignment
);
2237 delete[] inlineFilename
;
2242 // Last resort - a link to a PS file.
2243 TexOutput(_T("<A HREF=\""));
2244 TexOutput(ConvertCase(wxFileNameFromPath(filename
)));
2245 TexOutput(_T("\">Picture</A>\n"));
2246 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2253 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2256 static wxChar
*imageFile
= NULL
;
2257 if (start
&& (arg_no
== 2))
2259 // Try to find an XBM or GIF image first.
2260 wxChar
*filename
= copystring(GetArgData());
2263 wxStrcpy(buf
, filename
);
2264 StripExtension(buf
);
2265 wxStrcat(buf
, _T(".xbm"));
2266 wxString f
= TexPathList
.FindValidPath(buf
);
2268 if (f
== _T("")) // Try for a GIF instead
2270 wxStrcpy(buf
, filename
);
2271 StripExtension(buf
);
2272 wxStrcat(buf
, _T(".gif"));
2273 f
= TexPathList
.FindValidPath(buf
);
2278 wxSnprintf(buf
, sizeof(buf
), _T("Warning: could not find an inline XBM/GIF for %s."), filename
);
2287 imageFile
= copystring(f
);
2290 else if (start
&& (arg_no
== 3))
2294 // First, try to find a .shg (segmented hypergraphics file)
2295 // that we can convert to a map file
2297 wxStrcpy(buf
, imageFile
);
2298 StripExtension(buf
);
2299 wxStrcat(buf
, _T(".shg"));
2300 wxString f
= TexPathList
.FindValidPath(buf
);
2304 // The default HTML file to go to is THIS file (so a no-op)
2305 SHGToMap((wxChar
*)f
.c_str(), currentFileName
);
2308 wxChar
*mapName
= GetArgData();
2309 TexOutput(_T("<A HREF=\"/cgi-bin/imagemap/"));
2313 TexOutput(_T("unknown"));
2314 TexOutput(_T("\">"));
2315 TexOutput(_T("<img src=\""));
2316 TexOutput(ConvertCase(wxFileNameFromPath(imageFile
)));
2317 TexOutput(_T("\" ISMAP></A><P>"));
2337 descriptionItemArg
= GetArgChunk();
2343 case ltTWOCOLITEMRULED
:
2346 if (start && (arg_no == 1))
2347 TexOutput(_T("\n<DT> "));
2348 if (start && (arg_no == 2))
2349 TexOutput(_T("<DD> "));
2355 if (TwoColWidthA
> -1)
2358 wxSnprintf(buf
, sizeof(buf
), _T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA
);
2363 TexOutput(_T("\n<TR><TD VALIGN=TOP>\n"));
2367 TexOutput(_T("\n</FONT></TD>\n"));
2374 if (TwoColWidthB
> -1)
2377 wxSnprintf(buf
, sizeof(buf
), _T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB
);
2382 TexOutput(_T("\n<TD VALIGN=TOP>\n"));
2386 TexOutput(_T("\n</FONT></TD></TR>\n"));
2390 case ltNUMBEREDBIBITEM
:
2392 if (arg_no
== 1 && start
)
2394 TexOutput(_T("\n<DT> "));
2396 if (arg_no
== 2 && !start
)
2397 TexOutput(_T("<P>\n"));
2403 if (arg_no
== 1 && start
)
2405 wxChar
*citeKey
= GetArgData();
2406 TexRef
*ref
= (TexRef
*)TexReferences
.Get(citeKey
);
2409 if (ref
->sectionNumber
) delete[] ref
->sectionNumber
;
2410 wxSnprintf(buf
, sizeof(buf
), _T("[%d]"), citeCount
);
2411 ref
->sectionNumber
= copystring(buf
);
2414 wxSnprintf(buf
, sizeof(buf
), _T("\n<DT> [%d] "), citeCount
);
2419 if (arg_no
== 2 && !start
)
2420 TexOutput(_T("<P>\n"));
2424 case ltMARGINPARODD
:
2425 case ltMARGINPAREVEN
:
2431 TexOutput(_T("<HR>\n"));
2435 TexOutput(_T("<HR><P>\n"));
2439 case ltTWOCOLWIDTHA
:
2443 wxChar
*val
= GetArgData();
2444 float points
= ParseUnitArgument(val
);
2445 TwoColWidthA
= (int)((points
* 100.0) / 72.0);
2450 case ltTWOCOLWIDTHB
:
2454 wxChar
*val
= GetArgData();
2455 float points
= ParseUnitArgument(val
);
2456 TwoColWidthB
= (int)((points
* 100.0) / 72.0);
2464 case ltACCENT_GRAVE
:
2468 wxChar
*val
= GetArgData();
2474 TexOutput(_T("à"));
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("Ì"));
2510 case ltACCENT_ACUTE
:
2514 wxChar
*val
= GetArgData();
2520 TexOutput(_T("á"));
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("Ý"));
2562 case ltACCENT_CARET
:
2566 wxChar
*val
= GetArgData();
2572 TexOutput(_T("â"));
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("Î"));
2608 case ltACCENT_TILDE
:
2612 wxChar
*val
= GetArgData();
2621 TexOutput(_T("ã"));
2624 TexOutput(_T("ñ"));
2627 TexOutput(_T("õ"));
2630 TexOutput(_T("Ã"));
2633 TexOutput(_T("Ñ"));
2636 TexOutput(_T("Õ"));
2645 case ltACCENT_UMLAUT
:
2649 wxChar
*val
= GetArgData();
2655 TexOutput(_T("ä"));
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("Ÿ"));
2701 wxChar
*val
= GetArgData();
2707 TexOutput(_T("å"));
2710 TexOutput(_T("Å"));
2723 wxChar
*val
= GetArgData();
2726 bool isPicture
= false;
2727 ParseColourString(val
, &isPicture
);
2730 if (backgroundImageString
)
2731 delete[] backgroundImageString
;
2732 backgroundImageString
= copystring(val
);
2736 if (backgroundColourString
)
2737 delete[] backgroundColourString
;
2738 backgroundColourString
= copystring(val
);
2744 case ltBACKGROUNDIMAGE
:
2748 wxChar
*val
= GetArgData();
2751 if (backgroundImageString
)
2752 delete[] backgroundImageString
;
2753 backgroundImageString
= copystring(val
);
2758 case ltBACKGROUNDCOLOUR
:
2762 wxChar
*val
= GetArgData();
2765 if (backgroundColourString
)
2766 delete[] backgroundColourString
;
2767 backgroundColourString
= copystring(val
);
2776 wxChar
*val
= GetArgData();
2779 if (textColourString
)
2780 delete[] textColourString
;
2781 textColourString
= copystring(val
);
2790 wxChar
*val
= GetArgData();
2793 if (linkColourString
)
2794 delete[] linkColourString
;
2795 linkColourString
= copystring(val
);
2800 case ltFOLLOWEDLINKCOLOUR
:
2804 wxChar
*val
= GetArgData();
2807 if (followedLinkColourString
)
2808 delete[] followedLinkColourString
;
2809 followedLinkColourString
= copystring(val
);
2814 case ltACCENT_CADILLA
:
2818 wxChar
*val
= GetArgData();
2824 TexOutput(_T("ç"));
2827 TexOutput(_T("Ç"));
2838 case ltFOOTNOTEPOPUP:
2848 case ltSUPERTABULAR
:
2854 currentRowNumber
= 0;
2857 tableVerticalLineLeft
= false;
2858 tableVerticalLineRight
= false;
2860 wxChar
*alignString
= copystring(GetArgData());
2861 ParseTableArgument(alignString
);
2863 TexOutput(_T("<TABLE BORDER>\n"));
2865 // Write the first row formatting for compatibility
2866 // with standard Latex
2867 if (compatibilityMode
)
2869 TexOutput(_T("<TR>\n<TD>"));
2872 for (int i = 0; i < noColumns; i++)
2874 currentWidth += TableData[i].width;
2875 wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth);
2878 TexOutput(_T("\\pard\\intbl\n"));
2881 delete[] alignString
;
2886 else if (arg_no
== 2 && !start
)
2888 TexOutput(_T("</TABLE>\n"));
2893 case ltTHEBIBLIOGRAPHY
:
2895 if (start
&& (arg_no
== 1))
2897 ReopenFile(&Chapters
, &ChaptersName
, _T("bibliography"));
2898 AddTexRef(_T("bibliography"), ChaptersName
, _T("bibliography"));
2899 SetCurrentSubsectionName(_T("bibliography"), ChaptersName
);
2903 SetCurrentOutput(Chapters
);
2905 wxChar titleBuf
[150];
2906 if (truncateFilenames
)
2907 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s.htm"), wxFileNameFromPath(FileRoot
));
2909 wxSnprintf(titleBuf
, sizeof(titleBuf
), _T("%s_contents.html"), wxFileNameFromPath(FileRoot
));
2912 TexOutput(_T("<title>"));
2913 TexOutput(ReferencesNameString
);
2914 TexOutput(_T("</title></head>\n"));
2917 wxFprintf(Chapters
, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString
);
2918 AddBrowseButtons(_T("contents"), titleBuf
, // Up
2919 lastTopic
, lastFileName
, // Last topic
2920 _T("bibliography"), ChaptersName
); // This topic
2922 SetCurrentOutputs(Contents
, Chapters
);
2923 if(PrimaryAnchorOfTheFile(ChaptersName
, _T("bibliography")))
2924 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName
));
2926 wxFprintf(Contents
, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName
), _T("bibliography"));
2928 wxFprintf(Contents
, _T("%s</A>\n"), ReferencesNameString
);
2929 wxFprintf(Chapters
, _T("</H2>\n</A>\n"));
2931 SetCurrentOutput(Chapters
);
2934 if (!start
&& (arg_no
== 2))
2941 /* Build up list of keywords associated with topics */
2944 // wxChar *entry = GetArgData();
2946 OutputChunkToString(GetArgChunk(), buf
);
2949 AddKeyWordForTopic(CurrentTopic
, buf
, currentFileName
);
2963 wxChar
*name
= GetArgData();
2965 if (!FindColourHTMLString(name
, buf2
))
2967 wxStrcpy(buf2
, _T("#000000"));
2969 wxSnprintf(buf
, sizeof(buf
), _T("Could not find colour name %s"), name
);
2972 TexOutput(_T("<FONT COLOR=\""));
2974 TexOutput(_T("\">"));
2987 if (arg_no
== 2) TexOutput(_T("</FONT>"));
2991 case ltINSERTATLEVEL
:
2993 // This macro allows you to insert text at a different level
2994 // from the current level, e.g. into the Sections from within a subsubsection.
2997 static int currentLevelNo
= 1;
2998 static FILE* oldLevelFile
= Chapters
;
3005 oldLevelFile
= CurrentOutput1
;
3007 wxChar
*str
= GetArgData();
3008 currentLevelNo
= wxAtoi(str
);
3010 // TODO: cope with article style (no chapters)
3011 switch (currentLevelNo
)
3015 outputFile
= Chapters
;
3020 outputFile
= Sections
;
3025 outputFile
= Subsections
;
3030 outputFile
= Subsubsections
;
3040 CurrentOutput1
= outputFile
;
3056 CurrentOutput1
= oldLevelFile
;
3062 return DefaultOnArgument(macroId
, arg_no
, start
);
3074 tableVerticalLineLeft
= false;
3075 tableVerticalLineRight
= false;
3078 if (!InputFile
.empty() && !OutputFile
.empty())
3080 // Do some HTML-specific transformations on all the strings,
3082 Text2HTML(GetTopLevelChunk());
3085 if (truncateFilenames
)
3086 wxSnprintf(buf
, sizeof(buf
), _T("%s.htm"), FileRoot
);
3088 wxSnprintf(buf
, sizeof(buf
), _T("%s_contents.html"), FileRoot
);
3089 if (TitlepageName
) delete[] TitlepageName
;
3090 TitlepageName
= copystring(buf
);
3091 Titlepage
= wxFopen(buf
, _T("w"));
3093 if (truncateFilenames
)
3094 wxSnprintf(buf
, sizeof(buf
), _T("%s_fc.htm"), FileRoot
);
3096 wxSnprintf(buf
, sizeof(buf
), _T("%s_fcontents.html"), FileRoot
);
3098 contentsFrameName
= copystring(buf
);
3100 Contents
= wxFopen(TmpContentsName
, _T("w"));
3102 if (htmlFrameContents
)
3104 // FrameContents = wxFopen(TmpFrameContentsName, _T("w"));
3105 FrameContents
= wxFopen(contentsFrameName
, _T("w"));
3106 wxFprintf(FrameContents
, _T("<HTML>\n<UL>\n"));
3109 if (!Titlepage
|| !Contents
)
3111 OnError(_T("Cannot open output file!"));
3114 AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName
), ContentsNameString
);
3116 wxFprintf(Contents
, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString
);
3118 wxFprintf(Contents
, _T("<UL>\n"));
3120 SetCurrentOutput(Titlepage
);
3121 if (htmlWorkshopFiles
) HTMLWorkshopStartContents();
3122 OnInform(_T("Converting..."));
3125 wxFprintf(Contents
, _T("</UL>\n\n"));
3127 // SetCurrentOutput(Titlepage);
3132 // wxFprintf(Titlepage, _T("\n</BODY></HTML>\n"));
3139 wxFprintf(FrameContents
, _T("\n</UL>\n"));
3140 wxFprintf(FrameContents
, _T("</HTML>\n"));
3141 fclose(FrameContents
);
3142 FrameContents
= NULL
;
3147 wxFprintf(Chapters
, _T("\n</FONT></BODY></HTML>\n"));
3153 wxFprintf(Sections
, _T("\n</FONT></BODY></HTML>\n"));
3157 if (Subsections
&& !combineSubSections
)
3159 wxFprintf(Subsections
, _T("\n</FONT></BODY></HTML>\n"));
3160 fclose(Subsections
);
3163 if (Subsubsections
&& !combineSubSections
)
3165 wxFprintf(Subsubsections
, _T("\n</FONT></BODY></HTML>\n"));
3166 fclose(Subsubsections
);
3167 Subsubsections
= NULL
;
3169 if ( SectionContentsFD
)
3171 fclose(SectionContentsFD
);
3172 SectionContentsFD
= NULL
;
3175 // Create a temporary file for the title page header, add some info,
3176 // and concat the titlepage just generated.
3177 // This is necessary in order to put the title of the document
3178 // at the TOP of the file within <HEAD>, even though we only find out
3179 // what it is later on.
3180 FILE *tmpTitle
= wxFopen(_T("title.tmp"), _T("w"));
3185 SetCurrentOutput(tmpTitle
);
3187 TexOutput(_T("\n<TITLE>"));
3188 TraverseChildrenFromChunk(DocumentTitle
);
3189 TexOutput(_T("</TITLE></HEAD>\n"));
3193 SetCurrentOutput(tmpTitle
);
3194 HTMLHeadTo(tmpTitle
);
3196 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), contentsString
);
3198 wxFprintf(tmpTitle
, _T("<TITLE>%s</TITLE></HEAD>\n\n"), wxFileNameFromPath(FileRoot
));
3201 // Output frame information
3202 if (htmlFrameContents
)
3204 wxChar firstFileName
[300];
3205 if (truncateFilenames
)
3206 wxSnprintf(firstFileName
, sizeof(firstFileName
), _T("%s1.htm"), FileRoot
);
3208 wxStrcpy(firstFileName
, gs_filenames
[1].c_str());
3210 wxFprintf(tmpTitle
, _T("<FRAMESET COLS=\"30%%,70%%\">\n"));
3212 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName
)));
3213 wxFprintf(tmpTitle
, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName
)));
3214 wxFprintf(tmpTitle
, _T("</FRAMESET>\n"));
3216 wxFprintf(tmpTitle
, _T("<NOFRAMES>\n"));
3219 // Output <BODY...> to temporary title page
3224 FILE *fd
= wxFopen(TitlepageName
, _T("r"));
3230 wxPutc(ch
, tmpTitle
);
3236 wxFprintf(tmpTitle
, _T("\n</FONT></BODY>\n"));
3238 if (htmlFrameContents
)
3240 wxFprintf(tmpTitle
, _T("\n</NOFRAMES>\n"));
3242 wxFprintf(tmpTitle
, _T("\n</HTML>\n"));
3245 if (wxFileExists(TitlepageName
)) wxRemoveFile(TitlepageName
);
3246 if (!wxRenameFile(_T("title.tmp"), TitlepageName
))
3248 wxCopyFile(_T("title.tmp"), TitlepageName
);
3249 wxRemoveFile(_T("title.tmp"));
3253 if (lastFileName
) delete[] lastFileName
;
3254 lastFileName
= NULL
;
3255 if (lastTopic
) delete[] lastTopic
;
3258 if (wxFileExists(ContentsName
)) wxRemoveFile(ContentsName
);
3260 if (!wxRenameFile(TmpContentsName
, ContentsName
))
3262 wxCopyFile(TmpContentsName
, ContentsName
);
3263 wxRemoveFile(TmpContentsName
);
3266 // Generate .htx file if requested
3269 wxChar htmlIndexName
[300];
3270 wxSnprintf(htmlIndexName
, sizeof(htmlIndexName
), _T("%s.htx"), FileRoot
);
3271 GenerateHTMLIndexFile(htmlIndexName
);
3274 // Generate HTML Help Workshop files if requested
3275 if (htmlWorkshopFiles
)
3277 HTMLWorkshopEndContents();
3278 GenerateHTMLWorkshopFiles(FileRoot
);
3287 // Output .htx index file
3288 void GenerateHTMLIndexFile(wxChar
*fname
)
3290 FILE *fd
= wxFopen(fname
, _T("w"));
3294 TopicTable
.BeginFind();
3295 wxHashTable::Node
*node
= TopicTable
.Next();
3298 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3299 const wxChar
*topicName
= node
->GetKeyString();
3300 if (texTopic
->filename
&& texTopic
->keywords
)
3302 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3305 wxChar
*s
= (wxChar
*)node1
->GetData();
3306 wxFprintf(fd
, _T("%s|%s|%s\n"), topicName
, texTopic
->filename
, s
);
3307 node1
= node1
->GetNext();
3310 node
= TopicTable
.Next();
3321 // output .hpp, .hhc and .hhk files:
3324 void GenerateHTMLWorkshopFiles(wxChar
*fname
)
3329 /* Generate project file : */
3331 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhp"), fname
);
3332 f
= wxFopen(buf
, _T("wt"));
3335 _T("Compatibility=1.1\n")
3336 _T("Full-text search=Yes\n")
3337 _T("Contents file=%s.hhc\n")
3338 _T("Compiled file=%s.chm\n")
3339 _T("Default Window=%sHelp\n")
3340 _T("Default topic=%s\n")
3341 _T("Index file=%s.hhk\n")
3343 wxFileNameFromPath(fname
),
3344 wxFileNameFromPath(fname
),
3345 wxFileNameFromPath(fname
),
3346 wxFileNameFromPath(TitlepageName
),
3347 wxFileNameFromPath(fname
)
3350 if (DocumentTitle
) {
3351 SetCurrentOutput(f
);
3352 TraverseChildrenFromChunk(DocumentTitle
);
3354 else wxFprintf(f
, _T("(unknown)"));
3356 wxFprintf(f
, _T("\n\n[WINDOWS]\n")
3357 _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"),
3358 wxFileNameFromPath(fname
),
3359 wxFileNameFromPath(fname
),
3360 wxFileNameFromPath(fname
),
3361 wxFileNameFromPath(TitlepageName
));
3364 wxFprintf(f
, _T("\n\n[FILES]\n"));
3365 wxFprintf(f
, _T("%s\n"), wxFileNameFromPath(TitlepageName
));
3366 for (int i
= 1; i
<= fileId
; i
++) {
3367 if (truncateFilenames
)
3368 wxSnprintf(buf
, sizeof(buf
), _T("%s%d.htm"), wxFileNameFromPath(FileRoot
), i
);
3370 wxStrcpy(buf
, wxFileNameFromPath(gs_filenames
[i
].c_str()));
3371 wxFprintf(f
, _T("%s\n"), buf
);
3375 /* Generate index file : */
3377 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhk"), fname
);
3378 f
= wxFopen(buf
, _T("wt"));
3381 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3386 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3387 _T("<!-- Sitemap 1.0 -->\n")
3388 _T("</HEAD><BODY>\n")
3389 _T("<OBJECT type=\"text/site properties\">\n")
3390 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3394 TopicTable
.BeginFind();
3395 wxHashTable::Node
*node
= TopicTable
.Next();
3398 TexTopic
*texTopic
= (TexTopic
*)node
->GetData();
3399 const wxChar
*topicName
= node
->GetKeyString();
3400 if (texTopic
->filename
&& texTopic
->keywords
)
3402 wxStringListNode
*node1
= texTopic
->keywords
->GetFirst();
3405 wxChar
*s
= (wxChar
*)node1
->GetData();
3407 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3408 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3409 _T(" <param name=\"Name\" value=\"%s\">\n")
3411 texTopic
->filename
, topicName
, s
);
3412 node1
= node1
->GetNext();
3415 node
= TopicTable
.Next();
3418 wxFprintf(f
, _T("</UL>\n"));
3424 static FILE *HTMLWorkshopContents
= NULL
;
3425 static int HTMLWorkshopLastLevel
= 0;
3427 void HTMLWorkshopAddToContents(int level
, wxChar
*s
, wxChar
*file
)
3431 if (level
> HTMLWorkshopLastLevel
)
3432 for (i
= HTMLWorkshopLastLevel
; i
< level
; i
++)
3433 wxFprintf(HTMLWorkshopContents
, _T("<UL>"));
3434 if (level
< HTMLWorkshopLastLevel
)
3435 for (i
= level
; i
< HTMLWorkshopLastLevel
; i
++)
3436 wxFprintf(HTMLWorkshopContents
, _T("</UL>"));
3438 SetCurrentOutput(HTMLWorkshopContents
);
3439 wxFprintf(HTMLWorkshopContents
,
3440 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3441 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3442 _T(" <param name=\"Name\" value=\""),
3444 OutputCurrentSection();
3445 wxFprintf(HTMLWorkshopContents
,
3447 _T(" </OBJECT>\n"));
3448 HTMLWorkshopLastLevel
= level
;
3452 void HTMLWorkshopStartContents()
3455 wxSnprintf(buf
, sizeof(buf
), _T("%s.hhc"), FileRoot
);
3456 HTMLWorkshopContents
= wxFopen(buf
, _T("wt"));
3457 HTMLWorkshopLastLevel
= 0;
3459 wxFprintf(HTMLWorkshopContents
,
3460 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3462 HTMLHeadTo(HTMLWorkshopContents
);
3463 wxFprintf(HTMLWorkshopContents
,
3465 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3466 _T("<!-- Sitemap 1.0 -->\n")
3467 _T("</HEAD><BODY>\n")
3468 _T("<OBJECT type=\"text/site properties\">\n")
3469 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3472 _T("<LI> <OBJECT type=\"text/sitemap\">\n")
3473 _T("<param name=\"Local\" value=\"%s\">\n")
3474 _T("<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n"),
3475 wxFileNameFromPath(TitlepageName
)
3481 void HTMLWorkshopEndContents()
3483 for (int i
= HTMLWorkshopLastLevel
; i
>= 0; i
--)
3484 wxFprintf(HTMLWorkshopContents
, _T("</UL>\n"));
3485 fclose(HTMLWorkshopContents
);
3489 bool PrimaryAnchorOfTheFile( wxChar
*file
, wxChar
*label
)
3491 wxString file_label
;
3492 file_label
.Printf( HTML_FILENAME_PATTERN
, FileRoot
, label
);
3493 return file_label
.IsSameAs( file
, false );