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