]> git.saurik.com Git - wxWidgets.git/blob - utils/tex2rtf/src/htmlutil.cpp
Inital fill in background, removed tabs, -1->wxID_ANY, TRUE->true, FALSE->false
[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 // Read old .con file in at this point
878 wxChar buf[256];
879 wxStrcpy(buf, CurrentSectionFile);
880 wxStripExtension(buf);
881 wxStrcat(buf, _T(".con"));
882 FILE *fd = wxFopen(buf, _T("r"));
883 if ( fd )
884 {
885 int ch = getc(fd);
886 while (ch != EOF)
887 {
888 putc(ch, Sections);
889 ch = getc(fd);
890 }
891 fclose(fd);
892 }
893 wxFprintf(Sections, _T("<P>\n"));
894
895 // Close old file, create a new file for the sub(sub)section contents entries
896 ReopenSectionContentsFile();
897 }
898
899 startedSections = true;
900 subsectionStarted = true;
901
902 wxChar *topicName = FindTopicName(GetNextChunk());
903
904 if ( !combineSubSections )
905 {
906 SetCurrentOutput(NULL);
907 ReopenFile(&Subsections, &SubsectionsName, topicName);
908 AddTexRef(topicName, SubsectionsName, SubsectionNameString);
909 SetCurrentSubsectionName(topicName, SubsectionsName);
910 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SubsectionsName);
911 SetCurrentOutput(Subsections);
912
913 HTMLHead();
914 TexOutput(_T("<title>"));
915 OutputCurrentSection();
916 TexOutput(_T("</title></head>\n"));
917 OutputBodyStart();
918
919 wxFprintf(Subsections, _T("<A NAME=\"%s\"></A>"), topicName);
920 AddBrowseButtons(CurrentSectionName, CurrentSectionFile, // Up
921 lastTopic, lastFileName, // Last topic
922 topicName, SubsectionsName); // This topic
923
924 SetCurrentOutputs(Sections, Subsections);
925 wxFprintf(Sections, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName), topicName);
926
927 wxFprintf(Subsections, _T("\n<H3>"));
928 OutputCurrentSection();
929 wxFprintf(Sections, _T("</B></A><BR>\n"));
930 wxFprintf(Subsections, _T("</H3>\n"));
931
932 SetCurrentOutput(Subsections);
933 }
934 else
935 {
936 AddTexRef(topicName, SectionsName, SubsectionNameString);
937 SetCurrentSubsectionName(topicName, SectionsName);
938
939 // if ( subsectionNo != 0 )
940 wxFprintf(Sections, _T("\n<HR>\n"));
941
942 // We're putting everything into the section file
943 wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName);
944 wxFprintf(Sections, _T("\n<H3>"));
945 OutputCurrentSection();
946 wxFprintf(Sections, _T("</H3>\n"));
947
948 SetCurrentOutput(SectionContentsFD);
949 wxFprintf(SectionContentsFD, _T("<A HREF=\"#%s\">"), topicName);
950 OutputCurrentSection();
951 TexOutput(_T("</A><BR>\n"));
952
953 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName);
954 SetCurrentOutput(Sections);
955 }
956 // Add this section title to the list of keywords
957 if (htmlIndex)
958 {
959 OutputCurrentSectionToString(wxTex2RTFBuffer);
960 AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName);
961 }
962
963 }
964 }
965 break;
966 }
967 case ltSUBSUBSECTION:
968 case ltSUBSUBSECTIONSTAR:
969 {
970 if (!start)
971 {
972 if (!Subsections && !combineSubSections)
973 {
974 OnError(_T("You cannot have a subsubsection before a subsection!"));
975 }
976 else
977 {
978 if (macroId != ltSUBSUBSECTIONSTAR)
979 subsubsectionNo ++;
980
981 startedSections = true;
982
983 wxChar *topicName = FindTopicName(GetNextChunk());
984
985 if ( !combineSubSections )
986 {
987 SetCurrentOutput(NULL);
988 ReopenFile(&Subsubsections, &SubsubsectionsName, topicName);
989 AddTexRef(topicName, SubsubsectionsName, SubsubsectionNameString);
990 SetCurrentSubsubsectionName(topicName, SubsubsectionsName);
991 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(3, topicName, SubsubsectionsName);
992
993 SetCurrentOutput(Subsubsections);
994 HTMLHead();
995 TexOutput(_T("<title>"));
996 OutputCurrentSection();
997 TexOutput(_T("</title></head>\n"));
998 OutputBodyStart();
999
1000 wxFprintf(Subsubsections, _T("<A NAME=\"%s\"></A>"), topicName);
1001
1002 AddBrowseButtons(CurrentSubsectionName, CurrentSubsectionFile, // Up
1003 lastTopic, lastFileName, // Last topic
1004 topicName, SubsubsectionsName); // This topic
1005
1006 SetCurrentOutputs(Subsections, Subsubsections);
1007 wxFprintf(Subsections, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName), topicName);
1008
1009 wxFprintf(Subsubsections, _T("\n<H3>"));
1010 OutputCurrentSection();
1011 wxFprintf(Subsections, _T("</B></A><BR>\n"));
1012 wxFprintf(Subsubsections, _T("</H3>\n"));
1013 }
1014 else
1015 {
1016 AddTexRef(topicName, SectionsName, SubsubsectionNameString);
1017 SetCurrentSubsectionName(topicName, SectionsName);
1018 wxFprintf(Sections, _T("\n<HR>\n"));
1019
1020 // We're putting everything into the section file
1021 wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName);
1022 wxFprintf(Sections, _T("\n<H3>"));
1023 OutputCurrentSection();
1024 wxFprintf(Sections, _T("</H3>\n"));
1025 /* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
1026 SetCurrentOutput(SectionContentsFD);
1027 wxFprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
1028 OutputCurrentSection();
1029 TexOutput(_T("</A><BR>"));
1030 */
1031 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName);
1032 SetCurrentOutput(Sections);
1033 }
1034
1035 // Add this section title to the list of keywords
1036 if (htmlIndex)
1037 {
1038 OutputCurrentSectionToString(wxTex2RTFBuffer);
1039 AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName);
1040 }
1041 }
1042 }
1043 break;
1044 }
1045 case ltFUNC:
1046 case ltPFUNC:
1047 {
1048 if ( !combineSubSections )
1049 SetCurrentOutput(Subsections);
1050 else
1051 SetCurrentOutput(Sections);
1052 if (start)
1053 {
1054 }
1055 else
1056 {
1057 }
1058 break;
1059 }
1060 case ltCLIPSFUNC:
1061 {
1062 if ( !combineSubSections )
1063 SetCurrentOutput(Subsections);
1064 else
1065 SetCurrentOutput(Sections);
1066 if (start)
1067 {
1068 }
1069 else
1070 {
1071 }
1072 break;
1073 }
1074 case ltMEMBER:
1075 {
1076 if ( !combineSubSections )
1077 SetCurrentOutput(Subsections);
1078 else
1079 SetCurrentOutput(Sections);
1080 if (start)
1081 {
1082 }
1083 else
1084 {
1085 }
1086 break;
1087 }
1088 case ltVOID:
1089 // if (start)
1090 // TexOutput(_T("<B>void</B>"));
1091 break;
1092 case ltHARDY:
1093 if (start)
1094 TexOutput(_T("HARDY"));
1095 break;
1096 case ltWXCLIPS:
1097 if (start)
1098 TexOutput(_T("wxCLIPS"));
1099 break;
1100 case ltAMPERSAND:
1101 if (start)
1102 TexOutput(_T("&amp;"));
1103 break;
1104 case ltSPECIALAMPERSAND:
1105 {
1106 if (start)
1107 {
1108 if (inTabular)
1109 {
1110 // End cell, start cell
1111
1112 TexOutput(_T("</FONT></TD>"));
1113
1114 // Start new row and cell, setting alignment for the first cell.
1115 if (currentColumn < noColumns)
1116 currentColumn ++;
1117
1118 wxChar buf[100];
1119 if (TableData[currentColumn].justification == 'c')
1120 wxSnprintf(buf, sizeof(buf), _T("\n<TD ALIGN=CENTER>"));
1121 else if (TableData[currentColumn].justification == 'r')
1122 wxSnprintf(buf, sizeof(buf), _T("\n<TD ALIGN=RIGHT>"));
1123 else if (TableData[currentColumn].absWidth)
1124 {
1125 // Convert from points * 20 into pixels.
1126 int points = TableData[currentColumn].width / 20;
1127
1128 // Say the display is 100 DPI (dots/pixels per inch).
1129 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1130 int pixels = (int)(points * 100.0 / 72.0);
1131 wxSnprintf(buf, sizeof(buf), _T("<TD ALIGN=CENTER WIDTH=%d>"), pixels);
1132 }
1133 else
1134 wxSnprintf(buf, sizeof(buf), _T("\n<TD ALIGN=LEFT>"));
1135 TexOutput(buf);
1136 OutputFont();
1137 }
1138 else
1139 TexOutput(_T("&amp;"));
1140 }
1141 break;
1142 }
1143 case ltBACKSLASHCHAR:
1144 {
1145 if (start)
1146 {
1147 if (inTabular)
1148 {
1149 // End row. In fact, tables without use of \row or \ruledrow isn't supported for
1150 // HTML: the syntax is too different (e.g. how do we know where to put the first </TH>
1151 // if we've ended the last row?). So normally you wouldn't use \\ to end a row.
1152 TexOutput(_T("</TR>\n"));
1153 }
1154 else
1155 TexOutput(_T("<BR>\n"));
1156 }
1157 break;
1158 }
1159 case ltROW:
1160 case ltRULEDROW:
1161 {
1162 if (start)
1163 {
1164 currentColumn = 0;
1165
1166 // Start new row and cell, setting alignment for the first cell.
1167 wxChar buf[100];
1168 if (TableData[currentColumn].justification == 'c')
1169 wxSnprintf(buf, sizeof(buf), _T("<TR>\n<TD ALIGN=CENTER>"));
1170 else if (TableData[currentColumn].justification == 'r')
1171 wxSnprintf(buf, sizeof(buf), _T("<TR>\n<TD ALIGN=RIGHT>"));
1172 else if (TableData[currentColumn].absWidth)
1173 {
1174 // Convert from points * 20 into pixels.
1175 int points = TableData[currentColumn].width / 20;
1176
1177 // Say the display is 100 DPI (dots/pixels per inch).
1178 // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots.
1179 int pixels = (int)(points * 100.0 / 72.0);
1180 wxSnprintf(buf, sizeof(buf), _T("<TR>\n<TD ALIGN=CENTER WIDTH=%d>"), pixels);
1181 }
1182 else
1183 wxSnprintf(buf, sizeof(buf), _T("<TR>\n<TD ALIGN=LEFT>"));
1184 TexOutput(buf);
1185 OutputFont();
1186 }
1187 else
1188 {
1189 // End cell and row
1190 // Start new row and cell
1191 TexOutput(_T("</FONT></TD>\n</TR>\n"));
1192 }
1193 break;
1194 }
1195 // HTML-only: break until the end of the picture (both margins are clear).
1196 case ltBRCLEAR:
1197 {
1198 if (start)
1199 TexOutput(_T("<BR CLEAR=ALL>"));
1200 break;
1201 }
1202 case ltRTFSP: // Explicit space, RTF only
1203 break;
1204 case ltSPECIALTILDE:
1205 {
1206 if (start)
1207 {
1208 #if (1) // if(inVerbatim)
1209 TexOutput(_T("~"));
1210 #else
1211 TexOutput(_T(" "));
1212 #endif
1213 }
1214 break;
1215 }
1216 case ltINDENTED :
1217 {
1218 if ( start )
1219 TexOutput(_T("<UL><UL>\n"));
1220 else
1221 TexOutput(_T("</UL></UL>\n"));
1222 break;
1223 }
1224 case ltITEMIZE:
1225 case ltENUMERATE:
1226 case ltDESCRIPTION:
1227 // case ltTWOCOLLIST:
1228 {
1229 if (start)
1230 {
1231 indentLevel ++;
1232
1233 int listType;
1234 if (macroId == ltENUMERATE)
1235 listType = LATEX_ENUMERATE;
1236 else if (macroId == ltITEMIZE)
1237 listType = LATEX_ITEMIZE;
1238 else
1239 listType = LATEX_DESCRIPTION;
1240
1241 itemizeStack.Insert(new ItemizeStruc(listType));
1242 switch (listType)
1243 {
1244 case LATEX_ITEMIZE:
1245 TexOutput(_T("<UL>\n"));
1246 break;
1247 case LATEX_ENUMERATE:
1248 TexOutput(_T("<OL>\n"));
1249 break;
1250 case LATEX_DESCRIPTION:
1251 default:
1252 TexOutput(_T("<DL>\n"));
1253 break;
1254 }
1255 }
1256 else
1257 {
1258 indentLevel --;
1259 if (itemizeStack.GetFirst())
1260 {
1261 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
1262 switch (struc->listType)
1263 {
1264 case LATEX_ITEMIZE:
1265 TexOutput(_T("</UL>\n"));
1266 break;
1267 case LATEX_ENUMERATE:
1268 TexOutput(_T("</OL>\n"));
1269 break;
1270 case LATEX_DESCRIPTION:
1271 default:
1272 TexOutput(_T("</DL>\n"));
1273 break;
1274 }
1275
1276 delete struc;
1277 delete itemizeStack.GetFirst();
1278 }
1279 }
1280 break;
1281 }
1282 case ltTWOCOLLIST :
1283 {
1284 if ( start )
1285 TexOutput(_T("\n<TABLE>\n"));
1286 else {
1287 TexOutput(_T("\n</TABLE>\n"));
1288 // DHS
1289 TwoColWidthA = -1;
1290 TwoColWidthB = -1;
1291 }
1292 break;
1293 }
1294 case ltPAR:
1295 {
1296 if (start)
1297 TexOutput(_T("<P>\n"));
1298 break;
1299 }
1300 /* For footnotes we need to output the text at the bottom of the page and
1301 * insert a reference to it. Is it worth the trouble...
1302 case ltFOOTNOTE:
1303 case ltFOOTNOTEPOPUP:
1304 {
1305 if (start)
1306 {
1307 TexOutput(_T("<FN>"));
1308 }
1309 else TexOutput(_T("</FN>"));
1310 break;
1311 }
1312 */
1313 case ltVERB:
1314 {
1315 if (start)
1316 TexOutput(_T("<TT>"));
1317 else TexOutput(_T("</TT>"));
1318 break;
1319 }
1320 case ltVERBATIM:
1321 {
1322 if (start)
1323 {
1324 wxChar buf[100];
1325 wxSnprintf(buf, sizeof(buf), _T("<PRE>\n"));
1326 TexOutput(buf);
1327 }
1328 else TexOutput(_T("</PRE>\n"));
1329 break;
1330 }
1331 case ltCENTERLINE:
1332 case ltCENTER:
1333 {
1334 if (start)
1335 {
1336 TexOutput(_T("<CENTER>"));
1337 }
1338 else TexOutput(_T("</CENTER>"));
1339 break;
1340 }
1341 case ltFLUSHLEFT:
1342 {
1343 /*
1344 if (start)
1345 {
1346 TexOutput(_T("{\\ql "));
1347 }
1348 else TexOutput(_T("}\\par\\pard\n"));
1349 */
1350 break;
1351 }
1352 case ltFLUSHRIGHT:
1353 {
1354 /*
1355 if (start)
1356 {
1357 TexOutput(_T("{\\qr "));
1358 }
1359 else TexOutput(_T("}\\par\\pard\n"));
1360 */
1361 break;
1362 }
1363 case ltSMALL:
1364 {
1365 if (start)
1366 {
1367 // Netscape extension
1368 TexOutput(_T("<FONT SIZE=2>"));
1369 }
1370 else TexOutput(_T("</FONT>"));
1371 break;
1372 }
1373 case ltTINY:
1374 {
1375 if (start)
1376 {
1377 // Netscape extension
1378 TexOutput(_T("<FONT SIZE=1>"));
1379 }
1380 else TexOutput(_T("</FONT>"));
1381 break;
1382 }
1383 case ltNORMALSIZE:
1384 {
1385 if (start)
1386 {
1387 // Netscape extension
1388 TexOutput(_T("<FONT SIZE=3>"));
1389 }
1390 else TexOutput(_T("</FONT>"));
1391 break;
1392 }
1393 case ltlarge:
1394 {
1395 if (start)
1396 {
1397 // Netscape extension
1398 TexOutput(_T("<FONT SIZE=4>"));
1399 }
1400 else TexOutput(_T("</FONT>"));
1401 break;
1402 }
1403 case ltLarge:
1404 {
1405 if (start)
1406 {
1407 // Netscape extension
1408 TexOutput(_T("<FONT SIZE=5>"));
1409 }
1410 else TexOutput(_T("</FONT>"));
1411 break;
1412 }
1413 case ltLARGE:
1414 {
1415 if (start)
1416 {
1417 // Netscape extension
1418 TexOutput(_T("<FONT SIZE=6>"));
1419 }
1420 else TexOutput(_T("</FONT>"));
1421 break;
1422 }
1423 case ltBFSERIES:
1424 case ltTEXTBF:
1425 case ltBF:
1426 {
1427 if (start)
1428 {
1429 TexOutput(_T("<B>"));
1430 }
1431 else TexOutput(_T("</B>"));
1432 break;
1433 }
1434 case ltITSHAPE:
1435 case ltTEXTIT:
1436 case ltIT:
1437 {
1438 if (start)
1439 {
1440 TexOutput(_T("<I>"));
1441 }
1442 else TexOutput(_T("</I>"));
1443 break;
1444 }
1445 case ltEMPH:
1446 case ltEM:
1447 {
1448 if (start)
1449 {
1450 TexOutput(_T("<EM>"));
1451 }
1452 else TexOutput(_T("</EM>"));
1453 break;
1454 }
1455 case ltUNDERLINE:
1456 {
1457 if (start)
1458 {
1459 TexOutput(_T("<UL>"));
1460 }
1461 else TexOutput(_T("</UL>"));
1462 break;
1463 }
1464 case ltTTFAMILY:
1465 case ltTEXTTT:
1466 case ltTT:
1467 {
1468 if (start)
1469 {
1470 TexOutput(_T("<TT>"));
1471 }
1472 else TexOutput(_T("</TT>"));
1473 break;
1474 }
1475 case ltCOPYRIGHT:
1476 {
1477 if (start)
1478 TexOutput(_T("&copy;"), true);
1479 break;
1480 }
1481 case ltREGISTERED:
1482 {
1483 if (start)
1484 TexOutput(_T("&reg;"), true);
1485 break;
1486 }
1487 // Arrows
1488 case ltLEFTARROW:
1489 {
1490 if (start) TexOutput(_T("&lt;--"));
1491 break;
1492 }
1493 case ltLEFTARROW2:
1494 {
1495 if (start) TexOutput(_T("&lt;=="));
1496 break;
1497 }
1498 case ltRIGHTARROW:
1499 {
1500 if (start) TexOutput(_T("--&gt;"));
1501 break;
1502 }
1503 case ltRIGHTARROW2:
1504 {
1505 if (start) TexOutput(_T("==&gt;"));
1506 break;
1507 }
1508 case ltLEFTRIGHTARROW:
1509 {
1510 if (start) TexOutput(_T("&lt;--&gt;"));
1511 break;
1512 }
1513 case ltLEFTRIGHTARROW2:
1514 {
1515 if (start) TexOutput(_T("&lt;==&gt;"));
1516 break;
1517 }
1518 /*
1519 case ltSC:
1520 {
1521 break;
1522 }
1523 */
1524 case ltITEM:
1525 {
1526 if (!start)
1527 {
1528 wxNode *node = itemizeStack.GetFirst();
1529 if (node)
1530 {
1531 ItemizeStruc *struc = (ItemizeStruc *)node->GetData();
1532 struc->currentItem += 1;
1533 if (struc->listType == LATEX_DESCRIPTION)
1534 {
1535 if (descriptionItemArg)
1536 {
1537 TexOutput(_T("<DT> "));
1538 TraverseChildrenFromChunk(descriptionItemArg);
1539 TexOutput(_T("\n"));
1540 descriptionItemArg = NULL;
1541 }
1542 TexOutput(_T("<DD>"));
1543 }
1544 else
1545 TexOutput(_T("<LI>"));
1546 }
1547 }
1548 break;
1549 }
1550 case ltMAKETITLE:
1551 {
1552 if (start && DocumentTitle && DocumentAuthor)
1553 {
1554 // Add a special label for the contents page.
1555 // TexOutput(_T("<CENTER>\n"));
1556 TexOutput(_T("<A NAME=\"contents\">"));
1557 TexOutput(_T("<H2 ALIGN=CENTER>\n"));
1558 TraverseChildrenFromChunk(DocumentTitle);
1559 TexOutput(_T("</H2>"));
1560 TexOutput(_T("<P>"));
1561 TexOutput(_T("</A>\n"));
1562 TexOutput(_T("<P>\n\n"));
1563 TexOutput(_T("<H3 ALIGN=CENTER>"));
1564 TraverseChildrenFromChunk(DocumentAuthor);
1565 TexOutput(_T("</H3><P>\n\n"));
1566 if (DocumentDate)
1567 {
1568 TexOutput(_T("<H3 ALIGN=CENTER>"));
1569 TraverseChildrenFromChunk(DocumentDate);
1570 TexOutput(_T("</H3><P>\n\n"));
1571 }
1572 // TexOutput(_T("\n</CENTER>\n"));
1573 TexOutput(_T("\n<P><HR><P>\n"));
1574
1575 /*
1576 // Now do optional frame contents page
1577 if (htmlFrameContents && FrameContents)
1578 {
1579 SetCurrentOutput(FrameContents);
1580
1581 // Add a special label for the contents page.
1582 TexOutput(_T("<CENTER>\n"));
1583 TexOutput(_T("<H3>\n"));
1584 TraverseChildrenFromChunk(DocumentTitle);
1585 TexOutput(_T("</H3>"));
1586 TexOutput(_T("<P>"));
1587 TexOutput(_T("</A>\n"));
1588 TexOutput(_T("<P>\n\n"));
1589 TexOutput(_T("<H3>"));
1590 TraverseChildrenFromChunk(DocumentAuthor);
1591 TexOutput(_T("</H3><P>\n\n"));
1592 if (DocumentDate)
1593 {
1594 TexOutput(_T("<H4>"));
1595 TraverseChildrenFromChunk(DocumentDate);
1596 TexOutput(_T("</H4><P>\n\n"));
1597 }
1598 TexOutput(_T("\n</CENTER>\n"));
1599 TexOutput(_T("<P><HR><P>\n"));
1600
1601 SetCurrentOutput(Titlepage);
1602 }
1603 */
1604 }
1605 break;
1606 }
1607 case ltHELPREF:
1608 case ltHELPREFN:
1609 case ltPOPREF:
1610 case ltURLREF:
1611 {
1612 if (start)
1613 {
1614 helpRefFilename = NULL;
1615 helpRefText = NULL;
1616 }
1617 break;
1618 }
1619 case ltBIBLIOGRAPHY:
1620 {
1621 if (start)
1622 {
1623 DefaultOnMacro(macroId, no_args, start);
1624 }
1625 else
1626 {
1627 DefaultOnMacro(macroId, no_args, start);
1628 TexOutput(_T("</DL>\n"));
1629 }
1630 break;
1631 }
1632 case ltHRULE:
1633 {
1634 if (start)
1635 {
1636 TexOutput(_T("<HR>\n"));
1637 }
1638 break;
1639 }
1640 case ltRULE:
1641 {
1642 if (start)
1643 {
1644 TexOutput(_T("<HR>\n"));
1645 }
1646 break;
1647 }
1648 case ltTABLEOFCONTENTS:
1649 {
1650 if (start)
1651 {
1652 FILE *fd = wxFopen(ContentsName, _T("r"));
1653 if (fd)
1654 {
1655 int ch = getc(fd);
1656 while (ch != EOF)
1657 {
1658 putc(ch, Titlepage);
1659 ch = getc(fd);
1660 }
1661 fclose(fd);
1662 }
1663 else
1664 {
1665 TexOutput(_T("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n"));
1666 OnInform(_T("Run Tex2RTF again to include contents page."));
1667 }
1668 }
1669 break;
1670 }
1671 case ltLANGLEBRA:
1672 {
1673 if (start)
1674 TexOutput(_T("&lt;"));
1675 break;
1676 }
1677 case ltRANGLEBRA:
1678 {
1679 if (start)
1680 TexOutput(_T("&gt;"));
1681 break;
1682 }
1683 case ltQUOTE:
1684 case ltQUOTATION:
1685 {
1686 if (start)
1687 TexOutput(_T("<BLOCKQUOTE>"));
1688 else
1689 TexOutput(_T("</BLOCKQUOTE>"));
1690 break;
1691 }
1692 case ltCAPTION:
1693 case ltCAPTIONSTAR:
1694 {
1695 if (start)
1696 {
1697 if (inTabular)
1698 TexOutput(_T("\n<CAPTION>"));
1699
1700 wxChar figBuf[40];
1701
1702 if ( inFigure )
1703 {
1704 figureNo ++;
1705
1706 if (DocumentStyle != LATEX_ARTICLE)
1707 wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d.%d: "), FigureNameString, chapterNo, figureNo);
1708 else
1709 wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d: "), FigureNameString, figureNo);
1710 }
1711 else
1712 {
1713 tableNo ++;
1714
1715 if (DocumentStyle != LATEX_ARTICLE)
1716 wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d.%d: "), TableNameString, chapterNo, tableNo);
1717 else
1718 wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d: "), TableNameString, tableNo);
1719 }
1720
1721 TexOutput(figBuf);
1722 }
1723 else
1724 {
1725 if (inTabular)
1726 TexOutput(_T("\n</CAPTION>\n"));
1727
1728 wxChar *topicName = FindTopicName(GetNextChunk());
1729
1730 int n = inFigure ? figureNo : tableNo;
1731
1732 AddTexRef(topicName, NULL, NULL,
1733 ((DocumentStyle != LATEX_ARTICLE) ? chapterNo : n),
1734 ((DocumentStyle != LATEX_ARTICLE) ? n : 0));
1735 }
1736 break;
1737 }
1738 case ltSS:
1739 {
1740 if (start) TexOutput(_T("&szlig;"));
1741 break;
1742 }
1743 case ltFIGURE:
1744 {
1745 if (start) inFigure = true;
1746 else inFigure = false;
1747 break;
1748 }
1749 case ltTABLE:
1750 {
1751 if (start) inTable = true;
1752 else inTable = false;
1753 break;
1754 }
1755 default:
1756 DefaultOnMacro(macroId, no_args, start);
1757 break;
1758 }
1759 }
1760
1761 // Called on start/end of argument examination
1762 bool HTMLOnArgument(int macroId, int arg_no, bool start)
1763 {
1764 switch (macroId)
1765 {
1766 case ltCHAPTER:
1767 case ltCHAPTERSTAR:
1768 case ltCHAPTERHEADING:
1769 case ltSECTION:
1770 case ltSECTIONSTAR:
1771 case ltSECTIONHEADING:
1772 case ltSUBSECTION:
1773 case ltSUBSECTIONSTAR:
1774 case ltSUBSUBSECTION:
1775 case ltSUBSUBSECTIONSTAR:
1776 case ltGLOSS:
1777 case ltMEMBERSECTION:
1778 case ltFUNCTIONSECTION:
1779 {
1780 if (!start && (arg_no == 1))
1781 currentSection = GetArgChunk();
1782 return false;
1783 }
1784 case ltFUNC:
1785 {
1786 if (start && (arg_no == 1))
1787 TexOutput(_T("<B>"));
1788
1789 if (!start && (arg_no == 1))
1790 TexOutput(_T("</B> "));
1791
1792 if (start && (arg_no == 2))
1793 {
1794 if (!suppressNameDecoration) TexOutput(_T("<B>"));
1795 currentMember = GetArgChunk();
1796 }
1797 if (!start && (arg_no == 2))
1798 {
1799 if (!suppressNameDecoration) TexOutput(_T("</B>"));
1800 }
1801
1802 if (start && (arg_no == 3))
1803 TexOutput(_T("("));
1804 if (!start && (arg_no == 3))
1805 TexOutput(_T(")"));
1806 break;
1807 }
1808 case ltCLIPSFUNC:
1809 {
1810 if (start && (arg_no == 1))
1811 TexOutput(_T("<B>"));
1812 if (!start && (arg_no == 1))
1813 TexOutput(_T("</B> "));
1814
1815 if (start && (arg_no == 2))
1816 {
1817 if (!suppressNameDecoration) TexOutput(_T("( "));
1818 currentMember = GetArgChunk();
1819 }
1820 if (!start && (arg_no == 2))
1821 {
1822 }
1823
1824 if (!start && (arg_no == 3))
1825 TexOutput(_T(")"));
1826 break;
1827 }
1828 case ltPFUNC:
1829 {
1830 if (!start && (arg_no == 1))
1831 TexOutput(_T(" "));
1832
1833 if (start && (arg_no == 2))
1834 TexOutput(_T("(*"));
1835 if (!start && (arg_no == 2))
1836 TexOutput(_T(")"));
1837
1838 if (start && (arg_no == 2))
1839 currentMember = GetArgChunk();
1840
1841 if (start && (arg_no == 3))
1842 TexOutput(_T("("));
1843 if (!start && (arg_no == 3))
1844 TexOutput(_T(")"));
1845 break;
1846 }
1847 case ltPARAM:
1848 {
1849 if (start && (arg_no == 1))
1850 TexOutput(_T("<B>"));
1851 if (!start && (arg_no == 1))
1852 TexOutput(_T("</B>"));
1853 if (start && (arg_no == 2))
1854 {
1855 TexOutput(_T("<I>"));
1856 }
1857 if (!start && (arg_no == 2))
1858 {
1859 TexOutput(_T("</I>"));
1860 }
1861 break;
1862 }
1863 case ltCPARAM:
1864 {
1865 if (start && (arg_no == 1))
1866 TexOutput(_T("<B>"));
1867 if (!start && (arg_no == 1))
1868 TexOutput(_T("</B> ")); // This is the difference from param - one space!
1869 if (start && (arg_no == 2))
1870 {
1871 TexOutput(_T("<I>"));
1872 }
1873 if (!start && (arg_no == 2))
1874 {
1875 TexOutput(_T("</I>"));
1876 }
1877 break;
1878 }
1879 case ltMEMBER:
1880 {
1881 if (!start && (arg_no == 1))
1882 TexOutput(_T(" "));
1883
1884 if (start && (arg_no == 2))
1885 currentMember = GetArgChunk();
1886 break;
1887 }
1888 case ltREF:
1889 {
1890 if (start)
1891 {
1892 wxChar *sec = NULL;
1893
1894 wxChar *refName = GetArgData();
1895 if (refName)
1896 {
1897 TexRef *texRef = FindReference(refName);
1898 if (texRef)
1899 {
1900 sec = texRef->sectionNumber;
1901 }
1902 }
1903 if (sec)
1904 {
1905 TexOutput(sec);
1906 }
1907 return false;
1908 }
1909 break;
1910 }
1911 case ltURLREF:
1912 {
1913 if (IsArgOptional())
1914 return false;
1915 else if ((GetNoArgs() - arg_no) == 1)
1916 {
1917 if (start)
1918 helpRefText = GetArgChunk();
1919 return false;
1920 }
1921 else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional
1922 {
1923 if (start)
1924 {
1925 TexChunk *ref = GetArgChunk();
1926 TexOutput(_T("<A HREF=\""));
1927 inVerbatim = true;
1928 TraverseChildrenFromChunk(ref);
1929 inVerbatim = false;
1930 TexOutput(_T("\">"));
1931 if (helpRefText)
1932 TraverseChildrenFromChunk(helpRefText);
1933 TexOutput(_T("</A>"));
1934 }
1935 return false;
1936 }
1937 break;
1938 }
1939 case ltHELPREF:
1940 case ltHELPREFN:
1941 case ltPOPREF:
1942 {
1943 if (IsArgOptional())
1944 {
1945 if (start)
1946 helpRefFilename = GetArgChunk();
1947 return false;
1948 }
1949 if ((GetNoArgs() - arg_no) == 1)
1950 {
1951 if (start)
1952 helpRefText = GetArgChunk();
1953 return false;
1954 }
1955 else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional
1956 {
1957 if (start)
1958 {
1959 wxChar *refName = GetArgData();
1960 wxChar *refFilename = NULL;
1961
1962 if (refName)
1963 {
1964 TexRef *texRef = FindReference(refName);
1965 if (texRef)
1966 {
1967 if (texRef->refFile && wxStrcmp(texRef->refFile, _T("??")) != 0)
1968 refFilename = texRef->refFile;
1969
1970 TexOutput(_T("<A HREF=\""));
1971 // If a filename is supplied, use it, otherwise try to
1972 // use the filename associated with the reference (from this document).
1973 if (helpRefFilename)
1974 {
1975 TraverseChildrenFromChunk(helpRefFilename);
1976 TexOutput(_T("#"));
1977 }
1978 else if (refFilename)
1979 {
1980 TexOutput(ConvertCase(refFilename));
1981 TexOutput(_T("#"));
1982 }
1983 TexOutput(refName);
1984 TexOutput(_T("\">"));
1985 if (helpRefText)
1986 TraverseChildrenFromChunk(helpRefText);
1987 TexOutput(_T("</A>"));
1988 }
1989 else
1990 {
1991 if (helpRefText)
1992 TraverseChildrenFromChunk(helpRefText);
1993 if (!ignoreBadRefs)
1994 TexOutput(_T(" (REF NOT FOUND)"));
1995 wxString errBuf;
1996 errBuf.Printf(_T("Warning: unresolved reference '%s'"), refName);
1997 OnInform((wxChar *)errBuf.c_str());
1998 }
1999 }
2000 else TexOutput(_T("??"));
2001 }
2002 return false;
2003 }
2004 break;
2005 }
2006 case ltIMAGE:
2007 case ltIMAGEL:
2008 case ltIMAGER:
2009 case ltPSBOXTO:
2010 {
2011 if (arg_no == 2)
2012 {
2013 if (start)
2014 {
2015 wxChar *alignment = _T("");
2016 if (macroId == ltIMAGEL)
2017 alignment = _T(" align=left");
2018 else if (macroId == ltIMAGER)
2019 alignment = _T(" align=right");
2020
2021 // Try to find an XBM or GIF image first.
2022 wxChar *filename = copystring(GetArgData());
2023 wxChar buf[500];
2024
2025 wxStrcpy(buf, filename);
2026 StripExtension(buf);
2027 wxStrcat(buf, _T(".xbm"));
2028 wxString f = TexPathList.FindValidPath(buf);
2029
2030 if (f == _T("")) // Try for a GIF instead
2031 {
2032 wxStrcpy(buf, filename);
2033 StripExtension(buf);
2034 wxStrcat(buf, _T(".gif"));
2035 f = TexPathList.FindValidPath(buf);
2036 }
2037
2038 if (f == _T("")) // Try for a JPEG instead
2039 {
2040 wxStrcpy(buf, filename);
2041 StripExtension(buf);
2042 wxStrcat(buf, _T(".jpg"));
2043 f = TexPathList.FindValidPath(buf);
2044 }
2045
2046 if (f == _T("")) // Try for a PNG instead
2047 {
2048 wxStrcpy(buf, filename);
2049 StripExtension(buf);
2050 wxStrcat(buf, _T(".png"));
2051 f = TexPathList.FindValidPath(buf);
2052 }
2053
2054 if (f != _T(""))
2055 {
2056 wxChar *inlineFilename = copystring(f);
2057 #if 0
2058 wxChar *originalFilename = TexPathList.FindValidPath(filename);
2059 // If we have found the existing filename, make the inline
2060 // image point to the original file (could be PS, for example)
2061 if (originalFilename && (wxStrcmp(inlineFilename, originalFilename) != 0))
2062 {
2063 TexOutput(_T("<A HREF=\""));
2064 TexOutput(ConvertCase(originalFilename));
2065 TexOutput(_T("\">"));
2066 TexOutput(_T("<img src=\""));
2067 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename)));
2068 TexOutput(_T("\""));
2069 TexOutput(alignment);
2070 TexOutput(_T("></A>"));
2071 }
2072 else
2073 #endif
2074 {
2075 TexOutput(_T("<img src=\""));
2076 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename)));
2077 TexOutput(_T("\""));
2078 TexOutput(alignment);
2079 TexOutput(_T(">"));
2080 delete[] inlineFilename;
2081 }
2082 }
2083 else
2084 {
2085 // Last resort - a link to a PS file.
2086 TexOutput(_T("<A HREF=\""));
2087 TexOutput(ConvertCase(wxFileNameFromPath(filename)));
2088 TexOutput(_T("\">Picture</A>\n"));
2089 wxSnprintf(buf, sizeof(buf), _T("Warning: could not find an inline XBM/GIF for %s."), filename);
2090 OnInform(buf);
2091 }
2092 }
2093 }
2094 return false;
2095 }
2096 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2097 case ltIMAGEMAP:
2098 {
2099 static wxChar *imageFile = NULL;
2100 if (start && (arg_no == 2))
2101 {
2102 // Try to find an XBM or GIF image first.
2103 wxChar *filename = copystring(GetArgData());
2104 wxChar buf[500];
2105
2106 wxStrcpy(buf, filename);
2107 StripExtension(buf);
2108 wxStrcat(buf, _T(".xbm"));
2109 wxString f = TexPathList.FindValidPath(buf);
2110
2111 if (f == _T("")) // Try for a GIF instead
2112 {
2113 wxStrcpy(buf, filename);
2114 StripExtension(buf);
2115 wxStrcat(buf, _T(".gif"));
2116 f = TexPathList.FindValidPath(buf);
2117 }
2118 if (f == _T(""))
2119 {
2120 wxChar buf[300];
2121 wxSnprintf(buf, sizeof(buf), _T("Warning: could not find an inline XBM/GIF for %s."), filename);
2122 OnInform(buf);
2123 }
2124 delete[] filename;
2125 if (imageFile)
2126 delete[] imageFile;
2127 imageFile = NULL;
2128 if (!f.IsEmpty())
2129 {
2130 imageFile = copystring(f);
2131 }
2132 }
2133 else if (start && (arg_no == 3))
2134 {
2135 if (imageFile)
2136 {
2137 // First, try to find a .shg (segmented hypergraphics file)
2138 // that we can convert to a map file
2139 wxChar buf[256];
2140 wxStrcpy(buf, imageFile);
2141 StripExtension(buf);
2142 wxStrcat(buf, _T(".shg"));
2143 wxString f = TexPathList.FindValidPath(buf);
2144
2145 if (f != _T(""))
2146 {
2147 // The default HTML file to go to is THIS file (so a no-op)
2148 SHGToMap((wxChar *)f.c_str(), currentFileName);
2149 }
2150
2151 wxChar *mapName = GetArgData();
2152 TexOutput(_T("<A HREF=\"/cgi-bin/imagemap/"));
2153 if (mapName)
2154 TexOutput(mapName);
2155 else
2156 TexOutput(_T("unknown"));
2157 TexOutput(_T("\">"));
2158 TexOutput(_T("<img src=\""));
2159 TexOutput(ConvertCase(wxFileNameFromPath(imageFile)));
2160 TexOutput(_T("\" ISMAP></A><P>"));
2161 delete[] imageFile;
2162 imageFile = NULL;
2163 }
2164 }
2165 return false;
2166 }
2167 case ltINDENTED :
2168 {
2169 if ( arg_no == 1 )
2170 return false;
2171 else
2172 {
2173 return true;
2174 }
2175 }
2176 case ltITEM:
2177 {
2178 if (start)
2179 {
2180 descriptionItemArg = GetArgChunk();
2181 return false;
2182 }
2183 return true;
2184 }
2185 case ltTWOCOLITEM:
2186 case ltTWOCOLITEMRULED:
2187 {
2188 /*
2189 if (start && (arg_no == 1))
2190 TexOutput(_T("\n<DT> "));
2191 if (start && (arg_no == 2))
2192 TexOutput(_T("<DD> "));
2193 */
2194 if (arg_no == 1)
2195 {
2196 if ( start ) {
2197 // DHS
2198 if (TwoColWidthA > -1) {
2199 wxChar buf[100];
2200 wxSnprintf(buf, sizeof(buf), _T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA);
2201 TexOutput(buf);
2202 } else
2203 TexOutput(_T("\n<TR><TD VALIGN=TOP>\n"));
2204 OutputFont();
2205 } else
2206 TexOutput(_T("\n</FONT></TD>\n"));
2207 }
2208 if (arg_no == 2)
2209 {
2210 // DHS
2211 if ( start ) {
2212 if (TwoColWidthB > -1) {
2213 wxChar buf[100];
2214 wxSnprintf(buf, sizeof(buf), _T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB);
2215 TexOutput(buf);
2216 } else
2217 TexOutput(_T("\n<TD VALIGN=TOP>\n"));
2218 OutputFont();
2219 } else
2220 TexOutput(_T("\n</FONT></TD></TR>\n"));
2221 }
2222 return true;
2223 }
2224 case ltNUMBEREDBIBITEM:
2225 {
2226 if (arg_no == 1 && start)
2227 {
2228 TexOutput(_T("\n<DT> "));
2229 }
2230 if (arg_no == 2 && !start)
2231 TexOutput(_T("<P>\n"));
2232 break;
2233 }
2234 case ltBIBITEM:
2235 {
2236 wxChar buf[100];
2237 if (arg_no == 1 && start)
2238 {
2239 wxChar *citeKey = GetArgData();
2240 TexRef *ref = (TexRef *)TexReferences.Get(citeKey);
2241 if (ref)
2242 {
2243 if (ref->sectionNumber) delete[] ref->sectionNumber;
2244 wxSnprintf(buf, sizeof(buf), _T("[%d]"), citeCount);
2245 ref->sectionNumber = copystring(buf);
2246 }
2247
2248 wxSnprintf(buf, sizeof(buf), _T("\n<DT> [%d] "), citeCount);
2249 TexOutput(buf);
2250 citeCount ++;
2251 return false;
2252 }
2253 if (arg_no == 2 && !start)
2254 TexOutput(_T("<P>\n"));
2255 return true;
2256 }
2257 case ltMARGINPAR:
2258 case ltMARGINPARODD:
2259 case ltMARGINPAREVEN:
2260 case ltNORMALBOX:
2261 case ltNORMALBOXD:
2262 {
2263 if (start)
2264 {
2265 TexOutput(_T("<HR>\n"));
2266 return true;
2267 }
2268 else
2269 TexOutput(_T("<HR><P>\n"));
2270 break;
2271 }
2272 // DHS
2273 case ltTWOCOLWIDTHA:
2274 {
2275 if (start)
2276 {
2277 wxChar *val = GetArgData();
2278 float points = ParseUnitArgument(val);
2279 TwoColWidthA = (int)((points * 100.0) / 72.0);
2280 }
2281 return false;
2282 }
2283 // DHS
2284 case ltTWOCOLWIDTHB:
2285 {
2286 if (start)
2287 {
2288 wxChar *val = GetArgData();
2289 float points = ParseUnitArgument(val);
2290 TwoColWidthB = (int)((points * 100.0) / 72.0);
2291 }
2292 return false;
2293 }
2294 /*
2295 * Accents
2296 *
2297 */
2298 case ltACCENT_GRAVE:
2299 {
2300 if (start)
2301 {
2302 wxChar *val = GetArgData();
2303 if (val)
2304 {
2305 switch (val[0])
2306 {
2307 case 'a':
2308 TexOutput(_T("&agrave;"));
2309 break;
2310 case 'e':
2311 TexOutput(_T("&egrave;"));
2312 break;
2313 case 'i':
2314 TexOutput(_T("&igrave;"));
2315 break;
2316 case 'o':
2317 TexOutput(_T("&ograve;"));
2318 break;
2319 case 'u':
2320 TexOutput(_T("&ugrave;"));
2321 break;
2322 case 'A':
2323 TexOutput(_T("&Agrave;"));
2324 break;
2325 case 'E':
2326 TexOutput(_T("&Egrave;"));
2327 break;
2328 case 'I':
2329 TexOutput(_T("&Igrave;"));
2330 break;
2331 case 'O':
2332 TexOutput(_T("&Ograve;"));
2333 break;
2334 case 'U':
2335 TexOutput(_T("&Igrave;"));
2336 break;
2337 default:
2338 break;
2339 }
2340 }
2341 }
2342 return false;
2343 }
2344 case ltACCENT_ACUTE:
2345 {
2346 if (start)
2347 {
2348 wxChar *val = GetArgData();
2349 if (val)
2350 {
2351 switch (val[0])
2352 {
2353 case 'a':
2354 TexOutput(_T("&aacute;"));
2355 break;
2356 case 'e':
2357 TexOutput(_T("&eacute;"));
2358 break;
2359 case 'i':
2360 TexOutput(_T("&iacute;"));
2361 break;
2362 case 'o':
2363 TexOutput(_T("&oacute;"));
2364 break;
2365 case 'u':
2366 TexOutput(_T("&uacute;"));
2367 break;
2368 case 'y':
2369 TexOutput(_T("&yacute;"));
2370 break;
2371 case 'A':
2372 TexOutput(_T("&Aacute;"));
2373 break;
2374 case 'E':
2375 TexOutput(_T("&Eacute;"));
2376 break;
2377 case 'I':
2378 TexOutput(_T("&Iacute;"));
2379 break;
2380 case 'O':
2381 TexOutput(_T("&Oacute;"));
2382 break;
2383 case 'U':
2384 TexOutput(_T("&Uacute;"));
2385 break;
2386 case 'Y':
2387 TexOutput(_T("&Yacute;"));
2388 break;
2389 default:
2390 break;
2391 }
2392 }
2393 }
2394 return false;
2395 }
2396 case ltACCENT_CARET:
2397 {
2398 if (start)
2399 {
2400 wxChar *val = GetArgData();
2401 if (val)
2402 {
2403 switch (val[0])
2404 {
2405 case 'a':
2406 TexOutput(_T("&acirc;"));
2407 break;
2408 case 'e':
2409 TexOutput(_T("&ecirc;"));
2410 break;
2411 case 'i':
2412 TexOutput(_T("&icirc;"));
2413 break;
2414 case 'o':
2415 TexOutput(_T("&ocirc;"));
2416 break;
2417 case 'u':
2418 TexOutput(_T("&ucirc;"));
2419 break;
2420 case 'A':
2421 TexOutput(_T("&Acirc;"));
2422 break;
2423 case 'E':
2424 TexOutput(_T("&Ecirc;"));
2425 break;
2426 case 'I':
2427 TexOutput(_T("&Icirc;"));
2428 break;
2429 case 'O':
2430 TexOutput(_T("&Ocirc;"));
2431 break;
2432 case 'U':
2433 TexOutput(_T("&Icirc;"));
2434 break;
2435 default:
2436 break;
2437 }
2438 }
2439 }
2440 return false;
2441 }
2442 case ltACCENT_TILDE:
2443 {
2444 if (start)
2445 {
2446 wxChar *val = GetArgData();
2447 if (val)
2448 {
2449 switch (val[0])
2450 {
2451 case ' ':
2452 TexOutput(_T("~"));
2453 break;
2454 case 'a':
2455 TexOutput(_T("&atilde;"));
2456 break;
2457 case 'n':
2458 TexOutput(_T("&ntilde;"));
2459 break;
2460 case 'o':
2461 TexOutput(_T("&otilde;"));
2462 break;
2463 case 'A':
2464 TexOutput(_T("&Atilde;"));
2465 break;
2466 case 'N':
2467 TexOutput(_T("&Ntilde;"));
2468 break;
2469 case 'O':
2470 TexOutput(_T("&Otilde;"));
2471 break;
2472 default:
2473 break;
2474 }
2475 }
2476 }
2477 return false;
2478 }
2479 case ltACCENT_UMLAUT:
2480 {
2481 if (start)
2482 {
2483 wxChar *val = GetArgData();
2484 if (val)
2485 {
2486 switch (val[0])
2487 {
2488 case 'a':
2489 TexOutput(_T("&auml;"));
2490 break;
2491 case 'e':
2492 TexOutput(_T("&euml;"));
2493 break;
2494 case 'i':
2495 TexOutput(_T("&iuml;"));
2496 break;
2497 case 'o':
2498 TexOutput(_T("&ouml;"));
2499 break;
2500 case 'u':
2501 TexOutput(_T("&uuml;"));
2502 break;
2503 case 'y':
2504 TexOutput(_T("&yuml;"));
2505 break;
2506 case 'A':
2507 TexOutput(_T("&Auml;"));
2508 break;
2509 case 'E':
2510 TexOutput(_T("&Euml;"));
2511 break;
2512 case 'I':
2513 TexOutput(_T("&Iuml;"));
2514 break;
2515 case 'O':
2516 TexOutput(_T("&Ouml;"));
2517 break;
2518 case 'U':
2519 TexOutput(_T("&Uuml;"));
2520 break;
2521 case 'Y':
2522 TexOutput(_T("&Yuml;"));
2523 break;
2524 default:
2525 break;
2526 }
2527 }
2528 }
2529 return false;
2530 }
2531 case ltACCENT_DOT:
2532 {
2533 if (start)
2534 {
2535 wxChar *val = GetArgData();
2536 if (val)
2537 {
2538 switch (val[0])
2539 {
2540 case 'a':
2541 TexOutput(_T("&aring;"));
2542 break;
2543 case 'A':
2544 TexOutput(_T("&Aring;"));
2545 break;
2546 default:
2547 break;
2548 }
2549 }
2550 }
2551 return false;
2552 }
2553 case ltBACKGROUND:
2554 {
2555 if (start)
2556 {
2557 wxChar *val = GetArgData();
2558 if (val)
2559 {
2560 bool isPicture = false;
2561 ParseColourString(val, &isPicture);
2562 if (isPicture)
2563 {
2564 if (backgroundImageString)
2565 delete[] backgroundImageString;
2566 backgroundImageString = copystring(val);
2567 }
2568 else
2569 {
2570 if (backgroundColourString)
2571 delete[] backgroundColourString;
2572 backgroundColourString = copystring(val);
2573 }
2574 }
2575 }
2576 return false;
2577 }
2578 case ltBACKGROUNDIMAGE:
2579 {
2580 if (start)
2581 {
2582 wxChar *val = GetArgData();
2583 if (val)
2584 {
2585 if (backgroundImageString)
2586 delete[] backgroundImageString;
2587 backgroundImageString = copystring(val);
2588 }
2589 }
2590 return false;
2591 }
2592 case ltBACKGROUNDCOLOUR:
2593 {
2594 if (start)
2595 {
2596 wxChar *val = GetArgData();
2597 if (val)
2598 {
2599 if (backgroundColourString)
2600 delete[] backgroundColourString;
2601 backgroundColourString = copystring(val);
2602 }
2603 }
2604 return false;
2605 }
2606 case ltTEXTCOLOUR:
2607 {
2608 if (start)
2609 {
2610 wxChar *val = GetArgData();
2611 if (val)
2612 {
2613 if (textColourString)
2614 delete[] textColourString;
2615 textColourString = copystring(val);
2616 }
2617 }
2618 return false;
2619 }
2620 case ltLINKCOLOUR:
2621 {
2622 if (start)
2623 {
2624 wxChar *val = GetArgData();
2625 if (val)
2626 {
2627 if (linkColourString)
2628 delete[] linkColourString;
2629 linkColourString = copystring(val);
2630 }
2631 }
2632 return false;
2633 }
2634 case ltFOLLOWEDLINKCOLOUR:
2635 {
2636 if (start)
2637 {
2638 wxChar *val = GetArgData();
2639 if (val)
2640 {
2641 if (followedLinkColourString)
2642 delete[] followedLinkColourString;
2643 followedLinkColourString = copystring(val);
2644 }
2645 }
2646 return false;
2647 }
2648 case ltACCENT_CADILLA:
2649 {
2650 if (start)
2651 {
2652 wxChar *val = GetArgData();
2653 if (val)
2654 {
2655 switch (val[0])
2656 {
2657 case 'c':
2658 TexOutput(_T("&ccedil;"));
2659 break;
2660 case 'C':
2661 TexOutput(_T("&Ccedil;"));
2662 break;
2663 default:
2664 break;
2665 }
2666 }
2667 }
2668 return false;
2669 }
2670 /*
2671 case ltFOOTNOTE:
2672 case ltFOOTNOTEPOPUP:
2673 {
2674 if (arg_no == 1)
2675 return true;
2676 else
2677 return false;
2678 break;
2679 }
2680 */
2681 case ltTABULAR:
2682 case ltSUPERTABULAR:
2683 {
2684 if (arg_no == 1)
2685 {
2686 if (start)
2687 {
2688 currentRowNumber = 0;
2689 inTabular = true;
2690 startRows = true;
2691 tableVerticalLineLeft = false;
2692 tableVerticalLineRight = false;
2693
2694 wxChar *alignString = copystring(GetArgData());
2695 ParseTableArgument(alignString);
2696
2697 TexOutput(_T("<TABLE BORDER>\n"));
2698
2699 // Write the first row formatting for compatibility
2700 // with standard Latex
2701 if (compatibilityMode)
2702 {
2703 TexOutput(_T("<TR>\n<TD>"));
2704 OutputFont();
2705 /*
2706 for (int i = 0; i < noColumns; i++)
2707 {
2708 currentWidth += TableData[i].width;
2709 wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth);
2710 TexOutput(buf);
2711 }
2712 TexOutput(_T("\\pard\\intbl\n"));
2713 */
2714 }
2715 delete[] alignString;
2716
2717 return false;
2718 }
2719 }
2720 else if (arg_no == 2 && !start)
2721 {
2722 TexOutput(_T("</TABLE>\n"));
2723 inTabular = false;
2724 }
2725 break;
2726 }
2727 case ltTHEBIBLIOGRAPHY:
2728 {
2729 if (start && (arg_no == 1))
2730 {
2731 ReopenFile(&Chapters, &ChaptersName, _T("bibliography"));
2732 AddTexRef(_T("bibliography"), ChaptersName, _T("bibliography"));
2733 SetCurrentSubsectionName(_T("bibliography"), ChaptersName);
2734
2735 citeCount = 1;
2736
2737 SetCurrentOutput(Chapters);
2738
2739 wxChar titleBuf[150];
2740 if (truncateFilenames)
2741 wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s.htm"), wxFileNameFromPath(FileRoot));
2742 else
2743 wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s_contents.html"), wxFileNameFromPath(FileRoot));
2744
2745 HTMLHead();
2746 TexOutput(_T("<title>"));
2747 TexOutput(ReferencesNameString);
2748 TexOutput(_T("</title></head>\n"));
2749 OutputBodyStart();
2750
2751 wxFprintf(Chapters, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString);
2752 AddBrowseButtons(_T("contents"), titleBuf, // Up
2753 lastTopic, lastFileName, // Last topic
2754 _T("bibliography"), ChaptersName); // This topic
2755
2756 SetCurrentOutputs(Contents, Chapters);
2757 wxFprintf(Contents, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName), "bibliography");
2758
2759 wxFprintf(Contents, _T("%s</A>\n"), ReferencesNameString);
2760 wxFprintf(Chapters, _T("</H2>\n</A>\n"));
2761
2762 SetCurrentOutput(Chapters);
2763 return false;
2764 }
2765 if (!start && (arg_no == 2))
2766 {
2767 }
2768 return true;
2769 }
2770 case ltINDEX:
2771 {
2772 /* Build up list of keywords associated with topics */
2773 if (start)
2774 {
2775 // wxChar *entry = GetArgData();
2776 wxChar buf[300];
2777 OutputChunkToString(GetArgChunk(), buf);
2778 if (CurrentTopic)
2779 {
2780 AddKeyWordForTopic(CurrentTopic, buf, currentFileName);
2781 }
2782 }
2783 return false;
2784 }
2785 case ltFCOL:
2786 // case ltBCOL:
2787 {
2788 if (start)
2789 {
2790 switch (arg_no)
2791 {
2792 case 1:
2793 {
2794 wxChar *name = GetArgData();
2795 wxChar buf2[10];
2796 if (!FindColourHTMLString(name, buf2))
2797 {
2798 wxStrcpy(buf2, _T("#000000"));
2799 wxChar buf[100];
2800 wxSnprintf(buf, sizeof(buf), _T("Could not find colour name %s"), name);
2801 OnError(buf);
2802 }
2803 TexOutput(_T("<FONT COLOR=\""));
2804 TexOutput(buf2);
2805 TexOutput(_T("\">"));
2806 break;
2807 }
2808 case 2:
2809 {
2810 return true;
2811 }
2812 default:
2813 break;
2814 }
2815 }
2816 else
2817 {
2818 if (arg_no == 2) TexOutput(_T("</FONT>"));
2819 }
2820 return false;
2821 }
2822 case ltINSERTATLEVEL:
2823 {
2824 // This macro allows you to insert text at a different level
2825 // from the current level, e.g. into the Sections from within a subsubsection.
2826 if (useWord)
2827 return false;
2828 static int currentLevelNo = 1;
2829 static FILE* oldLevelFile = Chapters;
2830 if (start)
2831 {
2832 switch (arg_no)
2833 {
2834 case 1:
2835 {
2836 oldLevelFile = CurrentOutput1;
2837
2838 wxChar *str = GetArgData();
2839 currentLevelNo = wxAtoi(str);
2840 FILE* outputFile;
2841 // TODO: cope with article style (no chapters)
2842 switch (currentLevelNo)
2843 {
2844 case 1:
2845 {
2846 outputFile = Chapters;
2847 break;
2848 }
2849 case 2:
2850 {
2851 outputFile = Sections;
2852 break;
2853 }
2854 case 3:
2855 {
2856 outputFile = Subsections;
2857 break;
2858 }
2859 case 4:
2860 {
2861 outputFile = Subsubsections;
2862 break;
2863 }
2864 default:
2865 {
2866 outputFile = NULL;
2867 break;
2868 }
2869 }
2870 if (outputFile)
2871 CurrentOutput1 = outputFile;
2872 return false;
2873 }
2874 case 2:
2875 {
2876 return true;
2877 }
2878 default:
2879 break;
2880 }
2881 return true;
2882 }
2883 else
2884 {
2885 if (arg_no == 2)
2886 {
2887 CurrentOutput1 = oldLevelFile;
2888 }
2889 return true;
2890 }
2891 }
2892 default:
2893 return DefaultOnArgument(macroId, arg_no, start);
2894 }
2895 return true;
2896 }
2897
2898 bool HTMLGo(void)
2899 {
2900 fileId = 0;
2901 inVerbatim = false;
2902 indentLevel = 0;
2903 inTabular = false;
2904 startRows = false;
2905 tableVerticalLineLeft = false;
2906 tableVerticalLineRight = false;
2907 noColumns = 0;
2908
2909 if (InputFile && OutputFile)
2910 {
2911 // Do some HTML-specific transformations on all the strings,
2912 // recursively
2913 Text2HTML(GetTopLevelChunk());
2914
2915 wxChar buf[300];
2916 if (truncateFilenames)
2917 wxSnprintf(buf, sizeof(buf), _T("%s.htm"), FileRoot);
2918 else
2919 wxSnprintf(buf, sizeof(buf), _T("%s_contents.html"), FileRoot);
2920 if (TitlepageName) delete[] TitlepageName;
2921 TitlepageName = copystring(buf);
2922 Titlepage = wxFopen(buf, _T("w"));
2923
2924 if (truncateFilenames)
2925 wxSnprintf(buf, sizeof(buf), _T("%s_fc.htm"), FileRoot);
2926 else
2927 wxSnprintf(buf, sizeof(buf), _T("%s_fcontents.html"), FileRoot);
2928
2929 contentsFrameName = copystring(buf);
2930
2931 Contents = wxFopen(TmpContentsName, _T("w"));
2932
2933 if (htmlFrameContents)
2934 {
2935 // FrameContents = wxFopen(TmpFrameContentsName, _T("w"));
2936 FrameContents = wxFopen(contentsFrameName, _T("w"));
2937 wxFprintf(FrameContents, _T("<HTML>\n<UL>\n"));
2938 }
2939
2940 if (!Titlepage || !Contents)
2941 {
2942 OnError(_T("Cannot open output file!"));
2943 return false;
2944 }
2945 AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName), ContentsNameString);
2946
2947 wxFprintf(Contents, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString);
2948
2949 wxFprintf(Contents, _T("<UL>\n"));
2950
2951 SetCurrentOutput(Titlepage);
2952 if (htmlWorkshopFiles) HTMLWorkshopStartContents();
2953 OnInform(_T("Converting..."));
2954
2955 TraverseDocument();
2956 wxFprintf(Contents, _T("</UL>\n\n"));
2957
2958 // SetCurrentOutput(Titlepage);
2959 fclose(Titlepage);
2960
2961 if (Contents)
2962 {
2963 // wxFprintf(Titlepage, _T("\n</BODY></HTML>\n"));
2964 fclose(Contents);
2965 Contents = NULL;
2966 }
2967
2968 if (FrameContents)
2969 {
2970 wxFprintf(FrameContents, _T("\n</UL>\n"));
2971 wxFprintf(FrameContents, _T("</HTML>\n"));
2972 fclose(FrameContents);
2973 FrameContents = NULL;
2974 }
2975
2976 if (Chapters)
2977 {
2978 wxFprintf(Chapters, _T("\n</FONT></BODY></HTML>\n"));
2979 fclose(Chapters);
2980 Chapters = NULL;
2981 }
2982 if (Sections)
2983 {
2984 wxFprintf(Sections, _T("\n</FONT></BODY></HTML>\n"));
2985 fclose(Sections);
2986 Sections = NULL;
2987 }
2988 if (Subsections && !combineSubSections)
2989 {
2990 wxFprintf(Subsections, _T("\n</FONT></BODY></HTML>\n"));
2991 fclose(Subsections);
2992 Subsections = NULL;
2993 }
2994 if (Subsubsections && !combineSubSections)
2995 {
2996 wxFprintf(Subsubsections, _T("\n</FONT></BODY></HTML>\n"));
2997 fclose(Subsubsections);
2998 Subsubsections = NULL;
2999 }
3000 if ( SectionContentsFD )
3001 {
3002 fclose(SectionContentsFD);
3003 SectionContentsFD = NULL;
3004 }
3005
3006 // Create a temporary file for the title page header, add some info,
3007 // and concat the titlepage just generated.
3008 // This is necessary in order to put the title of the document
3009 // at the TOP of the file within <HEAD>, even though we only find out
3010 // what it is later on.
3011 FILE *tmpTitle = wxFopen(_T("title.tmp"), _T("w"));
3012 if (tmpTitle)
3013 {
3014 if (DocumentTitle)
3015 {
3016 SetCurrentOutput(tmpTitle);
3017 HTMLHead();
3018 TexOutput(_T("\n<HEAD><TITLE>"));
3019 TraverseChildrenFromChunk(DocumentTitle);
3020 TexOutput(_T("</TITLE></HEAD>\n"));
3021 }
3022 else
3023 {
3024 SetCurrentOutput(tmpTitle);
3025 HTMLHeadTo(tmpTitle);
3026 if (contentsString)
3027 wxFprintf(tmpTitle, _T("<TITLE>%s</TITLE></HEAD>\n\n"), contentsString);
3028 else
3029 wxFprintf(tmpTitle, _T("<TITLE>%s</TITLE></HEAD>\n\n"), wxFileNameFromPath(FileRoot));
3030 }
3031
3032 // Output frame information
3033 if (htmlFrameContents)
3034 {
3035 wxChar firstFileName[300];
3036 if (truncateFilenames)
3037 wxSnprintf(firstFileName, sizeof(firstFileName), _T("%s1.htm"), FileRoot);
3038 else
3039 wxStrcpy(firstFileName, gs_filenames[1].c_str());
3040
3041 wxFprintf(tmpTitle, _T("<FRAMESET COLS=\"30%%,70%%\">\n"));
3042
3043 wxFprintf(tmpTitle, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName)));
3044 wxFprintf(tmpTitle, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName)));
3045 wxFprintf(tmpTitle, _T("</FRAMESET>\n"));
3046
3047 wxFprintf(tmpTitle, _T("<NOFRAMES>\n"));
3048 }
3049
3050 // Output <BODY...> to temporary title page
3051 OutputBodyStart();
3052
3053 // Concat titlepage
3054 FILE *fd = wxFopen(TitlepageName, _T("r"));
3055 if (fd)
3056 {
3057 int ch = getc(fd);
3058 while (ch != EOF)
3059 {
3060 putc(ch, tmpTitle);
3061 ch = getc(fd);
3062 }
3063 fclose(fd);
3064 }
3065
3066 wxFprintf(tmpTitle, _T("\n</FONT></BODY>\n"));
3067
3068 if (htmlFrameContents)
3069 {
3070 wxFprintf(tmpTitle, _T("\n</NOFRAMES>\n"));
3071 }
3072 wxFprintf(tmpTitle, _T("\n</HTML>\n"));
3073
3074 fclose(tmpTitle);
3075 if (wxFileExists(TitlepageName)) wxRemoveFile(TitlepageName);
3076 if (!wxRenameFile(_T("title.tmp"), TitlepageName))
3077 {
3078 wxCopyFile(_T("title.tmp"), TitlepageName);
3079 wxRemoveFile(_T("title.tmp"));
3080 }
3081 }
3082
3083 if (lastFileName) delete[] lastFileName;
3084 lastFileName = NULL;
3085 if (lastTopic) delete[] lastTopic;
3086 lastTopic = NULL;
3087
3088 if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName);
3089
3090 if (!wxRenameFile(TmpContentsName, ContentsName))
3091 {
3092 wxCopyFile(TmpContentsName, ContentsName);
3093 wxRemoveFile(TmpContentsName);
3094 }
3095
3096 // Generate .htx file if requested
3097 if (htmlIndex)
3098 {
3099 wxChar htmlIndexName[300];
3100 wxSnprintf(htmlIndexName, sizeof(htmlIndexName), _T("%s.htx"), FileRoot);
3101 GenerateHTMLIndexFile(htmlIndexName);
3102 }
3103
3104 // Generate HTML Help Workshop files if requested
3105 if (htmlWorkshopFiles)
3106 {
3107 HTMLWorkshopEndContents();
3108 GenerateHTMLWorkshopFiles(FileRoot);
3109 }
3110
3111
3112 return true;
3113 }
3114
3115 return false;
3116 }
3117
3118 // Output .htx index file
3119 void GenerateHTMLIndexFile(wxChar *fname)
3120 {
3121 FILE *fd = wxFopen(fname, _T("w"));
3122 if (!fd)
3123 return;
3124
3125 TopicTable.BeginFind();
3126 wxHashTable::Node *node = TopicTable.Next();
3127 while (node)
3128 {
3129 TexTopic *texTopic = (TexTopic *)node->GetData();
3130 const wxChar *topicName = node->GetKeyString();
3131 if (texTopic->filename && texTopic->keywords)
3132 {
3133 wxStringListNode *node1 = texTopic->keywords->GetFirst();
3134 while (node1)
3135 {
3136 wxChar *s = (wxChar *)node1->GetData();
3137 wxFprintf(fd, _T("%s|%s|%s\n"), topicName, texTopic->filename, s);
3138 node1 = node1->GetNext();
3139 }
3140 }
3141 node = TopicTable.Next();
3142 }
3143 fclose(fd);
3144 }
3145
3146
3147
3148
3149
3150
3151
3152 // output .hpp, .hhc and .hhk files:
3153
3154
3155 void GenerateHTMLWorkshopFiles(wxChar *fname)
3156 {
3157 FILE *f;
3158 wxChar buf[300];
3159
3160 /* Generate project file : */
3161
3162 wxSnprintf(buf, sizeof(buf), _T("%s.hhp"), fname);
3163 f = wxFopen(buf, _T("wt"));
3164 wxFprintf(f,
3165 _T("[OPTIONS]\n")
3166 _T("Compatibility=1.1\n")
3167 _T("Full-text search=Yes\n")
3168 _T("Contents file=%s.hhc\n")
3169 _T("Compiled file=%s.chm\n")
3170 _T("Default Window=%sHelp\n")
3171 _T("Default topic=%s\n")
3172 _T("Index file=%s.hhk\n")
3173 _T("Title="),
3174 wxFileNameFromPath(fname),
3175 wxFileNameFromPath(fname),
3176 wxFileNameFromPath(fname),
3177 wxFileNameFromPath(TitlepageName),
3178 wxFileNameFromPath(fname)
3179 );
3180
3181 if (DocumentTitle) {
3182 SetCurrentOutput(f);
3183 TraverseChildrenFromChunk(DocumentTitle);
3184 }
3185 else wxFprintf(f, _T("(unknown)"));
3186
3187 wxFprintf(f, _T("\n\n[WINDOWS]\n")
3188 _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"),
3189 wxFileNameFromPath(fname),
3190 wxFileNameFromPath(fname),
3191 wxFileNameFromPath(fname),
3192 wxFileNameFromPath(TitlepageName));
3193
3194
3195 wxFprintf(f, _T("\n\n[FILES]\n"));
3196 wxFprintf(f, _T("%s\n"), wxFileNameFromPath(TitlepageName));
3197 for (int i = 1; i <= fileId; i++) {
3198 if (truncateFilenames)
3199 wxSnprintf(buf, sizeof(buf), _T("%s%d.htm"), wxFileNameFromPath(FileRoot), i);
3200 else
3201 wxStrcpy(buf, wxFileNameFromPath(gs_filenames[i].c_str()));
3202 wxFprintf(f, _T("%s\n"), buf);
3203 }
3204 fclose(f);
3205
3206 /* Generate index file : */
3207
3208 wxSnprintf(buf, sizeof(buf), _T("%s.hhk"), fname);
3209 f = wxFopen(buf, _T("wt"));
3210
3211 wxFprintf(f,
3212 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3213 _T("<HTML>\n"));
3214 HTMLHeadTo(f);
3215 wxFprintf(f,
3216 _T("\n")
3217 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3218 _T("<!-- Sitemap 1.0 -->\n")
3219 _T("</HEAD><BODY>\n")
3220 _T("<OBJECT type=\"text/site properties\">\n")
3221 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3222 _T("</OBJECT>\n")
3223 _T("<UL>\n"));
3224
3225 TopicTable.BeginFind();
3226 wxHashTable::Node *node = TopicTable.Next();
3227 while (node)
3228 {
3229 TexTopic *texTopic = (TexTopic *)node->GetData();
3230 const wxChar *topicName = node->GetKeyString();
3231 if (texTopic->filename && texTopic->keywords)
3232 {
3233 wxStringListNode *node1 = texTopic->keywords->GetFirst();
3234 while (node1)
3235 {
3236 wxChar *s = (wxChar *)node1->GetData();
3237 wxFprintf(f,
3238 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3239 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3240 _T(" <param name=\"Name\" value=\"%s\">\n")
3241 _T(" </OBJECT>\n"),
3242 texTopic->filename, topicName, s);
3243 node1 = node1->GetNext();
3244 }
3245 }
3246 node = TopicTable.Next();
3247 }
3248
3249 wxFprintf(f, _T("</UL>\n"));
3250 fclose(f);
3251 }
3252
3253
3254
3255 static FILE *HTMLWorkshopContents = NULL;
3256 static int HTMLWorkshopLastLevel = 0;
3257
3258 void HTMLWorkshopAddToContents(int level, wxChar *s, wxChar *file)
3259 {
3260 int i;
3261
3262 if (level > HTMLWorkshopLastLevel)
3263 for (i = HTMLWorkshopLastLevel; i < level; i++)
3264 wxFprintf(HTMLWorkshopContents, _T("<UL>"));
3265 if (level < HTMLWorkshopLastLevel)
3266 for (i = level; i < HTMLWorkshopLastLevel; i++)
3267 wxFprintf(HTMLWorkshopContents, _T("</UL>"));
3268
3269 SetCurrentOutput(HTMLWorkshopContents);
3270 wxFprintf(HTMLWorkshopContents,
3271 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3272 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3273 _T(" <param name=\"Name\" value=\""),
3274 file, s);
3275 OutputCurrentSection();
3276 wxFprintf(HTMLWorkshopContents,
3277 _T("\">\n")
3278 _T(" </OBJECT>\n"));
3279 HTMLWorkshopLastLevel = level;
3280 }
3281
3282
3283 void HTMLWorkshopStartContents()
3284 {
3285 wxChar buf[300];
3286 wxSnprintf(buf, sizeof(buf), _T("%s.hhc"), FileRoot);
3287 HTMLWorkshopContents = wxFopen(buf, _T("wt"));
3288 HTMLWorkshopLastLevel = 0;
3289
3290 wxFprintf(HTMLWorkshopContents,
3291 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3292 _T("<HTML>\n"));
3293 HTMLHeadTo(HTMLWorkshopContents);
3294 wxFprintf(HTMLWorkshopContents,
3295 _T("\n")
3296 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3297 _T("<!-- Sitemap 1.0 -->\n")
3298 _T("</HEAD><BODY>\n")
3299 _T("<OBJECT type=\"text/site properties\">\n")
3300 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3301 _T("</OBJECT>\n")
3302 _T("<UL>\n")
3303 _T("<LI> <OBJECT type=\"text/sitemap\">\n")
3304 _T("<param name=\"Local\" value=\"%s\">\n")
3305 _T("<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n"),
3306 wxFileNameFromPath(TitlepageName)
3307 );
3308
3309 }
3310
3311
3312 void HTMLWorkshopEndContents()
3313 {
3314 for (int i = HTMLWorkshopLastLevel; i >= 0; i--)
3315 wxFprintf(HTMLWorkshopContents, _T("</UL>\n"));
3316 fclose(HTMLWorkshopContents);
3317 }