質問

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

役に立ちましたか?

解決

Try following command (escaped |):

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

The output is not exactly same as that of grep.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top