#! /bin/bash # 1er arg : file.c # Script dedicated to work on RERS challenge. Takes a C file in # parameter and convert it into a go program that can then be processed # by the Go2Pins tool. filename=$(basename -- "$1") filename="${filename%.*}" echo Converting $filename cat $1 | sed 's/#include //g' | \ sed 's/#include //g' | \ sed 's/#include //g' | \ sed 's/#include //g' | \ sed 's/extern void __VERIFIER_error(int);/void __VERIFIER_error(int n){}/g' | \ sed 's/int input;/int __RERS__;/g' | sed 's/(input !=/(__RERS__ !=/g' | \ sed 's/calculate_output(input);/calculate_output(__RERS__);/g' | \ sed "s/scanf(\"%d\", &input);/__RERS__ = __RERS__ + 1;/g" | \ sed "s/return -2;/break;/g"| sed "s#fprintf#;//fprintf#g" | \ sed "s#printf#;//printf#g">/tmp/$filename.c # Requires C to Go transpiler https://github.com/Konstantin8105/c4go ./c4go transpile /tmp/$filename.c # This last step is mandatory to handle the tranduction of the C instruction # "a ? b : c" which is translated using closure. sed -i 's/int32/int/g' $filename.go