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