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