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