Skip to content

Commit e9a3797

Browse files
committed
csgrep --drop-scan-props: do not propagate scan properties
This is mainly useful in combination with `--mode=json`.
1 parent 89edee0 commit e9a3797

5 files changed

+3821
-0
lines changed

src/csgrep.cc

+30
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,32 @@ class PathStripper: public GenericAbstractFilter {
348348
const size_t prefSize_;
349349
};
350350

351+
class DropScanProps: public GenericAbstractFilter {
352+
public:
353+
DropScanProps(AbstractWriter *agent):
354+
GenericAbstractFilter(agent)
355+
{
356+
}
357+
358+
/// ignore any given scan properties
359+
virtual void setScanProps(const TScanProps &) {
360+
}
361+
362+
/// always return empty scan properties
363+
virtual const TScanProps& getScanProps() const {
364+
return emp_;
365+
}
366+
367+
protected:
368+
/// trivial pass-through
369+
virtual void handleDef(const Defect &def) {
370+
agent_->handleDef(def);
371+
}
372+
373+
private:
374+
const TScanProps emp_;
375+
};
376+
351377
class DuplicateFilter: public AbstractFilter {
352378
public:
353379
DuplicateFilter(AbstractWriter *agent):
@@ -552,6 +578,7 @@ int main(int argc, char *argv[])
552578
("annot", po::value<string>(), "defect matches if its annotation matches the given regex")
553579
("src-annot", po::value<string>(), "defect matches if an annotation in the _source_ file matches the given regex")
554580

581+
("drop-scan-props", "do not propagate scan properties")
555582
("embed-context,U", po::value<int>(), "embed a number of lines of context from the source file for the key event")
556583
("prune-events", po::value<int>(), "event is preserved if its verbosity level is below the given number")
557584
("remove-duplicates,u", "remove defects that are not unique by their key event")
@@ -631,6 +658,9 @@ int main(int argc, char *argv[])
631658
// an error message already printed out
632659
return 1;
633660

661+
if (vm.count("drop-scan-props"))
662+
eng = new DropScanProps(eng);
663+
634664
if (vm.count("remove-duplicates"))
635665
eng = new DuplicateFilter(eng);
636666

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--mode=json --drop-scan-props

0 commit comments

Comments
 (0)