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