Skip to content

Commit 8bbc1e4

Browse files
committed
csdiff --html-output: write the result in HTML format
Suggested-by: Fabio M. Di Nitto Fixes: https://github.com/kdudka/csdiff/issues/13 Closes: https://github.com/kdudka/csdiff/pull/14
1 parent 7380a6c commit 8bbc1e4

File tree

6 files changed

+32
-20
lines changed

6 files changed

+32
-20
lines changed

abstract-parser.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ enum EFileFormat {
3232
FF_AUTO, ///< choose format automatically
3333
FF_COVERITY, ///< what cov-format-errors produces
3434
FF_GCC, ///< GCC format
35-
FF_JSON ///< JSON format
35+
FF_JSON, ///< JSON format
36+
FF_HTML ///< HTML format (output only)
3637
};
3738

3839
// abstract class with a factory method

abstract-writer.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "cswriter.hh"
2323
#include "instream.hh"
2424
#include "json-writer.hh"
25+
#include "html-writer.hh"
2526

2627
#include <boost/regex.hpp>
2728

@@ -74,27 +75,36 @@ void AbstractWriter::setScanProps(const TScanProps &scanProps) {
7475
}
7576

7677
AbstractWriter* createWriter(
78+
std::ostream &strDst,
7779
const EFileFormat format,
7880
const EColorMode cm,
7981
const TScanProps &scanProps)
8082
{
8183
AbstractWriter *writer = 0;
8284

8385
switch (format) {
86+
case FF_GCC:
87+
// we have no writer for GCC format, fallback to Coverity
88+
// fall through!
89+
8490
case FF_INVALID:
8591
case FF_COVERITY:
86-
writer = new CovWriter(std::cout, cm);
92+
writer = new CovWriter(strDst, cm);
8793
break;
8894

89-
case FF_GCC:
90-
// TODO
91-
9295
case FF_AUTO:
9396
// TODO
9497

9598
case FF_JSON:
96-
writer = new JsonWriter(std::cout);
99+
writer = new JsonWriter(strDst);
100+
break;
101+
102+
case FF_HTML: {
103+
const std::string emp;
104+
const std::string spPlacement = "bottom";
105+
writer = new HtmlWriter(strDst, emp, emp, spPlacement);
97106
break;
107+
}
98108
}
99109

100110
if (!scanProps.empty())

abstract-writer.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class AbstractWriter {
6868
};
6969

7070
AbstractWriter* createWriter(
71+
std::ostream &strDst,
7172
const EFileFormat format,
7273
const EColorMode cm = CM_AUTO,
7374
const TScanProps &scanProps = TScanProps());

csdiff-core.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,17 @@ bool /* anyError */ diffScans(
5454
Parser pOld(strOld, fnOld, silent);
5555
Parser pNew(strNew, fnNew, silent);
5656

57+
// propagate scan properties if available
58+
TScanProps props = pNew.getScanProps();
59+
mergeScanProps(props, pOld.getScanProps());
60+
5761
// decide which format use for the output
5862
if (format == FF_AUTO)
5963
format = pNew.inputFormat();
6064

6165
// create the appropriate writer
62-
boost::shared_ptr<AbstractWriter> writer;
63-
if (format == FF_JSON)
64-
writer.reset(new JsonWriter(strDst));
65-
else
66-
writer.reset(new CovWriter(strDst, cm));
67-
68-
// propagate scan properties if available
69-
TScanProps props = pNew.getScanProps();
70-
mergeScanProps(props, pOld.getScanProps());
71-
writer->setScanProps(props);
66+
typedef boost::shared_ptr<AbstractWriter> TWriterPtr;
67+
TWriterPtr writer(createWriter(strDst, format, cm, props));
7268

7369
// read old
7470
DefLookup stor(/* TODO: document this side effect */ showInternal);

csdiff.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ int main(int argc, char *argv[])
4949
("quiet,q", "do not report any parsing errors")
5050
("coverity-output,c", "write the result in Coverity format")
5151
("json-output,j", "write the result in JSON format")
52+
("html-output", "write the result in HTML format")
5253
("file-rename,s", po::value<TStringList>(),
5354
"account the file base-name change, [OLD,NEW] (*testing*)");
5455

@@ -91,9 +92,10 @@ int main(int argc, char *argv[])
9192

9293
const bool forceCov = !!vm.count("coverity-output");
9394
const bool forceJson = !!vm.count("json-output");
94-
if (forceCov && forceJson) {
95+
const bool useHtml = !!vm.count("html-output");
96+
if (1 < static_cast<int>(forceCov) + forceJson + useHtml) {
9597
std::cerr << name << ": error: options --coverity-output(-c) "
96-
"and --json-output(-j) are mutually exclusive\n\n";
98+
"--json-output(-j), and --html-output are mutually exclusive\n\n";
9799
return 1;
98100
}
99101

@@ -102,6 +104,8 @@ int main(int argc, char *argv[])
102104
format = FF_COVERITY;
103105
else if (forceJson)
104106
format = FF_JSON;
107+
else if (useHtml)
108+
format = FF_HTML;
105109
else
106110
format = FF_AUTO;
107111

cssort.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class GenericSort: public AbstractWriter {
4949
std::sort(cont_.begin(), cont_.end());
5050

5151
// use the same output format is the input format
52-
AbstractWriter *writer = createWriter(this->inputFormat(), cm_);
53-
writer->setScanProps(scanProps_);
52+
AbstractWriter *writer =
53+
createWriter(std::cout, this->inputFormat(), cm_, scanProps_);
5454

5555
// write the data
5656
BOOST_FOREACH(const Defect &def, cont_)

0 commit comments

Comments
 (0)