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