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