The logic is simple. If the pattern is "-x" , we must print all lines that do not contain the pattern.
For this pattern, except is 1 .
Thus, the lines containing the pattern satisfy the condition
strstr(line,*argv)!=NULL
then this condition will always be 1 if the string contains a pattern.
Thus, if except is 1 and the condition strstr(line,*argv)!=NULL is 1, we must skip the pattern.
Otherwise, if the condition strstr(line,*argv)!=NULL not 1, that is, if the pattern is not found, the if statement
if( (strstr(line,*argv)!=NULL) != except)
returns true, and its compound statement is executed.
On the other hand, if except is 0 , then to ensure that the condition in the if expression evaluates to true, we need the condition strstr(line,*argv)!=NULL to be 1.
In fact, you can rewrite the if statement
if( (strstr(line,*argv)!=NULL) != except)
in the following way
if( ( ( strstr(line,*argv) != NULL ) == 1 && except == 0 ) || ( ( strstr(line,*argv) != NULL ) == 0 && except == 1 ) )
In short, the if statement does the job if either
1 and 0
or
0 and 1
If either
1 and 1
or
0 and 0
then the if statement will not be executed.
Here 1 and 0 are the results of evaluating two subexpressions in the if expression.