]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: htmlutil.cpp | |
3 | // Purpose: Converts Latex to HTML | |
4 | // Author: Julian Smart | |
5 | // Modified by: Wlodzimierz ABX Skiba 2003/2004 Unicode support | |
6 | // Ron Lee | |
7 | // Created: 7.9.93 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) Julian Smart | |
10 | // Licence: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // For compilers that support precompilation, includes "wx.h". | |
14 | #include "wx/wxprec.h" | |
15 | ||
16 | #ifdef __BORLANDC__ | |
17 | #pragma hdrstop | |
18 | #endif | |
19 | ||
20 | #ifndef WX_PRECOMP | |
21 | #endif | |
22 | ||
23 | #include "wx/arrstr.h" | |
24 | ||
25 | #include "tex2any.h" | |
26 | #include "tex2rtf.h" | |
27 | #include "table.h" | |
28 | #include <stdio.h> | |
29 | #define HTML_FILENAME_PATTERN _T("%s_%s.html") | |
30 | ||
31 | static inline wxChar* copystring(const wxChar* s) | |
32 | { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); } | |
33 | ||
34 | extern wxHashTable TexReferences; | |
35 | ||
36 | extern int passNumber; | |
37 | ||
38 | extern void DecToHex(int, wxChar *); | |
39 | void GenerateHTMLIndexFile(wxChar *fname); | |
40 | ||
41 | bool PrimaryAnchorOfTheFile( wxChar *file, wxChar *label ); | |
42 | ||
43 | void GenerateHTMLWorkshopFiles(wxChar *fname); | |
44 | void HTMLWorkshopAddToContents(int level, wxChar *s, wxChar *file); | |
45 | void HTMLWorkshopStartContents(); | |
46 | void HTMLWorkshopEndContents(); | |
47 | ||
48 | void OutputContentsFrame(void); | |
49 | ||
50 | #include "readshg.h" // Segmented hypergraphics parsing | |
51 | ||
52 | wxChar *ChaptersName = NULL; | |
53 | wxChar *SectionsName = NULL; | |
54 | wxChar *SubsectionsName = NULL; | |
55 | wxChar *SubsubsectionsName = NULL; | |
56 | wxChar *TitlepageName = NULL; | |
57 | wxChar *lastFileName = NULL; | |
58 | wxChar *lastTopic = NULL; | |
59 | wxChar *currentFileName = NULL; | |
60 | wxChar *contentsFrameName = NULL; | |
61 | ||
62 | static TexChunk *descriptionItemArg = NULL; | |
63 | static TexChunk *helpRefFilename = NULL; | |
64 | static TexChunk *helpRefText = NULL; | |
65 | static int indentLevel = 0; | |
66 | static int citeCount = 1; | |
67 | extern FILE *Contents; | |
68 | FILE *FrameContents = NULL; | |
69 | FILE *Titlepage = NULL; | |
70 | // FILE *FrameTitlepage = NULL; | |
71 | int fileId = 0; | |
72 | bool subsectionStarted = false; | |
73 | ||
74 | // Which column of a row are we in? (Assumes no nested tables, of course) | |
75 | int currentColumn = 0; | |
76 | ||
77 | // Are we in verbatim mode? If so, format differently. | |
78 | static bool inVerbatim = false; | |
79 | ||
80 | // Need to know whether we're in a table or figure for benefit | |
81 | // of listoffigures/listoftables | |
82 | static bool inFigure = false; | |
83 | static bool inTable = false; | |
84 | ||
85 | // This is defined in the Tex2Any library. | |
86 | extern wxChar *BigBuffer; | |
87 | ||
88 | // DHS Two-column table dimensions. | |
89 | static int TwoColWidthA = -1; | |
90 | static int TwoColWidthB = -1; | |
91 | ||
92 | ||
93 | class HyperReference: public wxObject | |
94 | { | |
95 | public: | |
96 | wxChar *refName; | |
97 | wxChar *refFile; | |
98 | HyperReference(wxChar *name, wxChar *file) | |
99 | { | |
100 | if (name) refName = copystring(name); | |
101 | if (file) refFile = copystring(file); | |
102 | } | |
103 | }; | |
104 | ||
105 | class TexNextPage: public wxObject | |
106 | { | |
107 | public: | |
108 | wxChar *label; | |
109 | wxChar *filename; | |
110 | TexNextPage(wxChar *theLabel, wxChar *theFile) | |
111 | { | |
112 | label = copystring(theLabel); | |
113 | filename = copystring(theFile); | |
114 | } | |
115 | virtual ~TexNextPage(void) | |
116 | { | |
117 | delete[] label; | |
118 | delete[] filename; | |
119 | } | |
120 | }; | |
121 | ||
122 | wxHashTable TexNextPages(wxKEY_STRING); | |
123 | ||
124 | static wxChar *CurrentChapterName = NULL; | |
125 | static wxChar *CurrentChapterFile = NULL; | |
126 | static wxChar *CurrentSectionName = NULL; | |
127 | static wxChar *CurrentSectionFile = NULL; | |
128 | static wxChar *CurrentSubsectionName = NULL; | |
129 | static wxChar *CurrentSubsectionFile = NULL; | |
130 | static wxChar *CurrentSubsubsectionName = NULL; | |
131 | static wxChar *CurrentSubsubsectionFile = NULL; | |
132 | static wxChar *CurrentTopic = NULL; | |
133 | ||
134 | static void SetCurrentTopic(wxChar *s) | |
135 | { | |
136 | if (CurrentTopic) delete[] CurrentTopic; | |
137 | CurrentTopic = copystring(s); | |
138 | } | |
139 | ||
140 | void SetCurrentChapterName(wxChar *s, wxChar *file) | |
141 | { | |
142 | if (CurrentChapterName) delete[] CurrentChapterName; | |
143 | CurrentChapterName = copystring(s); | |
144 | if (CurrentChapterFile) delete[] CurrentChapterFile; | |
145 | CurrentChapterFile = copystring(file); | |
146 | ||
147 | currentFileName = CurrentChapterFile; | |
148 | ||
149 | SetCurrentTopic(s); | |
150 | } | |
151 | void SetCurrentSectionName(wxChar *s, wxChar *file) | |
152 | { | |
153 | if (CurrentSectionName) delete[] CurrentSectionName; | |
154 | CurrentSectionName = copystring(s); | |
155 | if (CurrentSectionFile) delete[] CurrentSectionFile; | |
156 | CurrentSectionFile = copystring(file); | |
157 | ||
158 | currentFileName = CurrentSectionFile; | |
159 | SetCurrentTopic(s); | |
160 | } | |
161 | void SetCurrentSubsectionName(wxChar *s, wxChar *file) | |
162 | { | |
163 | if (CurrentSubsectionName) delete[] CurrentSubsectionName; | |
164 | CurrentSubsectionName = copystring(s); | |
165 | if (CurrentSubsectionFile) delete[] CurrentSubsectionFile; | |
166 | CurrentSubsectionFile = copystring(file); | |
167 | currentFileName = CurrentSubsectionFile; | |
168 | SetCurrentTopic(s); | |
169 | } | |
170 | void SetCurrentSubsubsectionName(wxChar *s, wxChar *file) | |
171 | { | |
172 | if (CurrentSubsubsectionName) delete[] CurrentSubsubsectionName; | |
173 | CurrentSubsubsectionName = copystring(s); | |
174 | if (CurrentSubsubsectionFile) delete[] CurrentSubsubsectionFile; | |
175 | CurrentSubsubsectionFile = copystring(file); | |
176 | currentFileName = CurrentSubsubsectionFile; | |
177 | SetCurrentTopic(s); | |
178 | } | |
179 | ||
180 | ||
181 | // mapping between fileId and filenames if truncateFilenames=false: | |
182 | static wxArrayString gs_filenames; | |
183 | ||
184 | ||
185 | /* | |
186 | * Close former filedescriptor and reopen using another filename. | |
187 | * | |
188 | */ | |
189 | ||
190 | void ReopenFile(FILE **fd, wxChar **fileName, const wxChar *label) | |
191 | { | |
192 | if (*fd) | |
193 | { | |
194 | wxFprintf(*fd, _T("\n</FONT></BODY></HTML>\n")); | |
195 | fclose(*fd); | |
196 | } | |
197 | fileId ++; | |
198 | wxChar buf[400]; | |
199 | if (truncateFilenames) | |
200 | { | |
201 | wxSnprintf(buf, sizeof(buf), _T("%s%d.htm"), FileRoot, fileId); | |
202 | } | |
203 | else | |
204 | { | |
205 | if (fileId == 1) | |
206 | gs_filenames.Add(wxEmptyString); | |
207 | wxSnprintf(buf, sizeof(buf), HTML_FILENAME_PATTERN, FileRoot, label); | |
208 | gs_filenames.Add(buf); | |
209 | } | |
210 | if (*fileName) delete[] *fileName; | |
211 | *fileName = copystring(wxFileNameFromPath(buf)); | |
212 | *fd = wxFopen(buf, _T("w")); | |
213 | wxFprintf(*fd, _T("<HTML>\n")); | |
214 | } | |
215 | ||
216 | /* | |
217 | * Reopen section contents file, i.e. the index appended to each section | |
218 | * in subsectionCombine mode | |
219 | */ | |
220 | ||
221 | static wxChar *SectionContentsFilename = NULL; | |
222 | static FILE *SectionContentsFD = NULL; | |
223 | ||
224 | void ReopenSectionContentsFile(void) | |
225 | { | |
226 | if ( SectionContentsFD ) | |
227 | { | |
228 | fclose(SectionContentsFD); | |
229 | } | |
230 | if ( SectionContentsFilename ) | |
231 | delete[] SectionContentsFilename; | |
232 | SectionContentsFD = NULL; | |
233 | SectionContentsFilename = NULL; | |
234 | ||
235 | // Create the name from the current section filename | |
236 | if ( CurrentSectionFile ) | |
237 | { | |
238 | wxChar buf[256]; | |
239 | wxStrcpy(buf, CurrentSectionFile); | |
240 | wxStripExtension(buf); | |
241 | wxStrcat(buf, _T(".con")); | |
242 | SectionContentsFilename = copystring(buf); | |
243 | ||
244 | SectionContentsFD = wxFopen(SectionContentsFilename, _T("w")); | |
245 | } | |
246 | } | |
247 | ||
248 | ||
249 | ||
250 | ||
251 | struct textreplace | |
252 | { | |
253 | wxChar *text; | |
254 | size_t text_length; | |
255 | wxChar *replace; | |
256 | size_t replace_length; | |
257 | }; | |
258 | ||
259 | #define tr(x,y) {x, sizeof(x)-1, y, sizeof(y)-1} | |
260 | ||
261 | static textreplace notverb_array[] = | |
262 | { | |
263 | tr(_T("``"), _T("“")), | |
264 | tr(_T("''"), _T("”")), | |
265 | tr(_T("`"), _T("‘")), | |
266 | tr(_T("'"), _T("’")), | |
267 | tr(_T("---"), _T("—")), | |
268 | tr(_T("--"), _T("–")), | |
269 | }; | |
270 | ||
271 | #undef tr | |
272 | ||
273 | /* | |
274 | * Given a TexChunk with a string value, scans through the string | |
275 | * converting Latex-isms into HTML-isms, such as 2 newlines -> <P>. | |
276 | * | |
277 | */ | |
278 | ||
279 | void ProcessText2HTML(TexChunk *chunk) | |
280 | { | |
281 | bool changed = false; | |
282 | int ptr = 0; | |
283 | int i = 0; | |
284 | wxChar ch = 1; | |
285 | size_t len = wxStrlen(chunk->value); | |
286 | while (ch != 0) | |
287 | { | |
288 | ch = chunk->value[i]; | |
289 | ||
290 | if (ch == _T('<')) // Change < to < | |
291 | { | |
292 | BigBuffer[ptr] = 0; | |
293 | wxStrcat(BigBuffer, _T("<")); | |
294 | ptr += 4; | |
295 | i += 1; | |
296 | len--; | |
297 | changed = true; | |
298 | } | |
299 | else if (ch == _T('>')) // Change > to > | |
300 | { | |
301 | BigBuffer[ptr] = 0; | |
302 | wxStrcat(BigBuffer, _T(">")); | |
303 | ptr += 4; | |
304 | i += 1; | |
305 | len--; | |
306 | changed = true; | |
307 | } | |
308 | else | |
309 | { | |
310 | bool replaced = false; | |
311 | if (!inVerbatim) | |
312 | { | |
313 | for (size_t x = 0; x < WXSIZEOF(notverb_array); x++) | |
314 | { | |
315 | textreplace& tr = notverb_array[x]; | |
316 | if (ch != tr.text[0]) | |
317 | continue; | |
318 | if (len < tr.text_length) | |
319 | continue; | |
320 | ||
321 | size_t y; | |
322 | for (y = 1; y < tr.text_length; y++) | |
323 | { | |
324 | if (chunk->value[y] != tr.text[y]) | |
325 | break; | |
326 | } | |
327 | ||
328 | if (y != tr.text_length) | |
329 | continue; | |
330 | ||
331 | // can now copy it over. | |
332 | for (y = 0; y < tr.replace_length; y++) | |
333 | { | |
334 | BigBuffer[ptr++] = tr.replace[y]; | |
335 | } | |
336 | ||
337 | len -= tr.text_length; | |
338 | i += tr.text_length; | |
339 | replaced = true; | |
340 | changed = true; | |
341 | break; | |
342 | } | |
343 | } | |
344 | ||
345 | if (!replaced) | |
346 | { | |
347 | BigBuffer[ptr] = ch; | |
348 | i ++; | |
349 | ptr ++; | |
350 | len--; | |
351 | } | |
352 | } | |
353 | } | |
354 | BigBuffer[ptr] = 0; | |
355 | ||
356 | if (changed) | |
357 | { | |
358 | delete chunk->value; | |
359 | chunk->value = copystring(BigBuffer); | |
360 | } | |
361 | } | |
362 | ||
363 | /* | |
364 | * Scan through all chunks starting from the given one, | |
365 | * calling ProcessText2HTML to convert Latex-isms to RTF-isms. | |
366 | * This should be called after Tex2Any has parsed the file, | |
367 | * and before TraverseDocument is called. | |
368 | * | |
369 | */ | |
370 | ||
371 | void Text2HTML(TexChunk *chunk) | |
372 | { | |
373 | Tex2RTFYield(); | |
374 | if (stopRunning) return; | |
375 | ||
376 | switch (chunk->type) | |
377 | { | |
378 | case CHUNK_TYPE_MACRO: | |
379 | { | |
380 | TexMacroDef *def = chunk->def; | |
381 | ||
382 | if (def && def->ignore) | |
383 | return; | |
384 | ||
385 | if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB || def->macroId == ltSPECIAL)) | |
386 | inVerbatim = true; | |
387 | ||
388 | wxNode *node = chunk->children.GetFirst(); | |
389 | while (node) | |
390 | { | |
391 | TexChunk *child_chunk = (TexChunk *)node->GetData(); | |
392 | Text2HTML(child_chunk); | |
393 | node = node->GetNext(); | |
394 | } | |
395 | ||
396 | if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB || def->macroId == ltSPECIAL)) | |
397 | inVerbatim = false; | |
398 | ||
399 | break; | |
400 | } | |
401 | case CHUNK_TYPE_ARG: | |
402 | { | |
403 | wxNode *node = chunk->children.GetFirst(); | |
404 | while (node) | |
405 | { | |
406 | TexChunk *child_chunk = (TexChunk *)node->GetData(); | |
407 | Text2HTML(child_chunk); | |
408 | node = node->GetNext(); | |
409 | } | |
410 | ||
411 | break; | |
412 | } | |
413 | case CHUNK_TYPE_STRING: | |
414 | { | |
415 | if (chunk->value) | |
416 | ProcessText2HTML(chunk); | |
417 | break; | |
418 | } | |
419 | } | |
420 | } | |
421 | ||
422 | /* | |
423 | * Add appropriate browse buttons to this page. | |
424 | * | |
425 | */ | |
426 | ||
427 | void AddBrowseButtons(wxChar *upLabel, wxChar *upFilename, | |
428 | wxChar *previousLabel, wxChar *previousFilename, | |
429 | wxChar *thisLabel, wxChar *thisFilename) | |
430 | { | |
431 | wxChar contentsReferenceBuf[80]; | |
432 | wxChar upReferenceBuf[80]; | |
433 | wxChar backReferenceBuf[80]; | |
434 | wxChar forwardReferenceBuf[80]; | |
435 | if (htmlBrowseButtons == HTML_BUTTONS_NONE) | |
436 | return; | |
437 | ||
438 | wxChar *contentsReference; // no need to initialize because always assigned below | |
439 | if (htmlBrowseButtons == HTML_BUTTONS_TEXT) | |
440 | contentsReference = ContentsNameString; | |
441 | else | |
442 | { | |
443 | // contentsReference = "<img align=center src=\"contents.gif\" BORDER=0 ALT=\"Contents\">"; | |
444 | contentsReference = contentsReferenceBuf; | |
445 | wxSnprintf(contentsReference, sizeof(contentsReferenceBuf), | |
446 | _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">"), | |
447 | ConvertCase(_T("contents.gif"))); | |
448 | } | |
449 | ||
450 | wxChar *upReference; // no need to initialize because always assigned below | |
451 | if (htmlBrowseButtons == HTML_BUTTONS_TEXT) | |
452 | upReference = UpNameString; | |
453 | else | |
454 | { | |
455 | // upReference = "<img align=center src=\"up.gif\" ALT=\"Up\">"; | |
456 | upReference = upReferenceBuf; | |
457 | wxSnprintf(upReference, sizeof(upReferenceBuf), | |
458 | _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">"), | |
459 | ConvertCase(_T("up.gif"))); | |
460 | } | |
461 | ||
462 | wxChar *backReference; // no need to initialize because always assigned below | |
463 | if (htmlBrowseButtons == HTML_BUTTONS_TEXT) | |
464 | backReference = _T("<<"); | |
465 | else | |
466 | { | |
467 | // backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">"; | |
468 | backReference = backReferenceBuf; | |
469 | wxSnprintf(backReference, sizeof(backReferenceBuf), | |
470 | _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">"), | |
471 | ConvertCase(_T("back.gif"))); | |
472 | } | |
473 | ||
474 | wxChar *forwardReference; // no need to initialize because always assigned below | |
475 | if (htmlBrowseButtons == HTML_BUTTONS_TEXT) | |
476 | forwardReference = _T(">>"); | |
477 | else | |
478 | { | |
479 | // forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">"; | |
480 | forwardReference = forwardReferenceBuf; | |
481 | wxSnprintf(forwardReference, sizeof(forwardReferenceBuf), | |
482 | _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">"), | |
483 | ConvertCase(_T("forward.gif"))); | |
484 | } | |
485 | ||
486 | TexOutput(_T("<CENTER>")); | |
487 | ||
488 | wxChar buf[200]; | |
489 | ||
490 | /* | |
491 | * Contents button | |
492 | * | |
493 | */ | |
494 | ||
495 | if (truncateFilenames) | |
496 | { | |
497 | wxChar buf1[80]; | |
498 | wxStrcpy(buf1, ConvertCase(wxFileNameFromPath(FileRoot))); | |
499 | wxSnprintf(buf, sizeof(buf), | |
500 | _T("\n<A HREF=\"%s.%s\">%s</A> "), | |
501 | buf1, ConvertCase(_T("htm")), contentsReference); | |
502 | } | |
503 | else | |
504 | { | |
505 | wxChar buf1[80]; | |
506 | wxStrcpy(buf1, ConvertCase(wxFileNameFromPath(FileRoot))); | |
507 | wxSnprintf(buf, sizeof(buf), | |
508 | _T("\n<A HREF=\"%s%s\">%s</A> "), | |
509 | buf1, ConvertCase(_T("_contents.html")), contentsReference); | |
510 | } | |
511 | // TexOutput(_T("<NOFRAMES>")); | |
512 | TexOutput(buf); | |
513 | // TexOutput(_T("</NOFRAMES>")); | |
514 | ||
515 | /* | |
516 | * Up button | |
517 | * | |
518 | */ | |
519 | ||
520 | if (upLabel && upFilename) | |
521 | { | |
522 | if ( (wxStrlen(upLabel) > 0) && !PrimaryAnchorOfTheFile(upFilename, upLabel) ) | |
523 | wxSnprintf(buf, sizeof(buf), | |
524 | _T("<A HREF=\"%s#%s\">%s</A> "), | |
525 | ConvertCase(upFilename), upLabel, upReference); | |
526 | else | |
527 | wxSnprintf(buf, sizeof(buf), | |
528 | _T("<A HREF=\"%s\">%s</A> "), | |
529 | ConvertCase(upFilename), upReference); | |
530 | if (wxStrcmp(upLabel, _T("contents")) == 0) | |
531 | { | |
532 | // TexOutput(_T("<NOFRAMES>")); | |
533 | TexOutput(buf); | |
534 | // TexOutput(_T("</NOFRAMES>")); | |
535 | } | |
536 | else | |
537 | TexOutput(buf); | |
538 | } | |
539 | ||
540 | /* | |
541 | * << button | |
542 | * | |
543 | */ | |
544 | ||
545 | if (previousLabel && previousFilename) | |
546 | { | |
547 | if (PrimaryAnchorOfTheFile(previousFilename, previousLabel)) | |
548 | wxSnprintf(buf, sizeof(buf), | |
549 | _T("<A HREF=\"%s\">%s</A> "), | |
550 | ConvertCase(previousFilename), backReference); | |
551 | else | |
552 | wxSnprintf(buf, sizeof(buf), | |
553 | _T("<A HREF=\"%s#%s\">%s</A> "), | |
554 | ConvertCase(previousFilename), previousLabel, backReference); | |
555 | if (wxStrcmp(previousLabel, _T("contents")) == 0) | |
556 | { | |
557 | // TexOutput(_T("<NOFRAMES>")); | |
558 | TexOutput(buf); | |
559 | // TexOutput(_T("</NOFRAMES>")); | |
560 | } | |
561 | else | |
562 | TexOutput(buf); | |
563 | } | |
564 | else | |
565 | { | |
566 | // A placeholder so the buttons don't keep moving position | |
567 | wxSnprintf(buf, sizeof(buf), _T("%s "), backReference); | |
568 | TexOutput(buf); | |
569 | } | |
570 | ||
571 | wxChar *nextLabel = NULL; | |
572 | wxChar *nextFilename = NULL; | |
573 | ||
574 | // Get the next page, and record the previous page's 'next' page | |
575 | // (i.e. this page) | |
576 | TexNextPage *nextPage = (TexNextPage *)TexNextPages.Get(thisLabel); | |
577 | if (nextPage) | |
578 | { | |
579 | nextLabel = nextPage->label; | |
580 | nextFilename = nextPage->filename; | |
581 | } | |
582 | if (previousLabel && previousFilename) | |
583 | { | |
584 | TexNextPage *oldNextPage = (TexNextPage *)TexNextPages.Get(previousLabel); | |
585 | if (oldNextPage) | |
586 | { | |
587 | delete oldNextPage; | |
588 | TexNextPages.Delete(previousLabel); | |
589 | } | |
590 | TexNextPage *newNextPage = new TexNextPage(thisLabel, thisFilename); | |
591 | TexNextPages.Put(previousLabel, newNextPage); | |
592 | } | |
593 | ||
594 | /* | |
595 | * >> button | |
596 | * | |
597 | */ | |
598 | ||
599 | if (nextLabel && nextFilename) | |
600 | { | |
601 | if (PrimaryAnchorOfTheFile(nextFilename, nextLabel)) | |
602 | wxSnprintf(buf, sizeof(buf), | |
603 | _T("<A HREF=\"%s\">%s</A> "), | |
604 | ConvertCase(nextFilename), forwardReference); | |
605 | else | |
606 | wxSnprintf(buf, sizeof(buf), | |
607 | _T("<A HREF=\"%s#%s\">%s</A> "), | |
608 | ConvertCase(nextFilename), nextLabel, forwardReference); | |
609 | TexOutput(buf); | |
610 | } | |
611 | else | |
612 | { | |
613 | // A placeholder so the buttons don't keep moving position | |
614 | wxSnprintf(buf, sizeof(buf), _T("%s "), forwardReference); | |
615 | TexOutput(buf); | |
616 | } | |
617 | ||
618 | /* | |
619 | * Horizontal rule to finish it off nicely. | |
620 | * | |
621 | */ | |
622 | TexOutput(_T("</CENTER>")); | |
623 | TexOutput(_T("<HR>\n")); | |
624 | ||
625 | // Update last topic/filename | |
626 | if (lastFileName) | |
627 | delete[] lastFileName; | |
628 | lastFileName = copystring(thisFilename); | |
629 | if (lastTopic) | |
630 | delete[] lastTopic; | |
631 | lastTopic = copystring(thisLabel); | |
632 | } | |
633 | ||
634 | // A colour string is either 3 numbers separated by semicolons (RGB), | |
635 | // or a reference to a GIF. Return the filename or a hex string like #934CE8 | |
636 | wxChar *ParseColourString(wxChar *bkStr, bool *isPicture) | |
637 | { | |
638 | static wxChar resStr[300]; | |
639 | wxStrcpy(resStr, bkStr); | |
640 | wxStringTokenizer tok(resStr, _T(";"), wxTOKEN_STRTOK); | |
641 | if (tok.HasMoreTokens()) | |
642 | { | |
643 | wxString token1 = tok.GetNextToken(); | |
644 | if (!tok.HasMoreTokens()) | |
645 | { | |
646 | *isPicture = true; | |
647 | return resStr; | |
648 | } | |
649 | else | |
650 | { | |
651 | wxString token2 = tok.GetNextToken(); | |
652 | *isPicture = false; | |
653 | if (tok.HasMoreTokens()) | |
654 | { | |
655 | wxString token3 = tok.GetNextToken(); | |
656 | ||
657 | // Now convert 3 strings into decimal numbers, and then hex numbers. | |
658 | int red = wxAtoi(token1.c_str()); | |
659 | int green = wxAtoi(token2.c_str()); | |
660 | int blue = wxAtoi(token3.c_str()); | |
661 | ||
662 | wxStrcpy(resStr, _T("#")); | |
663 | ||
664 | wxChar buf[3]; | |
665 | DecToHex(red, buf); | |
666 | wxStrcat(resStr, buf); | |
667 | DecToHex(green, buf); | |
668 | wxStrcat(resStr, buf); | |
669 | DecToHex(blue, buf); | |
670 | wxStrcat(resStr, buf); | |
671 | return resStr; | |
672 | } | |
673 | else return NULL; | |
674 | } | |
675 | } | |
676 | else return NULL; | |
677 | } | |
678 | ||
679 | void OutputFont(void) | |
680 | { | |
681 | // Only output <font face> if explicitly requested by htmlFaceName= directive in | |
682 | // tex2rtf.ini. Otherwise do NOT set the font because we want to use browser's | |
683 | // default font: | |
684 | if (htmlFaceName) | |
685 | { | |
686 | // Output <FONT FACE=...> | |
687 | TexOutput(_T("<FONT FACE=\"")); | |
688 | TexOutput(htmlFaceName); | |
689 | TexOutput(_T("\">\n")); | |
690 | } | |
691 | } | |
692 | ||
693 | // Output start of <BODY> block | |
694 | void OutputBodyStart(void) | |
695 | { | |
696 | TexOutput(_T("\n<BODY")); | |
697 | if (backgroundImageString) | |
698 | { | |
699 | bool isPicture = false; | |
700 | wxChar *s = ParseColourString(backgroundImageString, &isPicture); | |
701 | if (s) | |
702 | { | |
703 | TexOutput(_T(" BACKGROUND=\"")); | |
704 | TexOutput(s); | |
705 | TexOutput(_T("\"")); | |
706 | } | |
707 | } | |
708 | if (backgroundColourString) | |
709 | { | |
710 | bool isPicture = false; | |
711 | wxChar *s = ParseColourString(backgroundColourString, &isPicture); | |
712 | if (s) | |
713 | { | |
714 | TexOutput(_T(" BGCOLOR=")); | |
715 | TexOutput(s); | |
716 | } | |
717 | } | |
718 | ||
719 | // Set foreground text colour, if one is specified | |
720 | if (textColourString) | |
721 | { | |
722 | bool isPicture = false; | |
723 | wxChar *s = ParseColourString(textColourString, &isPicture); | |
724 | if (s) | |
725 | { | |
726 | TexOutput(_T(" TEXT=")); TexOutput(s); | |
727 | } | |
728 | } | |
729 | // Set link text colour, if one is specified | |
730 | if (linkColourString) | |
731 | { | |
732 | bool isPicture = false; | |
733 | wxChar *s = ParseColourString(linkColourString, &isPicture); | |
734 | if (s) | |
735 | { | |
736 | TexOutput(_T(" LINK=")); TexOutput(s); | |
737 | } | |
738 | } | |
739 | // Set followed link text colour, if one is specified | |
740 | if (followedLinkColourString) | |
741 | { | |
742 | bool isPicture = false; | |
743 | wxChar *s = ParseColourString(followedLinkColourString, &isPicture); | |
744 | if (s) | |
745 | { | |
746 | TexOutput(_T(" VLINK=")); TexOutput(s); | |
747 | } | |
748 | } | |
749 | TexOutput(_T(">\n")); | |
750 | ||
751 | OutputFont(); | |
752 | } | |
753 | ||
754 | void HTMLHead() | |
755 | { | |
756 | TexOutput(_T("<head>")); | |
757 | if (htmlStylesheet) { | |
758 | TexOutput(_T("<link rel=stylesheet type=\"text/css\" href=\"")); | |
759 | TexOutput(htmlStylesheet); | |
760 | TexOutput(_T("\">")); | |
761 | } | |
762 | }; | |
763 | ||
764 | void HTMLHeadTo(FILE* f) | |
765 | { | |
766 | if (htmlStylesheet) | |
767 | wxFprintf(f,_T("<head><link rel=stylesheet type=\"text/css\" href=\"%s\">"),htmlStylesheet); | |
768 | else | |
769 | wxFprintf(f,_T("<head>")); | |
770 | } | |
771 | ||
772 | // Called on start/end of macro examination | |
773 | void HTMLOnMacro(int macroId, int no_args, bool start) | |
774 | { | |
775 | switch (macroId) | |
776 | { | |
777 | case ltCHAPTER: | |
778 | case ltCHAPTERSTAR: | |
779 | case ltCHAPTERHEADING: | |
780 | { | |
781 | if (!start) | |
782 | { | |
783 | sectionNo = 0; | |
784 | figureNo = 0; | |
785 | subsectionNo = 0; | |
786 | subsubsectionNo = 0; | |
787 | if (macroId != ltCHAPTERSTAR) | |
788 | chapterNo ++; | |
789 | ||
790 | SetCurrentOutput(NULL); | |
791 | startedSections = true; | |
792 | ||
793 | wxChar *topicName = FindTopicName(GetNextChunk()); | |
794 | ReopenFile(&Chapters, &ChaptersName, topicName); | |
795 | AddTexRef(topicName, ChaptersName, ChapterNameString); | |
796 | ||
797 | SetCurrentChapterName(topicName, ChaptersName); | |
798 | if (htmlWorkshopFiles) HTMLWorkshopAddToContents(0, topicName, ChaptersName); | |
799 | ||
800 | SetCurrentOutput(Chapters); | |
801 | ||
802 | HTMLHead(); | |
803 | TexOutput(_T("<title>")); | |
804 | OutputCurrentSection(); // Repeat section header | |
805 | TexOutput(_T("</title></head>\n")); | |
806 | OutputBodyStart(); | |
807 | ||
808 | wxChar titleBuf[200]; | |
809 | if (truncateFilenames) | |
810 | wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s.htm"), wxFileNameFromPath(FileRoot)); | |
811 | else | |
812 | wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s_contents.html"), wxFileNameFromPath(FileRoot)); | |
813 | ||
814 | wxFprintf(Chapters, _T("<A NAME=\"%s\"></A>"), topicName); | |
815 | ||
816 | AddBrowseButtons(_T(""), titleBuf, // Up | |
817 | lastTopic, lastFileName, // Last topic | |
818 | topicName, ChaptersName); // This topic | |
819 | ||
820 | if(PrimaryAnchorOfTheFile(ChaptersName, topicName)) | |
821 | wxFprintf(Contents, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName)); | |
822 | else | |
823 | wxFprintf(Contents, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName), topicName); | |
824 | ||
825 | if (htmlFrameContents && FrameContents) | |
826 | { | |
827 | SetCurrentOutput(FrameContents); | |
828 | if(PrimaryAnchorOfTheFile(ChaptersName, topicName)) | |
829 | wxFprintf(FrameContents, _T("\n<LI><A HREF=\"%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName)); | |
830 | else | |
831 | wxFprintf(FrameContents, _T("\n<LI><A HREF=\"%s#%s\" TARGET=\"mainwindow\">"), ConvertCase(ChaptersName), topicName); | |
832 | OutputCurrentSection(); | |
833 | wxFprintf(FrameContents, _T("</A>\n")); | |
834 | } | |
835 | ||
836 | SetCurrentOutputs(Contents, Chapters); | |
837 | wxFprintf(Chapters, _T("\n<H2>")); | |
838 | OutputCurrentSection(); | |
839 | wxFprintf(Contents, _T("</A>\n")); | |
840 | wxFprintf(Chapters, _T("</H2>\n")); | |
841 | ||
842 | SetCurrentOutput(Chapters); | |
843 | ||
844 | // Add this section title to the list of keywords | |
845 | if (htmlIndex) | |
846 | { | |
847 | OutputCurrentSectionToString(wxTex2RTFBuffer); | |
848 | AddKeyWordForTopic(topicName, wxTex2RTFBuffer, ConvertCase(currentFileName)); | |
849 | } | |
850 | } | |
851 | break; | |
852 | } | |
853 | case ltSECTION: | |
854 | case ltSECTIONSTAR: | |
855 | case ltSECTIONHEADING: | |
856 | case ltGLOSS: | |
857 | { | |
858 | if (!start) | |
859 | { | |
860 | subsectionNo = 0; | |
861 | subsubsectionNo = 0; | |
862 | subsectionStarted = false; | |
863 | ||
864 | if (macroId != ltSECTIONSTAR) | |
865 | sectionNo ++; | |
866 | ||
867 | SetCurrentOutput(NULL); | |
868 | startedSections = true; | |
869 | ||
870 | wxChar *topicName = FindTopicName(GetNextChunk()); | |
871 | ReopenFile(&Sections, &SectionsName, topicName); | |
872 | AddTexRef(topicName, SectionsName, SectionNameString); | |
873 | ||
874 | SetCurrentSectionName(topicName, SectionsName); | |
875 | if (htmlWorkshopFiles) HTMLWorkshopAddToContents(1, topicName, SectionsName); | |
876 | ||
877 | SetCurrentOutput(Sections); | |
878 | HTMLHead(); | |
879 | TexOutput(_T("<title>")); | |
880 | OutputCurrentSection(); | |
881 | TexOutput(_T("</title></head>\n")); | |
882 | OutputBodyStart(); | |
883 | ||
884 | wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName); | |
885 | AddBrowseButtons(CurrentChapterName, CurrentChapterFile, // Up | |
886 | lastTopic, lastFileName, // Last topic | |
887 | topicName, SectionsName); // This topic | |
888 | ||
889 | FILE *jumpFrom = ((DocumentStyle == LATEX_ARTICLE) ? Contents : Chapters); | |
890 | ||
891 | SetCurrentOutputs(jumpFrom, Sections); | |
892 | if (DocumentStyle == LATEX_ARTICLE) | |
893 | { | |
894 | if(PrimaryAnchorOfTheFile(SectionsName, topicName)) | |
895 | wxFprintf(jumpFrom, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(SectionsName)); | |
896 | else | |
897 | wxFprintf(jumpFrom, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(SectionsName), topicName); | |
898 | } | |
899 | else | |
900 | { | |
901 | if(PrimaryAnchorOfTheFile(SectionsName, topicName)) | |
902 | wxFprintf(jumpFrom, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SectionsName)); | |
903 | else | |
904 | wxFprintf(jumpFrom, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SectionsName), topicName); | |
905 | } | |
906 | ||
907 | wxFprintf(Sections, _T("\n<H2>")); | |
908 | OutputCurrentSection(); | |
909 | ||
910 | if (DocumentStyle == LATEX_ARTICLE) | |
911 | wxFprintf(jumpFrom, _T("</A>\n")); | |
912 | else | |
913 | wxFprintf(jumpFrom, _T("</B></A><BR>\n")); | |
914 | wxFprintf(Sections, _T("</H2>\n")); | |
915 | ||
916 | SetCurrentOutput(Sections); | |
917 | // Add this section title to the list of keywords | |
918 | if (htmlIndex) | |
919 | { | |
920 | OutputCurrentSectionToString(wxTex2RTFBuffer); | |
921 | AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName); | |
922 | } | |
923 | } | |
924 | break; | |
925 | } | |
926 | case ltSUBSECTION: | |
927 | case ltSUBSECTIONSTAR: | |
928 | case ltMEMBERSECTION: | |
929 | case ltFUNCTIONSECTION: | |
930 | { | |
931 | if (!start) | |
932 | { | |
933 | if (!Sections) | |
934 | { | |
935 | OnError(_T("You cannot have a subsection before a section!")); | |
936 | } | |
937 | else | |
938 | { | |
939 | subsubsectionNo = 0; | |
940 | ||
941 | if (macroId != ltSUBSECTIONSTAR) | |
942 | subsectionNo ++; | |
943 | ||
944 | if ( combineSubSections && !subsectionStarted ) | |
945 | { | |
946 | fflush(Sections); | |
947 | ||
948 | // Read old .con file in at this point | |
949 | wxChar buf[256]; | |
950 | wxStrcpy(buf, CurrentSectionFile); | |
951 | wxStripExtension(buf); | |
952 | wxStrcat(buf, _T(".con")); | |
953 | FILE *fd = wxFopen(buf, _T("r")); | |
954 | if ( fd ) | |
955 | { | |
956 | int ch = getc(fd); | |
957 | while (ch != EOF) | |
958 | { | |
959 | wxPutc(ch, Sections); | |
960 | ch = getc(fd); | |
961 | } | |
962 | fclose(fd); | |
963 | } | |
964 | wxFprintf(Sections, _T("<P>\n")); | |
965 | ||
966 | // Close old file, create a new file for the sub(sub)section contents entries | |
967 | ReopenSectionContentsFile(); | |
968 | } | |
969 | ||
970 | startedSections = true; | |
971 | subsectionStarted = true; | |
972 | ||
973 | wxChar *topicName = FindTopicName(GetNextChunk()); | |
974 | ||
975 | if ( !combineSubSections ) | |
976 | { | |
977 | SetCurrentOutput(NULL); | |
978 | ReopenFile(&Subsections, &SubsectionsName, topicName); | |
979 | AddTexRef(topicName, SubsectionsName, SubsectionNameString); | |
980 | SetCurrentSubsectionName(topicName, SubsectionsName); | |
981 | if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SubsectionsName); | |
982 | SetCurrentOutput(Subsections); | |
983 | ||
984 | HTMLHead(); | |
985 | TexOutput(_T("<title>")); | |
986 | OutputCurrentSection(); | |
987 | TexOutput(_T("</title></head>\n")); | |
988 | OutputBodyStart(); | |
989 | ||
990 | wxFprintf(Subsections, _T("<A NAME=\"%s\"></A>"), topicName); | |
991 | AddBrowseButtons(CurrentSectionName, CurrentSectionFile, // Up | |
992 | lastTopic, lastFileName, // Last topic | |
993 | topicName, SubsectionsName); // This topic | |
994 | ||
995 | SetCurrentOutputs(Sections, Subsections); | |
996 | if(PrimaryAnchorOfTheFile(SubsectionsName, topicName)) | |
997 | wxFprintf(Sections, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsectionsName)); | |
998 | else | |
999 | wxFprintf(Sections, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsectionsName), topicName); | |
1000 | ||
1001 | wxFprintf(Subsections, _T("\n<H3>")); | |
1002 | OutputCurrentSection(); | |
1003 | wxFprintf(Sections, _T("</B></A><BR>\n")); | |
1004 | wxFprintf(Subsections, _T("</H3>\n")); | |
1005 | ||
1006 | SetCurrentOutput(Subsections); | |
1007 | } | |
1008 | else | |
1009 | { | |
1010 | AddTexRef(topicName, SectionsName, SubsectionNameString); | |
1011 | SetCurrentSubsectionName(topicName, SectionsName); | |
1012 | ||
1013 | // if ( subsectionNo != 0 ) | |
1014 | wxFprintf(Sections, _T("\n<HR>\n")); | |
1015 | ||
1016 | // We're putting everything into the section file | |
1017 | wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName); | |
1018 | wxFprintf(Sections, _T("\n<H3>")); | |
1019 | OutputCurrentSection(); | |
1020 | wxFprintf(Sections, _T("</H3>\n")); | |
1021 | ||
1022 | SetCurrentOutput(SectionContentsFD); | |
1023 | wxFprintf(SectionContentsFD, _T("<A HREF=\"#%s\">"), topicName); | |
1024 | OutputCurrentSection(); | |
1025 | TexOutput(_T("</A><BR>\n")); | |
1026 | ||
1027 | if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName); | |
1028 | SetCurrentOutput(Sections); | |
1029 | } | |
1030 | // Add this section title to the list of keywords | |
1031 | if (htmlIndex) | |
1032 | { | |
1033 | OutputCurrentSectionToString(wxTex2RTFBuffer); | |
1034 | AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName); | |
1035 | } | |
1036 | ||
1037 | } | |
1038 | } | |
1039 | break; | |
1040 | } | |
1041 | case ltSUBSUBSECTION: | |
1042 | case ltSUBSUBSECTIONSTAR: | |
1043 | { | |
1044 | if (!start) | |
1045 | { | |
1046 | if (!Subsections && !combineSubSections) | |
1047 | { | |
1048 | OnError(_T("You cannot have a subsubsection before a subsection!")); | |
1049 | } | |
1050 | else | |
1051 | { | |
1052 | if (macroId != ltSUBSUBSECTIONSTAR) | |
1053 | subsubsectionNo ++; | |
1054 | ||
1055 | startedSections = true; | |
1056 | ||
1057 | wxChar *topicName = FindTopicName(GetNextChunk()); | |
1058 | ||
1059 | if ( !combineSubSections ) | |
1060 | { | |
1061 | SetCurrentOutput(NULL); | |
1062 | ReopenFile(&Subsubsections, &SubsubsectionsName, topicName); | |
1063 | AddTexRef(topicName, SubsubsectionsName, SubsubsectionNameString); | |
1064 | SetCurrentSubsubsectionName(topicName, SubsubsectionsName); | |
1065 | if (htmlWorkshopFiles) HTMLWorkshopAddToContents(3, topicName, SubsubsectionsName); | |
1066 | ||
1067 | SetCurrentOutput(Subsubsections); | |
1068 | HTMLHead(); | |
1069 | TexOutput(_T("<title>")); | |
1070 | OutputCurrentSection(); | |
1071 | TexOutput(_T("</title></head>\n")); | |
1072 | OutputBodyStart(); | |
1073 | ||
1074 | wxFprintf(Subsubsections, _T("<A NAME=\"%s\"></A>"), topicName); | |
1075 | ||
1076 | AddBrowseButtons(CurrentSubsectionName, CurrentSubsectionFile, // Up | |
1077 | lastTopic, lastFileName, // Last topic | |
1078 | topicName, SubsubsectionsName); // This topic | |
1079 | ||
1080 | SetCurrentOutputs(Subsections, Subsubsections); | |
1081 | if(PrimaryAnchorOfTheFile(SubsubsectionsName, topicName)) | |
1082 | wxFprintf(Subsections, _T("\n<A HREF=\"%s\"><B>"), ConvertCase(SubsubsectionsName)); | |
1083 | else | |
1084 | wxFprintf(Subsections, _T("\n<A HREF=\"%s#%s\"><B>"), ConvertCase(SubsubsectionsName), topicName); | |
1085 | ||
1086 | wxFprintf(Subsubsections, _T("\n<H3>")); | |
1087 | OutputCurrentSection(); | |
1088 | wxFprintf(Subsections, _T("</B></A><BR>\n")); | |
1089 | wxFprintf(Subsubsections, _T("</H3>\n")); | |
1090 | } | |
1091 | else | |
1092 | { | |
1093 | AddTexRef(topicName, SectionsName, SubsubsectionNameString); | |
1094 | SetCurrentSubsectionName(topicName, SectionsName); | |
1095 | wxFprintf(Sections, _T("\n<HR>\n")); | |
1096 | ||
1097 | // We're putting everything into the section file | |
1098 | wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName); | |
1099 | wxFprintf(Sections, _T("\n<H3>")); | |
1100 | OutputCurrentSection(); | |
1101 | wxFprintf(Sections, _T("</H3>\n")); | |
1102 | /* TODO: where do we put subsubsection contents entry - indented, with subsection entries? | |
1103 | SetCurrentOutput(SectionContentsFD); | |
1104 | wxFprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName); | |
1105 | OutputCurrentSection(); | |
1106 | TexOutput(_T("</A><BR>")); | |
1107 | */ | |
1108 | if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName); | |
1109 | SetCurrentOutput(Sections); | |
1110 | } | |
1111 | ||
1112 | // Add this section title to the list of keywords | |
1113 | if (htmlIndex) | |
1114 | { | |
1115 | OutputCurrentSectionToString(wxTex2RTFBuffer); | |
1116 | AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName); | |
1117 | } | |
1118 | } | |
1119 | } | |
1120 | break; | |
1121 | } | |
1122 | case ltFUNC: | |
1123 | case ltPFUNC: | |
1124 | { | |
1125 | if ( !combineSubSections ) | |
1126 | SetCurrentOutput(Subsections); | |
1127 | else | |
1128 | SetCurrentOutput(Sections); | |
1129 | if (start) | |
1130 | { | |
1131 | } | |
1132 | else | |
1133 | { | |
1134 | } | |
1135 | break; | |
1136 | } | |
1137 | case ltCLIPSFUNC: | |
1138 | { | |
1139 | if ( !combineSubSections ) | |
1140 | SetCurrentOutput(Subsections); | |
1141 | else | |
1142 | SetCurrentOutput(Sections); | |
1143 | if (start) | |
1144 | { | |
1145 | } | |
1146 | else | |
1147 | { | |
1148 | } | |
1149 | break; | |
1150 | } | |
1151 | case ltMEMBER: | |
1152 | { | |
1153 | if ( !combineSubSections ) | |
1154 | SetCurrentOutput(Subsections); | |
1155 | else | |
1156 | SetCurrentOutput(Sections); | |
1157 | if (start) | |
1158 | { | |
1159 | } | |
1160 | else | |
1161 | { | |
1162 | } | |
1163 | break; | |
1164 | } | |
1165 | case ltVOID: | |
1166 | // if (start) | |
1167 | // TexOutput(_T("<B>void</B>")); | |
1168 | break; | |
1169 | case ltHARDY: | |
1170 | if (start) | |
1171 | TexOutput(_T("HARDY")); | |
1172 | break; | |
1173 | case ltWXCLIPS: | |
1174 | if (start) | |
1175 | TexOutput(_T("wxCLIPS")); | |
1176 | break; | |
1177 | case ltAMPERSAND: | |
1178 | if (start) | |
1179 | TexOutput(_T("&")); | |
1180 | break; | |
1181 | case ltSPECIALAMPERSAND: | |
1182 | { | |
1183 | if (start) | |
1184 | { | |
1185 | if (inTabular) | |
1186 | { | |
1187 | // End cell, start cell | |
1188 | ||
1189 | TexOutput(_T("</FONT></TD>")); | |
1190 | ||
1191 | // Start new row and cell, setting alignment for the first cell. | |
1192 | if (currentColumn < noColumns) | |
1193 | currentColumn ++; | |
1194 | ||
1195 | wxChar buf[100]; | |
1196 | if (TableData[currentColumn].justification == 'c') | |
1197 | wxSnprintf(buf, sizeof(buf), _T("\n<TD ALIGN=CENTER>")); | |
1198 | else if (TableData[currentColumn].justification == 'r') | |
1199 | wxSnprintf(buf, sizeof(buf), _T("\n<TD ALIGN=RIGHT>")); | |
1200 | else if (TableData[currentColumn].absWidth) | |
1201 | { | |
1202 | // Convert from points * 20 into pixels. | |
1203 | int points = TableData[currentColumn].width / 20; | |
1204 | ||
1205 | // Say the display is 100 DPI (dots/pixels per inch). | |
1206 | // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots. | |
1207 | int pixels = (int)(points * 100.0 / 72.0); | |
1208 | wxSnprintf(buf, sizeof(buf), _T("<TD ALIGN=CENTER WIDTH=%d>"), pixels); | |
1209 | } | |
1210 | else | |
1211 | wxSnprintf(buf, sizeof(buf), _T("\n<TD ALIGN=LEFT>")); | |
1212 | TexOutput(buf); | |
1213 | OutputFont(); | |
1214 | } | |
1215 | else | |
1216 | TexOutput(_T("&")); | |
1217 | } | |
1218 | break; | |
1219 | } | |
1220 | case ltBACKSLASHCHAR: | |
1221 | { | |
1222 | if (start) | |
1223 | { | |
1224 | if (inTabular) | |
1225 | { | |
1226 | // End row. In fact, tables without use of \row or \ruledrow isn't supported for | |
1227 | // HTML: the syntax is too different (e.g. how do we know where to put the first </TH> | |
1228 | // if we've ended the last row?). So normally you wouldn't use \\ to end a row. | |
1229 | TexOutput(_T("</TR>\n")); | |
1230 | } | |
1231 | else | |
1232 | TexOutput(_T("<BR>\n")); | |
1233 | } | |
1234 | break; | |
1235 | } | |
1236 | case ltROW: | |
1237 | case ltRULEDROW: | |
1238 | { | |
1239 | if (start) | |
1240 | { | |
1241 | currentColumn = 0; | |
1242 | ||
1243 | // Start new row and cell, setting alignment for the first cell. | |
1244 | wxChar buf[100]; | |
1245 | if (TableData[currentColumn].justification == 'c') | |
1246 | wxSnprintf(buf, sizeof(buf), _T("<TR>\n<TD ALIGN=CENTER>")); | |
1247 | else if (TableData[currentColumn].justification == 'r') | |
1248 | wxSnprintf(buf, sizeof(buf), _T("<TR>\n<TD ALIGN=RIGHT>")); | |
1249 | else if (TableData[currentColumn].absWidth) | |
1250 | { | |
1251 | // Convert from points * 20 into pixels. | |
1252 | int points = TableData[currentColumn].width / 20; | |
1253 | ||
1254 | // Say the display is 100 DPI (dots/pixels per inch). | |
1255 | // There are 72 pts to the inch. So 1pt = 1/72 inch, or 100 * 1/72 dots. | |
1256 | int pixels = (int)(points * 100.0 / 72.0); | |
1257 | wxSnprintf(buf, sizeof(buf), _T("<TR>\n<TD ALIGN=CENTER WIDTH=%d>"), pixels); | |
1258 | } | |
1259 | else | |
1260 | wxSnprintf(buf, sizeof(buf), _T("<TR>\n<TD ALIGN=LEFT>")); | |
1261 | TexOutput(buf); | |
1262 | OutputFont(); | |
1263 | } | |
1264 | else | |
1265 | { | |
1266 | // End cell and row | |
1267 | // Start new row and cell | |
1268 | TexOutput(_T("</FONT></TD>\n</TR>\n")); | |
1269 | } | |
1270 | break; | |
1271 | } | |
1272 | // HTML-only: break until the end of the picture (both margins are clear). | |
1273 | case ltBRCLEAR: | |
1274 | { | |
1275 | if (start) | |
1276 | TexOutput(_T("<BR CLEAR=ALL>")); | |
1277 | break; | |
1278 | } | |
1279 | case ltRTFSP: // Explicit space, RTF only | |
1280 | break; | |
1281 | case ltSPECIALTILDE: | |
1282 | { | |
1283 | if (start) | |
1284 | { | |
1285 | #if (1) // if(inVerbatim) | |
1286 | TexOutput(_T("~")); | |
1287 | #else | |
1288 | TexOutput(_T(" ")); | |
1289 | #endif | |
1290 | } | |
1291 | break; | |
1292 | } | |
1293 | case ltINDENTED : | |
1294 | { | |
1295 | if ( start ) | |
1296 | TexOutput(_T("<UL><UL>\n")); | |
1297 | else | |
1298 | TexOutput(_T("</UL></UL>\n")); | |
1299 | break; | |
1300 | } | |
1301 | case ltITEMIZE: | |
1302 | case ltENUMERATE: | |
1303 | case ltDESCRIPTION: | |
1304 | // case ltTWOCOLLIST: | |
1305 | { | |
1306 | if (start) | |
1307 | { | |
1308 | indentLevel ++; | |
1309 | ||
1310 | int listType; | |
1311 | if (macroId == ltENUMERATE) | |
1312 | listType = LATEX_ENUMERATE; | |
1313 | else if (macroId == ltITEMIZE) | |
1314 | listType = LATEX_ITEMIZE; | |
1315 | else | |
1316 | listType = LATEX_DESCRIPTION; | |
1317 | ||
1318 | itemizeStack.Insert(new ItemizeStruc(listType)); | |
1319 | switch (listType) | |
1320 | { | |
1321 | case LATEX_ITEMIZE: | |
1322 | TexOutput(_T("<UL>\n")); | |
1323 | break; | |
1324 | case LATEX_ENUMERATE: | |
1325 | TexOutput(_T("<OL>\n")); | |
1326 | break; | |
1327 | case LATEX_DESCRIPTION: | |
1328 | default: | |
1329 | TexOutput(_T("<DL>\n")); | |
1330 | break; | |
1331 | } | |
1332 | } | |
1333 | else | |
1334 | { | |
1335 | indentLevel --; | |
1336 | if (itemizeStack.GetFirst()) | |
1337 | { | |
1338 | ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData(); | |
1339 | switch (struc->listType) | |
1340 | { | |
1341 | case LATEX_ITEMIZE: | |
1342 | TexOutput(_T("</UL>\n")); | |
1343 | break; | |
1344 | case LATEX_ENUMERATE: | |
1345 | TexOutput(_T("</OL>\n")); | |
1346 | break; | |
1347 | case LATEX_DESCRIPTION: | |
1348 | default: | |
1349 | TexOutput(_T("</DL>\n")); | |
1350 | break; | |
1351 | } | |
1352 | ||
1353 | delete struc; | |
1354 | delete itemizeStack.GetFirst(); | |
1355 | } | |
1356 | } | |
1357 | break; | |
1358 | } | |
1359 | case ltTWOCOLLIST : | |
1360 | { | |
1361 | if ( start ) | |
1362 | TexOutput(_T("\n<TABLE>\n")); | |
1363 | else { | |
1364 | TexOutput(_T("\n</TABLE>\n")); | |
1365 | // DHS | |
1366 | TwoColWidthA = -1; | |
1367 | TwoColWidthB = -1; | |
1368 | } | |
1369 | break; | |
1370 | } | |
1371 | case ltPAR: | |
1372 | { | |
1373 | if (start) | |
1374 | TexOutput(_T("<P>\n")); | |
1375 | break; | |
1376 | } | |
1377 | /* For footnotes we need to output the text at the bottom of the page and | |
1378 | * insert a reference to it. Is it worth the trouble... | |
1379 | case ltFOOTNOTE: | |
1380 | case ltFOOTNOTEPOPUP: | |
1381 | { | |
1382 | if (start) | |
1383 | { | |
1384 | TexOutput(_T("<FN>")); | |
1385 | } | |
1386 | else TexOutput(_T("</FN>")); | |
1387 | break; | |
1388 | } | |
1389 | */ | |
1390 | case ltVERB: | |
1391 | { | |
1392 | if (start) | |
1393 | TexOutput(_T("<TT>")); | |
1394 | else TexOutput(_T("</TT>")); | |
1395 | break; | |
1396 | } | |
1397 | case ltVERBATIM: | |
1398 | { | |
1399 | if (start) | |
1400 | { | |
1401 | wxChar buf[100]; | |
1402 | wxSnprintf(buf, sizeof(buf), _T("<PRE>\n")); | |
1403 | TexOutput(buf); | |
1404 | } | |
1405 | else TexOutput(_T("</PRE>\n")); | |
1406 | break; | |
1407 | } | |
1408 | case ltCENTERLINE: | |
1409 | case ltCENTER: | |
1410 | { | |
1411 | if (start) | |
1412 | { | |
1413 | TexOutput(_T("<CENTER>")); | |
1414 | } | |
1415 | else TexOutput(_T("</CENTER>")); | |
1416 | break; | |
1417 | } | |
1418 | case ltFLUSHLEFT: | |
1419 | { | |
1420 | /* | |
1421 | if (start) | |
1422 | { | |
1423 | TexOutput(_T("{\\ql ")); | |
1424 | } | |
1425 | else TexOutput(_T("}\\par\\pard\n")); | |
1426 | */ | |
1427 | break; | |
1428 | } | |
1429 | case ltFLUSHRIGHT: | |
1430 | { | |
1431 | /* | |
1432 | if (start) | |
1433 | { | |
1434 | TexOutput(_T("{\\qr ")); | |
1435 | } | |
1436 | else TexOutput(_T("}\\par\\pard\n")); | |
1437 | */ | |
1438 | break; | |
1439 | } | |
1440 | case ltSMALL: | |
1441 | { | |
1442 | if (start) | |
1443 | { | |
1444 | // Netscape extension | |
1445 | TexOutput(_T("<FONT SIZE=2>")); | |
1446 | } | |
1447 | else TexOutput(_T("</FONT>")); | |
1448 | break; | |
1449 | } | |
1450 | case ltTINY: | |
1451 | { | |
1452 | if (start) | |
1453 | { | |
1454 | // Netscape extension | |
1455 | TexOutput(_T("<FONT SIZE=1>")); | |
1456 | } | |
1457 | else TexOutput(_T("</FONT>")); | |
1458 | break; | |
1459 | } | |
1460 | case ltNORMALSIZE: | |
1461 | { | |
1462 | if (start) | |
1463 | { | |
1464 | // Netscape extension | |
1465 | TexOutput(_T("<FONT SIZE=3>")); | |
1466 | } | |
1467 | else TexOutput(_T("</FONT>")); | |
1468 | break; | |
1469 | } | |
1470 | case ltlarge: | |
1471 | { | |
1472 | if (start) | |
1473 | { | |
1474 | // Netscape extension | |
1475 | TexOutput(_T("<FONT SIZE=4>")); | |
1476 | } | |
1477 | else TexOutput(_T("</FONT>")); | |
1478 | break; | |
1479 | } | |
1480 | case ltLarge: | |
1481 | { | |
1482 | if (start) | |
1483 | { | |
1484 | // Netscape extension | |
1485 | TexOutput(_T("<FONT SIZE=5>")); | |
1486 | } | |
1487 | else TexOutput(_T("</FONT>")); | |
1488 | break; | |
1489 | } | |
1490 | case ltLARGE: | |
1491 | { | |
1492 | if (start) | |
1493 | { | |
1494 | // Netscape extension | |
1495 | TexOutput(_T("<FONT SIZE=6>")); | |
1496 | } | |
1497 | else TexOutput(_T("</FONT>")); | |
1498 | break; | |
1499 | } | |
1500 | case ltBFSERIES: | |
1501 | case ltTEXTBF: | |
1502 | case ltBF: | |
1503 | { | |
1504 | if (start) | |
1505 | { | |
1506 | TexOutput(_T("<B>")); | |
1507 | } | |
1508 | else TexOutput(_T("</B>")); | |
1509 | break; | |
1510 | } | |
1511 | case ltITSHAPE: | |
1512 | case ltTEXTIT: | |
1513 | case ltIT: | |
1514 | { | |
1515 | if (start) | |
1516 | { | |
1517 | TexOutput(_T("<I>")); | |
1518 | } | |
1519 | else TexOutput(_T("</I>")); | |
1520 | break; | |
1521 | } | |
1522 | case ltEMPH: | |
1523 | case ltEM: | |
1524 | { | |
1525 | if (start) | |
1526 | { | |
1527 | TexOutput(_T("<EM>")); | |
1528 | } | |
1529 | else TexOutput(_T("</EM>")); | |
1530 | break; | |
1531 | } | |
1532 | case ltUNDERLINE: | |
1533 | { | |
1534 | if (start) | |
1535 | { | |
1536 | TexOutput(_T("<UL>")); | |
1537 | } | |
1538 | else TexOutput(_T("</UL>")); | |
1539 | break; | |
1540 | } | |
1541 | case ltTTFAMILY: | |
1542 | case ltTEXTTT: | |
1543 | case ltTT: | |
1544 | { | |
1545 | if (start) | |
1546 | { | |
1547 | TexOutput(_T("<TT>")); | |
1548 | } | |
1549 | else TexOutput(_T("</TT>")); | |
1550 | break; | |
1551 | } | |
1552 | case ltCOPYRIGHT: | |
1553 | { | |
1554 | if (start) | |
1555 | TexOutput(_T("©"), true); | |
1556 | break; | |
1557 | } | |
1558 | case ltREGISTERED: | |
1559 | { | |
1560 | if (start) | |
1561 | TexOutput(_T("®"), true); | |
1562 | break; | |
1563 | } | |
1564 | // Arrows | |
1565 | case ltLEFTARROW: | |
1566 | { | |
1567 | if (start) TexOutput(_T("<--")); | |
1568 | break; | |
1569 | } | |
1570 | case ltLEFTARROW2: | |
1571 | { | |
1572 | if (start) TexOutput(_T("<==")); | |
1573 | break; | |
1574 | } | |
1575 | case ltRIGHTARROW: | |
1576 | { | |
1577 | if (start) TexOutput(_T("-->")); | |
1578 | break; | |
1579 | } | |
1580 | case ltRIGHTARROW2: | |
1581 | { | |
1582 | if (start) TexOutput(_T("==>")); | |
1583 | break; | |
1584 | } | |
1585 | case ltLEFTRIGHTARROW: | |
1586 | { | |
1587 | if (start) TexOutput(_T("<-->")); | |
1588 | break; | |
1589 | } | |
1590 | case ltLEFTRIGHTARROW2: | |
1591 | { | |
1592 | if (start) TexOutput(_T("<==>")); | |
1593 | break; | |
1594 | } | |
1595 | /* | |
1596 | case ltSC: | |
1597 | { | |
1598 | break; | |
1599 | } | |
1600 | */ | |
1601 | case ltITEM: | |
1602 | { | |
1603 | if (!start) | |
1604 | { | |
1605 | wxNode *node = itemizeStack.GetFirst(); | |
1606 | if (node) | |
1607 | { | |
1608 | ItemizeStruc *struc = (ItemizeStruc *)node->GetData(); | |
1609 | struc->currentItem += 1; | |
1610 | if (struc->listType == LATEX_DESCRIPTION) | |
1611 | { | |
1612 | if (descriptionItemArg) | |
1613 | { | |
1614 | TexOutput(_T("<DT> ")); | |
1615 | TraverseChildrenFromChunk(descriptionItemArg); | |
1616 | TexOutput(_T("\n")); | |
1617 | descriptionItemArg = NULL; | |
1618 | } | |
1619 | TexOutput(_T("<DD>")); | |
1620 | } | |
1621 | else | |
1622 | TexOutput(_T("<LI>")); | |
1623 | } | |
1624 | } | |
1625 | break; | |
1626 | } | |
1627 | case ltMAKETITLE: | |
1628 | { | |
1629 | if (start && DocumentTitle && DocumentAuthor) | |
1630 | { | |
1631 | // Add a special label for the contents page. | |
1632 | // TexOutput(_T("<CENTER>\n")); | |
1633 | TexOutput(_T("<A NAME=\"contents\">")); | |
1634 | TexOutput(_T("<H2 ALIGN=CENTER>\n")); | |
1635 | TraverseChildrenFromChunk(DocumentTitle); | |
1636 | TexOutput(_T("</H2>")); | |
1637 | TexOutput(_T("<P>")); | |
1638 | TexOutput(_T("</A>\n")); | |
1639 | TexOutput(_T("<P>\n\n")); | |
1640 | TexOutput(_T("<H3 ALIGN=CENTER>")); | |
1641 | TraverseChildrenFromChunk(DocumentAuthor); | |
1642 | TexOutput(_T("</H3><P>\n\n")); | |
1643 | if (DocumentDate) | |
1644 | { | |
1645 | TexOutput(_T("<H3 ALIGN=CENTER>")); | |
1646 | TraverseChildrenFromChunk(DocumentDate); | |
1647 | TexOutput(_T("</H3><P>\n\n")); | |
1648 | } | |
1649 | // TexOutput(_T("\n</CENTER>\n")); | |
1650 | TexOutput(_T("\n<P><HR><P>\n")); | |
1651 | ||
1652 | /* | |
1653 | // Now do optional frame contents page | |
1654 | if (htmlFrameContents && FrameContents) | |
1655 | { | |
1656 | SetCurrentOutput(FrameContents); | |
1657 | ||
1658 | // Add a special label for the contents page. | |
1659 | TexOutput(_T("<CENTER>\n")); | |
1660 | TexOutput(_T("<H3>\n")); | |
1661 | TraverseChildrenFromChunk(DocumentTitle); | |
1662 | TexOutput(_T("</H3>")); | |
1663 | TexOutput(_T("<P>")); | |
1664 | TexOutput(_T("</A>\n")); | |
1665 | TexOutput(_T("<P>\n\n")); | |
1666 | TexOutput(_T("<H3>")); | |
1667 | TraverseChildrenFromChunk(DocumentAuthor); | |
1668 | TexOutput(_T("</H3><P>\n\n")); | |
1669 | if (DocumentDate) | |
1670 | { | |
1671 | TexOutput(_T("<H4>")); | |
1672 | TraverseChildrenFromChunk(DocumentDate); | |
1673 | TexOutput(_T("</H4><P>\n\n")); | |
1674 | } | |
1675 | TexOutput(_T("\n</CENTER>\n")); | |
1676 | TexOutput(_T("<P><HR><P>\n")); | |
1677 | ||
1678 | SetCurrentOutput(Titlepage); | |
1679 | } | |
1680 | */ | |
1681 | } | |
1682 | break; | |
1683 | } | |
1684 | case ltHELPREF: | |
1685 | case ltHELPREFN: | |
1686 | case ltPOPREF: | |
1687 | case ltURLREF: | |
1688 | { | |
1689 | if (start) | |
1690 | { | |
1691 | helpRefFilename = NULL; | |
1692 | helpRefText = NULL; | |
1693 | } | |
1694 | break; | |
1695 | } | |
1696 | case ltBIBLIOGRAPHY: | |
1697 | { | |
1698 | if (start) | |
1699 | { | |
1700 | DefaultOnMacro(macroId, no_args, start); | |
1701 | } | |
1702 | else | |
1703 | { | |
1704 | DefaultOnMacro(macroId, no_args, start); | |
1705 | TexOutput(_T("</DL>\n")); | |
1706 | } | |
1707 | break; | |
1708 | } | |
1709 | case ltHRULE: | |
1710 | { | |
1711 | if (start) | |
1712 | { | |
1713 | TexOutput(_T("<HR>\n")); | |
1714 | } | |
1715 | break; | |
1716 | } | |
1717 | case ltRULE: | |
1718 | { | |
1719 | if (start) | |
1720 | { | |
1721 | TexOutput(_T("<HR>\n")); | |
1722 | } | |
1723 | break; | |
1724 | } | |
1725 | case ltTABLEOFCONTENTS: | |
1726 | { | |
1727 | if (start) | |
1728 | { | |
1729 | // NB: if this is uncommented, the table of contents | |
1730 | // completely disappears. If left commented, it's in the wrong | |
1731 | // place. | |
1732 | //fflush(Titlepage); | |
1733 | ||
1734 | FILE *fd = wxFopen(ContentsName, _T("r")); | |
1735 | if (fd) | |
1736 | { | |
1737 | int ch = getc(fd); | |
1738 | while (ch != EOF) | |
1739 | { | |
1740 | wxPutc(ch, Titlepage); | |
1741 | ch = getc(fd); | |
1742 | } | |
1743 | fclose(fd); | |
1744 | fflush(Titlepage); | |
1745 | } | |
1746 | else | |
1747 | { | |
1748 | TexOutput(_T("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n")); | |
1749 | OnInform(_T("Run Tex2RTF again to include contents page.")); | |
1750 | } | |
1751 | } | |
1752 | break; | |
1753 | } | |
1754 | case ltLANGLEBRA: | |
1755 | { | |
1756 | if (start) | |
1757 | TexOutput(_T("<")); | |
1758 | break; | |
1759 | } | |
1760 | case ltRANGLEBRA: | |
1761 | { | |
1762 | if (start) | |
1763 | TexOutput(_T(">")); | |
1764 | break; | |
1765 | } | |
1766 | case ltQUOTE: | |
1767 | case ltQUOTATION: | |
1768 | { | |
1769 | if (start) | |
1770 | TexOutput(_T("<BLOCKQUOTE>")); | |
1771 | else | |
1772 | TexOutput(_T("</BLOCKQUOTE>")); | |
1773 | break; | |
1774 | } | |
1775 | case ltCAPTION: | |
1776 | case ltCAPTIONSTAR: | |
1777 | { | |
1778 | if (start) | |
1779 | { | |
1780 | if (inTabular) | |
1781 | TexOutput(_T("\n<CAPTION>")); | |
1782 | ||
1783 | wxChar figBuf[40]; | |
1784 | ||
1785 | if ( inFigure ) | |
1786 | { | |
1787 | figureNo ++; | |
1788 | ||
1789 | if (DocumentStyle != LATEX_ARTICLE) | |
1790 | wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d.%d: "), FigureNameString, chapterNo, figureNo); | |
1791 | else | |
1792 | wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d: "), FigureNameString, figureNo); | |
1793 | } | |
1794 | else | |
1795 | { | |
1796 | tableNo ++; | |
1797 | ||
1798 | if (DocumentStyle != LATEX_ARTICLE) | |
1799 | wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d.%d: "), TableNameString, chapterNo, tableNo); | |
1800 | else | |
1801 | wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d: "), TableNameString, tableNo); | |
1802 | } | |
1803 | ||
1804 | TexOutput(figBuf); | |
1805 | } | |
1806 | else | |
1807 | { | |
1808 | if (inTabular) | |
1809 | TexOutput(_T("\n</CAPTION>\n")); | |
1810 | ||
1811 | wxChar *topicName = FindTopicName(GetNextChunk()); | |
1812 | ||
1813 | int n = inFigure ? figureNo : tableNo; | |
1814 | ||
1815 | AddTexRef(topicName, NULL, NULL, | |
1816 | ((DocumentStyle != LATEX_ARTICLE) ? chapterNo : n), | |
1817 | ((DocumentStyle != LATEX_ARTICLE) ? n : 0)); | |
1818 | } | |
1819 | break; | |
1820 | } | |
1821 | case ltSS: | |
1822 | { | |
1823 | if (start) TexOutput(_T("ß")); | |
1824 | break; | |
1825 | } | |
1826 | case ltFIGURE: | |
1827 | { | |
1828 | if (start) inFigure = true; | |
1829 | else inFigure = false; | |
1830 | break; | |
1831 | } | |
1832 | case ltTABLE: | |
1833 | { | |
1834 | if (start) inTable = true; | |
1835 | else inTable = false; | |
1836 | break; | |
1837 | } | |
1838 | default: | |
1839 | DefaultOnMacro(macroId, no_args, start); | |
1840 | break; | |
1841 | } | |
1842 | } | |
1843 | /* CheckTypeRef() | |
1844 | ||
1845 | should be called at of argument which usually is | |
1846 | type declaration which propably contains name of | |
1847 | documented class | |
1848 | ||
1849 | examples: | |
1850 | HTMLOnArgument | |
1851 | - ltFUNC, | |
1852 | - ltPARAM | |
1853 | - ltCPARAM | |
1854 | ||
1855 | checks: GetArgData() if contains Type Declaration | |
1856 | and can be referenced to some file | |
1857 | prints: | |
1858 | before<a href="xxx&yyy">type</a>after | |
1859 | ||
1860 | returns: | |
1861 | false - if no reference was found | |
1862 | true - if reference was found and HREF printed | |
1863 | */ | |
1864 | static bool CheckTypeRef() | |
1865 | { | |
1866 | wxString typeDecl = GetArgData(); | |
1867 | if( !typeDecl.empty() ) { | |
1868 | typeDecl.Replace(wxT("\\"),wxT("")); | |
1869 | wxString label = typeDecl; | |
1870 | label.Replace(wxT("const"),wxT("")); | |
1871 | label.Replace(wxT("virtual"),wxT("")); | |
1872 | label.Replace(wxT("static"),wxT("")); | |
1873 | label.Replace(wxT("extern"),wxT("")); | |
1874 | label = label.BeforeFirst('&'); | |
1875 | label = label.BeforeFirst(wxT('*')); | |
1876 | label = label.BeforeFirst(wxT('\\')); | |
1877 | label.Trim(true); label.Trim(false); | |
1878 | wxString typeName = label; | |
1879 | label.MakeLower(); | |
1880 | TexRef *texRef = FindReference(label); | |
1881 | ||
1882 | if (texRef && texRef->refFile && wxStrcmp(texRef->refFile, _T("??")) != 0) { | |
1883 | int a = typeDecl.Find(typeName); | |
1884 | wxString before = typeDecl.Mid( 0, a ); | |
1885 | wxString after = typeDecl.Mid( a+typeName.Length() ); | |
1886 | //wxFprintf(stderr,wxT("%s <%s> %s to ... %s#%s !!!!\n"), | |
1887 | // before.c_str(), | |
1888 | // typeName.c_str(), | |
1889 | // after.c_str(), | |
1890 | // texRef->refFile,label.c_str()); | |
1891 | TexOutput(before); | |
1892 | TexOutput(_T("<A HREF=\"")); | |
1893 | TexOutput(texRef->refFile); | |
1894 | TexOutput(_T("#")); | |
1895 | TexOutput(label); | |
1896 | TexOutput(wxT("\">")); | |
1897 | TexOutput(typeName); | |
1898 | TexOutput(wxT("</A>")); | |
1899 | TexOutput(after); | |
1900 | return true; | |
1901 | } else { | |
1902 | //wxFprintf(stderr,wxT("'%s' from (%s) -> label %s NOT FOUND\n"), | |
1903 | // typeName.c_str(), | |
1904 | // typeDecl.c_str(), | |
1905 | // label.c_str()); | |
1906 | return false; | |
1907 | } | |
1908 | } | |
1909 | return false; | |
1910 | } | |
1911 | // Called on start/end of argument examination | |
1912 | bool HTMLOnArgument(int macroId, int arg_no, bool start) | |
1913 | { | |
1914 | switch (macroId) | |
1915 | { | |
1916 | case ltCHAPTER: | |
1917 | case ltCHAPTERSTAR: | |
1918 | case ltCHAPTERHEADING: | |
1919 | case ltSECTION: | |
1920 | case ltSECTIONSTAR: | |
1921 | case ltSECTIONHEADING: | |
1922 | case ltSUBSECTION: | |
1923 | case ltSUBSECTIONSTAR: | |
1924 | case ltSUBSUBSECTION: | |
1925 | case ltSUBSUBSECTIONSTAR: | |
1926 | case ltGLOSS: | |
1927 | case ltMEMBERSECTION: | |
1928 | case ltFUNCTIONSECTION: | |
1929 | { | |
1930 | if (!start && (arg_no == 1)) | |
1931 | currentSection = GetArgChunk(); | |
1932 | return false; | |
1933 | } | |
1934 | case ltFUNC: | |
1935 | { | |
1936 | if (start && (arg_no == 1)) { | |
1937 | TexOutput(_T("<B>")); | |
1938 | if( CheckTypeRef() ) { | |
1939 | TexOutput(_T("</B> ")); | |
1940 | return false; | |
1941 | } | |
1942 | } | |
1943 | ||
1944 | if (!start && (arg_no == 1)) | |
1945 | TexOutput(_T("</B> ")); | |
1946 | ||
1947 | if (start && (arg_no == 2)) | |
1948 | { | |
1949 | if (!suppressNameDecoration) TexOutput(_T("<B>")); | |
1950 | currentMember = GetArgChunk(); | |
1951 | } | |
1952 | if (!start && (arg_no == 2)) | |
1953 | { | |
1954 | if (!suppressNameDecoration) TexOutput(_T("</B>")); | |
1955 | } | |
1956 | ||
1957 | if (start && (arg_no == 3)) | |
1958 | TexOutput(_T("(")); | |
1959 | if (!start && (arg_no == 3)) | |
1960 | TexOutput(_T(")")); | |
1961 | break; | |
1962 | } | |
1963 | case ltCLIPSFUNC: | |
1964 | { | |
1965 | if (start && (arg_no == 1)) | |
1966 | TexOutput(_T("<B>")); | |
1967 | if (!start && (arg_no == 1)) | |
1968 | TexOutput(_T("</B> ")); | |
1969 | ||
1970 | if (start && (arg_no == 2)) | |
1971 | { | |
1972 | if (!suppressNameDecoration) TexOutput(_T("( ")); | |
1973 | currentMember = GetArgChunk(); | |
1974 | } | |
1975 | if (!start && (arg_no == 2)) | |
1976 | { | |
1977 | } | |
1978 | ||
1979 | if (!start && (arg_no == 3)) | |
1980 | TexOutput(_T(")")); | |
1981 | break; | |
1982 | } | |
1983 | case ltPFUNC: | |
1984 | { | |
1985 | if (!start && (arg_no == 1)) | |
1986 | TexOutput(_T(" ")); | |
1987 | ||
1988 | if (start && (arg_no == 2)) | |
1989 | TexOutput(_T("(*")); | |
1990 | if (!start && (arg_no == 2)) | |
1991 | TexOutput(_T(")")); | |
1992 | ||
1993 | if (start && (arg_no == 2)) | |
1994 | currentMember = GetArgChunk(); | |
1995 | ||
1996 | if (start && (arg_no == 3)) | |
1997 | TexOutput(_T("(")); | |
1998 | if (!start && (arg_no == 3)) | |
1999 | TexOutput(_T(")")); | |
2000 | break; | |
2001 | } | |
2002 | case ltPARAM: | |
2003 | case ltCPARAM: | |
2004 | { | |
2005 | const wxChar* pend = macroId == ltCPARAM ? | |
2006 | _T("</B> ") : _T("</B>"); | |
2007 | if( arg_no == 1) { | |
2008 | if( start ) { | |
2009 | TexOutput(_T("<B>")); | |
2010 | if( CheckTypeRef() ) { | |
2011 | TexOutput(pend); | |
2012 | return false; | |
2013 | } | |
2014 | } else { | |
2015 | TexOutput(pend); | |
2016 | } | |
2017 | } | |
2018 | if (start && (arg_no == 2)) | |
2019 | { | |
2020 | TexOutput(_T("<I>")); | |
2021 | } | |
2022 | if (!start && (arg_no == 2)) | |
2023 | { | |
2024 | TexOutput(_T("</I>")); | |
2025 | } | |
2026 | break; | |
2027 | } | |
2028 | case ltMEMBER: | |
2029 | { | |
2030 | if (!start && (arg_no == 1)) | |
2031 | TexOutput(_T(" ")); | |
2032 | ||
2033 | if (start && (arg_no == 2)) | |
2034 | currentMember = GetArgChunk(); | |
2035 | break; | |
2036 | } | |
2037 | case ltREF: | |
2038 | { | |
2039 | if (start) | |
2040 | { | |
2041 | wxChar *sec = NULL; | |
2042 | ||
2043 | wxChar *refName = GetArgData(); | |
2044 | if (refName) | |
2045 | { | |
2046 | TexRef *texRef = FindReference(refName); | |
2047 | if (texRef) | |
2048 | { | |
2049 | sec = texRef->sectionNumber; | |
2050 | } | |
2051 | } | |
2052 | if (sec) | |
2053 | { | |
2054 | TexOutput(sec); | |
2055 | } | |
2056 | return false; | |
2057 | } | |
2058 | break; | |
2059 | } | |
2060 | case ltURLREF: | |
2061 | { | |
2062 | if (IsArgOptional()) | |
2063 | return false; | |
2064 | else if ((GetNoArgs() - arg_no) == 1) | |
2065 | { | |
2066 | if (start) | |
2067 | helpRefText = GetArgChunk(); | |
2068 | return false; | |
2069 | } | |
2070 | else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional | |
2071 | { | |
2072 | if (start) | |
2073 | { | |
2074 | TexChunk *ref = GetArgChunk(); | |
2075 | TexOutput(_T("<A HREF=\"")); | |
2076 | inVerbatim = true; | |
2077 | TraverseChildrenFromChunk(ref); | |
2078 | inVerbatim = false; | |
2079 | TexOutput(_T("\">")); | |
2080 | if (helpRefText) | |
2081 | TraverseChildrenFromChunk(helpRefText); | |
2082 | TexOutput(_T("</A>")); | |
2083 | } | |
2084 | return false; | |
2085 | } | |
2086 | break; | |
2087 | } | |
2088 | ||
2089 | case ltHELPREF: | |
2090 | case ltHELPREFN: | |
2091 | case ltPOPREF: | |
2092 | { | |
2093 | if (IsArgOptional()) | |
2094 | { | |
2095 | if (start) | |
2096 | helpRefFilename = GetArgChunk(); | |
2097 | return false; | |
2098 | } | |
2099 | if ((GetNoArgs() - arg_no) == 1) | |
2100 | { | |
2101 | if (start) | |
2102 | helpRefText = GetArgChunk(); | |
2103 | return false; | |
2104 | } | |
2105 | else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional | |
2106 | { | |
2107 | if (start) | |
2108 | { | |
2109 | wxChar *refName = GetArgData(); | |
2110 | wxChar *refFilename = NULL; | |
2111 | ||
2112 | if (refName) | |
2113 | { | |
2114 | TexRef *texRef = FindReference(refName); | |
2115 | if (texRef) | |
2116 | { | |
2117 | if (texRef->refFile && wxStrcmp(texRef->refFile, _T("??")) != 0) | |
2118 | refFilename = texRef->refFile; | |
2119 | ||
2120 | TexOutput(_T("<A HREF=\"")); | |
2121 | // If a filename is supplied, use it, otherwise try to | |
2122 | // use the filename associated with the reference (from this document). | |
2123 | if (helpRefFilename) | |
2124 | { | |
2125 | TraverseChildrenFromChunk(helpRefFilename); | |
2126 | TexOutput(_T("#")); | |
2127 | TexOutput(refName); | |
2128 | } | |
2129 | else if (refFilename) | |
2130 | { | |
2131 | TexOutput(ConvertCase(refFilename)); | |
2132 | if(!PrimaryAnchorOfTheFile(texRef->refFile, refName)) | |
2133 | { | |
2134 | TexOutput(_T("#")); | |
2135 | TexOutput(refName); | |
2136 | } | |
2137 | } | |
2138 | TexOutput(_T("\">")); | |
2139 | if (helpRefText) | |
2140 | TraverseChildrenFromChunk(helpRefText); | |
2141 | TexOutput(_T("</A>")); | |
2142 | } | |
2143 | else | |
2144 | { | |
2145 | if (helpRefText) | |
2146 | TraverseChildrenFromChunk(helpRefText); | |
2147 | if (!ignoreBadRefs) | |
2148 | TexOutput(_T(" (REF NOT FOUND)")); | |
2149 | ||
2150 | // for launching twice do not warn in preparation pass | |
2151 | if ((passNumber == 1 && !runTwice) || | |
2152 | (passNumber == 2 && runTwice)) | |
2153 | { | |
2154 | wxString errBuf; | |
2155 | errBuf.Printf(_T("Warning: unresolved reference '%s'"), refName); | |
2156 | OnInform(errBuf); | |
2157 | } | |
2158 | } | |
2159 | } | |
2160 | else TexOutput(_T("??")); | |
2161 | } | |
2162 | return false; | |
2163 | } | |
2164 | break; | |
2165 | } | |
2166 | case ltIMAGE: | |
2167 | case ltIMAGEL: | |
2168 | case ltIMAGER: | |
2169 | case ltPSBOXTO: | |
2170 | { | |
2171 | if (arg_no == 2) | |
2172 | { | |
2173 | if (start) | |
2174 | { | |
2175 | wxChar *alignment = _T(""); | |
2176 | if (macroId == ltIMAGEL) | |
2177 | alignment = _T(" align=left"); | |
2178 | else if (macroId == ltIMAGER) | |
2179 | alignment = _T(" align=right"); | |
2180 | ||
2181 | // Try to find an XBM or GIF image first. | |
2182 | wxChar *filename = copystring(GetArgData()); | |
2183 | wxChar buf[500]; | |
2184 | ||
2185 | wxStrcpy(buf, filename); | |
2186 | StripExtension(buf); | |
2187 | wxStrcat(buf, _T(".xbm")); | |
2188 | wxString f = TexPathList.FindValidPath(buf); | |
2189 | ||
2190 | if (f == _T("")) // Try for a GIF instead | |
2191 | { | |
2192 | wxStrcpy(buf, filename); | |
2193 | StripExtension(buf); | |
2194 | wxStrcat(buf, _T(".gif")); | |
2195 | f = TexPathList.FindValidPath(buf); | |
2196 | } | |
2197 | ||
2198 | if (f == _T("")) // Try for a JPEG instead | |
2199 | { | |
2200 | wxStrcpy(buf, filename); | |
2201 | StripExtension(buf); | |
2202 | wxStrcat(buf, _T(".jpg")); | |
2203 | f = TexPathList.FindValidPath(buf); | |
2204 | } | |
2205 | ||
2206 | if (f == _T("")) // Try for a PNG instead | |
2207 | { | |
2208 | wxStrcpy(buf, filename); | |
2209 | StripExtension(buf); | |
2210 | wxStrcat(buf, _T(".png")); | |
2211 | f = TexPathList.FindValidPath(buf); | |
2212 | } | |
2213 | ||
2214 | if (f != _T("")) | |
2215 | { | |
2216 | wxChar *inlineFilename = copystring(f); | |
2217 | #if 0 | |
2218 | wxChar *originalFilename = TexPathList.FindValidPath(filename); | |
2219 | // If we have found the existing filename, make the inline | |
2220 | // image point to the original file (could be PS, for example) | |
2221 | if (originalFilename && (wxStrcmp(inlineFilename, originalFilename) != 0)) | |
2222 | { | |
2223 | TexOutput(_T("<A HREF=\"")); | |
2224 | TexOutput(ConvertCase(originalFilename)); | |
2225 | TexOutput(_T("\">")); | |
2226 | TexOutput(_T("<img src=\"")); | |
2227 | TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename))); | |
2228 | TexOutput(_T("\"")); | |
2229 | TexOutput(alignment); | |
2230 | TexOutput(_T("></A>")); | |
2231 | } | |
2232 | else | |
2233 | #endif | |
2234 | { | |
2235 | TexOutput(_T("<img src=\"")); | |
2236 | TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename))); | |
2237 | TexOutput(_T("\"")); | |
2238 | TexOutput(alignment); | |
2239 | TexOutput(_T(">")); | |
2240 | delete[] inlineFilename; | |
2241 | } | |
2242 | } | |
2243 | else | |
2244 | { | |
2245 | // Last resort - a link to a PS file. | |
2246 | TexOutput(_T("<A HREF=\"")); | |
2247 | TexOutput(ConvertCase(wxFileNameFromPath(filename))); | |
2248 | TexOutput(_T("\">Picture</A>\n")); | |
2249 | wxSnprintf(buf, sizeof(buf), _T("Warning: could not find an inline XBM/GIF for %s."), filename); | |
2250 | OnInform(buf); | |
2251 | } | |
2252 | } | |
2253 | } | |
2254 | return false; | |
2255 | } | |
2256 | // First arg is PSBOX spec (ignored), second is image file, third is map name. | |
2257 | case ltIMAGEMAP: | |
2258 | { | |
2259 | static wxChar *imageFile = NULL; | |
2260 | if (start && (arg_no == 2)) | |
2261 | { | |
2262 | // Try to find an XBM or GIF image first. | |
2263 | wxChar *filename = copystring(GetArgData()); | |
2264 | wxChar buf[500]; | |
2265 | ||
2266 | wxStrcpy(buf, filename); | |
2267 | StripExtension(buf); | |
2268 | wxStrcat(buf, _T(".xbm")); | |
2269 | wxString f = TexPathList.FindValidPath(buf); | |
2270 | ||
2271 | if (f == _T("")) // Try for a GIF instead | |
2272 | { | |
2273 | wxStrcpy(buf, filename); | |
2274 | StripExtension(buf); | |
2275 | wxStrcat(buf, _T(".gif")); | |
2276 | f = TexPathList.FindValidPath(buf); | |
2277 | } | |
2278 | if (f == _T("")) | |
2279 | { | |
2280 | wxChar buf[300]; | |
2281 | wxSnprintf(buf, sizeof(buf), _T("Warning: could not find an inline XBM/GIF for %s."), filename); | |
2282 | OnInform(buf); | |
2283 | } | |
2284 | delete[] filename; | |
2285 | if (imageFile) | |
2286 | delete[] imageFile; | |
2287 | imageFile = NULL; | |
2288 | if (!f.empty()) | |
2289 | { | |
2290 | imageFile = copystring(f); | |
2291 | } | |
2292 | } | |
2293 | else if (start && (arg_no == 3)) | |
2294 | { | |
2295 | if (imageFile) | |
2296 | { | |
2297 | // First, try to find a .shg (segmented hypergraphics file) | |
2298 | // that we can convert to a map file | |
2299 | wxChar buf[256]; | |
2300 | wxStrcpy(buf, imageFile); | |
2301 | StripExtension(buf); | |
2302 | wxStrcat(buf, _T(".shg")); | |
2303 | wxString f = TexPathList.FindValidPath(buf); | |
2304 | ||
2305 | if (f != _T("")) | |
2306 | { | |
2307 | // The default HTML file to go to is THIS file (so a no-op) | |
2308 | SHGToMap(f, currentFileName); | |
2309 | } | |
2310 | ||
2311 | wxChar *mapName = GetArgData(); | |
2312 | TexOutput(_T("<A HREF=\"/cgi-bin/imagemap/")); | |
2313 | if (mapName) | |
2314 | TexOutput(mapName); | |
2315 | else | |
2316 | TexOutput(_T("unknown")); | |
2317 | TexOutput(_T("\">")); | |
2318 | TexOutput(_T("<img src=\"")); | |
2319 | TexOutput(ConvertCase(wxFileNameFromPath(imageFile))); | |
2320 | TexOutput(_T("\" ISMAP></A><P>")); | |
2321 | delete[] imageFile; | |
2322 | imageFile = NULL; | |
2323 | } | |
2324 | } | |
2325 | return false; | |
2326 | } | |
2327 | case ltINDENTED : | |
2328 | { | |
2329 | if ( arg_no == 1 ) | |
2330 | return false; | |
2331 | else | |
2332 | { | |
2333 | return true; | |
2334 | } | |
2335 | } | |
2336 | case ltITEM: | |
2337 | { | |
2338 | if (start) | |
2339 | { | |
2340 | descriptionItemArg = GetArgChunk(); | |
2341 | return false; | |
2342 | } | |
2343 | return true; | |
2344 | } | |
2345 | case ltTWOCOLITEM: | |
2346 | case ltTWOCOLITEMRULED: | |
2347 | { | |
2348 | /* | |
2349 | if (start && (arg_no == 1)) | |
2350 | TexOutput(_T("\n<DT> ")); | |
2351 | if (start && (arg_no == 2)) | |
2352 | TexOutput(_T("<DD> ")); | |
2353 | */ | |
2354 | if (arg_no == 1) | |
2355 | { | |
2356 | if ( start ) { | |
2357 | // DHS | |
2358 | if (TwoColWidthA > -1) | |
2359 | { | |
2360 | wxChar buf[100]; | |
2361 | wxSnprintf(buf, sizeof(buf), _T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA); | |
2362 | TexOutput(buf); | |
2363 | } | |
2364 | else | |
2365 | { | |
2366 | TexOutput(_T("\n<TR><TD VALIGN=TOP>\n")); | |
2367 | } | |
2368 | OutputFont(); | |
2369 | } else | |
2370 | TexOutput(_T("\n</FONT></TD>\n")); | |
2371 | } | |
2372 | if (arg_no == 2) | |
2373 | { | |
2374 | // DHS | |
2375 | if ( start ) | |
2376 | { | |
2377 | if (TwoColWidthB > -1) | |
2378 | { | |
2379 | wxChar buf[100]; | |
2380 | wxSnprintf(buf, sizeof(buf), _T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB); | |
2381 | TexOutput(buf); | |
2382 | } | |
2383 | else | |
2384 | { | |
2385 | TexOutput(_T("\n<TD VALIGN=TOP>\n")); | |
2386 | } | |
2387 | OutputFont(); | |
2388 | } else | |
2389 | TexOutput(_T("\n</FONT></TD></TR>\n")); | |
2390 | } | |
2391 | return true; | |
2392 | } | |
2393 | case ltNUMBEREDBIBITEM: | |
2394 | { | |
2395 | if (arg_no == 1 && start) | |
2396 | { | |
2397 | TexOutput(_T("\n<DT> ")); | |
2398 | } | |
2399 | if (arg_no == 2 && !start) | |
2400 | TexOutput(_T("<P>\n")); | |
2401 | break; | |
2402 | } | |
2403 | case ltBIBITEM: | |
2404 | { | |
2405 | wxChar buf[100]; | |
2406 | if (arg_no == 1 && start) | |
2407 | { | |
2408 | wxChar *citeKey = GetArgData(); | |
2409 | TexRef *ref = (TexRef *)TexReferences.Get(citeKey); | |
2410 | if (ref) | |
2411 | { | |
2412 | if (ref->sectionNumber) delete[] ref->sectionNumber; | |
2413 | wxSnprintf(buf, sizeof(buf), _T("[%d]"), citeCount); | |
2414 | ref->sectionNumber = copystring(buf); | |
2415 | } | |
2416 | ||
2417 | wxSnprintf(buf, sizeof(buf), _T("\n<DT> [%d] "), citeCount); | |
2418 | TexOutput(buf); | |
2419 | citeCount ++; | |
2420 | return false; | |
2421 | } | |
2422 | if (arg_no == 2 && !start) | |
2423 | TexOutput(_T("<P>\n")); | |
2424 | return true; | |
2425 | } | |
2426 | case ltMARGINPAR: | |
2427 | case ltMARGINPARODD: | |
2428 | case ltMARGINPAREVEN: | |
2429 | case ltNORMALBOX: | |
2430 | case ltNORMALBOXD: | |
2431 | { | |
2432 | if (start) | |
2433 | { | |
2434 | TexOutput(_T("<HR>\n")); | |
2435 | return true; | |
2436 | } | |
2437 | else | |
2438 | TexOutput(_T("<HR><P>\n")); | |
2439 | break; | |
2440 | } | |
2441 | // DHS | |
2442 | case ltTWOCOLWIDTHA: | |
2443 | { | |
2444 | if (start) | |
2445 | { | |
2446 | wxChar *val = GetArgData(); | |
2447 | float points = ParseUnitArgument(val); | |
2448 | TwoColWidthA = (int)((points * 100.0) / 72.0); | |
2449 | } | |
2450 | return false; | |
2451 | } | |
2452 | // DHS | |
2453 | case ltTWOCOLWIDTHB: | |
2454 | { | |
2455 | if (start) | |
2456 | { | |
2457 | wxChar *val = GetArgData(); | |
2458 | float points = ParseUnitArgument(val); | |
2459 | TwoColWidthB = (int)((points * 100.0) / 72.0); | |
2460 | } | |
2461 | return false; | |
2462 | } | |
2463 | /* | |
2464 | * Accents | |
2465 | * | |
2466 | */ | |
2467 | case ltACCENT_GRAVE: | |
2468 | { | |
2469 | if (start) | |
2470 | { | |
2471 | wxChar *val = GetArgData(); | |
2472 | if (val) | |
2473 | { | |
2474 | switch (val[0]) | |
2475 | { | |
2476 | case 'a': | |
2477 | TexOutput(_T("à")); | |
2478 | break; | |
2479 | case 'e': | |
2480 | TexOutput(_T("è")); | |
2481 | break; | |
2482 | case 'i': | |
2483 | TexOutput(_T("ì")); | |
2484 | break; | |
2485 | case 'o': | |
2486 | TexOutput(_T("ò")); | |
2487 | break; | |
2488 | case 'u': | |
2489 | TexOutput(_T("ù")); | |
2490 | break; | |
2491 | case 'A': | |
2492 | TexOutput(_T("À")); | |
2493 | break; | |
2494 | case 'E': | |
2495 | TexOutput(_T("È")); | |
2496 | break; | |
2497 | case 'I': | |
2498 | TexOutput(_T("Ì")); | |
2499 | break; | |
2500 | case 'O': | |
2501 | TexOutput(_T("Ò")); | |
2502 | break; | |
2503 | case 'U': | |
2504 | TexOutput(_T("Ì")); | |
2505 | break; | |
2506 | default: | |
2507 | break; | |
2508 | } | |
2509 | } | |
2510 | } | |
2511 | return false; | |
2512 | } | |
2513 | case ltACCENT_ACUTE: | |
2514 | { | |
2515 | if (start) | |
2516 | { | |
2517 | wxChar *val = GetArgData(); | |
2518 | if (val) | |
2519 | { | |
2520 | switch (val[0]) | |
2521 | { | |
2522 | case 'a': | |
2523 | TexOutput(_T("á")); | |
2524 | break; | |
2525 | case 'e': | |
2526 | TexOutput(_T("é")); | |
2527 | break; | |
2528 | case 'i': | |
2529 | TexOutput(_T("í")); | |
2530 | break; | |
2531 | case 'o': | |
2532 | TexOutput(_T("ó")); | |
2533 | break; | |
2534 | case 'u': | |
2535 | TexOutput(_T("ú")); | |
2536 | break; | |
2537 | case 'y': | |
2538 | TexOutput(_T("ý")); | |
2539 | break; | |
2540 | case 'A': | |
2541 | TexOutput(_T("Á")); | |
2542 | break; | |
2543 | case 'E': | |
2544 | TexOutput(_T("É")); | |
2545 | break; | |
2546 | case 'I': | |
2547 | TexOutput(_T("Í")); | |
2548 | break; | |
2549 | case 'O': | |
2550 | TexOutput(_T("Ó")); | |
2551 | break; | |
2552 | case 'U': | |
2553 | TexOutput(_T("Ú")); | |
2554 | break; | |
2555 | case 'Y': | |
2556 | TexOutput(_T("Ý")); | |
2557 | break; | |
2558 | default: | |
2559 | break; | |
2560 | } | |
2561 | } | |
2562 | } | |
2563 | return false; | |
2564 | } | |
2565 | case ltACCENT_CARET: | |
2566 | { | |
2567 | if (start) | |
2568 | { | |
2569 | wxChar *val = GetArgData(); | |
2570 | if (val) | |
2571 | { | |
2572 | switch (val[0]) | |
2573 | { | |
2574 | case 'a': | |
2575 | TexOutput(_T("â")); | |
2576 | break; | |
2577 | case 'e': | |
2578 | TexOutput(_T("ê")); | |
2579 | break; | |
2580 | case 'i': | |
2581 | TexOutput(_T("î")); | |
2582 | break; | |
2583 | case 'o': | |
2584 | TexOutput(_T("ô")); | |
2585 | break; | |
2586 | case 'u': | |
2587 | TexOutput(_T("û")); | |
2588 | break; | |
2589 | case 'A': | |
2590 | TexOutput(_T("Â")); | |
2591 | break; | |
2592 | case 'E': | |
2593 | TexOutput(_T("Ê")); | |
2594 | break; | |
2595 | case 'I': | |
2596 | TexOutput(_T("Î")); | |
2597 | break; | |
2598 | case 'O': | |
2599 | TexOutput(_T("Ô")); | |
2600 | break; | |
2601 | case 'U': | |
2602 | TexOutput(_T("Î")); | |
2603 | break; | |
2604 | default: | |
2605 | break; | |
2606 | } | |
2607 | } | |
2608 | } | |
2609 | return false; | |
2610 | } | |
2611 | case ltACCENT_TILDE: | |
2612 | { | |
2613 | if (start) | |
2614 | { | |
2615 | wxChar *val = GetArgData(); | |
2616 | if (val) | |
2617 | { | |
2618 | switch (val[0]) | |
2619 | { | |
2620 | case ' ': | |
2621 | TexOutput(_T("~")); | |
2622 | break; | |
2623 | case 'a': | |
2624 | TexOutput(_T("ã")); | |
2625 | break; | |
2626 | case 'n': | |
2627 | TexOutput(_T("ñ")); | |
2628 | break; | |
2629 | case 'o': | |
2630 | TexOutput(_T("õ")); | |
2631 | break; | |
2632 | case 'A': | |
2633 | TexOutput(_T("Ã")); | |
2634 | break; | |
2635 | case 'N': | |
2636 | TexOutput(_T("Ñ")); | |
2637 | break; | |
2638 | case 'O': | |
2639 | TexOutput(_T("Õ")); | |
2640 | break; | |
2641 | default: | |
2642 | break; | |
2643 | } | |
2644 | } | |
2645 | } | |
2646 | return false; | |
2647 | } | |
2648 | case ltACCENT_UMLAUT: | |
2649 | { | |
2650 | if (start) | |
2651 | { | |
2652 | wxChar *val = GetArgData(); | |
2653 | if (val) | |
2654 | { | |
2655 | switch (val[0]) | |
2656 | { | |
2657 | case 'a': | |
2658 | TexOutput(_T("ä")); | |
2659 | break; | |
2660 | case 'e': | |
2661 | TexOutput(_T("ë")); | |
2662 | break; | |
2663 | case 'i': | |
2664 | TexOutput(_T("ï")); | |
2665 | break; | |
2666 | case 'o': | |
2667 | TexOutput(_T("ö")); | |
2668 | break; | |
2669 | case 'u': | |
2670 | TexOutput(_T("ü")); | |
2671 | break; | |
2672 | case 'y': | |
2673 | TexOutput(_T("ÿ")); | |
2674 | break; | |
2675 | case 'A': | |
2676 | TexOutput(_T("Ä")); | |
2677 | break; | |
2678 | case 'E': | |
2679 | TexOutput(_T("Ë")); | |
2680 | break; | |
2681 | case 'I': | |
2682 | TexOutput(_T("Ï")); | |
2683 | break; | |
2684 | case 'O': | |
2685 | TexOutput(_T("Ö")); | |
2686 | break; | |
2687 | case 'U': | |
2688 | TexOutput(_T("Ü")); | |
2689 | break; | |
2690 | case 'Y': | |
2691 | TexOutput(_T("Ÿ")); | |
2692 | break; | |
2693 | default: | |
2694 | break; | |
2695 | } | |
2696 | } | |
2697 | } | |
2698 | return false; | |
2699 | } | |
2700 | case ltACCENT_DOT: | |
2701 | { | |
2702 | if (start) | |
2703 | { | |
2704 | wxChar *val = GetArgData(); | |
2705 | if (val) | |
2706 | { | |
2707 | switch (val[0]) | |
2708 | { | |
2709 | case 'a': | |
2710 | TexOutput(_T("å")); | |
2711 | break; | |
2712 | case 'A': | |
2713 | TexOutput(_T("Å")); | |
2714 | break; | |
2715 | default: | |
2716 | break; | |
2717 | } | |
2718 | } | |
2719 | } | |
2720 | return false; | |
2721 | } | |
2722 | case ltBACKGROUND: | |
2723 | { | |
2724 | if (start) | |
2725 | { | |
2726 | wxChar *val = GetArgData(); | |
2727 | if (val) | |
2728 | { | |
2729 | bool isPicture = false; | |
2730 | ParseColourString(val, &isPicture); | |
2731 | if (isPicture) | |
2732 | { | |
2733 | if (backgroundImageString) | |
2734 | delete[] backgroundImageString; | |
2735 | backgroundImageString = copystring(val); | |
2736 | } | |
2737 | else | |
2738 | { | |
2739 | if (backgroundColourString) | |
2740 | delete[] backgroundColourString; | |
2741 | backgroundColourString = copystring(val); | |
2742 | } | |
2743 | } | |
2744 | } | |
2745 | return false; | |
2746 | } | |
2747 | case ltBACKGROUNDIMAGE: | |
2748 | { | |
2749 | if (start) | |
2750 | { | |
2751 | wxChar *val = GetArgData(); | |
2752 | if (val) | |
2753 | { | |
2754 | if (backgroundImageString) | |
2755 | delete[] backgroundImageString; | |
2756 | backgroundImageString = copystring(val); | |
2757 | } | |
2758 | } | |
2759 | return false; | |
2760 | } | |
2761 | case ltBACKGROUNDCOLOUR: | |
2762 | { | |
2763 | if (start) | |
2764 | { | |
2765 | wxChar *val = GetArgData(); | |
2766 | if (val) | |
2767 | { | |
2768 | if (backgroundColourString) | |
2769 | delete[] backgroundColourString; | |
2770 | backgroundColourString = copystring(val); | |
2771 | } | |
2772 | } | |
2773 | return false; | |
2774 | } | |
2775 | case ltTEXTCOLOUR: | |
2776 | { | |
2777 | if (start) | |
2778 | { | |
2779 | wxChar *val = GetArgData(); | |
2780 | if (val) | |
2781 | { | |
2782 | if (textColourString) | |
2783 | delete[] textColourString; | |
2784 | textColourString = copystring(val); | |
2785 | } | |
2786 | } | |
2787 | return false; | |
2788 | } | |
2789 | case ltLINKCOLOUR: | |
2790 | { | |
2791 | if (start) | |
2792 | { | |
2793 | wxChar *val = GetArgData(); | |
2794 | if (val) | |
2795 | { | |
2796 | if (linkColourString) | |
2797 | delete[] linkColourString; | |
2798 | linkColourString = copystring(val); | |
2799 | } | |
2800 | } | |
2801 | return false; | |
2802 | } | |
2803 | case ltFOLLOWEDLINKCOLOUR: | |
2804 | { | |
2805 | if (start) | |
2806 | { | |
2807 | wxChar *val = GetArgData(); | |
2808 | if (val) | |
2809 | { | |
2810 | if (followedLinkColourString) | |
2811 | delete[] followedLinkColourString; | |
2812 | followedLinkColourString = copystring(val); | |
2813 | } | |
2814 | } | |
2815 | return false; | |
2816 | } | |
2817 | case ltACCENT_CADILLA: | |
2818 | { | |
2819 | if (start) | |
2820 | { | |
2821 | wxChar *val = GetArgData(); | |
2822 | if (val) | |
2823 | { | |
2824 | switch (val[0]) | |
2825 | { | |
2826 | case 'c': | |
2827 | TexOutput(_T("ç")); | |
2828 | break; | |
2829 | case 'C': | |
2830 | TexOutput(_T("Ç")); | |
2831 | break; | |
2832 | default: | |
2833 | break; | |
2834 | } | |
2835 | } | |
2836 | } | |
2837 | return false; | |
2838 | } | |
2839 | /* | |
2840 | case ltFOOTNOTE: | |
2841 | case ltFOOTNOTEPOPUP: | |
2842 | { | |
2843 | if (arg_no == 1) | |
2844 | return true; | |
2845 | else | |
2846 | return false; | |
2847 | break; | |
2848 | } | |
2849 | */ | |
2850 | case ltTABULAR: | |
2851 | case ltSUPERTABULAR: | |
2852 | { | |
2853 | if (arg_no == 1) | |
2854 | { | |
2855 | if (start) | |
2856 | { | |
2857 | currentRowNumber = 0; | |
2858 | inTabular = true; | |
2859 | startRows = true; | |
2860 | tableVerticalLineLeft = false; | |
2861 | tableVerticalLineRight = false; | |
2862 | ||
2863 | wxChar *alignString = copystring(GetArgData()); | |
2864 | ParseTableArgument(alignString); | |
2865 | ||
2866 | TexOutput(_T("<TABLE BORDER>\n")); | |
2867 | ||
2868 | // Write the first row formatting for compatibility | |
2869 | // with standard Latex | |
2870 | if (compatibilityMode) | |
2871 | { | |
2872 | TexOutput(_T("<TR>\n<TD>")); | |
2873 | OutputFont(); | |
2874 | /* | |
2875 | for (int i = 0; i < noColumns; i++) | |
2876 | { | |
2877 | currentWidth += TableData[i].width; | |
2878 | wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth); | |
2879 | TexOutput(buf); | |
2880 | } | |
2881 | TexOutput(_T("\\pard\\intbl\n")); | |
2882 | */ | |
2883 | } | |
2884 | delete[] alignString; | |
2885 | ||
2886 | return false; | |
2887 | } | |
2888 | } | |
2889 | else if (arg_no == 2 && !start) | |
2890 | { | |
2891 | TexOutput(_T("</TABLE>\n")); | |
2892 | inTabular = false; | |
2893 | } | |
2894 | break; | |
2895 | } | |
2896 | case ltTHEBIBLIOGRAPHY: | |
2897 | { | |
2898 | if (start && (arg_no == 1)) | |
2899 | { | |
2900 | ReopenFile(&Chapters, &ChaptersName, _T("bibliography")); | |
2901 | AddTexRef(_T("bibliography"), ChaptersName, _T("bibliography")); | |
2902 | SetCurrentSubsectionName(_T("bibliography"), ChaptersName); | |
2903 | ||
2904 | citeCount = 1; | |
2905 | ||
2906 | SetCurrentOutput(Chapters); | |
2907 | ||
2908 | wxChar titleBuf[150]; | |
2909 | if (truncateFilenames) | |
2910 | wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s.htm"), wxFileNameFromPath(FileRoot)); | |
2911 | else | |
2912 | wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s_contents.html"), wxFileNameFromPath(FileRoot)); | |
2913 | ||
2914 | HTMLHead(); | |
2915 | TexOutput(_T("<title>")); | |
2916 | TexOutput(ReferencesNameString); | |
2917 | TexOutput(_T("</title></head>\n")); | |
2918 | OutputBodyStart(); | |
2919 | ||
2920 | wxFprintf(Chapters, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString); | |
2921 | AddBrowseButtons(_T("contents"), titleBuf, // Up | |
2922 | lastTopic, lastFileName, // Last topic | |
2923 | _T("bibliography"), ChaptersName); // This topic | |
2924 | ||
2925 | SetCurrentOutputs(Contents, Chapters); | |
2926 | if(PrimaryAnchorOfTheFile(ChaptersName, _T("bibliography"))) | |
2927 | wxFprintf(Contents, _T("\n<LI><A HREF=\"%s\">"), ConvertCase(ChaptersName)); | |
2928 | else | |
2929 | wxFprintf(Contents, _T("\n<LI><A HREF=\"%s#%s\">"), ConvertCase(ChaptersName), _T("bibliography")); | |
2930 | ||
2931 | wxFprintf(Contents, _T("%s</A>\n"), ReferencesNameString); | |
2932 | wxFprintf(Chapters, _T("</H2>\n</A>\n")); | |
2933 | ||
2934 | SetCurrentOutput(Chapters); | |
2935 | return false; | |
2936 | } | |
2937 | if (!start && (arg_no == 2)) | |
2938 | { | |
2939 | } | |
2940 | return true; | |
2941 | } | |
2942 | case ltINDEX: | |
2943 | { | |
2944 | /* Build up list of keywords associated with topics */ | |
2945 | if (start) | |
2946 | { | |
2947 | // wxChar *entry = GetArgData(); | |
2948 | wxChar buf[300]; | |
2949 | OutputChunkToString(GetArgChunk(), buf); | |
2950 | if (CurrentTopic) | |
2951 | { | |
2952 | AddKeyWordForTopic(CurrentTopic, buf, currentFileName); | |
2953 | } | |
2954 | } | |
2955 | return false; | |
2956 | } | |
2957 | case ltFCOL: | |
2958 | // case ltBCOL: | |
2959 | { | |
2960 | if (start) | |
2961 | { | |
2962 | switch (arg_no) | |
2963 | { | |
2964 | case 1: | |
2965 | { | |
2966 | wxChar *name = GetArgData(); | |
2967 | wxChar buf2[10]; | |
2968 | if (!FindColourHTMLString(name, buf2)) | |
2969 | { | |
2970 | wxStrcpy(buf2, _T("#000000")); | |
2971 | wxChar buf[100]; | |
2972 | wxSnprintf(buf, sizeof(buf), _T("Could not find colour name %s"), name); | |
2973 | OnError(buf); | |
2974 | } | |
2975 | TexOutput(_T("<FONT COLOR=\"")); | |
2976 | TexOutput(buf2); | |
2977 | TexOutput(_T("\">")); | |
2978 | break; | |
2979 | } | |
2980 | case 2: | |
2981 | { | |
2982 | return true; | |
2983 | } | |
2984 | default: | |
2985 | break; | |
2986 | } | |
2987 | } | |
2988 | else | |
2989 | { | |
2990 | if (arg_no == 2) TexOutput(_T("</FONT>")); | |
2991 | } | |
2992 | return false; | |
2993 | } | |
2994 | case ltINSERTATLEVEL: | |
2995 | { | |
2996 | // This macro allows you to insert text at a different level | |
2997 | // from the current level, e.g. into the Sections from within a subsubsection. | |
2998 | if (useWord) | |
2999 | return false; | |
3000 | static int currentLevelNo = 1; | |
3001 | static FILE* oldLevelFile = Chapters; | |
3002 | if (start) | |
3003 | { | |
3004 | switch (arg_no) | |
3005 | { | |
3006 | case 1: | |
3007 | { | |
3008 | oldLevelFile = CurrentOutput1; | |
3009 | ||
3010 | wxChar *str = GetArgData(); | |
3011 | currentLevelNo = wxAtoi(str); | |
3012 | FILE* outputFile; | |
3013 | // TODO: cope with article style (no chapters) | |
3014 | switch (currentLevelNo) | |
3015 | { | |
3016 | case 1: | |
3017 | { | |
3018 | outputFile = Chapters; | |
3019 | break; | |
3020 | } | |
3021 | case 2: | |
3022 | { | |
3023 | outputFile = Sections; | |
3024 | break; | |
3025 | } | |
3026 | case 3: | |
3027 | { | |
3028 | outputFile = Subsections; | |
3029 | break; | |
3030 | } | |
3031 | case 4: | |
3032 | { | |
3033 | outputFile = Subsubsections; | |
3034 | break; | |
3035 | } | |
3036 | default: | |
3037 | { | |
3038 | outputFile = NULL; | |
3039 | break; | |
3040 | } | |
3041 | } | |
3042 | if (outputFile) | |
3043 | CurrentOutput1 = outputFile; | |
3044 | return false; | |
3045 | } | |
3046 | case 2: | |
3047 | { | |
3048 | return true; | |
3049 | } | |
3050 | default: | |
3051 | break; | |
3052 | } | |
3053 | return true; | |
3054 | } | |
3055 | else | |
3056 | { | |
3057 | if (arg_no == 2) | |
3058 | { | |
3059 | CurrentOutput1 = oldLevelFile; | |
3060 | } | |
3061 | return true; | |
3062 | } | |
3063 | } | |
3064 | default: | |
3065 | return DefaultOnArgument(macroId, arg_no, start); | |
3066 | } | |
3067 | return true; | |
3068 | } | |
3069 | ||
3070 | bool HTMLGo(void) | |
3071 | { | |
3072 | fileId = 0; | |
3073 | inVerbatim = false; | |
3074 | indentLevel = 0; | |
3075 | inTabular = false; | |
3076 | startRows = false; | |
3077 | tableVerticalLineLeft = false; | |
3078 | tableVerticalLineRight = false; | |
3079 | noColumns = 0; | |
3080 | ||
3081 | if (!InputFile.empty() && !OutputFile.empty()) | |
3082 | { | |
3083 | // Do some HTML-specific transformations on all the strings, | |
3084 | // recursively | |
3085 | Text2HTML(GetTopLevelChunk()); | |
3086 | ||
3087 | wxChar buf[300]; | |
3088 | if (truncateFilenames) | |
3089 | wxSnprintf(buf, sizeof(buf), _T("%s.htm"), FileRoot); | |
3090 | else | |
3091 | wxSnprintf(buf, sizeof(buf), _T("%s_contents.html"), FileRoot); | |
3092 | if (TitlepageName) delete[] TitlepageName; | |
3093 | TitlepageName = copystring(buf); | |
3094 | Titlepage = wxFopen(buf, _T("w")); | |
3095 | ||
3096 | if (truncateFilenames) | |
3097 | wxSnprintf(buf, sizeof(buf), _T("%s_fc.htm"), FileRoot); | |
3098 | else | |
3099 | wxSnprintf(buf, sizeof(buf), _T("%s_fcontents.html"), FileRoot); | |
3100 | ||
3101 | contentsFrameName = copystring(buf); | |
3102 | ||
3103 | Contents = wxFopen(TmpContentsName, _T("w")); | |
3104 | ||
3105 | if (htmlFrameContents) | |
3106 | { | |
3107 | // FrameContents = wxFopen(TmpFrameContentsName, _T("w")); | |
3108 | FrameContents = wxFopen(contentsFrameName, _T("w")); | |
3109 | wxFprintf(FrameContents, _T("<HTML>\n<UL>\n")); | |
3110 | } | |
3111 | ||
3112 | if (!Titlepage || !Contents) | |
3113 | { | |
3114 | OnError(_T("Cannot open output file!")); | |
3115 | return false; | |
3116 | } | |
3117 | AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName), ContentsNameString); | |
3118 | ||
3119 | wxFprintf(Contents, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString); | |
3120 | ||
3121 | wxFprintf(Contents, _T("<UL>\n")); | |
3122 | ||
3123 | SetCurrentOutput(Titlepage); | |
3124 | if (htmlWorkshopFiles) HTMLWorkshopStartContents(); | |
3125 | OnInform(_T("Converting...")); | |
3126 | ||
3127 | TraverseDocument(); | |
3128 | wxFprintf(Contents, _T("</UL>\n\n")); | |
3129 | ||
3130 | // SetCurrentOutput(Titlepage); | |
3131 | fclose(Titlepage); | |
3132 | ||
3133 | if (Contents) | |
3134 | { | |
3135 | // wxFprintf(Titlepage, _T("\n</BODY></HTML>\n")); | |
3136 | fclose(Contents); | |
3137 | Contents = NULL; | |
3138 | } | |
3139 | ||
3140 | if (FrameContents) | |
3141 | { | |
3142 | wxFprintf(FrameContents, _T("\n</UL>\n")); | |
3143 | wxFprintf(FrameContents, _T("</HTML>\n")); | |
3144 | fclose(FrameContents); | |
3145 | FrameContents = NULL; | |
3146 | } | |
3147 | ||
3148 | if (Chapters) | |
3149 | { | |
3150 | wxFprintf(Chapters, _T("\n</FONT></BODY></HTML>\n")); | |
3151 | fclose(Chapters); | |
3152 | Chapters = NULL; | |
3153 | } | |
3154 | if (Sections) | |
3155 | { | |
3156 | wxFprintf(Sections, _T("\n</FONT></BODY></HTML>\n")); | |
3157 | fclose(Sections); | |
3158 | Sections = NULL; | |
3159 | } | |
3160 | if (Subsections && !combineSubSections) | |
3161 | { | |
3162 | wxFprintf(Subsections, _T("\n</FONT></BODY></HTML>\n")); | |
3163 | fclose(Subsections); | |
3164 | Subsections = NULL; | |
3165 | } | |
3166 | if (Subsubsections && !combineSubSections) | |
3167 | { | |
3168 | wxFprintf(Subsubsections, _T("\n</FONT></BODY></HTML>\n")); | |
3169 | fclose(Subsubsections); | |
3170 | Subsubsections = NULL; | |
3171 | } | |
3172 | if ( SectionContentsFD ) | |
3173 | { | |
3174 | fclose(SectionContentsFD); | |
3175 | SectionContentsFD = NULL; | |
3176 | } | |
3177 | ||
3178 | // Create a temporary file for the title page header, add some info, | |
3179 | // and concat the titlepage just generated. | |
3180 | // This is necessary in order to put the title of the document | |
3181 | // at the TOP of the file within <HEAD>, even though we only find out | |
3182 | // what it is later on. | |
3183 | FILE *tmpTitle = wxFopen(_T("title.tmp"), _T("w")); | |
3184 | if (tmpTitle) | |
3185 | { | |
3186 | if (DocumentTitle) | |
3187 | { | |
3188 | SetCurrentOutput(tmpTitle); | |
3189 | HTMLHead(); | |
3190 | TexOutput(_T("\n<TITLE>")); | |
3191 | TraverseChildrenFromChunk(DocumentTitle); | |
3192 | TexOutput(_T("</TITLE></HEAD>\n")); | |
3193 | } | |
3194 | else | |
3195 | { | |
3196 | SetCurrentOutput(tmpTitle); | |
3197 | HTMLHeadTo(tmpTitle); | |
3198 | if (contentsString) | |
3199 | wxFprintf(tmpTitle, _T("<TITLE>%s</TITLE></HEAD>\n\n"), contentsString); | |
3200 | else | |
3201 | wxFprintf(tmpTitle, _T("<TITLE>%s</TITLE></HEAD>\n\n"), wxFileNameFromPath(FileRoot)); | |
3202 | } | |
3203 | ||
3204 | // Output frame information | |
3205 | if (htmlFrameContents) | |
3206 | { | |
3207 | wxChar firstFileName[300]; | |
3208 | if (truncateFilenames) | |
3209 | wxSnprintf(firstFileName, sizeof(firstFileName), _T("%s1.htm"), FileRoot); | |
3210 | else | |
3211 | wxStrcpy(firstFileName, gs_filenames[1].c_str()); | |
3212 | ||
3213 | wxFprintf(tmpTitle, _T("<FRAMESET COLS=\"30%%,70%%\">\n")); | |
3214 | ||
3215 | wxFprintf(tmpTitle, _T("<FRAME SRC=\"%s\">\n"), ConvertCase(wxFileNameFromPath(contentsFrameName))); | |
3216 | wxFprintf(tmpTitle, _T("<FRAME SRC=\"%s\" NAME=\"mainwindow\">\n"), ConvertCase(wxFileNameFromPath(firstFileName))); | |
3217 | wxFprintf(tmpTitle, _T("</FRAMESET>\n")); | |
3218 | ||
3219 | wxFprintf(tmpTitle, _T("<NOFRAMES>\n")); | |
3220 | } | |
3221 | ||
3222 | // Output <BODY...> to temporary title page | |
3223 | OutputBodyStart(); | |
3224 | fflush(tmpTitle); | |
3225 | ||
3226 | // Concat titlepage | |
3227 | FILE *fd = wxFopen(TitlepageName, _T("r")); | |
3228 | if (fd) | |
3229 | { | |
3230 | int ch = getc(fd); | |
3231 | while (ch != EOF) | |
3232 | { | |
3233 | wxPutc(ch, tmpTitle); | |
3234 | ch = getc(fd); | |
3235 | } | |
3236 | fclose(fd); | |
3237 | } | |
3238 | ||
3239 | wxFprintf(tmpTitle, _T("\n</FONT></BODY>\n")); | |
3240 | ||
3241 | if (htmlFrameContents) | |
3242 | { | |
3243 | wxFprintf(tmpTitle, _T("\n</NOFRAMES>\n")); | |
3244 | } | |
3245 | wxFprintf(tmpTitle, _T("\n</HTML>\n")); | |
3246 | ||
3247 | fclose(tmpTitle); | |
3248 | if (wxFileExists(TitlepageName)) wxRemoveFile(TitlepageName); | |
3249 | if (!wxRenameFile(_T("title.tmp"), TitlepageName)) | |
3250 | { | |
3251 | wxCopyFile(_T("title.tmp"), TitlepageName); | |
3252 | wxRemoveFile(_T("title.tmp")); | |
3253 | } | |
3254 | } | |
3255 | ||
3256 | if (lastFileName) delete[] lastFileName; | |
3257 | lastFileName = NULL; | |
3258 | if (lastTopic) delete[] lastTopic; | |
3259 | lastTopic = NULL; | |
3260 | ||
3261 | if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName); | |
3262 | ||
3263 | if (!wxRenameFile(TmpContentsName, ContentsName)) | |
3264 | { | |
3265 | wxCopyFile(TmpContentsName, ContentsName); | |
3266 | wxRemoveFile(TmpContentsName); | |
3267 | } | |
3268 | ||
3269 | // Generate .htx file if requested | |
3270 | if (htmlIndex) | |
3271 | { | |
3272 | wxChar htmlIndexName[300]; | |
3273 | wxSnprintf(htmlIndexName, sizeof(htmlIndexName), _T("%s.htx"), FileRoot); | |
3274 | GenerateHTMLIndexFile(htmlIndexName); | |
3275 | } | |
3276 | ||
3277 | // Generate HTML Help Workshop files if requested | |
3278 | if (htmlWorkshopFiles) | |
3279 | { | |
3280 | HTMLWorkshopEndContents(); | |
3281 | GenerateHTMLWorkshopFiles(FileRoot); | |
3282 | } | |
3283 | ||
3284 | return true; | |
3285 | } | |
3286 | ||
3287 | return false; | |
3288 | } | |
3289 | ||
3290 | // Output .htx index file | |
3291 | void GenerateHTMLIndexFile(wxChar *fname) | |
3292 | { | |
3293 | FILE *fd = wxFopen(fname, _T("w")); | |
3294 | if (!fd) | |
3295 | return; | |
3296 | ||
3297 | TopicTable.BeginFind(); | |
3298 | wxHashTable::Node *node = TopicTable.Next(); | |
3299 | while (node) | |
3300 | { | |
3301 | TexTopic *texTopic = (TexTopic *)node->GetData(); | |
3302 | const wxChar *topicName = node->GetKeyString(); | |
3303 | if (texTopic->filename && texTopic->keywords) | |
3304 | { | |
3305 | wxStringListNode *node1 = texTopic->keywords->GetFirst(); | |
3306 | while (node1) | |
3307 | { | |
3308 | wxChar *s = (wxChar *)node1->GetData(); | |
3309 | wxFprintf(fd, _T("%s|%s|%s\n"), topicName, texTopic->filename, s); | |
3310 | node1 = node1->GetNext(); | |
3311 | } | |
3312 | } | |
3313 | node = TopicTable.Next(); | |
3314 | } | |
3315 | fclose(fd); | |
3316 | } | |
3317 | ||
3318 | ||
3319 | ||
3320 | ||
3321 | ||
3322 | ||
3323 | ||
3324 | // output .hpp, .hhc and .hhk files: | |
3325 | ||
3326 | ||
3327 | void GenerateHTMLWorkshopFiles(wxChar *fname) | |
3328 | { | |
3329 | FILE *f; | |
3330 | wxChar buf[300]; | |
3331 | ||
3332 | /* Generate project file : */ | |
3333 | ||
3334 | wxSnprintf(buf, sizeof(buf), _T("%s.hhp"), fname); | |
3335 | f = wxFopen(buf, _T("wt")); | |
3336 | wxFprintf(f, | |
3337 | _T("[OPTIONS]\n") | |
3338 | _T("Compatibility=1.1\n") | |
3339 | _T("Full-text search=Yes\n") | |
3340 | _T("Contents file=%s.hhc\n") | |
3341 | _T("Compiled file=%s.chm\n") | |
3342 | _T("Default Window=%sHelp\n") | |
3343 | _T("Default topic=%s\n") | |
3344 | _T("Index file=%s.hhk\n") | |
3345 | _T("Title="), | |
3346 | wxFileNameFromPath(fname), | |
3347 | wxFileNameFromPath(fname), | |
3348 | wxFileNameFromPath(fname), | |
3349 | wxFileNameFromPath(TitlepageName), | |
3350 | wxFileNameFromPath(fname) | |
3351 | ); | |
3352 | ||
3353 | if (DocumentTitle) { | |
3354 | SetCurrentOutput(f); | |
3355 | TraverseChildrenFromChunk(DocumentTitle); | |
3356 | } | |
3357 | else wxFprintf(f, _T("(unknown)")); | |
3358 | ||
3359 | wxFprintf(f, _T("\n\n[WINDOWS]\n") | |
3360 | _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"), | |
3361 | wxFileNameFromPath(fname), | |
3362 | wxFileNameFromPath(fname), | |
3363 | wxFileNameFromPath(fname), | |
3364 | wxFileNameFromPath(TitlepageName)); | |
3365 | ||
3366 | ||
3367 | wxFprintf(f, _T("\n\n[FILES]\n")); | |
3368 | wxFprintf(f, _T("%s\n"), wxFileNameFromPath(TitlepageName)); | |
3369 | for (int i = 1; i <= fileId; i++) { | |
3370 | if (truncateFilenames) | |
3371 | wxSnprintf(buf, sizeof(buf), _T("%s%d.htm"), wxFileNameFromPath(FileRoot), i); | |
3372 | else | |
3373 | wxStrcpy(buf, wxFileNameFromPath(gs_filenames[i].c_str())); | |
3374 | wxFprintf(f, _T("%s\n"), buf); | |
3375 | } | |
3376 | fclose(f); | |
3377 | ||
3378 | /* Generate index file : */ | |
3379 | ||
3380 | wxSnprintf(buf, sizeof(buf), _T("%s.hhk"), fname); | |
3381 | f = wxFopen(buf, _T("wt")); | |
3382 | ||
3383 | wxFprintf(f, | |
3384 | _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n") | |
3385 | _T("<HTML>\n")); | |
3386 | HTMLHeadTo(f); | |
3387 | wxFprintf(f, | |
3388 | _T("\n") | |
3389 | _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n") | |
3390 | _T("<!-- Sitemap 1.0 -->\n") | |
3391 | _T("</HEAD><BODY>\n") | |
3392 | _T("<OBJECT type=\"text/site properties\">\n") | |
3393 | _T(" <param name=\"ImageType\" value=\"Folder\">\n") | |
3394 | _T("</OBJECT>\n") | |
3395 | _T("<UL>\n")); | |
3396 | ||
3397 | TopicTable.BeginFind(); | |
3398 | wxHashTable::Node *node = TopicTable.Next(); | |
3399 | while (node) | |
3400 | { | |
3401 | TexTopic *texTopic = (TexTopic *)node->GetData(); | |
3402 | const wxChar *topicName = node->GetKeyString(); | |
3403 | if (texTopic->filename && texTopic->keywords) | |
3404 | { | |
3405 | wxStringListNode *node1 = texTopic->keywords->GetFirst(); | |
3406 | while (node1) | |
3407 | { | |
3408 | wxChar *s = (wxChar *)node1->GetData(); | |
3409 | wxFprintf(f, | |
3410 | _T(" <LI> <OBJECT type=\"text/sitemap\">\n") | |
3411 | _T(" <param name=\"Local\" value=\"%s#%s\">\n") | |
3412 | _T(" <param name=\"Name\" value=\"%s\">\n") | |
3413 | _T(" </OBJECT>\n"), | |
3414 | texTopic->filename, topicName, s); | |
3415 | node1 = node1->GetNext(); | |
3416 | } | |
3417 | } | |
3418 | node = TopicTable.Next(); | |
3419 | } | |
3420 | ||
3421 | wxFprintf(f, _T("</UL>\n")); | |
3422 | fclose(f); | |
3423 | } | |
3424 | ||
3425 | ||
3426 | ||
3427 | static FILE *HTMLWorkshopContents = NULL; | |
3428 | static int HTMLWorkshopLastLevel = 0; | |
3429 | ||
3430 | void HTMLWorkshopAddToContents(int level, wxChar *s, wxChar *file) | |
3431 | { | |
3432 | int i; | |
3433 | ||
3434 | if (level > HTMLWorkshopLastLevel) | |
3435 | for (i = HTMLWorkshopLastLevel; i < level; i++) | |
3436 | wxFprintf(HTMLWorkshopContents, _T("<UL>")); | |
3437 | if (level < HTMLWorkshopLastLevel) | |
3438 | for (i = level; i < HTMLWorkshopLastLevel; i++) | |
3439 | wxFprintf(HTMLWorkshopContents, _T("</UL>")); | |
3440 | ||
3441 | SetCurrentOutput(HTMLWorkshopContents); | |
3442 | wxFprintf(HTMLWorkshopContents, | |
3443 | _T(" <LI> <OBJECT type=\"text/sitemap\">\n") | |
3444 | _T(" <param name=\"Local\" value=\"%s#%s\">\n") | |
3445 | _T(" <param name=\"Name\" value=\""), | |
3446 | file, s); | |
3447 | OutputCurrentSection(); | |
3448 | wxFprintf(HTMLWorkshopContents, | |
3449 | _T("\">\n") | |
3450 | _T(" </OBJECT>\n")); | |
3451 | HTMLWorkshopLastLevel = level; | |
3452 | } | |
3453 | ||
3454 | ||
3455 | void HTMLWorkshopStartContents() | |
3456 | { | |
3457 | wxChar buf[300]; | |
3458 | wxSnprintf(buf, sizeof(buf), _T("%s.hhc"), FileRoot); | |
3459 | HTMLWorkshopContents = wxFopen(buf, _T("wt")); | |
3460 | HTMLWorkshopLastLevel = 0; | |
3461 | ||
3462 | wxFprintf(HTMLWorkshopContents, | |
3463 | _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n") | |
3464 | _T("<HTML>\n")); | |
3465 | HTMLHeadTo(HTMLWorkshopContents); | |
3466 | wxFprintf(HTMLWorkshopContents, | |
3467 | _T("\n") | |
3468 | _T("<meta name=\"GENERATOR\" content=\"tex2rtf\">\n") | |
3469 | _T("<!-- Sitemap 1.0 -->\n") | |
3470 | _T("</HEAD><BODY>\n") | |
3471 | _T("<OBJECT type=\"text/site properties\">\n") | |
3472 | _T(" <param name=\"ImageType\" value=\"Folder\">\n") | |
3473 | _T("</OBJECT>\n") | |
3474 | _T("<UL>\n") | |
3475 | _T("<LI> <OBJECT type=\"text/sitemap\">\n") | |
3476 | _T("<param name=\"Local\" value=\"%s\">\n") | |
3477 | _T("<param name=\"Name\" value=\"Contents\">\n</OBJECT>\n"), | |
3478 | wxFileNameFromPath(TitlepageName) | |
3479 | ); | |
3480 | ||
3481 | } | |
3482 | ||
3483 | ||
3484 | void HTMLWorkshopEndContents() | |
3485 | { | |
3486 | for (int i = HTMLWorkshopLastLevel; i >= 0; i--) | |
3487 | wxFprintf(HTMLWorkshopContents, _T("</UL>\n")); | |
3488 | fclose(HTMLWorkshopContents); | |
3489 | } | |
3490 | ||
3491 | ||
3492 | bool PrimaryAnchorOfTheFile( wxChar *file, wxChar *label ) | |
3493 | { | |
3494 | wxString file_label; | |
3495 | file_label.Printf( HTML_FILENAME_PATTERN, FileRoot, label ); | |
3496 | return file_label.IsSameAs( file , false ); | |
3497 | } |