OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [standalone/] [wxwin/] [docsystem.cpp] - Blame information for rev 817

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000, 2003, 2008 Free Software Foundation, Inc.
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
// docsystem.cpp :
23
//
24
//===========================================================================
25
//#####DESCRIPTIONBEGIN####
26
//
27
// Author(s):   julians, jld
28
// Contact(s):  julians
29
// Date:        2001/04/04
30
// Version:     $Id: docsystem.cpp,v 1.19 2001/12/11 15:59:51 julians Exp $
31
// Purpose:
32
// Description: Various classes for the documentation system
33
// Requires:
34
// Provides:
35
// See also:
36
// Known bugs:
37
// Usage:
38
//
39
//####DESCRIPTIONEND####
40
//
41
//===========================================================================
42
 
43
// ============================================================================
44
// declarations
45
// ============================================================================
46
 
47
// ----------------------------------------------------------------------------
48
// headers
49
// ----------------------------------------------------------------------------
50
#ifdef __GNUG__
51
#pragma implementation "docsystem.h"
52
#endif
53
 
54
// Includes other headers for precompiled compilation
55
#include "ecpch.h"
56
 
57
#ifdef __BORLANDC__
58
#pragma hdrstop
59
#endif
60
 
61
#include "wx/dir.h"
62
#include "wx/file.h"
63
#include "wx/wfstream.h"
64
#include "wx/progdlg.h"
65
#include "docsystem.h"
66
#include "htmlparser.h"
67
#include "configtooldoc.h"
68
#include "mainwin.h"
69
#include "shortdescrwin.h"
70
 
71
/*
72
 * ecHtmlIndexer
73
 * A class to parse files and generate suitable MS Html Help/wxHTML Help compatible
74
 * project, contents and keyword files.
75
 */
76
 
77
ecHtmlIndexer::ecHtmlIndexer(bool useRelativeURLs)
78
{
79
#if ecDOCSYSTEM_USE_RELATIVE_URLS
80
    m_useRelativeURLs = useRelativeURLs;
81
#else
82
    m_useRelativeURLs = FALSE;
83
#endif
84
    m_useOldDocs = TRUE;
85
 
86
    // Initialise some tables
87
    AddTutorialDirectory(wxT("arm"), wxT("ARM"));
88
    AddTutorialDirectory(wxT("am31-33"), wxT("AM31-33"));
89
    AddTutorialDirectory(wxT("i386pc"), wxT("i386 PC"));
90
    AddTutorialDirectory(wxT("ppc"), wxT("PowerPC"));
91
    AddTutorialDirectory(wxT("sh3"), wxT("SH-3"));
92
    AddTutorialDirectory(wxT("sparclite"), wxT("SPARClite"));
93
    AddTutorialDirectory(wxT("mips"), wxT("MIPS"));
94
    AddTutorialDirectory(wxT("v850"), wxT("V850"));
95
 
96
    AddEntityTranslation(wxT("—"), wxT("--"));
97
    AddEntityTranslation(wxT("&"), wxT("&"));
98
    AddEntityTranslation(wxT("“"), wxT("\""));
99
    AddEntityTranslation(wxT("”"), wxT("\""));
100
    AddEntityTranslation(wxT("["), wxT("["));
101
    AddEntityTranslation(wxT("]"), wxT("]"));
102
}
103
 
104
ecHtmlIndexer::~ecHtmlIndexer()
105
{
106
    ClearItems();
107
}
108
 
109
// Append HHC-compatible code to a stream according to the tags found in the
110
// given HTML file.
111
/*
112
 
113
Find the name and URL from a chunk of HTML like
114
the following.
115
 
116
<P CLASS="ChapterTitleTOC">
117
  <A NAME="pgfId=141252">
118
  </A>
119
  <A HREF="ecos-tutorial.4.html#pgfId=1065474" CLASS="Index">
120
     Documentation Roadmap
121
  </A>
122
     <EM CLASS="PageNumber"></EM>
123
</P>
124
 
125
We need to output something like this:
126
 
127
    <UL>
128
    <LI> <OBJECT type="text/sitemap"><param name="Name" value="Getting Started with eCos"><param name="Local" value="tutorials/arm/ecos-tutorial.1.html"></OBJECT>
129
    <LI> <UL>
130
           <LI> <OBJECT type="text/sitemap"><param name="Name" value="ARM"><param name="Local" value="tutorials/arm/ecos-tutorial.1.html"></OBJECT>
131
           <LI> <UL>
132
                  <LI><OBJECT type="text/sitemap"><param name="Name" value="Getting Started with eCos"><param name="Local" value="tutorials/arm/ecos-tutorial.1.html#pgfId=2052424"></OBJECT>
133
                  <LI><OBJECT type="text/sitemap"><param name="Name" value="Foreword"><param name="Local" value="tutorials/arm/ecos-tutorial.3.html#pgfId=1065235"></OBJECT>
134
                  <LI><OBJECT type="text/sitemap"><param name="Name" value="Documentation Roadmap"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1065474"></OBJECT>
135
                  <LI><UL>
136
                        <LI><OBJECT type="text/sitemap"><param name="Name" value="Getting Started with eCos"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1046487"></OBJECT>
137
                        <LI><OBJECT type="text/sitemap"><param name="Name" value="eCos User's Guide"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1046592"></OBJECT>
138
                        <LI><OBJECT type="text/sitemap"><param name="Name" value="eCos Reference Manual"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1046692"></OBJECT>
139
                      </UL>
140
                </UL>
141
         </UL>
142
  </UL>
143
 
144
*/
145
 
146
bool ecHtmlIndexer::CreateHHCByExaminingClass(const wxString& title, const wxString& topURL, const wxString& htmlFile, const wxString& docDir, wxOutputStream& stream, int startIndent)
147
{
148
    if (!wxFileExists(htmlFile))
149
        return FALSE;
150
 
151
    wxString sep(wxFILE_SEP_PATH);
152
    wxString pathPrefix(wxPathOnly(htmlFile));
153
    if (!wxIsAbsolutePath(htmlFile))
154
    {
155
        pathPrefix = pathPrefix.Mid(docDir.Length() + 1);
156
    }
157
 
158
    wxString topURL1(topURL);
159
    if (!UseRelativeURLs() && !wxIsAbsolutePath(topURL1))
160
        topURL1 = docDir + sep + topURL1;
161
 
162
    wxSimpleHtmlParser parser;
163
    if (parser.ParseFile(htmlFile))
164
    {
165
        stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\"";
166
        stream << TranslateEntities(title) << wxString("\">");
167
 
168
        if (!topURL.IsEmpty())
169
        {
170
            stream << "<param name=\"Local\" value=\"";
171
            stream << topURL1 << "\"></OBJECT>";
172
        }
173
        stream << "\n";
174
        int indent = startIndent;
175
        wxSimpleHtmlTag* tag = parser.GetTopLevelTag()->GetChildren();
176
 
177
        while (tag)
178
        {
179
            if (tag->GetType() == wxSimpleHtmlTag_Open)
180
            {
181
                wxSimpleHtmlAttribute* attr = NULL;
182
                if ((tag->NameIs("P") || tag->NameIs("DIV") ||
183
                     tag->NameIs("H1") || tag->NameIs("H2") || tag->NameIs("H3") || tag->NameIs("H4"))
184
                     &&
185
                     (attr = tag->FindAttribute("CLASS")))
186
                {
187
                    int level = -1;
188
                    if (attr->HasValue("Level1IX") ||
189
                        attr->HasValue("SectionTitleTOC") ||
190
                        attr->HasValue("IndexTitleTOC"))
191
                        level = 1;
192
 
193
                    else if (attr->HasValue("Level2IX") ||
194
                        attr->HasValue("ChapterTitleTOC") ||
195
                        attr->HasValue("IntroTitleTOC"))
196
                        level = 2;
197
 
198
                    else if (attr->HasValue("Heading1TOC"))
199
                        level = 3;
200
 
201
                    else if (attr->HasValue("Heading2TOC"))
202
                        level = 4;
203
 
204
                    if (level > -1)
205
                    {
206
                        wxSimpleHtmlTag* aTag = tag->FindTag("A", "HREF");
207
                        if (aTag)
208
                            CreateHHCOutputItem(aTag, level, indent, pathPrefix, docDir, stream);
209
                    }
210
                }
211
            }
212
            tag = tag->GetNext();
213
        }
214
 
215
        // Close any remaining levels
216
        int i;
217
        while (indent > startIndent)
218
        {
219
            indent --;
220
            for (i = 0; i < indent*2; i++) stream << " ";
221
            stream << "</UL>\n";
222
        }
223
 
224
        return TRUE;
225
    }
226
    else
227
        return FALSE;
228
}
229
 
230
// Append HHC-compatible code to a stream according to the tags found in the
231
// given HTML file. Use level of <DL> to determine contents heading level.
232
 
233
/*
234
 
235
Find the name and URL from a chunk of HTML like
236
the following.
237
 
238
<DL>
239
  <DT>
240
  <B>Table of Contents</B>
241
  </DT>
242
  <DT>
243
  1. <A HREF="overview.html">Overview</A>
244
  </DT>
245
  <DD>
246
    <DL>
247
      <DT>
248
      <A HREF="overview.html#OVERVIEW.TERMINOLOGY">Terminology</A>
249
      </DT>
250
      <DD>
251
        <DL>
252
          <DT>
253
          <A HREF="overview.html#CONCEPTS.TERMINOLOGY.FRAMEWORK">Component Framework</A>
254
          </DT>
255
 
256
  ...
257
 
258
    <UL>
259
    <LI> <OBJECT type="text/sitemap"><param name="Name" value="Getting Started with eCos"><param name="Local" value="tutorials/arm/ecos-tutorial.1.html"></OBJECT>
260
    <LI> <UL>
261
           <LI> <OBJECT type="text/sitemap"><param name="Name" value="ARM"><param name="Local" value="tutorials/arm/ecos-tutorial.1.html"></OBJECT>
262
           <LI> <UL>
263
                  <LI><OBJECT type="text/sitemap"><param name="Name" value="Getting Started with eCos"><param name="Local" value="tutorials/arm/ecos-tutorial.1.html#pgfId=2052424"></OBJECT>
264
                  <LI><OBJECT type="text/sitemap"><param name="Name" value="Foreword"><param name="Local" value="tutorials/arm/ecos-tutorial.3.html#pgfId=1065235"></OBJECT>
265
                  <LI><OBJECT type="text/sitemap"><param name="Name" value="Documentation Roadmap"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1065474"></OBJECT>
266
                  <LI><UL>
267
                        <LI><OBJECT type="text/sitemap"><param name="Name" value="Getting Started with eCos"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1046487"></OBJECT>
268
                        <LI><OBJECT type="text/sitemap"><param name="Name" value="eCos User's Guide"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1046592"></OBJECT>
269
                        <LI><OBJECT type="text/sitemap"><param name="Name" value="eCos Reference Manual"><param name="Local" value="tutorials/arm/ecos-tutorial.4.html#pgfId=1046692"></OBJECT>
270
                      </UL>
271
                </UL>
272
         </UL>
273
  </UL>
274
 
275
*/
276
 
277
bool ecHtmlIndexer::CreateHHCByExaminingList(const wxString& title, const wxString& topURL, const wxString& htmlFile, const wxString& docDir, wxOutputStream& stream, int startIndent)
278
{
279
    if (!wxFileExists(htmlFile))
280
        return FALSE;
281
 
282
    // The path prefix is the path relative to the doc dir
283
    wxString sep(wxFILE_SEP_PATH);
284
    wxString pathPrefix(wxPathOnly(htmlFile));
285
    if (!wxIsAbsolutePath(htmlFile))
286
    {
287
        pathPrefix = pathPrefix.Mid(docDir.Length() + 1);
288
    }
289
 
290
    wxString topURL1(topURL);
291
    if (!UseRelativeURLs() && !wxIsAbsolutePath(topURL1))
292
        topURL1 = docDir + sep + topURL1;
293
 
294
    wxSimpleHtmlParser parser;
295
    if (parser.ParseFile(htmlFile))
296
    {
297
        stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\"";
298
        stream << TranslateEntities(title) << wxString("\">");
299
 
300
        if (!topURL.IsEmpty())
301
        {
302
            stream << "<param name=\"Local\" value=\"";
303
            stream << topURL1 << "\"></OBJECT>";
304
        }
305
        stream << "\n";
306
        int indent = startIndent; int level = 0;
307
        wxSimpleHtmlTag* tag = parser.GetTopLevelTag()->GetChildren();
308
 
309
        while (tag)
310
        {
311
            if (tag->GetType() == wxSimpleHtmlTag_Open && tag->NameIs("DL")) level ++ ;
312
            if (tag->GetType() == wxSimpleHtmlTag_Close && tag->NameIs("DL")) level -- ;
313
            if (tag->GetType() == wxSimpleHtmlTag_Open && tag->NameIs("A") && tag->HasAttribute("HREF") && level > 0)
314
                CreateHHCOutputItem(tag, level, indent, pathPrefix, docDir, stream);
315
 
316
            // If we get to list of figures/tables/examples, finish
317
            if (tag->GetType() == wxSimpleHtmlTag_Text)
318
            {
319
                if (tag->GetText() == wxT("List of Figures") ||
320
                    tag->GetText() == wxT("List of Tables") ||
321
                    tag->GetText() == wxT("List of Examples"))
322
                {
323
                    tag = NULL;
324
                }
325
            }
326
 
327
            if (tag)
328
                tag = tag->GetNext();
329
        }
330
 
331
        // Close any remaining levels
332
        int i;
333
        while (indent > startIndent)
334
        {
335
            indent --;
336
            for (i = 0; i < indent*2; i++) stream << " ";
337
            stream << "</UL>\n";
338
        }
339
        return TRUE;
340
    }
341
    else
342
        return FALSE;
343
}
344
 
345
// Just add the given contents item without parsing
346
bool ecHtmlIndexer::CreateHHCItem(const wxString& title, const wxString& topURL, const wxString& docDir, wxOutputStream& stream, int indent)
347
{
348
    wxString sep(wxFILE_SEP_PATH);
349
    wxString topURL1(topURL);
350
    if (!UseRelativeURLs())
351
        topURL1 = docDir + sep + topURL1;
352
 
353
    int i;
354
    for (i = 0; i < indent*2; i++) stream << " ";
355
 
356
    stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\"";
357
    stream << TranslateEntities(title) << "\"><param name=\"Local\" value=\"";
358
    stream << topURL1 << "\"></OBJECT>\n";
359
 
360
    return TRUE;
361
}
362
 
363
void ecHtmlIndexer::CreateHHCOutputItem(wxSimpleHtmlTag* tag, int level, int& indent, const wxString& pathPrefix, const wxString& docDir, wxOutputStream& stream)
364
{
365
    wxString url, text;
366
    tag->GetAttributeValue(url, "HREF");
367
    tag->FindTextUntilTagClose(text, "A");
368
    text.Trim(TRUE); // Trim spaces from right of string
369
    text.Replace("\n", " "); // Remove newlines
370
 
371
    // Need to adjust the URL to give the path relative to where the index is
372
    url = pathPrefix + wxString(wxT("/")) + url;
373
 
374
    wxString sep(wxFILE_SEP_PATH);
375
    wxString url1(url);
376
    if (!UseRelativeURLs() && !wxIsAbsolutePath(url))
377
        url1 = docDir + sep + url;
378
 
379
    int i;
380
    while (level > indent)
381
    {
382
        for (i = 0; i < indent*2; i++) stream << " ";
383
 
384
        stream << "<UL>";
385
        indent ++;
386
 
387
        // If we're skipping one or more levels, we need to insert
388
        // a dummy node.
389
        if (level > indent)
390
        {
391
            stream << "\n";
392
            for (i = 0; i < indent*2; i++) stream << " ";
393
 
394
            stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\"";
395
            stream << TranslateEntities(text) << "\"><param name=\"Local\" value=\"";
396
            stream << url1 << "\"></OBJECT>";
397
        }
398
        stream << "\n";
399
    }
400
 
401
    while (level < indent)
402
    {
403
        indent--;
404
        for (i = 0; i < indent*2; i++) stream << " ";
405
 
406
        stream << "</UL>\n";
407
    }
408
 
409
    for (i = 0; i < indent*2; i++) stream << " ";
410
 
411
    stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\"";
412
    stream << TranslateEntities(text) << "\"><param name=\"Local\" value=\"";
413
    stream << url1 << "\"></OBJECT>\n";
414
}
415
 
416
void ecHtmlIndexer::CreateHHCWriteHeader(wxOutputStream& stream)
417
{
418
    stream << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n";
419
    stream << "<HTML>\n<HEAD>\n<meta name=\"GENERATOR\" content=\"Microsoft&reg; HTML Help Workshop 4.1\">\n";
420
    stream << "<!-- Sitemap 1.0 -->\n</HEAD><BODY>\n";
421
    stream << "<UL>\n";
422
}
423
 
424
void ecHtmlIndexer::CreateHHCWriteFooter(wxOutputStream& stream)
425
{
426
    stream << "</UL>\n";
427
    stream << "</BODY></HTML>";
428
}
429
 
430
bool ecHtmlIndexer::CreateHHCStartSection(const wxString& title, const wxString& topURL, const wxString& docDir, wxOutputStream& stream)
431
{
432
    wxString sep(wxFILE_SEP_PATH);
433
    wxString url1(topURL);
434
    if (!UseRelativeURLs() && !wxIsAbsolutePath(url1))
435
        url1 = docDir + sep + url1;
436
 
437
    stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\"";
438
    stream << TranslateEntities(title) << wxString("\">");
439
 
440
    if (!topURL.IsEmpty())
441
    {
442
        stream << "<param name=\"Local\" value=\"";
443
        stream << url1 << "\">" ;
444
    }
445
    stream << "</OBJECT>\n<UL>\n" ;
446
    return TRUE;
447
}
448
 
449
bool ecHtmlIndexer::CreateHHCEndSection(wxOutputStream& stream)
450
{
451
    stream << "</UL>\n";
452
    return TRUE;
453
}
454
 
455
// Write the project file
456
bool ecHtmlIndexer::WriteHHP(const wxString& filename, const wxString& docDir)
457
{
458
    wxFileOutputStream stream(filename);
459
 
460
    wxString sep(wxFILE_SEP_PATH);
461
    wxString path, name, ext;
462
    wxSplitPath(filename, & path, & name, & ext);
463
 
464
    wxString compiledFile(name + wxT(".chm"));
465
    wxString contentsFile(name + wxT(".hhc"));
466
    wxString keywordFile(name + wxT(".hhk"));
467
 
468
    stream << "[OPTIONS]\n\
469
Auto Index=Yes\n\
470
Binary Index=No\n\
471
Compatibility=1.1 or later\n\
472
Compiled file=";
473
    stream << compiledFile << "\nContents file=" << contentsFile << "\n";
474
    stream <<
475
"Default Window=mainwin\n\
476
Default topic=";
477
    if (!UseRelativeURLs())
478
        stream << docDir + sep;
479
    stream << wxT("index.html") << "\n\
480
Display compile progress=Yes\n\
481
Full-text search=Yes\n" <<
482
 
483
// Index file=" << keywordFile << "\n
484
 
485
"Language=0x409 English (United States)\n\
486
Title=eCos Documentation\n";
487
 
488
    stream <<
489
"[WINDOWS]\n\
490
mainwin=\"eCos Documentation\",\"eCos.hhc\",,,\"index.html\",\"http://sources.redhat.com/ecos/\",\"Net Release\",\"http://www.redhat.com/products/ecos/\",\"eCos Product\",0x40060420,,0xc287e,[0,0,762,400],,,,,,,0\n\
491
\n\
492
[FILES]\n\
493
index.html\n\
494
\n\
495
[INFOTYPES]\n" ;
496
 
497
    // When we have the ability to generate a hhk, replace above line with:
498
    // mainwin=\"eCos Documentation\",\"eCos.hhc\",\"eCos.hhk\",,\"index.html\",\"http://sources.redhat.com/ecos/\",\"Net Release\",\"http://www.redhat.com/products/ecos/\",\"eCos Product\",0x40060420,,0xc287e,[0,0,762,400],,,,,,,0\n\
499
 
500
    return TRUE;
501
 
502
}
503
 
504
// Create a section for all the Packages in the system, using the current document/repository.
505
// TODO: check each URL for redirection.
506
bool ecHtmlIndexer::CreateHHCPackagesSection(const wxString& title, const wxString& topURL, wxOutputStream& stream, const wxString& htmlPath)
507
{
508
    ecConfigToolDoc* doc = wxGetApp().GetConfigToolDoc();
509
    if (!doc)
510
        return FALSE;
511
 
512
    // If we have multiple tutorials or whatever, then we need to repeat this line ONCE
513
    // and then generate the multiple files. Otherwise we'll be repeating the same "Getting Started with eCos"
514
    // line. I.e. it'll only look right if we only have one tutorial.
515
    stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\"";
516
    stream << TranslateEntities(title) << wxString("\">");
517
 
518
    if (!topURL.IsEmpty())
519
    {
520
        stream << "<param name=\"Local\" value=\"";
521
        stream << topURL << "\">" ;
522
    }
523
    stream << "</OBJECT>\n<UL>\n" ;
524
 
525
    // generate the contents of the add/remove list boxes
526
    const std::vector<std::string> & packages = doc->GetCdlPkgData ()->get_packages ();
527
 
528
    std::vector<std::string>::const_iterator package_i;
529
    for (package_i = packages.begin (); package_i != packages.end (); package_i++)
530
    {
531
        //              if (! m_CdlPkgData->is_hardware_package (* package_i)) // do not list hardware packages
532
        {
533
            const std::vector<std::string> & aliases = doc->GetCdlPkgData ()->get_package_aliases (* package_i);
534
            wxString strMacroName = package_i->c_str ();
535
 
536
            // use the first alias (if any) as the package identifier
537
            wxString strPackageName = aliases.size () ? aliases [0].c_str () : strMacroName.c_str();
538
            ecConfigItem * pItem = doc->Find (strMacroName);
539
            if (pItem) // if the package is loaded
540
            {
541
                // TODO: what if the package is not loaded? how do we access the URL??
542
 
543
                wxString url(pItem->GetURL());
544
 
545
                url = htmlPath + wxString(wxFILE_SEP_PATH) + Redirect(htmlPath, url);
546
 
547
                stream << "<LI> <OBJECT type=\"text/sitemap\"><param name=\"Name\" value=\"";
548
                stream << TranslateEntities(strPackageName) << wxString("\">");
549
 
550
                if (!url.IsEmpty())
551
                {
552
                    stream << "<param name=\"Local\" value=\"";
553
                    stream << url << "\">" ;
554
                }
555
                stream << "</OBJECT>\n" ;
556
            }
557
        }
558
    }
559
 
560
    stream << "</UL>\n";
561
    return TRUE;
562
}
563
 
564
// Keeping looking for redirection until there's none.
565
wxString ecHtmlIndexer::Redirect(const wxString& baseName, const wxString& url)
566
{
567
    wxString path(baseName);
568
    path += wxFILE_SEP_PATH;
569
    path += url;
570
 
571
    wxString relativePath(wxPathOnly(url));
572
 
573
    wxSimpleHtmlParser parser;
574
    if ((path.Find(wxT('#')) == -1) && wxFileExists(path) && parser.ParseFile(path))
575
    {
576
        wxSimpleHtmlTag* tag = parser.GetTopLevelTag()->GetChildren();
577
 
578
        wxSimpleHtmlTag* refreshTag = tag->FindTag(wxT("meta"), wxT("http-equiv"));
579
        if (refreshTag)
580
        {
581
            wxString value;
582
            if (refreshTag->GetAttributeValue(value, wxT("content")))
583
            {
584
                if (!value.AfterFirst(wxT('=')).IsEmpty())
585
                    value = value.AfterFirst(wxT('=')) ;
586
 
587
                wxString newURL(relativePath + wxString(wxFILE_SEP_PATH) + value);
588
                return Redirect(baseName, newURL);
589
            }
590
        }
591
    }
592
    return url;
593
}
594
 
595
bool ecHtmlIndexer::DoIndexDocs(const wxString& reposDir, wxString& projectFile, bool force)
596
{
597
    wxString sep(wxFILE_SEP_PATH);
598
 
599
    wxString docDir(reposDir + sep + wxString(wxT("doc"))) ;
600
 
601
    // The CVS repository has an HTML subdirectory, but the
602
    // packaged version doesn't
603
    if (wxDirExists(docDir + sep + wxT("html")))
604
        docDir = docDir + sep + wxString(wxT("html"));
605
 
606
    wxString projectDir = FindIndexFilesDir(reposDir);
607
 
608
    projectFile = projectDir + sep + wxT("eCos.hhp");
609
    wxString contentsFile = projectDir + sep + wxT("eCos.hhc");
610
    wxString keywordFile = projectDir + sep + wxT("eCos.hhk");
611
 
612
    // See if it's already been generated
613
    if (wxFileExists(projectFile) && !force)
614
        return TRUE;
615
 
616
    // Project file
617
    if (!WriteHHP(projectFile, docDir))
618
        return FALSE;
619
 
620
    wxFileOutputStream stream(contentsFile);
621
 
622
    if (!stream.Ok())
623
        return FALSE;
624
 
625
    // Pop up a progress dialog
626
    wxProgressDialog dialog(wxGetApp().GetSettings().GetAppName(),
627
#if wxCHECK_VERSION(2, 6, 0)
628
        _("Compiling documentation index..."), m_indexItems.GetCount(),
629
#else
630
        _("Compiling documentation index..."), m_indexItems.Number(),
631
#endif
632
        wxGetApp().GetTopWindow());
633
 
634
    CreateHHCWriteHeader(stream);
635
 
636
    int count = 1;
637
#if wxCHECK_VERSION(2, 6, 0)
638
    wxNode* node = m_indexItems.GetFirst();
639
    while (node)
640
    {
641
        dialog.Update(count);
642
        count ++;
643
 
644
        ecIndexItem* item = (ecIndexItem*) node->GetData();
645
#else
646
    wxNode* node = m_indexItems.First();
647
    while (node)
648
    {
649
        dialog.Update(count);
650
        count ++;
651
 
652
        ecIndexItem* item = (ecIndexItem*) node->Data();
653
#endif
654
        wxString filename(item->m_urlToExamine);
655
        wxString urlFilename(item->m_urlToShow);
656
 
657
        if (!filename.IsEmpty())
658
        {
659
            if (!wxIsAbsolutePath(filename))
660
                filename = docDir + sep + filename;
661
#ifdef __WXMSW__
662
            filename.Replace(wxT("/"), wxT("\\"));
663
#endif
664
        }
665
 
666
        // Check that the URL we're going to show is available,
667
        // otherwise don't output it
668
        bool isOk = TRUE;
669
        if (!urlFilename.IsEmpty())
670
        {
671
            if (!wxIsAbsolutePath(urlFilename))
672
                urlFilename = docDir + sep + urlFilename;
673
#ifdef __WXMSW__
674
            urlFilename.Replace(wxT("/"), wxT("\\"));
675
#endif
676
            // Remove # part if there is any
677
            if (urlFilename.Find(wxT('#')) != -1)
678
                urlFilename = urlFilename.BeforeLast(wxT('#'));
679
            if (!wxFileExists(urlFilename))
680
                isOk = FALSE;
681
        }
682
 
683
        if (isOk)
684
        {
685
            switch (item->m_type)
686
            {
687
            case ecIndexByClass:
688
                {
689
                    CreateHHCByExaminingClass(item->m_title, item->m_urlToShow, filename, docDir, stream, item->m_startLevel);
690
                    break;
691
                }
692
            case ecIndexByList:
693
                {
694
                    CreateHHCByExaminingList(item->m_title, item->m_urlToShow, filename, docDir, stream, item->m_startLevel);
695
                    break;
696
                }
697
            case ecIndexNoParse:
698
                {
699
                    CreateHHCItem(item->m_title, item->m_urlToShow, docDir, stream, item->m_startLevel);
700
                    break;
701
                }
702
            case ecIndexStartSection:
703
                {
704
                    CreateHHCStartSection(item->m_title, item->m_urlToShow, docDir, stream);
705
                    break;
706
                }
707
            case ecIndexEndSection:
708
                {
709
                    CreateHHCEndSection(stream);
710
                    break;
711
                }
712
            default:
713
                {
714
                    wxASSERT( FALSE );
715
                    break;
716
                }
717
            }
718
        }
719
 
720
#if wxCHECK_VERSION(2, 6, 0)
721
        node = node->GetNext();
722
#else
723
        node = node->Next();
724
#endif
725
    }
726
 
727
//    CreateHHCPackagesSection(wxT("Packages"), wxEmptyString, stream, docDir);
728
 
729
    CreateHHCWriteFooter(stream);
730
 
731
#if 0 // def __WXGTK__
732
    // Hack to restore correct colour to short description window
733
    ecShortDescriptionWindow* sdw = wxGetApp().GetMainFrame()->GetShortDescriptionWindow();
734
 
735
    wxColour oldColour = sdw->GetBackgroundColour();
736
    if (oldColour.Ok())
737
    {
738
        sdw->SetBackgroundColour(*wxBLACK);
739
        sdw->SetBackgroundColour(oldColour);
740
    }
741
#endif
742
 
743
    return TRUE;
744
}
745
 
746
static bool ecDirectoryWriteable(const wxString& dir)
747
{
748
    // See if we can write to it
749
    wxString sep(wxFILE_SEP_PATH);
750
    wxString testFile = dir + sep + wxT("_test.tmp");
751
 
752
    bool ok = FALSE;
753
 
754
    {
755
        wxLogNull log;
756
        wxFile file;
757
        ok = file.Create(testFile) ;
758
        if (ok)
759
        {
760
            file.Close();
761
            wxRemoveFile(testFile);
762
        }
763
    }
764
 
765
    return ok;
766
}
767
 
768
// Find appropriate destination directory for writing files to
769
wxString ecHtmlIndexer::FindIndexFilesDir(const wxString& reposDir)
770
{
771
    wxString sep(wxFILE_SEP_PATH);
772
 
773
    // First try install dir
774
    wxString dir = reposDir;
775
 
776
#ifdef __WXMSW__
777
    if (!ecDirectoryWriteable(dir))
778
    {
779
        // Try temp directory as a last resort
780
        if (!wxGetEnv(wxT("TEMP"), & dir))
781
        {
782
            dir = wxT("c:\\temp");
783
        }
784
        return dir;
785
    }
786
    else
787
    {
788
        return dir;
789
    }
790
 
791
#else
792
    if (!ecDirectoryWriteable(dir))
793
    {
794
        dir = wxGetHomeDir();
795
        if (!ecDirectoryWriteable(dir))
796
        {
797
            // Try temp directory as a last resort
798
            if (!wxGetEnv(wxT("TEMP"), & dir))
799
            {
800
                dir = wxT("/tmp");
801
            }
802
        }
803
        else
804
        {
805
            wxString ecosDir = dir + sep + wxT(".eCosDocs");
806
            if (!wxDirExists(ecosDir))
807
            {
808
                wxMkdir(ecosDir);
809
            }
810
            wxString name(ecMakeNameFromPath(reposDir));
811
            wxString ecosVerDir = ecosDir + sep + name;
812
            if (!wxDirExists(ecosVerDir))
813
            {
814
                wxMkdir(ecosVerDir);
815
            }
816
            dir = ecosVerDir;
817
        }
818
        return dir;
819
    }
820
    else
821
    {
822
        return dir;
823
    }
824
 
825
#endif
826
}
827
 
828
//// Operations on items
829
void ecHtmlIndexer::AddIndexByClass(const wxString& title, const wxString& urlToShow, const wxString& urlToExamine, int startIndent)
830
{
831
    m_indexItems.Append(new ecIndexItem(ecIndexByClass, title, urlToShow, urlToExamine, startIndent));
832
}
833
 
834
void ecHtmlIndexer::AddIndexByList(const wxString& title, const wxString& urlToShow, const wxString& urlToExamine, int startIndent)
835
{
836
    m_indexItems.Append(new ecIndexItem(ecIndexByList, title, urlToShow, urlToExamine, startIndent));
837
}
838
 
839
void ecHtmlIndexer::AddIndexItem(const wxString& title, const wxString& urlToShow, int startIndent)
840
{
841
    m_indexItems.Append(new ecIndexItem(ecIndexNoParse, title, urlToShow, wxEmptyString, startIndent));
842
}
843
 
844
void ecHtmlIndexer::AddStartSection(const wxString& title, const wxString& urlToShow)
845
{
846
    m_indexItems.Append(new ecIndexItem(ecIndexStartSection, title, urlToShow, wxEmptyString));
847
}
848
 
849
void ecHtmlIndexer::AddEndSection()
850
{
851
    m_indexItems.Append(new ecIndexItem(ecIndexEndSection, wxEmptyString, wxEmptyString, wxEmptyString));
852
}
853
 
854
void ecHtmlIndexer::ClearItems()
855
{
856
#if wxCHECK_VERSION(2, 6, 0)
857
    wxNode* node = m_indexItems.GetFirst();
858
    while (node)
859
    {
860
        ecIndexItem* item = (ecIndexItem*) node->GetData();
861
        delete item;
862
        node = node->GetNext();
863
#else
864
    wxNode* node = m_indexItems.First();
865
    while (node)
866
    {
867
        ecIndexItem* item = (ecIndexItem*) node->Data();
868
        delete item;
869
        node = node->Next();
870
#endif
871
    }
872
    m_indexItems.Clear();
873
}
874
 
875
// Set m_useOldDocs to TRUE if we find old-style docs
876
bool ecHtmlIndexer::CheckDocEra(const wxString& reposDir)
877
{
878
    // We look for tutorials/arm/ecos-tutorial.1.html to see if it's old-style
879
    wxString sep(wxFILE_SEP_PATH);
880
 
881
    wxString docDir(reposDir + sep + wxString(wxT("doc"))) ;
882
 
883
    // The CVS repository has an HTML subdirectory, but the
884
    // packaged version doesn't
885
    if (wxDirExists(docDir + sep + wxT("html")))
886
        docDir = docDir + sep + wxString(wxT("html"));
887
 
888
    wxString armTutorial = docDir + sep + wxString(wxT("tutorials")) + sep +
889
        wxString(wxT("arm")) + sep + wxString(wxT("ecos-tutorial.1.html")) ;
890
 
891
    m_useOldDocs = wxFileExists(armTutorial);
892
    return m_useOldDocs;
893
}
894
 
895
 
896
// Top-level function: generate appropriate index files
897
// and place them either in the install directory or if that is read-only,
898
// in the user's .eCos directory.
899
// Returns TRUE and the created project file if successful
900
bool ecHtmlIndexer::IndexDocs(const wxString& reposDir, wxString& projectFile, bool force)
901
{
902
    CheckDocEra(reposDir);
903
 
904
    if (UseOldDocs())
905
    {
906
        // Old-style docs, where HTML is mostly generated from PageMaker
907
 
908
        AddStartSection(wxT("Getting Started with eCos"), wxT(""));
909
        AddIndexByClass(wxT("AM31-33"), wxT("tutorials/am31-33/ecos-tutorial.1.html"), wxT("tutorials/am31-33/ecos-tutorial.2.html"));
910
        AddIndexByClass(wxT("ARM"), wxT("tutorials/arm/ecos-tutorial.1.html"), wxT("/tutorials/arm/ecos-tutorial.2.html"));
911
        AddIndexByClass(wxT("i386 PC"), wxT("tutorials/i386pc/ecos-tutorial.1.html"), wxT("tutorials/i386pc/ecos-tutorial.2.html"));
912
        AddIndexByClass(wxT("PowerPC"), wxT("tutorials/ppc/ecos-tutorial.1.html"), wxT("tutorials/ppc/ecos-tutorial.2.html"));
913
        AddIndexByClass(wxT("SH-3"), wxT("tutorials/sh3/ecos-tutorial.1.html"), wxT("tutorials/sh3/ecos-tutorial.2.html"));
914
        AddIndexByClass(wxT("SPARClite"), wxT("tutorials/sparclite/ecos-tutorial.1.html"), wxT("tutorials/sparclite/ecos-tutorial.2.html"));
915
        AddIndexByClass(wxT("MIPS"), wxT("tutorials/mips/ecos-tutorial.1.html"), wxT("tutorials/mips/ecos-tutorial.2.html"));
916
        AddIndexByClass(wxT("V850"), wxT("tutorials/v850/ecos-tutorial.1.html"), wxT("tutorials/v850/ecos-tutorial.2.html"));
917
        AddEndSection();
918
 
919
        AddIndexByClass(wxT("eCos User's Guide"), wxT("guides/user-guides.1.html"), wxT("guides/user-guides.2.html"));
920
 
921
        AddIndexByList(wxT("RedBoot User's Guide"), wxT("redboot/redboot.html"), wxT("redboot/redboot.html"));
922
 
923
        AddIndexByClass(wxT("Linux Configuration Tool Guide"), wxGetApp().GetFullAppPath(wxT("manual/user-guides.4.html")), wxGetApp().GetFullAppPath(wxT("manual/user-guides.2.html")));
924
 
925
        AddIndexByList(wxT("eCos Component Writer's Guide"), wxT("cdl/cdl-guide.html"), wxT("cdl/cdl-guide.html"));
926
 
927
        AddIndexByClass(wxT("eCos Reference Manual"), wxT("ref/ecos-ref.1.html"), wxT("ref/ecos-ref.2.html"));
928
 
929
        AddIndexByClass(wxT("eCos-EL/IX Compatibility Guide"), wxT("ecos-elix/ecos-elix.html"), wxT("ecos-elix/ecos-elix.1.html"), 1);
930
 
931
        AddStartSection(wxT("GNUPro Toolkit Reference Manual"));
932
        // Start at indent 1 to avoid a spurious level
933
        AddIndexByClass(wxT("ARM"), wxT("ref/gnupro-ref/arm/ARM_COMBO_front.html"), wxT("ref/gnupro-ref/arm/ARM_COMBOTOC.html"), 1);
934
        AddIndexByClass(wxT("Fujitsu SPARClite"), wxT("ref/gnupro-ref/sparclite/index.html"), wxT("ref/gnupro-ref/sparclite/index.html"));
935
        AddIndexByClass(wxT("Matsushita MN10300"), wxT("ref/gnupro-ref/mn10300/am33_front.html"), wxT("ref/gnupro-ref/mn10300/am33toc.html"), 1);
936
        AddIndexByClass(wxT("PowerPC"), wxT("ref/gnupro-ref/powerpc/index.html"), wxT("ref/gnupro-ref/powerpc/index.html"));
937
        AddIndexByClass(wxT("Toshiba MIPS TX39"), wxT("/gnupro-ref/tx39/index.html"), wxT("/gnupro-ref/tx39/index.html"));
938
 
939
        // Don't parse HTML, just add this item, if the page exists.
940
        // Presumably the HTML can't be parsed for some reason.
941
        AddIndexItem(wxT("Toshiba MIPS TX49"), wxT("ref/gnupro-ref/tx49/tx49_ref.html"));
942
 
943
        AddIndexByClass(wxT("Hitachi SuperH"), wxT("ref/gnupro-ref/sh/SH_front.html"), wxT("ref/gnupro-ref/sh/SHTOC.html"), 1);
944
 
945
        AddIndexItem(wxT("NEC V850"), wxT("ref/gnupro-ref/v850/v850_ref_3.html"));
946
        AddIndexByClass(wxT("NEC VR4300"), wxT("ref/gnupro-ref/vr4300/Vr43REF_front.html"), wxT("ref/gnupro-ref/vr4300/Vr43REFTOC.html"), 1);
947
        AddEndSection();
948
    }
949
    else
950
    {
951
        // NEW-STYLE DOCUMENTATION (HTML is generated from SGML)
952
 
953
        // Get a list of all tutorials
954
 
955
        wxArrayString tutorials;
956
 
957
        wxString sep(wxFILE_SEP_PATH);
958
 
959
        wxString docDir(reposDir + sep + wxString(wxT("doc"))) ;
960
 
961
        // The CVS repository has an HTML subdirectory, but the
962
        // packaged version doesn't
963
        if (wxDirExists(docDir + sep + wxT("html")))
964
            docDir = docDir + sep + wxString(wxT("html"));
965
 
966
        docDir += sep ;
967
        docDir += wxString(wxT("tutorials"));
968
 
969
        wxLogNull log;
970
        wxDir dir(docDir);
971
 
972
        if (dir.IsOpened())
973
        {
974
            wxString filename;
975
            bool cont = dir.GetFirst(& filename, wxT("*"), wxDIR_DIRS);
976
            while (cont)
977
            {
978
                if (filename != wxT(".") && filename != wxT(".."))
979
                    tutorials.Add(filename);
980
 
981
                cont = dir.GetNext(& filename);
982
            }
983
        }
984
 
985
//        AddStartSection(wxT("Getting Started with eCos"), wxT(""));
986
        size_t i;
987
        for (i = 0; i < tutorials.GetCount(); i++)
988
        {
989
            wxString tutorial(tutorials[i]);
990
            wxString tutorialRelativePath = wxT("tutorials/") + tutorial + wxT("/ecos-tutorial.html");
991
 
992
            // Use a more friendly name than just the directory if it's available
993
            AddIndexByList(TranslateTutorialDirectory(tutorial), tutorialRelativePath, tutorialRelativePath);
994
        }
995
//        AddEndSection();
996
 
997
        AddIndexByList(wxT("User Guide"), wxT("user-guide/ecos-user-guide.html"), wxT("user-guide/ecos-user-guide.html"));
998
        AddIndexByList(wxT("RedBoot Guide"), wxT("redboot-guide/redboot-guide.html"), wxT("redboot-guide/redboot-guide.html"));
999
        AddIndexByList(wxT("eCos Reference"), wxT("ref/ecos-ref.html"), wxT("ref/ecos-ref.html"));
1000
        AddIndexByList(wxT("Component Writer's Guide"), wxT("cdl-guide/cdl-guide.html"), wxT("cdl-guide/cdl-guide.html"));
1001
//        AddIndexByList(wxT("eCos-EL/IX Compatibility Guide"), wxT("ecos-elix/elix-compatibility.html"), wxT("ecos-elix/elix-compatibility.html"));
1002
 
1003
        //// TOOLCHAIN REFERENCE MANUALS
1004
//        AddStartSection(wxT("GNUPro Toolkit Reference Manual"));
1005
        // Start at indent 1 to avoid a spurious level
1006
//        AddIndexByClass(wxT("ARM"), wxT("ref/gnupro-ref/arm/ARM_COMBO_front.html"), wxT("ref/gnupro-ref/arm/ARM_COMBOTOC.html"), 1);
1007
//        AddIndexByClass(wxT("Fujitsu SPARClite"), wxT("ref/gnupro-ref/sparclite/index.html"), wxT("ref/gnupro-ref/sparclite/index.html"), 1);
1008
//        AddIndexByClass(wxT("Matsushita MN10300"), wxT("ref/gnupro-ref/mn10300/am33_front.html"), wxT("ref/gnupro-ref/mn10300/am33toc.html"), 1);
1009
//        AddIndexByClass(wxT("PowerPC"), wxT("ref/gnupro-ref/powerpc/index.html"), wxT("ref/gnupro-ref/powerpc/index.html"));
1010
//        AddIndexByClass(wxT("Toshiba MIPS TX39"), wxT("/gnupro-ref/tx39/index.html"), wxT("/gnupro-ref/tx39/index.html"));
1011
 
1012
        // Don't parse HTML, just add this item, if the page exists.
1013
        // Presumably the HTML can't be parsed for some reason.
1014
//        AddIndexItem(wxT("Toshiba MIPS TX49"), wxT("ref/gnupro-ref/tx49/tx49_ref.html"));
1015
 
1016
//        AddIndexByClass(wxT("Hitachi SuperH"), wxT("ref/gnupro-ref/sh/SH_front.html"), wxT("ref/gnupro-ref/sh/SHTOC.html"), 1);
1017
 
1018
//        AddIndexItem(wxT("NEC V850"), wxT("ref/gnupro-ref/v850/v850_ref_3.html"));
1019
//        AddIndexByClass(wxT("NEC VR4300"), wxT("ref/gnupro-ref/vr4300/Vr43REF_front.html"), wxT("ref/gnupro-ref/vr4300/Vr43REFTOC.html"), 1);
1020
//        AddEndSection();
1021
    }
1022
 
1023
    DoIndexDocs(reposDir, projectFile, force);
1024
 
1025
    return TRUE;
1026
}
1027
 
1028
// Some things should be translated in the contents
1029
void ecHtmlIndexer::AddEntityTranslation(const wxString& entity, const wxString& translation)
1030
{
1031
    m_entityTableNames.Add(entity);
1032
    m_entityTableValues.Add(translation);
1033
}
1034
 
1035
// Apply all translations to this string
1036
wxString ecHtmlIndexer::TranslateEntities(const wxString& toTranslate)
1037
{
1038
    wxString result(toTranslate);
1039
    size_t i;
1040
    for (i = 0; i < m_entityTableNames.GetCount(); i++)
1041
    {
1042
        result.Replace(m_entityTableNames[i], m_entityTableValues[i]);
1043
    }
1044
    return result;
1045
}
1046
 
1047
// Mapping from directory to user-viewable name
1048
void ecHtmlIndexer::AddTutorialDirectory(const wxString& dirName, const wxString& title)
1049
{
1050
    m_tutorialTableNames.Add(dirName);
1051
    m_tutorialTableValues.Add(title);
1052
}
1053
 
1054
wxString ecHtmlIndexer::TranslateTutorialDirectory(const wxString& dirName)
1055
{
1056
    int i = m_tutorialTableNames.Index(dirName);
1057
    if (i >= 0)
1058
        return m_tutorialTableValues[i];
1059
    else
1060
        return dirName;
1061
}
1062
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.