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.
|
|
|
|
*
|
|
|
|
* 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/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
2019-05-22 00:07:23 +02:00
|
|
|
#include <algorithm>
|
2017-04-14 08:42:15 +10:00
|
|
|
#include <memory>
|
2013-05-06 17:25:51 +02:00
|
|
|
#include <HelpCompiler.hxx>
|
|
|
|
#include <BasCodeTagger.hxx>
|
2019-05-22 00:07:23 +02:00
|
|
|
#include <iostream>
|
2009-09-16 11:45:54 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <libxslt/xsltInternals.h>
|
|
|
|
#include <libxslt/transform.h>
|
2018-07-27 17:57:59 +02:00
|
|
|
#include <rtl/character.hxx>
|
|
|
|
#include <sal/log.hxx>
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
HelpCompiler::HelpCompiler(StreamTable &in_streamTable, const fs::path &in_inputFile,
|
2013-02-13 16:28:16 +01:00
|
|
|
const fs::path &in_src, const fs::path &in_zipdir, const fs::path &in_resCompactStylesheet,
|
|
|
|
const fs::path &in_resEmbStylesheet, const std::string &in_module, const std::string &in_lang,
|
|
|
|
bool in_bExtensionMode)
|
2009-09-16 11:45:54 +00:00
|
|
|
: streamTable(in_streamTable), inputFile(in_inputFile),
|
2013-02-13 16:28:16 +01:00
|
|
|
src(in_src), zipdir(in_zipdir), module(in_module), lang(in_lang), resCompactStylesheet(in_resCompactStylesheet),
|
|
|
|
resEmbStylesheet(in_resEmbStylesheet), bExtensionMode( in_bExtensionMode )
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
xmlKeepBlanksDefaultValue = 0;
|
2013-06-06 09:35:51 +02:00
|
|
|
char* os = getenv("OS");
|
|
|
|
if (os)
|
2012-08-07 10:06:04 +04:00
|
|
|
{
|
2013-06-06 09:35:51 +02:00
|
|
|
gui = (strcmp(os, "WNT") ? "UNIX" : "WIN");
|
|
|
|
gui = (strcmp(os, "MACOSX") ? gui : "MAC");
|
2012-08-07 10:06:04 +04:00
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 22:32:53 +01:00
|
|
|
void HelpCompiler::tagBasicCodeExamples( xmlDocPtr doc )
|
2013-02-11 16:49:40 +01:00
|
|
|
{
|
2013-02-12 22:32:53 +01:00
|
|
|
try
|
2013-02-11 16:49:40 +01:00
|
|
|
{
|
2013-02-12 22:32:53 +01:00
|
|
|
BasicCodeTagger bct( doc );
|
|
|
|
bct.tagBasicCodes();
|
|
|
|
}
|
|
|
|
catch ( BasicCodeTagger::TaggerException &ex )
|
|
|
|
{
|
|
|
|
if ( ex != BasicCodeTagger::EMPTY_DOCUMENT )
|
|
|
|
throw;
|
2013-02-11 16:49:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 16:28:16 +01:00
|
|
|
xmlDocPtr HelpCompiler::compactXhpForJar( xmlDocPtr doc )
|
|
|
|
{
|
2015-11-10 10:16:29 +01:00
|
|
|
static xsltStylesheetPtr compact = nullptr;
|
2013-02-13 16:28:16 +01:00
|
|
|
static const char *params[2 + 1];
|
2015-11-10 10:16:29 +01:00
|
|
|
params[0] = nullptr;
|
2013-02-13 16:28:16 +01:00
|
|
|
xmlDocPtr compacted;
|
|
|
|
|
|
|
|
if (!compact)
|
|
|
|
{
|
2015-01-17 18:47:15 +01:00
|
|
|
compact = xsltParseStylesheetFile(reinterpret_cast<const xmlChar *>(resCompactStylesheet.native_file_string().c_str()));
|
2013-02-13 16:28:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
compacted = xsltApplyStylesheet(compact, doc, params);
|
|
|
|
return compacted;
|
|
|
|
}
|
|
|
|
|
2013-02-12 22:32:53 +01:00
|
|
|
void HelpCompiler::saveXhpForJar( xmlDocPtr doc, const fs::path &filePath )
|
|
|
|
{
|
|
|
|
//save processed xhp document in ziptmp<module>_<lang>/text directory
|
2016-02-16 14:14:43 +02:00
|
|
|
#ifdef _WIN32
|
2013-02-12 22:32:53 +01:00
|
|
|
std::string pathSep = "\\";
|
|
|
|
#else
|
|
|
|
std::string pathSep = "/";
|
|
|
|
#endif
|
|
|
|
const std::string& sourceXhpPath = filePath.native_file_string();
|
|
|
|
std::string zipdirPath = zipdir.native_file_string();
|
2013-02-26 14:55:05 +01:00
|
|
|
const std::string srcdirPath( src.native_file_string() );
|
|
|
|
// srcdirPath contains trailing /, but we want the file path with / at the beginning
|
|
|
|
std::string jarXhpPath = sourceXhpPath.substr( srcdirPath.length() - 1 );
|
2013-02-12 22:32:53 +01:00
|
|
|
std::string xhpFileName = jarXhpPath.substr( jarXhpPath.rfind( pathSep ) + 1 );
|
|
|
|
jarXhpPath = jarXhpPath.substr( 0, jarXhpPath.rfind( pathSep ) );
|
|
|
|
if ( !jarXhpPath.compare( 1, 11, "text" + pathSep + "sbasic" ) )
|
|
|
|
{
|
|
|
|
tagBasicCodeExamples( doc );
|
|
|
|
}
|
|
|
|
if ( !jarXhpPath.compare( 1, 11, "text" + pathSep + "shared" ) )
|
|
|
|
{
|
2013-02-26 14:55:05 +01:00
|
|
|
const size_t pos = zipdirPath.find( "ziptmp" );
|
|
|
|
if ( pos != std::string::npos )
|
|
|
|
zipdirPath.replace( pos + 6, module.length(), "shared" );
|
2013-02-12 22:32:53 +01:00
|
|
|
}
|
2013-02-13 16:28:16 +01:00
|
|
|
xmlDocPtr compacted = compactXhpForJar( doc );
|
2013-02-12 22:32:53 +01:00
|
|
|
fs::create_directory( fs::path( zipdirPath + jarXhpPath, fs::native ) );
|
2013-02-13 16:28:16 +01:00
|
|
|
if ( -1 == xmlSaveFormatFileEnc( (zipdirPath + jarXhpPath + pathSep + xhpFileName).c_str(), compacted, "utf-8", 0 ) )
|
2013-02-12 22:32:53 +01:00
|
|
|
std::cerr << "Error saving file to " << (zipdirPath + jarXhpPath + pathSep + xhpFileName).c_str() << std::endl;
|
2013-02-13 16:28:16 +01:00
|
|
|
xmlFreeDoc(compacted);
|
2013-02-12 22:32:53 +01:00
|
|
|
}
|
|
|
|
|
2009-09-16 11:45:54 +00:00
|
|
|
xmlDocPtr HelpCompiler::getSourceDocument(const fs::path &filePath)
|
|
|
|
{
|
|
|
|
xmlDocPtr res;
|
2019-11-22 11:24:40 +00:00
|
|
|
if (bExtensionMode)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2019-11-22 11:24:40 +00:00
|
|
|
// this is the mode when used within LibreOffice for importing help
|
|
|
|
// bundled with an extension
|
2009-09-16 11:45:54 +00:00
|
|
|
res = xmlParseFile(filePath.native_file_string().c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-22 11:24:40 +00:00
|
|
|
// this is the mode when used at build time to generate LibreOffice
|
|
|
|
// help from its xhp source
|
|
|
|
static xsltStylesheetPtr cur = nullptr;
|
2013-02-12 22:32:53 +01:00
|
|
|
static const char *params[2 + 1];
|
2009-09-16 11:45:54 +00:00
|
|
|
if (!cur)
|
|
|
|
{
|
|
|
|
static std::string fsroot('\'' + src.toUTF8() + '\'');
|
|
|
|
|
2015-01-17 18:47:15 +01:00
|
|
|
cur = xsltParseStylesheetFile(reinterpret_cast<const xmlChar *>(resEmbStylesheet.native_file_string().c_str()));
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
int nbparams = 0;
|
|
|
|
params[nbparams++] = "fsroot";
|
|
|
|
params[nbparams++] = fsroot.c_str();
|
2015-11-10 10:16:29 +01:00
|
|
|
params[nbparams] = nullptr;
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
xmlDocPtr doc = xmlParseFile(filePath.native_file_string().c_str());
|
2013-02-12 22:32:53 +01:00
|
|
|
|
|
|
|
saveXhpForJar( doc, filePath );
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
res = xsltApplyStylesheet(cur, doc, params);
|
|
|
|
xmlFreeDoc(doc);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns a node representing the whole stuff compiled for the current
|
|
|
|
// application.
|
|
|
|
xmlNodePtr HelpCompiler::clone(xmlNodePtr node, const std::string& appl)
|
|
|
|
{
|
2012-08-06 16:25:37 +02:00
|
|
|
xmlNodePtr root = xmlCopyNode(node, 2);
|
|
|
|
if (node->xmlChildrenNode)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2012-08-06 16:25:37 +02:00
|
|
|
xmlNodePtr list = node->xmlChildrenNode;
|
|
|
|
while (list)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2015-01-17 18:47:15 +01:00
|
|
|
if (strcmp(reinterpret_cast<const char*>(list->name), "switchinline") == 0 || strcmp(reinterpret_cast<const char*>(list->name), "switch") == 0)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2012-08-06 16:25:37 +02:00
|
|
|
std::string tmp="";
|
2015-01-17 18:47:15 +01:00
|
|
|
xmlChar * prop = xmlGetProp(list, reinterpret_cast<xmlChar const *>("select"));
|
2015-11-10 10:16:29 +01:00
|
|
|
if (prop != nullptr)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2015-01-17 18:47:15 +01:00
|
|
|
if (strcmp(reinterpret_cast<char *>(prop), "sys") == 0)
|
2014-05-28 08:51:12 +02:00
|
|
|
{
|
|
|
|
tmp = gui;
|
|
|
|
}
|
2015-01-17 18:47:15 +01:00
|
|
|
else if (strcmp(reinterpret_cast<char *>(prop), "appl") == 0)
|
2014-05-28 08:51:12 +02:00
|
|
|
{
|
|
|
|
tmp = appl;
|
|
|
|
}
|
|
|
|
xmlFree(prop);
|
2012-08-06 16:25:37 +02:00
|
|
|
}
|
|
|
|
if (tmp.compare("") != 0)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2012-08-06 16:25:37 +02:00
|
|
|
bool isCase=false;
|
|
|
|
xmlNodePtr caseList=list->xmlChildrenNode;
|
|
|
|
while (caseList)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2015-01-17 18:47:15 +01:00
|
|
|
xmlChar *select = xmlGetProp(caseList, reinterpret_cast<xmlChar const *>("select"));
|
2009-09-16 11:45:54 +00:00
|
|
|
if (select)
|
|
|
|
{
|
2015-01-17 18:47:15 +01:00
|
|
|
if (!strcmp(reinterpret_cast<char*>(select), tmp.c_str()) && !isCase)
|
2012-08-06 16:25:37 +02:00
|
|
|
{
|
|
|
|
isCase=true;
|
|
|
|
xmlNodePtr clp = caseList->xmlChildrenNode;
|
|
|
|
while (clp)
|
|
|
|
{
|
|
|
|
xmlAddChild(root, clone(clp, appl));
|
|
|
|
clp = clp->next;
|
|
|
|
}
|
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
xmlFree(select);
|
|
|
|
}
|
2012-08-06 16:25:37 +02:00
|
|
|
else
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2015-01-17 18:47:15 +01:00
|
|
|
if ((strcmp(reinterpret_cast<const char*>(caseList->name), "defaultinline") != 0) && (strcmp(reinterpret_cast<const char*>(caseList->name), "default") != 0))
|
2012-08-06 16:25:37 +02:00
|
|
|
{
|
|
|
|
xmlAddChild(root, clone(caseList, appl));
|
|
|
|
}
|
|
|
|
else
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2012-08-06 16:25:37 +02:00
|
|
|
if (!isCase)
|
|
|
|
{
|
|
|
|
xmlNodePtr clp = caseList->xmlChildrenNode;
|
|
|
|
while (clp)
|
|
|
|
{
|
|
|
|
xmlAddChild(root, clone(clp, appl));
|
|
|
|
clp = clp->next;
|
|
|
|
}
|
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-06 16:25:37 +02:00
|
|
|
caseList = caseList->next;
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-06 16:25:37 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlAddChild(root, clone(list, appl));
|
|
|
|
}
|
|
|
|
list = list->next;
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-06 16:25:37 +02:00
|
|
|
return root;
|
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 myparser
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string documentId;
|
|
|
|
std::string fileName;
|
|
|
|
std::string title;
|
2018-06-03 16:00:14 +03:00
|
|
|
std::unique_ptr< std::vector<std::string> > hidlist;
|
2014-12-15 09:22:15 +00:00
|
|
|
std::unique_ptr<Hashtable> keywords;
|
|
|
|
std::unique_ptr<Stringtable> helptexts;
|
2009-09-16 11:45:54 +00:00
|
|
|
private:
|
2018-06-03 16:00:14 +03:00
|
|
|
std::vector<std::string> extendedHelpText;
|
2009-09-16 11:45:54 +00:00
|
|
|
public:
|
|
|
|
myparser(const std::string &indocumentId, const std::string &infileName,
|
|
|
|
const std::string &intitle) : documentId(indocumentId), fileName(infileName),
|
|
|
|
title(intitle)
|
|
|
|
{
|
2018-06-03 16:00:14 +03:00
|
|
|
hidlist.reset(new std::vector<std::string>);
|
2014-12-15 09:22:15 +00:00
|
|
|
keywords.reset(new Hashtable);
|
|
|
|
helptexts.reset(new Stringtable);
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
void traverse( xmlNodePtr parentNode );
|
|
|
|
private:
|
|
|
|
std::string dump(xmlNodePtr node);
|
|
|
|
};
|
|
|
|
|
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
|
|
|
std::string myparser::dump(xmlNodePtr node)
|
|
|
|
{
|
|
|
|
std::string app;
|
|
|
|
if (node->xmlChildrenNode)
|
|
|
|
{
|
|
|
|
xmlNodePtr list = node->xmlChildrenNode;
|
|
|
|
while (list)
|
|
|
|
{
|
|
|
|
app += dump(list);
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (xmlNodeIsText(node))
|
|
|
|
{
|
|
|
|
xmlChar *pContent = xmlNodeGetContent(node);
|
2015-01-17 18:47:15 +01:00
|
|
|
app += std::string(reinterpret_cast<char*>(pContent));
|
2009-09-16 11:45:54 +00:00
|
|
|
xmlFree(pContent);
|
|
|
|
}
|
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
2018-09-15 19:13:19 +02:00
|
|
|
static void trim(std::string& str)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
std::string::size_type pos = str.find_last_not_of(' ');
|
|
|
|
if(pos != std::string::npos)
|
|
|
|
{
|
|
|
|
str.erase(pos + 1);
|
|
|
|
pos = str.find_first_not_of(' ');
|
|
|
|
if(pos != std::string::npos)
|
|
|
|
str.erase(0, pos);
|
|
|
|
}
|
|
|
|
else
|
2019-02-18 13:30:30 +02:00
|
|
|
str.clear();
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void myparser::traverse( xmlNodePtr parentNode )
|
|
|
|
{
|
|
|
|
// traverse all nodes that belong to the parent
|
|
|
|
xmlNodePtr test ;
|
|
|
|
for (test = parentNode->xmlChildrenNode; test; test = test->next)
|
|
|
|
{
|
2015-01-17 18:47:15 +01:00
|
|
|
if (fileName.empty() && !strcmp(reinterpret_cast<const char*>(test->name), "filename"))
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
xmlNodePtr node = test->xmlChildrenNode;
|
|
|
|
if (xmlNodeIsText(node))
|
|
|
|
{
|
|
|
|
xmlChar *pContent = xmlNodeGetContent(node);
|
2015-01-17 18:47:15 +01:00
|
|
|
fileName = std::string(reinterpret_cast<char*>(pContent));
|
2009-09-16 11:45:54 +00:00
|
|
|
xmlFree(pContent);
|
|
|
|
}
|
|
|
|
}
|
2015-01-17 18:47:15 +01:00
|
|
|
else if (title.empty() && !strcmp(reinterpret_cast<const char*>(test->name), "title"))
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
title = dump(test);
|
|
|
|
if (title.empty())
|
|
|
|
title = "<notitle>";
|
|
|
|
}
|
2015-01-17 18:47:15 +01:00
|
|
|
else if (!strcmp(reinterpret_cast<const char*>(test->name), "bookmark"))
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2015-01-17 18:47:15 +01:00
|
|
|
xmlChar *branchxml = xmlGetProp(test, reinterpret_cast<const xmlChar*>("branch"));
|
2018-06-13 10:21:21 +02:00
|
|
|
if (branchxml == nullptr) {
|
|
|
|
throw HelpProcessingException(
|
|
|
|
HelpProcessingErrorClass::XmlParsing, "bookmark lacks branch attribute");
|
|
|
|
}
|
2015-01-17 18:47:15 +01:00
|
|
|
std::string branch(reinterpret_cast<char*>(branchxml));
|
2009-09-16 11:45:54 +00:00
|
|
|
xmlFree (branchxml);
|
2018-06-13 10:21:21 +02:00
|
|
|
xmlChar *idxml = xmlGetProp(test, reinterpret_cast<const xmlChar*>("id"));
|
|
|
|
if (idxml == nullptr) {
|
|
|
|
throw HelpProcessingException(
|
|
|
|
HelpProcessingErrorClass::XmlParsing, "bookmark lacks id attribute");
|
|
|
|
}
|
|
|
|
std::string anchor(reinterpret_cast<char*>(idxml));
|
2009-09-16 11:45:54 +00:00
|
|
|
xmlFree (idxml);
|
|
|
|
|
2015-12-10 23:47:00 +01:00
|
|
|
if (branch.compare(0, 3, "hid") == 0)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
size_t index = branch.find('/');
|
|
|
|
if (index != std::string::npos)
|
|
|
|
{
|
2016-08-23 12:17:35 +02:00
|
|
|
auto hid = branch.substr(1 + index);
|
2009-09-16 11:45:54 +00:00
|
|
|
// one shall serve as a documentId
|
|
|
|
if (documentId.empty())
|
|
|
|
documentId = hid;
|
|
|
|
extendedHelpText.push_back(hid);
|
2013-03-04 15:25:02 +01:00
|
|
|
HCDBG(std::cerr << "hid pushback" << (anchor.empty() ? hid : hid + "#" + anchor) << std::endl);
|
2009-09-16 11:45:54 +00:00
|
|
|
hidlist->push_back( anchor.empty() ? hid : hid + "#" + anchor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (branch.compare("index") == 0)
|
|
|
|
{
|
|
|
|
LinkedList ll;
|
|
|
|
|
|
|
|
for (xmlNodePtr nd = test->xmlChildrenNode; nd; nd = nd->next)
|
|
|
|
{
|
2015-01-17 18:47:15 +01:00
|
|
|
if (strcmp(reinterpret_cast<const char*>(nd->name), "bookmark_value"))
|
2009-09-16 11:45:54 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
std::string embedded;
|
2015-01-17 18:47:15 +01:00
|
|
|
xmlChar *embeddedxml = xmlGetProp(nd, reinterpret_cast<const xmlChar*>("embedded"));
|
2009-09-16 11:45:54 +00:00
|
|
|
if (embeddedxml)
|
|
|
|
{
|
2015-01-17 18:47:15 +01:00
|
|
|
embedded = std::string(reinterpret_cast<char*>(embeddedxml));
|
2009-09-16 11:45:54 +00:00
|
|
|
xmlFree (embeddedxml);
|
|
|
|
std::transform (embedded.begin(), embedded.end(),
|
2011-06-16 14:54:35 +01:00
|
|
|
embedded.begin(), tocharlower);
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isEmbedded = !embedded.empty() && embedded.compare("true") == 0;
|
|
|
|
if (isEmbedded)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::string keyword = dump(nd);
|
|
|
|
size_t keywordSem = keyword.find(';');
|
|
|
|
if (keywordSem != std::string::npos)
|
|
|
|
{
|
|
|
|
std::string tmppre =
|
|
|
|
keyword.substr(0,keywordSem);
|
|
|
|
trim(tmppre);
|
|
|
|
std::string tmppos =
|
|
|
|
keyword.substr(1+keywordSem);
|
|
|
|
trim(tmppos);
|
|
|
|
keyword = tmppre + ";" + tmppos;
|
|
|
|
}
|
|
|
|
ll.push_back(keyword);
|
|
|
|
}
|
|
|
|
if (!ll.empty())
|
|
|
|
(*keywords)[anchor] = ll;
|
|
|
|
}
|
|
|
|
else if (branch.compare("contents") == 0)
|
|
|
|
{
|
|
|
|
// currently not used
|
|
|
|
}
|
|
|
|
}
|
2015-01-17 18:47:15 +01:00
|
|
|
else if (!strcmp(reinterpret_cast<const char*>(test->name), "ahelp"))
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2015-02-02 14:49:15 +00:00
|
|
|
//tool-tip
|
2009-09-16 11:45:54 +00:00
|
|
|
std::string text = dump(test);
|
2015-01-15 08:27:18 +01:00
|
|
|
std::replace(text.begin(), text.end(), '\n', ' ');
|
2009-09-16 11:45:54 +00:00
|
|
|
trim(text);
|
|
|
|
|
2015-02-02 14:49:15 +00:00
|
|
|
//tool-tip target
|
|
|
|
std::string hidstr("."); //. == previous seen hid bookmarks
|
|
|
|
xmlChar *hid = xmlGetProp(test, reinterpret_cast<const xmlChar*>("hid"));
|
|
|
|
if (hid)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2015-02-02 14:49:15 +00:00
|
|
|
hidstr = std::string(reinterpret_cast<char*>(hid));
|
|
|
|
xmlFree (hid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hidstr != "." && !hidstr.empty()) //simple case of explicitly named target
|
|
|
|
{
|
|
|
|
assert(!hidstr.empty());
|
|
|
|
(*helptexts)[hidstr] = text;
|
|
|
|
}
|
|
|
|
else //apply to list of "current" hids determined by recent bookmarks that have hid in their branch
|
|
|
|
{
|
|
|
|
//TODO: make these asserts and flush out all our broken help ids
|
|
|
|
SAL_WARN_IF(hidstr.empty(), "helpcompiler", "hid='' for text:" << text);
|
2017-05-25 23:33:03 +02:00
|
|
|
SAL_WARN_IF(!hidstr.empty() && extendedHelpText.empty(), "helpcompiler", "hid='.' with no hid bookmark branches in file: " << fileName + " for text: " << text);
|
2018-10-23 07:50:57 +02:00
|
|
|
for (const std::string& name : extendedHelpText)
|
2015-02-02 14:49:15 +00:00
|
|
|
{
|
|
|
|
(*helptexts)[name] = text;
|
|
|
|
}
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
extendedHelpText.clear();
|
|
|
|
}
|
|
|
|
// traverse children
|
|
|
|
traverse(test);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 12:20:59 +02:00
|
|
|
void HelpCompiler::compile()
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
// we now have the jaroutputstream, which will contain the document.
|
|
|
|
// now determine the document as a dom tree in variable docResolved
|
|
|
|
|
|
|
|
xmlDocPtr docResolvedOrg = getSourceDocument(inputFile);
|
|
|
|
|
|
|
|
// now add path to the document
|
|
|
|
// resolve the dom
|
2012-08-06 16:25:37 +02:00
|
|
|
|
2009-09-16 11:45:54 +00:00
|
|
|
if (!docResolvedOrg)
|
|
|
|
{
|
2019-11-22 11:03:07 +00:00
|
|
|
std::stringstream aStrStream;
|
|
|
|
aStrStream << "ERROR: file not existing: " << inputFile.native_file_string().c_str() << std::endl;
|
|
|
|
throw HelpProcessingException( HelpProcessingErrorClass::General, aStrStream.str() );
|
2009-09-16 11:45:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string documentId;
|
|
|
|
std::string fileName;
|
|
|
|
std::string title;
|
2012-08-06 16:25:37 +02:00
|
|
|
// returns a clone of the document with switch-cases resolved
|
|
|
|
std::string appl = module.substr(1);
|
2016-04-28 10:24:35 +02:00
|
|
|
for (char & i : appl)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2017-03-21 22:50:15 +01:00
|
|
|
i=rtl::toAsciiUpperCase(static_cast<unsigned char>(i));
|
2012-08-06 16:25:37 +02:00
|
|
|
}
|
|
|
|
xmlNodePtr docResolved = clone(xmlDocGetRootElement(docResolvedOrg), appl);
|
|
|
|
myparser aparser(documentId, fileName, title);
|
|
|
|
aparser.traverse(docResolved);
|
|
|
|
documentId = aparser.documentId;
|
|
|
|
fileName = aparser.fileName;
|
|
|
|
title = aparser.title;
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2012-08-06 16:25:37 +02:00
|
|
|
HCDBG(std::cerr << documentId << " : " << fileName << " : " << title << std::endl);
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2012-08-06 16:25:37 +02:00
|
|
|
xmlDocPtr docResolvedDoc = xmlCopyDoc(docResolvedOrg, false);
|
|
|
|
xmlDocSetRootElement(docResolvedDoc, docResolved);
|
2009-09-16 11:45:54 +00:00
|
|
|
|
2012-08-06 16:25:37 +02:00
|
|
|
streamTable.dropappl();
|
|
|
|
streamTable.appl_doc = docResolvedDoc;
|
2018-04-12 15:39:54 +02:00
|
|
|
streamTable.appl_hidlist = std::move(aparser.hidlist);
|
|
|
|
streamTable.appl_helptexts = std::move(aparser.helptexts);
|
|
|
|
streamTable.appl_keywords = std::move(aparser.keywords);
|
2009-09-16 11:45:54 +00:00
|
|
|
|
|
|
|
streamTable.document_path = fileName;
|
|
|
|
streamTable.document_title = title;
|
|
|
|
std::string actMod = module;
|
2012-08-06 16:25:37 +02:00
|
|
|
|
2009-09-16 11:45:54 +00:00
|
|
|
if ( !bExtensionMode && !fileName.empty())
|
|
|
|
{
|
2015-12-08 12:07:49 +01:00
|
|
|
if (fileName.compare(0, 6, "/text/") == 0)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
2017-06-23 16:04:59 +02:00
|
|
|
actMod = fileName.substr(strlen("/text/"));
|
2009-09-16 11:45:54 +00:00
|
|
|
actMod = actMod.substr(0, actMod.find('/'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
streamTable.document_module = actMod;
|
|
|
|
xmlFreeDoc(docResolvedOrg);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace fs
|
|
|
|
{
|
2015-03-09 21:10:04 +00:00
|
|
|
void create_directory(const fs::path& indexDirName)
|
2009-09-16 11:45:54 +00:00
|
|
|
{
|
|
|
|
HCDBG(
|
|
|
|
std::cerr << "creating " <<
|
2013-04-07 12:06:47 +02:00
|
|
|
OUStringToOString(indexDirName.data, RTL_TEXTENCODING_UTF8).getStr()
|
2009-09-16 11:45:54 +00:00
|
|
|
<< std::endl
|
|
|
|
);
|
|
|
|
osl::Directory::createPath(indexDirName.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void copy(const fs::path &src, const fs::path &dest)
|
|
|
|
{
|
|
|
|
osl::File::copy(src.data, dest.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|