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