]>
Commit | Line | Data |
---|---|---|
9a29912f JS |
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 | |
9a29912f JS |
24 | #endif |
25 | ||
26 | #include "tex2any.h" | |
27 | #include "tex2rtf.h" | |
28 | #include <ctype.h> | |
29 | ||
ea172e69 MB |
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 | ||
9a29912f JS |
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 | ||
3924dd22 GT |
48 | |
49 | extern wxHashTable TexReferences; | |
50 | ||
51 | ||
9a29912f JS |
52 | void PadToTab(int tabPos) |
53 | { | |
54 | int currentCol = GetCurrentColumn(); | |
55 | for (int i = currentCol; i < tabPos; i++) | |
56 | TexOutput(" ", 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 | char 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 | fprintf(Contents, "\\hy-%d{%ld}{", hyBLOCK_SMALL_HEADING, id1); | |
90 | fprintf(Chapters, "\n\\hy-%d{%ld}{", hyBLOCK_LARGE_VISIBLE_SECTION, currentBlockId); | |
91 | fprintf(Index, "%ld %ld\n", id1, currentBlockId); | |
92 | ||
93 | OutputCurrentSection(); // Repeat section header | |
94 | ||
95 | fprintf(Contents, "}\n\n"); | |
96 | fprintf(Chapters, "}\n\n"); | |
97 | SetCurrentOutput(Chapters); | |
98 | char *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 | fprintf(Contents, "\\hy-%d{%ld}{", hyBLOCK_LARGE_HEADING, id1); | |
124 | else | |
125 | fprintf(Chapters, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id1); | |
126 | fprintf(Sections, "\n\\hy-%d{%ld}{", hyBLOCK_LARGE_VISIBLE_SECTION, currentBlockId); | |
127 | fprintf(Index, "%ld %ld\n", id1, currentBlockId); | |
128 | ||
129 | OutputCurrentSection(); // Repeat section header | |
130 | ||
131 | if (DocumentStyle == LATEX_ARTICLE) | |
132 | fprintf(Contents, "}\n\n"); | |
133 | else | |
134 | fprintf(Chapters, "}\n\n"); | |
135 | fprintf(Sections, "}\n\n"); | |
136 | SetCurrentOutput(Sections); | |
137 | char *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 | fprintf(Sections, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id1); | |
158 | fprintf(Subsections, "\n\\hy-%d{%ld}{", hyBLOCK_LARGE_VISIBLE_SECTION, currentBlockId); | |
159 | fprintf(Index, "%ld %ld\n", id1, currentBlockId); | |
160 | ||
161 | OutputCurrentSection(); // Repeat section header | |
162 | ||
163 | fprintf(Sections, "}\n\n"); | |
164 | fprintf(Subsections, "}\n\n"); | |
165 | SetCurrentOutput(Subsections); | |
166 | char *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 | fprintf(Subsections, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id1); | |
183 | fprintf(Subsubsections, "\n\\hy-%d{%ld}{", hyBLOCK_LARGE_VISIBLE_SECTION, currentBlockId); | |
184 | fprintf(Index, "%ld %ld\n", id1, currentBlockId); | |
185 | ||
186 | OutputCurrentSection(); // Repeat section header | |
187 | ||
188 | fprintf(Subsections, "}\n\n"); | |
189 | fprintf(Subsubsections, "}\n\n"); | |
190 | SetCurrentOutput(Subsubsections); | |
191 | char *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 | fprintf(Subsections, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id); | |
205 | } | |
206 | else | |
207 | fprintf(Subsections, "}"); | |
208 | break; | |
209 | } | |
210 | case ltVOID: | |
211 | // if (start) | |
212 | // TexOutput("void", TRUE); | |
213 | break; | |
214 | case ltBACKSLASHCHAR: | |
215 | if (start) | |
216 | TexOutput("\n", TRUE); | |
217 | break; | |
218 | case ltPAR: | |
219 | { | |
220 | if (start) | |
221 | { | |
222 | if (ParSkip > 0) | |
223 | TexOutput("\n", TRUE); | |
224 | TexOutput("\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 | char buf[100]; | |
241 | long id = NewBlockId(); | |
242 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id); | |
243 | TexOutput(buf); | |
244 | } | |
245 | else TexOutput("}"); | |
246 | break; | |
247 | } | |
248 | case ltTEXTIT: | |
249 | case ltITSHAPE: | |
250 | case ltIT: | |
251 | { | |
252 | if (start) | |
253 | { | |
254 | char buf[100]; | |
255 | long id = NewBlockId(); | |
256 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_ITALIC, id); | |
257 | TexOutput(buf); | |
258 | } | |
259 | else TexOutput("}"); | |
260 | break; | |
261 | } | |
262 | case ltTTFAMILY: | |
263 | case ltTEXTTT: | |
264 | case ltTT: | |
265 | { | |
266 | if (start) | |
267 | { | |
268 | long id = NewBlockId(); | |
269 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_TELETYPE, id); | |
270 | TexOutput(buf); | |
271 | } | |
272 | else TexOutput("}"); | |
273 | break; | |
274 | } | |
275 | case ltSMALL: | |
276 | { | |
277 | if (start) | |
278 | { | |
279 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_SMALL_TEXT, NewBlockId()); | |
280 | TexOutput(buf); | |
281 | } | |
282 | else TexOutput("}"); | |
283 | break; | |
284 | } | |
285 | case ltTINY: | |
286 | { | |
287 | if (start) | |
288 | { | |
289 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_SMALL_TEXT, NewBlockId()); | |
290 | TexOutput(buf); | |
291 | } | |
292 | else TexOutput("}"); | |
293 | break; | |
294 | } | |
295 | case ltNORMALSIZE: | |
296 | { | |
297 | if (start) | |
298 | { | |
299 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_NORMAL, NewBlockId()); | |
300 | TexOutput(buf); | |
301 | } | |
302 | else TexOutput("}"); | |
303 | break; | |
304 | } | |
305 | case ltlarge: | |
306 | { | |
307 | if (start) | |
308 | { | |
309 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_SMALL_HEADING, NewBlockId()); | |
310 | TexOutput(buf); | |
311 | } | |
312 | else TexOutput("}\n"); | |
313 | break; | |
314 | } | |
315 | case ltLARGE: | |
316 | { | |
317 | if (start) | |
318 | { | |
319 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_LARGE_HEADING, NewBlockId()); | |
320 | TexOutput(buf); | |
321 | } | |
322 | else TexOutput("}\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("\\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.First()) | |
352 | { | |
353 | ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.First()->Data(); | |
354 | delete struc; | |
355 | delete itemizeStack.First(); | |
356 | } | |
357 | } | |
358 | break; | |
359 | } | |
360 | case ltITEM: | |
361 | { | |
362 | wxNode *node = itemizeStack.First(); | |
363 | if (node) | |
364 | { | |
365 | ItemizeStruc *struc = (ItemizeStruc *)node->Data(); | |
366 | if (!start) | |
367 | { | |
368 | struc->currentItem += 1; | |
369 | char indentBuf[30]; | |
370 | ||
371 | switch (struc->listType) | |
372 | { | |
373 | case LATEX_ENUMERATE: | |
374 | { | |
375 | sprintf(indentBuf, "\\hy-%d{%ld}{%d.} ", | |
376 | hyBLOCK_BOLD, NewBlockId(), struc->currentItem); | |
377 | TexOutput(indentBuf); | |
378 | break; | |
379 | } | |
380 | case LATEX_ITEMIZE: | |
381 | { | |
382 | sprintf(indentBuf, "\\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 | sprintf(indentBuf, "\\hy-%d{%ld}{", | |
393 | hyBLOCK_BOLD, NewBlockId()); | |
394 | TexOutput(indentBuf); | |
395 | TraverseChildrenFromChunk(descriptionItemArg); | |
396 | TexOutput("} "); | |
397 | descriptionItemArg = NULL; | |
398 | } | |
399 | break; | |
400 | } | |
401 | } | |
402 | } | |
403 | } | |
404 | break; | |
405 | } | |
406 | case ltMAKETITLE: | |
407 | { | |
408 | if (start && DocumentTitle && DocumentAuthor) | |
409 | { | |
410 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_LARGE_HEADING, NewBlockId()); | |
411 | TexOutput(buf); | |
412 | TraverseChildrenFromChunk(DocumentTitle); | |
413 | TexOutput("}\n\n"); | |
414 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_SMALL_HEADING, NewBlockId()); | |
415 | TexOutput(buf); | |
416 | TraverseChildrenFromChunk(DocumentAuthor); | |
417 | TexOutput("}\n\n"); | |
418 | if (DocumentDate) | |
419 | { | |
420 | TraverseChildrenFromChunk(DocumentDate); | |
421 | TexOutput("\n"); | |
422 | } | |
423 | } | |
424 | break; | |
425 | } | |
426 | case ltTABLEOFCONTENTS: | |
427 | { | |
428 | if (start) | |
429 | { | |
430 | FILE *fd = fopen(ContentsName, "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("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n"); | |
444 | OnInform("Run Tex2RTF again to include contents page."); | |
445 | } | |
446 | } | |
447 | break; | |
448 | } | |
449 | case ltHARDY: | |
450 | { | |
451 | if (start) | |
452 | TexOutput("HARDY", TRUE); | |
453 | break; | |
454 | } | |
455 | case ltWXCLIPS: | |
456 | { | |
457 | if (start) | |
458 | TexOutput("wxCLIPS", TRUE); | |
459 | break; | |
460 | } | |
461 | case ltVERBATIM: | |
462 | { | |
463 | if (start) | |
464 | { | |
465 | char buf[100]; | |
466 | long id = NewBlockId(); | |
467 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_TELETYPE, id); | |
468 | TexOutput(buf); | |
469 | } | |
470 | else TexOutput("}"); | |
471 | break; | |
472 | } | |
473 | case ltHRULE: | |
474 | { | |
475 | if (start) | |
476 | { | |
477 | TexOutput("\n------------------------------------------------------------------", TRUE); | |
478 | } | |
479 | break; | |
480 | } | |
481 | case ltHLINE: | |
482 | { | |
483 | if (start) | |
484 | { | |
485 | TexOutput("--------------------------------------------------------------------------------", 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 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_TELETYPE, NewBlockId()); | |
505 | TexOutput(buf); | |
506 | } | |
507 | else | |
508 | TexOutput("}"); | |
509 | break; | |
510 | } | |
511 | case ltNUMBEREDBIBITEM: | |
512 | { | |
513 | if (!start) | |
514 | TexOutput("\n\n", TRUE); | |
515 | break; | |
516 | } | |
517 | case ltCAPTION: | |
518 | case ltCAPTIONSTAR: | |
519 | { | |
520 | if (start) | |
521 | { | |
522 | figureNo ++; | |
523 | ||
524 | char figBuf[40]; | |
525 | if (DocumentStyle != LATEX_ARTICLE) | |
526 | sprintf(figBuf, "Figure %d.%d: ", chapterNo, figureNo); | |
527 | else | |
528 | sprintf(figBuf, "Figure %d: ", figureNo); | |
529 | ||
530 | TexOutput(figBuf); | |
531 | } | |
532 | else | |
533 | { | |
534 | char *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 | char 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 | break; | |
573 | } | |
574 | case ltFUNC: | |
575 | { | |
576 | if (!start && (arg_no == 1)) | |
577 | TexOutput(" ", TRUE); | |
578 | if (start && (arg_no == 3)) | |
579 | TexOutput("(", TRUE); | |
580 | if (!start && (arg_no == 3)) | |
581 | TexOutput(")", TRUE); | |
582 | break; | |
583 | } | |
584 | case ltPFUNC: | |
585 | { | |
586 | if (!start && (arg_no == 1)) | |
587 | TexOutput(" ", TRUE); | |
588 | ||
589 | if (start && (arg_no == 2)) | |
590 | TexOutput("(*", TRUE); | |
591 | if (!start && (arg_no == 2)) | |
592 | TexOutput(")", TRUE); | |
593 | ||
594 | if (start && (arg_no == 3)) | |
595 | TexOutput("(", TRUE); | |
596 | if (!start && (arg_no == 3)) | |
597 | TexOutput(")", TRUE); | |
598 | break; | |
599 | } | |
600 | case ltCLIPSFUNC: | |
601 | { | |
602 | if (!start && (arg_no == 1)) | |
603 | TexOutput(" ", TRUE); | |
604 | if (start && (arg_no == 2)) | |
605 | { | |
606 | TexOutput("(", TRUE); | |
607 | long id = NewBlockId(); | |
608 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_BOLD, id); | |
609 | TexOutput(buf); | |
610 | } | |
611 | if (!start && (arg_no == 2)) | |
612 | { | |
613 | TexOutput("}"); | |
614 | } | |
615 | if (!start && (arg_no == 3)) | |
616 | TexOutput(")", TRUE); | |
617 | break; | |
618 | } | |
619 | case ltPARAM: | |
620 | { | |
621 | if (start && (arg_no == 2)) | |
622 | { | |
623 | long id = NewBlockId(); | |
624 | sprintf(buf, " \\hy-%d{%ld}{", hyBLOCK_BOLD, id); | |
625 | TexOutput(buf); | |
626 | } | |
627 | if (!start && (arg_no == 2)) | |
628 | { | |
629 | TexOutput("}"); | |
630 | } | |
631 | break; | |
632 | } | |
633 | case ltCPARAM: | |
634 | { | |
635 | if (start && (arg_no == 2)) | |
636 | { | |
637 | long id = NewBlockId(); | |
638 | sprintf(buf, " \\hy-%d{%ld}{", hyBLOCK_BOLD, id); | |
639 | TexOutput(buf); | |
640 | } | |
641 | if (!start && (arg_no == 2)) | |
642 | { | |
643 | TexOutput("}"); | |
644 | } | |
645 | break; | |
646 | } | |
647 | case ltMEMBER: | |
648 | { | |
649 | if (!start && (arg_no == 1)) | |
650 | TexOutput(" ", TRUE); | |
651 | break; | |
652 | } | |
653 | case ltLABEL: | |
654 | { | |
655 | return FALSE; | |
656 | break; | |
657 | } | |
658 | case ltREF: | |
659 | { | |
660 | if (start) | |
661 | { | |
662 | char *sec = NULL; | |
663 | ||
664 | char *refName = GetArgData(); | |
665 | if (refName) | |
666 | { | |
667 | TexRef *texRef = FindReference(refName); | |
668 | if (texRef) | |
669 | { | |
670 | sec = texRef->sectionNumber; | |
671 | } | |
672 | } | |
673 | if (sec) | |
674 | { | |
675 | TexOutput(sec); | |
676 | } | |
677 | return FALSE; | |
678 | } | |
679 | break; | |
680 | } | |
681 | case ltHELPREF: | |
682 | case ltHELPREFN: | |
683 | case ltPOPREF: | |
684 | { | |
685 | if (arg_no == 1) | |
686 | { | |
687 | if (start) | |
688 | { | |
689 | currentBlockId = NewBlockId(); | |
690 | sprintf(buf, "\\hy-%d{%ld}{", hyBLOCK_RED_ITALIC, currentBlockId); | |
691 | TexOutput(buf); | |
692 | } | |
693 | else TexOutput("}"); | |
694 | } | |
695 | if (arg_no == 2) | |
696 | { | |
697 | if (start) | |
698 | { | |
699 | char *label = GetArgData(); | |
700 | hyperLinks.Append(currentBlockId, (wxObject *)copystring(label)); | |
701 | } | |
702 | ||
703 | return FALSE; | |
704 | } | |
705 | break; | |
706 | } | |
707 | case ltURLREF: | |
708 | { | |
709 | if (arg_no == 1) | |
710 | { | |
711 | return TRUE; | |
712 | } | |
713 | else if (arg_no == 2) | |
714 | { | |
715 | if (start) | |
716 | TexOutput(" ("); | |
717 | else | |
718 | TexOutput(")"); | |
719 | return TRUE; | |
720 | } | |
721 | break; | |
722 | } | |
723 | case ltITEM: | |
724 | { | |
725 | if (start && IsArgOptional()) | |
726 | { | |
727 | descriptionItemArg = GetArgChunk(); | |
728 | return FALSE; | |
729 | } | |
730 | break; | |
731 | } | |
732 | case ltTABULAR: | |
733 | case ltSUPERTABULAR: | |
734 | { | |
735 | if (arg_no == 1) | |
736 | { | |
737 | if (start) | |
738 | { | |
739 | inTable = TRUE; | |
740 | tableVerticalLineLeft = FALSE; | |
741 | tableVerticalLineRight = FALSE; | |
742 | ||
743 | char *alignString = copystring(GetArgData()); | |
744 | ||
745 | // Count the number of columns | |
746 | noColumns = 0; | |
747 | int len = strlen(alignString); | |
748 | if (len > 0) | |
749 | { | |
750 | if (alignString[0] == '|') | |
751 | tableVerticalLineLeft = TRUE; | |
752 | if (alignString[len-1] == '|') | |
753 | tableVerticalLineRight = TRUE; | |
754 | } | |
755 | ||
756 | for (int i = 0; i < len; i++) | |
757 | if (isalpha(alignString[i])) | |
758 | noColumns ++; | |
759 | ||
760 | /* | |
761 | // Experimental | |
762 | TexOutput("\\brdrt\\brdrs"); | |
763 | if (tableVerticalLineLeft) | |
764 | TexOutput("\\brdrl\\brdrs"); | |
765 | if (tableVerticalLineRight) | |
766 | TexOutput("\\brdrr\\brdrs"); | |
767 | */ | |
768 | ||
769 | // Calculate a rough size for each column | |
770 | // int tabPos = 80/noColumns; | |
771 | currentTab = 0; | |
772 | ||
773 | return FALSE; | |
774 | } | |
775 | } | |
776 | else if (arg_no == 2 && !start) | |
777 | { | |
778 | inTable = FALSE; | |
779 | } | |
780 | else if (arg_no == 2 && start) | |
781 | return TRUE; | |
782 | break; | |
783 | } | |
784 | case ltMARGINPAR: | |
785 | case ltMARGINPAREVEN: | |
786 | case ltMARGINPARODD: | |
787 | case ltNORMALBOX: | |
788 | case ltNORMALBOXD: | |
789 | { | |
790 | if (start) | |
791 | { | |
792 | TexOutput("----------------------------------------------------------------------\n", TRUE); | |
793 | return TRUE; | |
794 | } | |
795 | else | |
796 | TexOutput("\n----------------------------------------------------------------------\n", TRUE); | |
797 | break; | |
798 | } | |
799 | case ltBIBITEM: | |
800 | { | |
801 | char buf[100]; | |
802 | if (arg_no == 1 && start) | |
803 | { | |
804 | char *citeKey = GetArgData(); | |
805 | TexRef *ref = (TexRef *)TexReferences.Get(citeKey); | |
806 | if (ref) | |
807 | { | |
808 | if (ref->sectionNumber) delete[] ref->sectionNumber; | |
809 | sprintf(buf, "[%d]", citeCount); | |
810 | ref->sectionNumber = copystring(buf); | |
811 | } | |
812 | ||
813 | sprintf(buf, "\\hy-%d{%ld}{[%d]} ", hyBLOCK_BOLD, NewBlockId(), citeCount); | |
814 | TexOutput(buf); | |
815 | citeCount ++; | |
816 | return FALSE; | |
817 | } | |
818 | return TRUE; | |
819 | break; | |
820 | } | |
821 | case ltTHEBIBLIOGRAPHY: | |
822 | { | |
823 | if (start && (arg_no == 1)) | |
824 | { | |
825 | citeCount = 1; | |
826 | ||
827 | SetCurrentOutput(Chapters); | |
828 | ||
829 | SetCurrentOutputs(Contents, Chapters); | |
830 | long id1 = NewBlockId(); | |
831 | long id2 = NewBlockId(); | |
832 | fprintf(Contents, "\\hy-%d{%ld}{%s}\n", hyBLOCK_SMALL_HEADING, id1, ReferencesNameString); | |
833 | fprintf(Chapters, "\\hy-%d{%ld}{%s}\n\n\n", hyBLOCK_LARGE_VISIBLE_SECTION, id2, ReferencesNameString); | |
834 | fprintf(Index, "%ld %ld\n", id1, id2); | |
835 | ||
836 | SetCurrentOutput(Chapters); | |
837 | return FALSE; | |
838 | } | |
839 | if (!start && (arg_no == 2)) | |
840 | { | |
841 | } | |
842 | return TRUE; | |
843 | break; | |
844 | } | |
845 | case ltTWOCOLITEM: | |
846 | case ltTWOCOLITEMRULED: | |
847 | { | |
848 | if (start && (arg_no == 2)) | |
849 | TexOutput("\n "); | |
850 | ||
851 | if (!start && (arg_no == 2)) | |
852 | TexOutput("\n"); | |
853 | return TRUE; | |
854 | } | |
855 | /* | |
856 | * Accents | |
857 | * | |
858 | */ | |
859 | case ltACCENT_GRAVE: | |
860 | { | |
861 | if (start) | |
862 | { | |
863 | char *val = GetArgData(); | |
864 | if (val) | |
865 | { | |
866 | switch (val[0]) | |
867 | { | |
868 | case 'a': | |
869 | TexOutput("a"); | |
870 | break; | |
871 | case 'e': | |
872 | TexOutput("e"); | |
873 | break; | |
874 | case 'i': | |
875 | TexOutput("i"); | |
876 | break; | |
877 | case 'o': | |
878 | TexOutput("o"); | |
879 | break; | |
880 | case 'u': | |
881 | TexOutput("u"); | |
882 | break; | |
883 | case 'A': | |
884 | TexOutput("a"); | |
885 | break; | |
886 | case 'E': | |
887 | TexOutput("E"); | |
888 | break; | |
889 | case 'I': | |
890 | TexOutput("I"); | |
891 | break; | |
892 | case 'O': | |
893 | TexOutput("O"); | |
894 | break; | |
895 | case 'U': | |
896 | TexOutput("U"); | |
897 | break; | |
898 | default: | |
899 | break; | |
900 | } | |
901 | } | |
902 | } | |
903 | return FALSE; | |
904 | break; | |
905 | } | |
906 | case ltACCENT_ACUTE: | |
907 | { | |
908 | if (start) | |
909 | { | |
910 | char *val = GetArgData(); | |
911 | if (val) | |
912 | { | |
913 | switch (val[0]) | |
914 | { | |
915 | case 'a': | |
916 | TexOutput("a"); | |
917 | break; | |
918 | case 'e': | |
919 | TexOutput("e"); | |
920 | break; | |
921 | case 'i': | |
922 | TexOutput("i"); | |
923 | break; | |
924 | case 'o': | |
925 | TexOutput("o"); | |
926 | break; | |
927 | case 'u': | |
928 | TexOutput("u"); | |
929 | break; | |
930 | case 'y': | |
931 | TexOutput("y"); | |
932 | break; | |
933 | case 'A': | |
934 | TexOutput("A"); | |
935 | break; | |
936 | case 'E': | |
937 | TexOutput("E"); | |
938 | break; | |
939 | case 'I': | |
940 | TexOutput("I"); | |
941 | break; | |
942 | case 'O': | |
943 | TexOutput("O"); | |
944 | break; | |
945 | case 'U': | |
946 | TexOutput("U"); | |
947 | break; | |
948 | case 'Y': | |
949 | TexOutput("Y"); | |
950 | break; | |
951 | default: | |
952 | break; | |
953 | } | |
954 | } | |
955 | } | |
956 | return FALSE; | |
957 | break; | |
958 | } | |
959 | case ltACCENT_CARET: | |
960 | { | |
961 | if (start) | |
962 | { | |
963 | char *val = GetArgData(); | |
964 | if (val) | |
965 | { | |
966 | switch (val[0]) | |
967 | { | |
968 | case 'a': | |
969 | TexOutput("a"); | |
970 | break; | |
971 | case 'e': | |
972 | TexOutput("e"); | |
973 | break; | |
974 | case 'i': | |
975 | TexOutput("i"); | |
976 | break; | |
977 | case 'o': | |
978 | TexOutput("o"); | |
979 | break; | |
980 | case 'u': | |
981 | TexOutput("u"); | |
982 | break; | |
983 | case 'A': | |
984 | TexOutput("A"); | |
985 | break; | |
986 | case 'E': | |
987 | TexOutput("E"); | |
988 | break; | |
989 | case 'I': | |
990 | TexOutput("I"); | |
991 | break; | |
992 | case 'O': | |
993 | TexOutput("O"); | |
994 | break; | |
995 | case 'U': | |
996 | TexOutput("U"); | |
997 | break; | |
998 | default: | |
999 | break; | |
1000 | } | |
1001 | } | |
1002 | } | |
1003 | return FALSE; | |
1004 | break; | |
1005 | } | |
1006 | case ltACCENT_TILDE: | |
1007 | { | |
1008 | if (start) | |
1009 | { | |
1010 | char *val = GetArgData(); | |
1011 | if (val) | |
1012 | { | |
1013 | switch (val[0]) | |
1014 | { | |
1015 | case 'a': | |
1016 | TexOutput("a"); | |
1017 | break; | |
1018 | case ' ': | |
1019 | TexOutput("~"); | |
1020 | break; | |
1021 | case 'n': | |
1022 | TexOutput("n"); | |
1023 | break; | |
1024 | case 'o': | |
1025 | TexOutput("o"); | |
1026 | break; | |
1027 | case 'A': | |
1028 | TexOutput("A"); | |
1029 | break; | |
1030 | case 'N': | |
1031 | TexOutput("N"); | |
1032 | break; | |
1033 | case 'O': | |
1034 | TexOutput("O"); | |
1035 | break; | |
1036 | default: | |
1037 | break; | |
1038 | } | |
1039 | } | |
1040 | } | |
1041 | return FALSE; | |
1042 | break; | |
1043 | } | |
1044 | case ltACCENT_UMLAUT: | |
1045 | { | |
1046 | if (start) | |
1047 | { | |
1048 | char *val = GetArgData(); | |
1049 | if (val) | |
1050 | { | |
1051 | switch (val[0]) | |
1052 | { | |
1053 | case 'a': | |
1054 | TexOutput("a"); | |
1055 | break; | |
1056 | case 'e': | |
1057 | TexOutput("e"); | |
1058 | break; | |
1059 | case 'i': | |
1060 | TexOutput("i"); | |
1061 | break; | |
1062 | case 'o': | |
1063 | TexOutput("o"); | |
1064 | break; | |
1065 | case 'u': | |
1066 | TexOutput("u"); | |
1067 | break; | |
1068 | case 'y': | |
1069 | TexOutput("y"); | |
1070 | break; | |
1071 | case 'A': | |
1072 | TexOutput("A"); | |
1073 | break; | |
1074 | case 'E': | |
1075 | TexOutput("E"); | |
1076 | break; | |
1077 | case 'I': | |
1078 | TexOutput("I"); | |
1079 | break; | |
1080 | case 'O': | |
1081 | TexOutput("O"); | |
1082 | break; | |
1083 | case 'U': | |
1084 | TexOutput("U"); | |
1085 | break; | |
1086 | case 'Y': | |
1087 | TexOutput("Y"); | |
1088 | break; | |
1089 | default: | |
1090 | break; | |
1091 | } | |
1092 | } | |
1093 | } | |
1094 | return FALSE; | |
1095 | break; | |
1096 | } | |
1097 | case ltACCENT_DOT: | |
1098 | { | |
1099 | if (start) | |
1100 | { | |
1101 | char *val = GetArgData(); | |
1102 | if (val) | |
1103 | { | |
1104 | switch (val[0]) | |
1105 | { | |
1106 | case 'a': | |
1107 | TexOutput("a"); | |
1108 | break; | |
1109 | case 'A': | |
1110 | TexOutput("A"); | |
1111 | break; | |
1112 | default: | |
1113 | break; | |
1114 | } | |
1115 | } | |
1116 | } | |
1117 | return FALSE; | |
1118 | break; | |
1119 | } | |
1120 | case ltACCENT_CADILLA: | |
1121 | { | |
1122 | if (start) | |
1123 | { | |
1124 | char *val = GetArgData(); | |
1125 | if (val) | |
1126 | { | |
1127 | switch (val[0]) | |
1128 | { | |
1129 | case 'c': | |
1130 | TexOutput("c"); | |
1131 | break; | |
1132 | case 'C': | |
1133 | TexOutput("C"); | |
1134 | break; | |
1135 | default: | |
1136 | break; | |
1137 | } | |
1138 | } | |
1139 | } | |
1140 | return FALSE; | |
1141 | break; | |
1142 | } | |
1143 | default: | |
1144 | { | |
1145 | return DefaultOnArgument(macroId, arg_no, start); | |
1146 | break; | |
1147 | } | |
1148 | } | |
1149 | return TRUE; | |
1150 | } | |
1151 | ||
1152 | bool XLPGo(void) | |
1153 | { | |
1154 | xlpBlockId = 0; | |
1155 | ||
1156 | if (InputFile && OutputFile) | |
1157 | { | |
1158 | Contents = fopen(TmpContentsName, "w"); | |
1159 | Chapters = fopen("chapters.xlp", "w"); | |
1160 | Sections = fopen("sections.xlp", "w"); | |
1161 | Subsections = fopen("subsections.xlp", "w"); | |
1162 | Subsubsections = fopen("subsubsections.xlp", "w"); | |
1163 | Index = fopen("index.xlp", "w"); | |
1164 | ||
1165 | // Insert invisible section marker at beginning | |
1166 | fprintf(Chapters, "\\hy-%d{%ld}{%s}\n", | |
1167 | hyBLOCK_INVISIBLE_SECTION, NewBlockId(), "\n"); | |
1168 | ||
1169 | fprintf(Contents, "\\hy-%d{%ld}{%s}\n\n", | |
1170 | // hyBLOCK_LARGE_HEADING, NewBlockId(), "\n\n%s\n\n", ContentsNameString); | |
1171 | hyBLOCK_LARGE_HEADING, NewBlockId(), ContentsNameString); | |
1172 | ||
1173 | SetCurrentOutput(Chapters); | |
1174 | ||
1175 | fprintf(Index, "\n\\hyindex{\n\"%s\"\n", | |
1176 | contentsString ? contentsString : "WXHELPCONTENTS"); | |
1177 | TraverseDocument(); | |
1178 | ||
1179 | wxNode *node = hyperLinks.First(); | |
1180 | while (node) | |
1181 | { | |
1182 | long from = node->GetKeyInteger(); | |
1183 | char *label = (char *)node->Data(); | |
1184 | wxNode *otherNode = hyperLabels.Find(label); | |
1185 | if (otherNode) | |
1186 | { | |
1187 | long to = (long)otherNode->Data(); | |
1188 | fprintf(Index, "%ld %ld\n", from, to); | |
1189 | } | |
1190 | node = node->Next(); | |
1191 | } | |
1192 | ||
1193 | fprintf(Index, "}\n"); | |
1194 | ||
1195 | fclose(Contents); Contents = NULL; | |
1196 | fclose(Chapters); Chapters = NULL; | |
1197 | fclose(Sections); Sections = NULL; | |
1198 | fclose(Subsections); Subsections = NULL; | |
1199 | fclose(Subsubsections); Subsubsections = NULL; | |
1200 | fclose(Index); Index = NULL; | |
1201 | ||
2b5f62a0 | 1202 | if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName); |
9a29912f JS |
1203 | |
1204 | if (!wxRenameFile(TmpContentsName, ContentsName)) | |
1205 | { | |
1206 | wxCopyFile(TmpContentsName, ContentsName); | |
1207 | wxRemoveFile(TmpContentsName); | |
1208 | } | |
1209 | ||
1210 | wxConcatFiles("chapters.xlp", "sections.xlp", "tmp2.xlp"); | |
1211 | wxConcatFiles("tmp2.xlp", "subsections.xlp", "tmp1.xlp"); | |
1212 | wxConcatFiles("tmp1.xlp", "subsubsections.xlp", "tmp2.xlp"); | |
1213 | wxConcatFiles("tmp2.xlp", "index.xlp", OutputFile); | |
1214 | ||
1215 | wxRemoveFile("tmp1.xlp"); | |
1216 | wxRemoveFile("tmp2.xlp"); | |
1217 | ||
1218 | wxRemoveFile("chapters.xlp"); | |
1219 | wxRemoveFile("sections.xlp"); | |
1220 | wxRemoveFile("subsections.xlp"); | |
1221 | wxRemoveFile("subsubsections.xlp"); | |
1222 | wxRemoveFile("index.xlp"); | |
1223 | return TRUE; | |
1224 | } | |
1225 | return FALSE; | |
1226 | } | |
1227 |