2017-02-07 14:56:41 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-02-08 14:30:14 +01:00
|
|
|
# ARGUMENTS
|
|
|
|
REMOVE_COMMENTS=YES
|
|
|
|
while getopts ":c" opt; do
|
|
|
|
case $opt in
|
|
|
|
c)
|
|
|
|
# keep comments
|
|
|
|
REMOVE_COMMENTS=NO
|
|
|
|
;;
|
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(expr $OPTIND - 1)
|
|
|
|
|
2017-02-07 14:56:41 +01:00
|
|
|
# GNU prefix command for mac os support (gsed, gsplit)
|
|
|
|
GP=
|
|
|
|
if [[ "$OSTYPE" =~ darwin* ]]; then
|
|
|
|
GP=g
|
|
|
|
fi
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2014-02-08 23:26:15 +01:00
|
|
|
for file in $*; do
|
2016-12-04 17:42:12 +01:00
|
|
|
d=${file#*/}
|
|
|
|
d=${d%/*}
|
|
|
|
f=${file##*/}
|
|
|
|
f=${f%.*}
|
2012-09-24 02:28:15 +02:00
|
|
|
|
2017-02-07 14:56:41 +01:00
|
|
|
tempfile=$(${GP}mktemp ${f}XXXX --suffix=.h)
|
2016-12-04 17:42:12 +01:00
|
|
|
|
|
|
|
# Remove comments
|
2017-02-08 14:30:14 +01:00
|
|
|
if [[ "$REMOVE_COMMENTS" =~ YES ]]; then
|
|
|
|
${GP}sed 's/a/aA/g;s/__/aB/g;s/#/aC/g' "src/$d/$f.h" | cpp -E $arg - | ${GP}sed 's/aC/#/g;s/aB/__/g;s/aA/a/g' > $tempfile
|
|
|
|
else
|
|
|
|
cp "src/$d/$f.h" $tempfile
|
|
|
|
fi
|
2016-12-04 17:42:12 +01:00
|
|
|
|
|
|
|
# Remove override keyword
|
2017-02-07 14:56:41 +01:00
|
|
|
${GP}sed -i 's/ override;/;/g' $tempfile
|
2016-12-04 17:42:12 +01:00
|
|
|
|
|
|
|
# Remove preprocessor directives
|
2017-02-07 14:56:41 +01:00
|
|
|
${GP}sed -i '/^#/d' $tempfile
|
2016-12-04 17:42:12 +01:00
|
|
|
|
|
|
|
# Remove CORE_EXPORT etc
|
2017-02-07 14:56:41 +01:00
|
|
|
${GP}sed -i 's/ [A-Z]*_EXPORT//g' $tempfile
|
2016-12-04 17:42:12 +01:00
|
|
|
|
|
|
|
# Remove public keyword from inherited classes
|
2017-02-07 14:56:41 +01:00
|
|
|
${GP}sed -i 's/\(class.*:\) public\(.*\)/\1\2/g' $tempfile
|
2016-12-04 17:42:12 +01:00
|
|
|
|
2017-02-07 16:24:45 +01:00
|
|
|
# Remove Q_OBJECT,ENUMS,PROPERTY
|
|
|
|
${GP}sed -i -r '/^\s*Q_(OBJECT|ENUMS|PROPERTY).*?$/d' $tempfile
|
|
|
|
|
|
|
|
# Remove function definition in header
|
2017-02-27 14:36:15 +01:00
|
|
|
${GP}sed -i -r 's/^(\s*)?(virtual |static )?(inline )?(void|bool|int|double|Q\w+)(\*?)(\s+[^ ]*?\(.*?\)( const)?)\s*\{.*?\}$/\1\2\4\5\6;/g' $tempfile
|
2017-02-07 16:24:45 +01:00
|
|
|
|
2017-02-07 16:35:28 +01:00
|
|
|
# Remove nullptr
|
|
|
|
${GP}sed -i 's/nullptr/0/g' $tempfile
|
|
|
|
|
2017-02-08 14:30:14 +01:00
|
|
|
# Remove forward declarations
|
|
|
|
${GP}sed -i -r '/^\s*class Q\w+;$/d' $tempfile
|
|
|
|
|
2017-02-20 09:01:05 +01:00
|
|
|
# Remove Q_INVOKABLE
|
|
|
|
${GP}sed -i 's/Q_INVOKABLE //g' $tempfile
|
|
|
|
|
2016-12-04 17:42:12 +01:00
|
|
|
vimdiff $tempfile python/$d/$f.sip
|
|
|
|
|
|
|
|
rm $tempfile
|
2014-02-08 23:26:15 +01:00
|
|
|
done
|