]> git.saurik.com Git - wxWidgets.git/blob - utils/tex2rtf/src/htmlutil.cpp
Applied patch [ 867187 ] wxWindows-like markup in TEX2RTF tool
[wxWidgets.git] / utils / tex2rtf / src / htmlutil.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: htmlutil.cpp
3 // Purpose: Converts Latex to HTML
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 7.9.93
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #endif
25
26 #include "tex2any.h"
27 #include "tex2rtf.h"
28 #include "table.h"
29
30 #if !WXWIN_COMPATIBILITY_2_4
31 static inline wxChar* copystring(const wxChar* s)
32 { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
33 #endif
34
35 extern wxHashTable TexReferences;
36
37
38 extern void DecToHex(int, wxChar *);
39 void GenerateHTMLIndexFile(wxChar *fname);
40
41 void GenerateHTMLWorkshopFiles(wxChar *fname);
42 void HTMLWorkshopAddToContents(int level, wxChar *s, wxChar *file);
43 void HTMLWorkshopStartContents();
44 void HTMLWorkshopEndContents();
45
46 void OutputContentsFrame(void);
47
48 #include "readshg.h" // Segmented hypergraphics parsing
49
50 wxChar *ChaptersName = NULL;
51 wxChar *SectionsName = NULL;
52 wxChar *SubsectionsName = NULL;
53 wxChar *SubsubsectionsName = NULL;
54 wxChar *TitlepageName = NULL;
55 wxChar *lastFileName = NULL;
56 wxChar *lastTopic = NULL;
57 wxChar *currentFileName = NULL;
58 wxChar *contentsFrameName = NULL;
59
60 static TexChunk *descriptionItemArg = NULL;
61 static TexChunk *helpRefFilename = NULL;
62 static TexChunk *helpRefText = NULL;
63 static int indentLevel = 0;
64 static int citeCount = 1;
65 extern FILE *Contents;
66 FILE *FrameContents = NULL;
67 FILE *Titlepage = NULL;
68 // FILE *FrameTitlepage = NULL;
69 int fileId = 0;
70 bool subsectionStarted = FALSE;
71
72 // Which column of a row are we in? (Assumes no nested tables, of course)
73 int currentColumn = 0;
74
75 // Are we in verbatim mode? If so, format differently.
76 static bool inVerbatim = FALSE;
77
78 // Need to know whether we're in a table or figure for benefit
79 // of listoffigures/listoftables
80 static bool inFigure = FALSE;
81 static bool inTable = FALSE;
82
83 // This is defined in the Tex2Any library.
84 extern wxChar *BigBuffer;
85
86 // DHS Two-column table dimensions.
87 static int TwoColWidthA = -1;
88 static int TwoColWidthB = -1;
89
90
91 class HyperReference: public wxObject
92 {
93 public:
94 wxChar *refName;
95 wxChar *refFile;
96 HyperReference(wxChar *name, wxChar *file)
97 {
98 if (name) refName = copystring(name);
99 if (file) refFile = copystring(file);
100 }
101 };
102
103 class TexNextPage: public wxObject
104 {
105 public:
106 wxChar *label;
107 wxChar *filename;
108 TexNextPage(wxChar *theLabel, wxChar *theFile)
109 {
110 label = copystring(theLabel);
111 filename = copystring(theFile);
112 }
113 ~TexNextPage(void)
114 {
115 delete[] label;
116 delete[] filename;
117 }
118 };
119
120 wxHashTable TexNextPages(wxKEY_STRING);
121
122 static wxChar *CurrentChapterName = NULL;
123 static wxChar *CurrentChapterFile = NULL;
124 static wxChar *CurrentSectionName = NULL;
125 static wxChar *CurrentSectionFile = NULL;
126 static wxChar *CurrentSubsectionName = NULL;
127 static wxChar *CurrentSubsectionFile = NULL;
128 static wxChar *CurrentSubsubsectionName = NULL;
129 static wxChar *CurrentSubsubsectionFile = NULL;
130 static wxChar *CurrentTopic = NULL;
131
132 static void SetCurrentTopic(wxChar *s)
133 {
134 if (CurrentTopic) delete[] CurrentTopic;
135 CurrentTopic = copystring(s);
136 }
137
138 void SetCurrentChapterName(wxChar *s, wxChar *file)
139 {
140 if (CurrentChapterName) delete[] CurrentChapterName;
141 CurrentChapterName = copystring(s);
142 if (CurrentChapterFile) delete[] CurrentChapterFile;
143 CurrentChapterFile = copystring(file);
144
145 currentFileName = CurrentChapterFile;
146
147 SetCurrentTopic(s);
148 }
149 void SetCurrentSectionName(wxChar *s, wxChar *file)
150 {
151 if (CurrentSectionName) delete[] CurrentSectionName;
152 CurrentSectionName = copystring(s);
153 if (CurrentSectionFile) delete[] CurrentSectionFile;
154 CurrentSectionFile = copystring(file);
155
156 currentFileName = CurrentSectionFile;
157 SetCurrentTopic(s);
158 }
159 void SetCurrentSubsectionName(wxChar *s, wxChar *file)
160 {
161 if (CurrentSubsectionName) delete[] CurrentSubsectionName;
162 CurrentSubsectionName = copystring(s);
163 if (CurrentSubsectionFile) delete[] CurrentSubsectionFile;
164 CurrentSubsectionFile = copystring(file);
165 currentFileName = CurrentSubsectionFile;
166 SetCurrentTopic(s);
167 }
168 void SetCurrentSubsubsectionName(wxChar *s, wxChar *file)
169 {
170 if (CurrentSubsubsectionName) delete[] CurrentSubsubsectionName;
171 CurrentSubsubsectionName = copystring(s);
172 if (CurrentSubsubsectionFile) delete[] CurrentSubsubsectionFile;
173 CurrentSubsubsectionFile = copystring(file);
174 currentFileName = CurrentSubsubsectionFile;
175 SetCurrentTopic(s);
176 }
177
178 /*
179 * Close former filedescriptor and reopen using another filename.
180 *
181 */
182
183 void ReopenFile(FILE **fd, wxChar **fileName)
184 {
185 if (*fd)
186 {
187 wxFprintf(*fd, _T("\n</FONT></BODY></HTML>\n"));
188 fclose(*fd);
189 }
190 fileId ++;
191 wxChar buf[400];
192 if (truncateFilenames)
193 wxSprintf(buf, _T("%s%d.htm"), FileRoot, fileId);
194 else
195 wxSprintf(buf, _T("%s%d.html"), FileRoot, fileId);
196 if (*fileName) delete[] *fileName;
197 *fileName = copystring(wxFileNameFromPath(buf));
198 *fd = wxFopen(buf, _T("w"));
199 wxFprintf(*fd, _T("<HTML>\n"));
200 }
201
202 /*
203 * Reopen section contents file, i.e. the index appended to each section
204 * in subsectionCombine mode
205 */
206
207 static wxChar *SectionContentsFilename = NULL;
208 static FILE *SectionContentsFD = NULL;
209
210 void ReopenSectionContentsFile(void)
211 {
212 if ( SectionContentsFD )
213 {
214 fclose(SectionContentsFD);
215 }
216 if ( SectionContentsFilename )
217 delete[] SectionContentsFilename;
218 SectionContentsFD = NULL;
219 SectionContentsFilename = NULL;
220
221 // Create the name from the current section filename
222 if ( CurrentSectionFile )
223 {
224 wxChar buf[256];
225 wxStrcpy(buf, CurrentSectionFile);
226 wxStripExtension(buf);
227 wxStrcat(buf, _T(".con"));
228 SectionContentsFilename = copystring(buf);
229
230 SectionContentsFD = wxFopen(SectionContentsFilename, _T("w"));
231 }
232 }
233
234
235 /*
236 * Given a TexChunk with a string value, scans through the string
237 * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>.
238 *
239 */
240
241 void ProcessText2HTML(TexChunk *chunk)
242 {
243 bool changed = FALSE;
244 int ptr = 0;
245 int i = 0;
246 char ch = 1;
247 int len = wxStrlen(chunk->value);
248 while (ch != 0)
249 {
250 ch = chunk->value[i];
251
252 // 2 newlines means \par
253 if (!inVerbatim && chunk->value[i] == 10 && ((len > i+1 && chunk->value[i+1] == 10) ||
254 ((len > i+1 && chunk->value[i+1] == 13) &&
255 (len > i+2 && chunk->value[i+2] == 10))))
256 {
257 BigBuffer[ptr] = 0; wxStrcat(BigBuffer, _T("<P>\n\n")); ptr += 5;
258 i += 2;
259 changed = TRUE;
260 }
261 else if (!inVerbatim && ch == '`' && (len >= i+1 && chunk->value[i+1] == '`'))
262 {
263 BigBuffer[ptr] = '"'; ptr ++;
264 i += 2;
265 changed = TRUE;
266 }
267 else if (!inVerbatim && ch == '`') // Change ` to '
268 {
269 BigBuffer[ptr] = 39; ptr ++;
270 i += 1;
271 changed = TRUE;
272 }
273 else if (ch == '<') // Change < to &lt
274 {
275 BigBuffer[ptr] = 0;
276 wxStrcat(BigBuffer, _T("&lt;"));
277 ptr += 4;
278 i += 1;
279 changed = TRUE;
280 }
281 else if (ch == '>') // Change > to &gt
282 {
283 BigBuffer[ptr] = 0;
284 wxStrcat(BigBuffer, _T("&gt;"));
285 ptr += 4;
286 i += 1;
287 changed = TRUE;
288 }
289 else
290 {
291 BigBuffer[ptr] = ch;
292 i ++;
293 ptr ++;
294 }
295 }
296 BigBuffer[ptr] = 0;
297
298 if (changed)
299 {
300 delete chunk->value;
301 chunk->value = copystring(BigBuffer);
302 }
303 }
304
305 /*
306 * Scan through all chunks starting from the given one,
307 * calling ProcessText2HTML to convert Latex-isms to RTF-isms.
308 * This should be called after Tex2Any has parsed the file,
309 * and before TraverseDocument is called.
310 *
311 */
312
313 void Text2HTML(TexChunk *chunk)
314 {
315 Tex2RTFYield();
316 if (stopRunning) return;
317
318 switch (chunk->type)
319 {
320 case CHUNK_TYPE_MACRO:
321 {
322 TexMacroDef *def = chunk->def;
323
324 if (def && def->ignore)
325 return;
326
327 if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB || def->macroId == ltSPECIAL))
328 inVerbatim = TRUE;
329
330 wxNode *node = chunk->children.GetFirst();
331 while (node)
332 {
333 TexChunk *child_chunk = (TexChunk *)node->GetData();
334 Text2HTML(child_chunk);
335 node = node->GetNext();
336 }
337
338 if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB || def->macroId == ltSPECIAL))
339 inVerbatim = FALSE;
340
341 break;
342 }
343 case CHUNK_TYPE_ARG:
344 {
345 wxNode *node = chunk->children.GetFirst();
346 while (node)
347 {
348 TexChunk *child_chunk = (TexChunk *)node->GetData();
349 Text2HTML(child_chunk);
350 node = node->GetNext();
351 }
352
353 break;
354 }
355 case CHUNK_TYPE_STRING:
356 {
357 if (chunk->value)
358 ProcessText2HTML(chunk);
359 break;
360 }
361 }
362 }
363
364 /*
365 * Add appropriate browse buttons to this page.
366 *
367 */
368
369 void AddBrowseButtons(wxChar *upLabel, wxChar *upFilename,
370 wxChar *previousLabel, wxChar *previousFilename,
371 wxChar *thisLabel, wxChar *thisFilename)
372 {
373 wxChar contentsReferenceBuf[80];
374 wxChar upReferenceBuf[80];
375 wxChar backReferenceBuf[80];
376 wxChar forwardReferenceBuf[80];
377 if (htmlBrowseButtons == HTML_BUTTONS_NONE)
378 return;
379
380 wxChar *contentsReference; // no need to initialize because always assigned below
381 if (htmlBrowseButtons == HTML_BUTTONS_TEXT)
382 contentsReference = ContentsNameString;
383 else
384 {
385 // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">";
386 contentsReference = contentsReferenceBuf;
387 wxSprintf(contentsReference, _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">"), ConvertCase(_T("contents.gif")));
388 }
389
390 wxChar *upReference; // no need to initialize because always assigned below
391 if (htmlBrowseButtons == HTML_BUTTONS_TEXT)
392 upReference = UpNameString;
393 else
394 {
395 // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">";
396 upReference = upReferenceBuf;
397 wxSprintf(upReference, _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">"), ConvertCase(_T("up.gif")));
398 }
399
400 wxChar *backReference; // no need to initialize because always assigned below
401 if (htmlBrowseButtons == HTML_BUTTONS_TEXT)
402 backReference = _T("&lt;&lt;");
403 else
404 {
405 // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
406 backReference = backReferenceBuf;
407 wxSprintf(backReference, _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">"), ConvertCase(_T("back.gif")));
408 }
409
410 wxChar *forwardReference; // no need to initialize because always assigned below
411 if (htmlBrowseButtons == HTML_BUTTONS_TEXT)
412 forwardReference = _T("&gt;&gt;");
413 else
414 {
415 // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
416 forwardReference = forwardReferenceBuf;
417 wxSprintf(forwardReference, _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">"), ConvertCase(_T("forward.gif")));
418 }
419
420 TexOutput(_T("<CENTER>"));
421
422 wxChar buf[200];
423
424 /*
425 * Contents button
426 *
427 */
428
429 if (truncateFilenames)
430 {
431 wxChar buf1[80];
432 wxStrcpy(buf1, ConvertCase(wxFileNameFromPath(FileRoot)));
433 wxSprintf(buf, _T("\n<A HREF=\"%s.%s\">%s</A> "), buf1, ConvertCase(_T("htm")), contentsReference);
434 }
435 else
436 {
437 wxChar buf1[80];
438 wxStrcpy(buf1, ConvertCase(wxFileNameFromPath(FileRoot)));
439 wxSprintf(buf, _T("\n<A HREF=\"%s%s\">%s</A> "), buf1, ConvertCase(_T("_contents.html")), contentsReference);
440 }
441 // TexOutput(_T("<NOFRAMES>"));
442 TexOutput(buf);
443 // TexOutput(_T("</NOFRAMES>"));
444
445 /*
446 * Up button
447 *
448 */
449
450 if (upLabel && upFilename)
451 {
452 if (wxStrlen(upLabel) > 0)
453 wxSprintf(buf, _T("<A HREF=\"%s#%s\">%s</A> "), ConvertCase(upFilename), upLabel, upReference);
454 else
455 wxSprintf(buf, _T("<A HREF=\"%s\">%s</A> "), ConvertCase(upFilename), upReference);
456 if (wxStrcmp(upLabel, _T("contents")) == 0)
457 {
458 // TexOutput(_T("<NOFRAMES>"));
459 TexOutput(buf);
460 // TexOutput(_T("</NOFRAMES>"));
461 }
462 else
463 TexOutput(buf);
464 }
465
466 /*
467 * << button
468 *
469 */
470
471 if (previousLabel && previousFilename)
472 {
473 wxSprintf(buf, _T("<A HREF=\"%s#%s\">%s</A> "), ConvertCase(previousFilename), previousLabel, backReference);
474 if (wxStrcmp(previousLabel, _T("contents")) == 0)
475 {
476 // TexOutput(_T("<NOFRAMES>"));
477 TexOutput(buf);
478 // TexOutput(_T("</NOFRAMES>"));
479 }
480 else
481 TexOutput(buf);
482 }
483 else
484 {
485 // A placeholder so the buttons don't keep moving position
486 wxSprintf(buf, _T("%s "), backReference);
487 TexOutput(buf);
488 }
489
490 wxChar *nextLabel = NULL;
491 wxChar *nextFilename = NULL;
492
493 // Get the next page, and record the previous page's 'next' page
494 // (i.e. this page)
495 TexNextPage *nextPage = (TexNextPage *)TexNextPages.Get(thisLabel);
496 if (nextPage)
497 {
498 nextLabel = nextPage->label;
499 nextFilename = nextPage->filename;
500 }
501 if (previousLabel && previousFilename)
502 {
503 TexNextPage *oldNextPage = (TexNextPage *)TexNextPages.Get(previousLabel);
504 if (oldNextPage)
505 {
506 delete oldNextPage;
507 TexNextPages.Delete(previousLabel);
508 }
509 TexNextPage *newNextPage = new TexNextPage(thisLabel, thisFilename);
510 TexNextPages.Put(previousLabel, newNextPage);
511 }
512
513 /*
514 * >> button
515 *
516 */
517
518 if (nextLabel && nextFilename)
519 {
520 wxSprintf(buf, _T("<A HREF=\"%s#%s\">%s</A> "), ConvertCase(nextFilename), nextLabel, forwardReference);
521 TexOutput(buf);
522 }
523 else
524 {
525 // A placeholder so the buttons don't keep moving position
526 wxSprintf(buf, _T("%s "), forwardReference);
527 TexOutput(buf);
528 }
529
530 /*
531 * Horizontal rule to finish it off nicely.
532 *
533 */
534 TexOutput(_T("</CENTER>"));
535 TexOutput(_T("<HR>\n"));
536
537 // Update last topic/filename
538 if (lastFileName)
539 delete[] lastFileName;
540 lastFileName = copystring(thisFilename);
541 if (lastTopic)
542 delete[] lastTopic;
543 lastTopic = copystring(thisLabel);
544 }
545
546 // A colour string is either 3 numbers separated by semicolons (RGB),
547 // or a reference to a GIF. Return the filename or a hex string like #934CE8
548 wxChar *ParseColourString(wxChar *bkStr, bool *isPicture)
549 {
550 static wxChar resStr[300];
551 wxStrcpy(resStr, bkStr);
552 wxStringTokenizer tok(resStr, _T(";"), wxTOKEN_STRTOK);
553 if (tok.HasMoreTokens())
554 {
555 wxString token1 = tok.GetNextToken();
556 if (!tok.HasMoreTokens())
557 {
558 *isPicture = TRUE;
559 return resStr;
560 }
561 else
562 {
563 wxString token2 = tok.GetNextToken();
564 *isPicture = FALSE;
565 if (tok.HasMoreTokens())
566 {
567 wxString token3 = tok.GetNextToken();
568
569 // Now convert 3 strings into decimal numbers, and then hex numbers.
570 int red = wxAtoi(token1.c_str());
571 int green = wxAtoi(token2.c_str());
572 int blue = wxAtoi(token3.c_str());
573
574 wxStrcpy(resStr, _T("#"));
575
576 wxChar buf[3];
577 DecToHex(red, buf);
578 wxStrcat(resStr, buf);
579 DecToHex(green, buf);
580 wxStrcat(resStr, buf);
581 DecToHex(blue, buf);
582 wxStrcat(resStr, buf);
583 return resStr;
584 }
585 else return NULL;
586 }
587 }
588 else return NULL;
589 }
590
591 void OutputFont(void)
592 {
593 // Only output <font face> if explicitly requested by htmlFaceName= directive in
594 // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's
595 // default font:
596 if (htmlFaceName)
597 {
598 // Output <FONT FACE=...>
599 TexOutput(_T("<FONT FACE=\""));
600 TexOutput(htmlFaceName);
601 TexOutput(_T("\">\n"));
602 }
603 }
604
605 // Output start of <BODY> block
606 void OutputBodyStart(void)
607 {
608 TexOutput(_T("\n<BODY"));
609 if (backgroundImageString)
610 {
611 bool isPicture = FALSE;
612 wxChar *s = ParseColourString(backgroundImageString, &isPicture);
613 if (s)
614 {
615 TexOutput(_T(" BACKGROUND=\""));
616 TexOutput(s);
617 TexOutput(_T("\""));
618 }
619 }
620 if (backgroundColourString)
621 {
622 bool isPicture = FALSE;
623 wxChar *s = ParseColourString(backgroundColourString, &isPicture);
624 if (s)
625 {
626 TexOutput(_T(" BGCOLOR="));
627 TexOutput(s);
628 }
629 }
630
631 // Set foreground text colour, if one is specified
632 if (textColourString)
633 {
634 bool isPicture = FALSE;
635 wxChar *s = ParseColourString(textColourString, &isPicture);
636 if (s)
637 {
638 TexOutput(_T(" TEXT=")); TexOutput(s);
639 }
640 }
641 // Set link text colour, if one is specified
642 if (linkColourString)
643 {
644 bool isPicture = FALSE;
645 wxChar *s = ParseColourString(linkColourString, &isPicture);
646 if (s)
647 {
648 TexOutput(_T(" LINK=")); TexOutput(s);
649 }
650 }
651 // Set followed link text colour, if one is specified
652 if (followedLinkColourString)
653 {
654 bool isPicture = FALSE;
655 wxChar *s = ParseColourString(followedLinkColourString, &isPicture);
656 if (s)
657 {
658 TexOutput(_T(" VLINK=")); TexOutput(s);
659 }
660 }
661 TexOutput(_T(">\n"));
662
663 OutputFont();
664 }
665
666 void HTMLHead()
667 {
668 TexOutput(_T("<head>"));
669 if (htmlStylesheet) {
670 TexOutput(_T("<link rel=stylesheet type=\"text/css\" href=\""));
671 TexOutput(htmlStylesheet);
672 TexOutput(_T("\">"));
673 }
674 };
675
676 void HTMLHeadTo(FILE* f)
677 {
678 if (htmlStylesheet)
679 wxFprintf(f,_T("<head><link rel=stylesheet type=\"text/css\" href=\"%s\">"),htmlStylesheet);
680 else
681 wxFprintf(f,_T("<head>"));
682 }
683
684 // Called on start/end of macro examination
685 void HTMLOnMacro(int macroId, int no_args, bool start)
686 {
687 switch (macroId)
688 {
689 case ltCHAPTER:
690 case ltCHAPTERSTAR:
691 case ltCHAPTERHEADING:
692 {
693 if (!start)
694 {
695 sectionNo = 0;
696 figureNo = 0;
697 subsectionNo = 0;
698 subsubsectionNo = 0;
699 if (macroId != ltCHAPTERSTAR)
700 chapterNo ++;
701
702 SetCurrentOutput(NULL);
703 startedSections = TRUE;
704
705 wxChar *topicName = FindTopicName(GetNextChunk());
706 ReopenFile(&Chapters, &ChaptersName);
707 AddTexRef(topicName, ChaptersName, ChapterNameString);
708
709 SetCurrentChapterName(topicName, ChaptersName);
710 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(0, topicName, ChaptersName);
711
712 SetCurrentOutput(Chapters);
713
714 HTMLHead();
715 TexOutput(_T("<title>"));
716 OutputCurrentSection(); // Repeat section header
717 TexOutput(_T("</title></head>\n"));
718 OutputBodyStart();
719
720 wxChar titleBuf[200];
721 if (truncateFilenames)
722 wxSprintf(titleBuf, _T("%s.htm"), wxFileNameFromPath(FileRoot));
723 else
724 wxSprintf(titleBuf, _T("%s_contents.html"), wxFileNameFromPath(FileRoot));
725
726 wxFprintf(Chapters, _T("<A NAME=\"%s\"></A>"), topicName);
727
728 AddBrowseButtons(_T(""), titleBuf, // Up
729 lastTopic, lastFileName, // Last topic
730 topicName, ChaptersName); // This topic
731
732 wxFprintf(Contents, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName), topicName);
733
734 if (htmlFrameContents && FrameContents)
735 {
736 SetCurrentOutput(FrameContents);
737 wxFprintf(FrameContents, _T("\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName), topicName);
738 OutputCurrentSection();
739 wxFprintf(FrameContents, _T("</A>\n"));
740 }
741
742 SetCurrentOutputs(Contents, Chapters);
743 wxFprintf(Chapters, _T("\n<H2>"));
744 OutputCurrentSection();
745 wxFprintf(Contents, _T("</A>\n"));
746 wxFprintf(Chapters, _T("</H2>\n"));
747
748 SetCurrentOutput(Chapters);
749
750 // Add this section title to the list of keywords
751 if (htmlIndex)
752 {
753 OutputCurrentSectionToString(wxTex2RTFBuffer);
754 AddKeyWordForTopic(topicName, wxTex2RTFBuffer, ConvertCase(currentFileName));
755 }
756 }
757 break;
758 }
759 case ltSECTION:
760 case ltSECTIONSTAR:
761 case ltSECTIONHEADING:
762 case ltGLOSS:
763 {
764 if (!start)
765 {
766 subsectionNo = 0;
767 subsubsectionNo = 0;
768 subsectionStarted = FALSE;
769
770 if (macroId != ltSECTIONSTAR)
771 sectionNo ++;
772
773 SetCurrentOutput(NULL);
774 startedSections = TRUE;
775
776 wxChar *topicName = FindTopicName(GetNextChunk());
777 ReopenFile(&Sections, &SectionsName);
778 AddTexRef(topicName, SectionsName, SectionNameString);
779
780 SetCurrentSectionName(topicName, SectionsName);
781 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(1, topicName, SectionsName);
782
783 SetCurrentOutput(Sections);
784 HTMLHead();
785 TexOutput(_T("<title>"));
786 OutputCurrentSection();
787 TexOutput(_T("</title></head>\n"));
788 OutputBodyStart();
789
790 wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName);
791 AddBrowseButtons(CurrentChapterName, CurrentChapterFile, // Up
792 lastTopic, lastFileName, // Last topic
793 topicName, SectionsName); // This topic
794
795 FILE *jumpFrom = ((DocumentStyle == LATEX_ARTICLE) ? Contents : Chapters);
796
797 SetCurrentOutputs(jumpFrom, Sections);
798 if (DocumentStyle == LATEX_ARTICLE)
799 wxFprintf(jumpFrom, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(SectionsName), topicName);
800 else
801 wxFprintf(jumpFrom, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SectionsName), topicName);
802
803 wxFprintf(Sections, _T("\n<H2>"));
804 OutputCurrentSection();
805
806 if (DocumentStyle == LATEX_ARTICLE)
807 wxFprintf(jumpFrom, _T("</A>\n"));
808 else
809 wxFprintf(jumpFrom, _T("</B></A><BR>\n"));
810 wxFprintf(Sections, _T("</H2>\n"));
811
812 SetCurrentOutput(Sections);
813 // Add this section title to the list of keywords
814 if (htmlIndex)
815 {
816 OutputCurrentSectionToString(wxTex2RTFBuffer);
817 AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName);
818 }
819 }
820 break;
821 }
822 case ltSUBSECTION:
823 case ltSUBSECTIONSTAR:
824 case ltMEMBERSECTION:
825 case ltFUNCTIONSECTION:
826 {
827 if (!start)
828 {
829 if (!Sections)
830 {
831 OnError(_T("You cannot have a subsection before a section!"));
832 }
833 else
834 {
835 subsubsectionNo = 0;
836
837 if (macroId != ltSUBSECTIONSTAR)
838 subsectionNo ++;
839
840 if ( combineSubSections && !subsectionStarted )
841 {
842 // Read old .con file in at this point
843 wxChar buf[256];
844 wxStrcpy(buf, CurrentSectionFile);
845 wxStripExtension(buf);
846 wxStrcat(buf, _T(".con"));
847 FILE *fd = wxFopen(buf, _T("r"));
848 if ( fd )
849 {
850 int ch = getc(fd);
851 while (ch != EOF)
852 {
853 putc(ch, Sections);
854 ch = getc(fd);
855 }
856 fclose(fd);
857 }
858 wxFprintf(Sections, _T("<P>\n"));
859
860 // Close old file, create a new file for the sub(sub)section contents entries
861 ReopenSectionContentsFile();
862 }
863
864 startedSections = TRUE;
865 subsectionStarted = TRUE;
866
867 wxChar *topicName = FindTopicName(GetNextChunk());
868
869 if ( !combineSubSections )
870 {
871 SetCurrentOutput(NULL);
872 ReopenFile(&Subsections, &SubsectionsName);
873 AddTexRef(topicName, SubsectionsName, SubsectionNameString);
874 SetCurrentSubsectionName(topicName, SubsectionsName);
875 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SubsectionsName);
876 SetCurrentOutput(Subsections);
877
878 HTMLHead();
879 TexOutput(_T("<title>"));
880 OutputCurrentSection();
881 TexOutput(_T("</title></head>\n"));
882 OutputBodyStart();
883
884 wxFprintf(Subsections, _T("<A NAME=\"%s\"></A>"), topicName);
885 AddBrowseButtons(CurrentSectionName, CurrentSectionFile, // Up
886 lastTopic, lastFileName, // Last topic
887 topicName, SubsectionsName); // This topic
888
889 SetCurrentOutputs(Sections, Subsections);
890 wxFprintf(Sections, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName), topicName);
891
892 wxFprintf(Subsections, _T("\n<H3>"));
893 OutputCurrentSection();
894 wxFprintf(Sections, _T("</B></A><BR>\n"));
895 wxFprintf(Subsections, _T("</H3>\n"));
896
897 SetCurrentOutput(Subsections);
898 }
899 else
900 {
901 AddTexRef(topicName, SectionsName, SubsectionNameString);
902 SetCurrentSubsectionName(topicName, SectionsName);
903
904 // if ( subsectionNo != 0 )
905 wxFprintf(Sections, _T("\n<HR>\n"));
906
907 // We're putting everything into the section file
908 wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName);
909 wxFprintf(Sections, _T("\n<H3>"));
910 OutputCurrentSection();
911 wxFprintf(Sections, _T("</H3>\n"));
912
913 SetCurrentOutput(SectionContentsFD);
914 wxFprintf(SectionContentsFD, _T("<A HREF=\"#%s\">"), topicName);
915 OutputCurrentSection();
916 TexOutput(_T("</A><BR>\n"));
917
918 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName);
919 SetCurrentOutput(Sections);
920 }
921 // Add this section title to the list of keywords
922 if (htmlIndex)
923 {
924 OutputCurrentSectionToString(wxTex2RTFBuffer);
925 AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName);
926 }
927
928 }
929 }
930 break;
931 }
932 case ltSUBSUBSECTION:
933 case ltSUBSUBSECTIONSTAR:
934 {
935 if (!start)
936 {
937 if (!Subsections && !combineSubSections)
938 {
939 OnError(_T("You cannot have a subsubsection before a subsection!"));
940 }
941 else
942 {
943 if (macroId != ltSUBSUBSECTIONSTAR)
944 subsubsectionNo ++;
945
946 startedSections = TRUE;
947
948 wxChar *topicName = FindTopicName(GetNextChunk());
949
950 if ( !combineSubSections )
951 {
952 SetCurrentOutput(NULL);
953 ReopenFile(&Subsubsections, &SubsubsectionsName);
954 AddTexRef(topicName, SubsubsectionsName, SubsubsectionNameString);
955 SetCurrentSubsubsectionName(topicName, SubsubsectionsName);
956 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(3, topicName, SubsubsectionsName);
957
958 SetCurrentOutput(Subsubsections);
959 HTMLHead();
960 TexOutput(_T("<title>"));
961 OutputCurrentSection();
962 TexOutput(_T("</title></head>\n"));
963 OutputBodyStart();
964
965 wxFprintf(Subsubsections, _T("<A NAME=\"%s\"></A>"), topicName);
966
967 AddBrowseButtons(CurrentSubsectionName, CurrentSubsectionFile, // Up
968 lastTopic, lastFileName, // Last topic
969 topicName, SubsubsectionsName); // This topic
970
971 SetCurrentOutputs(Subsections, Subsubsections);
972 wxFprintf(Subsections, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName), topicName);
973
974 wxFprintf(Subsubsections, _T("\n<H3>"));
975 OutputCurrentSection();
976 wxFprintf(Subsections, _T("</B></A><BR>\n"));
977 wxFprintf(Subsubsections, _T("</H3>\n"));
978 }
979 else
980 {
981 AddTexRef(topicName, SectionsName, SubsubsectionNameString);
982 SetCurrentSubsectionName(topicName, SectionsName);
983 wxFprintf(Sections, _T("\n<HR>\n"));
984
985 // We're putting everything into the section file
986 wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName);
987 wxFprintf(Sections, _T("\n<H3>"));
988 OutputCurrentSection();
989 wxFprintf(Sections, _T("</H3>\n"));
990 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
991 SetCurrentOutput(SectionContentsFD);
992 wxFprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
993 OutputCurrentSection();
994 TexOutput(_T("</A><BR>"));
995 */
996 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName);
997 SetCurrentOutput(Sections);
998 }
999
1000 // Add this section title to the list of keywords
1001 if (htmlIndex)
1002 {
1003 OutputCurrentSectionToString(wxTex2RTFBuffer);
1004 AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName);
1005 }
1006 }
1007 }
1008 break;
1009 }
1010 case ltFUNC:
1011 case ltPFUNC:
1012 {
1013 if ( !combineSubSections )
1014 SetCurrentOutput(Subsections);
1015 else
1016 SetCurrentOutput(Sections);
1017 if (start)
1018 {
1019 }
1020 else
1021 {
1022 }
1023 break;
1024 }
1025 case ltCLIPSFUNC:
1026 {
1027 if ( !combineSubSections )
1028 SetCurrentOutput(Subsections);
1029 else
1030 SetCurrentOutput(Sections);
1031 if (start)
1032 {
1033 }
1034 else
1035 {
1036 }
1037 break;
1038 }
1039 case ltMEMBER:
1040 {
1041 if ( !combineSubSections )
1042 SetCurrentOutput(Subsections);
1043 else
1044 SetCurrentOutput(Sections);
1045 if (start)
1046 {
1047 }
1048 else
1049 {
1050 }
1051 break;
1052 }
1053 case ltVOID:
1054 // if (start)
1055 // TexOutput(_T("<B>void</B>"));
1056 break;
1057 case ltHARDY:
1058 if (start)
1059 TexOutput(_T("HARDY"));
1060 break;
1061 case ltWXCLIPS:
1062 if (start)
1063 TexOutput(_T("wxCLIPS"));
1064 break;
1065 case ltAMPERSAND:
1066 if (start)
1067 TexOutput(_T("&amp;"));
1068 break;
1069 case ltSPECIALAMPERSAND:
1070 {
1071 if (start)
1072 {
1073 if (inTabular)
1074 {
1075 // End cell, start cell
1076
1077 TexOutput(_T("</FONT></TD>"));
1078
1079 // Start new row and cell, setting alignment for the first cell.
1080 if (currentColumn < noColumns)
1081 currentColumn ++;
1082
1083 wxChar buf[100];
1084 if (TableData[currentColumn].justification == 'c')
1085 wxSprintf(buf, _T("\n<TD ALIGN=CENTER>"));
1086 else if (TableData[currentColumn].justification == 'r')
1087 wxSprintf(buf, _T("\n<TD ALIGN=RIGHT>"));
1088 else if (TableData[currentColumn].absWidth)
1089 {
1090 // Convert from points * 20 into pixels.
1091 int points = TableData[currentColumn].width / 20;
1092
1093 // Say the display is 100 DPI (dots/pixels per inch).
1094 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1095 int pixels = (int)(points * 100.0 / 72.0);
1096 wxSprintf(buf, _T("<TD ALIGN=CENTER WIDTH=%d>"), pixels);
1097 }
1098 else
1099 wxSprintf(buf, _T("\n<TD ALIGN=LEFT>"));
1100 TexOutput(buf);
1101 OutputFont();
1102 }
1103 else
1104 TexOutput(_T("&amp;"));
1105 }
1106 break;
1107 }
1108 case ltBACKSLASHCHAR:
1109 {
1110 if (start)
1111 {
1112 if (inTabular)
1113 {
1114 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1115 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1116 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1117 TexOutput(_T("</TR>\n"));
1118 }
1119 else
1120 TexOutput(_T("<BR>\n"));
1121 }
1122 break;
1123 }
1124 case ltROW:
1125 case ltRULEDROW:
1126 {
1127 if (start)
1128 {
1129 currentColumn = 0;
1130
1131 // Start new row and cell, setting alignment for the first cell.
1132 wxChar buf[100];
1133 if (TableData[currentColumn].justification == 'c')
1134 wxSprintf(buf, _T("<TR>\n<TD ALIGN=CENTER>"));
1135 else if (TableData[currentColumn].justification == 'r')
1136 wxSprintf(buf, _T("<TR>\n<TD ALIGN=RIGHT>"));
1137 else if (TableData[currentColumn].absWidth)
1138 {
1139 // Convert from points * 20 into pixels.
1140 int points = TableData[currentColumn].width / 20;
1141
1142 // Say the display is 100 DPI (dots/pixels per inch).
1143 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1144 int pixels = (int)(points * 100.0 / 72.0);
1145 wxSprintf(buf, _T("<TR>\n<TD ALIGN=CENTER WIDTH=%d>"), pixels);
1146 }
1147 else
1148 wxSprintf(buf, _T("<TR>\n<TD ALIGN=LEFT>"));
1149 TexOutput(buf);
1150 OutputFont();
1151 }
1152 else
1153 {
1154 // End cell and row
1155 // Start new row and cell
1156 TexOutput(_T("</FONT></TD>\n</TR>\n"));
1157 }
1158 break;
1159 }
1160 // HTML-only: break until the end of the picture (both margins are clear).
1161 case ltBRCLEAR:
1162 {
1163 if (start)
1164 TexOutput(_T("<BR CLEAR=ALL>"));
1165 break;
1166 }
1167 case ltRTFSP: // Explicit space, RTF only
1168 break;
1169 case ltSPECIALTILDE:
1170 {
1171 if (start)
1172 {
1173 if (inVerbatim)
1174 TexOutput(_T("~"));
1175 else
1176 TexOutput(_T(" "));
1177 }
1178 break;
1179 }
1180 case ltINDENTED :
1181 {
1182 if ( start )
1183 TexOutput(_T("<UL><UL>\n"));
1184 else
1185 TexOutput(_T("</UL></UL>\n"));
1186 break;
1187 }
1188 case ltITEMIZE:
1189 case ltENUMERATE:
1190 case ltDESCRIPTION:
1191 // case ltTWOCOLLIST:
1192 {
1193 if (start)
1194 {
1195 indentLevel ++;
1196
1197 int listType;
1198 if (macroId == ltENUMERATE)
1199 listType = LATEX_ENUMERATE;
1200 else if (macroId == ltITEMIZE)
1201 listType = LATEX_ITEMIZE;
1202 else
1203 listType = LATEX_DESCRIPTION;
1204
1205 itemizeStack.Insert(new ItemizeStruc(listType));
1206 switch (listType)
1207 {
1208 case LATEX_ITEMIZE:
1209 TexOutput(_T("<UL>\n"));
1210 break;
1211 case LATEX_ENUMERATE:
1212 TexOutput(_T("<OL>\n"));
1213 break;
1214 case LATEX_DESCRIPTION:
1215 default:
1216 TexOutput(_T("<DL>\n"));
1217 break;
1218 }
1219 }
1220 else
1221 {
1222 indentLevel --;
1223 if (itemizeStack.GetFirst())
1224 {
1225 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
1226 switch (struc->listType)
1227 {
1228 case LATEX_ITEMIZE:
1229 TexOutput(_T("</UL>\n"));
1230 break;
1231 case LATEX_ENUMERATE:
1232 TexOutput(_T("</OL>\n"));
1233 break;
1234 case LATEX_DESCRIPTION:
1235 default:
1236 TexOutput(_T("</DL>\n"));
1237 break;
1238 }
1239
1240 delete struc;
1241 delete itemizeStack.GetFirst();
1242 }
1243 }
1244 break;
1245 }
1246 case ltTWOCOLLIST :
1247 {
1248 if ( start )
1249 TexOutput(_T("\n<TABLE>\n"));
1250 else {
1251 TexOutput(_T("\n</TABLE>\n"));
1252 // DHS
1253 TwoColWidthA = -1;
1254 TwoColWidthB = -1;
1255 }
1256 break;
1257 }
1258 case ltPAR:
1259 {
1260 if (start)
1261 TexOutput(_T("<P>\n"));
1262 break;
1263 }
1264 /* For footnotes we need to output the text at the bottom of the page and
1265 * insert a reference to it. Is it worth the trouble...
1266 case ltFOOTNOTE:
1267 case ltFOOTNOTEPOPUP:
1268 {
1269 if (start)
1270 {
1271 TexOutput(_T("<FN>"));
1272 }
1273 else TexOutput(_T("</FN>"));
1274 break;
1275 }
1276 */
1277 case ltVERB:
1278 {
1279 if (start)
1280 TexOutput(_T("<TT>"));
1281 else TexOutput(_T("</TT>"));
1282 break;
1283 }
1284 case ltVERBATIM:
1285 {
1286 if (start)
1287 {
1288 wxChar buf[100];
1289 wxSprintf(buf, _T("<PRE>\n"));
1290 TexOutput(buf);
1291 }
1292 else TexOutput(_T("</PRE>\n"));
1293 break;
1294 }
1295 case ltCENTERLINE:
1296 case ltCENTER:
1297 {
1298 if (start)
1299 {
1300 TexOutput(_T("<CENTER>"));
1301 }
1302 else TexOutput(_T("</CENTER>"));
1303 break;
1304 }
1305 case ltFLUSHLEFT:
1306 {
1307 /*
1308 if (start)
1309 {
1310 TexOutput(_T("{\\ql "));
1311 }
1312 else TexOutput(_T("}\\par\\pard\n"));
1313 */
1314 break;
1315 }
1316 case ltFLUSHRIGHT:
1317 {
1318 /*
1319 if (start)
1320 {
1321 TexOutput(_T("{\\qr "));
1322 }
1323 else TexOutput(_T("}\\par\\pard\n"));
1324 */
1325 break;
1326 }
1327 case ltSMALL:
1328 {
1329 if (start)
1330 {
1331 // Netscape extension
1332 TexOutput(_T("<FONT SIZE=2>"));
1333 }
1334 else TexOutput(_T("</FONT>"));
1335 break;
1336 }
1337 case ltTINY:
1338 {
1339 if (start)
1340 {
1341 // Netscape extension
1342 TexOutput(_T("<FONT SIZE=1>"));
1343 }
1344 else TexOutput(_T("</FONT>"));
1345 break;
1346 }
1347 case ltNORMALSIZE:
1348 {
1349 if (start)
1350 {
1351 // Netscape extension
1352 TexOutput(_T("<FONT SIZE=3>"));
1353 }
1354 else TexOutput(_T("</FONT>"));
1355 break;
1356 }
1357 case ltlarge:
1358 {
1359 if (start)
1360 {
1361 // Netscape extension
1362 TexOutput(_T("<FONT SIZE=4>"));
1363 }
1364 else TexOutput(_T("</FONT>"));
1365 break;
1366 }
1367 case ltLarge:
1368 {
1369 if (start)
1370 {
1371 // Netscape extension
1372 TexOutput(_T("<FONT SIZE=5>"));
1373 }
1374 else TexOutput(_T("</FONT>"));
1375 break;
1376 }
1377 case ltLARGE:
1378 {
1379 if (start)
1380 {
1381 // Netscape extension
1382 TexOutput(_T("<FONT SIZE=6>"));
1383 }
1384 else TexOutput(_T("</FONT>"));
1385 break;
1386 }
1387 case ltBFSERIES:
1388 case ltTEXTBF:
1389 case ltBF:
1390 {
1391 if (start)
1392 {
1393 TexOutput(_T("<B>"));
1394 }
1395 else TexOutput(_T("</B>"));
1396 break;
1397 }
1398 case ltITSHAPE:
1399 case ltTEXTIT:
1400 case ltIT:
1401 {
1402 if (start)
1403 {
1404 TexOutput(_T("<I>"));
1405 }
1406 else TexOutput(_T("</I>"));
1407 break;
1408 }
1409 case ltEMPH:
1410 case ltEM:
1411 {
1412 if (start)
1413 {
1414 TexOutput(_T("<EM>"));
1415 }
1416 else TexOutput(_T("</EM>"));
1417 break;
1418 }
1419 case ltUNDERLINE:
1420 {
1421 if (start)
1422 {
1423 TexOutput(_T("<UL>"));
1424 }
1425 else TexOutput(_T("</UL>"));
1426 break;
1427 }
1428 case ltTTFAMILY:
1429 case ltTEXTTT:
1430 case ltTT:
1431 {
1432 if (start)
1433 {
1434 TexOutput(_T("<TT>"));
1435 }
1436 else TexOutput(_T("</TT>"));
1437 break;
1438 }
1439 case ltCOPYRIGHT:
1440 {
1441 if (start)
1442 TexOutput(_T("&copy;"), TRUE);
1443 break;
1444 }
1445 case ltREGISTERED:
1446 {
1447 if (start)
1448 TexOutput(_T("&reg;"), TRUE);
1449 break;
1450 }
1451 // Arrows
1452 case ltLEFTARROW:
1453 {
1454 if (start) TexOutput(_T("&lt;--"));
1455 break;
1456 }
1457 case ltLEFTARROW2:
1458 {
1459 if (start) TexOutput(_T("&lt;=="));
1460 break;
1461 }
1462 case ltRIGHTARROW:
1463 {
1464 if (start) TexOutput(_T("--&gt;"));
1465 break;
1466 }
1467 case ltRIGHTARROW2:
1468 {
1469 if (start) TexOutput(_T("==&gt;"));
1470 break;
1471 }
1472 case ltLEFTRIGHTARROW:
1473 {
1474 if (start) TexOutput(_T("&lt;--&gt;"));
1475 break;
1476 }
1477 case ltLEFTRIGHTARROW2:
1478 {
1479 if (start) TexOutput(_T("&lt;==&gt;"));
1480 break;
1481 }
1482 /*
1483 case ltSC:
1484 {
1485 break;
1486 }
1487 */
1488 case ltITEM:
1489 {
1490 if (!start)
1491 {
1492 wxNode *node = itemizeStack.GetFirst();
1493 if (node)
1494 {
1495 ItemizeStruc *struc = (ItemizeStruc *)node->GetData();
1496 struc->currentItem += 1;
1497 if (struc->listType == LATEX_DESCRIPTION)
1498 {
1499 if (descriptionItemArg)
1500 {
1501 TexOutput(_T("<DT> "));
1502 TraverseChildrenFromChunk(descriptionItemArg);
1503 TexOutput(_T("\n"));
1504 descriptionItemArg = NULL;
1505 }
1506 TexOutput(_T("<DD>"));
1507 }
1508 else
1509 TexOutput(_T("<LI>"));
1510 }
1511 }
1512 break;
1513 }
1514 case ltMAKETITLE:
1515 {
1516 if (start && DocumentTitle && DocumentAuthor)
1517 {
1518 // Add a special label for the contents page.
1519 // TexOutput(_T("<CENTER>\n"));
1520 TexOutput(_T("<A NAME=\"contents\">"));
1521 TexOutput(_T("<H2 ALIGN=CENTER>\n"));
1522 TraverseChildrenFromChunk(DocumentTitle);
1523 TexOutput(_T("</H2>"));
1524 TexOutput(_T("<P>"));
1525 TexOutput(_T("</A>\n"));
1526 TexOutput(_T("<P>\n\n"));
1527 TexOutput(_T("<H3 ALIGN=CENTER>"));
1528 TraverseChildrenFromChunk(DocumentAuthor);
1529 TexOutput(_T("</H3><P>\n\n"));
1530 if (DocumentDate)
1531 {
1532 TexOutput(_T("<H3 ALIGN=CENTER>"));
1533 TraverseChildrenFromChunk(DocumentDate);
1534 TexOutput(_T("</H3><P>\n\n"));
1535 }
1536 // TexOutput(_T("\n</CENTER>\n"));
1537 TexOutput(_T("\n<P><HR><P>\n"));
1538
1539 /*
1540 // Now do optional frame contents page
1541 if (htmlFrameContents && FrameContents)
1542 {
1543 SetCurrentOutput(FrameContents);
1544
1545 // Add a special label for the contents page.
1546 TexOutput(_T("<CENTER>\n"));
1547 TexOutput(_T("<H3>\n"));
1548 TraverseChildrenFromChunk(DocumentTitle);
1549 TexOutput(_T("</H3>"));
1550 TexOutput(_T("<P>"));
1551 TexOutput(_T("</A>\n"));
1552 TexOutput(_T("<P>\n\n"));
1553 TexOutput(_T("<H3>"));
1554 TraverseChildrenFromChunk(DocumentAuthor);
1555 TexOutput(_T("</H3><P>\n\n"));
1556 if (DocumentDate)
1557 {
1558 TexOutput(_T("<H4>"));
1559 TraverseChildrenFromChunk(DocumentDate);
1560 TexOutput(_T("</H4><P>\n\n"));
1561 }
1562 TexOutput(_T("\n</CENTER>\n"));
1563 TexOutput(_T("<P><HR><P>\n"));
1564
1565 SetCurrentOutput(Titlepage);
1566 }
1567 */
1568 }
1569 break;
1570 }
1571 case ltHELPREF:
1572 case ltHELPREFN:
1573 case ltPOPREF:
1574 case ltURLREF:
1575 {
1576 if (start)
1577 {
1578 helpRefFilename = NULL;
1579 helpRefText = NULL;
1580 }
1581 break;
1582 }
1583 case ltBIBLIOGRAPHY:
1584 {
1585 if (start)
1586 {
1587 DefaultOnMacro(macroId, no_args, start);
1588 }
1589 else
1590 {
1591 DefaultOnMacro(macroId, no_args, start);
1592 TexOutput(_T("</DL>\n"));
1593 }
1594 break;
1595 }
1596 case ltHRULE:
1597 {
1598 if (start)
1599 {
1600 TexOutput(_T("<HR>\n"));
1601 }
1602 break;
1603 }
1604 case ltRULE:
1605 {
1606 if (start)
1607 {
1608 TexOutput(_T("<HR>\n"));
1609 }
1610 break;
1611 }
1612 case ltTABLEOFCONTENTS:
1613 {
1614 if (start)
1615 {
1616 FILE *fd = wxFopen(ContentsName, _T("r"));
1617 if (fd)
1618 {
1619 int ch = getc(fd);
1620 while (ch != EOF)
1621 {
1622 putc(ch, Titlepage);
1623 ch = getc(fd);
1624 }
1625 fclose(fd);
1626 }
1627 else
1628 {
1629 TexOutput(_T("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n"));
1630 OnInform(_T("Run Tex2RTF again to include contents page."));
1631 }
1632 }
1633 break;
1634 }
1635 case ltLANGLEBRA:
1636 {
1637 if (start)
1638 TexOutput(_T("&lt;"));
1639 break;
1640 }
1641 case ltRANGLEBRA:
1642 {
1643 if (start)
1644 TexOutput(_T("&gt;"));
1645 break;
1646 }
1647 case ltQUOTE:
1648 case ltQUOTATION:
1649 {
1650 if (start)
1651 TexOutput(_T("<BLOCKQUOTE>"));
1652 else
1653 TexOutput(_T("</BLOCKQUOTE>"));
1654 break;
1655 }
1656 case ltCAPTION:
1657 case ltCAPTIONSTAR:
1658 {
1659 if (start)
1660 {
1661 if (inTabular)
1662 TexOutput(_T("\n<CAPTION>"));
1663
1664 wxChar figBuf[40];
1665
1666 if ( inFigure )
1667 {
1668 figureNo ++;
1669
1670 if (DocumentStyle != LATEX_ARTICLE)
1671 wxSprintf(figBuf, _T("%s %d.%d: "), FigureNameString, chapterNo, figureNo);
1672 else
1673 wxSprintf(figBuf, _T("%s %d: "), FigureNameString, figureNo);
1674 }
1675 else
1676 {
1677 tableNo ++;
1678
1679 if (DocumentStyle != LATEX_ARTICLE)
1680 wxSprintf(figBuf, _T("%s %d.%d: "), TableNameString, chapterNo, tableNo);
1681 else
1682 wxSprintf(figBuf, _T("%s %d: "), TableNameString, tableNo);
1683 }
1684
1685 TexOutput(figBuf);
1686 }
1687 else
1688 {
1689 if (inTabular)
1690 TexOutput(_T("\n</CAPTION>\n"));
1691
1692 wxChar *topicName = FindTopicName(GetNextChunk());
1693
1694 int n = inFigure ? figureNo : tableNo;
1695
1696 AddTexRef(topicName, NULL, NULL,
1697 ((DocumentStyle != LATEX_ARTICLE) ? chapterNo : n),
1698 ((DocumentStyle != LATEX_ARTICLE) ? n : 0));
1699 }
1700 break;
1701 }
1702 case ltSS:
1703 {
1704 if (start) TexOutput(_T("&szlig;"));
1705 break;
1706 }
1707 case ltFIGURE:
1708 {
1709 if (start) inFigure = TRUE;
1710 else inFigure = FALSE;
1711 break;
1712 }
1713 case ltTABLE:
1714 {
1715 if (start) inTable = TRUE;
1716 else inTable = FALSE;
1717 break;
1718 }
1719 default:
1720 DefaultOnMacro(macroId, no_args, start);
1721 break;
1722 }
1723 }
1724
1725 // Called on start/end of argument examination
1726 bool HTMLOnArgument(int macroId, int arg_no, bool start)
1727 {
1728 switch (macroId)
1729 {
1730 case ltCHAPTER:
1731 case ltCHAPTERSTAR:
1732 case ltCHAPTERHEADING:
1733 case ltSECTION:
1734 case ltSECTIONSTAR:
1735 case ltSECTIONHEADING:
1736 case ltSUBSECTION:
1737 case ltSUBSECTIONSTAR:
1738 case ltSUBSUBSECTION:
1739 case ltSUBSUBSECTIONSTAR:
1740 case ltGLOSS:
1741 case ltMEMBERSECTION:
1742 case ltFUNCTIONSECTION:
1743 {
1744 if (!start && (arg_no == 1))
1745 currentSection = GetArgChunk();
1746 return FALSE;
1747 }
1748 case ltFUNC:
1749 {
1750 if (start && (arg_no == 1))
1751 TexOutput(_T("<B>"));
1752
1753 if (!start && (arg_no == 1))
1754 TexOutput(_T("</B> "));
1755
1756 if (start && (arg_no == 2))
1757 {
1758 if (!suppressNameDecoration) TexOutput(_T("<B>"));
1759 currentMember = GetArgChunk();
1760 }
1761 if (!start && (arg_no == 2))
1762 {
1763 if (!suppressNameDecoration) TexOutput(_T("</B>"));
1764 }
1765
1766 if (start && (arg_no == 3))
1767 TexOutput(_T("("));
1768 if (!start && (arg_no == 3))
1769 TexOutput(_T(")"));
1770 break;
1771 }
1772 case ltCLIPSFUNC:
1773 {
1774 if (start && (arg_no == 1))
1775 TexOutput(_T("<B>"));
1776 if (!start && (arg_no == 1))
1777 TexOutput(_T("</B> "));
1778
1779 if (start && (arg_no == 2))
1780 {
1781 if (!suppressNameDecoration) TexOutput(_T("( "));
1782 currentMember = GetArgChunk();
1783 }
1784 if (!start && (arg_no == 2))
1785 {
1786 }
1787
1788 if (!start && (arg_no == 3))
1789 TexOutput(_T(")"));
1790 break;
1791 }
1792 case ltPFUNC:
1793 {
1794 if (!start && (arg_no == 1))
1795 TexOutput(_T(" "));
1796
1797 if (start && (arg_no == 2))
1798 TexOutput(_T("(*"));
1799 if (!start && (arg_no == 2))
1800 TexOutput(_T(")"));
1801
1802 if (start && (arg_no == 2))
1803 currentMember = GetArgChunk();
1804
1805 if (start && (arg_no == 3))
1806 TexOutput(_T("("));
1807 if (!start && (arg_no == 3))
1808 TexOutput(_T(")"));
1809 break;
1810 }
1811 case ltPARAM:
1812 {
1813 if (start && (arg_no == 1))
1814 TexOutput(_T("<B>"));
1815 if (!start && (arg_no == 1))
1816 TexOutput(_T("</B>"));
1817 if (start && (arg_no == 2))
1818 {
1819 TexOutput(_T("<I>"));
1820 }
1821 if (!start && (arg_no == 2))
1822 {
1823 TexOutput(_T("</I>"));
1824 }
1825 break;
1826 }
1827 case ltCPARAM:
1828 {
1829 if (start && (arg_no == 1))
1830 TexOutput(_T("<B>"));
1831 if (!start && (arg_no == 1))
1832 TexOutput(_T("</B> ")); // This is the difference from param - one space!
1833 if (start && (arg_no == 2))
1834 {
1835 TexOutput(_T("<I>"));
1836 }
1837 if (!start && (arg_no == 2))
1838 {
1839 TexOutput(_T("</I>"));
1840 }
1841 break;
1842 }
1843 case ltMEMBER:
1844 {
1845 if (!start && (arg_no == 1))
1846 TexOutput(_T(" "));
1847
1848 if (start && (arg_no == 2))
1849 currentMember = GetArgChunk();
1850 break;
1851 }
1852 case ltREF:
1853 {
1854 if (start)
1855 {
1856 wxChar *sec = NULL;
1857
1858 wxChar *refName = GetArgData();
1859 if (refName)
1860 {
1861 TexRef *texRef = FindReference(refName);
1862 if (texRef)
1863 {
1864 sec = texRef->sectionNumber;
1865 }
1866 }
1867 if (sec)
1868 {
1869 TexOutput(sec);
1870 }
1871 return FALSE;
1872 }
1873 break;
1874 }
1875 case ltURLREF:
1876 {
1877 if (IsArgOptional())
1878 return FALSE;
1879 else if ((GetNoArgs() - arg_no) == 1)
1880 {
1881 if (start)
1882 helpRefText = GetArgChunk();
1883 return FALSE;
1884 }
1885 else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional
1886 {
1887 if (start)
1888 {
1889 TexChunk *ref = GetArgChunk();
1890 TexOutput(_T("<A HREF=\""));
1891 inVerbatim = TRUE;
1892 TraverseChildrenFromChunk(ref);
1893 inVerbatim = FALSE;
1894 TexOutput(_T("\">"));
1895 if (helpRefText)
1896 TraverseChildrenFromChunk(helpRefText);
1897 TexOutput(_T("</A>"));
1898 }
1899 return FALSE;
1900 }
1901 break;
1902 }
1903 case ltHELPREF:
1904 case ltHELPREFN:
1905 case ltPOPREF:
1906 {
1907 if (IsArgOptional())
1908 {
1909 if (start)
1910 helpRefFilename = GetArgChunk();
1911 return FALSE;
1912 }
1913 if ((GetNoArgs() - arg_no) == 1)
1914 {
1915 if (start)
1916 helpRefText = GetArgChunk();
1917 return FALSE;
1918 }
1919 else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional
1920 {
1921 if (start)
1922 {
1923 wxChar *refName = GetArgData();
1924 wxChar *refFilename = NULL;
1925
1926 if (refName)
1927 {
1928 TexRef *texRef = FindReference(refName);
1929 if (texRef)
1930 {
1931 if (texRef->refFile && wxStrcmp(texRef->refFile, _T("??")) != 0)
1932 refFilename = texRef->refFile;
1933
1934 TexOutput(_T("<A HREF=\""));
1935 // If a filename is supplied, use it, otherwise try to
1936 // use the filename associated with the reference (from this document).
1937 if (helpRefFilename)
1938 {
1939 TraverseChildrenFromChunk(helpRefFilename);
1940 TexOutput(_T("#"));
1941 }
1942 else if (refFilename)
1943 {
1944 TexOutput(ConvertCase(refFilename));
1945 TexOutput(_T("#"));
1946 }
1947 TexOutput(refName);
1948 TexOutput(_T("\">"));
1949 if (helpRefText)
1950 TraverseChildrenFromChunk(helpRefText);
1951 TexOutput(_T("</A>"));
1952 }
1953 else
1954 {
1955 if (helpRefText)
1956 TraverseChildrenFromChunk(helpRefText);
1957 if (!ignoreBadRefs)
1958 TexOutput(_T(" (REF NOT FOUND)"));
1959 wxString errBuf;
1960 errBuf.Printf(_T("Warning: unresolved reference '%s'"), refName);
1961 OnInform((wxChar *)errBuf.c_str());
1962 }
1963 }
1964 else TexOutput(_T("??"));
1965 }
1966 return FALSE;
1967 }
1968 break;
1969 }
1970 case ltIMAGE:
1971 case ltIMAGEL:
1972 case ltIMAGER:
1973 case ltPSBOXTO:
1974 {
1975 if (arg_no == 2)
1976 {
1977 if (start)
1978 {
1979 wxChar *alignment = _T("");
1980 if (macroId == ltIMAGEL)
1981 alignment = _T(" align=left");
1982 else if (macroId == ltIMAGER)
1983 alignment = _T(" align=right");
1984
1985 // Try to find an XBM or GIF image first.
1986 wxChar *filename = copystring(GetArgData());
1987 wxChar buf[500];
1988
1989 wxStrcpy(buf, filename);
1990 StripExtension(buf);
1991 wxStrcat(buf, _T(".xbm"));
1992 wxString f = TexPathList.FindValidPath(buf);
1993
1994 if (f == _T("")) // Try for a GIF instead
1995 {
1996 wxStrcpy(buf, filename);
1997 StripExtension(buf);
1998 wxStrcat(buf, _T(".gif"));
1999 f = TexPathList.FindValidPath(buf);
2000 }
2001
2002 if (f == _T("")) // Try for a JPEG instead
2003 {
2004 wxStrcpy(buf, filename);
2005 StripExtension(buf);
2006 wxStrcat(buf, _T(".jpg"));
2007 f = TexPathList.FindValidPath(buf);
2008 }
2009
2010 if (f == _T("")) // Try for a PNG instead
2011 {
2012 wxStrcpy(buf, filename);
2013 StripExtension(buf);
2014 wxStrcat(buf, _T(".png"));
2015 f = TexPathList.FindValidPath(buf);
2016 }
2017
2018 if (f != _T(""))
2019 {
2020 wxChar *inlineFilename = copystring(f);
2021 #if 0
2022 wxChar *originalFilename = TexPathList.FindValidPath(filename);
2023 // If we have found the existing filename, make the inline
2024 // image point to the original file (could be PS, for example)
2025 if (originalFilename && (wxStrcmp(inlineFilename, originalFilename) != 0))
2026 {
2027 TexOutput(_T("<A HREF=\""));
2028 TexOutput(ConvertCase(originalFilename));
2029 TexOutput(_T("\">"));
2030 TexOutput(_T("<img src=\""));
2031 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename)));
2032 TexOutput(_T("\""));
2033 TexOutput(alignment);
2034 TexOutput(_T("></A>"));
2035 }
2036 else
2037 #endif
2038 {
2039 TexOutput(_T("<img src=\""));
2040 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename)));
2041 TexOutput(_T("\""));
2042 TexOutput(alignment);
2043 TexOutput(_T(">"));
2044 delete[] inlineFilename;
2045 }
2046 }
2047 else
2048 {
2049 // Last resort - a link to a PS file.
2050 TexOutput(_T("<A HREF=\""));
2051 TexOutput(ConvertCase(wxFileNameFromPath(filename)));
2052 TexOutput(_T("\">Picture</A>\n"));
2053 wxSprintf(buf, _T("Warning: could not find an inline XBM/GIF for %s."), filename);
2054 OnInform(buf);
2055 }
2056 }
2057 }
2058 return FALSE;
2059 }
2060 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2061 case ltIMAGEMAP:
2062 {
2063 static wxChar *imageFile = NULL;
2064 if (start && (arg_no == 2))
2065 {
2066 // Try to find an XBM or GIF image first.
2067 wxChar *filename = copystring(GetArgData());
2068 wxChar buf[500];
2069
2070 wxStrcpy(buf, filename);
2071 StripExtension(buf);
2072 wxStrcat(buf, _T(".xbm"));
2073 wxString f = TexPathList.FindValidPath(buf);
2074
2075 if (f == _T("")) // Try for a GIF instead
2076 {
2077 wxStrcpy(buf, filename);
2078 StripExtension(buf);
2079 wxStrcat(buf, _T(".gif"));
2080 f = TexPathList.FindValidPath(buf);
2081 }
2082 if (f == _T(""))
2083 {
2084 wxChar buf[300];
2085 wxSprintf(buf, _T("Warning: could not find an inline XBM/GIF for %s."), filename);
2086 OnInform(buf);
2087 }
2088 delete[] filename;
2089 if (imageFile)
2090 delete[] imageFile;
2091 imageFile = NULL;
2092 if (!f.IsEmpty())
2093 {
2094 imageFile = copystring(f);
2095 }
2096 }
2097 else if (start && (arg_no == 3))
2098 {
2099 if (imageFile)
2100 {
2101 // First, try to find a .shg (segmented hypergraphics file)
2102 // that we can convert to a map file
2103 wxChar buf[256];
2104 wxStrcpy(buf, imageFile);
2105 StripExtension(buf);
2106 wxStrcat(buf, _T(".shg"));
2107 wxString f = TexPathList.FindValidPath(buf);
2108
2109 if (f != _T(""))
2110 {
2111 // The default HTML file to go to is THIS file (so a no-op)
2112 SHGToMap((wxChar *)f.c_str(), currentFileName);
2113 }
2114
2115 wxChar *mapName = GetArgData();
2116 TexOutput(_T("<A HREF=\"/cgi-bin/imagemap/"));
2117 if (mapName)
2118 TexOutput(mapName);
2119 else
2120 TexOutput(_T("unknown"));
2121 TexOutput(_T("\">"));
2122 TexOutput(_T("<img src=\""));
2123 TexOutput(ConvertCase(wxFileNameFromPath(imageFile)));
2124 TexOutput(_T("\" ISMAP></A><P>"));
2125 delete[] imageFile;
2126 imageFile = NULL;
2127 }
2128 }
2129 return FALSE;
2130 }
2131 case ltINDENTED :
2132 {
2133 if ( arg_no == 1 )
2134 return FALSE;
2135 else
2136 {
2137 return TRUE;
2138 }
2139 }
2140 case ltITEM:
2141 {
2142 if (start)
2143 {
2144 descriptionItemArg = GetArgChunk();
2145 return FALSE;
2146 }
2147 return TRUE;
2148 }
2149 case ltTWOCOLITEM:
2150 case ltTWOCOLITEMRULED:
2151 {
2152 /*
2153 if (start && (arg_no == 1))
2154 TexOutput(_T("\n<DT> "));
2155 if (start && (arg_no == 2))
2156 TexOutput(_T("<DD> "));
2157 */
2158 if (arg_no == 1)
2159 {
2160 if ( start ) {
2161 // DHS
2162 if (TwoColWidthA > -1) {
2163 wxChar buf[100];
2164 wxSprintf(buf,_T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA);
2165 TexOutput(buf);
2166 } else
2167 TexOutput(_T("\n<TR><TD VALIGN=TOP>\n"));
2168 OutputFont();
2169 } else
2170 TexOutput(_T("\n</FONT></TD>\n"));
2171 }
2172 if (arg_no == 2)
2173 {
2174 // DHS
2175 if ( start ) {
2176 if (TwoColWidthB > -1) {
2177 wxChar buf[100];
2178 wxSprintf(buf,_T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB);
2179 TexOutput(buf);
2180 } else
2181 TexOutput(_T("\n<TD VALIGN=TOP>\n"));
2182 OutputFont();
2183 } else
2184 TexOutput(_T("\n</FONT></TD></TR>\n"));
2185 }
2186 return TRUE;
2187 }
2188 case ltNUMBEREDBIBITEM:
2189 {
2190 if (arg_no == 1 && start)
2191 {
2192 TexOutput(_T("\n<DT> "));
2193 }
2194 if (arg_no == 2 && !start)
2195 TexOutput(_T("<P>\n"));
2196 break;
2197 }
2198 case ltBIBITEM:
2199 {
2200 wxChar buf[100];
2201 if (arg_no == 1 && start)
2202 {
2203 wxChar *citeKey = GetArgData();
2204 TexRef *ref = (TexRef *)TexReferences.Get(citeKey);
2205 if (ref)
2206 {
2207 if (ref->sectionNumber) delete[] ref->sectionNumber;
2208 wxSprintf(buf, _T("[%d]"), citeCount);
2209 ref->sectionNumber = copystring(buf);
2210 }
2211
2212 wxSprintf(buf, _T("\n<DT> [%d] "), citeCount);
2213 TexOutput(buf);
2214 citeCount ++;
2215 return FALSE;
2216 }
2217 if (arg_no == 2 && !start)
2218 TexOutput(_T("<P>\n"));
2219 return TRUE;
2220 }
2221 case ltMARGINPAR:
2222 case ltMARGINPARODD:
2223 case ltMARGINPAREVEN:
2224 case ltNORMALBOX:
2225 case ltNORMALBOXD:
2226 {
2227 if (start)
2228 {
2229 TexOutput(_T("<HR>\n"));
2230 return TRUE;
2231 }
2232 else
2233 TexOutput(_T("<HR><P>\n"));
2234 break;
2235 }
2236 // DHS
2237 case ltTWOCOLWIDTHA:
2238 {
2239 if (start)
2240 {
2241 wxChar *val = GetArgData();
2242 float points = ParseUnitArgument(val);
2243 TwoColWidthA = (int)((points * 100.0) / 72.0);
2244 }
2245 return FALSE;
2246 }
2247 // DHS
2248 case ltTWOCOLWIDTHB:
2249 {
2250 if (start)
2251 {
2252 wxChar *val = GetArgData();
2253 float points = ParseUnitArgument(val);
2254 TwoColWidthB = (int)((points * 100.0) / 72.0);
2255 }
2256 return FALSE;
2257 }
2258 /*
2259 * Accents
2260 *
2261 */
2262 case ltACCENT_GRAVE:
2263 {
2264 if (start)
2265 {
2266 wxChar *val = GetArgData();
2267 if (val)
2268 {
2269 switch (val[0])
2270 {
2271 case 'a':
2272 TexOutput(_T("&agrave;"));
2273 break;
2274 case 'e':
2275 TexOutput(_T("&egrave;"));
2276 break;
2277 case 'i':
2278 TexOutput(_T("&igrave;"));
2279 break;
2280 case 'o':
2281 TexOutput(_T("&ograve;"));
2282 break;
2283 case 'u':
2284 TexOutput(_T("&ugrave;"));
2285 break;
2286 case 'A':
2287 TexOutput(_T("&Agrave;"));
2288 break;
2289 case 'E':
2290 TexOutput(_T("&Egrave;"));
2291 break;
2292 case 'I':
2293 TexOutput(_T("&Igrave;"));
2294 break;
2295 case 'O':
2296 TexOutput(_T("&Ograve;"));
2297 break;
2298 case 'U':
2299 TexOutput(_T("&Igrave;"));
2300 break;
2301 default:
2302 break;
2303 }
2304 }
2305 }
2306 return FALSE;
2307 }
2308 case ltACCENT_ACUTE:
2309 {
2310 if (start)
2311 {
2312 wxChar *val = GetArgData();
2313 if (val)
2314 {
2315 switch (val[0])
2316 {
2317 case 'a':
2318 TexOutput(_T("&aacute;"));
2319 break;
2320 case 'e':
2321 TexOutput(_T("&eacute;"));
2322 break;
2323 case 'i':
2324 TexOutput(_T("&iacute;"));
2325 break;
2326 case 'o':
2327 TexOutput(_T("&oacute;"));
2328 break;
2329 case 'u':
2330 TexOutput(_T("&uacute;"));
2331 break;
2332 case 'y':
2333 TexOutput(_T("&yacute;"));
2334 break;
2335 case 'A':
2336 TexOutput(_T("&Aacute;"));
2337 break;
2338 case 'E':
2339 TexOutput(_T("&Eacute;"));
2340 break;
2341 case 'I':
2342 TexOutput(_T("&Iacute;"));
2343 break;
2344 case 'O':
2345 TexOutput(_T("&Oacute;"));
2346 break;
2347 case 'U':
2348 TexOutput(_T("&Uacute;"));
2349 break;
2350 case 'Y':
2351 TexOutput(_T("&Yacute;"));
2352 break;
2353 default:
2354 break;
2355 }
2356 }
2357 }
2358 return FALSE;
2359 }
2360 case ltACCENT_CARET:
2361 {
2362 if (start)
2363 {
2364 wxChar *val = GetArgData();
2365 if (val)
2366 {
2367 switch (val[0])
2368 {
2369 case 'a':
2370 TexOutput(_T("&acirc;"));
2371 break;
2372 case 'e':
2373 TexOutput(_T("&ecirc;"));
2374 break;
2375 case 'i':
2376 TexOutput(_T("&icirc;"));
2377 break;
2378 case 'o':
2379 TexOutput(_T("&ocirc;"));
2380 break;
2381 case 'u':
2382 TexOutput(_T("&ucirc;"));
2383 break;
2384 case 'A':
2385 TexOutput(_T("&Acirc;"));
2386 break;
2387 case 'E':
2388 TexOutput(_T("&Ecirc;"));
2389 break;
2390 case 'I':
2391 TexOutput(_T("&Icirc;"));
2392 break;
2393 case 'O':
2394 TexOutput(_T("&Ocirc;"));
2395 break;
2396 case 'U':
2397 TexOutput(_T("&Icirc;"));
2398 break;
2399 default:
2400 break;
2401 }
2402 }
2403 }
2404 return FALSE;
2405 }
2406 case ltACCENT_TILDE:
2407 {
2408 if (start)
2409 {
2410 wxChar *val = GetArgData();
2411 if (val)
2412 {
2413 switch (val[0])
2414 {
2415 case ' ':
2416 TexOutput(_T("~"));
2417 break;
2418 case 'a':
2419 TexOutput(_T("&atilde;"));
2420 break;
2421 case 'n':
2422 TexOutput(_T("&ntilde;"));
2423 break;
2424 case 'o':
2425 TexOutput(_T("&otilde;"));
2426 break;
2427 case 'A':
2428 TexOutput(_T("&Atilde;"));
2429 break;
2430 case 'N':
2431 TexOutput(_T("&Ntilde;"));
2432 break;
2433 case 'O':
2434 TexOutput(_T("&Otilde;"));
2435 break;
2436 default:
2437 break;
2438 }
2439 }
2440 }
2441 return FALSE;
2442 }
2443 case ltACCENT_UMLAUT:
2444 {
2445 if (start)
2446 {
2447 wxChar *val = GetArgData();
2448 if (val)
2449 {
2450 switch (val[0])
2451 {
2452 case 'a':
2453 TexOutput(_T("&auml;"));
2454 break;
2455 case 'e':
2456 TexOutput(_T("&euml;"));
2457 break;
2458 case 'i':
2459 TexOutput(_T("&iuml;"));
2460 break;
2461 case 'o':
2462 TexOutput(_T("&ouml;"));
2463 break;
2464 case 'u':
2465 TexOutput(_T("&uuml;"));
2466 break;
2467 case 'y':
2468 TexOutput(_T("&yuml;"));
2469 break;
2470 case 'A':
2471 TexOutput(_T("&Auml;"));
2472 break;
2473 case 'E':
2474 TexOutput(_T("&Euml;"));
2475 break;
2476 case 'I':
2477 TexOutput(_T("&Iuml;"));
2478 break;
2479 case 'O':
2480 TexOutput(_T("&Ouml;"));
2481 break;
2482 case 'U':
2483 TexOutput(_T("&Uuml;"));
2484 break;
2485 case 'Y':
2486 TexOutput(_T("&Yuml;"));
2487 break;
2488 default:
2489 break;
2490 }
2491 }
2492 }
2493 return FALSE;
2494 }
2495 case ltACCENT_DOT:
2496 {
2497 if (start)
2498 {
2499 wxChar *val = GetArgData();
2500 if (val)
2501 {
2502 switch (val[0])
2503 {
2504 case 'a':
2505 TexOutput(_T("&aring;"));
2506 break;
2507 case 'A':
2508 TexOutput(_T("&Aring;"));
2509 break;
2510 default:
2511 break;
2512 }
2513 }
2514 }
2515 return FALSE;
2516 }
2517 case ltBACKGROUND:
2518 {
2519 if (start)
2520 {
2521 wxChar *val = GetArgData();
2522 if (val)
2523 {
2524 bool isPicture = FALSE;
2525 ParseColourString(val, &isPicture);
2526 if (isPicture)
2527 {
2528 if (backgroundImageString)
2529 delete[] backgroundImageString;
2530 backgroundImageString = copystring(val);
2531 }
2532 else
2533 {
2534 if (backgroundColourString)
2535 delete[] backgroundColourString;
2536 backgroundColourString = copystring(val);
2537 }
2538 }
2539 }
2540 return FALSE;
2541 }
2542 case ltBACKGROUNDIMAGE:
2543 {
2544 if (start)
2545 {
2546 wxChar *val = GetArgData();
2547 if (val)
2548 {
2549 if (backgroundImageString)
2550 delete[] backgroundImageString;
2551 backgroundImageString = copystring(val);
2552 }
2553 }
2554 return FALSE;
2555 }
2556 case ltBACKGROUNDCOLOUR:
2557 {
2558 if (start)
2559 {
2560 wxChar *val = GetArgData();
2561 if (val)
2562 {
2563 if (backgroundColourString)
2564 delete[] backgroundColourString;
2565 backgroundColourString = copystring(val);
2566 }
2567 }
2568 return FALSE;
2569 }
2570 case ltTEXTCOLOUR:
2571 {
2572 if (start)
2573 {
2574 wxChar *val = GetArgData();
2575 if (val)
2576 {
2577 if (textColourString)
2578 delete[] textColourString;
2579 textColourString = copystring(val);
2580 }
2581 }
2582 return FALSE;
2583 }
2584 case ltLINKCOLOUR:
2585 {
2586 if (start)
2587 {
2588 wxChar *val = GetArgData();
2589 if (val)
2590 {
2591 if (linkColourString)
2592 delete[] linkColourString;
2593 linkColourString = copystring(val);
2594 }
2595 }
2596 return FALSE;
2597 }
2598 case ltFOLLOWEDLINKCOLOUR:
2599 {
2600 if (start)
2601 {
2602 wxChar *val = GetArgData();
2603 if (val)
2604 {
2605 if (followedLinkColourString)
2606 delete[] followedLinkColourString;
2607 followedLinkColourString = copystring(val);
2608 }
2609 }
2610 return FALSE;
2611 }
2612 case ltACCENT_CADILLA:
2613 {
2614 if (start)
2615 {
2616 wxChar *val = GetArgData();
2617 if (val)
2618 {
2619 switch (val[0])
2620 {
2621 case 'c':
2622 TexOutput(_T("&ccedil;"));
2623 break;
2624 case 'C':
2625 TexOutput(_T("&Ccedil;"));
2626 break;
2627 default:
2628 break;
2629 }
2630 }
2631 }
2632 return FALSE;
2633 }
2634 /*
2635 case ltFOOTNOTE:
2636 case ltFOOTNOTEPOPUP:
2637 {
2638 if (arg_no == 1)
2639 return TRUE;
2640 else
2641 return FALSE;
2642 break;
2643 }
2644 */
2645 case ltTABULAR:
2646 case ltSUPERTABULAR:
2647 {
2648 if (arg_no == 1)
2649 {
2650 if (start)
2651 {
2652 currentRowNumber = 0;
2653 inTabular = TRUE;
2654 startRows = TRUE;
2655 tableVerticalLineLeft = FALSE;
2656 tableVerticalLineRight = FALSE;
2657
2658 wxChar *alignString = copystring(GetArgData());
2659 ParseTableArgument(alignString);
2660
2661 TexOutput(_T("<TABLE BORDER>\n"));
2662
2663 // Write the first row formatting for compatibility
2664 // with standard Latex
2665 if (compatibilityMode)
2666 {
2667 TexOutput(_T("<TR>\n<TD>"));
2668 OutputFont();
2669 /*
2670 for (int i = 0; i < noColumns; i++)
2671 {
2672 currentWidth += TableData[i].width;
2673 wxSprintf(buf, _T("\\cellx%d"), currentWidth);
2674 TexOutput(buf);
2675 }
2676 TexOutput(_T("\\pard\\intbl\n"));
2677 */
2678 }
2679 delete[] alignString;
2680
2681 return FALSE;
2682 }
2683 }
2684 else if (arg_no == 2 && !start)
2685 {
2686 TexOutput(_T("</TABLE>\n"));
2687 inTabular = FALSE;
2688 }
2689 break;
2690 }
2691 case ltTHEBIBLIOGRAPHY:
2692 {
2693 if (start && (arg_no == 1))
2694 {
2695 ReopenFile(&Chapters, &ChaptersName);
2696 AddTexRef(_T("bibliography"), ChaptersName, _T("bibliography"));
2697 SetCurrentSubsectionName(_T("bibliography"), ChaptersName);
2698
2699 citeCount = 1;
2700
2701 SetCurrentOutput(Chapters);
2702
2703 wxChar titleBuf[150];
2704 if (truncateFilenames)
2705 wxSprintf(titleBuf, _T("%s.htm"), wxFileNameFromPath(FileRoot));
2706 else
2707 wxSprintf(titleBuf, _T("%s_contents.html"), wxFileNameFromPath(FileRoot));
2708
2709 HTMLHead();
2710 TexOutput(_T("<title>"));
2711 TexOutput(ReferencesNameString);
2712 TexOutput(_T("</title></head>\n"));
2713 OutputBodyStart();
2714
2715 wxFprintf(Chapters, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString);
2716 AddBrowseButtons(_T("contents"), titleBuf, // Up
2717 lastTopic, lastFileName, // Last topic
2718 _T("bibliography"), ChaptersName); // This topic
2719
2720 SetCurrentOutputs(Contents, Chapters);
2721 wxFprintf(Contents, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName), "bibliography");
2722
2723 wxFprintf(Contents, _T("%s</A>\n"), ReferencesNameString);
2724 wxFprintf(Chapters, _T("</H2>\n</A>\n"));
2725
2726 SetCurrentOutput(Chapters);
2727 return FALSE;
2728 }
2729 if (!start && (arg_no == 2))
2730 {
2731 }
2732 return TRUE;
2733 }
2734 case ltINDEX:
2735 {
2736 /* Build up list of keywords associated with topics */
2737 if (start)
2738 {
2739 // wxChar *entry = GetArgData();
2740 wxChar buf[300];
2741 OutputChunkToString(GetArgChunk(), buf);
2742 if (CurrentTopic)
2743 {
2744 AddKeyWordForTopic(CurrentTopic, buf, currentFileName);
2745 }
2746 }
2747 return FALSE;
2748 }
2749 case ltFCOL:
2750 // case ltBCOL:
2751 {
2752 if (start)
2753 {
2754 switch (arg_no)
2755 {
2756 case 1:
2757 {
2758 wxChar *name = GetArgData();
2759 wxChar buf2[10];
2760 if (!FindColourHTMLString(name, buf2))
2761 {
2762 wxStrcpy(buf2, _T("#000000"));
2763 wxChar buf[100];
2764 wxSprintf(buf, _T("Could not find colour name %s"), name);
2765 OnError(buf);
2766 }
2767 TexOutput(_T("<FONT COLOR=\""));
2768 TexOutput(buf2);
2769 TexOutput(_T("\">"));
2770 break;
2771 }
2772 case 2:
2773 {
2774 return TRUE;
2775 }
2776 default:
2777 break;
2778 }
2779 }
2780 else
2781 {
2782 if (arg_no == 2) TexOutput(_T("</FONT>"));
2783 }
2784 return FALSE;
2785 }
2786 case ltINSERTATLEVEL:
2787 {
2788 // This macro allows you to insert text at a different level
2789 // from the current level, e.g. into the Sections from within a subsubsection.
2790 if (useWord)
2791 return FALSE;
2792 static int currentLevelNo = 1;
2793 static FILE* oldLevelFile = Chapters;
2794 if (start)
2795 {
2796 switch (arg_no)
2797 {
2798 case 1:
2799 {
2800 oldLevelFile = CurrentOutput1;
2801
2802 wxChar *str = GetArgData();
2803 currentLevelNo = wxAtoi(str);
2804 FILE* outputFile;
2805 // TODO: cope with article style (no chapters)
2806 switch (currentLevelNo)
2807 {
2808 case 1:
2809 {
2810 outputFile = Chapters;
2811 break;
2812 }
2813 case 2:
2814 {
2815 outputFile = Sections;
2816 break;
2817 }
2818 case 3:
2819 {
2820 outputFile = Subsections;
2821 break;
2822 }
2823 case 4:
2824 {
2825 outputFile = Subsubsections;
2826 break;
2827 }
2828 default:
2829 {
2830 outputFile = NULL;
2831 break;
2832 }
2833 }
2834 if (outputFile)
2835 CurrentOutput1 = outputFile;
2836 return FALSE;
2837 }
2838 case 2:
2839 {
2840 return TRUE;
2841 }
2842 default:
2843 break;
2844 }
2845 return TRUE;
2846 }
2847 else
2848 {
2849 if (arg_no == 2)
2850 {
2851 CurrentOutput1 = oldLevelFile;
2852 }
2853 return TRUE;
2854 }
2855 }
2856 default:
2857 return DefaultOnArgument(macroId, arg_no, start);
2858 }
2859 return TRUE;
2860 }
2861
2862 bool HTMLGo(void)
2863 {
2864 fileId = 0;
2865 inVerbatim = FALSE;
2866 indentLevel = 0;
2867 inTabular = FALSE;
2868 startRows = FALSE;
2869 tableVerticalLineLeft = FALSE;
2870 tableVerticalLineRight = FALSE;
2871 noColumns = 0;
2872
2873 if (InputFile && OutputFile)
2874 {
2875 // Do some HTML-specific transformations on all the strings,
2876 // recursively
2877 Text2HTML(GetTopLevelChunk());
2878
2879 wxChar buf[300];
2880 if (truncateFilenames)
2881 wxSprintf(buf, _T("%s.htm"), FileRoot);
2882 else
2883 wxSprintf(buf, _T("%s_contents.html"), FileRoot);
2884 if (TitlepageName) delete[] TitlepageName;
2885 TitlepageName = copystring(buf);
2886 Titlepage = wxFopen(buf, _T("w"));
2887
2888 if (truncateFilenames)
2889 wxSprintf(buf, _T("%s_fc.htm"), FileRoot);
2890 else
2891 wxSprintf(buf, _T("%s_fcontents.html"), FileRoot);
2892
2893 contentsFrameName = copystring(buf);
2894
2895 Contents = wxFopen(TmpContentsName, _T("w"));
2896
2897 if (htmlFrameContents)
2898 {
2899 // FrameContents = wxFopen(TmpFrameContentsName, _T("w"));
2900 FrameContents = wxFopen(contentsFrameName, _T("w"));
2901 wxFprintf(FrameContents, _T("<HTML>\n<UL>\n"));
2902 }
2903
2904 if (!Titlepage || !Contents)
2905 {
2906 OnError(_T("Cannot open output file!"));
2907 return FALSE;
2908 }
2909 AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName), ContentsNameString);
2910
2911 wxFprintf(Contents, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString);
2912
2913 wxFprintf(Contents, _T("<UL>\n"));
2914
2915 SetCurrentOutput(Titlepage);
2916 if (htmlWorkshopFiles) HTMLWorkshopStartContents();
2917 OnInform(_T("Converting..."));
2918
2919 TraverseDocument();
2920 wxFprintf(Contents, _T("</UL>\n\n"));
2921
2922 // SetCurrentOutput(Titlepage);
2923 fclose(Titlepage);
2924
2925 if (Contents)
2926 {
2927 // wxFprintf(Titlepage, _T("\n</BODY></HTML>\n"));
2928 fclose(Contents);
2929 Contents = NULL;
2930 }
2931
2932 if (FrameContents)
2933 {
2934 wxFprintf(FrameContents, _T("\n</UL>\n"));
2935 wxFprintf(FrameContents, _T("</HTML>\n"));
2936 fclose(FrameContents);
2937 FrameContents = NULL;
2938 }
2939
2940 if (Chapters)
2941 {
2942 wxFprintf(Chapters, _T("\n</FONT></BODY></HTML>\n"));
2943 fclose(Chapters);
2944 Chapters = NULL;
2945 }
2946 if (Sections)
2947 {
2948 wxFprintf(Sections, _T("\n</FONT></BODY></HTML>\n"));
2949 fclose(Sections);
2950 Sections = NULL;
2951 }
2952 if (Subsections && !combineSubSections)
2953 {
2954 wxFprintf(Subsections, _T("\n</FONT></BODY></HTML>\n"));
2955 fclose(Subsections);
2956 Subsections = NULL;
2957 }
2958 if (Subsubsections && !combineSubSections)
2959 {
2960 wxFprintf(Subsubsections, _T("\n</FONT></BODY></HTML>\n"));
2961 fclose(Subsubsections);
2962 Subsubsections = NULL;
2963 }
2964 if ( SectionContentsFD )
2965 {
2966 fclose(SectionContentsFD);
2967 SectionContentsFD = NULL;
2968 }
2969
2970 // Create a temporary file for the title page header, add some info,
2971 // and concat the titlepage just generated.
2972 // This is necessary in order to put the title of the document
2973 // at the TOP of the file within <HEAD>, even though we only find out
2974 // what it is later on.
2975 FILE *tmpTitle = wxFopen(_T("title.tmp"), _T("w"));
2976 if (tmpTitle)
2977 {
2978 if (DocumentTitle)
2979 {
2980 SetCurrentOutput(tmpTitle);
2981 HTMLHead();
2982 TexOutput(_T("\n<HEAD><TITLE>"));
2983 TraverseChildrenFromChunk(DocumentTitle);
2984 TexOutput(_T("</TITLE></HEAD>\n"));
2985 }
2986 else
2987 {
2988 SetCurrentOutput(tmpTitle);
2989 HTMLHeadTo(tmpTitle);
2990 if (contentsString)
2991 wxFprintf(tmpTitle, _T("<TITLE>%s</TITLE></HEAD>\n\n"), contentsString);
2992 else
2993 wxFprintf(tmpTitle, _T("<TITLE>%s</TITLE></HEAD>\n\n"), wxFileNameFromPath(FileRoot));
2994 }
2995
2996 // Output frame information
2997 if (htmlFrameContents)
2998 {
2999 wxChar firstFileName[300];
3000 if (truncateFilenames)
3001 wxSprintf(firstFileName, _T("%s1.htm"), FileRoot);
3002 else
3003 wxSprintf(firstFileName, _T("%s1.html"), FileRoot);
3004
3005 wxFprintf(tmpTitle, _T("<FRAMESET COLS=\"30%%,70%%\">\n"));
3006
3007 wxFprintf(tmpTitle, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName)));
3008 wxFprintf(tmpTitle, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName)));
3009 wxFprintf(tmpTitle, _T("</FRAMESET>\n"));
3010
3011 wxFprintf(tmpTitle, _T("<NOFRAMES>\n"));
3012 }
3013
3014 // Output <BODY...> to temporary title page
3015 OutputBodyStart();
3016
3017 // Concat titlepage
3018 FILE *fd = wxFopen(TitlepageName, _T("r"));
3019 if (fd)
3020 {
3021 int ch = getc(fd);
3022 while (ch != EOF)
3023 {
3024 putc(ch, tmpTitle);
3025 ch = getc(fd);
3026 }
3027 fclose(fd);
3028 }
3029
3030 wxFprintf(tmpTitle, _T("\n</FONT></BODY>\n"));
3031
3032 if (htmlFrameContents)
3033 {
3034 wxFprintf(tmpTitle, _T("\n</NOFRAMES>\n"));
3035 }
3036 wxFprintf(tmpTitle, _T("\n</HTML>\n"));
3037
3038 fclose(tmpTitle);
3039 if (wxFileExists(TitlepageName)) wxRemoveFile(TitlepageName);
3040 if (!wxRenameFile(_T("title.tmp"), TitlepageName))
3041 {
3042 wxCopyFile(_T("title.tmp"), TitlepageName);
3043 wxRemoveFile(_T("title.tmp"));
3044 }
3045 }
3046
3047 if (lastFileName) delete[] lastFileName;
3048 lastFileName = NULL;
3049 if (lastTopic) delete[] lastTopic;
3050 lastTopic = NULL;
3051
3052 if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName);
3053
3054 if (!wxRenameFile(TmpContentsName, ContentsName))
3055 {
3056 wxCopyFile(TmpContentsName, ContentsName);
3057 wxRemoveFile(TmpContentsName);
3058 }
3059
3060 // Generate .htx file if requested
3061 if (htmlIndex)
3062 {
3063 wxChar htmlIndexName[300];
3064 wxSprintf(htmlIndexName, _T("%s.htx"), FileRoot);
3065 GenerateHTMLIndexFile(htmlIndexName);
3066 }
3067
3068 // Generate HTML Help Workshop files if requested
3069 if (htmlWorkshopFiles)
3070 {
3071 HTMLWorkshopEndContents();
3072 GenerateHTMLWorkshopFiles(FileRoot);
3073 }
3074
3075
3076 return TRUE;
3077 }
3078
3079 return FALSE;
3080 }
3081
3082 // Output .htx index file
3083 void GenerateHTMLIndexFile(wxChar *fname)
3084 {
3085 FILE *fd = wxFopen(fname, _T("w"));
3086 if (!fd)
3087 return;
3088
3089 TopicTable.BeginFind();
3090 wxNode *node = TopicTable.Next();
3091 while (node)
3092 {
3093 TexTopic *texTopic = (TexTopic *)node->GetData();
3094 const wxChar *topicName = node->GetKeyString();
3095 if (texTopic->filename && texTopic->keywords)
3096 {
3097 wxStringListNode *node1 = texTopic->keywords->GetFirst();
3098 while (node1)
3099 {
3100 wxChar *s = (wxChar *)node1->GetData();
3101 wxFprintf(fd, _T("%s|%s|%s\n"), topicName, texTopic->filename, s);
3102 node1 = node1->GetNext();
3103 }
3104 }
3105 node = TopicTable.Next();
3106 }
3107 fclose(fd);
3108 }
3109
3110
3111
3112
3113
3114
3115
3116 // output .hpp, .hhc and .hhk files:
3117
3118
3119 void GenerateHTMLWorkshopFiles(wxChar *fname)
3120 {
3121 FILE *f;
3122 wxChar buf[300];
3123
3124 /* Generate project file : */
3125
3126 wxSprintf(buf, _T("%s.hhp"), fname);
3127 f = wxFopen(buf, _T("wt"));
3128 wxFprintf(f,
3129 _T("[OPTIONS]\n")
3130 _T("Compatibility=1.1\n")
3131 _T("Full-text search=Yes\n")
3132 _T("Contents file=%s.hhc\n")
3133 _T("Compiled file=%s.chm\n")
3134 _T("Default Window=%sHelp\n")
3135 _T("Default topic=%s\n")
3136 _T("Index file=%s.hhk\n")
3137 _T("Title="),
3138 wxFileNameFromPath(fname),
3139 wxFileNameFromPath(fname),
3140 wxFileNameFromPath(fname),
3141 wxFileNameFromPath(TitlepageName),
3142 wxFileNameFromPath(fname)
3143 );
3144
3145 if (DocumentTitle) {
3146 SetCurrentOutput(f);
3147 TraverseChildrenFromChunk(DocumentTitle);
3148 }
3149 else wxFprintf(f, _T("(unknown)"));
3150
3151 wxFprintf(f, _T("\n\n[WINDOWS]\n")
3152 _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"),
3153 wxFileNameFromPath(fname),
3154 wxFileNameFromPath(fname),
3155 wxFileNameFromPath(fname),
3156 wxFileNameFromPath(TitlepageName));
3157
3158
3159 wxFprintf(f, _T("\n\n[FILES]\n"));
3160 wxFprintf(f, _T("%s\n"), wxFileNameFromPath(TitlepageName));
3161 for (int i = 1; i <= fileId; i++) {
3162 if (truncateFilenames)
3163 wxSprintf(buf, _T("%s%d.htm"), wxFileNameFromPath(FileRoot), i);
3164 else
3165 wxSprintf(buf, _T("%s%d.html"), wxFileNameFromPath(FileRoot), i);
3166 wxFprintf(f, _T("%s\n"), buf);
3167 }
3168 fclose(f);
3169
3170 /* Generate index file : */
3171
3172 wxSprintf(buf, _T("%s.hhk"), fname);
3173 f = wxFopen(buf, _T("wt"));
3174
3175 wxFprintf(f,
3176 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3177 _T("<HTML>\n"));
3178 HTMLHeadTo(f);
3179 wxFprintf(f,
3180 _T("\n")
3181 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3182 _T("<!-- Sitemap 1.0 -->\n")
3183 _T("</HEAD><BODY>\n")
3184 _T("<OBJECT type=\"text/site properties\">\n")
3185 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3186 _T("</OBJECT>\n")
3187 _T("<UL>\n"));
3188
3189 TopicTable.BeginFind();
3190 wxNode *node = TopicTable.Next();
3191 while (node)
3192 {
3193 TexTopic *texTopic = (TexTopic *)node->GetData();
3194 const wxChar *topicName = node->GetKeyString();
3195 if (texTopic->filename && texTopic->keywords)
3196 {
3197 wxStringListNode *node1 = texTopic->keywords->GetFirst();
3198 while (node1)
3199 {
3200 wxChar *s = (wxChar *)node1->GetData();
3201 wxFprintf(f,
3202 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3203 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3204 _T(" <param name=\"Name\" value=\"%s\">\n")
3205 _T(" </OBJECT>\n"),
3206 texTopic->filename, topicName, s);
3207 node1 = node1->GetNext();
3208 }
3209 }
3210 node = TopicTable.Next();
3211 }
3212
3213 wxFprintf(f, _T("</UL>\n"));
3214 fclose(f);
3215 }
3216
3217
3218
3219 static FILE *HTMLWorkshopContents = NULL;
3220 static int HTMLWorkshopLastLevel = 0;
3221
3222 void HTMLWorkshopAddToContents(int level, wxChar *s, wxChar *file)
3223 {
3224 int i;
3225
3226 if (level > HTMLWorkshopLastLevel)
3227 for (i = HTMLWorkshopLastLevel; i < level; i++)
3228 wxFprintf(HTMLWorkshopContents, _T("<UL>"));
3229 if (level < HTMLWorkshopLastLevel)
3230 for (i = level; i < HTMLWorkshopLastLevel; i++)
3231 wxFprintf(HTMLWorkshopContents, _T("</UL>"));
3232
3233 SetCurrentOutput(HTMLWorkshopContents);
3234 wxFprintf(HTMLWorkshopContents,
3235 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3236 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3237 _T(" <param name=\"Name\" value=\""),
3238 file, s);
3239 OutputCurrentSection();
3240 wxFprintf(HTMLWorkshopContents,
3241 _T("\">\n")
3242 _T(" </OBJECT>\n"));
3243 HTMLWorkshopLastLevel = level;
3244 }
3245
3246
3247 void HTMLWorkshopStartContents()
3248 {
3249 wxChar buf[300];
3250 wxSprintf(buf, _T("%s.hhc"), FileRoot);
3251 HTMLWorkshopContents = wxFopen(buf, _T("wt"));
3252 HTMLWorkshopLastLevel = 0;
3253
3254 wxFprintf(HTMLWorkshopContents,
3255 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3256 _T("<HTML>\n"));
3257 HTMLHeadTo(HTMLWorkshopContents);
3258 wxFprintf(HTMLWorkshopContents,
3259 _T("\n")
3260 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3261 _T("<!-- Sitemap 1.0 -->\n")
3262 _T("</HEAD><BODY>\n")
3263 _T("<OBJECT type=\"text/site properties\">\n")
3264 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3265 _T("</OBJECT>\n")
3266 _T("<UL>\n")
3267 _T("<LI> <OBJECT type=\"text/sitemap\">\n")
3268 _T("<param name=\"Local\" value=\"%s\">\n")
3269 _T("<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n"),
3270 wxFileNameFromPath(TitlepageName)
3271 );
3272
3273 }
3274
3275
3276 void HTMLWorkshopEndContents()
3277 {
3278 for (int i = HTMLWorkshopLastLevel; i >= 0; i--)
3279 wxFprintf(HTMLWorkshopContents, _T("</UL>\n"));
3280 fclose(HTMLWorkshopContents);
3281 }