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