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