]> git.saurik.com Git - wxWidgets.git/blob - utils/tex2rtf/src/htmlutil.cpp
550f553a0d5d09b96b3c66602f7a2e52b1bbe1de
[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
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 char 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 == '`' && (len >= i+1 && chunk->value[i+1] == '`'))
281 {
282 BigBuffer[ptr] = '"'; ptr ++;
283 i += 2;
284 changed = true;
285 }
286 else if (!inVerbatim && ch == '`') // Change ` to '
287 {
288 BigBuffer[ptr] = 39; ptr ++;
289 i += 1;
290 changed = true;
291 }
292 else if (ch == '<') // 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 == '>') // 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
1805 // Called on start/end of argument examination
1806 bool HTMLOnArgument(int macroId, int arg_no, bool start)
1807 {
1808 switch (macroId)
1809 {
1810 case ltCHAPTER:
1811 case ltCHAPTERSTAR:
1812 case ltCHAPTERHEADING:
1813 case ltSECTION:
1814 case ltSECTIONSTAR:
1815 case ltSECTIONHEADING:
1816 case ltSUBSECTION:
1817 case ltSUBSECTIONSTAR:
1818 case ltSUBSUBSECTION:
1819 case ltSUBSUBSECTIONSTAR:
1820 case ltGLOSS:
1821 case ltMEMBERSECTION:
1822 case ltFUNCTIONSECTION:
1823 {
1824 if (!start && (arg_no == 1))
1825 currentSection = GetArgChunk();
1826 return false;
1827 }
1828 case ltFUNC:
1829 {
1830 if (start && (arg_no == 1))
1831 TexOutput(_T("<B>"));
1832
1833 if (!start && (arg_no == 1))
1834 TexOutput(_T("</B> "));
1835
1836 if (start && (arg_no == 2))
1837 {
1838 if (!suppressNameDecoration) TexOutput(_T("<B>"));
1839 currentMember = GetArgChunk();
1840 }
1841 if (!start && (arg_no == 2))
1842 {
1843 if (!suppressNameDecoration) TexOutput(_T("</B>"));
1844 }
1845
1846 if (start && (arg_no == 3))
1847 TexOutput(_T("("));
1848 if (!start && (arg_no == 3))
1849 TexOutput(_T(")"));
1850 break;
1851 }
1852 case ltCLIPSFUNC:
1853 {
1854 if (start && (arg_no == 1))
1855 TexOutput(_T("<B>"));
1856 if (!start && (arg_no == 1))
1857 TexOutput(_T("</B> "));
1858
1859 if (start && (arg_no == 2))
1860 {
1861 if (!suppressNameDecoration) TexOutput(_T("( "));
1862 currentMember = GetArgChunk();
1863 }
1864 if (!start && (arg_no == 2))
1865 {
1866 }
1867
1868 if (!start && (arg_no == 3))
1869 TexOutput(_T(")"));
1870 break;
1871 }
1872 case ltPFUNC:
1873 {
1874 if (!start && (arg_no == 1))
1875 TexOutput(_T(" "));
1876
1877 if (start && (arg_no == 2))
1878 TexOutput(_T("(*"));
1879 if (!start && (arg_no == 2))
1880 TexOutput(_T(")"));
1881
1882 if (start && (arg_no == 2))
1883 currentMember = GetArgChunk();
1884
1885 if (start && (arg_no == 3))
1886 TexOutput(_T("("));
1887 if (!start && (arg_no == 3))
1888 TexOutput(_T(")"));
1889 break;
1890 }
1891 case ltPARAM:
1892 {
1893 if (start && (arg_no == 1))
1894 TexOutput(_T("<B>"));
1895 if (!start && (arg_no == 1))
1896 TexOutput(_T("</B>"));
1897 if (start && (arg_no == 2))
1898 {
1899 TexOutput(_T("<I>"));
1900 }
1901 if (!start && (arg_no == 2))
1902 {
1903 TexOutput(_T("</I>"));
1904 }
1905 break;
1906 }
1907 case ltCPARAM:
1908 {
1909 if (start && (arg_no == 1))
1910 TexOutput(_T("<B>"));
1911 if (!start && (arg_no == 1))
1912 TexOutput(_T("</B> ")); // This is the difference from param - one space!
1913 if (start && (arg_no == 2))
1914 {
1915 TexOutput(_T("<I>"));
1916 }
1917 if (!start && (arg_no == 2))
1918 {
1919 TexOutput(_T("</I>"));
1920 }
1921 break;
1922 }
1923 case ltMEMBER:
1924 {
1925 if (!start && (arg_no == 1))
1926 TexOutput(_T(" "));
1927
1928 if (start && (arg_no == 2))
1929 currentMember = GetArgChunk();
1930 break;
1931 }
1932 case ltREF:
1933 {
1934 if (start)
1935 {
1936 wxChar *sec = NULL;
1937
1938 wxChar *refName = GetArgData();
1939 if (refName)
1940 {
1941 TexRef *texRef = FindReference(refName);
1942 if (texRef)
1943 {
1944 sec = texRef->sectionNumber;
1945 }
1946 }
1947 if (sec)
1948 {
1949 TexOutput(sec);
1950 }
1951 return false;
1952 }
1953 break;
1954 }
1955 case ltURLREF:
1956 {
1957 if (IsArgOptional())
1958 return false;
1959 else if ((GetNoArgs() - arg_no) == 1)
1960 {
1961 if (start)
1962 helpRefText = GetArgChunk();
1963 return false;
1964 }
1965 else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional
1966 {
1967 if (start)
1968 {
1969 TexChunk *ref = GetArgChunk();
1970 TexOutput(_T("<A HREF=\""));
1971 inVerbatim = true;
1972 TraverseChildrenFromChunk(ref);
1973 inVerbatim = false;
1974 TexOutput(_T("\">"));
1975 if (helpRefText)
1976 TraverseChildrenFromChunk(helpRefText);
1977 TexOutput(_T("</A>"));
1978 }
1979 return false;
1980 }
1981 break;
1982 }
1983 case ltHELPREF:
1984 case ltHELPREFN:
1985 case ltPOPREF:
1986 {
1987 if (IsArgOptional())
1988 {
1989 if (start)
1990 helpRefFilename = GetArgChunk();
1991 return false;
1992 }
1993 if ((GetNoArgs() - arg_no) == 1)
1994 {
1995 if (start)
1996 helpRefText = GetArgChunk();
1997 return false;
1998 }
1999 else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional
2000 {
2001 if (start)
2002 {
2003 wxChar *refName = GetArgData();
2004 wxChar *refFilename = NULL;
2005
2006 if (refName)
2007 {
2008 TexRef *texRef = FindReference(refName);
2009 if (texRef)
2010 {
2011 if (texRef->refFile && wxStrcmp(texRef->refFile, _T("??")) != 0)
2012 refFilename = texRef->refFile;
2013
2014 TexOutput(_T("<A HREF=\""));
2015 // If a filename is supplied, use it, otherwise try to
2016 // use the filename associated with the reference (from this document).
2017 if (helpRefFilename)
2018 {
2019 TraverseChildrenFromChunk(helpRefFilename);
2020 TexOutput(_T("#"));
2021 TexOutput(refName);
2022 }
2023 else if (refFilename)
2024 {
2025 TexOutput(ConvertCase(refFilename));
2026 if(!PrimaryAnchorOfTheFile(texRef->refFile, refName))
2027 {
2028 TexOutput(_T("#"));
2029 TexOutput(refName);
2030 }
2031 }
2032 TexOutput(_T("\">"));
2033 if (helpRefText)
2034 TraverseChildrenFromChunk(helpRefText);
2035 TexOutput(_T("</A>"));
2036 }
2037 else
2038 {
2039 if (helpRefText)
2040 TraverseChildrenFromChunk(helpRefText);
2041 if (!ignoreBadRefs)
2042 TexOutput(_T(" (REF NOT FOUND)"));
2043 wxString errBuf;
2044 errBuf.Printf(_T("Warning: unresolved reference '%s'"), refName);
2045 OnInform((wxChar *)errBuf.c_str());
2046 }
2047 }
2048 else TexOutput(_T("??"));
2049 }
2050 return false;
2051 }
2052 break;
2053 }
2054 case ltIMAGE:
2055 case ltIMAGEL:
2056 case ltIMAGER:
2057 case ltPSBOXTO:
2058 {
2059 if (arg_no == 2)
2060 {
2061 if (start)
2062 {
2063 wxChar *alignment = _T("");
2064 if (macroId == ltIMAGEL)
2065 alignment = _T(" align=left");
2066 else if (macroId == ltIMAGER)
2067 alignment = _T(" align=right");
2068
2069 // Try to find an XBM or GIF image first.
2070 wxChar *filename = copystring(GetArgData());
2071 wxChar buf[500];
2072
2073 wxStrcpy(buf, filename);
2074 StripExtension(buf);
2075 wxStrcat(buf, _T(".xbm"));
2076 wxString f = TexPathList.FindValidPath(buf);
2077
2078 if (f == _T("")) // Try for a GIF instead
2079 {
2080 wxStrcpy(buf, filename);
2081 StripExtension(buf);
2082 wxStrcat(buf, _T(".gif"));
2083 f = TexPathList.FindValidPath(buf);
2084 }
2085
2086 if (f == _T("")) // Try for a JPEG instead
2087 {
2088 wxStrcpy(buf, filename);
2089 StripExtension(buf);
2090 wxStrcat(buf, _T(".jpg"));
2091 f = TexPathList.FindValidPath(buf);
2092 }
2093
2094 if (f == _T("")) // Try for a PNG instead
2095 {
2096 wxStrcpy(buf, filename);
2097 StripExtension(buf);
2098 wxStrcat(buf, _T(".png"));
2099 f = TexPathList.FindValidPath(buf);
2100 }
2101
2102 if (f != _T(""))
2103 {
2104 wxChar *inlineFilename = copystring(f);
2105 #if 0
2106 wxChar *originalFilename = TexPathList.FindValidPath(filename);
2107 // If we have found the existing filename, make the inline
2108 // image point to the original file (could be PS, for example)
2109 if (originalFilename && (wxStrcmp(inlineFilename, originalFilename) != 0))
2110 {
2111 TexOutput(_T("<A HREF=\""));
2112 TexOutput(ConvertCase(originalFilename));
2113 TexOutput(_T("\">"));
2114 TexOutput(_T("<img src=\""));
2115 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename)));
2116 TexOutput(_T("\""));
2117 TexOutput(alignment);
2118 TexOutput(_T("></A>"));
2119 }
2120 else
2121 #endif
2122 {
2123 TexOutput(_T("<img src=\""));
2124 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename)));
2125 TexOutput(_T("\""));
2126 TexOutput(alignment);
2127 TexOutput(_T(">"));
2128 delete[] inlineFilename;
2129 }
2130 }
2131 else
2132 {
2133 // Last resort - a link to a PS file.
2134 TexOutput(_T("<A HREF=\""));
2135 TexOutput(ConvertCase(wxFileNameFromPath(filename)));
2136 TexOutput(_T("\">Picture</A>\n"));
2137 wxSnprintf(buf, sizeof(buf), _T("Warning: could not find an inline XBM/GIF for %s."), filename);
2138 OnInform(buf);
2139 }
2140 }
2141 }
2142 return false;
2143 }
2144 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2145 case ltIMAGEMAP:
2146 {
2147 static wxChar *imageFile = NULL;
2148 if (start && (arg_no == 2))
2149 {
2150 // Try to find an XBM or GIF image first.
2151 wxChar *filename = copystring(GetArgData());
2152 wxChar buf[500];
2153
2154 wxStrcpy(buf, filename);
2155 StripExtension(buf);
2156 wxStrcat(buf, _T(".xbm"));
2157 wxString f = TexPathList.FindValidPath(buf);
2158
2159 if (f == _T("")) // Try for a GIF instead
2160 {
2161 wxStrcpy(buf, filename);
2162 StripExtension(buf);
2163 wxStrcat(buf, _T(".gif"));
2164 f = TexPathList.FindValidPath(buf);
2165 }
2166 if (f == _T(""))
2167 {
2168 wxChar buf[300];
2169 wxSnprintf(buf, sizeof(buf), _T("Warning: could not find an inline XBM/GIF for %s."), filename);
2170 OnInform(buf);
2171 }
2172 delete[] filename;
2173 if (imageFile)
2174 delete[] imageFile;
2175 imageFile = NULL;
2176 if (!f.IsEmpty())
2177 {
2178 imageFile = copystring(f);
2179 }
2180 }
2181 else if (start && (arg_no == 3))
2182 {
2183 if (imageFile)
2184 {
2185 // First, try to find a .shg (segmented hypergraphics file)
2186 // that we can convert to a map file
2187 wxChar buf[256];
2188 wxStrcpy(buf, imageFile);
2189 StripExtension(buf);
2190 wxStrcat(buf, _T(".shg"));
2191 wxString f = TexPathList.FindValidPath(buf);
2192
2193 if (f != _T(""))
2194 {
2195 // The default HTML file to go to is THIS file (so a no-op)
2196 SHGToMap((wxChar *)f.c_str(), currentFileName);
2197 }
2198
2199 wxChar *mapName = GetArgData();
2200 TexOutput(_T("<A HREF=\"/cgi-bin/imagemap/"));
2201 if (mapName)
2202 TexOutput(mapName);
2203 else
2204 TexOutput(_T("unknown"));
2205 TexOutput(_T("\">"));
2206 TexOutput(_T("<img src=\""));
2207 TexOutput(ConvertCase(wxFileNameFromPath(imageFile)));
2208 TexOutput(_T("\" ISMAP></A><P>"));
2209 delete[] imageFile;
2210 imageFile = NULL;
2211 }
2212 }
2213 return false;
2214 }
2215 case ltINDENTED :
2216 {
2217 if ( arg_no == 1 )
2218 return false;
2219 else
2220 {
2221 return true;
2222 }
2223 }
2224 case ltITEM:
2225 {
2226 if (start)
2227 {
2228 descriptionItemArg = GetArgChunk();
2229 return false;
2230 }
2231 return true;
2232 }
2233 case ltTWOCOLITEM:
2234 case ltTWOCOLITEMRULED:
2235 {
2236 /*
2237 if (start && (arg_no == 1))
2238 TexOutput(_T("\n<DT> "));
2239 if (start && (arg_no == 2))
2240 TexOutput(_T("<DD> "));
2241 */
2242 if (arg_no == 1)
2243 {
2244 if ( start ) {
2245 // DHS
2246 if (TwoColWidthA > -1)
2247 {
2248 wxChar buf[100];
2249 wxSnprintf(buf, sizeof(buf), _T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA);
2250 TexOutput(buf);
2251 }
2252 else
2253 {
2254 TexOutput(_T("\n<TR><TD VALIGN=TOP>\n"));
2255 }
2256 OutputFont();
2257 } else
2258 TexOutput(_T("\n</FONT></TD>\n"));
2259 }
2260 if (arg_no == 2)
2261 {
2262 // DHS
2263 if ( start )
2264 {
2265 if (TwoColWidthB > -1)
2266 {
2267 wxChar buf[100];
2268 wxSnprintf(buf, sizeof(buf), _T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB);
2269 TexOutput(buf);
2270 }
2271 else
2272 {
2273 TexOutput(_T("\n<TD VALIGN=TOP>\n"));
2274 }
2275 OutputFont();
2276 } else
2277 TexOutput(_T("\n</FONT></TD></TR>\n"));
2278 }
2279 return true;
2280 }
2281 case ltNUMBEREDBIBITEM:
2282 {
2283 if (arg_no == 1 && start)
2284 {
2285 TexOutput(_T("\n<DT> "));
2286 }
2287 if (arg_no == 2 && !start)
2288 TexOutput(_T("<P>\n"));
2289 break;
2290 }
2291 case ltBIBITEM:
2292 {
2293 wxChar buf[100];
2294 if (arg_no == 1 && start)
2295 {
2296 wxChar *citeKey = GetArgData();
2297 TexRef *ref = (TexRef *)TexReferences.Get(citeKey);
2298 if (ref)
2299 {
2300 if (ref->sectionNumber) delete[] ref->sectionNumber;
2301 wxSnprintf(buf, sizeof(buf), _T("[%d]"), citeCount);
2302 ref->sectionNumber = copystring(buf);
2303 }
2304
2305 wxSnprintf(buf, sizeof(buf), _T("\n<DT> [%d] "), citeCount);
2306 TexOutput(buf);
2307 citeCount ++;
2308 return false;
2309 }
2310 if (arg_no == 2 && !start)
2311 TexOutput(_T("<P>\n"));
2312 return true;
2313 }
2314 case ltMARGINPAR:
2315 case ltMARGINPARODD:
2316 case ltMARGINPAREVEN:
2317 case ltNORMALBOX:
2318 case ltNORMALBOXD:
2319 {
2320 if (start)
2321 {
2322 TexOutput(_T("<HR>\n"));
2323 return true;
2324 }
2325 else
2326 TexOutput(_T("<HR><P>\n"));
2327 break;
2328 }
2329 // DHS
2330 case ltTWOCOLWIDTHA:
2331 {
2332 if (start)
2333 {
2334 wxChar *val = GetArgData();
2335 float points = ParseUnitArgument(val);
2336 TwoColWidthA = (int)((points * 100.0) / 72.0);
2337 }
2338 return false;
2339 }
2340 // DHS
2341 case ltTWOCOLWIDTHB:
2342 {
2343 if (start)
2344 {
2345 wxChar *val = GetArgData();
2346 float points = ParseUnitArgument(val);
2347 TwoColWidthB = (int)((points * 100.0) / 72.0);
2348 }
2349 return false;
2350 }
2351 /*
2352 * Accents
2353 *
2354 */
2355 case ltACCENT_GRAVE:
2356 {
2357 if (start)
2358 {
2359 wxChar *val = GetArgData();
2360 if (val)
2361 {
2362 switch (val[0])
2363 {
2364 case 'a':
2365 TexOutput(_T("&agrave;"));
2366 break;
2367 case 'e':
2368 TexOutput(_T("&egrave;"));
2369 break;
2370 case 'i':
2371 TexOutput(_T("&igrave;"));
2372 break;
2373 case 'o':
2374 TexOutput(_T("&ograve;"));
2375 break;
2376 case 'u':
2377 TexOutput(_T("&ugrave;"));
2378 break;
2379 case 'A':
2380 TexOutput(_T("&Agrave;"));
2381 break;
2382 case 'E':
2383 TexOutput(_T("&Egrave;"));
2384 break;
2385 case 'I':
2386 TexOutput(_T("&Igrave;"));
2387 break;
2388 case 'O':
2389 TexOutput(_T("&Ograve;"));
2390 break;
2391 case 'U':
2392 TexOutput(_T("&Igrave;"));
2393 break;
2394 default:
2395 break;
2396 }
2397 }
2398 }
2399 return false;
2400 }
2401 case ltACCENT_ACUTE:
2402 {
2403 if (start)
2404 {
2405 wxChar *val = GetArgData();
2406 if (val)
2407 {
2408 switch (val[0])
2409 {
2410 case 'a':
2411 TexOutput(_T("&aacute;"));
2412 break;
2413 case 'e':
2414 TexOutput(_T("&eacute;"));
2415 break;
2416 case 'i':
2417 TexOutput(_T("&iacute;"));
2418 break;
2419 case 'o':
2420 TexOutput(_T("&oacute;"));
2421 break;
2422 case 'u':
2423 TexOutput(_T("&uacute;"));
2424 break;
2425 case 'y':
2426 TexOutput(_T("&yacute;"));
2427 break;
2428 case 'A':
2429 TexOutput(_T("&Aacute;"));
2430 break;
2431 case 'E':
2432 TexOutput(_T("&Eacute;"));
2433 break;
2434 case 'I':
2435 TexOutput(_T("&Iacute;"));
2436 break;
2437 case 'O':
2438 TexOutput(_T("&Oacute;"));
2439 break;
2440 case 'U':
2441 TexOutput(_T("&Uacute;"));
2442 break;
2443 case 'Y':
2444 TexOutput(_T("&Yacute;"));
2445 break;
2446 default:
2447 break;
2448 }
2449 }
2450 }
2451 return false;
2452 }
2453 case ltACCENT_CARET:
2454 {
2455 if (start)
2456 {
2457 wxChar *val = GetArgData();
2458 if (val)
2459 {
2460 switch (val[0])
2461 {
2462 case 'a':
2463 TexOutput(_T("&acirc;"));
2464 break;
2465 case 'e':
2466 TexOutput(_T("&ecirc;"));
2467 break;
2468 case 'i':
2469 TexOutput(_T("&icirc;"));
2470 break;
2471 case 'o':
2472 TexOutput(_T("&ocirc;"));
2473 break;
2474 case 'u':
2475 TexOutput(_T("&ucirc;"));
2476 break;
2477 case 'A':
2478 TexOutput(_T("&Acirc;"));
2479 break;
2480 case 'E':
2481 TexOutput(_T("&Ecirc;"));
2482 break;
2483 case 'I':
2484 TexOutput(_T("&Icirc;"));
2485 break;
2486 case 'O':
2487 TexOutput(_T("&Ocirc;"));
2488 break;
2489 case 'U':
2490 TexOutput(_T("&Icirc;"));
2491 break;
2492 default:
2493 break;
2494 }
2495 }
2496 }
2497 return false;
2498 }
2499 case ltACCENT_TILDE:
2500 {
2501 if (start)
2502 {
2503 wxChar *val = GetArgData();
2504 if (val)
2505 {
2506 switch (val[0])
2507 {
2508 case ' ':
2509 TexOutput(_T("~"));
2510 break;
2511 case 'a':
2512 TexOutput(_T("&atilde;"));
2513 break;
2514 case 'n':
2515 TexOutput(_T("&ntilde;"));
2516 break;
2517 case 'o':
2518 TexOutput(_T("&otilde;"));
2519 break;
2520 case 'A':
2521 TexOutput(_T("&Atilde;"));
2522 break;
2523 case 'N':
2524 TexOutput(_T("&Ntilde;"));
2525 break;
2526 case 'O':
2527 TexOutput(_T("&Otilde;"));
2528 break;
2529 default:
2530 break;
2531 }
2532 }
2533 }
2534 return false;
2535 }
2536 case ltACCENT_UMLAUT:
2537 {
2538 if (start)
2539 {
2540 wxChar *val = GetArgData();
2541 if (val)
2542 {
2543 switch (val[0])
2544 {
2545 case 'a':
2546 TexOutput(_T("&auml;"));
2547 break;
2548 case 'e':
2549 TexOutput(_T("&euml;"));
2550 break;
2551 case 'i':
2552 TexOutput(_T("&iuml;"));
2553 break;
2554 case 'o':
2555 TexOutput(_T("&ouml;"));
2556 break;
2557 case 'u':
2558 TexOutput(_T("&uuml;"));
2559 break;
2560 case 'y':
2561 TexOutput(_T("&yuml;"));
2562 break;
2563 case 'A':
2564 TexOutput(_T("&Auml;"));
2565 break;
2566 case 'E':
2567 TexOutput(_T("&Euml;"));
2568 break;
2569 case 'I':
2570 TexOutput(_T("&Iuml;"));
2571 break;
2572 case 'O':
2573 TexOutput(_T("&Ouml;"));
2574 break;
2575 case 'U':
2576 TexOutput(_T("&Uuml;"));
2577 break;
2578 case 'Y':
2579 TexOutput(_T("&Yuml;"));
2580 break;
2581 default:
2582 break;
2583 }
2584 }
2585 }
2586 return false;
2587 }
2588 case ltACCENT_DOT:
2589 {
2590 if (start)
2591 {
2592 wxChar *val = GetArgData();
2593 if (val)
2594 {
2595 switch (val[0])
2596 {
2597 case 'a':
2598 TexOutput(_T("&aring;"));
2599 break;
2600 case 'A':
2601 TexOutput(_T("&Aring;"));
2602 break;
2603 default:
2604 break;
2605 }
2606 }
2607 }
2608 return false;
2609 }
2610 case ltBACKGROUND:
2611 {
2612 if (start)
2613 {
2614 wxChar *val = GetArgData();
2615 if (val)
2616 {
2617 bool isPicture = false;
2618 ParseColourString(val, &isPicture);
2619 if (isPicture)
2620 {
2621 if (backgroundImageString)
2622 delete[] backgroundImageString;
2623 backgroundImageString = copystring(val);
2624 }
2625 else
2626 {
2627 if (backgroundColourString)
2628 delete[] backgroundColourString;
2629 backgroundColourString = copystring(val);
2630 }
2631 }
2632 }
2633 return false;
2634 }
2635 case ltBACKGROUNDIMAGE:
2636 {
2637 if (start)
2638 {
2639 wxChar *val = GetArgData();
2640 if (val)
2641 {
2642 if (backgroundImageString)
2643 delete[] backgroundImageString;
2644 backgroundImageString = copystring(val);
2645 }
2646 }
2647 return false;
2648 }
2649 case ltBACKGROUNDCOLOUR:
2650 {
2651 if (start)
2652 {
2653 wxChar *val = GetArgData();
2654 if (val)
2655 {
2656 if (backgroundColourString)
2657 delete[] backgroundColourString;
2658 backgroundColourString = copystring(val);
2659 }
2660 }
2661 return false;
2662 }
2663 case ltTEXTCOLOUR:
2664 {
2665 if (start)
2666 {
2667 wxChar *val = GetArgData();
2668 if (val)
2669 {
2670 if (textColourString)
2671 delete[] textColourString;
2672 textColourString = copystring(val);
2673 }
2674 }
2675 return false;
2676 }
2677 case ltLINKCOLOUR:
2678 {
2679 if (start)
2680 {
2681 wxChar *val = GetArgData();
2682 if (val)
2683 {
2684 if (linkColourString)
2685 delete[] linkColourString;
2686 linkColourString = copystring(val);
2687 }
2688 }
2689 return false;
2690 }
2691 case ltFOLLOWEDLINKCOLOUR:
2692 {
2693 if (start)
2694 {
2695 wxChar *val = GetArgData();
2696 if (val)
2697 {
2698 if (followedLinkColourString)
2699 delete[] followedLinkColourString;
2700 followedLinkColourString = copystring(val);
2701 }
2702 }
2703 return false;
2704 }
2705 case ltACCENT_CADILLA:
2706 {
2707 if (start)
2708 {
2709 wxChar *val = GetArgData();
2710 if (val)
2711 {
2712 switch (val[0])
2713 {
2714 case 'c':
2715 TexOutput(_T("&ccedil;"));
2716 break;
2717 case 'C':
2718 TexOutput(_T("&Ccedil;"));
2719 break;
2720 default:
2721 break;
2722 }
2723 }
2724 }
2725 return false;
2726 }
2727 /*
2728 case ltFOOTNOTE:
2729 case ltFOOTNOTEPOPUP:
2730 {
2731 if (arg_no == 1)
2732 return true;
2733 else
2734 return false;
2735 break;
2736 }
2737 */
2738 case ltTABULAR:
2739 case ltSUPERTABULAR:
2740 {
2741 if (arg_no == 1)
2742 {
2743 if (start)
2744 {
2745 currentRowNumber = 0;
2746 inTabular = true;
2747 startRows = true;
2748 tableVerticalLineLeft = false;
2749 tableVerticalLineRight = false;
2750
2751 wxChar *alignString = copystring(GetArgData());
2752 ParseTableArgument(alignString);
2753
2754 TexOutput(_T("<TABLE BORDER>\n"));
2755
2756 // Write the first row formatting for compatibility
2757 // with standard Latex
2758 if (compatibilityMode)
2759 {
2760 TexOutput(_T("<TR>\n<TD>"));
2761 OutputFont();
2762 /*
2763 for (int i = 0; i < noColumns; i++)
2764 {
2765 currentWidth += TableData[i].width;
2766 wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth);
2767 TexOutput(buf);
2768 }
2769 TexOutput(_T("\\pard\\intbl\n"));
2770 */
2771 }
2772 delete[] alignString;
2773
2774 return false;
2775 }
2776 }
2777 else if (arg_no == 2 && !start)
2778 {
2779 TexOutput(_T("</TABLE>\n"));
2780 inTabular = false;
2781 }
2782 break;
2783 }
2784 case ltTHEBIBLIOGRAPHY:
2785 {
2786 if (start && (arg_no == 1))
2787 {
2788 ReopenFile(&Chapters, &ChaptersName, _T("bibliography"));
2789 AddTexRef(_T("bibliography"), ChaptersName, _T("bibliography"));
2790 SetCurrentSubsectionName(_T("bibliography"), ChaptersName);
2791
2792 citeCount = 1;
2793
2794 SetCurrentOutput(Chapters);
2795
2796 wxChar titleBuf[150];
2797 if (truncateFilenames)
2798 wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s.htm"), wxFileNameFromPath(FileRoot));
2799 else
2800 wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s_contents.html"), wxFileNameFromPath(FileRoot));
2801
2802 HTMLHead();
2803 TexOutput(_T("<title>"));
2804 TexOutput(ReferencesNameString);
2805 TexOutput(_T("</title></head>\n"));
2806 OutputBodyStart();
2807
2808 wxFprintf(Chapters, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString);
2809 AddBrowseButtons(_T("contents"), titleBuf, // Up
2810 lastTopic, lastFileName, // Last topic
2811 _T("bibliography"), ChaptersName); // This topic
2812
2813 SetCurrentOutputs(Contents, Chapters);
2814 if(PrimaryAnchorOfTheFile(ChaptersName, _T("bibliography")))
2815 wxFprintf(Contents, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName));
2816 else
2817 wxFprintf(Contents, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName), _T("bibliography"));
2818
2819 wxFprintf(Contents, _T("%s</A>\n"), ReferencesNameString);
2820 wxFprintf(Chapters, _T("</H2>\n</A>\n"));
2821
2822 SetCurrentOutput(Chapters);
2823 return false;
2824 }
2825 if (!start && (arg_no == 2))
2826 {
2827 }
2828 return true;
2829 }
2830 case ltINDEX:
2831 {
2832 /* Build up list of keywords associated with topics */
2833 if (start)
2834 {
2835 // wxChar *entry = GetArgData();
2836 wxChar buf[300];
2837 OutputChunkToString(GetArgChunk(), buf);
2838 if (CurrentTopic)
2839 {
2840 AddKeyWordForTopic(CurrentTopic, buf, currentFileName);
2841 }
2842 }
2843 return false;
2844 }
2845 case ltFCOL:
2846 // case ltBCOL:
2847 {
2848 if (start)
2849 {
2850 switch (arg_no)
2851 {
2852 case 1:
2853 {
2854 wxChar *name = GetArgData();
2855 wxChar buf2[10];
2856 if (!FindColourHTMLString(name, buf2))
2857 {
2858 wxStrcpy(buf2, _T("#000000"));
2859 wxChar buf[100];
2860 wxSnprintf(buf, sizeof(buf), _T("Could not find colour name %s"), name);
2861 OnError(buf);
2862 }
2863 TexOutput(_T("<FONT COLOR=\""));
2864 TexOutput(buf2);
2865 TexOutput(_T("\">"));
2866 break;
2867 }
2868 case 2:
2869 {
2870 return true;
2871 }
2872 default:
2873 break;
2874 }
2875 }
2876 else
2877 {
2878 if (arg_no == 2) TexOutput(_T("</FONT>"));
2879 }
2880 return false;
2881 }
2882 case ltINSERTATLEVEL:
2883 {
2884 // This macro allows you to insert text at a different level
2885 // from the current level, e.g. into the Sections from within a subsubsection.
2886 if (useWord)
2887 return false;
2888 static int currentLevelNo = 1;
2889 static FILE* oldLevelFile = Chapters;
2890 if (start)
2891 {
2892 switch (arg_no)
2893 {
2894 case 1:
2895 {
2896 oldLevelFile = CurrentOutput1;
2897
2898 wxChar *str = GetArgData();
2899 currentLevelNo = wxAtoi(str);
2900 FILE* outputFile;
2901 // TODO: cope with article style (no chapters)
2902 switch (currentLevelNo)
2903 {
2904 case 1:
2905 {
2906 outputFile = Chapters;
2907 break;
2908 }
2909 case 2:
2910 {
2911 outputFile = Sections;
2912 break;
2913 }
2914 case 3:
2915 {
2916 outputFile = Subsections;
2917 break;
2918 }
2919 case 4:
2920 {
2921 outputFile = Subsubsections;
2922 break;
2923 }
2924 default:
2925 {
2926 outputFile = NULL;
2927 break;
2928 }
2929 }
2930 if (outputFile)
2931 CurrentOutput1 = outputFile;
2932 return false;
2933 }
2934 case 2:
2935 {
2936 return true;
2937 }
2938 default:
2939 break;
2940 }
2941 return true;
2942 }
2943 else
2944 {
2945 if (arg_no == 2)
2946 {
2947 CurrentOutput1 = oldLevelFile;
2948 }
2949 return true;
2950 }
2951 }
2952 default:
2953 return DefaultOnArgument(macroId, arg_no, start);
2954 }
2955 return true;
2956 }
2957
2958 bool HTMLGo(void)
2959 {
2960 fileId = 0;
2961 inVerbatim = false;
2962 indentLevel = 0;
2963 inTabular = false;
2964 startRows = false;
2965 tableVerticalLineLeft = false;
2966 tableVerticalLineRight = false;
2967 noColumns = 0;
2968
2969 if (InputFile && OutputFile)
2970 {
2971 // Do some HTML-specific transformations on all the strings,
2972 // recursively
2973 Text2HTML(GetTopLevelChunk());
2974
2975 wxChar buf[300];
2976 if (truncateFilenames)
2977 wxSnprintf(buf, sizeof(buf), _T("%s.htm"), FileRoot);
2978 else
2979 wxSnprintf(buf, sizeof(buf), _T("%s_contents.html"), FileRoot);
2980 if (TitlepageName) delete[] TitlepageName;
2981 TitlepageName = copystring(buf);
2982 Titlepage = wxFopen(buf, _T("w"));
2983
2984 if (truncateFilenames)
2985 wxSnprintf(buf, sizeof(buf), _T("%s_fc.htm"), FileRoot);
2986 else
2987 wxSnprintf(buf, sizeof(buf), _T("%s_fcontents.html"), FileRoot);
2988
2989 contentsFrameName = copystring(buf);
2990
2991 Contents = wxFopen(TmpContentsName, _T("w"));
2992
2993 if (htmlFrameContents)
2994 {
2995 // FrameContents = wxFopen(TmpFrameContentsName, _T("w"));
2996 FrameContents = wxFopen(contentsFrameName, _T("w"));
2997 wxFprintf(FrameContents, _T("<HTML>\n<UL>\n"));
2998 }
2999
3000 if (!Titlepage || !Contents)
3001 {
3002 OnError(_T("Cannot open output file!"));
3003 return false;
3004 }
3005 AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName), ContentsNameString);
3006
3007 wxFprintf(Contents, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString);
3008
3009 wxFprintf(Contents, _T("<UL>\n"));
3010
3011 SetCurrentOutput(Titlepage);
3012 if (htmlWorkshopFiles) HTMLWorkshopStartContents();
3013 OnInform(_T("Converting..."));
3014
3015 TraverseDocument();
3016 wxFprintf(Contents, _T("</UL>\n\n"));
3017
3018 // SetCurrentOutput(Titlepage);
3019 fclose(Titlepage);
3020
3021 if (Contents)
3022 {
3023 // wxFprintf(Titlepage, _T("\n</BODY></HTML>\n"));
3024 fclose(Contents);
3025 Contents = NULL;
3026 }
3027
3028 if (FrameContents)
3029 {
3030 wxFprintf(FrameContents, _T("\n</UL>\n"));
3031 wxFprintf(FrameContents, _T("</HTML>\n"));
3032 fclose(FrameContents);
3033 FrameContents = NULL;
3034 }
3035
3036 if (Chapters)
3037 {
3038 wxFprintf(Chapters, _T("\n</FONT></BODY></HTML>\n"));
3039 fclose(Chapters);
3040 Chapters = NULL;
3041 }
3042 if (Sections)
3043 {
3044 wxFprintf(Sections, _T("\n</FONT></BODY></HTML>\n"));
3045 fclose(Sections);
3046 Sections = NULL;
3047 }
3048 if (Subsections && !combineSubSections)
3049 {
3050 wxFprintf(Subsections, _T("\n</FONT></BODY></HTML>\n"));
3051 fclose(Subsections);
3052 Subsections = NULL;
3053 }
3054 if (Subsubsections && !combineSubSections)
3055 {
3056 wxFprintf(Subsubsections, _T("\n</FONT></BODY></HTML>\n"));
3057 fclose(Subsubsections);
3058 Subsubsections = NULL;
3059 }
3060 if ( SectionContentsFD )
3061 {
3062 fclose(SectionContentsFD);
3063 SectionContentsFD = NULL;
3064 }
3065
3066 // Create a temporary file for the title page header, add some info,
3067 // and concat the titlepage just generated.
3068 // This is necessary in order to put the title of the document
3069 // at the TOP of the file within <HEAD>, even though we only find out
3070 // what it is later on.
3071 FILE *tmpTitle = wxFopen(_T("title.tmp"), _T("w"));
3072 if (tmpTitle)
3073 {
3074 if (DocumentTitle)
3075 {
3076 SetCurrentOutput(tmpTitle);
3077 HTMLHead();
3078 TexOutput(_T("\n<TITLE>"));
3079 TraverseChildrenFromChunk(DocumentTitle);
3080 TexOutput(_T("</TITLE></HEAD>\n"));
3081 }
3082 else
3083 {
3084 SetCurrentOutput(tmpTitle);
3085 HTMLHeadTo(tmpTitle);
3086 if (contentsString)
3087 wxFprintf(tmpTitle, _T("<TITLE>%s</TITLE></HEAD>\n\n"), contentsString);
3088 else
3089 wxFprintf(tmpTitle, _T("<TITLE>%s</TITLE></HEAD>\n\n"), wxFileNameFromPath(FileRoot));
3090 }
3091
3092 // Output frame information
3093 if (htmlFrameContents)
3094 {
3095 wxChar firstFileName[300];
3096 if (truncateFilenames)
3097 wxSnprintf(firstFileName, sizeof(firstFileName), _T("%s1.htm"), FileRoot);
3098 else
3099 wxStrcpy(firstFileName, gs_filenames[1].c_str());
3100
3101 wxFprintf(tmpTitle, _T("<FRAMESET COLS=\"30%%,70%%\">\n"));
3102
3103 wxFprintf(tmpTitle, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName)));
3104 wxFprintf(tmpTitle, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName)));
3105 wxFprintf(tmpTitle, _T("</FRAMESET>\n"));
3106
3107 wxFprintf(tmpTitle, _T("<NOFRAMES>\n"));
3108 }
3109
3110 // Output <BODY...> to temporary title page
3111 OutputBodyStart();
3112 fflush(tmpTitle);
3113
3114 // Concat titlepage
3115 FILE *fd = wxFopen(TitlepageName, _T("r"));
3116 if (fd)
3117 {
3118 int ch = getc(fd);
3119 while (ch != EOF)
3120 {
3121 wxPutc(ch, tmpTitle);
3122 ch = getc(fd);
3123 }
3124 fclose(fd);
3125 }
3126
3127 wxFprintf(tmpTitle, _T("\n</FONT></BODY>\n"));
3128
3129 if (htmlFrameContents)
3130 {
3131 wxFprintf(tmpTitle, _T("\n</NOFRAMES>\n"));
3132 }
3133 wxFprintf(tmpTitle, _T("\n</HTML>\n"));
3134
3135 fclose(tmpTitle);
3136 if (wxFileExists(TitlepageName)) wxRemoveFile(TitlepageName);
3137 if (!wxRenameFile(_T("title.tmp"), TitlepageName))
3138 {
3139 wxCopyFile(_T("title.tmp"), TitlepageName);
3140 wxRemoveFile(_T("title.tmp"));
3141 }
3142 }
3143
3144 if (lastFileName) delete[] lastFileName;
3145 lastFileName = NULL;
3146 if (lastTopic) delete[] lastTopic;
3147 lastTopic = NULL;
3148
3149 if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName);
3150
3151 if (!wxRenameFile(TmpContentsName, ContentsName))
3152 {
3153 wxCopyFile(TmpContentsName, ContentsName);
3154 wxRemoveFile(TmpContentsName);
3155 }
3156
3157 // Generate .htx file if requested
3158 if (htmlIndex)
3159 {
3160 wxChar htmlIndexName[300];
3161 wxSnprintf(htmlIndexName, sizeof(htmlIndexName), _T("%s.htx"), FileRoot);
3162 GenerateHTMLIndexFile(htmlIndexName);
3163 }
3164
3165 // Generate HTML Help Workshop files if requested
3166 if (htmlWorkshopFiles)
3167 {
3168 HTMLWorkshopEndContents();
3169 GenerateHTMLWorkshopFiles(FileRoot);
3170 }
3171
3172
3173 return true;
3174 }
3175
3176 return false;
3177 }
3178
3179 // Output .htx index file
3180 void GenerateHTMLIndexFile(wxChar *fname)
3181 {
3182 FILE *fd = wxFopen(fname, _T("w"));
3183 if (!fd)
3184 return;
3185
3186 TopicTable.BeginFind();
3187 wxHashTable::Node *node = TopicTable.Next();
3188 while (node)
3189 {
3190 TexTopic *texTopic = (TexTopic *)node->GetData();
3191 const wxChar *topicName = node->GetKeyString();
3192 if (texTopic->filename && texTopic->keywords)
3193 {
3194 wxStringListNode *node1 = texTopic->keywords->GetFirst();
3195 while (node1)
3196 {
3197 wxChar *s = (wxChar *)node1->GetData();
3198 wxFprintf(fd, _T("%s|%s|%s\n"), topicName, texTopic->filename, s);
3199 node1 = node1->GetNext();
3200 }
3201 }
3202 node = TopicTable.Next();
3203 }
3204 fclose(fd);
3205 }
3206
3207
3208
3209
3210
3211
3212
3213 // output .hpp, .hhc and .hhk files:
3214
3215
3216 void GenerateHTMLWorkshopFiles(wxChar *fname)
3217 {
3218 FILE *f;
3219 wxChar buf[300];
3220
3221 /* Generate project file : */
3222
3223 wxSnprintf(buf, sizeof(buf), _T("%s.hhp"), fname);
3224 f = wxFopen(buf, _T("wt"));
3225 wxFprintf(f,
3226 _T("[OPTIONS]\n")
3227 _T("Compatibility=1.1\n")
3228 _T("Full-text search=Yes\n")
3229 _T("Contents file=%s.hhc\n")
3230 _T("Compiled file=%s.chm\n")
3231 _T("Default Window=%sHelp\n")
3232 _T("Default topic=%s\n")
3233 _T("Index file=%s.hhk\n")
3234 _T("Title="),
3235 wxFileNameFromPath(fname),
3236 wxFileNameFromPath(fname),
3237 wxFileNameFromPath(fname),
3238 wxFileNameFromPath(TitlepageName),
3239 wxFileNameFromPath(fname)
3240 );
3241
3242 if (DocumentTitle) {
3243 SetCurrentOutput(f);
3244 TraverseChildrenFromChunk(DocumentTitle);
3245 }
3246 else wxFprintf(f, _T("(unknown)"));
3247
3248 wxFprintf(f, _T("\n\n[WINDOWS]\n")
3249 _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"),
3250 wxFileNameFromPath(fname),
3251 wxFileNameFromPath(fname),
3252 wxFileNameFromPath(fname),
3253 wxFileNameFromPath(TitlepageName));
3254
3255
3256 wxFprintf(f, _T("\n\n[FILES]\n"));
3257 wxFprintf(f, _T("%s\n"), wxFileNameFromPath(TitlepageName));
3258 for (int i = 1; i <= fileId; i++) {
3259 if (truncateFilenames)
3260 wxSnprintf(buf, sizeof(buf), _T("%s%d.htm"), wxFileNameFromPath(FileRoot), i);
3261 else
3262 wxStrcpy(buf, wxFileNameFromPath(gs_filenames[i].c_str()));
3263 wxFprintf(f, _T("%s\n"), buf);
3264 }
3265 fclose(f);
3266
3267 /* Generate index file : */
3268
3269 wxSnprintf(buf, sizeof(buf), _T("%s.hhk"), fname);
3270 f = wxFopen(buf, _T("wt"));
3271
3272 wxFprintf(f,
3273 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3274 _T("<HTML>\n"));
3275 HTMLHeadTo(f);
3276 wxFprintf(f,
3277 _T("\n")
3278 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3279 _T("<!-- Sitemap 1.0 -->\n")
3280 _T("</HEAD><BODY>\n")
3281 _T("<OBJECT type=\"text/site properties\">\n")
3282 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3283 _T("</OBJECT>\n")
3284 _T("<UL>\n"));
3285
3286 TopicTable.BeginFind();
3287 wxHashTable::Node *node = TopicTable.Next();
3288 while (node)
3289 {
3290 TexTopic *texTopic = (TexTopic *)node->GetData();
3291 const wxChar *topicName = node->GetKeyString();
3292 if (texTopic->filename && texTopic->keywords)
3293 {
3294 wxStringListNode *node1 = texTopic->keywords->GetFirst();
3295 while (node1)
3296 {
3297 wxChar *s = (wxChar *)node1->GetData();
3298 wxFprintf(f,
3299 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3300 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3301 _T(" <param name=\"Name\" value=\"%s\">\n")
3302 _T(" </OBJECT>\n"),
3303 texTopic->filename, topicName, s);
3304 node1 = node1->GetNext();
3305 }
3306 }
3307 node = TopicTable.Next();
3308 }
3309
3310 wxFprintf(f, _T("</UL>\n"));
3311 fclose(f);
3312 }
3313
3314
3315
3316 static FILE *HTMLWorkshopContents = NULL;
3317 static int HTMLWorkshopLastLevel = 0;
3318
3319 void HTMLWorkshopAddToContents(int level, wxChar *s, wxChar *file)
3320 {
3321 int i;
3322
3323 if (level > HTMLWorkshopLastLevel)
3324 for (i = HTMLWorkshopLastLevel; i < level; i++)
3325 wxFprintf(HTMLWorkshopContents, _T("<UL>"));
3326 if (level < HTMLWorkshopLastLevel)
3327 for (i = level; i < HTMLWorkshopLastLevel; i++)
3328 wxFprintf(HTMLWorkshopContents, _T("</UL>"));
3329
3330 SetCurrentOutput(HTMLWorkshopContents);
3331 wxFprintf(HTMLWorkshopContents,
3332 _T(" <LI> <OBJECT type=\"text/sitemap\">\n")
3333 _T(" <param name=\"Local\" value=\"%s#%s\">\n")
3334 _T(" <param name=\"Name\" value=\""),
3335 file, s);
3336 OutputCurrentSection();
3337 wxFprintf(HTMLWorkshopContents,
3338 _T("\">\n")
3339 _T(" </OBJECT>\n"));
3340 HTMLWorkshopLastLevel = level;
3341 }
3342
3343
3344 void HTMLWorkshopStartContents()
3345 {
3346 wxChar buf[300];
3347 wxSnprintf(buf, sizeof(buf), _T("%s.hhc"), FileRoot);
3348 HTMLWorkshopContents = wxFopen(buf, _T("wt"));
3349 HTMLWorkshopLastLevel = 0;
3350
3351 wxFprintf(HTMLWorkshopContents,
3352 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3353 _T("<HTML>\n"));
3354 HTMLHeadTo(HTMLWorkshopContents);
3355 wxFprintf(HTMLWorkshopContents,
3356 _T("\n")
3357 _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n")
3358 _T("<!-- Sitemap 1.0 -->\n")
3359 _T("</HEAD><BODY>\n")
3360 _T("<OBJECT type=\"text/site properties\">\n")
3361 _T(" <param name=\"ImageType\" value=\"Folder\">\n")
3362 _T("</OBJECT>\n")
3363 _T("<UL>\n")
3364 _T("<LI> <OBJECT type=\"text/sitemap\">\n")
3365 _T("<param name=\"Local\" value=\"%s\">\n")
3366 _T("<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n"),
3367 wxFileNameFromPath(TitlepageName)
3368 );
3369
3370 }
3371
3372
3373 void HTMLWorkshopEndContents()
3374 {
3375 for (int i = HTMLWorkshopLastLevel; i >= 0; i--)
3376 wxFprintf(HTMLWorkshopContents, _T("</UL>\n"));
3377 fclose(HTMLWorkshopContents);
3378 }
3379
3380
3381 bool PrimaryAnchorOfTheFile( wxChar *file, wxChar *label )
3382 {
3383 wxString file_label;
3384 file_label.Printf( HTML_FILENAME_PATTERN, FileRoot, label );
3385 return file_label.IsSameAs( file , false );
3386 }