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