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