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