11#! /bin/bash
22# Script Used by generate_and_run_more_tests.sh
33
4+ # "gsed" is a GNU compatible version of "sed" on MacOS
5+ SED_CMD=$( command -v gsed || command -v sed)
6+
47DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
58
69set -e
@@ -19,85 +22,85 @@ $CPPCHECK -q --template=cppcheck1 . 2> 1.txt
1922
2023
2124# (!x) => (x==0)
22- sed -ri ' s/([(&][ ]*)\!([a-z]+)([ ]*[&)])/\1\2==0\3/' * .cpp
25+ $SED_CMD -ri ' s/([(&][ ]*)\!([a-z]+)([ ]*[&)])/\1\2==0\3/' * .cpp
2326$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
2427
2528# (x==0) => (0==x)
26- sed -ri ' s/([(&][ ]*)([a-z]+)[ ]*==[ ]*0([ ]*[&)])/\10==\2\3/' * .cpp
29+ $SED_CMD -ri ' s/([(&][ ]*)([a-z]+)[ ]*==[ ]*0([ ]*[&)])/\10==\2\3/' * .cpp
2730$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
2831
2932# (0==x) => (!x)
30- sed -ri ' s/([(&][ ]*)0[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1!\2\3/' * .cpp
33+ $SED_CMD -ri ' s/([(&][ ]*)0[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1!\2\3/' * .cpp
3134$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
3235
3336
3437
3538
3639# if (x) => (x!=0)
37- sed -ri ' s/(if[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' * .cpp
40+ $SED_CMD -ri ' s/(if[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' * .cpp
3841$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
3942
4043# while (x) => (x!=0)
41- sed -ri ' s/(while[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' * .cpp
44+ $SED_CMD -ri ' s/(while[ ]*\([ ]*[a-z]+)([ ]*[&)])/\1!=0\2/' * .cpp
4245$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
4346
4447# (x!=0) => (0!=x)
45- sed -ri ' s/([(&][ ]*)([a-z]+)[ ]*!=[ ]*0([ ]*[&)])/\10!=\2\3/' * .cpp
48+ $SED_CMD -ri ' s/([(&][ ]*)([a-z]+)[ ]*!=[ ]*0([ ]*[&)])/\10!=\2\3/' * .cpp
4649$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
4750
4851# (0!=x) => (x)
49- sed -ri ' s/([(&][ ]*)0[ ]*!=[ ]*([a-z]+[ ]*[&)])/\1\2/' * .cpp
52+ $SED_CMD -ri ' s/([(&][ ]*)0[ ]*!=[ ]*([a-z]+[ ]*[&)])/\1\2/' * .cpp
5053$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
5154
5255
5356# (x < 0) => (0 > x)
54- sed -ri ' s/([(&][ ]*)([a-z]+)[ ]*<[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>\2\4/' * .cpp
57+ $SED_CMD -ri ' s/([(&][ ]*)([a-z]+)[ ]*<[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>\2\4/' * .cpp
5558$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
5659
5760# (x <= 0) => (0 >= x)
58- sed -ri ' s/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' * .cpp
61+ $SED_CMD -ri ' s/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' * .cpp
5962$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
6063
6164# (x > 0) => (0 < x)
62- sed -ri ' s/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' * .cpp
65+ $SED_CMD -ri ' s/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' * .cpp
6366$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
6467
6568# (x >= 0) => (0 <= x)
66- sed -ri ' s/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' * .cpp
69+ $SED_CMD -ri ' s/([(&][ ]*)([a-z]+)[ ]*<=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3>=\2\4/' * .cpp
6770$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
6871
6972# (x == 123) => (123 == x)
70- sed -ri ' s/([(&][ ]*)([a-z]+)[ ]*==[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3==\2\4/' * .cpp
73+ $SED_CMD -ri ' s/([(&][ ]*)([a-z]+)[ ]*==[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3==\2\4/' * .cpp
7174$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
7275
7376# (x != 123) => (123 != x)
74- sed -ri ' s/([(&][ ]*)([a-z]+)[ ]*\!=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3!=\2\4/' * .cpp
77+ $SED_CMD -ri ' s/([(&][ ]*)([a-z]+)[ ]*\!=[ ]*(\-?[0-9]+)([ ]*[&)])/\1\3!=\2\4/' * .cpp
7578$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
7679
7780
7881
7982# (0 < x) => (x > 0)
80- sed -ri ' s/([(&][ ]*)(\-?[0-9]+)[ ]*<[ ]*([a-z]+)([ ]*[&)])/\1\3>\2\4/' * .cpp
83+ $SED_CMD -ri ' s/([(&][ ]*)(\-?[0-9]+)[ ]*<[ ]*([a-z]+)([ ]*[&)])/\1\3>\2\4/' * .cpp
8184$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
8285
8386# (0 <= x) => (x >= 0)
84- sed -ri ' s/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' * .cpp
87+ $SED_CMD -ri ' s/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' * .cpp
8588$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
8689
8790# (0 > x) => (x < 0)
88- sed -ri ' s/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' * .cpp
91+ $SED_CMD -ri ' s/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' * .cpp
8992$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
9093
9194# (0 >= x) => (x <= 0)
92- sed -ri ' s/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' * .cpp
95+ $SED_CMD -ri ' s/([(&][ ]*)(\-?[0-9]+)[ ]*<=[ ]*([a-z]+)([ ]*[&)])/\1\3>=\2\4/' * .cpp
9396$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
9497
9598# (123 == x) => (x == 123)
96- sed -ri ' s/([(&][ ]*)(\-?[0-9]+)[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1\3==\2\4/' * .cpp
99+ $SED_CMD -ri ' s/([(&][ ]*)(\-?[0-9]+)[ ]*==[ ]*([a-z]+)([ ]*[&)])/\1\3==\2\4/' * .cpp
97100$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
98101
99102# (123 != x) => (x <= 123)
100- sed -ri ' s/([(&][ ]*)(\-?[0-9]+)[ ]*\!=[ ]*([a-z]+)([ ]*[&)])/\1\3!=\2\4/' * .cpp
103+ $SED_CMD -ri ' s/([(&][ ]*)(\-?[0-9]+)[ ]*\!=[ ]*([a-z]+)([ ]*[&)])/\1\3!=\2\4/' * .cpp
101104$CPPCHECK -q --template=cppcheck1 . 2> 2.txt && diff 1.txt 2.txt
102105
103106
0 commit comments