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