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