@@ -388,6 +388,54 @@ class DropScanProps: public GenericAbstractFilter {
388388 const TScanProps emp_;
389389};
390390
391+ class ScanPropSetter : public GenericAbstractFilter {
392+ public:
393+ ScanPropSetter (AbstractWriter *agent, const TStringList &propList);
394+
395+ // / override specified scan properties
396+ void setScanProps (const TScanProps &origProps) override ;
397+
398+ private:
399+ // key/val pairs are stored in a vector
400+ using TItem = std::pair<std::string, std::string>;
401+ using TList = std::vector<TItem>;
402+ TList itemList_;
403+ };
404+
405+ ScanPropSetter::ScanPropSetter (
406+ AbstractWriter *agent,
407+ const TStringList &propList):
408+ GenericAbstractFilter(agent)
409+ {
410+ // iterate over the given NAME:VALUE strings
411+ for (const std::string &str : propList) {
412+ // split the string by the first occurrence of ':'
413+ size_t ddAt = str.find (' :' );
414+ if (std::string::npos == ddAt) {
415+ const auto msg = " missing ':' in " + str;
416+ throw std::runtime_error (msg);
417+ }
418+
419+ // store the key/val pair into the vector
420+ itemList_.emplace_back (
421+ /* key */ str.substr (0 , ddAt),
422+ /* val */ str.substr (ddAt + 1 ));
423+ }
424+ }
425+
426+ void ScanPropSetter::setScanProps (const TScanProps &origProps)
427+ {
428+ // we need to copy the given map
429+ TScanProps props = origProps;
430+
431+ // apply specified changes
432+ for (const auto &item : itemList_)
433+ props[item./* key */ first] = item./* val */ second;
434+
435+ // forward the result
436+ agent_->setScanProps (props);
437+ }
438+
391439class DuplicateFilter : public AbstractFilter {
392440 public:
393441 DuplicateFilter (AbstractWriter *agent):
@@ -632,6 +680,7 @@ int main(int argc, char *argv[])
632680 (" embed-context,U" , po::value<int >(), " embed a number of lines of context from the source file for the key event" )
633681 (" prune-events" , po::value<int >(), " event is preserved if its verbosity level is below the given number" )
634682 (" remove-duplicates,u" , " remove defects that are not unique by their key event" )
683+ (" set-scan-prop" , po::value<TStringList>(), " NAME:VALUE pair to override the specified scan property" )
635684 (" strip-path-prefix" , po::value<string>(), " string prefix to strip from path (applied after all filters)" )
636685
637686 (" ignore-case,i" , " ignore case when matching regular expressions" )
@@ -712,6 +761,11 @@ int main(int argc, char *argv[])
712761 " strip-path-prefix" ))
713762 return 1 ;
714763
764+ // insert ScanPropSetter into the chain if requested
765+ if (!chainDecoratorGeneric<ScanPropSetter, TStringList>(&eng, vm,
766+ " set-scan-prop" ))
767+ return 1 ;
768+
715769 // chain all filters
716770 if (!chainFilters (&eng, vm))
717771 // an error message already printed out
0 commit comments