Skip to content

Commit

Permalink
Write out used settings when generating XML output
Browse files Browse the repository at this point in the history
When generating XML output is is afterwards unknown which settings have been used to generate the XML output, e.g. whether `EXTRACT_PRIVATE` was set or not as the XML output tries to write out all information contained in the sources and not to limit it.
By writing out a Doxyfile.xml with all the used settings this can be overcome.
  • Loading branch information
albert-github committed Mar 28, 2021
1 parent cef71dc commit 16fd18f
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ namespace Config
*/
void compareDoxyfile(std::ostream &t);

/*! Writes a the used settings of the current configuartion as XML format
* to stream \a t.
*/
void writeXMLDoxyfile(std::ostream &t);

/*! Parses a configuration file with name \a fn.
* \returns TRUE if successful, FALSE if the file could not be
* opened or read.
Expand Down
26 changes: 23 additions & 3 deletions src/configimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ class ConfigOption
protected:
virtual void writeTemplate(std::ostream &t,bool sl,bool upd) = 0;
virtual void compareDoxyfile(std::ostream &t) = 0;
virtual void writeXMLDoxyfile(std::ostream &t) = 0;
virtual void convertStrToVal() {}
virtual void emptyValueToDefault() {}
virtual void substEnvVars() = 0;
virtual void init() {}
virtual bool isDefault() {return true;}

void writeBoolValue(std::ostream &t,bool v);
void writeIntValue(std::ostream &t,int i);
void writeStringValue(std::ostream &t,const QCString &s);
void writeBoolValue(std::ostream &t,bool v,bool initSpace = true);
void writeIntValue(std::ostream &t,int i,bool initSpace = true);
void writeStringValue(std::ostream &t,const QCString &s,bool initSpace = true);
void writeStringList(std::ostream &t,const StringVector &l);

QCString m_spaces;
Expand All @@ -109,6 +111,7 @@ class ConfigInfo : public ConfigOption
}
void writeTemplate(std::ostream &t, bool sl,bool);
void compareDoxyfile(std::ostream &){};
void writeXMLDoxyfile(std::ostream &) {};
void substEnvVars() {}
};

Expand All @@ -132,8 +135,10 @@ class ConfigList : public ConfigOption
StringVector getDefault() { return m_defaultValue; }
void writeTemplate(std::ostream &t,bool sl,bool);
void compareDoxyfile(std::ostream &t);
void writeXMLDoxyfile(std::ostream &t);
void substEnvVars();
void init() { m_value = m_defaultValue; }
bool isDefault();
private:
StringVector m_value;
StringVector m_defaultValue;
Expand All @@ -160,7 +165,9 @@ class ConfigEnum : public ConfigOption
void writeTemplate(std::ostream &t,bool sl,bool);
void convertStrToVal();
void compareDoxyfile(std::ostream &t);
void writeXMLDoxyfile(std::ostream &t);
void init() { m_value = m_defValue.copy(); }
bool isDefault() { return (m_value == m_defValue); }

private:
std::vector<QCString> m_valueRange;
Expand Down Expand Up @@ -190,9 +197,11 @@ class ConfigString : public ConfigOption
QCString *valueRef() { return &m_value; }
void writeTemplate(std::ostream &t,bool sl,bool);
void compareDoxyfile(std::ostream &t);
void writeXMLDoxyfile(std::ostream &t);
void substEnvVars();
void init() { m_value = m_defValue.copy(); }
void emptyValueToDefault() { if(m_value.isEmpty()) m_value=m_defValue; };
bool isDefault() { return (m_value.stripWhiteSpace() == m_defValue.stripWhiteSpace()); }

private:
QCString m_value;
Expand Down Expand Up @@ -223,7 +232,9 @@ class ConfigInt : public ConfigOption
void substEnvVars();
void writeTemplate(std::ostream &t,bool sl,bool upd);
void compareDoxyfile(std::ostream &t);
void writeXMLDoxyfile(std::ostream &t);
void init() { m_value = m_defValue; }
bool isDefault() { return (m_value == m_defValue); }
private:
int m_value;
int m_defValue;
Expand Down Expand Up @@ -252,7 +263,9 @@ class ConfigBool : public ConfigOption
void setValueString(const QCString &v) { m_valueString = v; }
void writeTemplate(std::ostream &t,bool sl,bool upd);
void compareDoxyfile(std::ostream &t);
void writeXMLDoxyfile(std::ostream &t);
void init() { m_value = m_defValue; }
bool isDefault() { return (m_value == m_defValue); }
private:
bool m_value;
bool m_defValue;
Expand All @@ -268,6 +281,7 @@ class ConfigObsolete : public ConfigOption
{ m_name = name; }
void writeTemplate(std::ostream &,bool,bool);
void compareDoxyfile(std::ostream &) {}
void writeXMLDoxyfile(std::ostream &) {};
void substEnvVars() {}
};

Expand All @@ -280,6 +294,7 @@ class ConfigDisabled : public ConfigOption
{ m_name = name; }
void writeTemplate(std::ostream &,bool,bool);
void compareDoxyfile(std::ostream &) {}
void writeXMLDoxyfile(std::ostream &) {};
void substEnvVars() {}
};

Expand Down Expand Up @@ -480,6 +495,11 @@ class ConfigImpl
*/
void compareDoxyfile(std::ostream &t);

/*! Writes a the used settings of the current configuartion as XML format
* to stream \a t.
*/
void writeXMLDoxyfile(std::ostream &t);

void setHeader(const char *header) { m_header = header; }

/////////////////////////////
Expand Down
123 changes: 108 additions & 15 deletions src/configimpl.l
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "portable.h"
#include "message.h"
#include "lang_cfg.h"
#include "language.h"
#include "configoptions.h"
#include "fileinfo.h"
#include "dir.h"
Expand Down Expand Up @@ -127,18 +128,19 @@ static QCString convertToComment(const QCString &s, const QCString &u)
return result;
}

void ConfigOption::writeBoolValue(std::ostream &t,bool v)
void ConfigOption::writeBoolValue(std::ostream &t,bool v,bool initSpace)
{
t << " ";
if (initSpace) t << " ";
if (v) t << "YES"; else t << "NO";
}

void ConfigOption::writeIntValue(std::ostream &t,int i)
void ConfigOption::writeIntValue(std::ostream &t,int i,bool initSpace)
{
t << " " << i;
if (initSpace) t << " ";
t << i;
}

void ConfigOption::writeStringValue(std::ostream &t,const QCString &s)
void ConfigOption::writeStringValue(std::ostream &t,const QCString &s,bool initSpace)
{
char c;
bool needsEscaping=FALSE;
Expand All @@ -147,7 +149,7 @@ void ConfigOption::writeStringValue(std::ostream &t,const QCString &s)
const char *p=se.data();
if (p)
{
t << " ";
if (initSpace) t << " ";
while ((c=*p++)!=0 && !needsEscaping)
needsEscaping = (c==' ' || c== ',' || c=='\n' || c=='\t' || c=='"' || c=='#');
if (needsEscaping)
Expand Down Expand Up @@ -349,16 +351,15 @@ void ConfigList::writeTemplate(std::ostream &t,bool sl,bool)
t << "\n";
}

void ConfigList::compareDoxyfile(std::ostream &t)
bool ConfigList::isDefault()
{
auto get_stripped = [](std::string s) { return QCString(s.c_str()).stripWhiteSpace(); };
auto is_not_empty = [get_stripped](std::string s) { return !get_stripped(s).isEmpty(); };
int defCnt = std::count_if( m_value.begin(), m_value.end(),is_not_empty);
int valCnt = std::count_if(m_defaultValue.begin(),m_defaultValue.end(),is_not_empty);
if ( valCnt != defCnt)
{
writeTemplate(t,TRUE,TRUE);
return;
return false;
}
auto it1 = m_value.begin();
auto it2 = m_defaultValue.begin();
Expand All @@ -373,13 +374,37 @@ void ConfigList::compareDoxyfile(std::ostream &t)
{
if (get_stripped(*it1) != get_stripped(*it2)) // not the default, write as difference
{
writeTemplate(t,TRUE,TRUE);
return;
return false;
}
++it1;
++it2;
}
}
return true;
}

void ConfigList::compareDoxyfile(std::ostream &t)
{
if (!isDefault()) writeTemplate(t,TRUE,TRUE);
}

void ConfigList::writeXMLDoxyfile(std::ostream &t)
{
t << " <option id='" << m_name << "'";
t << " default='" << (isDefault() ? "yes" : "no") << "'";
t << " type='stringlist'";
t << ">";
t << "\n";
for (const auto &p : m_value)
{
QCString s=p.c_str();
t << " <value>";
t << "<![CDATA[";
writeStringValue(t,s,false);
t << "]]>";
t << "</value>\n";
}
t << " </option>\n";
}

void ConfigEnum::writeTemplate(std::ostream &t,bool sl,bool)
Expand All @@ -401,7 +426,19 @@ void ConfigEnum::writeTemplate(std::ostream &t,bool sl,bool)

void ConfigEnum::compareDoxyfile(std::ostream &t)
{
if (m_value != m_defValue) writeTemplate(t,TRUE,TRUE);
if (!isDefault()) writeTemplate(t,TRUE,TRUE);
}

void ConfigEnum::writeXMLDoxyfile(std::ostream &t)
{
t << " <option id='" << m_name << "'";
t << " default='" << (isDefault() ? "yes" : "no") << "'";
t << " type='string'";
t << ">";
t << "<value>";
writeStringValue(t,m_value,false);
t << "</value>";
t << "</option>\n";
}

void ConfigString::writeTemplate(std::ostream &t,bool sl,bool)
Expand All @@ -423,7 +460,21 @@ void ConfigString::writeTemplate(std::ostream &t,bool sl,bool)

void ConfigString::compareDoxyfile(std::ostream &t)
{
if (m_value.stripWhiteSpace() != m_defValue.stripWhiteSpace()) writeTemplate(t,TRUE,TRUE);
if (!isDefault()) writeTemplate(t,TRUE,TRUE);
}

void ConfigString::writeXMLDoxyfile(std::ostream &t)
{
t << " <option id='" << m_name << "'";
t << " default='" << (isDefault() ? "yes" : "no") << "'";
t << " type='string'";
t << ">";
t << "<value>";
t << "<![CDATA[";
writeStringValue(t,m_value,false);
t << "]]>";
t << "</value>";
t << "</option>\n";
}

void ConfigInt::writeTemplate(std::ostream &t,bool sl,bool upd)
Expand Down Expand Up @@ -452,9 +503,22 @@ void ConfigInt::writeTemplate(std::ostream &t,bool sl,bool upd)

void ConfigInt::compareDoxyfile(std::ostream &t)
{
if (m_value != m_defValue) writeTemplate(t,TRUE,TRUE);
if (!isDefault()) writeTemplate(t,TRUE,TRUE);
}

void ConfigInt::writeXMLDoxyfile(std::ostream &t)
{
t << " <option id='" << m_name << "'";
t << " default='" << (isDefault() ? "yes" : "no") << "'";
t << " type='int'";
t << ">";
t << "<value>";
writeIntValue(t,m_value,false);
t << "</value>";
t << "</option>\n";
}


void ConfigBool::writeTemplate(std::ostream &t,bool sl,bool upd)
{
if (!sl)
Expand Down Expand Up @@ -482,9 +546,22 @@ void ConfigBool::writeTemplate(std::ostream &t,bool sl,bool upd)

void ConfigBool::compareDoxyfile(std::ostream &t)
{
if (m_value != m_defValue) writeTemplate(t,TRUE,TRUE);
if (!isDefault()) writeTemplate(t,TRUE,TRUE);
}

void ConfigBool::writeXMLDoxyfile(std::ostream &t)
{
t << " <option id='" << m_name << "'";
t << " default='" << (isDefault() ? "yes" : "no") << "'";
t << " type='bool'";
t << ">";
t << "<value>";
writeBoolValue(t,m_value,false);
t << "</value>";
t << "</option>\n";
}


void ConfigObsolete::writeTemplate(std::ostream &,bool,bool) {}
void ConfigDisabled::writeTemplate(std::ostream &,bool,bool) {}

Expand Down Expand Up @@ -1117,6 +1194,17 @@ void ConfigImpl::compareDoxyfile(std::ostream &t)
}
}

void ConfigImpl::writeXMLDoxyfile(std::ostream &t)
{
t << "<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n";
t << "<doxyfile xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"doxyfile.xsd\" version=\"" << getDoxygenVersion() << "\" xml:lang=\"" << theTranslator->trISOLang() << "\">\n";
for (const auto &option : m_options)
{
option->writeXMLDoxyfile(t);
}
t << "</doxyfile>\n";
}

void ConfigImpl::convertStrToVal()
{
for (const auto &option : m_options)
Expand Down Expand Up @@ -2073,6 +2161,11 @@ void Config::compareDoxyfile(std::ostream &t)
ConfigImpl::instance()->compareDoxyfile(t);
}

void Config::writeXMLDoxyfile(std::ostream &t)
{
ConfigImpl::instance()->writeXMLDoxyfile(t);
}

bool Config::parse(const char *fileName,bool update)
{
return ConfigImpl::instance()->parse(fileName,update);
Expand Down
14 changes: 14 additions & 0 deletions src/xmlgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,7 @@ void generateXML()

ResourceMgr::instance().copyResource("xml.xsd",outputDirectory);
ResourceMgr::instance().copyResource("index.xsd",outputDirectory);
ResourceMgr::instance().copyResource("doxyfile.xsd",outputDirectory);

QCString fileName=outputDirectory+"/compound.xsd";
std::ofstream t(fileName.str(),std::ofstream::out | std::ofstream::binary);
Expand Down Expand Up @@ -1858,6 +1859,19 @@ void generateXML()
}
t.close();

std::ofstream f;
fileName=outputDirectory+"/Doxyfile.xml";
bool fileOpened=openOutputFile(fileName,f);
if (fileOpened)
{
Config::writeXMLDoxyfile(f);
}
else
{
err("Cannot open file %s for writing\n",fileName.data());
return;
}

fileName=outputDirectory+"/index.xml";
t.open(fileName.str(),std::ofstream::out | std::ofstream::binary);
if (!t.is_open())
Expand Down
Loading

0 comments on commit 16fd18f

Please sign in to comment.