Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return values for other modes. Functions for use in external tools. #8

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,37 @@ To install the par command-line application:
go get -u github.com/akalin/gopar/cmd/par
```

## License
or run

```
go build cmd/par/main.go
```

after a checkout of this repository.

### Usage

Create, verify and repair parity files. Run `par --help` for an overview of all options.

### libgopar

Use gopar in your own Go code. Feed a string array with the commandline arguments to Gopar():

```
import "github.com/akalin/gopar/libgopar"
my_args := []strings
libgopar.Gopar(my_args)
```

Alternatively, compile a C library:

```
go build -buildmode=c-shared -o libgopar.so ./libgopar/C.go
```

This library exposes the `gopar()` function.

### License

Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
33 changes: 33 additions & 0 deletions cmd/par/C.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"C"
"unsafe"
"fmt"

"github.com/akalin/gopar/libgopar"
)

//export gopar
func gopar(argc_ C.int, argv_ **C.char) int {
retval := 7
defer func() {
if r := recover(); r != nil {
// libgopar only panics with strings currently
fmt.Println("libgopar panicked! ", r)
}
}()

length := int(argc_)
cStrings := (*[1 << 28]*C.char)(unsafe.Pointer(argv_))[:length:length]

args_ := make([]string, length+1)
args_[0] = "libgopar"
for i, cString := range cStrings {
args_[i+1] = C.GoString(cString)
}
retval = libgopar.Par(args_,true)
return retval
}

func main(){}
Loading