]> git.saurik.com Git - wxWidgets.git/blame - utils/tex2rtf/src/htmlutil.cpp
more code simplification
[wxWidgets.git] / utils / tex2rtf / src / htmlutil.cpp
CommitLineData
9a29912f
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: htmlutil.cpp
3// Purpose: Converts Latex to HTML
4// Author: Julian Smart
ae6c0ccf 5// Modified by: Wlodzimierz ABX Skiba 2003/2004 Unicode support
b63b07a8 6// Ron Lee
9a29912f
JS
7// Created: 7.9.93
8// RCS-ID: $Id$
9// Copyright: (c) Julian Smart
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
9a29912f
JS
13// For compilers that support precompilation, includes "wx.h".
14#include "wx/wxprec.h"
15
16#ifdef __BORLANDC__
17#pragma hdrstop
18#endif
19
20#ifndef WX_PRECOMP
9a29912f
JS
21#endif
22
66828481
VS
23#include "wx/arrstr.h"
24
9a29912f
JS
25#include "tex2any.h"
26#include "tex2rtf.h"
27#include "table.h"
4116fac0 28#include <stdio.h>
ae6c0ccf
WS
29#define HTML_FILENAME_PATTERN _T("%s_%s.html")
30
ea172e69
MB
31static inline wxChar* copystring(const wxChar* s)
32 { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
3924dd22
GT
33
34extern wxHashTable TexReferences;
35
7e9968f7 36extern int passNumber;
3924dd22 37
6c155d33
JS
38extern void DecToHex(int, wxChar *);
39void GenerateHTMLIndexFile(wxChar *fname);
14204c7a 40
ae6c0ccf
WS
41bool PrimaryAnchorOfTheFile( wxChar *file, wxChar *label );
42
6c155d33
JS
43void GenerateHTMLWorkshopFiles(wxChar *fname);
44void HTMLWorkshopAddToContents(int level, wxChar *s, wxChar *file);
14204c7a
VS
45void HTMLWorkshopStartContents();
46void HTMLWorkshopEndContents();
47
9a29912f
JS
48void OutputContentsFrame(void);
49
50#include "readshg.h" // Segmented hypergraphics parsing
51
6c155d33
JS
52wxChar *ChaptersName = NULL;
53wxChar *SectionsName = NULL;
54wxChar *SubsectionsName = NULL;
55wxChar *SubsubsectionsName = NULL;
56wxChar *TitlepageName = NULL;
57wxChar *lastFileName = NULL;
58wxChar *lastTopic = NULL;
59wxChar *currentFileName = NULL;
60wxChar *contentsFrameName = NULL;
9a29912f
JS
61
62static TexChunk *descriptionItemArg = NULL;
63static TexChunk *helpRefFilename = NULL;
64static TexChunk *helpRefText = NULL;
65static int indentLevel = 0;
66static int citeCount = 1;
67extern FILE *Contents;
68FILE *FrameContents = NULL;
69FILE *Titlepage = NULL;
70// FILE *FrameTitlepage = NULL;
71int fileId = 0;
b63b07a8 72bool subsectionStarted = false;
9a29912f
JS
73
74// Which column of a row are we in? (Assumes no nested tables, of course)
75int currentColumn = 0;
76
77// Are we in verbatim mode? If so, format differently.
b63b07a8 78static bool inVerbatim = false;
9a29912f
JS
79
80// Need to know whether we're in a table or figure for benefit
81// of listoffigures/listoftables
b63b07a8
RL
82static bool inFigure = false;
83static bool inTable = false;
9a29912f
JS
84
85// This is defined in the Tex2Any library.
6c155d33 86extern wxChar *BigBuffer;
9a29912f 87
c103ca4b
JS
88// DHS Two-column table dimensions.
89static int TwoColWidthA = -1;
90static int TwoColWidthB = -1;
91
92
9a29912f
JS
93class HyperReference: public wxObject
94{
95 public:
6c155d33
JS
96 wxChar *refName;
97 wxChar *refFile;
98 HyperReference(wxChar *name, wxChar *file)
9a29912f
JS
99 {
100 if (name) refName = copystring(name);
101 if (file) refFile = copystring(file);
102 }
103};
104
105class TexNextPage: public wxObject
106{
107 public:
6c155d33
JS
108 wxChar *label;
109 wxChar *filename;
110 TexNextPage(wxChar *theLabel, wxChar *theFile)
9a29912f
JS
111 {
112 label = copystring(theLabel);
113 filename = copystring(theFile);
114 }
d3c7fc99 115 virtual ~TexNextPage(void)
9a29912f
JS
116 {
117 delete[] label;
118 delete[] filename;
119 }
120};
121
122wxHashTable TexNextPages(wxKEY_STRING);
123
6c155d33
JS
124static wxChar *CurrentChapterName = NULL;
125static wxChar *CurrentChapterFile = NULL;
126static wxChar *CurrentSectionName = NULL;
127static wxChar *CurrentSectionFile = NULL;
128static wxChar *CurrentSubsectionName = NULL;
129static wxChar *CurrentSubsectionFile = NULL;
130static wxChar *CurrentSubsubsectionName = NULL;
131static wxChar *CurrentSubsubsectionFile = NULL;
132static wxChar *CurrentTopic = NULL;
133
134static void SetCurrentTopic(wxChar *s)
9a29912f
JS
135{
136 if (CurrentTopic) delete[] CurrentTopic;
137 CurrentTopic = copystring(s);
138}
139
6c155d33 140void SetCurrentChapterName(wxChar *s, wxChar *file)
9a29912f
JS
141{
142 if (CurrentChapterName) delete[] CurrentChapterName;
143 CurrentChapterName = copystring(s);
144 if (CurrentChapterFile) delete[] CurrentChapterFile;
145 CurrentChapterFile = copystring(file);
146
147 currentFileName = CurrentChapterFile;
119f7a8c 148
9a29912f
JS
149 SetCurrentTopic(s);
150}
6c155d33 151void SetCurrentSectionName(wxChar *s, wxChar *file)
9a29912f
JS
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}
6c155d33 161void SetCurrentSubsectionName(wxChar *s, wxChar *file)
9a29912f
JS
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}
6c155d33 170void SetCurrentSubsubsectionName(wxChar *s, wxChar *file)
9a29912f
JS
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
66828481
VS
180
181// mapping between fileId and filenames if truncateFilenames=false:
182static wxArrayString gs_filenames;
183
184
9a29912f
JS
185/*
186 * Close former filedescriptor and reopen using another filename.
187 *
188 */
189
66828481 190void ReopenFile(FILE **fd, wxChar **fileName, const wxChar *label)
9a29912f
JS
191{
192 if (*fd)
193 {
6c155d33 194 wxFprintf(*fd, _T("\n</FONT></BODY></HTML>\n"));
9a29912f
JS
195 fclose(*fd);
196 }
197 fileId ++;
6c155d33 198 wxChar buf[400];
9a29912f 199 if (truncateFilenames)
66828481 200 {
b63b07a8 201 wxSnprintf(buf, sizeof(buf), _T("%s%d.htm"), FileRoot, fileId);
66828481 202 }
9a29912f 203 else
66828481 204 {
e6a0295c
VS
205 if (fileId == 1)
206 gs_filenames.Add(wxEmptyString);
ae6c0ccf 207 wxSnprintf(buf, sizeof(buf), HTML_FILENAME_PATTERN, FileRoot, label);
e6a0295c 208 gs_filenames.Add(buf);
66828481 209 }
9a29912f 210 if (*fileName) delete[] *fileName;
2b5f62a0 211 *fileName = copystring(wxFileNameFromPath(buf));
6c155d33
JS
212 *fd = wxFopen(buf, _T("w"));
213 wxFprintf(*fd, _T("<HTML>\n"));
9a29912f
JS
214}
215
216/*
217 * Reopen section contents file, i.e. the index appended to each section
218 * in subsectionCombine mode
219 */
220
6c155d33 221static wxChar *SectionContentsFilename = NULL;
9a29912f
JS
222static FILE *SectionContentsFD = NULL;
223
224void 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 {
6c155d33
JS
238 wxChar buf[256];
239 wxStrcpy(buf, CurrentSectionFile);
9a29912f 240 wxStripExtension(buf);
6c155d33 241 wxStrcat(buf, _T(".con"));
9a29912f
JS
242 SectionContentsFilename = copystring(buf);
243
6c155d33 244 SectionContentsFD = wxFopen(SectionContentsFilename, _T("w"));
9a29912f
JS
245 }
246}
247
248
0727e0a7
VZ
249
250
251struct textreplace
252{
253 wxChar *text;
f252b658 254 size_t text_length;
0727e0a7 255 wxChar *replace;
f252b658 256 size_t replace_length;
0727e0a7
VZ
257};
258
259#define tr(x,y) {x, sizeof(x)-1, y, sizeof(y)-1}
260
261static textreplace notverb_array[] =
262{
0727e0a7
VZ
263 tr(_T("``"), _T("&#8220;")),
264 tr(_T("''"), _T("&#8221;")),
265 tr(_T("`"), _T("&#8216;")),
266 tr(_T("'"), _T("&#8217;")),
267 tr(_T("---"), _T("&#8212;")),
268 tr(_T("--"), _T("&#8211;")),
269};
270
271#undef tr
272
9a29912f
JS
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 */
119f7a8c 278
9a29912f
JS
279void ProcessText2HTML(TexChunk *chunk)
280{
b63b07a8 281 bool changed = false;
9a29912f
JS
282 int ptr = 0;
283 int i = 0;
1b392b3a 284 wxChar ch = 1;
f252b658 285 size_t len = wxStrlen(chunk->value);
9a29912f
JS
286 while (ch != 0)
287 {
288 ch = chunk->value[i];
289
0727e0a7 290 if (ch == _T('<')) // Change < to &lt
9a29912f
JS
291 {
292 BigBuffer[ptr] = 0;
6c155d33 293 wxStrcat(BigBuffer, _T("&lt;"));
9a29912f
JS
294 ptr += 4;
295 i += 1;
0727e0a7 296 len--;
b63b07a8 297 changed = true;
9a29912f 298 }
1b392b3a 299 else if (ch == _T('>')) // Change > to &gt
9a29912f
JS
300 {
301 BigBuffer[ptr] = 0;
6c155d33 302 wxStrcat(BigBuffer, _T("&gt;"));
9a29912f
JS
303 ptr += 4;
304 i += 1;
0727e0a7 305 len--;
b63b07a8 306 changed = true;
9a29912f
JS
307 }
308 else
309 {
0727e0a7
VZ
310 bool replaced = false;
311 if (!inVerbatim)
312 {
f252b658 313 for (size_t x = 0; x < WXSIZEOF(notverb_array); x++)
0727e0a7
VZ
314 {
315 textreplace& tr = notverb_array[x];
f252b658
VZ
316 if (ch != tr.text[0])
317 continue;
318 if (len < tr.text_length)
319 continue;
0727e0a7 320
f252b658 321 size_t y;
0727e0a7
VZ
322 for (y = 1; y < tr.text_length; y++)
323 {
f252b658
VZ
324 if (chunk->value[y] != tr.text[y])
325 break;
0727e0a7 326 }
f252b658
VZ
327
328 if (y != tr.text_length)
329 continue;
0727e0a7
VZ
330
331 // can now copy it over.
332 for (y = 0; y < tr.replace_length; y++)
333 {
334 BigBuffer[ptr++] = tr.replace[y];
335 }
f252b658 336
0727e0a7
VZ
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 }
9a29912f
JS
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 */
119f7a8c 370
9a29912f
JS
371void 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))
b63b07a8 386 inVerbatim = true;
9a29912f 387
ddc4f3b5 388 wxNode *node = chunk->children.GetFirst();
9a29912f
JS
389 while (node)
390 {
ddc4f3b5 391 TexChunk *child_chunk = (TexChunk *)node->GetData();
9a29912f 392 Text2HTML(child_chunk);
ddc4f3b5 393 node = node->GetNext();
9a29912f
JS
394 }
395
396 if (def && (def->macroId == ltVERBATIM || def->macroId == ltVERB || def->macroId == ltSPECIAL))
b63b07a8 397 inVerbatim = false;
9a29912f
JS
398
399 break;
400 }
401 case CHUNK_TYPE_ARG:
402 {
ddc4f3b5 403 wxNode *node = chunk->children.GetFirst();
9a29912f
JS
404 while (node)
405 {
ddc4f3b5 406 TexChunk *child_chunk = (TexChunk *)node->GetData();
9a29912f 407 Text2HTML(child_chunk);
ddc4f3b5 408 node = node->GetNext();
9a29912f
JS
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
6c155d33
JS
427void AddBrowseButtons(wxChar *upLabel, wxChar *upFilename,
428 wxChar *previousLabel, wxChar *previousFilename,
429 wxChar *thisLabel, wxChar *thisFilename)
9a29912f 430{
6c155d33
JS
431 wxChar contentsReferenceBuf[80];
432 wxChar upReferenceBuf[80];
433 wxChar backReferenceBuf[80];
434 wxChar forwardReferenceBuf[80];
9a29912f
JS
435 if (htmlBrowseButtons == HTML_BUTTONS_NONE)
436 return;
437
6c155d33 438 wxChar *contentsReference; // no need to initialize because always assigned below
9a29912f
JS
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;
b63b07a8
RL
445 wxSnprintf(contentsReference, sizeof(contentsReferenceBuf),
446 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Contents\">"),
447 ConvertCase(_T("contents.gif")));
9a29912f 448 }
119f7a8c 449
6c155d33 450 wxChar *upReference; // no need to initialize because always assigned below
9a29912f
JS
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;
b63b07a8
RL
457 wxSnprintf(upReference, sizeof(upReferenceBuf),
458 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Up\">"),
459 ConvertCase(_T("up.gif")));
9a29912f 460 }
119f7a8c 461
6c155d33 462 wxChar *backReference; // no need to initialize because always assigned below
9a29912f 463 if (htmlBrowseButtons == HTML_BUTTONS_TEXT)
6c155d33 464 backReference = _T("&lt;&lt;");
9a29912f
JS
465 else
466 {
467// backReference = "<img align=center src=\"back.gif\" ALT=\"Previous\">";
468 backReference = backReferenceBuf;
b63b07a8
RL
469 wxSnprintf(backReference, sizeof(backReferenceBuf),
470 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Previous\">"),
471 ConvertCase(_T("back.gif")));
9a29912f 472 }
119f7a8c 473
6c155d33 474 wxChar *forwardReference; // no need to initialize because always assigned below
9a29912f 475 if (htmlBrowseButtons == HTML_BUTTONS_TEXT)
6c155d33 476 forwardReference = _T("&gt;&gt;");
9a29912f
JS
477 else
478 {
479// forwardReference = "<img align=center src=\"forward.gif\" ALT=\"Next\">";
480 forwardReference = forwardReferenceBuf;
b63b07a8
RL
481 wxSnprintf(forwardReference, sizeof(forwardReferenceBuf),
482 _T("<img align=center src=\"%s\" BORDER=0 ALT=\"Next\">"),
483 ConvertCase(_T("forward.gif")));
9a29912f 484 }
119f7a8c 485
6c155d33 486 TexOutput(_T("<CENTER>"));
119f7a8c 487
6c155d33 488 wxChar buf[200];
9a29912f
JS
489
490 /*
491 * Contents button
492 *
493 */
494
495 if (truncateFilenames)
496 {
6c155d33
JS
497 wxChar buf1[80];
498 wxStrcpy(buf1, ConvertCase(wxFileNameFromPath(FileRoot)));
b63b07a8
RL
499 wxSnprintf(buf, sizeof(buf),
500 _T("\n<A HREF=\"%s.%s\">%s</A> "),
501 buf1, ConvertCase(_T("htm")), contentsReference);
9a29912f
JS
502 }
503 else
504 {
6c155d33
JS
505 wxChar buf1[80];
506 wxStrcpy(buf1, ConvertCase(wxFileNameFromPath(FileRoot)));
b63b07a8
RL
507 wxSnprintf(buf, sizeof(buf),
508 _T("\n<A HREF=\"%s%s\">%s</A> "),
509 buf1, ConvertCase(_T("_contents.html")), contentsReference);
9a29912f 510 }
6c155d33 511// TexOutput(_T("<NOFRAMES>"));
9a29912f 512 TexOutput(buf);
6c155d33 513// TexOutput(_T("</NOFRAMES>"));
9a29912f
JS
514
515 /*
516 * Up button
517 *
518 */
519
520 if (upLabel && upFilename)
521 {
ae6c0ccf 522 if ( (wxStrlen(upLabel) > 0) && !PrimaryAnchorOfTheFile(upFilename, upLabel) )
b63b07a8
RL
523 wxSnprintf(buf, sizeof(buf),
524 _T("<A HREF=\"%s#%s\">%s</A> "),
525 ConvertCase(upFilename), upLabel, upReference);
9a29912f 526 else
b63b07a8
RL
527 wxSnprintf(buf, sizeof(buf),
528 _T("<A HREF=\"%s\">%s</A> "),
529 ConvertCase(upFilename), upReference);
6c155d33 530 if (wxStrcmp(upLabel, _T("contents")) == 0)
9a29912f 531 {
6c155d33 532// TexOutput(_T("<NOFRAMES>"));
9a29912f 533 TexOutput(buf);
6c155d33 534// TexOutput(_T("</NOFRAMES>"));
9a29912f
JS
535 }
536 else
537 TexOutput(buf);
538 }
539
540 /*
541 * << button
542 *
543 */
544
545 if (previousLabel && previousFilename)
546 {
ae6c0ccf
WS
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);
6c155d33 555 if (wxStrcmp(previousLabel, _T("contents")) == 0)
9a29912f 556 {
6c155d33 557// TexOutput(_T("<NOFRAMES>"));
9a29912f 558 TexOutput(buf);
6c155d33 559// TexOutput(_T("</NOFRAMES>"));
9a29912f
JS
560 }
561 else
562 TexOutput(buf);
563 }
564 else
565 {
566 // A placeholder so the buttons don't keep moving position
b63b07a8 567 wxSnprintf(buf, sizeof(buf), _T("%s "), backReference);
9a29912f
JS
568 TexOutput(buf);
569 }
570
6c155d33
JS
571 wxChar *nextLabel = NULL;
572 wxChar *nextFilename = NULL;
9a29912f
JS
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 {
ae6c0ccf
WS
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);
9a29912f
JS
609 TexOutput(buf);
610 }
611 else
612 {
613 // A placeholder so the buttons don't keep moving position
b63b07a8 614 wxSnprintf(buf, sizeof(buf), _T("%s "), forwardReference);
9a29912f
JS
615 TexOutput(buf);
616 }
617
618 /*
619 * Horizontal rule to finish it off nicely.
620 *
621 */
6c155d33
JS
622 TexOutput(_T("</CENTER>"));
623 TexOutput(_T("<HR>\n"));
9a29912f
JS
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
6c155d33 636wxChar *ParseColourString(wxChar *bkStr, bool *isPicture)
9a29912f 637{
6c155d33
JS
638 static wxChar resStr[300];
639 wxStrcpy(resStr, bkStr);
640 wxStringTokenizer tok(resStr, _T(";"), wxTOKEN_STRTOK);
641 if (tok.HasMoreTokens())
9a29912f 642 {
6c155d33
JS
643 wxString token1 = tok.GetNextToken();
644 if (!tok.HasMoreTokens())
9a29912f 645 {
b63b07a8 646 *isPicture = true;
9a29912f
JS
647 return resStr;
648 }
649 else
650 {
6c155d33 651 wxString token2 = tok.GetNextToken();
b63b07a8 652 *isPicture = false;
6c155d33 653 if (tok.HasMoreTokens())
9a29912f 654 {
6c155d33
JS
655 wxString token3 = tok.GetNextToken();
656
9a29912f 657 // Now convert 3 strings into decimal numbers, and then hex numbers.
6c155d33
JS
658 int red = wxAtoi(token1.c_str());
659 int green = wxAtoi(token2.c_str());
660 int blue = wxAtoi(token3.c_str());
119f7a8c 661
6c155d33 662 wxStrcpy(resStr, _T("#"));
119f7a8c 663
6c155d33 664 wxChar buf[3];
9a29912f 665 DecToHex(red, buf);
6c155d33 666 wxStrcat(resStr, buf);
9a29912f 667 DecToHex(green, buf);
6c155d33 668 wxStrcat(resStr, buf);
9a29912f 669 DecToHex(blue, buf);
6c155d33 670 wxStrcat(resStr, buf);
9a29912f
JS
671 return resStr;
672 }
673 else return NULL;
674 }
675 }
676 else return NULL;
677}
678
d7d17624
JS
679void OutputFont(void)
680{
2b5f62a0
VZ
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:
d7d17624 684 if (htmlFaceName)
2b5f62a0
VZ
685 {
686 // Output <FONT FACE=...>
6c155d33 687 TexOutput(_T("<FONT FACE=\""));
2b5f62a0 688 TexOutput(htmlFaceName);
6c155d33 689 TexOutput(_T("\">\n"));
2b5f62a0 690 }
d7d17624
JS
691}
692
9a29912f
JS
693// Output start of <BODY> block
694void OutputBodyStart(void)
695{
6c155d33 696 TexOutput(_T("\n<BODY"));
9a29912f
JS
697 if (backgroundImageString)
698 {
b63b07a8 699 bool isPicture = false;
6c155d33 700 wxChar *s = ParseColourString(backgroundImageString, &isPicture);
9a29912f
JS
701 if (s)
702 {
6c155d33 703 TexOutput(_T(" BACKGROUND=\""));
7e9968f7 704 TexOutput(s);
6c155d33 705 TexOutput(_T("\""));
9a29912f
JS
706 }
707 }
708 if (backgroundColourString)
709 {
b63b07a8 710 bool isPicture = false;
6c155d33 711 wxChar *s = ParseColourString(backgroundColourString, &isPicture);
9a29912f
JS
712 if (s)
713 {
6c155d33
JS
714 TexOutput(_T(" BGCOLOR="));
715 TexOutput(s);
9a29912f
JS
716 }
717 }
119f7a8c 718
9a29912f
JS
719 // Set foreground text colour, if one is specified
720 if (textColourString)
721 {
b63b07a8 722 bool isPicture = false;
6c155d33 723 wxChar *s = ParseColourString(textColourString, &isPicture);
9a29912f
JS
724 if (s)
725 {
6c155d33 726 TexOutput(_T(" TEXT=")); TexOutput(s);
9a29912f
JS
727 }
728 }
729 // Set link text colour, if one is specified
730 if (linkColourString)
731 {
b63b07a8 732 bool isPicture = false;
6c155d33 733 wxChar *s = ParseColourString(linkColourString, &isPicture);
9a29912f
JS
734 if (s)
735 {
6c155d33 736 TexOutput(_T(" LINK=")); TexOutput(s);
9a29912f
JS
737 }
738 }
739 // Set followed link text colour, if one is specified
740 if (followedLinkColourString)
741 {
b63b07a8 742 bool isPicture = false;
6c155d33 743 wxChar *s = ParseColourString(followedLinkColourString, &isPicture);
9a29912f
JS
744 if (s)
745 {
6c155d33 746 TexOutput(_T(" VLINK=")); TexOutput(s);
9a29912f
JS
747 }
748 }
6c155d33 749 TexOutput(_T(">\n"));
d7d17624
JS
750
751 OutputFont();
9a29912f
JS
752}
753
6d8b260c
VS
754void HTMLHead()
755{
6c155d33 756 TexOutput(_T("<head>"));
6d8b260c 757 if (htmlStylesheet) {
6c155d33 758 TexOutput(_T("<link rel=stylesheet type=\"text/css\" href=\""));
6d8b260c 759 TexOutput(htmlStylesheet);
6c155d33 760 TexOutput(_T("\">"));
6d8b260c
VS
761 }
762};
763
764void HTMLHeadTo(FILE* f)
765{
766 if (htmlStylesheet)
6c155d33 767 wxFprintf(f,_T("<head><link rel=stylesheet type=\"text/css\" href=\"%s\">"),htmlStylesheet);
6d8b260c 768 else
6c155d33 769 wxFprintf(f,_T("<head>"));
6d8b260c
VS
770}
771
9a29912f
JS
772// Called on start/end of macro examination
773void 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);
b63b07a8 791 startedSections = true;
9a29912f 792
6c155d33 793 wxChar *topicName = FindTopicName(GetNextChunk());
66828481 794 ReopenFile(&Chapters, &ChaptersName, topicName);
9a29912f
JS
795 AddTexRef(topicName, ChaptersName, ChapterNameString);
796
797 SetCurrentChapterName(topicName, ChaptersName);
14204c7a 798 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(0, topicName, ChaptersName);
9a29912f
JS
799
800 SetCurrentOutput(Chapters);
801
6d8b260c 802 HTMLHead();
6c155d33 803 TexOutput(_T("<title>"));
9a29912f 804 OutputCurrentSection(); // Repeat section header
6c155d33 805 TexOutput(_T("</title></head>\n"));
9a29912f
JS
806 OutputBodyStart();
807
6c155d33 808 wxChar titleBuf[200];
9a29912f 809 if (truncateFilenames)
b63b07a8 810 wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s.htm"), wxFileNameFromPath(FileRoot));
9a29912f 811 else
b63b07a8 812 wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s_contents.html"), wxFileNameFromPath(FileRoot));
9a29912f 813
6c155d33 814 wxFprintf(Chapters, _T("<A NAME=\"%s\"></A>"), topicName);
119f7a8c 815
6c155d33 816 AddBrowseButtons(_T(""), titleBuf, // Up
9a29912f
JS
817 lastTopic, lastFileName, // Last topic
818 topicName, ChaptersName); // This topic
819
ae6c0ccf
WS
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);
9a29912f
JS
824
825 if (htmlFrameContents && FrameContents)
826 {
827 SetCurrentOutput(FrameContents);
ae6c0ccf
WS
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);
9a29912f 832 OutputCurrentSection();
6c155d33 833 wxFprintf(FrameContents, _T("</A>\n"));
9a29912f
JS
834 }
835
836 SetCurrentOutputs(Contents, Chapters);
6c155d33 837 wxFprintf(Chapters, _T("\n<H2>"));
9a29912f 838 OutputCurrentSection();
6c155d33
JS
839 wxFprintf(Contents, _T("</A>\n"));
840 wxFprintf(Chapters, _T("</H2>\n"));
9a29912f
JS
841
842 SetCurrentOutput(Chapters);
843
844 // Add this section title to the list of keywords
845 if (htmlIndex)
846 {
aed3314d
JS
847 OutputCurrentSectionToString(wxTex2RTFBuffer);
848 AddKeyWordForTopic(topicName, wxTex2RTFBuffer, ConvertCase(currentFileName));
9a29912f
JS
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;
b63b07a8 862 subsectionStarted = false;
9a29912f
JS
863
864 if (macroId != ltSECTIONSTAR)
865 sectionNo ++;
119f7a8c 866
9a29912f 867 SetCurrentOutput(NULL);
b63b07a8 868 startedSections = true;
9a29912f 869
6c155d33 870 wxChar *topicName = FindTopicName(GetNextChunk());
66828481 871 ReopenFile(&Sections, &SectionsName, topicName);
9a29912f
JS
872 AddTexRef(topicName, SectionsName, SectionNameString);
873
874 SetCurrentSectionName(topicName, SectionsName);
14204c7a 875 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(1, topicName, SectionsName);
9a29912f
JS
876
877 SetCurrentOutput(Sections);
6d8b260c 878 HTMLHead();
6c155d33 879 TexOutput(_T("<title>"));
9a29912f 880 OutputCurrentSection();
6c155d33 881 TexOutput(_T("</title></head>\n"));
9a29912f
JS
882 OutputBodyStart();
883
6c155d33 884 wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName);
9a29912f
JS
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)
ae6c0ccf
WS
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 }
9a29912f 899 else
ae6c0ccf
WS
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 }
9a29912f 906
6c155d33 907 wxFprintf(Sections, _T("\n<H2>"));
9a29912f
JS
908 OutputCurrentSection();
909
910 if (DocumentStyle == LATEX_ARTICLE)
6c155d33 911 wxFprintf(jumpFrom, _T("</A>\n"));
9a29912f 912 else
6c155d33
JS
913 wxFprintf(jumpFrom, _T("</B></A><BR>\n"));
914 wxFprintf(Sections, _T("</H2>\n"));
9a29912f
JS
915
916 SetCurrentOutput(Sections);
917 // Add this section title to the list of keywords
918 if (htmlIndex)
919 {
aed3314d
JS
920 OutputCurrentSectionToString(wxTex2RTFBuffer);
921 AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName);
9a29912f
JS
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 {
6c155d33 935 OnError(_T("You cannot have a subsection before a section!"));
9a29912f
JS
936 }
937 else
938 {
939 subsubsectionNo = 0;
940
941 if (macroId != ltSUBSECTIONSTAR)
942 subsectionNo ++;
943
944 if ( combineSubSections && !subsectionStarted )
945 {
af318c88 946 fflush(Sections);
7e9968f7 947
9a29912f 948 // Read old .con file in at this point
6c155d33
JS
949 wxChar buf[256];
950 wxStrcpy(buf, CurrentSectionFile);
9a29912f 951 wxStripExtension(buf);
6c155d33
JS
952 wxStrcat(buf, _T(".con"));
953 FILE *fd = wxFopen(buf, _T("r"));
9a29912f
JS
954 if ( fd )
955 {
956 int ch = getc(fd);
957 while (ch != EOF)
958 {
7f997541 959 wxPutc(ch, Sections);
9a29912f
JS
960 ch = getc(fd);
961 }
962 fclose(fd);
963 }
6c155d33 964 wxFprintf(Sections, _T("<P>\n"));
9a29912f
JS
965
966 // Close old file, create a new file for the sub(sub)section contents entries
967 ReopenSectionContentsFile();
968 }
969
b63b07a8
RL
970 startedSections = true;
971 subsectionStarted = true;
9a29912f 972
6c155d33 973 wxChar *topicName = FindTopicName(GetNextChunk());
9a29912f
JS
974
975 if ( !combineSubSections )
976 {
977 SetCurrentOutput(NULL);
66828481 978 ReopenFile(&Subsections, &SubsectionsName, topicName);
9a29912f
JS
979 AddTexRef(topicName, SubsectionsName, SubsectionNameString);
980 SetCurrentSubsectionName(topicName, SubsectionsName);
14204c7a 981 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SubsectionsName);
9a29912f
JS
982 SetCurrentOutput(Subsections);
983
4fe30bce 984 HTMLHead();
6c155d33 985 TexOutput(_T("<title>"));
9a29912f 986 OutputCurrentSection();
6c155d33 987 TexOutput(_T("</title></head>\n"));
9a29912f
JS
988 OutputBodyStart();
989
6c155d33 990 wxFprintf(Subsections, _T("<A NAME=\"%s\"></A>"), topicName);
9a29912f
JS
991 AddBrowseButtons(CurrentSectionName, CurrentSectionFile, // Up
992 lastTopic, lastFileName, // Last topic
993 topicName, SubsectionsName); // This topic
994
995 SetCurrentOutputs(Sections, Subsections);
ae6c0ccf
WS
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);
9a29912f 1000
6c155d33 1001 wxFprintf(Subsections, _T("\n<H3>"));
9a29912f 1002 OutputCurrentSection();
6c155d33
JS
1003 wxFprintf(Sections, _T("</B></A><BR>\n"));
1004 wxFprintf(Subsections, _T("</H3>\n"));
9a29912f
JS
1005
1006 SetCurrentOutput(Subsections);
1007 }
1008 else
1009 {
1010 AddTexRef(topicName, SectionsName, SubsectionNameString);
1011 SetCurrentSubsectionName(topicName, SectionsName);
14204c7a 1012
9a29912f 1013// if ( subsectionNo != 0 )
6c155d33 1014 wxFprintf(Sections, _T("\n<HR>\n"));
9a29912f
JS
1015
1016 // We're putting everything into the section file
6c155d33
JS
1017 wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName);
1018 wxFprintf(Sections, _T("\n<H3>"));
9a29912f 1019 OutputCurrentSection();
6c155d33 1020 wxFprintf(Sections, _T("</H3>\n"));
9a29912f
JS
1021
1022 SetCurrentOutput(SectionContentsFD);
6c155d33 1023 wxFprintf(SectionContentsFD, _T("<A HREF=\"#%s\">"), topicName);
9a29912f 1024 OutputCurrentSection();
6c155d33 1025 TexOutput(_T("</A><BR>\n"));
9a29912f 1026
14204c7a 1027 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName);
9a29912f
JS
1028 SetCurrentOutput(Sections);
1029 }
1030 // Add this section title to the list of keywords
1031 if (htmlIndex)
1032 {
aed3314d
JS
1033 OutputCurrentSectionToString(wxTex2RTFBuffer);
1034 AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName);
9a29912f
JS
1035 }
1036
1037 }
1038 }
1039 break;
1040 }
1041 case ltSUBSUBSECTION:
1042 case ltSUBSUBSECTIONSTAR:
1043 {
1044 if (!start)
1045 {
1046 if (!Subsections && !combineSubSections)
1047 {
6c155d33 1048 OnError(_T("You cannot have a subsubsection before a subsection!"));
9a29912f
JS
1049 }
1050 else
1051 {
1052 if (macroId != ltSUBSUBSECTIONSTAR)
1053 subsubsectionNo ++;
1054
b63b07a8 1055 startedSections = true;
9a29912f 1056
6c155d33 1057 wxChar *topicName = FindTopicName(GetNextChunk());
9a29912f
JS
1058
1059 if ( !combineSubSections )
1060 {
1061 SetCurrentOutput(NULL);
66828481 1062 ReopenFile(&Subsubsections, &SubsubsectionsName, topicName);
9a29912f
JS
1063 AddTexRef(topicName, SubsubsectionsName, SubsubsectionNameString);
1064 SetCurrentSubsubsectionName(topicName, SubsubsectionsName);
14204c7a 1065 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(3, topicName, SubsubsectionsName);
9a29912f
JS
1066
1067 SetCurrentOutput(Subsubsections);
4fe30bce 1068 HTMLHead();
6c155d33 1069 TexOutput(_T("<title>"));
9a29912f 1070 OutputCurrentSection();
6c155d33 1071 TexOutput(_T("</title></head>\n"));
9a29912f
JS
1072 OutputBodyStart();
1073
6c155d33 1074 wxFprintf(Subsubsections, _T("<A NAME=\"%s\"></A>"), topicName);
9a29912f
JS
1075
1076 AddBrowseButtons(CurrentSubsectionName, CurrentSubsectionFile, // Up
1077 lastTopic, lastFileName, // Last topic
1078 topicName, SubsubsectionsName); // This topic
1079
1080 SetCurrentOutputs(Subsections, Subsubsections);
ae6c0ccf
WS
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);
9a29912f 1085
6c155d33 1086 wxFprintf(Subsubsections, _T("\n<H3>"));
9a29912f 1087 OutputCurrentSection();
6c155d33
JS
1088 wxFprintf(Subsections, _T("</B></A><BR>\n"));
1089 wxFprintf(Subsubsections, _T("</H3>\n"));
9a29912f
JS
1090 }
1091 else
1092 {
1093 AddTexRef(topicName, SectionsName, SubsubsectionNameString);
1094 SetCurrentSubsectionName(topicName, SectionsName);
6c155d33 1095 wxFprintf(Sections, _T("\n<HR>\n"));
9a29912f
JS
1096
1097 // We're putting everything into the section file
6c155d33
JS
1098 wxFprintf(Sections, _T("<A NAME=\"%s\"></A>"), topicName);
1099 wxFprintf(Sections, _T("\n<H3>"));
9a29912f 1100 OutputCurrentSection();
6c155d33 1101 wxFprintf(Sections, _T("</H3>\n"));
9a29912f
JS
1102/* TODO: where do we put subsubsection contents entry - indented, with subsection entries?
1103 SetCurrentOutput(SectionContentsFD);
6c155d33 1104 wxFprintf(SectionContentsFD, "<A HREF=\"#%s\">", topicName);
9a29912f 1105 OutputCurrentSection();
6c155d33 1106 TexOutput(_T("</A><BR>"));
9a29912f 1107*/
119f7a8c 1108 if (htmlWorkshopFiles) HTMLWorkshopAddToContents(2, topicName, SectionsName);
9a29912f
JS
1109 SetCurrentOutput(Sections);
1110 }
1111
1112 // Add this section title to the list of keywords
1113 if (htmlIndex)
1114 {
aed3314d
JS
1115 OutputCurrentSectionToString(wxTex2RTFBuffer);
1116 AddKeyWordForTopic(topicName, wxTex2RTFBuffer, currentFileName);
9a29912f
JS
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)
6c155d33 1167// TexOutput(_T("<B>void</B>"));
9a29912f
JS
1168 break;
1169 case ltHARDY:
1170 if (start)
6c155d33 1171 TexOutput(_T("HARDY"));
9a29912f
JS
1172 break;
1173 case ltWXCLIPS:
1174 if (start)
6c155d33 1175 TexOutput(_T("wxCLIPS"));
9a29912f
JS
1176 break;
1177 case ltAMPERSAND:
1178 if (start)
6c155d33 1179 TexOutput(_T("&amp;"));
9a29912f
JS
1180 break;
1181 case ltSPECIALAMPERSAND:
1182 {
1183 if (start)
1184 {
1185 if (inTabular)
1186 {
1187 // End cell, start cell
d7d17624 1188
6c155d33 1189 TexOutput(_T("</FONT></TD>"));
119f7a8c 1190
9a29912f
JS
1191 // Start new row and cell, setting alignment for the first cell.
1192 if (currentColumn < noColumns)
1193 currentColumn ++;
1194
6c155d33 1195 wxChar buf[100];
9a29912f 1196 if (TableData[currentColumn].justification == 'c')
b63b07a8 1197 wxSnprintf(buf, sizeof(buf), _T("\n<TD ALIGN=CENTER>"));
9a29912f 1198 else if (TableData[currentColumn].justification == 'r')
b63b07a8 1199 wxSnprintf(buf, sizeof(buf), _T("\n<TD ALIGN=RIGHT>"));
9a29912f
JS
1200 else if (TableData[currentColumn].absWidth)
1201 {
1202 // Convert from points * 20 into pixels.
1203 int points = TableData[currentColumn].width / 20;
119f7a8c 1204
9a29912f
JS
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);
b63b07a8 1208 wxSnprintf(buf, sizeof(buf), _T("<TD ALIGN=CENTER WIDTH=%d>"), pixels);
9a29912f
JS
1209 }
1210 else
b63b07a8 1211 wxSnprintf(buf, sizeof(buf), _T("\n<TD ALIGN=LEFT>"));
9a29912f 1212 TexOutput(buf);
4fe30bce 1213 OutputFont();
9a29912f
JS
1214 }
1215 else
6c155d33 1216 TexOutput(_T("&amp;"));
9a29912f
JS
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.
6c155d33 1229 TexOutput(_T("</TR>\n"));
9a29912f
JS
1230 }
1231 else
6c155d33 1232 TexOutput(_T("<BR>\n"));
9a29912f
JS
1233 }
1234 break;
1235 }
1236 case ltROW:
1237 case ltRULEDROW:
1238 {
1239 if (start)
1240 {
1241 currentColumn = 0;
119f7a8c 1242
9a29912f 1243 // Start new row and cell, setting alignment for the first cell.
6c155d33 1244 wxChar buf[100];
9a29912f 1245 if (TableData[currentColumn].justification == 'c')
b63b07a8 1246 wxSnprintf(buf, sizeof(buf), _T("<TR>\n<TD ALIGN=CENTER>"));
9a29912f 1247 else if (TableData[currentColumn].justification == 'r')
b63b07a8 1248 wxSnprintf(buf, sizeof(buf), _T("<TR>\n<TD ALIGN=RIGHT>"));
9a29912f
JS
1249 else if (TableData[currentColumn].absWidth)
1250 {
1251 // Convert from points * 20 into pixels.
1252 int points = TableData[currentColumn].width / 20;
119f7a8c 1253
9a29912f
JS
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);
b63b07a8 1257 wxSnprintf(buf, sizeof(buf), _T("<TR>\n<TD ALIGN=CENTER WIDTH=%d>"), pixels);
9a29912f
JS
1258 }
1259 else
b63b07a8 1260 wxSnprintf(buf, sizeof(buf), _T("<TR>\n<TD ALIGN=LEFT>"));
9a29912f 1261 TexOutput(buf);
4fe30bce 1262 OutputFont();
9a29912f
JS
1263 }
1264 else
1265 {
1266 // End cell and row
1267 // Start new row and cell
6c155d33 1268 TexOutput(_T("</FONT></TD>\n</TR>\n"));
9a29912f
JS
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)
6c155d33 1276 TexOutput(_T("<BR CLEAR=ALL>"));
9a29912f
JS
1277 break;
1278 }
1279 case ltRTFSP: // Explicit space, RTF only
1280 break;
1281 case ltSPECIALTILDE:
1282 {
1283 if (start)
1284 {
b63b07a8 1285 #if (1) // if(inVerbatim)
6c155d33 1286 TexOutput(_T("~"));
b63b07a8 1287 #else
6c155d33 1288 TexOutput(_T(" "));
b63b07a8 1289 #endif
9a29912f
JS
1290 }
1291 break;
1292 }
1293 case ltINDENTED :
1294 {
1295 if ( start )
6c155d33 1296 TexOutput(_T("<UL><UL>\n"));
9a29912f 1297 else
6c155d33 1298 TexOutput(_T("</UL></UL>\n"));
9a29912f
JS
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:
6c155d33 1322 TexOutput(_T("<UL>\n"));
9a29912f
JS
1323 break;
1324 case LATEX_ENUMERATE:
6c155d33 1325 TexOutput(_T("<OL>\n"));
9a29912f
JS
1326 break;
1327 case LATEX_DESCRIPTION:
1328 default:
6c155d33 1329 TexOutput(_T("<DL>\n"));
9a29912f
JS
1330 break;
1331 }
1332 }
1333 else
1334 {
1335 indentLevel --;
ddc4f3b5 1336 if (itemizeStack.GetFirst())
9a29912f 1337 {
ddc4f3b5 1338 ItemizeStruc *struc = (ItemizeStruc *)itemizeStack.GetFirst()->GetData();
9a29912f
JS
1339 switch (struc->listType)
1340 {
1341 case LATEX_ITEMIZE:
6c155d33 1342 TexOutput(_T("</UL>\n"));
9a29912f
JS
1343 break;
1344 case LATEX_ENUMERATE:
6c155d33 1345 TexOutput(_T("</OL>\n"));
9a29912f
JS
1346 break;
1347 case LATEX_DESCRIPTION:
1348 default:
6c155d33 1349 TexOutput(_T("</DL>\n"));
9a29912f
JS
1350 break;
1351 }
1352
1353 delete struc;
ddc4f3b5 1354 delete itemizeStack.GetFirst();
9a29912f
JS
1355 }
1356 }
1357 break;
1358 }
1359 case ltTWOCOLLIST :
1360 {
1361 if ( start )
6c155d33 1362 TexOutput(_T("\n<TABLE>\n"));
c103ca4b 1363 else {
6c155d33 1364 TexOutput(_T("\n</TABLE>\n"));
7e9968f7 1365 // DHS
c103ca4b
JS
1366 TwoColWidthA = -1;
1367 TwoColWidthB = -1;
1368 }
9a29912f
JS
1369 break;
1370 }
1371 case ltPAR:
1372 {
1373 if (start)
6c155d33 1374 TexOutput(_T("<P>\n"));
9a29912f
JS
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 {
6c155d33 1384 TexOutput(_T("<FN>"));
9a29912f 1385 }
6c155d33 1386 else TexOutput(_T("</FN>"));
9a29912f
JS
1387 break;
1388 }
1389*/
1390 case ltVERB:
1391 {
1392 if (start)
6c155d33
JS
1393 TexOutput(_T("<TT>"));
1394 else TexOutput(_T("</TT>"));
9a29912f
JS
1395 break;
1396 }
1397 case ltVERBATIM:
1398 {
1399 if (start)
1400 {
6c155d33 1401 wxChar buf[100];
b63b07a8 1402 wxSnprintf(buf, sizeof(buf), _T("<PRE>\n"));
9a29912f
JS
1403 TexOutput(buf);
1404 }
6c155d33 1405 else TexOutput(_T("</PRE>\n"));
9a29912f
JS
1406 break;
1407 }
1408 case ltCENTERLINE:
1409 case ltCENTER:
1410 {
1411 if (start)
1412 {
6c155d33 1413 TexOutput(_T("<CENTER>"));
9a29912f 1414 }
6c155d33 1415 else TexOutput(_T("</CENTER>"));
9a29912f
JS
1416 break;
1417 }
1418 case ltFLUSHLEFT:
1419 {
1420/*
1421 if (start)
1422 {
6c155d33 1423 TexOutput(_T("{\\ql "));
9a29912f 1424 }
6c155d33 1425 else TexOutput(_T("}\\par\\pard\n"));
9a29912f
JS
1426*/
1427 break;
1428 }
1429 case ltFLUSHRIGHT:
1430 {
1431/*
1432 if (start)
1433 {
6c155d33 1434 TexOutput(_T("{\\qr "));
9a29912f 1435 }
6c155d33 1436 else TexOutput(_T("}\\par\\pard\n"));
9a29912f
JS
1437*/
1438 break;
1439 }
1440 case ltSMALL:
1441 {
1442 if (start)
1443 {
1444 // Netscape extension
6c155d33 1445 TexOutput(_T("<FONT SIZE=2>"));
9a29912f 1446 }
6c155d33 1447 else TexOutput(_T("</FONT>"));
9a29912f
JS
1448 break;
1449 }
1450 case ltTINY:
1451 {
1452 if (start)
1453 {
1454 // Netscape extension
6c155d33 1455 TexOutput(_T("<FONT SIZE=1>"));
9a29912f 1456 }
6c155d33 1457 else TexOutput(_T("</FONT>"));
9a29912f
JS
1458 break;
1459 }
1460 case ltNORMALSIZE:
1461 {
1462 if (start)
1463 {
1464 // Netscape extension
6c155d33 1465 TexOutput(_T("<FONT SIZE=3>"));
9a29912f 1466 }
6c155d33 1467 else TexOutput(_T("</FONT>"));
9a29912f
JS
1468 break;
1469 }
1470 case ltlarge:
1471 {
1472 if (start)
1473 {
1474 // Netscape extension
6c155d33 1475 TexOutput(_T("<FONT SIZE=4>"));
9a29912f 1476 }
6c155d33 1477 else TexOutput(_T("</FONT>"));
9a29912f
JS
1478 break;
1479 }
1480 case ltLarge:
1481 {
1482 if (start)
1483 {
1484 // Netscape extension
6c155d33 1485 TexOutput(_T("<FONT SIZE=5>"));
9a29912f 1486 }
6c155d33 1487 else TexOutput(_T("</FONT>"));
9a29912f
JS
1488 break;
1489 }
1490 case ltLARGE:
1491 {
1492 if (start)
1493 {
1494 // Netscape extension
6c155d33 1495 TexOutput(_T("<FONT SIZE=6>"));
9a29912f 1496 }
6c155d33 1497 else TexOutput(_T("</FONT>"));
9a29912f
JS
1498 break;
1499 }
1500 case ltBFSERIES:
1501 case ltTEXTBF:
1502 case ltBF:
1503 {
1504 if (start)
1505 {
6c155d33 1506 TexOutput(_T("<B>"));
9a29912f 1507 }
6c155d33 1508 else TexOutput(_T("</B>"));
9a29912f
JS
1509 break;
1510 }
1511 case ltITSHAPE:
1512 case ltTEXTIT:
1513 case ltIT:
1514 {
1515 if (start)
1516 {
6c155d33 1517 TexOutput(_T("<I>"));
9a29912f 1518 }
6c155d33 1519 else TexOutput(_T("</I>"));
9a29912f
JS
1520 break;
1521 }
1522 case ltEMPH:
1523 case ltEM:
1524 {
1525 if (start)
1526 {
6c155d33 1527 TexOutput(_T("<EM>"));
9a29912f 1528 }
6c155d33 1529 else TexOutput(_T("</EM>"));
9a29912f
JS
1530 break;
1531 }
1532 case ltUNDERLINE:
1533 {
1534 if (start)
1535 {
6c155d33 1536 TexOutput(_T("<UL>"));
9a29912f 1537 }
6c155d33 1538 else TexOutput(_T("</UL>"));
9a29912f
JS
1539 break;
1540 }
1541 case ltTTFAMILY:
1542 case ltTEXTTT:
1543 case ltTT:
1544 {
1545 if (start)
1546 {
6c155d33 1547 TexOutput(_T("<TT>"));
9a29912f 1548 }
6c155d33 1549 else TexOutput(_T("</TT>"));
9a29912f
JS
1550 break;
1551 }
1552 case ltCOPYRIGHT:
1553 {
1554 if (start)
b63b07a8 1555 TexOutput(_T("&copy;"), true);
9a29912f
JS
1556 break;
1557 }
1558 case ltREGISTERED:
1559 {
1560 if (start)
b63b07a8 1561 TexOutput(_T("&reg;"), true);
9a29912f
JS
1562 break;
1563 }
1564 // Arrows
1565 case ltLEFTARROW:
1566 {
6c155d33 1567 if (start) TexOutput(_T("&lt;--"));
9a29912f
JS
1568 break;
1569 }
1570 case ltLEFTARROW2:
1571 {
6c155d33 1572 if (start) TexOutput(_T("&lt;=="));
9a29912f
JS
1573 break;
1574 }
1575 case ltRIGHTARROW:
1576 {
6c155d33 1577 if (start) TexOutput(_T("--&gt;"));
9a29912f
JS
1578 break;
1579 }
1580 case ltRIGHTARROW2:
1581 {
6c155d33 1582 if (start) TexOutput(_T("==&gt;"));
9a29912f
JS
1583 break;
1584 }
1585 case ltLEFTRIGHTARROW:
1586 {
6c155d33 1587 if (start) TexOutput(_T("&lt;--&gt;"));
9a29912f
JS
1588 break;
1589 }
1590 case ltLEFTRIGHTARROW2:
1591 {
6c155d33 1592 if (start) TexOutput(_T("&lt;==&gt;"));
9a29912f
JS
1593 break;
1594 }
1595/*
1596 case ltSC:
1597 {
1598 break;
1599 }
1600*/
1601 case ltITEM:
1602 {
1603 if (!start)
1604 {
ddc4f3b5 1605 wxNode *node = itemizeStack.GetFirst();
9a29912f
JS
1606 if (node)
1607 {
ddc4f3b5 1608 ItemizeStruc *struc = (ItemizeStruc *)node->GetData();
9a29912f
JS
1609 struc->currentItem += 1;
1610 if (struc->listType == LATEX_DESCRIPTION)
1611 {
1612 if (descriptionItemArg)
1613 {
6c155d33 1614 TexOutput(_T("<DT> "));
9a29912f 1615 TraverseChildrenFromChunk(descriptionItemArg);
6c155d33 1616 TexOutput(_T("\n"));
9a29912f
JS
1617 descriptionItemArg = NULL;
1618 }
6c155d33 1619 TexOutput(_T("<DD>"));
9a29912f
JS
1620 }
1621 else
6c155d33 1622 TexOutput(_T("<LI>"));
9a29912f
JS
1623 }
1624 }
1625 break;
1626 }
1627 case ltMAKETITLE:
1628 {
1629 if (start && DocumentTitle && DocumentAuthor)
1630 {
1631 // Add a special label for the contents page.
6c155d33
JS
1632// TexOutput(_T("<CENTER>\n"));
1633 TexOutput(_T("<A NAME=\"contents\">"));
1634 TexOutput(_T("<H2 ALIGN=CENTER>\n"));
9a29912f 1635 TraverseChildrenFromChunk(DocumentTitle);
6c155d33
JS
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>"));
9a29912f 1641 TraverseChildrenFromChunk(DocumentAuthor);
6c155d33 1642 TexOutput(_T("</H3><P>\n\n"));
9a29912f
JS
1643 if (DocumentDate)
1644 {
6c155d33 1645 TexOutput(_T("<H3 ALIGN=CENTER>"));
9a29912f 1646 TraverseChildrenFromChunk(DocumentDate);
6c155d33 1647 TexOutput(_T("</H3><P>\n\n"));
9a29912f 1648 }
6c155d33
JS
1649// TexOutput(_T("\n</CENTER>\n"));
1650 TexOutput(_T("\n<P><HR><P>\n"));
9a29912f
JS
1651
1652/*
1653 // Now do optional frame contents page
1654 if (htmlFrameContents && FrameContents)
1655 {
1656 SetCurrentOutput(FrameContents);
119f7a8c 1657
9a29912f 1658 // Add a special label for the contents page.
6c155d33
JS
1659 TexOutput(_T("<CENTER>\n"));
1660 TexOutput(_T("<H3>\n"));
9a29912f 1661 TraverseChildrenFromChunk(DocumentTitle);
6c155d33
JS
1662 TexOutput(_T("</H3>"));
1663 TexOutput(_T("<P>"));
1664 TexOutput(_T("</A>\n"));
1665 TexOutput(_T("<P>\n\n"));
1666 TexOutput(_T("<H3>"));
9a29912f 1667 TraverseChildrenFromChunk(DocumentAuthor);
6c155d33 1668 TexOutput(_T("</H3><P>\n\n"));
9a29912f
JS
1669 if (DocumentDate)
1670 {
6c155d33 1671 TexOutput(_T("<H4>"));
9a29912f 1672 TraverseChildrenFromChunk(DocumentDate);
6c155d33 1673 TexOutput(_T("</H4><P>\n\n"));
9a29912f 1674 }
6c155d33
JS
1675 TexOutput(_T("\n</CENTER>\n"));
1676 TexOutput(_T("<P><HR><P>\n"));
119f7a8c 1677
9a29912f
JS
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);
6c155d33 1705 TexOutput(_T("</DL>\n"));
9a29912f
JS
1706 }
1707 break;
1708 }
1709 case ltHRULE:
1710 {
1711 if (start)
1712 {
6c155d33 1713 TexOutput(_T("<HR>\n"));
9a29912f
JS
1714 }
1715 break;
1716 }
1717 case ltRULE:
1718 {
1719 if (start)
1720 {
6c155d33 1721 TexOutput(_T("<HR>\n"));
9a29912f
JS
1722 }
1723 break;
1724 }
1725 case ltTABLEOFCONTENTS:
1726 {
1727 if (start)
1728 {
af318c88
JS
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
6c155d33 1734 FILE *fd = wxFopen(ContentsName, _T("r"));
9a29912f
JS
1735 if (fd)
1736 {
1737 int ch = getc(fd);
1738 while (ch != EOF)
1739 {
7f997541 1740 wxPutc(ch, Titlepage);
9a29912f
JS
1741 ch = getc(fd);
1742 }
1743 fclose(fd);
af318c88 1744 fflush(Titlepage);
9a29912f
JS
1745 }
1746 else
1747 {
6c155d33
JS
1748 TexOutput(_T("RUN TEX2RTF AGAIN FOR CONTENTS PAGE\n"));
1749 OnInform(_T("Run Tex2RTF again to include contents page."));
9a29912f
JS
1750 }
1751 }
1752 break;
1753 }
1754 case ltLANGLEBRA:
1755 {
1756 if (start)
6c155d33 1757 TexOutput(_T("&lt;"));
9a29912f
JS
1758 break;
1759 }
1760 case ltRANGLEBRA:
1761 {
1762 if (start)
6c155d33 1763 TexOutput(_T("&gt;"));
9a29912f
JS
1764 break;
1765 }
1766 case ltQUOTE:
1767 case ltQUOTATION:
1768 {
1769 if (start)
6c155d33 1770 TexOutput(_T("<BLOCKQUOTE>"));
9a29912f 1771 else
6c155d33 1772 TexOutput(_T("</BLOCKQUOTE>"));
9a29912f
JS
1773 break;
1774 }
1775 case ltCAPTION:
1776 case ltCAPTIONSTAR:
1777 {
1778 if (start)
1779 {
1780 if (inTabular)
6c155d33 1781 TexOutput(_T("\n<CAPTION>"));
9a29912f 1782
6c155d33 1783 wxChar figBuf[40];
9a29912f
JS
1784
1785 if ( inFigure )
1786 {
1787 figureNo ++;
1788
1789 if (DocumentStyle != LATEX_ARTICLE)
b63b07a8 1790 wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d.%d: "), FigureNameString, chapterNo, figureNo);
9a29912f 1791 else
b63b07a8 1792 wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d: "), FigureNameString, figureNo);
9a29912f
JS
1793 }
1794 else
1795 {
1796 tableNo ++;
1797
1798 if (DocumentStyle != LATEX_ARTICLE)
b63b07a8 1799 wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d.%d: "), TableNameString, chapterNo, tableNo);
9a29912f 1800 else
b63b07a8 1801 wxSnprintf(figBuf, sizeof(figBuf), _T("%s %d: "), TableNameString, tableNo);
9a29912f
JS
1802 }
1803
1804 TexOutput(figBuf);
1805 }
1806 else
1807 {
1808 if (inTabular)
6c155d33 1809 TexOutput(_T("\n</CAPTION>\n"));
9a29912f 1810
6c155d33 1811 wxChar *topicName = FindTopicName(GetNextChunk());
9a29912f
JS
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 {
6c155d33 1823 if (start) TexOutput(_T("&szlig;"));
9a29912f
JS
1824 break;
1825 }
1826 case ltFIGURE:
1827 {
b63b07a8
RL
1828 if (start) inFigure = true;
1829 else inFigure = false;
9a29912f
JS
1830 break;
1831 }
1832 case ltTABLE:
1833 {
b63b07a8
RL
1834 if (start) inTable = true;
1835 else inTable = false;
9a29912f
JS
1836 break;
1837 }
1838 default:
1839 DefaultOnMacro(macroId, no_args, start);
1840 break;
1841 }
1842}
4116fac0
VZ
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*/
1864static bool CheckTypeRef()
1865{
1866 wxString typeDecl = GetArgData();
5c66e5b2 1867 if( !typeDecl.empty() ) {
4116fac0
VZ
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();
1693108c 1880 TexRef *texRef = FindReference(label);
4116fac0
VZ
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}
9a29912f
JS
1911// Called on start/end of argument examination
1912bool 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();
b63b07a8 1932 return false;
9a29912f
JS
1933 }
1934 case ltFUNC:
1935 {
4116fac0 1936 if (start && (arg_no == 1)) {
6c155d33 1937 TexOutput(_T("<B>"));
4116fac0
VZ
1938 if( CheckTypeRef() ) {
1939 TexOutput(_T("</B> "));
1940 return false;
1941 }
1942 }
9a29912f
JS
1943
1944 if (!start && (arg_no == 1))
6c155d33 1945 TexOutput(_T("</B> "));
9a29912f
JS
1946
1947 if (start && (arg_no == 2))
1948 {
6c155d33 1949 if (!suppressNameDecoration) TexOutput(_T("<B>"));
9a29912f
JS
1950 currentMember = GetArgChunk();
1951 }
1952 if (!start && (arg_no == 2))
1953 {
6c155d33 1954 if (!suppressNameDecoration) TexOutput(_T("</B>"));
9a29912f 1955 }
119f7a8c 1956
9a29912f 1957 if (start && (arg_no == 3))
6c155d33 1958 TexOutput(_T("("));
9a29912f 1959 if (!start && (arg_no == 3))
6c155d33 1960 TexOutput(_T(")"));
9a29912f
JS
1961 break;
1962 }
1963 case ltCLIPSFUNC:
1964 {
1965 if (start && (arg_no == 1))
6c155d33 1966 TexOutput(_T("<B>"));
9a29912f 1967 if (!start && (arg_no == 1))
6c155d33 1968 TexOutput(_T("</B> "));
9a29912f
JS
1969
1970 if (start && (arg_no == 2))
1971 {
6c155d33 1972 if (!suppressNameDecoration) TexOutput(_T("( "));
9a29912f
JS
1973 currentMember = GetArgChunk();
1974 }
1975 if (!start && (arg_no == 2))
1976 {
1977 }
1978
1979 if (!start && (arg_no == 3))
6c155d33 1980 TexOutput(_T(")"));
9a29912f
JS
1981 break;
1982 }
1983 case ltPFUNC:
1984 {
1985 if (!start && (arg_no == 1))
6c155d33 1986 TexOutput(_T(" "));
9a29912f
JS
1987
1988 if (start && (arg_no == 2))
6c155d33 1989 TexOutput(_T("(*"));
9a29912f 1990 if (!start && (arg_no == 2))
6c155d33 1991 TexOutput(_T(")"));
9a29912f
JS
1992
1993 if (start && (arg_no == 2))
1994 currentMember = GetArgChunk();
1995
1996 if (start && (arg_no == 3))
6c155d33 1997 TexOutput(_T("("));
9a29912f 1998 if (!start && (arg_no == 3))
6c155d33 1999 TexOutput(_T(")"));
9a29912f
JS
2000 break;
2001 }
2002 case ltPARAM:
9a29912f
JS
2003 case ltCPARAM:
2004 {
4116fac0
VZ
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 }
9a29912f
JS
2018 if (start && (arg_no == 2))
2019 {
6c155d33 2020 TexOutput(_T("<I>"));
9a29912f
JS
2021 }
2022 if (!start && (arg_no == 2))
2023 {
6c155d33 2024 TexOutput(_T("</I>"));
9a29912f
JS
2025 }
2026 break;
2027 }
2028 case ltMEMBER:
2029 {
2030 if (!start && (arg_no == 1))
6c155d33 2031 TexOutput(_T(" "));
9a29912f
JS
2032
2033 if (start && (arg_no == 2))
2034 currentMember = GetArgChunk();
2035 break;
2036 }
2037 case ltREF:
2038 {
2039 if (start)
2040 {
6c155d33 2041 wxChar *sec = NULL;
119f7a8c 2042
6c155d33 2043 wxChar *refName = GetArgData();
9a29912f
JS
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 }
b63b07a8 2056 return false;
9a29912f
JS
2057 }
2058 break;
2059 }
2060 case ltURLREF:
2061 {
2062 if (IsArgOptional())
b63b07a8 2063 return false;
9a29912f
JS
2064 else if ((GetNoArgs() - arg_no) == 1)
2065 {
2066 if (start)
2067 helpRefText = GetArgChunk();
b63b07a8 2068 return false;
9a29912f
JS
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();
6c155d33 2075 TexOutput(_T("<A HREF=\""));
b63b07a8 2076 inVerbatim = true;
9a29912f 2077 TraverseChildrenFromChunk(ref);
b63b07a8 2078 inVerbatim = false;
6c155d33 2079 TexOutput(_T("\">"));
9a29912f
JS
2080 if (helpRefText)
2081 TraverseChildrenFromChunk(helpRefText);
6c155d33 2082 TexOutput(_T("</A>"));
9a29912f 2083 }
b63b07a8 2084 return false;
9a29912f
JS
2085 }
2086 break;
2087 }
4116fac0 2088
9a29912f
JS
2089 case ltHELPREF:
2090 case ltHELPREFN:
2091 case ltPOPREF:
2092 {
2093 if (IsArgOptional())
2094 {
2095 if (start)
2096 helpRefFilename = GetArgChunk();
b63b07a8 2097 return false;
9a29912f
JS
2098 }
2099 if ((GetNoArgs() - arg_no) == 1)
2100 {
2101 if (start)
2102 helpRefText = GetArgChunk();
b63b07a8 2103 return false;
9a29912f
JS
2104 }
2105 else if ((GetNoArgs() - arg_no) == 0) // Arg = 2, or 3 if first is optional
2106 {
2107 if (start)
2108 {
6c155d33
JS
2109 wxChar *refName = GetArgData();
2110 wxChar *refFilename = NULL;
9a29912f
JS
2111
2112 if (refName)
2113 {
2114 TexRef *texRef = FindReference(refName);
2115 if (texRef)
2116 {
6c155d33 2117 if (texRef->refFile && wxStrcmp(texRef->refFile, _T("??")) != 0)
9a29912f
JS
2118 refFilename = texRef->refFile;
2119
6c155d33 2120 TexOutput(_T("<A HREF=\""));
9a29912f
JS
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)
4fe30bce 2124 {
9a29912f 2125 TraverseChildrenFromChunk(helpRefFilename);
6c155d33 2126 TexOutput(_T("#"));
ae6c0ccf 2127 TexOutput(refName);
4fe30bce 2128 }
9a29912f 2129 else if (refFilename)
4fe30bce 2130 {
9a29912f 2131 TexOutput(ConvertCase(refFilename));
ae6c0ccf
WS
2132 if(!PrimaryAnchorOfTheFile(texRef->refFile, refName))
2133 {
2134 TexOutput(_T("#"));
2135 TexOutput(refName);
2136 }
4fe30bce 2137 }
6c155d33 2138 TexOutput(_T("\">"));
9a29912f
JS
2139 if (helpRefText)
2140 TraverseChildrenFromChunk(helpRefText);
6c155d33 2141 TexOutput(_T("</A>"));
9a29912f
JS
2142 }
2143 else
2144 {
2145 if (helpRefText)
2146 TraverseChildrenFromChunk(helpRefText);
bf16085d 2147 if (!ignoreBadRefs)
6c155d33 2148 TexOutput(_T(" (REF NOT FOUND)"));
7e9968f7
WS
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);
1693108c 2156 OnInform(errBuf);
7e9968f7 2157 }
9a29912f
JS
2158 }
2159 }
6c155d33 2160 else TexOutput(_T("??"));
9a29912f 2161 }
b63b07a8 2162 return false;
9a29912f
JS
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 {
6c155d33 2175 wxChar *alignment = _T("");
9a29912f 2176 if (macroId == ltIMAGEL)
6c155d33 2177 alignment = _T(" align=left");
9a29912f 2178 else if (macroId == ltIMAGER)
6c155d33 2179 alignment = _T(" align=right");
119f7a8c 2180
9a29912f 2181 // Try to find an XBM or GIF image first.
6c155d33
JS
2182 wxChar *filename = copystring(GetArgData());
2183 wxChar buf[500];
119f7a8c 2184
6c155d33 2185 wxStrcpy(buf, filename);
9a29912f 2186 StripExtension(buf);
6c155d33 2187 wxStrcat(buf, _T(".xbm"));
9a29912f
JS
2188 wxString f = TexPathList.FindValidPath(buf);
2189
6c155d33 2190 if (f == _T("")) // Try for a GIF instead
9a29912f 2191 {
6c155d33 2192 wxStrcpy(buf, filename);
9a29912f 2193 StripExtension(buf);
6c155d33 2194 wxStrcat(buf, _T(".gif"));
9a29912f
JS
2195 f = TexPathList.FindValidPath(buf);
2196 }
14204c7a 2197
6c155d33 2198 if (f == _T("")) // Try for a JPEG instead
14204c7a 2199 {
6c155d33 2200 wxStrcpy(buf, filename);
14204c7a 2201 StripExtension(buf);
6c155d33 2202 wxStrcat(buf, _T(".jpg"));
14204c7a
VS
2203 f = TexPathList.FindValidPath(buf);
2204 }
2205
6c155d33 2206 if (f == _T("")) // Try for a PNG instead
14204c7a 2207 {
6c155d33 2208 wxStrcpy(buf, filename);
14204c7a 2209 StripExtension(buf);
6c155d33 2210 wxStrcat(buf, _T(".png"));
14204c7a
VS
2211 f = TexPathList.FindValidPath(buf);
2212 }
2213
6c155d33 2214 if (f != _T(""))
9a29912f 2215 {
6c155d33 2216 wxChar *inlineFilename = copystring(f);
9a29912f 2217#if 0
6c155d33 2218 wxChar *originalFilename = TexPathList.FindValidPath(filename);
9a29912f
JS
2219 // If we have found the existing filename, make the inline
2220 // image point to the original file (could be PS, for example)
6c155d33 2221 if (originalFilename && (wxStrcmp(inlineFilename, originalFilename) != 0))
4fe30bce 2222 {
6c155d33 2223 TexOutput(_T("<A HREF=\""));
9a29912f 2224 TexOutput(ConvertCase(originalFilename));
6c155d33
JS
2225 TexOutput(_T("\">"));
2226 TexOutput(_T("<img src=\""));
9a29912f 2227 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename)));
6c155d33 2228 TexOutput(_T("\""));
7e9968f7 2229 TexOutput(alignment);
6c155d33 2230 TexOutput(_T("></A>"));
4fe30bce 2231 }
9a29912f
JS
2232 else
2233#endif
4fe30bce 2234 {
6c155d33 2235 TexOutput(_T("<img src=\""));
9a29912f 2236 TexOutput(ConvertCase(wxFileNameFromPath(inlineFilename)));
6c155d33 2237 TexOutput(_T("\""));
7e9968f7 2238 TexOutput(alignment);
6c155d33 2239 TexOutput(_T(">"));
9a29912f 2240 delete[] inlineFilename;
4fe30bce 2241 }
9a29912f
JS
2242 }
2243 else
2244 {
2245 // Last resort - a link to a PS file.
6c155d33 2246 TexOutput(_T("<A HREF=\""));
9a29912f 2247 TexOutput(ConvertCase(wxFileNameFromPath(filename)));
6c155d33 2248 TexOutput(_T("\">Picture</A>\n"));
b63b07a8 2249 wxSnprintf(buf, sizeof(buf), _T("Warning: could not find an inline XBM/GIF for %s."), filename);
9a29912f
JS
2250 OnInform(buf);
2251 }
2252 }
2253 }
b63b07a8 2254 return false;
9a29912f
JS
2255 }
2256 // First arg is PSBOX spec (ignored), second is image file, third is map name.
2257 case ltIMAGEMAP:
2258 {
6c155d33 2259 static wxChar *imageFile = NULL;
9a29912f
JS
2260 if (start && (arg_no == 2))
2261 {
2262 // Try to find an XBM or GIF image first.
6c155d33
JS
2263 wxChar *filename = copystring(GetArgData());
2264 wxChar buf[500];
119f7a8c 2265
6c155d33 2266 wxStrcpy(buf, filename);
9a29912f 2267 StripExtension(buf);
6c155d33 2268 wxStrcat(buf, _T(".xbm"));
9a29912f
JS
2269 wxString f = TexPathList.FindValidPath(buf);
2270
6c155d33 2271 if (f == _T("")) // Try for a GIF instead
9a29912f 2272 {
6c155d33 2273 wxStrcpy(buf, filename);
9a29912f 2274 StripExtension(buf);
6c155d33 2275 wxStrcat(buf, _T(".gif"));
9a29912f
JS
2276 f = TexPathList.FindValidPath(buf);
2277 }
6c155d33 2278 if (f == _T(""))
9a29912f 2279 {
6c155d33 2280 wxChar buf[300];
b63b07a8 2281 wxSnprintf(buf, sizeof(buf), _T("Warning: could not find an inline XBM/GIF for %s."), filename);
9a29912f
JS
2282 OnInform(buf);
2283 }
2284 delete[] filename;
2285 if (imageFile)
2286 delete[] imageFile;
2287 imageFile = NULL;
5c66e5b2 2288 if (!f.empty())
9a29912f
JS
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
6c155d33
JS
2299 wxChar buf[256];
2300 wxStrcpy(buf, imageFile);
9a29912f 2301 StripExtension(buf);
6c155d33 2302 wxStrcat(buf, _T(".shg"));
9a29912f
JS
2303 wxString f = TexPathList.FindValidPath(buf);
2304
6c155d33 2305 if (f != _T(""))
9a29912f
JS
2306 {
2307 // The default HTML file to go to is THIS file (so a no-op)
1693108c 2308 SHGToMap(f, currentFileName);
9a29912f
JS
2309 }
2310
6c155d33
JS
2311 wxChar *mapName = GetArgData();
2312 TexOutput(_T("<A HREF=\"/cgi-bin/imagemap/"));
9a29912f
JS
2313 if (mapName)
2314 TexOutput(mapName);
2315 else
6c155d33
JS
2316 TexOutput(_T("unknown"));
2317 TexOutput(_T("\">"));
2318 TexOutput(_T("<img src=\""));
9a29912f 2319 TexOutput(ConvertCase(wxFileNameFromPath(imageFile)));
6c155d33 2320 TexOutput(_T("\" ISMAP></A><P>"));
9a29912f
JS
2321 delete[] imageFile;
2322 imageFile = NULL;
2323 }
2324 }
b63b07a8 2325 return false;
9a29912f
JS
2326 }
2327 case ltINDENTED :
2328 {
2329 if ( arg_no == 1 )
b63b07a8 2330 return false;
9a29912f
JS
2331 else
2332 {
b63b07a8 2333 return true;
9a29912f
JS
2334 }
2335 }
2336 case ltITEM:
2337 {
2338 if (start)
2339 {
2340 descriptionItemArg = GetArgChunk();
b63b07a8 2341 return false;
9a29912f 2342 }
b63b07a8 2343 return true;
9a29912f
JS
2344 }
2345 case ltTWOCOLITEM:
2346 case ltTWOCOLITEMRULED:
2347 {
2348/*
2349 if (start && (arg_no == 1))
6c155d33 2350 TexOutput(_T("\n<DT> "));
9a29912f 2351 if (start && (arg_no == 2))
6c155d33 2352 TexOutput(_T("<DD> "));
9a29912f
JS
2353*/
2354 if (arg_no == 1)
2355 {
c103ca4b
JS
2356 if ( start ) {
2357 // DHS
4fe30bce
WS
2358 if (TwoColWidthA > -1)
2359 {
6c155d33 2360 wxChar buf[100];
b63b07a8 2361 wxSnprintf(buf, sizeof(buf), _T("\n<TR><TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthA);
c103ca4b 2362 TexOutput(buf);
4fe30bce
WS
2363 }
2364 else
2365 {
6c155d33 2366 TexOutput(_T("\n<TR><TD VALIGN=TOP>\n"));
4fe30bce
WS
2367 }
2368 OutputFont();
c103ca4b 2369 } else
6c155d33 2370 TexOutput(_T("\n</FONT></TD>\n"));
9a29912f
JS
2371 }
2372 if (arg_no == 2)
2373 {
c103ca4b 2374 // DHS
4fe30bce
WS
2375 if ( start )
2376 {
2377 if (TwoColWidthB > -1)
2378 {
6c155d33 2379 wxChar buf[100];
b63b07a8 2380 wxSnprintf(buf, sizeof(buf), _T("\n<TD VALIGN=TOP WIDTH=%d>\n"),TwoColWidthB);
c103ca4b 2381 TexOutput(buf);
4fe30bce 2382 }
7e9968f7 2383 else
4fe30bce
WS
2384 {
2385 TexOutput(_T("\n<TD VALIGN=TOP>\n"));
2386 }
2387 OutputFont();
c103ca4b 2388 } else
6c155d33 2389 TexOutput(_T("\n</FONT></TD></TR>\n"));
9a29912f 2390 }
b63b07a8 2391 return true;
9a29912f
JS
2392 }
2393 case ltNUMBEREDBIBITEM:
2394 {
2395 if (arg_no == 1 && start)
2396 {
6c155d33 2397 TexOutput(_T("\n<DT> "));
9a29912f
JS
2398 }
2399 if (arg_no == 2 && !start)
6c155d33 2400 TexOutput(_T("<P>\n"));
9a29912f
JS
2401 break;
2402 }
2403 case ltBIBITEM:
2404 {
6c155d33 2405 wxChar buf[100];
9a29912f
JS
2406 if (arg_no == 1 && start)
2407 {
6c155d33 2408 wxChar *citeKey = GetArgData();
9a29912f
JS
2409 TexRef *ref = (TexRef *)TexReferences.Get(citeKey);
2410 if (ref)
2411 {
2412 if (ref->sectionNumber) delete[] ref->sectionNumber;
b63b07a8 2413 wxSnprintf(buf, sizeof(buf), _T("[%d]"), citeCount);
9a29912f
JS
2414 ref->sectionNumber = copystring(buf);
2415 }
2416
b63b07a8 2417 wxSnprintf(buf, sizeof(buf), _T("\n<DT> [%d] "), citeCount);
9a29912f
JS
2418 TexOutput(buf);
2419 citeCount ++;
b63b07a8 2420 return false;
9a29912f
JS
2421 }
2422 if (arg_no == 2 && !start)
6c155d33 2423 TexOutput(_T("<P>\n"));
b63b07a8 2424 return true;
9a29912f
JS
2425 }
2426 case ltMARGINPAR:
2427 case ltMARGINPARODD:
2428 case ltMARGINPAREVEN:
2429 case ltNORMALBOX:
2430 case ltNORMALBOXD:
2431 {
2432 if (start)
2433 {
6c155d33 2434 TexOutput(_T("<HR>\n"));
b63b07a8 2435 return true;
9a29912f
JS
2436 }
2437 else
6c155d33 2438 TexOutput(_T("<HR><P>\n"));
9a29912f
JS
2439 break;
2440 }
c103ca4b
JS
2441 // DHS
2442 case ltTWOCOLWIDTHA:
2443 {
2444 if (start)
2445 {
6c155d33 2446 wxChar *val = GetArgData();
c103ca4b
JS
2447 float points = ParseUnitArgument(val);
2448 TwoColWidthA = (int)((points * 100.0) / 72.0);
2449 }
b63b07a8 2450 return false;
c103ca4b
JS
2451 }
2452 // DHS
2453 case ltTWOCOLWIDTHB:
2454 {
2455 if (start)
2456 {
6c155d33 2457 wxChar *val = GetArgData();
c103ca4b
JS
2458 float points = ParseUnitArgument(val);
2459 TwoColWidthB = (int)((points * 100.0) / 72.0);
2460 }
b63b07a8 2461 return false;
c103ca4b 2462 }
9a29912f
JS
2463 /*
2464 * Accents
2465 *
2466 */
2467 case ltACCENT_GRAVE:
2468 {
2469 if (start)
2470 {
6c155d33 2471 wxChar *val = GetArgData();
9a29912f
JS
2472 if (val)
2473 {
2474 switch (val[0])
2475 {
2476 case 'a':
6c155d33 2477 TexOutput(_T("&agrave;"));
9a29912f
JS
2478 break;
2479 case 'e':
6c155d33 2480 TexOutput(_T("&egrave;"));
9a29912f
JS
2481 break;
2482 case 'i':
6c155d33 2483 TexOutput(_T("&igrave;"));
9a29912f
JS
2484 break;
2485 case 'o':
6c155d33 2486 TexOutput(_T("&ograve;"));
9a29912f
JS
2487 break;
2488 case 'u':
6c155d33 2489 TexOutput(_T("&ugrave;"));
9a29912f
JS
2490 break;
2491 case 'A':
6c155d33 2492 TexOutput(_T("&Agrave;"));
9a29912f
JS
2493 break;
2494 case 'E':
6c155d33 2495 TexOutput(_T("&Egrave;"));
9a29912f
JS
2496 break;
2497 case 'I':
6c155d33 2498 TexOutput(_T("&Igrave;"));
9a29912f
JS
2499 break;
2500 case 'O':
6c155d33 2501 TexOutput(_T("&Ograve;"));
9a29912f
JS
2502 break;
2503 case 'U':
6c155d33 2504 TexOutput(_T("&Igrave;"));
9a29912f
JS
2505 break;
2506 default:
2507 break;
2508 }
2509 }
2510 }
b63b07a8 2511 return false;
9a29912f
JS
2512 }
2513 case ltACCENT_ACUTE:
2514 {
2515 if (start)
2516 {
6c155d33 2517 wxChar *val = GetArgData();
9a29912f
JS
2518 if (val)
2519 {
2520 switch (val[0])
2521 {
2522 case 'a':
6c155d33 2523 TexOutput(_T("&aacute;"));
9a29912f
JS
2524 break;
2525 case 'e':
6c155d33 2526 TexOutput(_T("&eacute;"));
9a29912f
JS
2527 break;
2528 case 'i':
6c155d33 2529 TexOutput(_T("&iacute;"));
9a29912f
JS
2530 break;
2531 case 'o':
6c155d33 2532 TexOutput(_T("&oacute;"));
9a29912f
JS
2533 break;
2534 case 'u':
6c155d33 2535 TexOutput(_T("&uacute;"));
9a29912f
JS
2536 break;
2537 case 'y':
6c155d33 2538 TexOutput(_T("&yacute;"));
9a29912f
JS
2539 break;
2540 case 'A':
6c155d33 2541 TexOutput(_T("&Aacute;"));
9a29912f
JS
2542 break;
2543 case 'E':
6c155d33 2544 TexOutput(_T("&Eacute;"));
9a29912f
JS
2545 break;
2546 case 'I':
6c155d33 2547 TexOutput(_T("&Iacute;"));
9a29912f
JS
2548 break;
2549 case 'O':
6c155d33 2550 TexOutput(_T("&Oacute;"));
9a29912f
JS
2551 break;
2552 case 'U':
6c155d33 2553 TexOutput(_T("&Uacute;"));
9a29912f
JS
2554 break;
2555 case 'Y':
6c155d33 2556 TexOutput(_T("&Yacute;"));
9a29912f
JS
2557 break;
2558 default:
2559 break;
2560 }
2561 }
2562 }
b63b07a8 2563 return false;
9a29912f
JS
2564 }
2565 case ltACCENT_CARET:
2566 {
2567 if (start)
2568 {
6c155d33 2569 wxChar *val = GetArgData();
9a29912f
JS
2570 if (val)
2571 {
2572 switch (val[0])
2573 {
2574 case 'a':
6c155d33 2575 TexOutput(_T("&acirc;"));
9a29912f
JS
2576 break;
2577 case 'e':
6c155d33 2578 TexOutput(_T("&ecirc;"));
9a29912f
JS
2579 break;
2580 case 'i':
6c155d33 2581 TexOutput(_T("&icirc;"));
9a29912f
JS
2582 break;
2583 case 'o':
6c155d33 2584 TexOutput(_T("&ocirc;"));
9a29912f
JS
2585 break;
2586 case 'u':
6c155d33 2587 TexOutput(_T("&ucirc;"));
9a29912f
JS
2588 break;
2589 case 'A':
6c155d33 2590 TexOutput(_T("&Acirc;"));
9a29912f
JS
2591 break;
2592 case 'E':
6c155d33 2593 TexOutput(_T("&Ecirc;"));
9a29912f
JS
2594 break;
2595 case 'I':
6c155d33 2596 TexOutput(_T("&Icirc;"));
9a29912f
JS
2597 break;
2598 case 'O':
6c155d33 2599 TexOutput(_T("&Ocirc;"));
9a29912f
JS
2600 break;
2601 case 'U':
6c155d33 2602 TexOutput(_T("&Icirc;"));
9a29912f
JS
2603 break;
2604 default:
2605 break;
2606 }
2607 }
2608 }
b63b07a8 2609 return false;
9a29912f
JS
2610 }
2611 case ltACCENT_TILDE:
2612 {
2613 if (start)
2614 {
6c155d33 2615 wxChar *val = GetArgData();
9a29912f
JS
2616 if (val)
2617 {
2618 switch (val[0])
2619 {
2620 case ' ':
6c155d33 2621 TexOutput(_T("~"));
9a29912f
JS
2622 break;
2623 case 'a':
6c155d33 2624 TexOutput(_T("&atilde;"));
9a29912f
JS
2625 break;
2626 case 'n':
6c155d33 2627 TexOutput(_T("&ntilde;"));
9a29912f
JS
2628 break;
2629 case 'o':
6c155d33 2630 TexOutput(_T("&otilde;"));
9a29912f
JS
2631 break;
2632 case 'A':
6c155d33 2633 TexOutput(_T("&Atilde;"));
9a29912f
JS
2634 break;
2635 case 'N':
6c155d33 2636 TexOutput(_T("&Ntilde;"));
9a29912f
JS
2637 break;
2638 case 'O':
6c155d33 2639 TexOutput(_T("&Otilde;"));
9a29912f
JS
2640 break;
2641 default:
2642 break;
2643 }
2644 }
2645 }
b63b07a8 2646 return false;
9a29912f
JS
2647 }
2648 case ltACCENT_UMLAUT:
2649 {
2650 if (start)
2651 {
6c155d33 2652 wxChar *val = GetArgData();
9a29912f
JS
2653 if (val)
2654 {
2655 switch (val[0])
2656 {
2657 case 'a':
6c155d33 2658 TexOutput(_T("&auml;"));
9a29912f
JS
2659 break;
2660 case 'e':
6c155d33 2661 TexOutput(_T("&euml;"));
9a29912f
JS
2662 break;
2663 case 'i':
6c155d33 2664 TexOutput(_T("&iuml;"));
9a29912f
JS
2665 break;
2666 case 'o':
6c155d33 2667 TexOutput(_T("&ouml;"));
9a29912f
JS
2668 break;
2669 case 'u':
6c155d33 2670 TexOutput(_T("&uuml;"));
9a29912f
JS
2671 break;
2672 case 'y':
6c155d33 2673 TexOutput(_T("&yuml;"));
9a29912f
JS
2674 break;
2675 case 'A':
6c155d33 2676 TexOutput(_T("&Auml;"));
9a29912f
JS
2677 break;
2678 case 'E':
6c155d33 2679 TexOutput(_T("&Euml;"));
9a29912f
JS
2680 break;
2681 case 'I':
6c155d33 2682 TexOutput(_T("&Iuml;"));
9a29912f
JS
2683 break;
2684 case 'O':
6c155d33 2685 TexOutput(_T("&Ouml;"));
9a29912f
JS
2686 break;
2687 case 'U':
6c155d33 2688 TexOutput(_T("&Uuml;"));
9a29912f
JS
2689 break;
2690 case 'Y':
6c155d33 2691 TexOutput(_T("&Yuml;"));
9a29912f
JS
2692 break;
2693 default:
2694 break;
2695 }
2696 }
2697 }
b63b07a8 2698 return false;
9a29912f
JS
2699 }
2700 case ltACCENT_DOT:
2701 {
2702 if (start)
2703 {
6c155d33 2704 wxChar *val = GetArgData();
9a29912f
JS
2705 if (val)
2706 {
2707 switch (val[0])
2708 {
2709 case 'a':
6c155d33 2710 TexOutput(_T("&aring;"));
9a29912f
JS
2711 break;
2712 case 'A':
6c155d33 2713 TexOutput(_T("&Aring;"));
9a29912f
JS
2714 break;
2715 default:
2716 break;
2717 }
2718 }
2719 }
b63b07a8 2720 return false;
9a29912f
JS
2721 }
2722 case ltBACKGROUND:
2723 {
2724 if (start)
2725 {
6c155d33 2726 wxChar *val = GetArgData();
9a29912f
JS
2727 if (val)
2728 {
b63b07a8 2729 bool isPicture = false;
6a205442 2730 ParseColourString(val, &isPicture);
9a29912f
JS
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 }
b63b07a8 2745 return false;
9a29912f
JS
2746 }
2747 case ltBACKGROUNDIMAGE:
2748 {
2749 if (start)
2750 {
6c155d33 2751 wxChar *val = GetArgData();
9a29912f
JS
2752 if (val)
2753 {
2754 if (backgroundImageString)
2755 delete[] backgroundImageString;
2756 backgroundImageString = copystring(val);
2757 }
2758 }
b63b07a8 2759 return false;
9a29912f
JS
2760 }
2761 case ltBACKGROUNDCOLOUR:
2762 {
2763 if (start)
2764 {
6c155d33 2765 wxChar *val = GetArgData();
9a29912f
JS
2766 if (val)
2767 {
2768 if (backgroundColourString)
2769 delete[] backgroundColourString;
2770 backgroundColourString = copystring(val);
2771 }
2772 }
b63b07a8 2773 return false;
9a29912f
JS
2774 }
2775 case ltTEXTCOLOUR:
2776 {
2777 if (start)
2778 {
6c155d33 2779 wxChar *val = GetArgData();
9a29912f
JS
2780 if (val)
2781 {
2782 if (textColourString)
2783 delete[] textColourString;
2784 textColourString = copystring(val);
2785 }
2786 }
b63b07a8 2787 return false;
9a29912f
JS
2788 }
2789 case ltLINKCOLOUR:
2790 {
2791 if (start)
2792 {
6c155d33 2793 wxChar *val = GetArgData();
9a29912f
JS
2794 if (val)
2795 {
2796 if (linkColourString)
2797 delete[] linkColourString;
2798 linkColourString = copystring(val);
2799 }
2800 }
b63b07a8 2801 return false;
9a29912f
JS
2802 }
2803 case ltFOLLOWEDLINKCOLOUR:
2804 {
2805 if (start)
2806 {
6c155d33 2807 wxChar *val = GetArgData();
9a29912f
JS
2808 if (val)
2809 {
2810 if (followedLinkColourString)
2811 delete[] followedLinkColourString;
2812 followedLinkColourString = copystring(val);
2813 }
2814 }
b63b07a8 2815 return false;
9a29912f
JS
2816 }
2817 case ltACCENT_CADILLA:
2818 {
2819 if (start)
2820 {
6c155d33 2821 wxChar *val = GetArgData();
9a29912f
JS
2822 if (val)
2823 {
2824 switch (val[0])
2825 {
2826 case 'c':
6c155d33 2827 TexOutput(_T("&ccedil;"));
9a29912f
JS
2828 break;
2829 case 'C':
6c155d33 2830 TexOutput(_T("&Ccedil;"));
9a29912f
JS
2831 break;
2832 default:
2833 break;
2834 }
2835 }
2836 }
b63b07a8 2837 return false;
9a29912f
JS
2838 }
2839/*
2840 case ltFOOTNOTE:
2841 case ltFOOTNOTEPOPUP:
2842 {
2843 if (arg_no == 1)
b63b07a8 2844 return true;
9a29912f 2845 else
b63b07a8 2846 return false;
9a29912f
JS
2847 break;
2848 }
119f7a8c 2849*/
9a29912f
JS
2850 case ltTABULAR:
2851 case ltSUPERTABULAR:
2852 {
2853 if (arg_no == 1)
2854 {
2855 if (start)
2856 {
2857 currentRowNumber = 0;
b63b07a8
RL
2858 inTabular = true;
2859 startRows = true;
2860 tableVerticalLineLeft = false;
2861 tableVerticalLineRight = false;
9a29912f 2862
6c155d33 2863 wxChar *alignString = copystring(GetArgData());
9a29912f
JS
2864 ParseTableArgument(alignString);
2865
6c155d33 2866 TexOutput(_T("<TABLE BORDER>\n"));
9a29912f
JS
2867
2868 // Write the first row formatting for compatibility
2869 // with standard Latex
2870 if (compatibilityMode)
2871 {
6c155d33 2872 TexOutput(_T("<TR>\n<TD>"));
4fe30bce 2873 OutputFont();
9a29912f
JS
2874/*
2875 for (int i = 0; i < noColumns; i++)
2876 {
2877 currentWidth += TableData[i].width;
b63b07a8 2878 wxSnprintf(buf, sizeof(buf), _T("\\cellx%d"), currentWidth);
9a29912f
JS
2879 TexOutput(buf);
2880 }
6c155d33 2881 TexOutput(_T("\\pard\\intbl\n"));
9a29912f
JS
2882*/
2883 }
2884 delete[] alignString;
2885
b63b07a8 2886 return false;
9a29912f
JS
2887 }
2888 }
2889 else if (arg_no == 2 && !start)
2890 {
6c155d33 2891 TexOutput(_T("</TABLE>\n"));
b63b07a8 2892 inTabular = false;
9a29912f
JS
2893 }
2894 break;
2895 }
2896 case ltTHEBIBLIOGRAPHY:
2897 {
2898 if (start && (arg_no == 1))
2899 {
66828481 2900 ReopenFile(&Chapters, &ChaptersName, _T("bibliography"));
6c155d33
JS
2901 AddTexRef(_T("bibliography"), ChaptersName, _T("bibliography"));
2902 SetCurrentSubsectionName(_T("bibliography"), ChaptersName);
9a29912f
JS
2903
2904 citeCount = 1;
2905
2906 SetCurrentOutput(Chapters);
2907
6c155d33 2908 wxChar titleBuf[150];
9a29912f 2909 if (truncateFilenames)
b63b07a8 2910 wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s.htm"), wxFileNameFromPath(FileRoot));
9a29912f 2911 else
b63b07a8 2912 wxSnprintf(titleBuf, sizeof(titleBuf), _T("%s_contents.html"), wxFileNameFromPath(FileRoot));
9a29912f 2913
6d8b260c 2914 HTMLHead();
6c155d33 2915 TexOutput(_T("<title>"));
9a29912f 2916 TexOutput(ReferencesNameString);
6c155d33 2917 TexOutput(_T("</title></head>\n"));
9a29912f
JS
2918 OutputBodyStart();
2919
6c155d33
JS
2920 wxFprintf(Chapters, _T("<A NAME=\"%s\">\n<H2>%s"), _T("bibliography"), ReferencesNameString);
2921 AddBrowseButtons(_T("contents"), titleBuf, // Up
9a29912f 2922 lastTopic, lastFileName, // Last topic
6c155d33 2923 _T("bibliography"), ChaptersName); // This topic
9a29912f
JS
2924
2925 SetCurrentOutputs(Contents, Chapters);
ae6c0ccf
WS
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"));
9a29912f 2930
6c155d33
JS
2931 wxFprintf(Contents, _T("%s</A>\n"), ReferencesNameString);
2932 wxFprintf(Chapters, _T("</H2>\n</A>\n"));
9a29912f
JS
2933
2934 SetCurrentOutput(Chapters);
b63b07a8 2935 return false;
9a29912f
JS
2936 }
2937 if (!start && (arg_no == 2))
2938 {
2939 }
b63b07a8 2940 return true;
9a29912f
JS
2941 }
2942 case ltINDEX:
2943 {
2944 /* Build up list of keywords associated with topics */
2945 if (start)
2946 {
6c155d33
JS
2947// wxChar *entry = GetArgData();
2948 wxChar buf[300];
9a29912f
JS
2949 OutputChunkToString(GetArgChunk(), buf);
2950 if (CurrentTopic)
2951 {
2952 AddKeyWordForTopic(CurrentTopic, buf, currentFileName);
2953 }
2954 }
b63b07a8 2955 return false;
9a29912f
JS
2956 }
2957 case ltFCOL:
2958// case ltBCOL:
2959 {
2960 if (start)
2961 {
2962 switch (arg_no)
2963 {
2964 case 1:
2965 {
6c155d33
JS
2966 wxChar *name = GetArgData();
2967 wxChar buf2[10];
9a29912f
JS
2968 if (!FindColourHTMLString(name, buf2))
2969 {
6c155d33
JS
2970 wxStrcpy(buf2, _T("#000000"));
2971 wxChar buf[100];
4fe30bce 2972 wxSnprintf(buf, sizeof(buf), _T("Could not find colour name %s"), name);
9a29912f
JS
2973 OnError(buf);
2974 }
6c155d33 2975 TexOutput(_T("<FONT COLOR=\""));
9a29912f 2976 TexOutput(buf2);
6c155d33 2977 TexOutput(_T("\">"));
9a29912f
JS
2978 break;
2979 }
2980 case 2:
2981 {
b63b07a8 2982 return true;
9a29912f
JS
2983 }
2984 default:
2985 break;
2986 }
2987 }
2988 else
2989 {
6c155d33 2990 if (arg_no == 2) TexOutput(_T("</FONT>"));
9a29912f 2991 }
b63b07a8 2992 return false;
9a29912f
JS
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)
b63b07a8 2999 return false;
9a29912f
JS
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
6c155d33
JS
3010 wxChar *str = GetArgData();
3011 currentLevelNo = wxAtoi(str);
9a29912f
JS
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;
b63b07a8 3044 return false;
9a29912f
JS
3045 }
3046 case 2:
3047 {
b63b07a8 3048 return true;
9a29912f
JS
3049 }
3050 default:
3051 break;
3052 }
b63b07a8 3053 return true;
9a29912f
JS
3054 }
3055 else
3056 {
3057 if (arg_no == 2)
3058 {
3059 CurrentOutput1 = oldLevelFile;
3060 }
b63b07a8 3061 return true;
9a29912f
JS
3062 }
3063 }
3064 default:
3065 return DefaultOnArgument(macroId, arg_no, start);
9a29912f 3066 }
b63b07a8 3067 return true;
9a29912f
JS
3068}
3069
3070bool HTMLGo(void)
3071{
5c66e5b2
WS
3072 fileId = 0;
3073 inVerbatim = false;
3074 indentLevel = 0;
3075 inTabular = false;
3076 startRows = false;
3077 tableVerticalLineLeft = false;
3078 tableVerticalLineRight = false;
3079 noColumns = 0;
119f7a8c 3080
5c66e5b2
WS
3081 if (!InputFile.empty() && !OutputFile.empty())
3082 {
3083 // Do some HTML-specific transformations on all the strings,
3084 // recursively
3085 Text2HTML(GetTopLevelChunk());
9a29912f 3086
5c66e5b2
WS
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"));
9a29912f 3095
5c66e5b2
WS
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);
9a29912f 3100
5c66e5b2 3101 contentsFrameName = copystring(buf);
9a29912f 3102
5c66e5b2 3103 Contents = wxFopen(TmpContentsName, _T("w"));
9a29912f 3104
5c66e5b2
WS
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 }
9a29912f 3111
5c66e5b2
WS
3112 if (!Titlepage || !Contents)
3113 {
3114 OnError(_T("Cannot open output file!"));
3115 return false;
3116 }
3117 AddTexRef(_T("contents"), wxFileNameFromPath(TitlepageName), ContentsNameString);
9a29912f 3118
5c66e5b2 3119 wxFprintf(Contents, _T("<P><P><H2>%s</H2><P><P>\n"), ContentsNameString);
9a29912f 3120
5c66e5b2 3121 wxFprintf(Contents, _T("<UL>\n"));
9a29912f 3122
5c66e5b2
WS
3123 SetCurrentOutput(Titlepage);
3124 if (htmlWorkshopFiles) HTMLWorkshopStartContents();
3125 OnInform(_T("Converting..."));
9a29912f 3126
5c66e5b2
WS
3127 TraverseDocument();
3128 wxFprintf(Contents, _T("</UL>\n\n"));
9a29912f 3129
5c66e5b2
WS
3130// SetCurrentOutput(Titlepage);
3131 fclose(Titlepage);
9a29912f 3132
5c66e5b2
WS
3133 if (Contents)
3134 {
3135// wxFprintf(Titlepage, _T("\n</BODY></HTML>\n"));
3136 fclose(Contents);
3137 Contents = NULL;
3138 }
9a29912f 3139
5c66e5b2
WS
3140 if (FrameContents)
3141 {
3142 wxFprintf(FrameContents, _T("\n</UL>\n"));
3143 wxFprintf(FrameContents, _T("</HTML>\n"));
3144 fclose(FrameContents);
3145 FrameContents = NULL;
3146 }
119f7a8c 3147
5c66e5b2
WS
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 }
9a29912f 3177
5c66e5b2
WS
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 }
9a29912f 3203
5c66e5b2
WS
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());
119f7a8c 3212
5c66e5b2 3213 wxFprintf(tmpTitle, _T("<FRAMESET COLS=\"30%%,70%%\">\n"));
9a29912f 3214
5c66e5b2
WS
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"));
119f7a8c 3218
5c66e5b2
WS
3219 wxFprintf(tmpTitle, _T("<NOFRAMES>\n"));
3220 }
9a29912f 3221
5c66e5b2
WS
3222 // Output <BODY...> to temporary title page
3223 OutputBodyStart();
3224 fflush(tmpTitle);
9a29912f 3225
5c66e5b2
WS
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 }
9a29912f 3238
5c66e5b2 3239 wxFprintf(tmpTitle, _T("\n</FONT></BODY>\n"));
9a29912f 3240
5c66e5b2
WS
3241 if (htmlFrameContents)
3242 {
3243 wxFprintf(tmpTitle, _T("\n</NOFRAMES>\n"));
3244 }
3245 wxFprintf(tmpTitle, _T("\n</HTML>\n"));
9a29912f 3246
5c66e5b2
WS
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 }
9a29912f 3255
5c66e5b2
WS
3256 if (lastFileName) delete[] lastFileName;
3257 lastFileName = NULL;
3258 if (lastTopic) delete[] lastTopic;
3259 lastTopic = NULL;
9a29912f 3260
5c66e5b2 3261 if (wxFileExists(ContentsName)) wxRemoveFile(ContentsName);
9a29912f 3262
5c66e5b2
WS
3263 if (!wxRenameFile(TmpContentsName, ContentsName))
3264 {
3265 wxCopyFile(TmpContentsName, ContentsName);
3266 wxRemoveFile(TmpContentsName);
3267 }
14204c7a 3268
5c66e5b2
WS
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 }
14204c7a 3276
5c66e5b2
WS
3277 // Generate HTML Help Workshop files if requested
3278 if (htmlWorkshopFiles)
3279 {
3280 HTMLWorkshopEndContents();
3281 GenerateHTMLWorkshopFiles(FileRoot);
3282 }
14204c7a 3283
5c66e5b2
WS
3284 return true;
3285 }
3286
3287 return false;
9a29912f
JS
3288}
3289
3290// Output .htx index file
6c155d33 3291void GenerateHTMLIndexFile(wxChar *fname)
9a29912f 3292{
6c155d33 3293 FILE *fd = wxFopen(fname, _T("w"));
9a29912f
JS
3294 if (!fd)
3295 return;
3296
3297 TopicTable.BeginFind();
f6fe5318 3298 wxHashTable::Node *node = TopicTable.Next();
6c155d33 3299 while (node)
9a29912f 3300 {
ddc4f3b5 3301 TexTopic *texTopic = (TexTopic *)node->GetData();
6c155d33 3302 const wxChar *topicName = node->GetKeyString();
9a29912f
JS
3303 if (texTopic->filename && texTopic->keywords)
3304 {
ddc4f3b5 3305 wxStringListNode *node1 = texTopic->keywords->GetFirst();
9a29912f
JS
3306 while (node1)
3307 {
6c155d33
JS
3308 wxChar *s = (wxChar *)node1->GetData();
3309 wxFprintf(fd, _T("%s|%s|%s\n"), topicName, texTopic->filename, s);
ddc4f3b5 3310 node1 = node1->GetNext();
9a29912f
JS
3311 }
3312 }
6c155d33 3313 node = TopicTable.Next();
9a29912f
JS
3314 }
3315 fclose(fd);
3316}
14204c7a
VS
3317
3318
3319
3320
3321
3322
3323
3324// output .hpp, .hhc and .hhk files:
3325
3326
6c155d33 3327void GenerateHTMLWorkshopFiles(wxChar *fname)
14204c7a
VS
3328{
3329 FILE *f;
6c155d33 3330 wxChar buf[300];
14204c7a
VS
3331
3332 /* Generate project file : */
3333
b63b07a8 3334 wxSnprintf(buf, sizeof(buf), _T("%s.hhp"), fname);
6c155d33
JS
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="),
2b5f62a0
VZ
3346 wxFileNameFromPath(fname),
3347 wxFileNameFromPath(fname),
3348 wxFileNameFromPath(fname),
3349 wxFileNameFromPath(TitlepageName),
3350 wxFileNameFromPath(fname)
14204c7a 3351 );
119f7a8c 3352
14204c7a
VS
3353 if (DocumentTitle) {
3354 SetCurrentOutput(f);
3355 TraverseChildrenFromChunk(DocumentTitle);
3356 }
6c155d33 3357 else wxFprintf(f, _T("(unknown)"));
119f7a8c 3358
6c155d33
JS
3359 wxFprintf(f, _T("\n\n[WINDOWS]\n")
3360 _T("%sHelp=,\"%s.hhc\",\"%s.hhk\",\"%s\",,,,,,0x2420,,0x380e,,,,,0,,,"),
2b5f62a0
VZ
3361 wxFileNameFromPath(fname),
3362 wxFileNameFromPath(fname),
3363 wxFileNameFromPath(fname),
3364 wxFileNameFromPath(TitlepageName));
119f7a8c
RD
3365
3366
6c155d33
JS
3367 wxFprintf(f, _T("\n\n[FILES]\n"));
3368 wxFprintf(f, _T("%s\n"), wxFileNameFromPath(TitlepageName));
119f7a8c 3369 for (int i = 1; i <= fileId; i++) {
14204c7a 3370 if (truncateFilenames)
b63b07a8 3371 wxSnprintf(buf, sizeof(buf), _T("%s%d.htm"), wxFileNameFromPath(FileRoot), i);
14204c7a 3372 else
66828481 3373 wxStrcpy(buf, wxFileNameFromPath(gs_filenames[i].c_str()));
6c155d33 3374 wxFprintf(f, _T("%s\n"), buf);
14204c7a
VS
3375 }
3376 fclose(f);
3377
3378 /* Generate index file : */
3379
b63b07a8 3380 wxSnprintf(buf, sizeof(buf), _T("%s.hhk"), fname);
6c155d33 3381 f = wxFopen(buf, _T("wt"));
14204c7a 3382
6c155d33
JS
3383 wxFprintf(f,
3384 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3385 _T("<HTML>\n"));
6d8b260c 3386 HTMLHeadTo(f);
6c155d33
JS
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"));
14204c7a
VS
3396
3397 TopicTable.BeginFind();
f6fe5318 3398 wxHashTable::Node *node = TopicTable.Next();
6c155d33 3399 while (node)
14204c7a 3400 {
ddc4f3b5 3401 TexTopic *texTopic = (TexTopic *)node->GetData();
6c155d33 3402 const wxChar *topicName = node->GetKeyString();
14204c7a
VS
3403 if (texTopic->filename && texTopic->keywords)
3404 {
ddc4f3b5 3405 wxStringListNode *node1 = texTopic->keywords->GetFirst();
14204c7a
VS
3406 while (node1)
3407 {
6c155d33
JS
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"),
4fe30bce 3414 texTopic->filename, topicName, s);
ddc4f3b5 3415 node1 = node1->GetNext();
14204c7a
VS
3416 }
3417 }
6c155d33 3418 node = TopicTable.Next();
14204c7a 3419 }
119f7a8c 3420
6c155d33 3421 wxFprintf(f, _T("</UL>\n"));
14204c7a
VS
3422 fclose(f);
3423}
3424
3425
3426
3427static FILE *HTMLWorkshopContents = NULL;
3428static int HTMLWorkshopLastLevel = 0;
3429
6c155d33 3430void HTMLWorkshopAddToContents(int level, wxChar *s, wxChar *file)
14204c7a
VS
3431{
3432 int i;
3433
3434 if (level > HTMLWorkshopLastLevel)
3435 for (i = HTMLWorkshopLastLevel; i < level; i++)
6c155d33 3436 wxFprintf(HTMLWorkshopContents, _T("<UL>"));
14204c7a
VS
3437 if (level < HTMLWorkshopLastLevel)
3438 for (i = level; i < HTMLWorkshopLastLevel; i++)
6c155d33 3439 wxFprintf(HTMLWorkshopContents, _T("</UL>"));
119f7a8c 3440
14204c7a 3441 SetCurrentOutput(HTMLWorkshopContents);
6c155d33
JS
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=\""),
4fe30bce 3446 file, s);
14204c7a 3447 OutputCurrentSection();
6c155d33 3448 wxFprintf(HTMLWorkshopContents,
4fe30bce 3449 _T("\">\n")
6c155d33 3450 _T(" </OBJECT>\n"));
14204c7a
VS
3451 HTMLWorkshopLastLevel = level;
3452}
3453
3454
3455void HTMLWorkshopStartContents()
3456{
6c155d33 3457 wxChar buf[300];
b63b07a8 3458 wxSnprintf(buf, sizeof(buf), _T("%s.hhc"), FileRoot);
6c155d33 3459 HTMLWorkshopContents = wxFopen(buf, _T("wt"));
14204c7a
VS
3460 HTMLWorkshopLastLevel = 0;
3461
6c155d33
JS
3462 wxFprintf(HTMLWorkshopContents,
3463 _T("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n")
3464 _T("<HTML>\n"));
6d8b260c 3465 HTMLHeadTo(HTMLWorkshopContents);
6c155d33
JS
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"),
2b5f62a0 3478 wxFileNameFromPath(TitlepageName)
119f7a8c
RD
3479 );
3480
14204c7a
VS
3481}
3482
3483
3484void HTMLWorkshopEndContents()
3485{
ae6c0ccf
WS
3486 for (int i = HTMLWorkshopLastLevel; i >= 0; i--)
3487 wxFprintf(HTMLWorkshopContents, _T("</UL>\n"));
3488 fclose(HTMLWorkshopContents);
14204c7a 3489}
ae6c0ccf
WS
3490
3491
3492bool 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 );
bf8f21fd 3497}