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