]> git.saurik.com Git - wxWidgets.git/blob - utils/tex2rtf/src/htmlutil.cpp
c3233630b791dbeefbee1d08d9db5b6442659d5e
[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 {
2200 wxChar buf[100];
2201 wxSnprintf(buf, sizeof(buf), _T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA);
2202 TexOutput(buf);
2203 }
2204 else
2205 {
2206 TexOutput(_T("\n<TR><TD VALIGN=TOP>\n"));
2207 }
2208 OutputFont();
2209 } else
2210 TexOutput(_T("\n</FONT></TD>\n"));
2211 }
2212 if (arg_no == 2)
2213 {
2214 // DHS
2215 if ( start )
2216 {
2217 if (TwoColWidthB > -1)
2218 {
2219 wxChar buf[100];
2220 wxSnprintf(buf, sizeof(buf), _T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB);
2221 TexOutput(buf);
2222 }
2223 else
2224 {
2225 TexOutput(_T("\n<TD VALIGN=TOP>\n"));
2226 }
2227 OutputFont();
2228 } else
2229 TexOutput(_T("\n</FONT></TD></TR>\n"));
2230 }
2231 return true;
2232 }
2233 case ltNUMBEREDBIBITEM:
2234 {
2235 if (arg_no == 1 && start)
2236 {
2237 TexOutput(_T("\n<DT> "));
2238 }
2239 if (arg_no == 2 && !start)
2240 TexOutput(_T("<P>\n"));
2241 break;
2242 }
2243 case ltBIBITEM:
2244 {
2245 wxChar buf[100];
2246 if (arg_no == 1 && start)
2247 {
2248 wxChar *citeKey = GetArgData();
2249 TexRef *ref = (TexRef *)TexReferences.Get(citeKey);
2250 if (ref)
2251 {
2252 if (ref->sectionNumber) delete[] ref->sectionNumber;
2253 wxSnprintf(buf, sizeof(buf), _T("[%d]"), citeCount);
2254 ref->sectionNumber = copystring(buf);
2255 }
2256
2257 wxSnprintf(buf, sizeof(buf), _T("\n<DT> [%d] "), citeCount);
2258 TexOutput(buf);
2259 citeCount ++;
2260 return false;
2261 }
2262 if (arg_no == 2 && !start)
2263 TexOutput(_T("<P>\n"));
2264 return true;
2265 }
2266 case ltMARGINPAR:
2267 case ltMARGINPARODD:
2268 case ltMARGINPAREVEN:
2269 case ltNORMALBOX:
2270 case ltNORMALBOXD:
2271 {
2272 if (start)
2273 {
2274 TexOutput(_T("<HR>\n"));
2275 return true;
2276 }
2277 else
2278 TexOutput(_T("<HR><P>\n"));
2279 break;
2280 }
2281 // DHS
2282 case ltTWOCOLWIDTHA:
2283 {
2284 if (start)
2285 {
2286 wxChar *val = GetArgData();
2287 float points = ParseUnitArgument(val);
2288 TwoColWidthA = (int)((points * 100.0) / 72.0);
2289 }
2290 return false;
2291 }
2292 // DHS
2293 case ltTWOCOLWIDTHB:
2294 {
2295 if (start)
2296 {
2297 wxChar *val = GetArgData();
2298 float points = ParseUnitArgument(val);
2299 TwoColWidthB = (int)((points * 100.0) / 72.0);
2300 }
2301 return false;
2302 }
2303 /*
2304 * Accents
2305 *
2306 */
2307 case ltACCENT_GRAVE:
2308 {
2309 if (start)
2310 {
2311 wxChar *val = GetArgData();
2312 if (val)
2313 {
2314 switch (val[0])
2315 {
2316 case 'a':
2317 TexOutput(_T("&agrave;"));
2318 break;
2319 case 'e':
2320 TexOutput(_T("&egrave;"));
2321 break;
2322 case 'i':
2323 TexOutput(_T("&igrave;"));
2324 break;
2325 case 'o':
2326 TexOutput(_T("&ograve;"));
2327 break;
2328 case 'u':
2329 TexOutput(_T("&ugrave;"));
2330 break;
2331 case 'A':
2332 TexOutput(_T("&Agrave;"));
2333 break;
2334 case 'E':
2335 TexOutput(_T("&Egrave;"));
2336 break;
2337 case 'I':
2338 TexOutput(_T("&Igrave;"));
2339 break;
2340 case 'O':
2341 TexOutput(_T("&Ograve;"));
2342 break;
2343 case 'U':
2344 TexOutput(_T("&Igrave;"));
2345 break;
2346 default:
2347 break;
2348 }
2349 }
2350 }
2351 return false;
2352 }
2353 case ltACCENT_ACUTE:
2354 {
2355 if (start)
2356 {
2357 wxChar *val = GetArgData();
2358 if (val)
2359 {
2360 switch (val[0])
2361 {
2362 case 'a':
2363 TexOutput(_T("&aacute;"));
2364 break;
2365 case 'e':
2366 TexOutput(_T("&eacute;"));
2367 break;
2368 case 'i':
2369 TexOutput(_T("&iacute;"));
2370 break;
2371 case 'o':
2372 TexOutput(_T("&oacute;"));
2373 break;
2374 case 'u':
2375 TexOutput(_T("&uacute;"));
2376 break;
2377 case 'y':
2378 TexOutput(_T("&yacute;"));
2379 break;
2380 case 'A':
2381 TexOutput(_T("&Aacute;"));
2382 break;
2383 case 'E':
2384 TexOutput(_T("&Eacute;"));
2385 break;
2386 case 'I':
2387 TexOutput(_T("&Iacute;"));
2388 break;
2389 case 'O':
2390 TexOutput(_T("&Oacute;"));
2391 break;
2392 case 'U':
2393 TexOutput(_T("&Uacute;"));
2394 break;
2395 case 'Y':
2396 TexOutput(_T("&Yacute;"));
2397 break;
2398 default:
2399 break;
2400 }
2401 }
2402 }
2403 return false;
2404 }
2405 case ltACCENT_CARET:
2406 {
2407 if (start)
2408 {
2409 wxChar *val = GetArgData();
2410 if (val)
2411 {
2412 switch (val[0])
2413 {
2414 case 'a':
2415 TexOutput(_T("&acirc;"));
2416 break;
2417 case 'e':
2418 TexOutput(_T("&ecirc;"));
2419 break;
2420 case 'i':
2421 TexOutput(_T("&icirc;"));
2422 break;
2423 case 'o':
2424 TexOutput(_T("&ocirc;"));
2425 break;
2426 case 'u':
2427 TexOutput(_T("&ucirc;"));
2428 break;
2429 case 'A':
2430 TexOutput(_T("&Acirc;"));
2431 break;
2432 case 'E':
2433 TexOutput(_T("&Ecirc;"));
2434 break;
2435 case 'I':
2436 TexOutput(_T("&Icirc;"));
2437 break;
2438 case 'O':
2439 TexOutput(_T("&Ocirc;"));
2440 break;
2441 case 'U':
2442 TexOutput(_T("&Icirc;"));
2443 break;
2444 default:
2445 break;
2446 }
2447 }
2448 }
2449 return false;
2450 }
2451 case ltACCENT_TILDE:
2452 {
2453 if (start)
2454 {
2455 wxChar *val = GetArgData();
2456 if (val)
2457 {
2458 switch (val[0])
2459 {
2460 case ' ':
2461 TexOutput(_T("~"));
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 case 'A':
2473 TexOutput(_T("&Atilde;"));
2474 break;
2475 case 'N':
2476 TexOutput(_T("&Ntilde;"));
2477 break;
2478 case 'O':
2479 TexOutput(_T("&Otilde;"));
2480 break;
2481 default:
2482 break;
2483 }
2484 }
2485 }
2486 return false;
2487 }
2488 case ltACCENT_UMLAUT:
2489 {
2490 if (start)
2491 {
2492 wxChar *val = GetArgData();
2493 if (val)
2494 {
2495 switch (val[0])
2496 {
2497 case 'a':
2498 TexOutput(_T("&auml;"));
2499 break;
2500 case 'e':
2501 TexOutput(_T("&euml;"));
2502 break;
2503 case 'i':
2504 TexOutput(_T("&iuml;"));
2505 break;
2506 case 'o':
2507 TexOutput(_T("&ouml;"));
2508 break;
2509 case 'u':
2510 TexOutput(_T("&uuml;"));
2511 break;
2512 case 'y':
2513 TexOutput(_T("&yuml;"));
2514 break;
2515 case 'A':
2516 TexOutput(_T("&Auml;"));
2517 break;
2518 case 'E':
2519 TexOutput(_T("&Euml;"));
2520 break;
2521 case 'I':
2522 TexOutput(_T("&Iuml;"));
2523 break;
2524 case 'O':
2525 TexOutput(_T("&Ouml;"));
2526 break;
2527 case 'U':
2528 TexOutput(_T("&Uuml;"));
2529 break;
2530 case 'Y':
2531 TexOutput(_T("&Yuml;"));
2532 break;
2533 default:
2534 break;
2535 }
2536 }
2537 }
2538 return false;
2539 }
2540 case ltACCENT_DOT:
2541 {
2542 if (start)
2543 {
2544 wxChar *val = GetArgData();
2545 if (val)
2546 {
2547 switch (val[0])
2548 {
2549 case 'a':
2550 TexOutput(_T("&aring;"));
2551 break;
2552 case 'A':
2553 TexOutput(_T("&Aring;"));
2554 break;
2555 default:
2556 break;
2557 }
2558 }
2559 }
2560 return false;
2561 }
2562 case ltBACKGROUND:
2563 {
2564 if (start)
2565 {
2566 wxChar *val = GetArgData();
2567 if (val)
2568 {
2569 bool isPicture = false;
2570 ParseColourString(val, &isPicture);
2571 if (isPicture)
2572 {
2573 if (backgroundImageString)
2574 delete[] backgroundImageString;
2575 backgroundImageString = copystring(val);
2576 }
2577 else
2578 {
2579 if (backgroundColourString)
2580 delete[] backgroundColourString;
2581 backgroundColourString = copystring(val);
2582 }
2583 }
2584 }
2585 return false;
2586 }
2587 case ltBACKGROUNDIMAGE:
2588 {
2589 if (start)
2590 {
2591 wxChar *val = GetArgData();
2592 if (val)
2593 {
2594 if (backgroundImageString)
2595 delete[] backgroundImageString;
2596 backgroundImageString = copystring(val);
2597 }
2598 }
2599 return false;
2600 }
2601 case ltBACKGROUNDCOLOUR:
2602 {
2603 if (start)
2604 {
2605 wxChar *val = GetArgData();
2606 if (val)
2607 {
2608 if (backgroundColourString)
2609 delete[] backgroundColourString;
2610 backgroundColourString = copystring(val);
2611 }
2612 }
2613 return false;
2614 }
2615 case ltTEXTCOLOUR:
2616 {
2617 if (start)
2618 {
2619 wxChar *val = GetArgData();
2620 if (val)
2621 {
2622 if (textColourString)
2623 delete[] textColourString;
2624 textColourString = copystring(val);
2625 }
2626 }
2627 return false;
2628 }
2629 case ltLINKCOLOUR:
2630 {
2631 if (start)
2632 {
2633 wxChar *val = GetArgData();
2634 if (val)
2635 {
2636 if (linkColourString)
2637 delete[] linkColourString;
2638 linkColourString = copystring(val);
2639 }
2640 }
2641 return false;
2642 }
2643 case ltFOLLOWEDLINKCOLOUR:
2644 {
2645 if (start)
2646 {
2647 wxChar *val = GetArgData();
2648 if (val)
2649 {
2650 if (followedLinkColourString)
2651 delete[] followedLinkColourString;
2652 followedLinkColourString = copystring(val);
2653 }
2654 }
2655 return false;
2656 }
2657 case ltACCENT_CADILLA:
2658 {
2659 if (start)
2660 {
2661 wxChar *val = GetArgData();
2662 if (val)
2663 {
2664 switch (val[0])
2665 {
2666 case 'c':
2667 TexOutput(_T("&ccedil;"));
2668 break;
2669 case 'C':
2670 TexOutput(_T("&Ccedil;"));
2671 break;
2672 default:
2673 break;
2674 }
2675 }
2676 }
2677 return false;
2678 }
2679 /*
2680 case ltFOOTNOTE:
2681 case ltFOOTNOTEPOPUP:
2682 {
2683 if (arg_no == 1)
2684 return true;
2685 else
2686 return false;
2687 break;
2688 }
2689 */
2690 case ltTABULAR:
2691 case ltSUPERTABULAR:
2692 {
2693 if (arg_no == 1)
2694 {
2695 if (start)
2696 {
2697 currentRowNumber = 0;
2698 inTabular = true;
2699 startRows = true;
2700 tableVerticalLineLeft = false;
2701 tableVerticalLineRight = false;
2702
2703 wxChar *alignString = copystring(GetArgData());
2704 ParseTableArgument(alignString);
2705
2706 TexOutput(_T("<TABLE BORDER>\n"));
2707
2708 // Write the first row formatting for compatibility
2709 // with standard Latex
2710 if (compatibilityMode)
2711 {
2712 TexOutput(_T("<TR>\n<TD>"));
2713 OutputFont();
2714 /*
2715 for (int i = 0; i < noColumns; i++)
2716 {
2717 currentWidth += TableData[i].width;
2718 wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth);
2719 TexOutput(buf);
2720 }
2721 TexOutput(_T("\\pard\\intbl\n"));
2722 */
2723 }
2724 delete[] alignString;
2725
2726 return false;
2727 }
2728 }
2729 else if (arg_no == 2 && !start)
2730 {
2731 TexOutput(_T("</TABLE>\n"));
2732 inTabular = false;
2733 }
2734 break;
2735 }
2736 case ltTHEBIBLIOGRAPHY:
2737 {
2738 if (start && (arg_no == 1))
2739 {
2740 ReopenFile(&Chapters, &ChaptersName, _T("bibliography"));
2741 AddTexRef(_T("bibliography"), ChaptersName, _T("bibliography"));
2742 SetCurrentSubsectionName(_T("bibliography"), ChaptersName);
2743
2744 citeCount = 1;
2745
2746 SetCurrentOutput(Chapters);
2747
2748 wxChar titleBuf[150];
2749 if (truncateFilenames)
2750 wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s.htm"), wxFileNameFromPath(FileRoot));
2751 else
2752 wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s_contents.html"), wxFileNameFromPath(FileRoot));
2753
2754 HTMLHead();
2755 TexOutput(_T("<title>"));
2756 TexOutput(ReferencesNameString);
2757 TexOutput(_T("</title></head>\n"));
2758 OutputBodyStart();
2759
2760 wxFprintf(Chapters, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString);
2761 AddBrowseButtons(_T("contents"), titleBuf, // Up
2762 lastTopic, lastFileName, // Last topic
2763 _T("bibliography"), ChaptersName); // This topic
2764
2765 SetCurrentOutputs(Contents, Chapters);
2766 wxFprintf(Contents, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName), "bibliography");
2767
2768 wxFprintf(Contents, _T("%s</A>\n"), ReferencesNameString);
2769 wxFprintf(Chapters, _T("</H2>\n</A>\n"));
2770
2771 SetCurrentOutput(Chapters);
2772 return false;
2773 }
2774 if (!start && (arg_no == 2))
2775 {
2776 }
2777 return true;
2778 }
2779 case ltINDEX:
2780 {
2781 /* Build up list of keywords associated with topics */
2782 if (start)
2783 {
2784 // wxChar *entry = GetArgData();
2785 wxChar buf[300];
2786 OutputChunkToString(GetArgChunk(), buf);
2787 if (CurrentTopic)
2788 {
2789 AddKeyWordForTopic(CurrentTopic, buf, currentFileName);
2790 }
2791 }
2792 return false;
2793 }
2794 case ltFCOL:
2795 // case ltBCOL:
2796 {
2797 if (start)
2798 {
2799 switch (arg_no)
2800 {
2801 case 1:
2802 {
2803 wxChar *name = GetArgData();
2804 wxChar buf2[10];
2805 if (!FindColourHTMLString(name, buf2))
2806 {
2807 wxStrcpy(buf2, _T("#000000"));
2808 wxChar buf[100];
2809 wxSnprintf(buf, sizeof(buf), _T("Could not find colour name %s"), name);
2810 OnError(buf);
2811 }
2812 TexOutput(_T("<FONT COLOR=\""));
2813 TexOutput(buf2);
2814 TexOutput(_T("\">"));
2815 break;
2816 }
2817 case 2:
2818 {
2819 return true;
2820 }
2821 default:
2822 break;
2823 }
2824 }
2825 else
2826 {
2827 if (arg_no == 2) TexOutput(_T("</FONT>"));
2828 }
2829 return false;
2830 }
2831 case ltINSERTATLEVEL:
2832 {
2833 // This macro allows you to insert text at a different level
2834 // from the current level, e.g. into the Sections from within a subsubsection.
2835 if (useWord)
2836 return false;
2837 static int currentLevelNo = 1;
2838 static FILE* oldLevelFile = Chapters;
2839 if (start)
2840 {
2841 switch (arg_no)
2842 {
2843 case 1:
2844 {
2845 oldLevelFile = CurrentOutput1;
2846
2847 wxChar *str = GetArgData();
2848 currentLevelNo = wxAtoi(str);
2849 FILE* outputFile;
2850 // TODO: cope with article style (no chapters)
2851 switch (currentLevelNo)
2852 {
2853 case 1:
2854 {
2855 outputFile = Chapters;
2856 break;
2857 }
2858 case 2:
2859 {
2860 outputFile = Sections;
2861 break;
2862 }
2863 case 3:
2864 {
2865 outputFile = Subsections;
2866 break;
2867 }
2868 case 4:
2869 {
2870 outputFile = Subsubsections;
2871 break;
2872 }
2873 default:
2874 {
2875 outputFile = NULL;
2876 break;
2877 }
2878 }
2879 if (outputFile)
2880 CurrentOutput1 = outputFile;
2881 return false;
2882 }
2883 case 2:
2884 {
2885 return true;
2886 }
2887 default:
2888 break;
2889 }
2890 return true;
2891 }
2892 else
2893 {
2894 if (arg_no == 2)
2895 {
2896 CurrentOutput1 = oldLevelFile;
2897 }
2898 return true;
2899 }
2900 }
2901 default:
2902 return DefaultOnArgument(macroId, arg_no, start);
2903 }
2904 return true;
2905 }
2906
2907 bool HTMLGo(void)
2908 {
2909 fileId = 0;
2910 inVerbatim = false;
2911 indentLevel = 0;
2912 inTabular = false;
2913 startRows = false;
2914 tableVerticalLineLeft = false;
2915 tableVerticalLineRight = false;
2916 noColumns = 0;
2917
2918 if (InputFile && OutputFile)
2919 {
2920 // Do some HTML-specific transformations on all the strings,
2921 // recursively
2922 Text2HTML(GetTopLevelChunk());
2923
2924 wxChar buf[300];
2925 if (truncateFilenames)
2926 wxSnprintf(buf, sizeof(buf), _T("%s.htm"), FileRoot);
2927 else
2928 wxSnprintf(buf, sizeof(buf), _T("%s_contents.html"), FileRoot);
2929 if (TitlepageName) delete[] TitlepageName;
2930 TitlepageName = copystring(buf);
2931 Titlepage = wxFopen(buf, _T("w"));
2932
2933 if (truncateFilenames)
2934 wxSnprintf(buf, sizeof(buf), _T("%s_fc.htm"), FileRoot);
2935 else
2936 wxSnprintf(buf, sizeof(buf), _T("%s_fcontents.html"), FileRoot);
2937
2938 contentsFrameName = copystring(buf);
2939
2940 Contents = wxFopen(TmpContentsName, _T("w"));
2941
2942 if (htmlFrameContents)
2943 {
2944 // FrameContents = wxFopen(TmpFrameContentsName, _T("w"));
2945 FrameContents = wxFopen(contentsFrameName, _T("w"));
2946 wxFprintf(FrameContents, _T("<HTML>\n<UL>\n"));
2947 }
2948
2949 if (!Titlepage || !Contents)
2950 {
2951 OnError(_T("Cannot open output file!"));
2952 return false;
2953 }
2954 AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName), ContentsNameString);
2955
2956 wxFprintf(Contents, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString);
2957
2958 wxFprintf(Contents, _T("<UL>\n"));
2959
2960 SetCurrentOutput(Titlepage);
2961 if (htmlWorkshopFiles) HTMLWorkshopStartContents();
2962 OnInform(_T("Converting..."));
2963
2964 TraverseDocument();
2965 wxFprintf(Contents, _T("</UL>\n\n"));
2966
2967 // SetCurrentOutput(Titlepage);
2968 fclose(Titlepage);
2969
2970 if (Contents)
2971 {
2972 // wxFprintf(Titlepage, _T("\n</BODY></HTML>\n"));
2973 fclose(Contents);
2974 Contents = NULL;
2975 }
2976
2977 if (FrameContents)
2978 {
2979 wxFprintf(FrameContents, _T("\n</UL>\n"));
2980 wxFprintf(FrameContents, _T("</HTML>\n"));
2981 fclose(FrameContents);
2982 FrameContents = NULL;
2983 }
2984
2985 if (Chapters)
2986 {
2987 wxFprintf(Chapters, _T("\n</FONT></BODY></HTML>\n"));
2988 fclose(Chapters);
2989 Chapters = NULL;
2990 }
2991 if (Sections)
2992 {
2993 wxFprintf(Sections, _T("\n</FONT></BODY></HTML>\n"));
2994 fclose(Sections);
2995 Sections = NULL;
2996 }
2997 if (Subsections && !combineSubSections)
2998 {
2999 wxFprintf(Subsections, _T("\n</FONT></BODY></HTML>\n"));
3000 fclose(Subsections);
3001 Subsections = NULL;
3002 }
3003 if (Subsubsections && !combineSubSections)
3004 {
3005 wxFprintf(Subsubsections, _T("\n</FONT></BODY></HTML>\n"));
3006 fclose(Subsubsections);
3007 Subsubsections = NULL;
3008 }
3009 if ( SectionContentsFD )
3010 {
3011 fclose(SectionContentsFD);
3012 SectionContentsFD = NULL;
3013 }
3014
3015 // Create a temporary file for the title page header, add some info,
3016 // and concat the titlepage just generated.
3017 // This is necessary in order to put the title of the document
3018 // at the TOP of the file within <HEAD>, even though we only find out
3019 // what it is later on.
3020 FILE *tmpTitle = wxFopen(_T("title.tmp"), _T("w"));
3021 if (tmpTitle)
3022 {
3023 if (DocumentTitle)
3024 {
3025 SetCurrentOutput(tmpTitle);
3026 HTMLHead();
3027 TexOutput(_T("\n<HEAD><TITLE>"));
3028 TraverseChildrenFromChunk(DocumentTitle);
3029 TexOutput(_T("</TITLE></HEAD>\n"));
3030 }
3031 else
3032 {
3033 SetCurrentOutput(tmpTitle);
3034 HTMLHeadTo(tmpTitle);
3035 if (contentsString)
3036 wxFprintf(tmpTitle, _T("<TITLE>%s</TITLE></HEAD>\n\n"), contentsString);
3037 else
3038 wxFprintf(tmpTitle, _T("<TITLE>%s</TITLE></HEAD>\n\n"), wxFileNameFromPath(FileRoot));
3039 }
3040
3041 // Output frame information
3042 if (htmlFrameContents)
3043 {
3044 wxChar firstFileName[300];
3045 if (truncateFilenames)
3046 wxSnprintf(firstFileName, sizeof(firstFileName), _T("%s1.htm"), FileRoot);
3047 else
3048 wxStrcpy(firstFileName, gs_filenames[1].c_str());
3049
3050 wxFprintf(tmpTitle, _T("<FRAMESET COLS=\"30%%,70%%\">\n"));
3051
3052 wxFprintf(tmpTitle, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName)));
3053 wxFprintf(tmpTitle, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName)));
3054 wxFprintf(tmpTitle, _T("</FRAMESET>\n"));
3055
3056 wxFprintf(tmpTitle, _T("<NOFRAMES>\n"));
3057 }
3058
3059 // Output <BODY...> to temporary title page
3060 OutputBodyStart();
3061
3062 // Concat titlepage
3063 FILE *fd = wxFopen(TitlepageName, _T("r"));
3064 if (fd)
3065 {
3066 int ch = getc(fd);
3067 while (ch != EOF)
3068 {
3069 putc(ch, tmpTitle);
3070 ch = getc(fd);
3071 }
3072 fclose(fd);
3073 }
3074
3075 wxFprintf(tmpTitle, _T("\n</FONT></BODY>\n"));
3076
3077 if (htmlFrameContents)
3078 {
3079 wxFprintf(tmpTitle, _T("\n</NOFRAMES>\n"));
3080 }
3081 wxFprintf(tmpTitle, _T("\n</HTML>\n"));
3082
3083 fclose(tmpTitle);
3084 if (wxFileExists(TitlepageName)) wxRemoveFile(TitlepageName);
3085 if (!wxRenameFile(_T("title.tmp"), TitlepageName))
3086 {
3087 wxCopyFile(_T("title.tmp"), TitlepageName);
3088 wxRemoveFile(_T("title.tmp"));
3089 }
3090 }
3091
3092 if (lastFileName) delete[] lastFileName;
3093 lastFileName = NULL;
3094 if (lastTopic) delete[] lastTopic;
3095 lastTopic = NULL;
3096
3097 if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName);
3098
3099 if (!wxRenameFile(TmpContentsName, ContentsName))
3100 {
3101 wxCopyFile(TmpContentsName, ContentsName);
3102 wxRemoveFile(TmpContentsName);
3103 }
3104
3105 // Generate .htx file if requested
3106 if (htmlIndex)
3107 {
3108 wxChar htmlIndexName[300];
3109 wxSnprintf(htmlIndexName, sizeof(htmlIndexName), _T("%s.htx"), FileRoot);
3110 GenerateHTMLIndexFile(htmlIndexName);
3111 }
3112
3113 // Generate HTML Help Workshop files if requested
3114 if (htmlWorkshopFiles)
3115 {
3116 HTMLWorkshopEndContents();
3117 GenerateHTMLWorkshopFiles(FileRoot);
3118 }
3119
3120
3121 return true;
3122 }
3123
3124 return false;
3125 }
3126
3127 // Output .htx index file
3128 void GenerateHTMLIndexFile(wxChar *fname)
3129 {
3130 FILE *fd = wxFopen(fname, _T("w"));
3131 if (!fd)
3132 return;
3133
3134 TopicTable.BeginFind();
3135 wxHashTable::Node *node = TopicTable.Next();
3136 while (node)
3137 {
3138 TexTopic *texTopic = (TexTopic *)node->GetData();
3139 const wxChar *topicName = node->GetKeyString();
3140 if (texTopic->filename && texTopic->keywords)
3141 {
3142 wxStringListNode *node1 = texTopic->keywords->GetFirst();
3143 while (node1)
3144 {
3145 wxChar *s = (wxChar *)node1->GetData();
3146 wxFprintf(fd, _T("%s|%s|%s\n"), topicName, texTopic->filename, s);
3147 node1 = node1->GetNext();
3148 }
3149 }
3150 node = TopicTable.Next();
3151 }
3152 fclose(fd);
3153 }
3154
3155
3156
3157
3158
3159
3160
3161 // output .hpp, .hhc and .hhk files:
3162
3163
3164 void GenerateHTMLWorkshopFiles(wxChar *fname)
3165 {
3166 FILE *f;
3167 wxChar buf[300];
3168
3169 /* Generate project file : */
3170
3171 wxSnprintf(buf, sizeof(buf), _T("%s.hhp"), fname);
3172 f = wxFopen(buf, _T("wt"));
3173 wxFprintf(f,
3174 _T("[OPTIONS]\n")
3175 _T("Compatibility=1.1\n")
3176 _T("Full-text search=Yes\n")
3177 _T("Contents file=%s.hhc\n")
3178 _T("Compiled file=%s.chm\n")
3179 _T("Default Window=%sHelp\n")
3180 _T("Default topic=%s\n")
3181 _T("Index file=%s.hhk\n")
3182 _T("Title="),
3183 wxFileNameFromPath(fname),
3184 wxFileNameFromPath(fname),
3185 wxFileNameFromPath(fname),
3186 wxFileNameFromPath(TitlepageName),
3187 wxFileNameFromPath(fname)
3188 );
3189
3190 if (DocumentTitle) {
3191 SetCurrentOutput(f);
3192 TraverseChildrenFromChunk(DocumentTitle);
3193 }
3194 else wxFprintf(f, _T("(unknown)"));
3195
3196 wxFprintf(f, _T("\n\n[WINDOWS]\n")
3197 _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"),
3198 wxFileNameFromPath(fname),
3199 wxFileNameFromPath(fname),
3200 wxFileNameFromPath(fname),
3201 wxFileNameFromPath(TitlepageName));
3202
3203
3204 wxFprintf(f, _T("\n\n[FILES]\n"));
3205 wxFprintf(f, _T("%s\n"), wxFileNameFromPath(TitlepageName));
3206 for (int i = 1; i <= fileId; i++) {
3207 if (truncateFilenames)
3208 wxSnprintf(buf, sizeof(buf), _T("%s%d.htm"), wxFileNameFromPath(FileRoot), i);
3209 else
3210 wxStrcpy(buf, wxFileNameFromPath(gs_filenames[i].c_str()));
3211 wxFprintf(f, _T("%s\n"), buf);
3212 }
3213 fclose(f);
3214
3215 /* Generate index file : */
3216
3217 wxSnprintf(buf, sizeof(buf), _T("%s.hhk"), fname);
3218 f = wxFopen(buf, _T("wt"));
3219
3220 wxFprintf(f,
3221 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3222 _T("<HTML>\n"));
3223 HTMLHeadTo(f);
3224 wxFprintf(f,
3225 _T("\n")
3226 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3227 _T("<!-- Sitemap 1.0 -->\n")
3228 _T("</HEAD><BODY>\n")
3229 _T("<OBJECT type=\"text/site properties\">\n")
3230 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3231 _T("</OBJECT>\n")
3232 _T("<UL>\n"));
3233
3234 TopicTable.BeginFind();
3235 wxHashTable::Node *node = TopicTable.Next();
3236 while (node)
3237 {
3238 TexTopic *texTopic = (TexTopic *)node->GetData();
3239 const wxChar *topicName = node->GetKeyString();
3240 if (texTopic->filename && texTopic->keywords)
3241 {
3242 wxStringListNode *node1 = texTopic->keywords->GetFirst();
3243 while (node1)
3244 {
3245 wxChar *s = (wxChar *)node1->GetData();
3246 wxFprintf(f,
3247 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3248 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3249 _T(" <param name=\"Name\" value=\"%s\">\n")
3250 _T(" </OBJECT>\n"),
3251 texTopic->filename, topicName, s);
3252 node1 = node1->GetNext();
3253 }
3254 }
3255 node = TopicTable.Next();
3256 }
3257
3258 wxFprintf(f, _T("</UL>\n"));
3259 fclose(f);
3260 }
3261
3262
3263
3264 static FILE *HTMLWorkshopContents = NULL;
3265 static int HTMLWorkshopLastLevel = 0;
3266
3267 void HTMLWorkshopAddToContents(int level, wxChar *s, wxChar *file)
3268 {
3269 int i;
3270
3271 if (level > HTMLWorkshopLastLevel)
3272 for (i = HTMLWorkshopLastLevel; i < level; i++)
3273 wxFprintf(HTMLWorkshopContents, _T("<UL>"));
3274 if (level < HTMLWorkshopLastLevel)
3275 for (i = level; i < HTMLWorkshopLastLevel; i++)
3276 wxFprintf(HTMLWorkshopContents, _T("</UL>"));
3277
3278 SetCurrentOutput(HTMLWorkshopContents);
3279 wxFprintf(HTMLWorkshopContents,
3280 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3281 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3282 _T(" <param name=\"Name\" value=\""),
3283 file, s);
3284 OutputCurrentSection();
3285 wxFprintf(HTMLWorkshopContents,
3286 _T("\">\n")
3287 _T(" </OBJECT>\n"));
3288 HTMLWorkshopLastLevel = level;
3289 }
3290
3291
3292 void HTMLWorkshopStartContents()
3293 {
3294 wxChar buf[300];
3295 wxSnprintf(buf, sizeof(buf), _T("%s.hhc"), FileRoot);
3296 HTMLWorkshopContents = wxFopen(buf, _T("wt"));
3297 HTMLWorkshopLastLevel = 0;
3298
3299 wxFprintf(HTMLWorkshopContents,
3300 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3301 _T("<HTML>\n"));
3302 HTMLHeadTo(HTMLWorkshopContents);
3303 wxFprintf(HTMLWorkshopContents,
3304 _T("\n")
3305 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3306 _T("<!-- Sitemap 1.0 -->\n")
3307 _T("</HEAD><BODY>\n")
3308 _T("<OBJECT type=\"text/site properties\">\n")
3309 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3310 _T("</OBJECT>\n")
3311 _T("<UL>\n")
3312 _T("<LI> <OBJECT type=\"text/sitemap\">\n")
3313 _T("<param name=\"Local\" value=\"%s\">\n")
3314 _T("<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n"),
3315 wxFileNameFromPath(TitlepageName)
3316 );
3317
3318 }
3319
3320
3321 void HTMLWorkshopEndContents()
3322 {
3323 for (int i = HTMLWorkshopLastLevel; i >= 0; i--)
3324 wxFprintf(HTMLWorkshopContents, _T("</UL>\n"));
3325 fclose(HTMLWorkshopContents);
3326 }