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