2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-10-01 16:08:38 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
2009-09-16 11:45:54 +00:00
|
|
|
*
|
2012-10-01 16:08:38 +01:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2009-09-16 11:45:54 +00:00
|
|
|
*
|
2012-10-01 16:08:38 +01:00
|
|
|
* This file incorporates work covered by the following license notice:
|
2009-09-16 11:45:54 +00:00
|
|
|
*
|
2012-10-01 16:08:38 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2013-05-06 17:25:51 +02:00
|
|
|
#include <HelpCompiler.hxx>
|
|
|
|
#include <HelpLinker.hxx>
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2019-05-22 00:07:23 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <fstream>
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2019-05-22 00:07:23 +02:00
|
|
|
#include <libxslt/transform.h>
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
#include <sal/types.h>
|
2017-10-05 06:19:56 +03:00
|
|
|
#include <o3tl/char16_t2wchar_t.hxx>
|
2018-07-27 17:57:59 +02:00
|
|
|
#include <sal/log.hxx>
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
#include <expat.h>
|
2015-06-15 17:58:15 +09:00
|
|
|
#include <memory>
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2017-10-03 12:44:07 +03:00
|
|
|
namespace {
|
|
|
|
FILE* fopen_impl(const fs::path& rPath, const char* szMode)
|
|
|
|
{
|
|
|
|
#ifdef _WIN32 //We need _wfopen to support long file paths on Windows XP
|
2017-10-05 06:19:56 +03:00
|
|
|
return _wfopen(rPath.native_file_string_w().c_str(), o3tl::toW(OUString::createFromAscii(szMode).getStr()));
|
2017-10-03 12:44:07 +03:00
|
|
|
#else
|
|
|
|
return fopen(rPath.native_file_string().c_str(), szMode);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-16 11:45:54 +00:00
|
|
|
IndexerPreProcessor::IndexerPreProcessor
|
2015-11-20 14:48:17 +02:00
|
|
|
( const fs::path& fsIndexBaseDir,
|
2009-09-16 11:45:54 +00:00
|
|
|
const fs::path& idxCaptionStylesheet, const fs::path& idxContentStylesheet )
|
|
|
|
{
|
|
|
|
m_fsCaptionFilesDirName = fsIndexBaseDir / "caption";
|
|
|
|
fs::create_directory( m_fsCaptionFilesDirName );
|
|
|
|
|
|
|
|
m_fsContentFilesDirName = fsIndexBaseDir / "content";
|
|
|
|
fs::create_directory( m_fsContentFilesDirName );
|
|
|
|
|
|
|
|
m_xsltStylesheetPtrCaption = xsltParseStylesheetFile
|
2015-01-17 18:47:15 +01:00
|
|
|
(reinterpret_cast<const xmlChar *>(idxCaptionStylesheet.native_file_string().c_str()));
|
2009-09-16 11:45:54 +00:00
|
|
|
m_xsltStylesheetPtrContent = xsltParseStylesheetFile
|
2015-01-17 18:47:15 +01:00
|
|
|
(reinterpret_cast<const xmlChar *>(idxContentStylesheet.native_file_string().c_str()));
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IndexerPreProcessor::~IndexerPreProcessor()
|
|
|
|
{
|
|
|
|
if( m_xsltStylesheetPtrCaption )
|
|
|
|
xsltFreeStylesheet( m_xsltStylesheetPtrCaption );
|
|
|
|
if( m_xsltStylesheetPtrContent )
|
|
|
|
xsltFreeStylesheet( m_xsltStylesheetPtrContent );
|
|
|
|
}
|
|
|
|
|
2018-09-15 19:13:19 +02:00
|
|
|
static std::string getEncodedPath( const std::string& Path )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OString aOStr_Path( Path.c_str() );
|
|
|
|
OUString aOUStr_Path( OStringToOUString
|
2019-11-22 11:09:49 +00:00
|
|
|
( aOStr_Path, osl_getThreadTextEncoding() ) );
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString aPathURL;
|
2009-09-16 11:45:54 +00:00
|
|
|
osl::File::getFileURLFromSystemPath( aOUStr_Path, aPathURL );
|
2013-04-07 12:06:47 +02:00
|
|
|
OString aOStr_PathURL( OUStringToOString
|
2019-11-22 11:09:49 +00:00
|
|
|
( aPathURL, osl_getThreadTextEncoding() ) );
|
2009-09-16 11:45:54 +00:00
|
|
|
std::string aStdStr_PathURL( aOStr_PathURL.getStr() );
|
|
|
|
return aStdStr_PathURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IndexerPreProcessor::processDocument
|
|
|
|
( xmlDocPtr doc, const std::string &EncodedDocPath )
|
|
|
|
{
|
|
|
|
std::string aStdStr_EncodedDocPathURL = getEncodedPath( EncodedDocPath );
|
|
|
|
|
2009-12-03 17:21:16 +00:00
|
|
|
if( m_xsltStylesheetPtrCaption )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2015-11-10 10:16:29 +01:00
|
|
|
xmlDocPtr resCaption = xsltApplyStylesheet( m_xsltStylesheetPtrCaption, doc, nullptr );
|
2009-12-03 17:21:16 +00:00
|
|
|
xmlNodePtr pResNodeCaption = resCaption->xmlChildrenNode;
|
|
|
|
if( pResNodeCaption )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2009-12-03 17:21:16 +00:00
|
|
|
fs::path fsCaptionPureTextFile_docURL = m_fsCaptionFilesDirName / aStdStr_EncodedDocPathURL;
|
2017-10-03 12:44:07 +03:00
|
|
|
FILE* pFile_docURL = fopen_impl( fsCaptionPureTextFile_docURL, "w" );
|
2009-12-03 17:21:16 +00:00
|
|
|
if( pFile_docURL )
|
|
|
|
{
|
|
|
|
fprintf( pFile_docURL, "%s\n", pResNodeCaption->content );
|
|
|
|
fclose( pFile_docURL );
|
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
2009-12-03 17:21:16 +00:00
|
|
|
xmlFreeDoc(resCaption);
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
2009-12-03 17:21:16 +00:00
|
|
|
if( m_xsltStylesheetPtrContent )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2015-11-10 10:16:29 +01:00
|
|
|
xmlDocPtr resContent = xsltApplyStylesheet( m_xsltStylesheetPtrContent, doc, nullptr );
|
2009-12-03 17:21:16 +00:00
|
|
|
xmlNodePtr pResNodeContent = resContent->xmlChildrenNode;
|
|
|
|
if( pResNodeContent )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2009-12-03 17:21:16 +00:00
|
|
|
fs::path fsContentPureTextFile_docURL = m_fsContentFilesDirName / aStdStr_EncodedDocPathURL;
|
2017-10-03 12:44:07 +03:00
|
|
|
FILE* pFile_docURL = fopen_impl( fsContentPureTextFile_docURL, "w" );
|
2009-12-03 17:21:16 +00:00
|
|
|
if( pFile_docURL )
|
|
|
|
{
|
|
|
|
fprintf( pFile_docURL, "%s\n", pResNodeContent->content );
|
|
|
|
fclose( pFile_docURL );
|
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
2009-12-03 17:21:16 +00:00
|
|
|
xmlFreeDoc(resContent);
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
namespace {
|
|
|
|
|
2009-09-16 11:45:54 +00:00
|
|
|
struct Data
|
|
|
|
{
|
|
|
|
std::vector<std::string> _idList;
|
|
|
|
|
|
|
|
void append(const std::string &id)
|
|
|
|
{
|
|
|
|
_idList.push_back(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getString() const
|
|
|
|
{
|
|
|
|
std::string ret;
|
2018-03-17 22:06:55 +01:00
|
|
|
for (auto const& elem : _idList)
|
|
|
|
ret += elem + ";";
|
2009-09-16 11:45:54 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
}
|
|
|
|
|
2018-09-15 19:13:19 +02:00
|
|
|
static void writeKeyValue_DBHelp( FILE* pFile, const std::string& aKeyStr, const std::string& aValueStr )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2015-11-10 10:16:29 +01:00
|
|
|
if( pFile == nullptr )
|
2009-09-16 11:45:54 +00:00
|
|
|
return;
|
2017-06-23 16:04:59 +02:00
|
|
|
char const cLF = 10;
|
2009-10-30 09:37:43 +00:00
|
|
|
unsigned int nKeyLen = aKeyStr.length();
|
|
|
|
unsigned int nValueLen = aValueStr.length();
|
2009-09-16 11:45:54 +00:00
|
|
|
fprintf( pFile, "%x ", nKeyLen );
|
|
|
|
if( nKeyLen > 0 )
|
2009-10-30 09:37:43 +00:00
|
|
|
{
|
|
|
|
if (fwrite( aKeyStr.c_str(), 1, nKeyLen, pFile ) != nKeyLen)
|
|
|
|
fprintf(stderr, "fwrite to db failed\n");
|
|
|
|
}
|
|
|
|
if (fprintf( pFile, " %x ", nValueLen ) < 0)
|
|
|
|
fprintf(stderr, "fwrite to db failed\n");
|
2009-09-16 11:45:54 +00:00
|
|
|
if( nValueLen > 0 )
|
2009-10-30 09:37:43 +00:00
|
|
|
{
|
|
|
|
if (fwrite( aValueStr.c_str(), 1, nValueLen, pFile ) != nValueLen)
|
|
|
|
fprintf(stderr, "fwrite to db failed\n");
|
|
|
|
}
|
|
|
|
if (fprintf( pFile, "%c", cLF ) < 0)
|
|
|
|
fprintf(stderr, "fwrite to db failed\n");
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
namespace {
|
|
|
|
|
2009-09-16 11:45:54 +00:00
|
|
|
class HelpKeyword
|
|
|
|
{
|
|
|
|
private:
|
2019-04-07 09:13:30 +02:00
|
|
|
typedef std::unordered_map<std::string, Data> DataHashtable;
|
2009-09-16 11:45:54 +00:00
|
|
|
DataHashtable _hash;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void insert(const std::string &key, const std::string &id)
|
|
|
|
{
|
|
|
|
Data &data = _hash[key];
|
|
|
|
data.append(id);
|
|
|
|
}
|
|
|
|
|
2011-02-24 17:12:55 +01:00
|
|
|
void dump_DBHelp( const fs::path& rFileName )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2017-10-03 12:44:07 +03:00
|
|
|
FILE* pFile = fopen_impl( rFileName, "wb" );
|
2015-11-10 10:16:29 +01:00
|
|
|
if( pFile == nullptr )
|
2009-09-16 11:45:54 +00:00
|
|
|
return;
|
|
|
|
|
2018-03-17 22:06:55 +01:00
|
|
|
for (auto const& elem : _hash)
|
|
|
|
writeKeyValue_DBHelp( pFile, elem.first, elem.second.getString() );
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
fclose( pFile );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Extend loplugin:external to warn about classes
...following up on 314f15bff08b76bf96acf99141776ef64d2f1355 "Extend
loplugin:external to warn about enums".
Cases where free functions were moved into an unnamed namespace along with a
class, to not break ADL, are in:
filter/source/svg/svgexport.cxx
sc/source/filter/excel/xelink.cxx
sc/source/filter/excel/xilink.cxx
svx/source/sdr/contact/viewobjectcontactofunocontrol.cxx
All other free functions mentioning moved classes appear to be harmless and not
give rise to (silent, even) ADL breakage. (One remaining TODO in
compilerplugins/clang/external.cxx is that derived classes are not covered by
computeAffectedTypes, even though they could also be affected by ADL-breakage---
but don't seem to be in any acutal case across the code base.)
For friend declarations using elaborate type specifiers, like
class C1 {};
class C2 { friend class C1; };
* If C2 (but not C1) is moved into an unnamed namespace, the friend declaration
must be changed to not use an elaborate type specifier (i.e., "friend C1;"; see
C++17 [namespace.memdef]/3: "If the name in a friend declaration is neither
qualified nor a template-id and the declaration is a function or an
elaborated-type-specifier, the lookup to determine whether the entity has been
previously declared shall not consider any scopes outside the innermost
enclosing namespace.")
* If C1 (but not C2) is moved into an unnamed namespace, the friend declaration
must be changed too, see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71882>
"elaborated-type-specifier friend not looked up in unnamed namespace".
Apart from that, to keep changes simple and mostly mechanical (which should help
avoid regressions), out-of-line definitions of class members have been left in
the enclosing (named) namespace. But explicit specializations of class
templates had to be moved into the unnamed namespace to appease
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92598> "explicit specialization of
template from unnamed namespace using unqualified-id in enclosing namespace".
Also, accompanying declarations (of e.g. typedefs or static variables) that
could arguably be moved into the unnamed namespace too have been left alone.
And in some cases, mention of affected types in blacklists in other loplugins
needed to be adapted.
And sc/qa/unit/mark_test.cxx uses a hack of including other .cxx, one of which
is sc/source/core/data/segmenttree.cxx where e.g. ScFlatUInt16SegmentsImpl is
not moved into an unnamed namespace (because it is declared in
sc/inc/segmenttree.hxx), but its base ScFlatSegmentsImpl is. GCC warns about
such combinations with enabled-by-default -Wsubobject-linkage, but "The compiler
doesn’t give this warning for types defined in the main .C file, as those are
unlikely to have multiple definitions."
(<https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/Warning-Options.html>) The
warned-about classes also don't have multiple definitions in the given test, so
disable the warning when including the .cxx.
Change-Id: Ib694094c0d8168be68f8fe90dfd0acbb66a3f1e4
Reviewed-on: https://gerrit.libreoffice.org/83239
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2019-11-19 16:32:49 +01:00
|
|
|
}
|
|
|
|
|
2009-09-16 11:45:54 +00:00
|
|
|
namespace URLEncoder
|
|
|
|
{
|
|
|
|
static std::string encode(const std::string &rIn)
|
|
|
|
{
|
2017-01-10 08:11:57 +01:00
|
|
|
const char * const good = "!$&'()*+,-.=@_";
|
2009-09-16 11:45:54 +00:00
|
|
|
static const char hex[17] = "0123456789ABCDEF";
|
|
|
|
|
|
|
|
std::string result;
|
2016-04-28 10:24:35 +02:00
|
|
|
for (char c : rIn)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2017-03-22 21:41:44 +01:00
|
|
|
if (rtl::isAsciiAlphanumeric (static_cast<unsigned char>(c))
|
|
|
|
|| strchr (good, c))
|
|
|
|
{
|
2009-09-16 11:45:54 +00:00
|
|
|
result += c;
|
2017-03-22 21:41:44 +01:00
|
|
|
} else {
|
2009-09-16 11:45:54 +00:00
|
|
|
result += '%';
|
2017-01-06 18:15:24 +01:00
|
|
|
result += hex[static_cast<unsigned char>(c) >> 4];
|
2009-09-16 11:45:54 +00:00
|
|
|
result += hex[c & 0xf];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-01 16:08:38 +01:00
|
|
|
void HelpLinker::addBookmark( FILE* pFile_DBHelp, std::string thishid,
|
2009-09-16 11:45:54 +00:00
|
|
|
const std::string& fileB, const std::string& anchorB,
|
|
|
|
const std::string& jarfileB, const std::string& titleB)
|
|
|
|
{
|
|
|
|
HCDBG(std::cerr << "HelpLinker::addBookmark " << thishid << " " <<
|
|
|
|
fileB << " " << anchorB << " " << jarfileB << " " << titleB << std::endl);
|
|
|
|
|
|
|
|
thishid = URLEncoder::encode(thishid);
|
|
|
|
|
|
|
|
int fileLen = fileB.length();
|
|
|
|
if (!anchorB.empty())
|
|
|
|
fileLen += (1 + anchorB.length());
|
|
|
|
int dataLen = 1 + fileLen + 1 + jarfileB.length() + 1 + titleB.length();
|
|
|
|
|
|
|
|
std::vector<unsigned char> dataB(dataLen);
|
|
|
|
size_t i = 0;
|
|
|
|
dataB[i++] = static_cast<unsigned char>(fileLen);
|
2016-04-28 10:24:35 +02:00
|
|
|
for (char j : fileB)
|
|
|
|
dataB[i++] = static_cast<unsigned char>(j);
|
2009-09-16 11:45:54 +00:00
|
|
|
if (!anchorB.empty())
|
|
|
|
{
|
|
|
|
dataB[i++] = '#';
|
2016-04-28 10:24:35 +02:00
|
|
|
for (char j : anchorB)
|
|
|
|
dataB[i++] = j;
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
dataB[i++] = static_cast<unsigned char>(jarfileB.length());
|
2016-04-28 10:24:35 +02:00
|
|
|
for (char j : jarfileB)
|
|
|
|
dataB[i++] = j;
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
dataB[i++] = static_cast<unsigned char>(titleB.length());
|
2016-04-28 10:24:35 +02:00
|
|
|
for (char j : titleB)
|
|
|
|
dataB[i++] = j;
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2015-11-10 10:16:29 +01:00
|
|
|
if( pFile_DBHelp != nullptr )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
std::string aValueStr( dataB.begin(), dataB.end() );
|
|
|
|
writeKeyValue_DBHelp( pFile_DBHelp, thishid, aValueStr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HelpLinker::initIndexerPreProcessor()
|
|
|
|
{
|
2017-01-16 14:15:13 +02:00
|
|
|
m_pIndexerPreProcessor.reset( new IndexerPreProcessor( indexDirParentName,
|
|
|
|
idxCaptionStylesheet, idxContentStylesheet ) );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
void HelpLinker::link()
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2009-10-30 09:37:43 +00:00
|
|
|
|
2009-09-16 11:45:54 +00:00
|
|
|
if( bExtensionMode )
|
|
|
|
{
|
2010-05-07 17:02:22 +02:00
|
|
|
indexDirParentName = extensionDestination;
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
indexDirParentName = zipdir;
|
|
|
|
fs::create_directory(indexDirParentName);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string mod = module;
|
2011-06-16 14:54:35 +01:00
|
|
|
std::transform (mod.begin(), mod.end(), mod.begin(), tocharlower);
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
// do the work here
|
|
|
|
// continue with introduction of the overall process thing into the
|
|
|
|
// here all hzip files will be worked on
|
|
|
|
bool bUse_ = true;
|
|
|
|
if( !bExtensionMode )
|
|
|
|
bUse_ = false;
|
|
|
|
|
|
|
|
fs::path helpTextFileName_DBHelp(indexDirParentName / (mod + (bUse_ ? ".ht_" : ".ht")));
|
2017-10-03 12:44:07 +03:00
|
|
|
FILE* pFileHelpText_DBHelp = fopen_impl( helpTextFileName_DBHelp, "wb" );
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
fs::path dbBaseFileName_DBHelp(indexDirParentName / (mod + (bUse_ ? ".db_" : ".db")));
|
2017-10-03 12:44:07 +03:00
|
|
|
FILE* pFileDbBase_DBHelp = fopen_impl( dbBaseFileName_DBHelp, "wb" );
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
fs::path keyWordFileName_DBHelp(indexDirParentName / (mod + (bUse_ ? ".key_" : ".key")));
|
|
|
|
|
|
|
|
HelpKeyword helpKeyword;
|
|
|
|
|
|
|
|
// catch HelpProcessingException to avoid locking data bases
|
|
|
|
try
|
|
|
|
{
|
2015-01-04 22:50:05 +01:00
|
|
|
bool bIndexForExtension = true;
|
2014-12-16 21:54:25 +01:00
|
|
|
// lastly, initialize the indexBuilder
|
|
|
|
if ( (!bExtensionMode || bIndexForExtension) && !helpFiles.empty())
|
|
|
|
initIndexerPreProcessor();
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
// here we start our loop over the hzip files.
|
2018-03-17 22:06:55 +01:00
|
|
|
for (auto const& helpFile : helpFiles)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2014-12-16 21:54:25 +01:00
|
|
|
// process one file
|
|
|
|
// streamTable contains the streams in the hzip file
|
|
|
|
StreamTable streamTable;
|
2018-03-17 22:06:55 +01:00
|
|
|
const std::string &xhpFileName = helpFile;
|
2012-05-16 11:19:17 +01:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
if (!bExtensionMode && xhpFileName.rfind(".xhp") != xhpFileName.length()-4)
|
|
|
|
{
|
|
|
|
// only work on .xhp - files
|
|
|
|
SAL_WARN("helpcompiler",
|
|
|
|
"ERROR: input list entry '"
|
|
|
|
<< xhpFileName
|
|
|
|
<< "' has the wrong extension (only files with extension .xhp are accepted)");
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
continue;
|
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
fs::path langsourceRoot(sourceRoot);
|
|
|
|
fs::path xhpFile;
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
if( bExtensionMode )
|
|
|
|
{
|
|
|
|
// langsourceRoot == sourceRoot for extensions
|
|
|
|
std::string xhpFileNameComplete( extensionPath );
|
|
|
|
xhpFileNameComplete.append( '/' + xhpFileName );
|
|
|
|
xhpFile = fs::path( xhpFileNameComplete );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
langsourceRoot.append( "/" );
|
|
|
|
if ( m_bUseLangRoot )
|
|
|
|
langsourceRoot.append( lang + '/' );
|
|
|
|
xhpFile = fs::path(xhpFileName, fs::native);
|
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
HelpCompiler hc( streamTable, xhpFile, langsourceRoot, zipdir,
|
|
|
|
compactStylesheet, embeddStylesheet, module, lang, bExtensionMode );
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
HCDBG(std::cerr << "before compile of " << xhpFileName << std::endl);
|
2018-07-26 12:20:59 +02:00
|
|
|
hc.compile();
|
2014-12-16 21:54:25 +01:00
|
|
|
HCDBG(std::cerr << "after compile of " << xhpFileName << std::endl);
|
|
|
|
|
|
|
|
if (!m_bCreateIndex)
|
|
|
|
continue;
|
2013-02-28 11:12:53 +01:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
std::string documentPath = streamTable.document_path;
|
2015-12-08 12:07:49 +01:00
|
|
|
if (documentPath.compare(0, 1, "/") == 0)
|
2014-12-16 21:54:25 +01:00
|
|
|
documentPath = documentPath.substr(1);
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
std::string documentJarfile = streamTable.document_module + ".jar";
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
std::string documentTitle = streamTable.document_title;
|
|
|
|
if (documentTitle.empty())
|
|
|
|
documentTitle = "<notitle>";
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
const std::string& fileB = documentPath;
|
|
|
|
const std::string& jarfileB = documentJarfile;
|
|
|
|
std::string& titleB = documentTitle;
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
// add once this as its own id.
|
|
|
|
addBookmark( pFileDbBase_DBHelp, documentPath, fileB, std::string(), jarfileB, titleB);
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2018-06-03 16:00:14 +03:00
|
|
|
const std::vector<std::string> *hidlist = streamTable.appl_hidlist.get();
|
2018-11-28 15:13:42 +02:00
|
|
|
if (hidlist)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2014-12-16 21:54:25 +01:00
|
|
|
// now iterate over all elements of the hidlist
|
2018-03-17 22:06:55 +01:00
|
|
|
for (auto & elem : *hidlist)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2018-03-17 22:06:55 +01:00
|
|
|
std::string thishid = elem;
|
2014-12-16 21:54:25 +01:00
|
|
|
|
|
|
|
std::string anchorB;
|
|
|
|
size_t index = thishid.rfind('#');
|
|
|
|
if (index != std::string::npos)
|
|
|
|
{
|
|
|
|
anchorB = thishid.substr(1 + index);
|
|
|
|
thishid = thishid.substr(0, index);
|
|
|
|
}
|
|
|
|
addBookmark( pFileDbBase_DBHelp, thishid, fileB, anchorB, jarfileB, titleB);
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
// now the keywords
|
2018-04-12 15:39:54 +02:00
|
|
|
const Hashtable *anchorToLL = streamTable.appl_keywords.get();
|
2014-12-16 21:54:25 +01:00
|
|
|
if (anchorToLL && !anchorToLL->empty())
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2014-12-16 21:54:25 +01:00
|
|
|
std::string fakedHid = URLEncoder::encode(documentPath);
|
2018-03-17 22:06:55 +01:00
|
|
|
for (auto const& elemAnchor : *anchorToLL)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2018-03-17 22:06:55 +01:00
|
|
|
const std::string &anchor = elemAnchor.first;
|
2014-12-16 21:54:25 +01:00
|
|
|
addBookmark(pFileDbBase_DBHelp, documentPath, fileB,
|
|
|
|
anchor, jarfileB, titleB);
|
|
|
|
std::string totalId = fakedHid + "#" + anchor;
|
|
|
|
// std::cerr << hzipFileName << std::endl;
|
2018-03-17 22:06:55 +01:00
|
|
|
const LinkedList& ll = elemAnchor.second;
|
|
|
|
for (auto const& elem : ll)
|
2014-12-16 21:54:25 +01:00
|
|
|
{
|
2018-03-17 22:06:55 +01:00
|
|
|
helpKeyword.insert(elem, totalId);
|
2014-12-16 21:54:25 +01:00
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
// and last the helptexts
|
2018-04-12 15:39:54 +02:00
|
|
|
const Stringtable *helpTextHash = streamTable.appl_helptexts.get();
|
2018-11-28 15:13:42 +02:00
|
|
|
if (helpTextHash)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2018-03-17 22:06:55 +01:00
|
|
|
for (auto const& elem : *helpTextHash)
|
2014-12-16 21:54:25 +01:00
|
|
|
{
|
2018-03-17 22:06:55 +01:00
|
|
|
std::string helpTextId = elem.first;
|
|
|
|
const std::string& helpTextText = elem.second;
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
helpTextId = URLEncoder::encode(helpTextId);
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2015-11-10 10:16:29 +01:00
|
|
|
if( pFileHelpText_DBHelp != nullptr )
|
2014-12-16 21:54:25 +01:00
|
|
|
writeKeyValue_DBHelp( pFileHelpText_DBHelp, helpTextId, helpTextText );
|
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
//IndexerPreProcessor
|
|
|
|
if( !bExtensionMode || bIndexForExtension )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2014-12-16 21:54:25 +01:00
|
|
|
// now the indexing
|
|
|
|
xmlDocPtr document = streamTable.appl_doc;
|
|
|
|
if (document)
|
|
|
|
{
|
|
|
|
std::string temp = module;
|
|
|
|
std::transform (temp.begin(), temp.end(), temp.begin(), tocharlower);
|
|
|
|
m_pIndexerPreProcessor->processDocument(document, URLEncoder::encode(documentPath) );
|
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2014-12-16 21:54:25 +01:00
|
|
|
}
|
2010-10-20 12:19:56 +02:00
|
|
|
catch( const HelpProcessingException& )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
// catch HelpProcessingException to avoid locking data bases
|
2015-11-10 10:16:29 +01:00
|
|
|
if( pFileHelpText_DBHelp != nullptr )
|
2009-09-16 11:45:54 +00:00
|
|
|
fclose( pFileHelpText_DBHelp );
|
2015-11-10 10:16:29 +01:00
|
|
|
if( pFileDbBase_DBHelp != nullptr )
|
2009-09-16 11:45:54 +00:00
|
|
|
fclose( pFileDbBase_DBHelp );
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2015-11-10 10:16:29 +01:00
|
|
|
if( pFileHelpText_DBHelp != nullptr )
|
2009-09-16 11:45:54 +00:00
|
|
|
fclose( pFileHelpText_DBHelp );
|
2015-11-10 10:16:29 +01:00
|
|
|
if( pFileDbBase_DBHelp != nullptr )
|
2009-09-16 11:45:54 +00:00
|
|
|
fclose( pFileDbBase_DBHelp );
|
|
|
|
|
2011-02-24 17:12:55 +01:00
|
|
|
helpKeyword.dump_DBHelp( keyWordFileName_DBHelp);
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
if( !bExtensionMode )
|
|
|
|
{
|
|
|
|
// New index
|
2018-03-17 22:06:55 +01:00
|
|
|
for (auto const& additionalFile : additionalFiles)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2018-03-17 22:06:55 +01:00
|
|
|
const std::string &additionalFileName = additionalFile.second;
|
|
|
|
const std::string &additionalFileKey = additionalFile.first;
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
fs::path fsAdditionalFileName( additionalFileName, fs::native );
|
2012-06-07 19:19:49 +01:00
|
|
|
HCDBG({
|
|
|
|
std::string aNativeStr = fsAdditionalFileName.native_file_string();
|
|
|
|
const char* pStr = aNativeStr.c_str();
|
|
|
|
std::cerr << pStr << std::endl;
|
|
|
|
});
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
fs::path fsTargetName( indexDirParentName / additionalFileKey );
|
|
|
|
|
|
|
|
fs::copy( fsAdditionalFileName, fsTargetName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-03 17:21:16 +00:00
|
|
|
void HelpLinker::main( std::vector<std::string> &args,
|
2017-07-18 09:02:03 +02:00
|
|
|
std::string const * pExtensionPath, std::string const * pDestination,
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString* pOfficeHelpPath )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
bExtensionMode = false;
|
2010-08-23 12:49:12 +02:00
|
|
|
helpFiles.clear();
|
|
|
|
|
2011-08-30 23:11:44 +02:00
|
|
|
if ((!args.empty()) && args[0][0] == '@')
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
std::vector<std::string> stringList;
|
|
|
|
std::ifstream fileReader(args[0].substr(1).c_str());
|
|
|
|
|
|
|
|
while (fileReader)
|
|
|
|
{
|
|
|
|
std::string token;
|
|
|
|
fileReader >> token;
|
|
|
|
if (!token.empty())
|
|
|
|
stringList.push_back(token);
|
|
|
|
}
|
|
|
|
fileReader.close();
|
|
|
|
|
|
|
|
args = stringList;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t i = 0;
|
2010-08-23 12:49:12 +02:00
|
|
|
bool bSrcOption = false;
|
2009-09-16 11:45:54 +00:00
|
|
|
while (i < args.size())
|
|
|
|
{
|
2010-08-23 12:49:12 +02:00
|
|
|
if (args[i].compare("-extlangsrc") == 0)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "extension source missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2010-08-23 12:49:12 +02:00
|
|
|
}
|
|
|
|
extsource = args[i];
|
|
|
|
}
|
|
|
|
else if (args[i].compare("-extlangdest") == 0)
|
|
|
|
{
|
|
|
|
//If this argument is not provided then the location provided in -extsource will
|
|
|
|
//also be the destination
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "extension destination missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2010-08-23 12:49:12 +02:00
|
|
|
}
|
|
|
|
extdestination = args[i];
|
|
|
|
}
|
|
|
|
else if (args[i].compare("-src") == 0)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "sourceroot missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
2010-08-23 12:49:12 +02:00
|
|
|
bSrcOption = true;
|
|
|
|
sourceRoot = fs::path(args[i], fs::native);
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
2013-02-13 16:28:16 +01:00
|
|
|
else if (args[i].compare("-compact") == 0)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "compactStylesheet missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2013-02-13 16:28:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
compactStylesheet = fs::path(args[i], fs::native);
|
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
else if (args[i].compare("-sty") == 0)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "embeddingStylesheet missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
embeddStylesheet = fs::path(args[i], fs::native);
|
|
|
|
}
|
|
|
|
else if (args[i].compare("-zipdir") == 0)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "idxtemp missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zipdir = fs::path(args[i], fs::native);
|
|
|
|
}
|
|
|
|
else if (args[i].compare("-idxcaption") == 0)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "idxcaption stylesheet missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
idxCaptionStylesheet = fs::path(args[i], fs::native);
|
|
|
|
}
|
|
|
|
else if (args[i].compare("-idxcontent") == 0)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "idxcontent stylesheet missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
idxContentStylesheet = fs::path(args[i], fs::native);
|
|
|
|
}
|
|
|
|
else if (args[i].compare("-o") == 0)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "outputfilename missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
outputFile = fs::path(args[i], fs::native);
|
|
|
|
}
|
|
|
|
else if (args[i].compare("-mod") == 0)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "module name missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module = args[i];
|
|
|
|
}
|
|
|
|
else if (args[i].compare("-lang") == 0)
|
|
|
|
{
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "language name missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lang = args[i];
|
|
|
|
}
|
|
|
|
else if (args[i].compare("-hid") == 0)
|
|
|
|
{
|
|
|
|
++i;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, "obsolete -hid argument used" );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
else if (args[i].compare("-add") == 0)
|
|
|
|
{
|
|
|
|
std::string addFile, addFileUnderPath;
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "pathname missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addFileUnderPath = args[i];
|
|
|
|
++i;
|
|
|
|
if (i >= args.size())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "pathname missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
addFile = args[i];
|
|
|
|
if (!addFileUnderPath.empty() && !addFile.empty())
|
|
|
|
additionalFiles[addFileUnderPath] = addFile;
|
|
|
|
}
|
2013-02-26 14:55:52 +01:00
|
|
|
else if (args[i].compare("-nolangroot") == 0)
|
|
|
|
m_bUseLangRoot = false;
|
2013-02-28 11:12:53 +01:00
|
|
|
else if (args[i].compare("-noindex") == 0)
|
|
|
|
m_bCreateIndex = false;
|
2009-09-16 11:45:54 +00:00
|
|
|
else
|
|
|
|
helpFiles.push_back(args[i]);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2010-08-23 12:49:12 +02:00
|
|
|
//We can be called from the helplinker executable or the extension manager
|
|
|
|
//In the latter case extsource is not used.
|
|
|
|
if( (pExtensionPath && pExtensionPath->length() > 0 && pOfficeHelpPath)
|
|
|
|
|| !extsource.empty())
|
|
|
|
{
|
|
|
|
bExtensionMode = true;
|
|
|
|
if (!extsource.empty())
|
|
|
|
{
|
|
|
|
//called from helplinker.exe, pExtensionPath and pOfficeHelpPath
|
|
|
|
//should be NULL
|
|
|
|
sourceRoot = fs::path(extsource, fs::native);
|
|
|
|
extensionPath = sourceRoot.toUTF8();
|
|
|
|
|
|
|
|
if (extdestination.empty())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "-extlangdest is missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2010-08-23 12:49:12 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Convert from system path to file URL!!!
|
|
|
|
fs::path p(extdestination, fs::native);
|
|
|
|
extensionDestination = p.toUTF8();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ //called from extension manager
|
|
|
|
extensionPath = *pExtensionPath;
|
|
|
|
sourceRoot = fs::path(extensionPath);
|
|
|
|
extensionDestination = *pDestination;
|
|
|
|
}
|
|
|
|
//check if -src option was used. This option must not be used
|
|
|
|
//when extension help is compiled.
|
|
|
|
if (bSrcOption)
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "-src must not be used together with -extsource missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2010-08-23 12:49:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-16 11:45:54 +00:00
|
|
|
if (!bExtensionMode && zipdir.empty())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "no index dir given" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
2010-08-23 12:49:12 +02:00
|
|
|
|
2010-10-12 15:48:16 +01:00
|
|
|
if ( (!bExtensionMode && idxCaptionStylesheet.empty())
|
|
|
|
|| (!extsource.empty() && idxCaptionStylesheet.empty()) )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2010-08-23 12:49:12 +02:00
|
|
|
//No extension mode and extension mode using commandline
|
|
|
|
//!extsource.empty indicates extension mode using commandline
|
2014-04-11 08:39:07 +02:00
|
|
|
// -idxcaption parameter is required
|
2009-09-16 11:45:54 +00:00
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "no index caption stylesheet given" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
2010-08-23 12:49:12 +02:00
|
|
|
else if ( bExtensionMode && extsource.empty())
|
2009-10-30 09:37:43 +00:00
|
|
|
{
|
2010-08-23 12:49:12 +02:00
|
|
|
//This part is used when compileExtensionHelp is called from the extensions manager.
|
|
|
|
//If extension help is compiled using helplinker in the build process
|
2019-09-30 15:10:42 +02:00
|
|
|
OUString aIdxCaptionPathFileURL = *pOfficeHelpPath + "/idxcaption.xsl";
|
2009-10-30 09:37:43 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString aOStr_IdxCaptionPathFileURL( OUStringToOString
|
2019-11-22 11:09:49 +00:00
|
|
|
( aIdxCaptionPathFileURL, osl_getThreadTextEncoding() ) );
|
2009-09-16 11:45:54 +00:00
|
|
|
std::string aStdStr_IdxCaptionPathFileURL( aOStr_IdxCaptionPathFileURL.getStr() );
|
2009-10-30 09:37:43 +00:00
|
|
|
|
|
|
|
idxCaptionStylesheet = fs::path( aStdStr_IdxCaptionPathFileURL );
|
|
|
|
}
|
2010-08-23 12:49:12 +02:00
|
|
|
|
2010-10-12 15:50:15 +01:00
|
|
|
if ( (!bExtensionMode && idxContentStylesheet.empty())
|
|
|
|
|| (!extsource.empty() && idxContentStylesheet.empty()) )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2010-08-23 12:49:12 +02:00
|
|
|
//No extension mode and extension mode using commandline
|
|
|
|
//!extsource.empty indicates extension mode using commandline
|
2014-04-11 08:39:07 +02:00
|
|
|
// -idxcontent parameter is required
|
2009-09-16 11:45:54 +00:00
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "no index content stylesheet given" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
2010-08-23 12:49:12 +02:00
|
|
|
else if ( bExtensionMode && extsource.empty())
|
2009-10-30 09:37:43 +00:00
|
|
|
{
|
2010-08-23 12:49:12 +02:00
|
|
|
//If extension help is compiled using helplinker in the build process
|
|
|
|
//then -idxcontent must be supplied
|
|
|
|
//This part is used when compileExtensionHelp is called from the extensions manager.
|
2019-09-30 15:10:42 +02:00
|
|
|
OUString aIdxContentPathFileURL = *pOfficeHelpPath + "/idxcontent.xsl";
|
2009-10-30 09:37:43 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString aOStr_IdxContentPathFileURL( OUStringToOString
|
2019-11-22 11:09:49 +00:00
|
|
|
( aIdxContentPathFileURL, osl_getThreadTextEncoding() ) );
|
2009-09-16 11:45:54 +00:00
|
|
|
std::string aStdStr_IdxContentPathFileURL( aOStr_IdxContentPathFileURL.getStr() );
|
2009-10-30 09:37:43 +00:00
|
|
|
|
|
|
|
idxContentStylesheet = fs::path( aStdStr_IdxContentPathFileURL );
|
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
if (!bExtensionMode && embeddStylesheet.empty())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "no embedding resolving file given" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
if (sourceRoot.empty())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "no sourceroot given" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
if (!bExtensionMode && outputFile.empty())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "no output file given" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
if (module.empty())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "module missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
if (!bExtensionMode && lang.empty())
|
|
|
|
{
|
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "language missing" << std::endl;
|
2017-02-15 15:44:07 +02:00
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
link();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Variable to set an exception in "C" StructuredXMLErrorFunction
|
2015-11-10 10:16:29 +01:00
|
|
|
static const HelpProcessingException* GpXMLParsingException = nullptr;
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2018-09-15 19:13:19 +02:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
static void StructuredXMLErrorFunction(SAL_UNUSED_PARAMETER void *, xmlErrorPtr error)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
std::string aErrorMsg = error->message;
|
|
|
|
std::string aXMLParsingFile;
|
2015-11-10 10:16:29 +01:00
|
|
|
if( error->file != nullptr )
|
2009-09-16 11:45:54 +00:00
|
|
|
aXMLParsingFile = error->file;
|
|
|
|
int nXMLParsingLine = error->line;
|
|
|
|
HelpProcessingException* pException = new HelpProcessingException( aErrorMsg, aXMLParsingFile, nXMLParsingLine );
|
|
|
|
GpXMLParsingException = pException;
|
|
|
|
|
|
|
|
// Reset error handler
|
2015-11-10 10:16:29 +01:00
|
|
|
xmlSetStructuredErrorFunc( nullptr, nullptr );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
2018-09-15 19:13:19 +02:00
|
|
|
}
|
|
|
|
|
2009-09-16 11:45:54 +00:00
|
|
|
HelpProcessingErrorInfo& HelpProcessingErrorInfo::operator=( const struct HelpProcessingException& e )
|
|
|
|
{
|
|
|
|
m_eErrorClass = e.m_eErrorClass;
|
2013-04-07 12:06:47 +02:00
|
|
|
OString tmpErrorMsg( e.m_aErrorMsg.c_str() );
|
2019-11-22 11:09:49 +00:00
|
|
|
m_aErrorMsg = OStringToOUString( tmpErrorMsg, osl_getThreadTextEncoding() );
|
2013-04-07 12:06:47 +02:00
|
|
|
OString tmpXMLParsingFile( e.m_aXMLParsingFile.c_str() );
|
2019-11-22 11:09:49 +00:00
|
|
|
m_aXMLParsingFile = OStringToOUString( tmpXMLParsingFile, osl_getThreadTextEncoding() );
|
2009-09-16 11:45:54 +00:00
|
|
|
m_nXMLParsingLine = e.m_nXMLParsingLine;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns true in case of success, false in case of error
|
2015-01-05 13:05:50 +01:00
|
|
|
bool compileExtensionHelp
|
2009-09-16 11:45:54 +00:00
|
|
|
(
|
2013-04-07 12:06:47 +02:00
|
|
|
const OUString& aOfficeHelpPath,
|
|
|
|
const OUString& aExtensionName,
|
|
|
|
const OUString& aExtensionLanguageRoot,
|
|
|
|
sal_Int32 nXhpFileCount, const OUString* pXhpFiles,
|
|
|
|
const OUString& aDestination,
|
2009-09-16 11:45:54 +00:00
|
|
|
HelpProcessingErrorInfo& o_rHelpProcessingErrorInfo
|
|
|
|
)
|
|
|
|
{
|
|
|
|
bool bSuccess = true;
|
|
|
|
|
2010-10-11 12:27:45 +02:00
|
|
|
std::vector<std::string> args;
|
|
|
|
args.reserve(nXhpFileCount + 2);
|
|
|
|
args.push_back(std::string("-mod"));
|
2019-11-22 11:09:49 +00:00
|
|
|
OString aOExtensionName = OUStringToOString( aExtensionName, osl_getThreadTextEncoding() );
|
2010-10-11 12:27:45 +02:00
|
|
|
args.push_back(std::string(aOExtensionName.getStr()));
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
for( sal_Int32 iXhp = 0 ; iXhp < nXhpFileCount ; ++iXhp )
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString aXhpFile = pXhpFiles[iXhp];
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2019-11-22 11:09:49 +00:00
|
|
|
OString aOXhpFile = OUStringToOString( aXhpFile, osl_getThreadTextEncoding() );
|
2010-10-11 12:27:45 +02:00
|
|
|
args.push_back(std::string(aOXhpFile.getStr()));
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
2019-11-22 11:09:49 +00:00
|
|
|
OString aOExtensionLanguageRoot = OUStringToOString( aExtensionLanguageRoot, osl_getThreadTextEncoding() );
|
2009-09-16 11:45:54 +00:00
|
|
|
const char* pExtensionPath = aOExtensionLanguageRoot.getStr();
|
|
|
|
std::string aStdStrExtensionPath = pExtensionPath;
|
2019-11-22 11:09:49 +00:00
|
|
|
OString aODestination = OUStringToOString(aDestination, osl_getThreadTextEncoding());
|
2010-04-06 17:15:01 +02:00
|
|
|
const char* pDestination = aODestination.getStr();
|
|
|
|
std::string aStdStrDestination = pDestination;
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
// Set error handler
|
2015-11-10 10:16:29 +01:00
|
|
|
xmlSetStructuredErrorFunc( nullptr, StructuredXMLErrorFunction );
|
2009-09-16 11:45:54 +00:00
|
|
|
try
|
|
|
|
{
|
2015-09-18 15:37:00 +01:00
|
|
|
std::unique_ptr<HelpLinker> pHelpLinker(new HelpLinker());
|
2010-04-06 17:15:01 +02:00
|
|
|
pHelpLinker->main( args, &aStdStrExtensionPath, &aStdStrDestination, &aOfficeHelpPath );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
catch( const HelpProcessingException& e )
|
|
|
|
{
|
2015-11-10 10:16:29 +01:00
|
|
|
if( GpXMLParsingException != nullptr )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
o_rHelpProcessingErrorInfo = *GpXMLParsingException;
|
|
|
|
delete GpXMLParsingException;
|
2015-11-10 10:16:29 +01:00
|
|
|
GpXMLParsingException = nullptr;
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
o_rHelpProcessingErrorInfo = e;
|
|
|
|
}
|
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
// Reset error handler
|
2015-11-10 10:16:29 +01:00
|
|
|
xmlSetStructuredErrorFunc( nullptr, nullptr );
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
// i83624: Tree files
|
2013-04-08 13:36:55 +02:00
|
|
|
// The following basically checks if the help.tree is well formed XML.
|
|
|
|
// Apparently there have been cases when translations contained
|
|
|
|
// non-well-formed XML in the past.
|
2013-10-25 17:17:50 +02:00
|
|
|
OUString aTreeFileURL = aExtensionLanguageRoot + "/help.tree";
|
2009-09-16 11:45:54 +00:00
|
|
|
osl::DirectoryItem aTreeFileItem;
|
|
|
|
osl::FileBase::RC rcGet = osl::DirectoryItem::get( aTreeFileURL, aTreeFileItem );
|
2011-04-13 20:52:55 +02:00
|
|
|
osl::FileStatus aFileStatus( osl_FileStatus_Mask_FileSize );
|
2009-09-16 11:45:54 +00:00
|
|
|
if( rcGet == osl::FileBase::E_None &&
|
|
|
|
aTreeFileItem.getFileStatus( aFileStatus ) == osl::FileBase::E_None &&
|
2011-04-13 20:52:55 +02:00
|
|
|
aFileStatus.isValid( osl_FileStatus_Mask_FileSize ) )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
sal_uInt64 ret, len = aFileStatus.getFileSize();
|
2015-06-15 17:58:15 +09:00
|
|
|
std::unique_ptr<char[]> s(new char[ int(len) ]); // the buffer to hold the installed files
|
2009-09-16 11:45:54 +00:00
|
|
|
osl::File aFile( aTreeFileURL );
|
2019-07-18 10:09:30 +01:00
|
|
|
(void)aFile.open( osl_File_OpenFlag_Read );
|
2014-04-17 10:56:03 +09:00
|
|
|
aFile.read( s.get(), len, ret );
|
2009-09-16 11:45:54 +00:00
|
|
|
aFile.close();
|
|
|
|
|
2015-11-10 10:16:29 +01:00
|
|
|
XML_Parser parser = XML_ParserCreate( nullptr );
|
2014-04-17 10:56:03 +09:00
|
|
|
XML_Status parsed = XML_Parse( parser, s.get(), int( len ), true );
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2012-07-12 22:08:10 +02:00
|
|
|
if (XML_STATUS_ERROR == parsed)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
XML_Error nError = XML_GetErrorCode( parser );
|
2017-02-15 15:44:07 +02:00
|
|
|
o_rHelpProcessingErrorInfo.m_eErrorClass = HelpProcessingErrorClass::XmlParsing;
|
2016-01-09 22:55:28 +01:00
|
|
|
o_rHelpProcessingErrorInfo.m_aErrorMsg = OUString::createFromAscii( XML_ErrorString( nError ) );
|
2009-09-16 11:45:54 +00:00
|
|
|
o_rHelpProcessingErrorInfo.m_aXMLParsingFile = aTreeFileURL;
|
2015-09-29 17:54:04 +02:00
|
|
|
// CRASHES!!! o_rHelpProcessingErrorInfo.m_nXMLParsingLine = XML_GetCurrentLineNumber( parser );
|
2009-09-16 11:45:54 +00:00
|
|
|
bSuccess = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
XML_ParserFree( parser );
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|