github.com/Konstantin8105/c4go@v0.0.0-20240505174241-768bb1c65a51/scripts/triangle.sh (about) 1 #!/bin/bash 2 3 set -e 4 5 go build 6 7 mkdir -p ./testdata/ 8 9 # prepare variables 10 export C4GO_DIR=$GOPATH/src/github.com/Konstantin8105/c4go 11 export C4GO=$C4GO_DIR/c4go 12 export NAME="triangle" 13 export TEMP_FOLDER="./testdata/$NAME" 14 export GO_FILE="$TEMP_FOLDER/$NAME.go" 15 export GO_APP="$TEMP_FOLDER/$NAME.app" 16 17 # prepare C code 18 if [ ! -d $TEMP_FOLDER ]; then 19 mkdir -p $TEMP_FOLDER 20 curl http://www.mirrorservice.org/sites/ftp.netlib.org/voronoi/triangle.zip > $TEMP_FOLDER/$NAME.zip 21 unzip $TEMP_FOLDER/$NAME.zip -d $TEMP_FOLDER 22 fi 23 24 # remove go files from last transpilation 25 echo "***** remove go files" 26 rm -f $TEMP_FOLDER/*.go 27 rm -f $TEMP_FOLDER/*.app 28 29 # transpilation of all projects 30 echo "Transpile to $GO_FILE" 31 $C4GO transpile \ 32 -s \ 33 -o="$GO_FILE" \ 34 $TEMP_FOLDER/triangle.c 35 36 # show warnings comments in Go source 37 echo "Calculate warnings in file: $GO_FILE" 38 WARNINGS=`cat $GO_FILE | grep "^// Warning" | sort | uniq | wc -l` 39 echo " After transpiling : $WARNINGS warnings." 40 41 # show other warnings 42 # show amount error from `go build`: 43 echo "Build to $GO_APP file" 44 WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | wc -l` 45 echo " Go build : $WARNINGS_GO warnings" 46 # amount unsafe 47 UNSAFE=`cat $GO_FILE | grep "unsafe\." | wc -l` 48 echo " Unsafe : $UNSAFE" 49 # amount Go code lines 50 LINES=`wc $GO_FILE` 51 echo "(lines,words,bytes) : $LINES" 52 # defers 53 DEFER=`cat $GO_FILE | grep "defer func" | wc -l` 54 echo "defer func : $DEFER" 55 56 57 # Arguments menu 58 echo " -s for show detail of Go build errors" 59 if [ "$1" == "-s" ]; then 60 # show go build warnings 61 # c4go warnings 62 cat $GO_FILE | grep "^// Warning" | sort | uniq 63 # show amount error from `go build`: 64 go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 65 fi 66