]>
Commit | Line | Data |
---|---|---|
9a29912f JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: xlputils.cpp | |
3 | // Purpose: Converts Latex to obsolete XLP format | |
4 | // Author: Julian Smart | |
b63b07a8 RL |
5 | // Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support |
6 | // Ron Lee | |
9a29912f JS |
7 | // Created: 7.9.93 |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) Julian Smart | |
10 | // Licence: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
9a29912f JS |
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 | |
9a29912f JS |
21 | #endif |
22 | ||
23 | #include "tex2any.h" | |
24 | #include "tex2rtf.h" | |
25 | #include <ctype.h> | |
26 | ||
ea172e69 MB |
27 | static inline wxChar* copystring(const wxChar* s) |
28 | { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); } | |
ea172e69 | 29 | |
9a29912f JS |
30 | long currentBlockId = -1; |
31 | static TexChunk *descriptionItemArg = NULL; | |
32 | static int indentLevel = 0; | |
33 | static int noColumns = 0; | |
34 | static int currentTab = 0; | |
b63b07a8 RL |
35 | static bool tableVerticalLineLeft = false; |
36 | static bool tableVerticalLineRight = false; | |
37 | static bool inTable = false; | |
9a29912f JS |
38 | static int citeCount = 1; |
39 | wxList hyperLinks(wxKEY_INTEGER); | |
40 | wxList hyperLabels(wxKEY_STRING); | |
41 | FILE *Index = NULL; | |
42 | ||
3924dd22 GT |
43 | |
44 | extern wxHashTable TexReferences; | |
45 | ||
46 | ||
9a29912f JS |
47 | void PadToTab(int tabPos) |
48 | { | |
49 | int currentCol = GetCurrentColumn(); | |
50 | for (int i = currentCol; i < tabPos; i++) | |
b63b07a8 | 51 | TexOutput(_T(" "), true); |
9a29912f JS |
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 | { | |
6c155d33 | 63 | wxChar buf[100]; |
9a29912f JS |
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 | ||
b63b07a8 | 83 | startedSections = true; |
6c155d33 JS |
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); | |
9a29912f JS |
87 | |
88 | OutputCurrentSection(); // Repeat section header | |
89 | ||
6c155d33 JS |
90 | wxFprintf(Contents, _T("}\n\n")); |
91 | wxFprintf(Chapters, _T("}\n\n")); | |
9a29912f | 92 | SetCurrentOutput(Chapters); |
6c155d33 | 93 | wxChar *topicName = FindTopicName(GetNextChunk()); |
9a29912f JS |
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 ++; | |
5c66e5b2 | 110 | |
9a29912f JS |
111 | SetCurrentOutputs(Chapters, Sections); |
112 | long id1 = NewBlockId(); | |
113 | currentBlockId = NewBlockId(); | |
114 | ||
b63b07a8 | 115 | startedSections = true; |
9a29912f JS |
116 | |
117 | if (DocumentStyle == LATEX_ARTICLE) | |
6c155d33 | 118 | wxFprintf(Contents, _T("\\hy-%d{%ld}{"), hyBLOCK_LARGE_HEADING, id1); |
9a29912f | 119 | else |
6c155d33 JS |
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); | |
9a29912f JS |
123 | |
124 | OutputCurrentSection(); // Repeat section header | |
125 | ||
126 | if (DocumentStyle == LATEX_ARTICLE) | |
6c155d33 | 127 | wxFprintf(Contents, _T("}\n\n")); |
9a29912f | 128 | else |
6c155d33 JS |
129 | wxFprintf(Chapters, _T("}\n\n")); |
130 | wxFprintf(Sections, _T("}\n\n")); | |
9a29912f | 131 | SetCurrentOutput(Sections); |
6c155d33 | 132 | wxChar *topicName = FindTopicName(GetNextChunk()); |
9a29912f JS |
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(); | |
6c155d33 JS |
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); | |
9a29912f JS |
155 | |
156 | OutputCurrentSection(); // Repeat section header | |
157 | ||
6c155d33 JS |
158 | wxFprintf(Sections, _T("}\n\n")); |
159 | wxFprintf(Subsections, _T("}\n\n")); | |
9a29912f | 160 | SetCurrentOutput(Subsections); |
6c155d33 | 161 | wxChar *topicName = FindTopicName(GetNextChunk()); |
9a29912f JS |
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(); | |
6c155d33 JS |
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); | |
9a29912f JS |
180 | |
181 | OutputCurrentSection(); // Repeat section header | |
182 | ||
6c155d33 JS |
183 | wxFprintf(Subsections, _T("}\n\n")); |
184 | wxFprintf(Subsubsections, _T("}\n\n")); | |
9a29912f | 185 | SetCurrentOutput(Subsubsections); |
6c155d33 | 186 | wxChar *topicName = FindTopicName(GetNextChunk()); |
9a29912f JS |
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(); | |
6c155d33 | 199 | wxFprintf(Subsections, _T("\\hy-%d{%ld}{"), hyBLOCK_BOLD, id); |
9a29912f JS |
200 | } |
201 | else | |
6c155d33 | 202 | wxFprintf(Subsections, _T("}")); |
9a29912f JS |
203 | break; |
204 | } | |
205 | case ltVOID: | |
206 | // if (start) | |
b63b07a8 | 207 | // TexOutput(_T("void"), true); |
9a29912f JS |
208 | break; |
209 | case ltBACKSLASHCHAR: | |
210 | if (start) | |
b63b07a8 | 211 | TexOutput(_T("\n"), true); |
9a29912f JS |
212 | break; |
213 | case ltPAR: | |
214 | { | |
215 | if (start) | |
216 | { | |
217 | if (ParSkip > 0) | |
b63b07a8 RL |
218 | TexOutput(_T("\n"), true); |
219 | TexOutput(_T("\n"), true); | |
9a29912f JS |
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 | { | |
6c155d33 | 235 | wxChar buf[100]; |
9a29912f | 236 | long id = NewBlockId(); |
b63b07a8 | 237 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_BOLD, id); |
9a29912f JS |
238 | TexOutput(buf); |
239 | } | |
6c155d33 | 240 | else TexOutput(_T("}")); |
9a29912f JS |
241 | break; |
242 | } | |
243 | case ltTEXTIT: | |
244 | case ltITSHAPE: | |
245 | case ltIT: | |
246 | { | |
247 | if (start) | |
248 | { | |
6c155d33 | 249 | wxChar buf[100]; |
9a29912f | 250 | long id = NewBlockId(); |
b63b07a8 | 251 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_ITALIC, id); |
9a29912f JS |
252 | TexOutput(buf); |
253 | } | |
6c155d33 | 254 | else TexOutput(_T("}")); |
9a29912f JS |
255 | break; |
256 | } | |
257 | case ltTTFAMILY: | |
258 | case ltTEXTTT: | |
259 | case ltTT: | |
260 | { | |
261 | if (start) | |
262 | { | |
263 | long id = NewBlockId(); | |
b63b07a8 | 264 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_TELETYPE, id); |
9a29912f JS |
265 | TexOutput(buf); |
266 | } | |
6c155d33 | 267 | else TexOutput(_T("}")); |
9a29912f JS |
268 | break; |
269 | } | |
270 | case ltSMALL: | |
271 | { | |
272 | if (start) | |
273 | { | |
b63b07a8 | 274 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_SMALL_TEXT, NewBlockId()); |
9a29912f JS |
275 | TexOutput(buf); |
276 | } | |
6c155d33 | 277 | else TexOutput(_T("}")); |
9a29912f JS |
278 | break; |
279 | } | |
280 | case ltTINY: | |
281 | { | |
282 | if (start) | |
283 | { | |
b63b07a8 | 284 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_SMALL_TEXT, NewBlockId()); |
9a29912f JS |
285 | TexOutput(buf); |
286 | } | |
6c155d33 | 287 | else TexOutput(_T("}")); |
9a29912f JS |
288 | break; |
289 | } | |
290 | case ltNORMALSIZE: | |
291 | { | |
292 | if (start) | |
293 | { | |
b63b07a8 | 294 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_NORMAL, NewBlockId()); |
9a29912f JS |
295 | TexOutput(buf); |
296 | } | |
6c155d33 | 297 | else TexOutput(_T("}")); |
9a29912f JS |
298 | break; |
299 | } | |
300 | case ltlarge: | |
301 | { | |
302 | if (start) | |
303 | { | |
b63b07a8 | 304 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_SMALL_HEADING, NewBlockId()); |
9a29912f JS |
305 | TexOutput(buf); |
306 | } | |
6c155d33 | 307 | else TexOutput(_T("}\n")); |
9a29912f JS |
308 | break; |
309 | } | |
310 | case ltLARGE: | |
311 | { | |
312 | if (start) | |
313 | { | |
b63b07a8 | 314 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_LARGE_HEADING, NewBlockId()); |
9a29912f JS |
315 | TexOutput(buf); |
316 | } | |
6c155d33 | 317 | else TexOutput(_T("}\n")); |
9a29912f JS |
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) | |
6c155d33 | 330 | // TexOutput(_T("\\par\\par\n")); |
9a29912f JS |
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 | ||
ddc4f3b5 | 346 | if (itemizeStack.GetFirst()) |
9a29912f | 347 | { |
ddc4f3b5 | 348 | ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData(); |
9a29912f | 349 | delete struc; |
ddc4f3b5 | 350 | delete itemizeStack.GetFirst(); |
9a29912f JS |
351 | } |
352 | } | |
353 | break; | |
354 | } | |
355 | case ltITEM: | |
356 | { | |
ddc4f3b5 | 357 | wxNode *node = itemizeStack.GetFirst(); |
9a29912f JS |
358 | if (node) |
359 | { | |
ddc4f3b5 | 360 | ItemizeStruc *struc = (ItemizeStruc *)node->GetData(); |
9a29912f JS |
361 | if (!start) |
362 | { | |
363 | struc->currentItem += 1; | |
6c155d33 | 364 | wxChar indentBuf[30]; |
9a29912f JS |
365 | |
366 | switch (struc->listType) | |
367 | { | |
368 | case LATEX_ENUMERATE: | |
369 | { | |
b63b07a8 | 370 | wxSnprintf(indentBuf, sizeof(indentBuf), _T("\\hy-%d{%ld}{%d.} "), |
9a29912f JS |
371 | hyBLOCK_BOLD, NewBlockId(), struc->currentItem); |
372 | TexOutput(indentBuf); | |
373 | break; | |
374 | } | |
375 | case LATEX_ITEMIZE: | |
376 | { | |
b63b07a8 | 377 | wxSnprintf(indentBuf, sizeof(indentBuf), _T("\\hy-%d{%ld}{o} "), |
9a29912f JS |
378 | hyBLOCK_BOLD, NewBlockId()); |
379 | TexOutput(indentBuf); | |
380 | break; | |
381 | } | |
382 | default: | |
383 | case LATEX_DESCRIPTION: | |
384 | { | |
385 | if (descriptionItemArg) | |
386 | { | |
b63b07a8 | 387 | wxSnprintf(indentBuf, sizeof(indentBuf), _T("\\hy-%d{%ld}{"), |
9a29912f JS |
388 | hyBLOCK_BOLD, NewBlockId()); |
389 | TexOutput(indentBuf); | |
390 | TraverseChildrenFromChunk(descriptionItemArg); | |
6c155d33 | 391 | TexOutput(_T("} ")); |
9a29912f JS |
392 | descriptionItemArg = NULL; |
393 | } | |
394 | break; | |
395 | } | |
4fe30bce | 396 | } |
9a29912f JS |
397 | } |
398 | } | |
399 | break; | |
400 | } | |
401 | case ltMAKETITLE: | |
402 | { | |
403 | if (start && DocumentTitle && DocumentAuthor) | |
404 | { | |
b63b07a8 | 405 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_LARGE_HEADING, NewBlockId()); |
9a29912f JS |
406 | TexOutput(buf); |
407 | TraverseChildrenFromChunk(DocumentTitle); | |
6c155d33 | 408 | TexOutput(_T("}\n\n")); |
b63b07a8 | 409 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_SMALL_HEADING, NewBlockId()); |
9a29912f JS |
410 | TexOutput(buf); |
411 | TraverseChildrenFromChunk(DocumentAuthor); | |
6c155d33 | 412 | TexOutput(_T("}\n\n")); |
9a29912f JS |
413 | if (DocumentDate) |
414 | { | |
415 | TraverseChildrenFromChunk(DocumentDate); | |
6c155d33 | 416 | TexOutput(_T("\n")); |
9a29912f JS |
417 | } |
418 | } | |
419 | break; | |
420 | } | |
421 | case ltTABLEOFCONTENTS: | |
422 | { | |
423 | if (start) | |
424 | { | |
6c155d33 | 425 | FILE *fd = wxFopen(ContentsName, _T("r")); |
9a29912f JS |
426 | if (fd) |
427 | { | |
428 | int ch = getc(fd); | |
429 | while (ch != EOF) | |
430 | { | |
7f997541 | 431 | wxPutc(ch, Chapters); |
9a29912f JS |
432 | ch = getc(fd); |
433 | } | |
434 | fclose(fd); | |
435 | } | |
436 | else | |
437 | { | |
6c155d33 JS |
438 | TexOutput(_T("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n")); |
439 | OnInform(_T("Run Tex2RTF again to include contents page.")); | |
9a29912f JS |
440 | } |
441 | } | |
442 | break; | |
443 | } | |
444 | case ltHARDY: | |
445 | { | |
446 | if (start) | |
b63b07a8 | 447 | TexOutput(_T("HARDY"), true); |
9a29912f JS |
448 | break; |
449 | } | |
450 | case ltWXCLIPS: | |
451 | { | |
452 | if (start) | |
b63b07a8 | 453 | TexOutput(_T("wxCLIPS"), true); |
9a29912f JS |
454 | break; |
455 | } | |
456 | case ltVERBATIM: | |
457 | { | |
458 | if (start) | |
459 | { | |
6c155d33 | 460 | wxChar buf[100]; |
9a29912f | 461 | long id = NewBlockId(); |
b63b07a8 | 462 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_TELETYPE, id); |
9a29912f JS |
463 | TexOutput(buf); |
464 | } | |
6c155d33 | 465 | else TexOutput(_T("}")); |
9a29912f JS |
466 | break; |
467 | } | |
468 | case ltHRULE: | |
469 | { | |
470 | if (start) | |
471 | { | |
b63b07a8 | 472 | TexOutput(_T("\n------------------------------------------------------------------"), true); |
9a29912f JS |
473 | } |
474 | break; | |
475 | } | |
476 | case ltHLINE: | |
477 | { | |
478 | if (start) | |
479 | { | |
b63b07a8 | 480 | TexOutput(_T("--------------------------------------------------------------------------------"), true); |
9a29912f JS |
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 | { | |
b63b07a8 | 499 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_TELETYPE, NewBlockId()); |
9a29912f JS |
500 | TexOutput(buf); |
501 | } | |
502 | else | |
6c155d33 | 503 | TexOutput(_T("}")); |
9a29912f JS |
504 | break; |
505 | } | |
506 | case ltNUMBEREDBIBITEM: | |
507 | { | |
508 | if (!start) | |
b63b07a8 | 509 | TexOutput(_T("\n\n"), true); |
9a29912f JS |
510 | break; |
511 | } | |
512 | case ltCAPTION: | |
513 | case ltCAPTIONSTAR: | |
514 | { | |
515 | if (start) | |
516 | { | |
517 | figureNo ++; | |
518 | ||
6c155d33 | 519 | wxChar figBuf[40]; |
9a29912f | 520 | if (DocumentStyle != LATEX_ARTICLE) |
b63b07a8 | 521 | wxSnprintf(figBuf, sizeof(figBuf), _T("Figure %d.%d: "), chapterNo, figureNo); |
9a29912f | 522 | else |
b63b07a8 | 523 | wxSnprintf(figBuf, sizeof(figBuf), _T("Figure %d: "), figureNo); |
9a29912f JS |
524 | |
525 | TexOutput(figBuf); | |
526 | } | |
527 | else | |
528 | { | |
6c155d33 | 529 | wxChar *topicName = FindTopicName(GetNextChunk()); |
9a29912f JS |
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 | { | |
6c155d33 | 547 | wxChar buf[300]; |
9a29912f JS |
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(); | |
b63b07a8 | 566 | return false; |
9a29912f JS |
567 | } |
568 | case ltFUNC: | |
569 | { | |
570 | if (!start && (arg_no == 1)) | |
b63b07a8 | 571 | TexOutput(_T(" "), true); |
9a29912f | 572 | if (start && (arg_no == 3)) |
b63b07a8 | 573 | TexOutput(_T("("), true); |
9a29912f | 574 | if (!start && (arg_no == 3)) |
b63b07a8 | 575 | TexOutput(_T(")"), true); |
9a29912f JS |
576 | break; |
577 | } | |
578 | case ltPFUNC: | |
579 | { | |
580 | if (!start && (arg_no == 1)) | |
b63b07a8 | 581 | TexOutput(_T(" "), true); |
9a29912f JS |
582 | |
583 | if (start && (arg_no == 2)) | |
b63b07a8 | 584 | TexOutput(_T("(*"), true); |
9a29912f | 585 | if (!start && (arg_no == 2)) |
b63b07a8 | 586 | TexOutput(_T(")"), true); |
9a29912f JS |
587 | |
588 | if (start && (arg_no == 3)) | |
b63b07a8 | 589 | TexOutput(_T("("), true); |
9a29912f | 590 | if (!start && (arg_no == 3)) |
b63b07a8 | 591 | TexOutput(_T(")"), true); |
9a29912f JS |
592 | break; |
593 | } | |
594 | case ltCLIPSFUNC: | |
595 | { | |
596 | if (!start && (arg_no == 1)) | |
b63b07a8 | 597 | TexOutput(_T(" "), true); |
9a29912f JS |
598 | if (start && (arg_no == 2)) |
599 | { | |
b63b07a8 | 600 | TexOutput(_T("("), true); |
9a29912f | 601 | long id = NewBlockId(); |
b63b07a8 | 602 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_BOLD, id); |
9a29912f JS |
603 | TexOutput(buf); |
604 | } | |
605 | if (!start && (arg_no == 2)) | |
606 | { | |
6c155d33 | 607 | TexOutput(_T("}")); |
9a29912f JS |
608 | } |
609 | if (!start && (arg_no == 3)) | |
b63b07a8 | 610 | TexOutput(_T(")"), true); |
9a29912f JS |
611 | break; |
612 | } | |
613 | case ltPARAM: | |
614 | { | |
615 | if (start && (arg_no == 2)) | |
616 | { | |
617 | long id = NewBlockId(); | |
b63b07a8 | 618 | wxSnprintf(buf, sizeof(buf), _T(" \\hy-%d{%ld}{"), hyBLOCK_BOLD, id); |
9a29912f JS |
619 | TexOutput(buf); |
620 | } | |
621 | if (!start && (arg_no == 2)) | |
622 | { | |
6c155d33 | 623 | TexOutput(_T("}")); |
9a29912f JS |
624 | } |
625 | break; | |
626 | } | |
627 | case ltCPARAM: | |
628 | { | |
629 | if (start && (arg_no == 2)) | |
630 | { | |
631 | long id = NewBlockId(); | |
b63b07a8 | 632 | wxSnprintf(buf, sizeof(buf), _T(" \\hy-%d{%ld}{"), hyBLOCK_BOLD, id); |
9a29912f JS |
633 | TexOutput(buf); |
634 | } | |
635 | if (!start && (arg_no == 2)) | |
636 | { | |
6c155d33 | 637 | TexOutput(_T("}")); |
9a29912f JS |
638 | } |
639 | break; | |
640 | } | |
641 | case ltMEMBER: | |
642 | { | |
643 | if (!start && (arg_no == 1)) | |
b63b07a8 | 644 | TexOutput(_T(" "), true); |
9a29912f JS |
645 | break; |
646 | } | |
647 | case ltLABEL: | |
648 | { | |
b63b07a8 | 649 | return false; |
9a29912f JS |
650 | } |
651 | case ltREF: | |
652 | { | |
653 | if (start) | |
654 | { | |
6c155d33 | 655 | wxChar *sec = NULL; |
5c66e5b2 | 656 | |
6c155d33 | 657 | wxChar *refName = GetArgData(); |
9a29912f JS |
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 | } | |
b63b07a8 | 670 | return false; |
9a29912f JS |
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(); | |
b63b07a8 | 683 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{"), hyBLOCK_RED_ITALIC, currentBlockId); |
9a29912f JS |
684 | TexOutput(buf); |
685 | } | |
6c155d33 | 686 | else TexOutput(_T("}")); |
9a29912f JS |
687 | } |
688 | if (arg_no == 2) | |
689 | { | |
690 | if (start) | |
691 | { | |
6c155d33 | 692 | wxChar *label = GetArgData(); |
9a29912f JS |
693 | hyperLinks.Append(currentBlockId, (wxObject *)copystring(label)); |
694 | } | |
5c66e5b2 | 695 | |
b63b07a8 | 696 | return false; |
9a29912f JS |
697 | } |
698 | break; | |
699 | } | |
700 | case ltURLREF: | |
701 | { | |
702 | if (arg_no == 1) | |
703 | { | |
b63b07a8 | 704 | return true; |
9a29912f JS |
705 | } |
706 | else if (arg_no == 2) | |
707 | { | |
708 | if (start) | |
6c155d33 | 709 | TexOutput(_T(" (")); |
9a29912f | 710 | else |
6c155d33 | 711 | TexOutput(_T(")")); |
b63b07a8 | 712 | return true; |
9a29912f JS |
713 | } |
714 | break; | |
715 | } | |
716 | case ltITEM: | |
717 | { | |
718 | if (start && IsArgOptional()) | |
719 | { | |
720 | descriptionItemArg = GetArgChunk(); | |
b63b07a8 | 721 | return false; |
9a29912f JS |
722 | } |
723 | break; | |
724 | } | |
725 | case ltTABULAR: | |
726 | case ltSUPERTABULAR: | |
727 | { | |
728 | if (arg_no == 1) | |
729 | { | |
730 | if (start) | |
731 | { | |
b63b07a8 RL |
732 | inTable = true; |
733 | tableVerticalLineLeft = false; | |
734 | tableVerticalLineRight = false; | |
9a29912f | 735 | |
6c155d33 | 736 | wxChar *alignString = copystring(GetArgData()); |
9a29912f JS |
737 | |
738 | // Count the number of columns | |
739 | noColumns = 0; | |
6c155d33 | 740 | int len = wxStrlen(alignString); |
9a29912f JS |
741 | if (len > 0) |
742 | { | |
743 | if (alignString[0] == '|') | |
b63b07a8 | 744 | tableVerticalLineLeft = true; |
9a29912f | 745 | if (alignString[len-1] == '|') |
b63b07a8 | 746 | tableVerticalLineRight = true; |
9a29912f JS |
747 | } |
748 | ||
749 | for (int i = 0; i < len; i++) | |
750 | if (isalpha(alignString[i])) | |
751 | noColumns ++; | |
752 | ||
753 | /* | |
754 | // Experimental | |
6c155d33 | 755 | TexOutput(_T("\\brdrt\\brdrs")); |
9a29912f | 756 | if (tableVerticalLineLeft) |
6c155d33 | 757 | TexOutput(_T("\\brdrl\\brdrs")); |
9a29912f | 758 | if (tableVerticalLineRight) |
6c155d33 | 759 | TexOutput(_T("\\brdrr\\brdrs")); |
9a29912f JS |
760 | */ |
761 | ||
762 | // Calculate a rough size for each column | |
763 | // int tabPos = 80/noColumns; | |
764 | currentTab = 0; | |
765 | ||
b63b07a8 | 766 | return false; |
9a29912f JS |
767 | } |
768 | } | |
769 | else if (arg_no == 2 && !start) | |
770 | { | |
b63b07a8 | 771 | inTable = false; |
9a29912f JS |
772 | } |
773 | else if (arg_no == 2 && start) | |
b63b07a8 | 774 | return true; |
9a29912f JS |
775 | break; |
776 | } | |
777 | case ltMARGINPAR: | |
778 | case ltMARGINPAREVEN: | |
779 | case ltMARGINPARODD: | |
780 | case ltNORMALBOX: | |
781 | case ltNORMALBOXD: | |
782 | { | |
783 | if (start) | |
784 | { | |
b63b07a8 RL |
785 | TexOutput(_T("----------------------------------------------------------------------\n"), true); |
786 | return true; | |
9a29912f JS |
787 | } |
788 | else | |
b63b07a8 | 789 | TexOutput(_T("\n----------------------------------------------------------------------\n"), true); |
9a29912f JS |
790 | break; |
791 | } | |
792 | case ltBIBITEM: | |
793 | { | |
6c155d33 | 794 | wxChar buf[100]; |
9a29912f JS |
795 | if (arg_no == 1 && start) |
796 | { | |
6c155d33 | 797 | wxChar *citeKey = GetArgData(); |
9a29912f JS |
798 | TexRef *ref = (TexRef *)TexReferences.Get(citeKey); |
799 | if (ref) | |
800 | { | |
801 | if (ref->sectionNumber) delete[] ref->sectionNumber; | |
b63b07a8 | 802 | wxSnprintf(buf, sizeof(buf), _T("[%d]"), citeCount); |
9a29912f JS |
803 | ref->sectionNumber = copystring(buf); |
804 | } | |
805 | ||
b63b07a8 | 806 | wxSnprintf(buf, sizeof(buf), _T("\\hy-%d{%ld}{[%d]} "), hyBLOCK_BOLD, NewBlockId(), citeCount); |
9a29912f JS |
807 | TexOutput(buf); |
808 | citeCount ++; | |
b63b07a8 | 809 | return false; |
9a29912f | 810 | } |
b63b07a8 | 811 | return true; |
9a29912f JS |
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(); | |
6c155d33 JS |
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); | |
9a29912f JS |
827 | |
828 | SetCurrentOutput(Chapters); | |
b63b07a8 | 829 | return false; |
9a29912f JS |
830 | } |
831 | if (!start && (arg_no == 2)) | |
832 | { | |
833 | } | |
b63b07a8 | 834 | return true; |
9a29912f JS |
835 | } |
836 | case ltTWOCOLITEM: | |
837 | case ltTWOCOLITEMRULED: | |
838 | { | |
839 | if (start && (arg_no == 2)) | |
6c155d33 | 840 | TexOutput(_T("\n ")); |
9a29912f JS |
841 | |
842 | if (!start && (arg_no == 2)) | |
6c155d33 | 843 | TexOutput(_T("\n")); |
b63b07a8 | 844 | return true; |
9a29912f JS |
845 | } |
846 | /* | |
847 | * Accents | |
848 | * | |
849 | */ | |
850 | case ltACCENT_GRAVE: | |
851 | { | |
852 | if (start) | |
853 | { | |
6c155d33 | 854 | wxChar *val = GetArgData(); |
9a29912f JS |
855 | if (val) |
856 | { | |
857 | switch (val[0]) | |
858 | { | |
6c155d33 JS |
859 | case _T('a'): |
860 | TexOutput(_T("a")); | |
9a29912f | 861 | break; |
6c155d33 JS |
862 | case _T('e'): |
863 | TexOutput(_T("e")); | |
9a29912f | 864 | break; |
6c155d33 JS |
865 | case _T('i'): |
866 | TexOutput(_T("i")); | |
9a29912f | 867 | break; |
6c155d33 JS |
868 | case _T('o'): |
869 | TexOutput(_T("o")); | |
9a29912f | 870 | break; |
6c155d33 JS |
871 | case _T('u'): |
872 | TexOutput(_T("u")); | |
9a29912f | 873 | break; |
6c155d33 JS |
874 | case _T('A'): |
875 | TexOutput(_T("a")); | |
9a29912f | 876 | break; |
6c155d33 JS |
877 | case _T('E'): |
878 | TexOutput(_T("E")); | |
9a29912f | 879 | break; |
6c155d33 JS |
880 | case _T('I'): |
881 | TexOutput(_T("I")); | |
9a29912f | 882 | break; |
6c155d33 JS |
883 | case _T('O'): |
884 | TexOutput(_T("O")); | |
9a29912f | 885 | break; |
6c155d33 JS |
886 | case _T('U'): |
887 | TexOutput(_T("U")); | |
9a29912f JS |
888 | break; |
889 | default: | |
890 | break; | |
891 | } | |
892 | } | |
893 | } | |
b63b07a8 | 894 | return false; |
9a29912f JS |
895 | } |
896 | case ltACCENT_ACUTE: | |
897 | { | |
898 | if (start) | |
899 | { | |
6c155d33 | 900 | wxChar *val = GetArgData(); |
9a29912f JS |
901 | if (val) |
902 | { | |
903 | switch (val[0]) | |
904 | { | |
6c155d33 JS |
905 | case _T('a'): |
906 | TexOutput(_T("a")); | |
9a29912f | 907 | break; |
6c155d33 JS |
908 | case _T('e'): |
909 | TexOutput(_T("e")); | |
9a29912f | 910 | break; |
6c155d33 JS |
911 | case _T('i'): |
912 | TexOutput(_T("i")); | |
9a29912f | 913 | break; |
6c155d33 JS |
914 | case _T('o'): |
915 | TexOutput(_T("o")); | |
9a29912f | 916 | break; |
6c155d33 JS |
917 | case _T('u'): |
918 | TexOutput(_T("u")); | |
9a29912f | 919 | break; |
6c155d33 JS |
920 | case _T('y'): |
921 | TexOutput(_T("y")); | |
9a29912f | 922 | break; |
6c155d33 JS |
923 | case _T('A'): |
924 | TexOutput(_T("A")); | |
9a29912f | 925 | break; |
6c155d33 JS |
926 | case _T('E'): |
927 | TexOutput(_T("E")); | |
9a29912f | 928 | break; |
6c155d33 JS |
929 | case _T('I'): |
930 | TexOutput(_T("I")); | |
9a29912f | 931 | break; |
6c155d33 JS |
932 | case _T('O'): |
933 | TexOutput(_T("O")); | |
9a29912f | 934 | break; |
6c155d33 JS |
935 | case _T('U'): |
936 | TexOutput(_T("U")); | |
9a29912f | 937 | break; |
6c155d33 JS |
938 | case _T('Y'): |
939 | TexOutput(_T("Y")); | |
9a29912f JS |
940 | break; |
941 | default: | |
942 | break; | |
943 | } | |
944 | } | |
945 | } | |
b63b07a8 | 946 | return false; |
9a29912f JS |
947 | } |
948 | case ltACCENT_CARET: | |
949 | { | |
950 | if (start) | |
951 | { | |
6c155d33 | 952 | wxChar *val = GetArgData(); |
9a29912f JS |
953 | if (val) |
954 | { | |
955 | switch (val[0]) | |
956 | { | |
6c155d33 JS |
957 | case _T('a'): |
958 | TexOutput(_T("a")); | |
9a29912f | 959 | break; |
6c155d33 JS |
960 | case _T('e'): |
961 | TexOutput(_T("e")); | |
9a29912f | 962 | break; |
6c155d33 JS |
963 | case _T('i'): |
964 | TexOutput(_T("i")); | |
9a29912f | 965 | break; |
6c155d33 JS |
966 | case _T('o'): |
967 | TexOutput(_T("o")); | |
9a29912f | 968 | break; |
6c155d33 JS |
969 | case _T('u'): |
970 | TexOutput(_T("u")); | |
9a29912f | 971 | break; |
6c155d33 JS |
972 | case _T('A'): |
973 | TexOutput(_T("A")); | |
9a29912f | 974 | break; |
6c155d33 JS |
975 | case _T('E'): |
976 | TexOutput(_T("E")); | |
9a29912f | 977 | break; |
6c155d33 JS |
978 | case _T('I'): |
979 | TexOutput(_T("I")); | |
9a29912f | 980 | break; |
6c155d33 JS |
981 | case _T('O'): |
982 | TexOutput(_T("O")); | |
9a29912f | 983 | break; |
6c155d33 JS |
984 | case _T('U'): |
985 | TexOutput(_T("U")); | |
9a29912f JS |
986 | break; |
987 | default: | |
988 | break; | |
989 | } | |
990 | } | |
991 | } | |
b63b07a8 | 992 | return false; |
9a29912f JS |
993 | } |
994 | case ltACCENT_TILDE: | |
995 | { | |
996 | if (start) | |
997 | { | |
6c155d33 | 998 | wxChar *val = GetArgData(); |
9a29912f JS |
999 | if (val) |
1000 | { | |
1001 | switch (val[0]) | |
1002 | { | |
6c155d33 JS |
1003 | case _T('a'): |
1004 | TexOutput(_T("a")); | |
9a29912f | 1005 | break; |
6c155d33 JS |
1006 | case _T(' '): |
1007 | TexOutput(_T("~")); | |
9a29912f | 1008 | break; |
6c155d33 JS |
1009 | case _T('n'): |
1010 | TexOutput(_T("n")); | |
9a29912f | 1011 | break; |
6c155d33 JS |
1012 | case _T('o'): |
1013 | TexOutput(_T("o")); | |
9a29912f | 1014 | break; |
6c155d33 JS |
1015 | case _T('A'): |
1016 | TexOutput(_T("A")); | |
9a29912f | 1017 | break; |
6c155d33 JS |
1018 | case _T('N'): |
1019 | TexOutput(_T("N")); | |
9a29912f | 1020 | break; |
6c155d33 JS |
1021 | case _T('O'): |
1022 | TexOutput(_T("O")); | |
9a29912f JS |
1023 | break; |
1024 | default: | |
1025 | break; | |
1026 | } | |
1027 | } | |
1028 | } | |
b63b07a8 | 1029 | return false; |
9a29912f JS |
1030 | } |
1031 | case ltACCENT_UMLAUT: | |
1032 | { | |
1033 | if (start) | |
1034 | { | |
6c155d33 | 1035 | wxChar *val = GetArgData(); |
9a29912f JS |
1036 | if (val) |
1037 | { | |
1038 | switch (val[0]) | |
1039 | { | |
6c155d33 JS |
1040 | case _T('a'): |
1041 | TexOutput(_T("a")); | |
9a29912f | 1042 | break; |
6c155d33 JS |
1043 | case _T('e'): |
1044 | TexOutput(_T("e")); | |
9a29912f | 1045 | break; |
6c155d33 JS |
1046 | case _T('i'): |
1047 | TexOutput(_T("i")); | |
9a29912f | 1048 | break; |
6c155d33 JS |
1049 | case _T('o'): |
1050 | TexOutput(_T("o")); | |
9a29912f | 1051 | break; |
6c155d33 JS |
1052 | case _T('u'): |
1053 | TexOutput(_T("u")); | |
9a29912f | 1054 | break; |
6c155d33 JS |
1055 | case _T('y'): |
1056 | TexOutput(_T("y")); | |
9a29912f | 1057 | break; |
6c155d33 JS |
1058 | case _T('A'): |
1059 | TexOutput(_T("A")); | |
9a29912f | 1060 | break; |
6c155d33 JS |
1061 | case _T('E'): |
1062 | TexOutput(_T("E")); | |
9a29912f | 1063 | break; |
6c155d33 JS |
1064 | case _T('I'): |
1065 | TexOutput(_T("I")); | |
9a29912f | 1066 | break; |
6c155d33 JS |
1067 | case _T('O'): |
1068 | TexOutput(_T("O")); | |
9a29912f | 1069 | break; |
6c155d33 JS |
1070 | case _T('U'): |
1071 | TexOutput(_T("U")); | |
9a29912f | 1072 | break; |
6c155d33 JS |
1073 | case _T('Y'): |
1074 | TexOutput(_T("Y")); | |
9a29912f JS |
1075 | break; |
1076 | default: | |
1077 | break; | |
1078 | } | |
1079 | } | |
1080 | } | |
b63b07a8 | 1081 | return false; |
9a29912f JS |
1082 | } |
1083 | case ltACCENT_DOT: | |
1084 | { | |
1085 | if (start) | |
1086 | { | |
6c155d33 | 1087 | wxChar *val = GetArgData(); |
9a29912f JS |
1088 | if (val) |
1089 | { | |
1090 | switch (val[0]) | |
1091 | { | |
6c155d33 JS |
1092 | case _T('a'): |
1093 | TexOutput(_T("a")); | |
9a29912f | 1094 | break; |
6c155d33 JS |
1095 | case _T('A'): |
1096 | TexOutput(_T("A")); | |
9a29912f JS |
1097 | break; |
1098 | default: | |
1099 | break; | |
1100 | } | |
1101 | } | |
1102 | } | |
b63b07a8 | 1103 | return false; |
9a29912f JS |
1104 | } |
1105 | case ltACCENT_CADILLA: | |
1106 | { | |
1107 | if (start) | |
1108 | { | |
6c155d33 | 1109 | wxChar *val = GetArgData(); |
9a29912f JS |
1110 | if (val) |
1111 | { | |
1112 | switch (val[0]) | |
1113 | { | |
6c155d33 JS |
1114 | case _T('c'): |
1115 | TexOutput(_T("c")); | |
9a29912f | 1116 | break; |
6c155d33 JS |
1117 | case _T('C'): |
1118 | TexOutput(_T("C")); | |
9a29912f JS |
1119 | break; |
1120 | default: | |
1121 | break; | |
1122 | } | |
1123 | } | |
1124 | } | |
b63b07a8 | 1125 | return false; |
9a29912f JS |
1126 | } |
1127 | default: | |
1128 | { | |
1129 | return DefaultOnArgument(macroId, arg_no, start); | |
9a29912f JS |
1130 | } |
1131 | } | |
b63b07a8 | 1132 | return true; |
9a29912f JS |
1133 | } |
1134 | ||
1135 | bool XLPGo(void) | |
1136 | { | |
1137 | xlpBlockId = 0; | |
1138 | ||
5c66e5b2 | 1139 | if (!InputFile.empty() && !OutputFile.empty()) |
9a29912f | 1140 | { |
6c155d33 JS |
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")); | |
9a29912f JS |
1147 | |
1148 | // Insert invisible section marker at beginning | |
6c155d33 JS |
1149 | wxFprintf(Chapters, _T("\\hy-%d{%ld}{%s}\n"), |
1150 | hyBLOCK_INVISIBLE_SECTION, NewBlockId(), _T("\n")); | |
9a29912f | 1151 | |
6c155d33 | 1152 | wxFprintf(Contents, _T("\\hy-%d{%ld}{%s}\n\n"), |
9a29912f JS |
1153 | // hyBLOCK_LARGE_HEADING, NewBlockId(), "\n\n%s\n\n", ContentsNameString); |
1154 | hyBLOCK_LARGE_HEADING, NewBlockId(), ContentsNameString); | |
1155 | ||
1156 | SetCurrentOutput(Chapters); | |
1157 | ||
6c155d33 JS |
1158 | wxFprintf(Index, _T("\n\\hyindex{\n\"%s\"\n"), |
1159 | contentsString ? contentsString : _T("WXHELPCONTENTS")); | |
9a29912f JS |
1160 | TraverseDocument(); |
1161 | ||
ddc4f3b5 | 1162 | wxNode *node = hyperLinks.GetFirst(); |
9a29912f JS |
1163 | while (node) |
1164 | { | |
1165 | long from = node->GetKeyInteger(); | |
6c155d33 | 1166 | wxChar *label = (wxChar *)node->GetData(); |
9a29912f JS |
1167 | wxNode *otherNode = hyperLabels.Find(label); |
1168 | if (otherNode) | |
1169 | { | |
ddc4f3b5 | 1170 | long to = (long)otherNode->GetData(); |
6c155d33 | 1171 | wxFprintf(Index, _T("%ld %ld\n"), from, to); |
9a29912f | 1172 | } |
ddc4f3b5 | 1173 | node = node->GetNext(); |
9a29912f JS |
1174 | } |
1175 | ||
6c155d33 | 1176 | wxFprintf(Index, _T("}\n")); |
9a29912f JS |
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 | ||
2b5f62a0 | 1185 | if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName); |
9a29912f JS |
1186 | |
1187 | if (!wxRenameFile(TmpContentsName, ContentsName)) | |
1188 | { | |
1189 | wxCopyFile(TmpContentsName, ContentsName); | |
1190 | wxRemoveFile(TmpContentsName); | |
1191 | } | |
1192 | ||
6c155d33 JS |
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); | |
9a29912f | 1197 | |
6c155d33 JS |
1198 | wxRemoveFile(_T("tmp1.xlp")); |
1199 | wxRemoveFile(_T("tmp2.xlp")); | |
9a29912f | 1200 | |
6c155d33 JS |
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")); | |
b63b07a8 | 1206 | return true; |
9a29912f | 1207 | } |
b63b07a8 | 1208 | return false; |
9a29912f | 1209 | } |