]> git.saurik.com Git - wxWidgets.git/blob - utils/tex2rtf/src/xlputils.cpp
documented wxFontMapper
[wxWidgets.git] / utils / tex2rtf / src / xlputils.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xlputils.cpp
3 // Purpose: Converts Latex to obsolete XLP format
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 <ctype.h>
30
31 long currentBlockId = -1;
32 static TexChunk *descriptionItemArg = NULL;
33 static int indentLevel = 0;
34 static int noColumns = 0;
35 static int currentTab = 0;
36 static bool tableVerticalLineLeft = FALSE;
37 static bool tableVerticalLineRight = FALSE;
38 static bool inTable = FALSE;
39 static int citeCount = 1;
40 wxList hyperLinks(wxKEY_INTEGER);
41 wxList hyperLabels(wxKEY_STRING);
42 FILE *Index = NULL;
43
44 void PadToTab(int tabPos)
45 {
46 int currentCol = GetCurrentColumn();
47 for (int i = currentCol; i < tabPos; i++)
48 TexOutput(" ", TRUE);
49 }
50
51 static long xlpBlockId = 0;
52 long NewBlockId(void)
53 {
54 return xlpBlockId ++;
55 }
56
57 // Called on start/end of macro examination
58 void XLPOnMacro(int macroId, int no_args, bool start)
59 {
60 char buf[100];
61 switch (macroId)
62 {
63 case ltCHAPTER:
64 case ltCHAPTERSTAR:
65 case ltCHAPTERHEADING:
66 {
67 if (!start)
68 {
69 sectionNo = 0;
70 figureNo = 0;
71 subsectionNo = 0;
72 subsubsectionNo = 0;
73 if (macroId != ltCHAPTERSTAR)
74 chapterNo ++;
75
76 SetCurrentOutputs(Contents, Chapters);
77 long id1 = NewBlockId();
78 currentBlockId = NewBlockId();
79
80 startedSections = TRUE;
81 fprintf(Contents, "\\hy-%d{%ld}{", hyBLOCK_SMALL_HEADING, id1);
82 fprintf(Chapters, "\n\\hy-%d{%ld}{", hyBLOCK_LARGE_VISIBLE_SECTION, currentBlockId);
83 fprintf(Index, "%ld %ld\n", id1, currentBlockId);
84
85 OutputCurrentSection(); // Repeat section header
86
87 fprintf(Contents, "}\n\n");
88 fprintf(Chapters, "}\n\n");
89 SetCurrentOutput(Chapters);
90 char *topicName = FindTopicName(GetNextChunk());
91 hyperLabels.Append(topicName, (wxObject *)currentBlockId);
92 }
93 break;
94 }
95 case ltSECTION:
96 case ltSECTIONSTAR:
97 case ltSECTIONHEADING:
98 case ltGLOSS:
99 {
100 if (!start)
101 {
102 subsectionNo = 0;
103 subsubsectionNo = 0;
104
105 if (macroId != ltSECTIONSTAR)
106 sectionNo ++;
107
108 SetCurrentOutputs(Chapters, Sections);
109 long id1 = NewBlockId();
110 currentBlockId = NewBlockId();
111
112 startedSections = TRUE;
113
114 if (DocumentStyle == LATEX_ARTICLE)
115 fprintf(Contents, "\\hy-%d{%ld}{", hyBLOCK_LARGE_HEADING, id1);
116 else
117 fprintf(Chapters, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id1);
118 fprintf(Sections, "\n\\hy-%d{%ld}{", hyBLOCK_LARGE_VISIBLE_SECTION, currentBlockId);
119 fprintf(Index, "%ld %ld\n", id1, currentBlockId);
120
121 OutputCurrentSection(); // Repeat section header
122
123 if (DocumentStyle == LATEX_ARTICLE)
124 fprintf(Contents, "}\n\n");
125 else
126 fprintf(Chapters, "}\n\n");
127 fprintf(Sections, "}\n\n");
128 SetCurrentOutput(Sections);
129 char *topicName = FindTopicName(GetNextChunk());
130 hyperLabels.Append(topicName, (wxObject *)currentBlockId);
131 }
132 break;
133 }
134 case ltSUBSECTION:
135 case ltSUBSECTIONSTAR:
136 case ltMEMBERSECTION:
137 case ltFUNCTIONSECTION:
138 {
139 if (!start)
140 {
141 subsubsectionNo = 0;
142
143 if (macroId != ltSUBSECTIONSTAR)
144 subsectionNo ++;
145
146 SetCurrentOutputs(Sections, Subsections);
147 long id1 = NewBlockId();
148 currentBlockId = NewBlockId();
149 fprintf(Sections, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id1);
150 fprintf(Subsections, "\n\\hy-%d{%ld}{", hyBLOCK_LARGE_VISIBLE_SECTION, currentBlockId);
151 fprintf(Index, "%ld %ld\n", id1, currentBlockId);
152
153 OutputCurrentSection(); // Repeat section header
154
155 fprintf(Sections, "}\n\n");
156 fprintf(Subsections, "}\n\n");
157 SetCurrentOutput(Subsections);
158 char *topicName = FindTopicName(GetNextChunk());
159 hyperLabels.Append(topicName, (wxObject *)currentBlockId);
160 }
161 break;
162 }
163 case ltSUBSUBSECTION:
164 case ltSUBSUBSECTIONSTAR:
165 {
166 if (!start)
167 {
168 if (macroId != ltSUBSUBSECTIONSTAR)
169 subsubsectionNo ++;
170
171 SetCurrentOutputs(Subsections, Subsubsections);
172 long id1 = NewBlockId();
173 currentBlockId = NewBlockId();
174 fprintf(Subsections, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id1);
175 fprintf(Subsubsections, "\n\\hy-%d{%ld}{", hyBLOCK_LARGE_VISIBLE_SECTION, currentBlockId);
176 fprintf(Index, "%ld %ld\n", id1, currentBlockId);
177
178 OutputCurrentSection(); // Repeat section header
179
180 fprintf(Subsections, "}\n\n");
181 fprintf(Subsubsections, "}\n\n");
182 SetCurrentOutput(Subsubsections);
183 char *topicName = FindTopicName(GetNextChunk());
184 hyperLabels.Append(topicName, (wxObject *)currentBlockId);
185 }
186 break;
187 }
188 case ltFUNC:
189 case ltPFUNC:
190 case ltMEMBER:
191 {
192 SetCurrentOutput(Subsections);
193 if (start)
194 {
195 long id = NewBlockId();
196 fprintf(Subsections, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id);
197 }
198 else
199 fprintf(Subsections, "}");
200 break;
201 }
202 case ltVOID:
203 // if (start)
204 // TexOutput("void", TRUE);
205 break;
206 case ltBACKSLASHCHAR:
207 if (start)
208 TexOutput("\n", TRUE);
209 break;
210 case ltPAR:
211 {
212 if (start)
213 {
214 if (ParSkip > 0)
215 TexOutput("\n", TRUE);
216 TexOutput("\n", TRUE);
217 }
218 break;
219 }
220 case ltRMFAMILY:
221 case ltTEXTRM:
222 case ltRM:
223 {
224 break;
225 }
226 case ltTEXTBF:
227 case ltBFSERIES:
228 case ltBF:
229 {
230 if (start)
231 {
232 char buf[100];
233 long id = NewBlockId();
234 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id);
235 TexOutput(buf);
236 }
237 else TexOutput("}");
238 break;
239 }
240 case ltTEXTIT:
241 case ltITSHAPE:
242 case ltIT:
243 {
244 if (start)
245 {
246 char buf[100];
247 long id = NewBlockId();
248 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_ITALIC, id);
249 TexOutput(buf);
250 }
251 else TexOutput("}");
252 break;
253 }
254 case ltTTFAMILY:
255 case ltTEXTTT:
256 case ltTT:
257 {
258 if (start)
259 {
260 long id = NewBlockId();
261 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_TELETYPE, id);
262 TexOutput(buf);
263 }
264 else TexOutput("}");
265 break;
266 }
267 case ltSMALL:
268 {
269 if (start)
270 {
271 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_SMALL_TEXT, NewBlockId());
272 TexOutput(buf);
273 }
274 else TexOutput("}");
275 break;
276 }
277 case ltTINY:
278 {
279 if (start)
280 {
281 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_SMALL_TEXT, NewBlockId());
282 TexOutput(buf);
283 }
284 else TexOutput("}");
285 break;
286 }
287 case ltNORMALSIZE:
288 {
289 if (start)
290 {
291 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_NORMAL, NewBlockId());
292 TexOutput(buf);
293 }
294 else TexOutput("}");
295 break;
296 }
297 case ltlarge:
298 {
299 if (start)
300 {
301 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_SMALL_HEADING, NewBlockId());
302 TexOutput(buf);
303 }
304 else TexOutput("}\n");
305 break;
306 }
307 case ltLARGE:
308 {
309 if (start)
310 {
311 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_LARGE_HEADING, NewBlockId());
312 TexOutput(buf);
313 }
314 else TexOutput("}\n");
315 break;
316 }
317 case ltITEMIZE:
318 case ltENUMERATE:
319 case ltDESCRIPTION:
320 case ltTWOCOLLIST:
321 {
322 if (start)
323 {
324 // tabCount ++;
325
326 // if (indentLevel > 0)
327 // TexOutput("\\par\\par\n");
328 indentLevel ++;
329 int listType;
330 if (macroId == ltENUMERATE)
331 listType = LATEX_ENUMERATE;
332 else if (macroId == ltITEMIZE)
333 listType = LATEX_ITEMIZE;
334 else
335 listType = LATEX_DESCRIPTION;
336 itemizeStack.Insert(new ItemizeStruc(listType));
337
338 }
339 else
340 {
341 indentLevel --;
342
343 if (itemizeStack.First())
344 {
345 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data();
346 delete struc;
347 delete itemizeStack.First();
348 }
349 }
350 break;
351 }
352 case ltITEM:
353 {
354 wxNode *node = itemizeStack.First();
355 if (node)
356 {
357 ItemizeStruc *struc = (ItemizeStruc *)node->Data();
358 if (!start)
359 {
360 struc->currentItem += 1;
361 char indentBuf[30];
362
363 switch (struc->listType)
364 {
365 case LATEX_ENUMERATE:
366 {
367 sprintf(indentBuf, "\\hy-%d{%ld}{%d.} ",
368 hyBLOCK_BOLD, NewBlockId(), struc->currentItem);
369 TexOutput(indentBuf);
370 break;
371 }
372 case LATEX_ITEMIZE:
373 {
374 sprintf(indentBuf, "\\hy-%d{%ld}{o} ",
375 hyBLOCK_BOLD, NewBlockId());
376 TexOutput(indentBuf);
377 break;
378 }
379 default:
380 case LATEX_DESCRIPTION:
381 {
382 if (descriptionItemArg)
383 {
384 sprintf(indentBuf, "\\hy-%d{%ld}{",
385 hyBLOCK_BOLD, NewBlockId());
386 TexOutput(indentBuf);
387 TraverseChildrenFromChunk(descriptionItemArg);
388 TexOutput("} ");
389 descriptionItemArg = NULL;
390 }
391 break;
392 }
393 }
394 }
395 }
396 break;
397 }
398 case ltMAKETITLE:
399 {
400 if (start && DocumentTitle && DocumentAuthor)
401 {
402 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_LARGE_HEADING, NewBlockId());
403 TexOutput(buf);
404 TraverseChildrenFromChunk(DocumentTitle);
405 TexOutput("}\n\n");
406 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_SMALL_HEADING, NewBlockId());
407 TexOutput(buf);
408 TraverseChildrenFromChunk(DocumentAuthor);
409 TexOutput("}\n\n");
410 if (DocumentDate)
411 {
412 TraverseChildrenFromChunk(DocumentDate);
413 TexOutput("\n");
414 }
415 }
416 break;
417 }
418 case ltTABLEOFCONTENTS:
419 {
420 if (start)
421 {
422 FILE *fd = fopen(ContentsName, "r");
423 if (fd)
424 {
425 int ch = getc(fd);
426 while (ch != EOF)
427 {
428 putc(ch, Chapters);
429 ch = getc(fd);
430 }
431 fclose(fd);
432 }
433 else
434 {
435 TexOutput("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n");
436 OnInform("Run Tex2RTF again to include contents page.");
437 }
438 }
439 break;
440 }
441 case ltHARDY:
442 {
443 if (start)
444 TexOutput("HARDY", TRUE);
445 break;
446 }
447 case ltWXCLIPS:
448 {
449 if (start)
450 TexOutput("wxCLIPS", TRUE);
451 break;
452 }
453 case ltVERBATIM:
454 {
455 if (start)
456 {
457 char buf[100];
458 long id = NewBlockId();
459 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_TELETYPE, id);
460 TexOutput(buf);
461 }
462 else TexOutput("}");
463 break;
464 }
465 case ltHRULE:
466 {
467 if (start)
468 {
469 TexOutput("\n------------------------------------------------------------------", TRUE);
470 }
471 break;
472 }
473 case ltHLINE:
474 {
475 if (start)
476 {
477 TexOutput("--------------------------------------------------------------------------------", TRUE);
478 }
479 break;
480 }
481 case ltSPECIALAMPERSAND:
482 {
483 if (start)
484 {
485 currentTab ++;
486 int tabPos = (80/noColumns)*currentTab;
487 PadToTab(tabPos);
488 }
489 break;
490 }
491 case ltTABULAR:
492 case ltSUPERTABULAR:
493 {
494 if (start)
495 {
496 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_TELETYPE, NewBlockId());
497 TexOutput(buf);
498 }
499 else
500 TexOutput("}");
501 break;
502 }
503 case ltNUMBEREDBIBITEM:
504 {
505 if (!start)
506 TexOutput("\n\n", TRUE);
507 break;
508 }
509 case ltCAPTION:
510 case ltCAPTIONSTAR:
511 {
512 if (start)
513 {
514 figureNo ++;
515
516 char figBuf[40];
517 if (DocumentStyle != LATEX_ARTICLE)
518 sprintf(figBuf, "Figure %d.%d: ", chapterNo, figureNo);
519 else
520 sprintf(figBuf, "Figure %d: ", figureNo);
521
522 TexOutput(figBuf);
523 }
524 else
525 {
526 char *topicName = FindTopicName(GetNextChunk());
527
528 AddTexRef(topicName, NULL, NULL,
529 ((DocumentStyle != LATEX_ARTICLE) ? chapterNo : figureNo),
530 ((DocumentStyle != LATEX_ARTICLE) ? figureNo : 0));
531 }
532 break;
533 }
534 default:
535 {
536 DefaultOnMacro(macroId, no_args, start);
537 break;
538 }
539 }
540 }
541
542 bool XLPOnArgument(int macroId, int arg_no, bool start)
543 {
544 char buf[300];
545 switch (macroId)
546 {
547 case ltCHAPTER:
548 case ltCHAPTERSTAR:
549 case ltCHAPTERHEADING:
550 case ltSECTION:
551 case ltSECTIONSTAR:
552 case ltSECTIONHEADING:
553 case ltSUBSECTION:
554 case ltSUBSECTIONSTAR:
555 case ltSUBSUBSECTION:
556 case ltSUBSUBSECTIONSTAR:
557 case ltGLOSS:
558 case ltMEMBERSECTION:
559 case ltFUNCTIONSECTION:
560 {
561 if (!start && (arg_no == 1))
562 currentSection = GetArgChunk();
563 return FALSE;
564 break;
565 }
566 case ltFUNC:
567 {
568 if (!start && (arg_no == 1))
569 TexOutput(" ", TRUE);
570 if (start && (arg_no == 3))
571 TexOutput("(", TRUE);
572 if (!start && (arg_no == 3))
573 TexOutput(")", TRUE);
574 break;
575 }
576 case ltPFUNC:
577 {
578 if (!start && (arg_no == 1))
579 TexOutput(" ", TRUE);
580
581 if (start && (arg_no == 2))
582 TexOutput("(*", TRUE);
583 if (!start && (arg_no == 2))
584 TexOutput(")", TRUE);
585
586 if (start && (arg_no == 3))
587 TexOutput("(", TRUE);
588 if (!start && (arg_no == 3))
589 TexOutput(")", TRUE);
590 break;
591 }
592 case ltCLIPSFUNC:
593 {
594 if (!start && (arg_no == 1))
595 TexOutput(" ", TRUE);
596 if (start && (arg_no == 2))
597 {
598 TexOutput("(", TRUE);
599 long id = NewBlockId();
600 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id);
601 TexOutput(buf);
602 }
603 if (!start && (arg_no == 2))
604 {
605 TexOutput("}");
606 }
607 if (!start && (arg_no == 3))
608 TexOutput(")", TRUE);
609 break;
610 }
611 case ltPARAM:
612 {
613 if (start && (arg_no == 2))
614 {
615 long id = NewBlockId();
616 sprintf(buf, " \\hy-%d{%ld}{", hyBLOCK_BOLD, id);
617 TexOutput(buf);
618 }
619 if (!start && (arg_no == 2))
620 {
621 TexOutput("}");
622 }
623 break;
624 }
625 case ltCPARAM:
626 {
627 if (start && (arg_no == 2))
628 {
629 long id = NewBlockId();
630 sprintf(buf, " \\hy-%d{%ld}{", hyBLOCK_BOLD, id);
631 TexOutput(buf);
632 }
633 if (!start && (arg_no == 2))
634 {
635 TexOutput("}");
636 }
637 break;
638 }
639 case ltMEMBER:
640 {
641 if (!start && (arg_no == 1))
642 TexOutput(" ", TRUE);
643 break;
644 }
645 case ltLABEL:
646 {
647 return FALSE;
648 break;
649 }
650 case ltREF:
651 {
652 if (start)
653 {
654 char *sec = NULL;
655
656 char *refName = GetArgData();
657 if (refName)
658 {
659 TexRef *texRef = FindReference(refName);
660 if (texRef)
661 {
662 sec = texRef->sectionNumber;
663 }
664 }
665 if (sec)
666 {
667 TexOutput(sec);
668 }
669 return FALSE;
670 }
671 break;
672 }
673 case ltHELPREF:
674 case ltHELPREFN:
675 case ltPOPREF:
676 {
677 if (arg_no == 1)
678 {
679 if (start)
680 {
681 currentBlockId = NewBlockId();
682 sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_RED_ITALIC, currentBlockId);
683 TexOutput(buf);
684 }
685 else TexOutput("}");
686 }
687 if (arg_no == 2)
688 {
689 if (start)
690 {
691 char *label = GetArgData();
692 hyperLinks.Append(currentBlockId, (wxObject *)copystring(label));
693 }
694
695 return FALSE;
696 }
697 break;
698 }
699 case ltURLREF:
700 {
701 if (arg_no == 1)
702 {
703 return TRUE;
704 }
705 else if (arg_no == 2)
706 {
707 if (start)
708 TexOutput(" (");
709 else
710 TexOutput(")");
711 return TRUE;
712 }
713 break;
714 }
715 case ltITEM:
716 {
717 if (start && IsArgOptional())
718 {
719 descriptionItemArg = GetArgChunk();
720 return FALSE;
721 }
722 break;
723 }
724 case ltTABULAR:
725 case ltSUPERTABULAR:
726 {
727 if (arg_no == 1)
728 {
729 if (start)
730 {
731 inTable = TRUE;
732 tableVerticalLineLeft = FALSE;
733 tableVerticalLineRight = FALSE;
734
735 char *alignString = copystring(GetArgData());
736
737 // Count the number of columns
738 noColumns = 0;
739 int len = strlen(alignString);
740 if (len > 0)
741 {
742 if (alignString[0] == '|')
743 tableVerticalLineLeft = TRUE;
744 if (alignString[len-1] == '|')
745 tableVerticalLineRight = TRUE;
746 }
747
748 for (int i = 0; i < len; i++)
749 if (isalpha(alignString[i]))
750 noColumns ++;
751
752 /*
753 // Experimental
754 TexOutput("\\brdrt\\brdrs");
755 if (tableVerticalLineLeft)
756 TexOutput("\\brdrl\\brdrs");
757 if (tableVerticalLineRight)
758 TexOutput("\\brdrr\\brdrs");
759 */
760
761 // Calculate a rough size for each column
762 // int tabPos = 80/noColumns;
763 currentTab = 0;
764
765 return FALSE;
766 }
767 }
768 else if (arg_no == 2 && !start)
769 {
770 inTable = FALSE;
771 }
772 else if (arg_no == 2 && start)
773 return TRUE;
774 break;
775 }
776 case ltMARGINPAR:
777 case ltMARGINPAREVEN:
778 case ltMARGINPARODD:
779 case ltNORMALBOX:
780 case ltNORMALBOXD:
781 {
782 if (start)
783 {
784 TexOutput("----------------------------------------------------------------------\n", TRUE);
785 return TRUE;
786 }
787 else
788 TexOutput("\n----------------------------------------------------------------------\n", TRUE);
789 break;
790 }
791 case ltBIBITEM:
792 {
793 char buf[100];
794 if (arg_no == 1 && start)
795 {
796 char *citeKey = GetArgData();
797 TexRef *ref = (TexRef *)TexReferences.Get(citeKey);
798 if (ref)
799 {
800 if (ref->sectionNumber) delete[] ref->sectionNumber;
801 sprintf(buf, "[%d]", citeCount);
802 ref->sectionNumber = copystring(buf);
803 }
804
805 sprintf(buf, "\\hy-%d{%ld}{[%d]} ", hyBLOCK_BOLD, NewBlockId(), citeCount);
806 TexOutput(buf);
807 citeCount ++;
808 return FALSE;
809 }
810 return TRUE;
811 break;
812 }
813 case ltTHEBIBLIOGRAPHY:
814 {
815 if (start && (arg_no == 1))
816 {
817 citeCount = 1;
818
819 SetCurrentOutput(Chapters);
820
821 SetCurrentOutputs(Contents, Chapters);
822 long id1 = NewBlockId();
823 long id2 = NewBlockId();
824 fprintf(Contents, "\\hy-%d{%ld}{%s}\n", hyBLOCK_SMALL_HEADING, id1, ReferencesNameString);
825 fprintf(Chapters, "\\hy-%d{%ld}{%s}\n\n\n", hyBLOCK_LARGE_VISIBLE_SECTION, id2, ReferencesNameString);
826 fprintf(Index, "%ld %ld\n", id1, id2);
827
828 SetCurrentOutput(Chapters);
829 return FALSE;
830 }
831 if (!start && (arg_no == 2))
832 {
833 }
834 return TRUE;
835 break;
836 }
837 case ltTWOCOLITEM:
838 case ltTWOCOLITEMRULED:
839 {
840 if (start && (arg_no == 2))
841 TexOutput("\n ");
842
843 if (!start && (arg_no == 2))
844 TexOutput("\n");
845 return TRUE;
846 }
847 /*
848 * Accents
849 *
850 */
851 case ltACCENT_GRAVE:
852 {
853 if (start)
854 {
855 char *val = GetArgData();
856 if (val)
857 {
858 switch (val[0])
859 {
860 case 'a':
861 TexOutput("a");
862 break;
863 case 'e':
864 TexOutput("e");
865 break;
866 case 'i':
867 TexOutput("i");
868 break;
869 case 'o':
870 TexOutput("o");
871 break;
872 case 'u':
873 TexOutput("u");
874 break;
875 case 'A':
876 TexOutput("a");
877 break;
878 case 'E':
879 TexOutput("E");
880 break;
881 case 'I':
882 TexOutput("I");
883 break;
884 case 'O':
885 TexOutput("O");
886 break;
887 case 'U':
888 TexOutput("U");
889 break;
890 default:
891 break;
892 }
893 }
894 }
895 return FALSE;
896 break;
897 }
898 case ltACCENT_ACUTE:
899 {
900 if (start)
901 {
902 char *val = GetArgData();
903 if (val)
904 {
905 switch (val[0])
906 {
907 case 'a':
908 TexOutput("a");
909 break;
910 case 'e':
911 TexOutput("e");
912 break;
913 case 'i':
914 TexOutput("i");
915 break;
916 case 'o':
917 TexOutput("o");
918 break;
919 case 'u':
920 TexOutput("u");
921 break;
922 case 'y':
923 TexOutput("y");
924 break;
925 case 'A':
926 TexOutput("A");
927 break;
928 case 'E':
929 TexOutput("E");
930 break;
931 case 'I':
932 TexOutput("I");
933 break;
934 case 'O':
935 TexOutput("O");
936 break;
937 case 'U':
938 TexOutput("U");
939 break;
940 case 'Y':
941 TexOutput("Y");
942 break;
943 default:
944 break;
945 }
946 }
947 }
948 return FALSE;
949 break;
950 }
951 case ltACCENT_CARET:
952 {
953 if (start)
954 {
955 char *val = GetArgData();
956 if (val)
957 {
958 switch (val[0])
959 {
960 case 'a':
961 TexOutput("a");
962 break;
963 case 'e':
964 TexOutput("e");
965 break;
966 case 'i':
967 TexOutput("i");
968 break;
969 case 'o':
970 TexOutput("o");
971 break;
972 case 'u':
973 TexOutput("u");
974 break;
975 case 'A':
976 TexOutput("A");
977 break;
978 case 'E':
979 TexOutput("E");
980 break;
981 case 'I':
982 TexOutput("I");
983 break;
984 case 'O':
985 TexOutput("O");
986 break;
987 case 'U':
988 TexOutput("U");
989 break;
990 default:
991 break;
992 }
993 }
994 }
995 return FALSE;
996 break;
997 }
998 case ltACCENT_TILDE:
999 {
1000 if (start)
1001 {
1002 char *val = GetArgData();
1003 if (val)
1004 {
1005 switch (val[0])
1006 {
1007 case 'a':
1008 TexOutput("a");
1009 break;
1010 case ' ':
1011 TexOutput("~");
1012 break;
1013 case 'n':
1014 TexOutput("n");
1015 break;
1016 case 'o':
1017 TexOutput("o");
1018 break;
1019 case 'A':
1020 TexOutput("A");
1021 break;
1022 case 'N':
1023 TexOutput("N");
1024 break;
1025 case 'O':
1026 TexOutput("O");
1027 break;
1028 default:
1029 break;
1030 }
1031 }
1032 }
1033 return FALSE;
1034 break;
1035 }
1036 case ltACCENT_UMLAUT:
1037 {
1038 if (start)
1039 {
1040 char *val = GetArgData();
1041 if (val)
1042 {
1043 switch (val[0])
1044 {
1045 case 'a':
1046 TexOutput("a");
1047 break;
1048 case 'e':
1049 TexOutput("e");
1050 break;
1051 case 'i':
1052 TexOutput("i");
1053 break;
1054 case 'o':
1055 TexOutput("o");
1056 break;
1057 case 'u':
1058 TexOutput("u");
1059 break;
1060 case 'y':
1061 TexOutput("y");
1062 break;
1063 case 'A':
1064 TexOutput("A");
1065 break;
1066 case 'E':
1067 TexOutput("E");
1068 break;
1069 case 'I':
1070 TexOutput("I");
1071 break;
1072 case 'O':
1073 TexOutput("O");
1074 break;
1075 case 'U':
1076 TexOutput("U");
1077 break;
1078 case 'Y':
1079 TexOutput("Y");
1080 break;
1081 default:
1082 break;
1083 }
1084 }
1085 }
1086 return FALSE;
1087 break;
1088 }
1089 case ltACCENT_DOT:
1090 {
1091 if (start)
1092 {
1093 char *val = GetArgData();
1094 if (val)
1095 {
1096 switch (val[0])
1097 {
1098 case 'a':
1099 TexOutput("a");
1100 break;
1101 case 'A':
1102 TexOutput("A");
1103 break;
1104 default:
1105 break;
1106 }
1107 }
1108 }
1109 return FALSE;
1110 break;
1111 }
1112 case ltACCENT_CADILLA:
1113 {
1114 if (start)
1115 {
1116 char *val = GetArgData();
1117 if (val)
1118 {
1119 switch (val[0])
1120 {
1121 case 'c':
1122 TexOutput("c");
1123 break;
1124 case 'C':
1125 TexOutput("C");
1126 break;
1127 default:
1128 break;
1129 }
1130 }
1131 }
1132 return FALSE;
1133 break;
1134 }
1135 default:
1136 {
1137 return DefaultOnArgument(macroId, arg_no, start);
1138 break;
1139 }
1140 }
1141 return TRUE;
1142 }
1143
1144 bool XLPGo(void)
1145 {
1146 xlpBlockId = 0;
1147
1148 if (InputFile && OutputFile)
1149 {
1150 Contents = fopen(TmpContentsName, "w");
1151 Chapters = fopen("chapters.xlp", "w");
1152 Sections = fopen("sections.xlp", "w");
1153 Subsections = fopen("subsections.xlp", "w");
1154 Subsubsections = fopen("subsubsections.xlp", "w");
1155 Index = fopen("index.xlp", "w");
1156
1157 // Insert invisible section marker at beginning
1158 fprintf(Chapters, "\\hy-%d{%ld}{%s}\n",
1159 hyBLOCK_INVISIBLE_SECTION, NewBlockId(), "\n");
1160
1161 fprintf(Contents, "\\hy-%d{%ld}{%s}\n\n",
1162 // hyBLOCK_LARGE_HEADING, NewBlockId(), "\n\n%s\n\n", ContentsNameString);
1163 hyBLOCK_LARGE_HEADING, NewBlockId(), ContentsNameString);
1164
1165 SetCurrentOutput(Chapters);
1166
1167 fprintf(Index, "\n\\hyindex{\n\"%s\"\n",
1168 contentsString ? contentsString : "WXHELPCONTENTS");
1169 TraverseDocument();
1170
1171 wxNode *node = hyperLinks.First();
1172 while (node)
1173 {
1174 long from = node->GetKeyInteger();
1175 char *label = (char *)node->Data();
1176 wxNode *otherNode = hyperLabels.Find(label);
1177 if (otherNode)
1178 {
1179 long to = (long)otherNode->Data();
1180 fprintf(Index, "%ld %ld\n", from, to);
1181 }
1182 node = node->Next();
1183 }
1184
1185 fprintf(Index, "}\n");
1186
1187 fclose(Contents); Contents = NULL;
1188 fclose(Chapters); Chapters = NULL;
1189 fclose(Sections); Sections = NULL;
1190 fclose(Subsections); Subsections = NULL;
1191 fclose(Subsubsections); Subsubsections = NULL;
1192 fclose(Index); Index = NULL;
1193
1194 if (FileExists(ContentsName)) wxRemoveFile(ContentsName);
1195
1196 if (!wxRenameFile(TmpContentsName, ContentsName))
1197 {
1198 wxCopyFile(TmpContentsName, ContentsName);
1199 wxRemoveFile(TmpContentsName);
1200 }
1201
1202 wxConcatFiles("chapters.xlp", "sections.xlp", "tmp2.xlp");
1203 wxConcatFiles("tmp2.xlp", "subsections.xlp", "tmp1.xlp");
1204 wxConcatFiles("tmp1.xlp", "subsubsections.xlp", "tmp2.xlp");
1205 wxConcatFiles("tmp2.xlp", "index.xlp", OutputFile);
1206
1207 wxRemoveFile("tmp1.xlp");
1208 wxRemoveFile("tmp2.xlp");
1209
1210 wxRemoveFile("chapters.xlp");
1211 wxRemoveFile("sections.xlp");
1212 wxRemoveFile("subsections.xlp");
1213 wxRemoveFile("subsubsections.xlp");
1214 wxRemoveFile("index.xlp");
1215 return TRUE;
1216 }
1217 return FALSE;
1218 }
1219