1

I have a code snippet int t.c like

val =  (val1 << 8) | (val >> 8 );
val =  (val2 << 16) | (val >> 8 );
val =  (val3 << 32) | (val >> 8 );
val =  (val << 8);

I will get ouput if I grep as grep -nhE "(<<.*|).*(>>)" t.c

1:val =  (val1 << 8) | (val >> 8 );
2:val =  (val2 << 16) | (val >> 8 );
3:val =  (val3 << 32) | (val >> 8 );

But If search with cppcheck like ./cppcheck --rule="(<<.*|).*(>>)" t.c I will get output

[../test/t.c:1]: (style) found ' val = ( val1 << 8 ) | ( val >> 8 ) ; val = ( val2 << 16 ) | ( val >> 8 ) ; val = ( val3 << 32 ) | ( val >>'

ie the whole matching lines together from first matching is displaying. I want the result as in grep command.

Please help

dday
  • 47
  • 4
  • your rule is overly complicated. due to the alternation operator `|` you are effective searching for `>>`only. combining the simpler expression with vs-compatible output, use `./cppcheck --template=vs --rule=">>" t.c`. you may define your own template for formatting the output, see [chapter 5 of the manual](http://cppcheck.sourceforge.net/manual.pdf). – collapsar Jul 10 '13 at 10:01

1 Answers1

0

Try following command (escaped |):

cppcheck --rule="<<.*?\|.*?>>" t.c

The output is not exactly same as that of grep.

falsetru
  • 357,413
  • 63
  • 732
  • 636