Repository: Konstantin8105/c4go
Pull request #383 (2019-04-03 10:41:59)

scripts: add more scripts

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/383?src=pr&el=h1) Report
> Merging [#383](https://codecov.io/gh/Konstantin8105/c4go/pull/383?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/336c3d2b1f78d492e9cbebe636d8030de57f7f82?src=pr&el=desc) will **decrease** coverage by `0.15%`.
> The diff coverage is `0%`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/383/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/383?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #383      +/-   ##
==========================================
- Coverage   85.94%   85.78%   -0.16%     
==========================================
  Files         188      188              
  Lines       10949    10955       +6     
==========================================
- Hits         9410     9398      -12     
- Misses       1099     1110      +11     
- Partials      440      447       +7
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/383?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [noarch/fcntl.go](https://codecov.io/gh/Konstantin8105/c4go/pull/383/diff?src=pr&el=tree#diff-bm9hcmNoL2ZjbnRsLmdv) | `0% <0%> (ø)` | :arrow_up: |
| [noarch/unistd.go](https://codecov.io/gh/Konstantin8105/c4go/pull/383/diff?src=pr&el=tree#diff-bm9hcmNoL3VuaXN0ZC5nbw==) | `0% <0%> (ø)` | :arrow_up: |
| [transpiler/bind.go](https://codecov.io/gh/Konstantin8105/c4go/pull/383/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9iaW5kLmdv) | `67.59% <0%> (-2.93%)` | :arrow_down: |
| [types/resolve.go](https://codecov.io/gh/Konstantin8105/c4go/pull/383/diff?src=pr&el=tree#diff-dHlwZXMvcmVzb2x2ZS5nbw==) | `73.7% <0%> (-1.6%)` | :arrow_down: |
| [transpiler/binary.go](https://codecov.io/gh/Konstantin8105/c4go/pull/383/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9iaW5hcnkuZ28=) | `68.33% <0%> (-1.26%)` | :arrow_down: |
| [types/cast.go](https://codecov.io/gh/Konstantin8105/c4go/pull/383/diff?src=pr&el=tree#diff-dHlwZXMvY2FzdC5nbw==) | `69.4% <0%> (-1.12%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/383?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/383?src=pr&el=footer). Last update [336c3d2...0752ab8](https://codecov.io/gh/Konstantin8105/c4go/pull/383?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/noarch/fcntl.go b/noarch/fcntl.go
index 991c757..69281e1 100644
--- a/noarch/fcntl.go
+++ b/noarch/fcntl.go
@@ -1,14 +1,14 @@
 package noarch
 
-import "golang.org/x/sys/unix"
+import "syscall"
 
-type Flock = unix.Flock_t
+type Flock = syscall.Flock_t
 
 func Open(pathname []byte, flags int32, mode ...int32) int32 {
 	if len(mode) == 0 {
 		mode = append(mode, 644)
 	}
-	fd, err := unix.Open(CStringToString(pathname), int(flags), uint32(mode[0]))
+	fd, err := syscall.Open(CStringToString(pathname), int(flags), uint32(mode[0]))
 	if err != nil {
 		return -1
 	}
diff --git a/noarch/sys_resource.go b/noarch/sys_resource.go
index 662aef2..eb2bc1f 100644
--- a/noarch/sys_resource.go
+++ b/noarch/sys_resource.go
@@ -1,5 +1,5 @@
 package noarch
 
-import "golang.org/x/sys/unix"
+import "syscall"
 
-type Rusage = unix.Rusage
+type Rusage = syscall.Rusage
diff --git a/noarch/unistd.go b/noarch/unistd.go
index 7eb91cc..5fc852a 100644
--- a/noarch/unistd.go
+++ b/noarch/unistd.go
@@ -5,10 +5,11 @@ import (
 	"os"
 
 	"golang.org/x/sys/unix"
+	"syscall"
 )
 
 func Isatty(fd int32) int32 {
-	_, err := unix.IoctlGetTermios(int(fd), unix.TCGETS)
+	_, err := unix.IoctlGetTermios(int(fd), syscall.TCGETS)
 	// TODO need test
 	if err != nil {
 		return 0
@@ -17,7 +18,7 @@ func Isatty(fd int32) int32 {
 }
 
 func CloseOnExec(c int32) {
-	unix.CloseOnExec(int(c))
+	syscall.CloseOnExec(int(c))
 }
 
 func Pipe(p []int32) int32 {
@@ -25,7 +26,7 @@ func Pipe(p []int32) int32 {
 	for i := range p {
 		pi[i] = int(p[i])
 	}
-	err := unix.Pipe(pi)
+	err := syscall.Pipe(pi)
 	if err != nil {
 		fmt.Fprintf(os.Stderr, "%v", err)
 		return -1
@@ -37,7 +38,7 @@ func Pipe(p []int32) int32 {
 }
 
 func Read(fd int32, p []byte, num uint) SsizeT {
-	n, err := unix.Read(int(fd), p)
+	n, err := syscall.Read(int(fd), p)
 	if err != nil {
 		return SsizeT(-1)
 	}
@@ -45,7 +46,7 @@ func Read(fd int32, p []byte, num uint) SsizeT {
 }
 
 func Write(fd int32, p []byte, num uint) SsizeT {
-	n, err := unix.Write(int(fd), p)
+	n, err := syscall.Write(int(fd), p)
 	if err != nil {
 		return SsizeT(-1)
 	}
@@ -55,7 +56,7 @@ func Write(fd int32, p []byte, num uint) SsizeT {
 type SsizeT int32
 
 func Ftruncate(fd int32, length int64) int32 {
-	err := unix.Ftruncate(int(fd), length)
+	err := syscall.Ftruncate(int(fd), length)
 	if err != nil {
 		return -1
 	}
diff --git a/scripts/kilo.sh b/scripts/kilo.sh
new file mode 100755
index 0000000..7c0b90c
--- /dev/null
+++ b/scripts/kilo.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+set -e
+
+go build
+
+mkdir -p ./testdata/
+
+# prepare variables
+	export C4GO_DIR=$GOPATH/src/github.com/Konstantin8105/c4go
+	export C4GO=$C4GO_DIR/c4go
+	export GIT_SOURCE="https://github.com/antirez/kilo.git"
+	export NAME="kilo"
+	export TEMP_FOLDER="./testdata/$NAME"
+	export GO_FILE="$TEMP_FOLDER/$NAME.go"
+	export GO_APP="$TEMP_FOLDER/$NAME.app"
+
+# prepare C code
+    if [ ! -d $TEMP_FOLDER ]; then
+		mkdir -p $TEMP_FOLDER
+		git clone $GIT_SOURCE $TEMP_FOLDER
+	fi
+
+# remove go files from last transpilation
+	echo "***** remove go files"
+	rm -f $TEMP_FOLDER/*.go
+	rm -f $TEMP_FOLDER/*.app
+
+# transpilation of all projects
+	echo "Transpile to $GO_FILE"
+	$C4GO transpile                         \
+		-o="$GO_FILE"                       \
+		$TEMP_FOLDER/*.c
+
+# show warnings comments in Go source
+	echo "Calculate warnings in file: $GO_FILE"
+	WARNINGS=`cat $GO_FILE | grep "^// Warning" | sort | uniq | wc -l`
+	echo "		After transpiling : $WARNINGS warnings."
+
+# show other warnings
+	# show amount error from `go build`:
+		echo "Build to $GO_APP file"
+		WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | wc -l`
+		echo "		Go build : $WARNINGS_GO warnings"
+	# amount unsafe
+		UNSAFE=`cat $GO_FILE | grep "unsafe\." | wc -l`
+		echo "		Unsafe   : $UNSAFE"
+
+
+# Arguments menu
+echo "    -s for show detail of Go build errors"
+if [ "$1" == "-s" ]; then
+	# show go build warnings	
+		# c4go warnings
+			cat $GO_FILE | grep "^// Warning" | sort | uniq
+		# show amount error from `go build`:
+			go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1
+fi
diff --git a/scripts/neatmail.sh b/scripts/neatmail.sh
index b2b4e29..a56423c 100755
--- a/scripts/neatmail.sh
+++ b/scripts/neatmail.sh
@@ -32,6 +32,7 @@ mkdir -p ./testdata/
 # transpilation of all projects
 	echo "Transpile to $GO_FILE"
 	$C4GO transpile                         \
+		-s                                  \
 		-o="$GO_FILE"                       \
 		$TEMP_FOLDER/*.c
 
diff --git a/scripts/neatmkfn.sh b/scripts/neatmkfn.sh
index e2e4f1f..830bef9 100755
--- a/scripts/neatmkfn.sh
+++ b/scripts/neatmkfn.sh
@@ -30,6 +30,7 @@ mkdir -p ./testdata/
 # transpilation of all projects
 	echo "Transpile to $GO_FILE"
 	$C4GO transpile                         \
+		-s                                  \
 		-clang-flag="-DTROFFFDIR=\"MMM\""	\
 		-clang-flag="-DTROFFMDIR=\"WWW\""	\
 		-o="$GO_FILE"                       \
diff --git a/scripts/neatvi.sh b/scripts/neatvi.sh
index e8971d6..80737a6 100755
--- a/scripts/neatvi.sh
+++ b/scripts/neatvi.sh
@@ -33,7 +33,6 @@ mkdir -p ./testdata/
 # transpilation of all projects
 	echo "Transpile to $GO_FILE"
 	$C4GO transpile                         \
-		-s									\
 		-clang-flag="-DTROFFFDIR=\"MMM\""	\
 		-clang-flag="-DTROFFMDIR=\"WWW\""	\
 		-o="$GO_FILE"                       \
diff --git a/scripts/scripts.sh b/scripts/scripts.sh
index 7f1628d..ed1bfde 100755
--- a/scripts/scripts.sh
+++ b/scripts/scripts.sh
@@ -18,6 +18,9 @@ echo "" >> $OUTPUT_FILE
 ./scripts/ed.sh			2>&1 | grep -E 'warning|unsafe|Unsafe' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
+./scripts/kilo.sh			2>&1 | grep -E 'warning|unsafe|Unsafe' | tee -a $OUTPUT_FILE
+echo "" >> $OUTPUT_FILE
+
 ./scripts/minmad.sh			2>&1 | grep -E 'warning|unsafe|Unsafe' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
@@ -42,6 +45,12 @@ echo "" >> $OUTPUT_FILE
 ./scripts/neatvi.sh		2>&1 | grep -E 'warning|unsafe|Unsafe' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
+./scripts/triangle.sh		2>&1 | grep -E 'warning|unsafe|Unsafe' | tee -a $OUTPUT_FILE
+echo "" >> $OUTPUT_FILE
+
+./scripts/sqlite.sh		2>&1 | grep -E 'warning|unsafe|Unsafe' | tee -a $OUTPUT_FILE
+echo "" >> $OUTPUT_FILE
+
 ./scripts/vorbis.sh		2>&1 | grep -E 'warning|unsafe|Unsafe' | tee -a $OUTPUT_FILE
 echo "" >> $OUTPUT_FILE
 
diff --git a/scripts/scripts.txt b/scripts/scripts.txt
index 51d0976..d6d506e 100644
--- a/scripts/scripts.txt
+++ b/scripts/scripts.txt
@@ -1,17 +1,22 @@
 
 Calculate warnings : ./testdata/9wm
-		After transpiling : 4 warnings.
-		Go build : 4 warnings
-		Unsafe   : 407
+		After transpiling : 2 warnings.
+		Go build : 3 warnings
+		Unsafe   : 409
 
 Calculate warnings : ./testdata/ed
 		After transpiling : 1 warnings.
 		Go build : 2 warnings
 		Unsafe   : 170
 
+Calculate warnings in file: ./testdata/kilo/kilo.go
+		After transpiling : 0 warnings.
+		Go build : 0 warnings
+		Unsafe   : 17
+
 Calculate warnings in file: ./testdata/minmad/minmad.go
-		After transpiling : 66 warnings.
-		Go build : 2 warnings
+		After transpiling : 65 warnings.
+		Go build : 3 warnings
 		Unsafe   : 17
 
 Calculate warnings in file: ./testdata/neateqn/neateqn.go
@@ -20,14 +25,14 @@ Calculate warnings in file: ./testdata/neateqn/neateqn.go
 		Unsafe   : 22
 
 Calculate warnings in file: ./testdata/neatmkfn/neatmkfn.go
-		After transpiling : 557 warnings.
-		Go build : 72 warnings
-		Unsafe   : 44
+		After transpiling : 7 warnings.
+		Go build : 287 warnings
+		Unsafe   : 135
 
 Calculate warnings in file: ./testdata/neatmail/neatmail.go
-		After transpiling : 35 warnings.
+		After transpiling : 5 warnings.
 		Go build : 2 warnings
-		Unsafe   : 175
+		Unsafe   : 248
 
 Calculate warnings in file: ./testdata/neatpost/neatpost.go
 		After transpiling : 0 warnings.
@@ -41,16 +46,26 @@ Calculate warnings in file: ./testdata/neatrefer/neatrefer.go
 
 Calculate warnings in file: ./testdata/neatroff/neatroff.go
 		After transpiling : 1 warnings.
-		Go build : 40 warnings
+		Go build : 38 warnings
 		Unsafe   : 254
 
 Calculate warnings in file: ./testdata/neatvi/neatvi.go
+		After transpiling : 33 warnings.
+		Go build : 3 warnings
+		Unsafe   : 130
+
+Calculate warnings in file: ./testdata/triangle/triangle.go
 		After transpiling : 2 warnings.
-		Go build : 2 warnings
-		Unsafe   : 210
+		Go build : 589 warnings
+		Unsafe   : 1411
+
+Calculate warnings in file: ./testdata/SQLITE/sqlite.go
+		After transpiling : 2 warnings.
+		Go build : 1 warnings
+		Unsafe   : 2599
 
 Calculate warnings in file: testdata/vorbis/vorbis.go
 		After transpiling : 4 warnings.
-		Go build : 21 warnings
+		Go build : 25 warnings
 		Unsafe   : 255
 
diff --git a/scripts/sqlite.sh b/scripts/sqlite.sh
index a106e9e..69d2239 100755
--- a/scripts/sqlite.sh
+++ b/scripts/sqlite.sh
@@ -39,15 +39,18 @@ $C4GO transpile  -s                                          \
 # go tool pprof ./testdata/cpu.out
 
 # Show amount "Warning":
-SQLITE_WARNINGS=`cat $SQLITE_TEMP_FOLDER/sqlite.go | grep "^// Warning" | sort | uniq | wc -l`
-echo "After transpiling shell.c and sqlite3.c together, have summary: $SQLITE_WARNINGS warnings."
+export GO_FILE="$SQLITE_TEMP_FOLDER/sqlite.go"
+echo "Calculate warnings in file: $GO_FILE"
+
+SQLITE_WARNINGS=`cat $GO_FILE | grep "^// Warning" | sort | uniq | wc -l`
+echo "		After transpiling : $SQLITE_WARNINGS warnings."
 
 # Show amount error from `go build`:
 SQLITE_WARNINGS_GO=`go build -o $SQLITE_TEMP_FOLDER/sqlite.app $SQLITE_TEMP_FOLDER/sqlite.go -gcflags="-e" 2>&1 | wc -l`
-echo "In file sqlite.go summary : $SQLITE_WARNINGS_GO warnings in go build."
+echo "		Go build : $SQLITE_WARNINGS_GO warnings"
 
 SQLITE_UNSAFE=`cat $SQLITE_TEMP_FOLDER/sqlite.go | grep "unsafe\." | wc -l`
-echo "Amount unsafe package using: $SQLITE_UNSAFE"
+echo "		Unsafe   : $SQLITE_UNSAFE"
 
 # Arguments menu
 echo "    -s for show detail of Go build errors"
diff --git a/scripts/triangle.sh b/scripts/triangle.sh
new file mode 100755
index 0000000..849e781
--- /dev/null
+++ b/scripts/triangle.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+set -e
+
+go build
+
+mkdir -p ./testdata/
+
+# prepare variables
+	export C4GO_DIR=$GOPATH/src/github.com/Konstantin8105/c4go
+	export C4GO=$C4GO_DIR/c4go
+	export NAME="triangle"
+	export TEMP_FOLDER="./testdata/$NAME"
+	export GO_FILE="$TEMP_FOLDER/$NAME.go"
+	export GO_APP="$TEMP_FOLDER/$NAME.app"
+
+# prepare C code
+    if [ ! -d $TEMP_FOLDER ]; then
+		mkdir -p $TEMP_FOLDER
+   	 	curl http://www.netlib.org/voronoi/triangle.zip > $TEMP_FOLDER/$NAME.zip
+    	unzip $TEMP_FOLDER/$NAME.zip -d $TEMP_FOLDER
+	fi
+
+# remove go files from last transpilation
+	echo "***** remove go files"
+	rm -f $TEMP_FOLDER/*.go
+	rm -f $TEMP_FOLDER/*.app
+
+# transpilation of all projects
+	echo "Transpile to $GO_FILE"
+	$C4GO transpile                         \
+		-s									\
+		-o="$GO_FILE"                       \
+		$TEMP_FOLDER/triangle.c
+
+# show warnings comments in Go source
+	echo "Calculate warnings in file: $GO_FILE"
+	WARNINGS=`cat $GO_FILE | grep "^// Warning" | sort | uniq | wc -l`
+	echo "		After transpiling : $WARNINGS warnings."
+
+# show other warnings
+	# show amount error from `go build`:
+		echo "Build to $GO_APP file"
+		WARNINGS_GO=`go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1 | wc -l`
+		echo "		Go build : $WARNINGS_GO warnings"
+	# amount unsafe
+		UNSAFE=`cat $GO_FILE | grep "unsafe\." | wc -l`
+		echo "		Unsafe   : $UNSAFE"
+
+
+# Arguments menu
+echo "    -s for show detail of Go build errors"
+if [ "$1" == "-s" ]; then
+	# show go build warnings	
+		# c4go warnings
+			cat $GO_FILE | grep "^// Warning" | sort | uniq
+		# show amount error from `go build`:
+			go build -o $GO_APP -gcflags="-e" $GO_FILE 2>&1
+fi
+
diff --git a/transpiler/bind.go b/transpiler/bind.go
index b8ed24d..8183695 100644
--- a/transpiler/bind.go
+++ b/transpiler/bind.go
@@ -84,6 +84,11 @@ func getBindFunction(p *program.Program, d program.DefinitionFunction) (code str
 	var fl goast.FieldList
 	var argResolvedType []string
 	for i := range d.ArgumentTypes {
+		if i == len(d.ArgumentTypes)-1 && d.ArgumentTypes[i] == "..." {
+			argResolvedType[len(argResolvedType)-1] =
+				"..." + argResolvedType[len(argResolvedType)-1]
+			continue
+		}
 		resolveType, err := types.ResolveType(p, d.ArgumentTypes[i])
 		if err != nil {
 			return "", fmt.Errorf("cannot generate argument binding function `%s`: %v", d.Name, err)
@@ -239,7 +244,9 @@ func ResolveCgoType(p *program.Program, goType string, expr goast.Expr) (a goast
 
 	t := goType
 
-	if strings.HasPrefix(goType, "[") {
+	if strings.HasPrefix(goType, "[][]") {
+		t = "interface{}"
+	} else if strings.HasPrefix(goType, "[") {
 		// []int  -> * _Ctype_int
 		t = goType[2:]
 		var ok bool
@@ -318,7 +325,7 @@ func bindFromCtoGo(p *program.Program, cType string, goType string, expr goast.E
 		goType = "C4GO_UNDEFINE_GO_TYPE"
 	}
 
-	if cType == "" {
+	if cType == "" || cType == "void" {
 		stmts = append(stmts, &goast.ReturnStmt{Results: []goast.Expr{expr}})
 		return
 	}


Test patch:
diff --git a/other_test.go b/other_test.go
index f88f7c1..62286b0 100644
--- a/other_test.go
+++ b/other_test.go
@@ -384,67 +384,6 @@ func TestCsparse(t *testing.T) {
 	}
 }
 
-func TestTriangle(t *testing.T) {
-	folder := "./testdata/git-source/triangle/"
-
-	// Create build folder
-	if _, err := os.Stat(folder); os.IsNotExist(err) {
-		err = os.MkdirAll(folder, os.ModePerm)
-		if err != nil {
-			t.Fatalf("Cannot create folder %v . %v", folder, err)
-		}
-
-		// download file
-		t.Logf("Download file")
-		fileUrl := "http://www.netlib.org/voronoi/triangle.zip"
-		err := downloadFile(folder+"triangle.zip", fileUrl)
-		if err != nil {
-			t.Logf("Cannot download : %v", err)
-			return
-		}
-
-		// extract zip
-		t.Logf("Extract")
-		_, err = unzip(folder+"triangle.zip", folder)
-		if err != nil {
-			t.Fatalf("Cannot unzip : %v", err)
-		}
-	}
-
-	args := DefaultProgramArgs()
-	args.inputFiles = []string{
-		folder + "triangle.c",
-	}
-	args.clangFlags = []string{}
-	args.outputFile = folder + "main.go"
-	args.ast = false
-	args.verbose = false
-
-	if err := Start(args); err != nil {
-		t.Fatalf("Cannot transpile `%v`: %v", args, err)
-	}
-
-	// print logs
-	ls, err := getLogs(folder + "main.go")
-	if err != nil {
-		t.Fatalf("Cannot show logs: %v", err)
-	}
-	for _, l := range ls {
-		t.Log(l)
-	}
-
-	cmd := exec.Command("go", "build", "-o", folder+"triangle", "-gcflags", "-e",
-		args.outputFile)
-	var stdout, stderr bytes.Buffer
-	cmd.Stdout = &stdout
-	cmd.Stderr = &stderr
-	err = cmd.Run()
-	if err != nil {
-		parseError(t, stderr.String())
-		t.Logf("cmd.Run() failed with %s : %v\n", err, stderr.String())
-	}
-}
-
 func parseError(t *testing.T, str string) {
 	// Example:
 	// testdata/git-source/triangle/main.go:2478:41: invalid operation: (operator & not defined on slice)