// http://www.netlib.org/blas/dgemm.f func dgemm(transa, transb Transpose, m, n, k int, alpha float64, a []float64, lda int, b []float64, ldb int, beta float64, c []float64, ldc int) { var ( transa_ = C.char(transa) transb_ = C.char(transb) m_ = C.integer(m) n_ = C.integer(n) k_ = C.integer(k) alpha_ = (*C.doublereal)(unsafe.Pointer(&alpha)) a_ *C.doublereal lda_ = C.integer(lda) b_ *C.doublereal ldb_ = C.integer(ldb) beta_ = (*C.doublereal)(unsafe.Pointer(&beta)) c_ *C.doublereal ldc_ = C.integer(ldc) ) if len(a) > 0 { a_ = (*C.doublereal)(unsafe.Pointer(&a[0])) } if len(b) > 0 { b_ = (*C.doublereal)(unsafe.Pointer(&b[0])) } if len(c) > 0 { c_ = (*C.doublereal)(unsafe.Pointer(&c[0])) } C.dgemm_(&transa_, &transb_, &m_, &n_, &k_, alpha_, a_, &lda_, b_, &ldb_, beta_, c_, &ldc_) }
//TODO: implement TT_BYTES and other tokens func convertToken(token ast.Token) (ctoken *C.HParsedToken, govalue *interface{}) { switch v := token.Value.(type) { case nil: return nil, nil case ast.NoneType: ctoken := &C.HParsedToken{ token_type: C.TT_NONE, index: C.size_t(token.ByteOffset), bit_offset: C.char(token.BitOffset), } return ctoken, nil case uint64: ctoken := &C.HParsedToken{ token_type: C.TT_UINT, index: C.size_t(token.ByteOffset), bit_offset: C.char(token.BitOffset), } C.assignUintValue(ctoken, C.uint64_t(v)) return ctoken, nil } // go token ctoken = &C.HParsedToken{ token_type: goHParsedToken, index: C.size_t(token.ByteOffset), bit_offset: C.char(token.BitOffset), } union := (**interface{})(unionPointer(ctoken)) *union = &token.Value return ctoken, &token.Value }
func uploChar(tri Triangle) C.char { switch tri { case UpperTri: return C.char('U') case LowerTri: return C.char('L') default: panic(fmt.Sprintf("invalid uplo value: %v", rune(tri))) } }
func diagChar(diag diagType) C.char { switch diag { case nonUnitDiag: return C.char('N') case unitDiag: return C.char('U') default: panic(fmt.Sprintf("invalid diag value: %v", rune(diag))) } }
func jobzChar(jobz jobzMode) C.char { switch jobz { case values: return C.char('N') case vectors: return C.char('V') default: panic(fmt.Sprintf("invalid jobz value: %v", rune(jobz))) } }
func sideChar(side matSide) C.char { switch side { case left: return C.char('L') case right: return C.char('R') default: panic(fmt.Sprintf("invalid side value: %v", rune(side))) } }
// Needs to be supplied ipiv and work. func zhesvHelper(n, nrhs int, a []complex128, lda int, ipiv []C.integer, b []complex128, ldb int, work []complex128, lwork int) error { var ( uplo_ = C.char(DefaultTri) n_ = C.integer(n) nrhs_ = C.integer(nrhs) a_ = ptrComplex128(a) lda_ = C.integer(lda) ipiv_ = ptrInt(ipiv) b_ = ptrComplex128(b) ldb_ = C.integer(ldb) work_ = ptrComplex128(work) lwork_ = C.integer(lwork) ) var info_ C.integer C.zhesv_(&uplo_, &n_, &nrhs_, a_, &lda_, ipiv_, b_, &ldb_, work_, &lwork_, &info_) info := int(info_) switch { case info < 0: return errInvalidArg(-info) case info > 0: return errSingular(info) default: return nil } }
func fatStrReplace(str string, replacement rune) (string, bool) { cstr := C.CString(str) ok := C.fat_str_replace(cstr, C.char(replacement)) == 1 newStr := C.GoString(cstr) C.free(unsafe.Pointer(cstr)) return newStr, ok }
// Purely exists for the test, as cgo isn't supported inside tests func byteToBufferAdapter(buffer [128]byte) string { var tmp [128]C.char for i, c := range buffer { tmp[i] = C.char(c) } return bufferToString(tmp) }
// Internal helper function, wrapped by several other functions func convertWcharToGoRune(w Wchar) (output rune, err error) { // return if len(input) == 0 if w == 0 { return '\000', nil } // open iconv iconv, errno := C.iconv_open(iconvCharsetUtf8, iconvCharsetWchar) if iconv == nil || errno != nil { return '\000', fmt.Errorf("Could not open iconv instance: %s", errno.Error()) } defer C.iconv_close(iconv) // split Wchar into bytes wcharAsBytes := make([]byte, 4) binary.LittleEndian.PutUint32(wcharAsBytes, uint32(w)) // place the wcharAsBytes into wcharAsCChars // TODO: use unsafe.Pointer here to do the conversion? wcharAsCChars := make([]C.char, 0, 4) for i := 0; i < 4; i++ { wcharAsCChars = append(wcharAsCChars, C.char(wcharAsBytes[i])) } // pointer to the first wcharAsCChars wcharAsCCharsPtr := &wcharAsCChars[0] // calculate buffer size for input bytesLeftInCSize := C.size_t(4) // calculate buffer size for output bytesLeftOutCSize := C.size_t(4) // create output buffer outputChars := make([]C.char, 4) // output buffer pointer for C outputCharsPtr := &outputChars[0] // call iconv for conversion of charsets _, errno = C.iconv(iconv, &wcharAsCCharsPtr, &bytesLeftInCSize, &outputCharsPtr, &bytesLeftOutCSize) if errno != nil { return '\000', errno } // convert outputChars ([]int8, len 4) to Wchar // TODO: can this conversion be done easier by using this: ? // output = *((*rune)(unsafe.Pointer(&outputChars[0]))) runeAsByteAry := make([]byte, 4) runeAsByteAry[0] = byte(outputChars[0]) runeAsByteAry[1] = byte(outputChars[1]) runeAsByteAry[2] = byte(outputChars[2]) runeAsByteAry[3] = byte(outputChars[3]) // combine 4 position byte slice into uint32 and convert to rune. runeAsUint32 := binary.LittleEndian.Uint32(runeAsByteAry) output = rune(runeAsUint32) return output, nil }
func New(path string, n ...int) (*Tbx, error) { if !(xopen.Exists(path) && (xopen.Exists(path+".tbi") || xopen.Exists(path+".csi"))) { return nil, fmt.Errorf("need gz file and .tbi for %s", path) } size := 20 if len(n) > 0 { size = n[0] } t := &Tbx{path: path} cs, mode := C.CString(t.path), C.char('r') defer C.free(unsafe.Pointer(cs)) t.htfs = make(chan *C.htsFile, size) for i := 0; i < cap(t.htfs); i++ { t.htfs <- C.hts_open(cs, &mode) } t.kCache = make(chan C.kstring_t, size*2) for i := 0; i < cap(t.kCache); i++ { t.kCache <- C.kstring_t{} } t.chromCache = make(map[string]C.int) if xopen.Exists(path + ".csi") { csi := C.CString(path + ".csi") defer C.free(unsafe.Pointer(csi)) t.tbx = C.tbx_index_load2(cs, csi) } else { t.tbx = C.tbx_index_load(cs) } runtime.SetFinalizer(t, _close) return t, nil }
func subvolSnapshot(src, dest, name string) error { srcDir, err := openDir(src) if err != nil { return err } defer closeDir(srcDir) destDir, err := openDir(dest) if err != nil { return err } defer closeDir(destDir) var args C.struct_btrfs_ioctl_vol_args_v2 args.fd = C.__s64(getDirFd(srcDir)) for i, c := range []byte(name) { args.name[i] = C.char(c) } _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, getDirFd(destDir), C.BTRFS_IOC_SNAP_CREATE_V2, uintptr(unsafe.Pointer(&args))) if errno != 0 { return fmt.Errorf("Failed to create btrfs snapshot: %v", errno.Error()) } return nil }
func CharacterColor(renderer *sdl.Renderer, x, y int, c byte, color sdl.Color) bool { _x := C.Sint16(x) _y := C.Sint16(y) _c := C.char(c) _color := C.Uint32(gfxColor(color)) return C.characterColor(renderer, _x, _y, _c, _color) == 0 }
func (e *wkbEncoder) encodeEWkb(g *Geometry) ([]byte, error) { srid, _ := g.SRID() if srid > 0 { cGEOSWKBWriter_setIncludeSRID(e.w, C.char(1)) } return encodeWkb(e, g, cGEOSWKBWriter_write) }
func zgesddHelper(m, n int, a []complex128, lda int, s []float64, u []complex128, ldu int, vt []complex128, ldvt int, work []complex128, lwork int, rwork []float64, iwork []C.integer) error { var ( jobz_ = C.char('S') m_ = C.integer(m) n_ = C.integer(n) a_ = ptrComplex128(a) lda_ = C.integer(lda) s_ = ptrFloat64(s) u_ = ptrComplex128(u) ldu_ = C.integer(ldu) vt_ = ptrComplex128(vt) ldvt_ = C.integer(ldvt) work_ = ptrComplex128(work) lwork_ = C.integer(lwork) rwork_ = ptrFloat64(rwork) iwork_ = ptrInt(iwork) ) var info_ C.integer C.zgesdd_(&jobz_, &m_, &n_, a_, &lda_, s_, u_, &ldu_, vt_, &ldvt_, work_, &lwork_, rwork_, iwork_, &info_) info := int(info_) switch { case info < 0: return errInvalidArg(-info) case info > 0: return errFailConverge(info) default: return nil } }
func ffiSubvolumeCreate(path string) error { var args C.struct_btrfs_ioctl_vol_args for i, c := range []byte(filepath.Base(path)) { args.name[i] = C.char(c) } return ffiIoctl(filepath.Dir(path), C.BTRFS_IOC_SUBVOL_CREATE, uintptr(unsafe.Pointer(&args))) }
// strCopy OMIT // fake strncpy so we don't need to allocate a new byte slice // Careful, we're not checking the length of src! func strCopy(dest *[C.MaxTextExtent]C.char, src []byte) { for i, c := range src { dest[i] = C.char(c) } // This is C, we need to terminate the string! dest[len(src)] = 0 }
func arrFromGoString(arr []C.char, src string) { for i, r := range src { if i >= len(arr) { break } arr[i] = C.char(r) } }
// aiString allocates and returns a new aiString, it must later be free'd. func aiString(g string) *C.struct_aiString { s := (*C.struct_aiString)(C.calloc(1, C.size_t(len(g)))) s.length = C.size_t(len(g)) for i, c := range g { s.data[i] = C.char(c) } return s }
func CharacterRGBA(renderer *sdl.Renderer, x, y int, c, r, g, b, a uint8) bool { _x := C.Sint16(x) _y := C.Sint16(y) _c := C.char(c) _r := C.Uint8(r) _g := C.Uint8(g) _b := C.Uint8(b) _a := C.Uint8(a) return C.characterRGBA(renderer, _x, _y, _c, _r, _g, _b, _a) == 0 }
func RegisterHotKey(key xplm.VirtualKeyCode, flags xplm.KeyFlags, description string, callback HotKeyCallback, ref interface{}) HotKeyID { cDescription := C.CString(description) defer C.free(unsafe.Pointer(cDescription)) cId := C.CString(goplane.IdGenerator()) regData := &hotKeyRegData{nil, callback, ref} hotkeys[cId] = regData hotkeyId := HotKeyID(C.XPLMRegisterHotKey(C.char(key), C.XPLMKeyFlags(flags), cDescription, C.XPLMHotKey_f(unsafe.Pointer(C.handleHotKey)), unsafe.Pointer(cId))) regData.id = hotkeyId return hotkeyId }
func readdelattr(filepath string) (bool, error) { val := C.char(0) err := C.getxattr( C.CString(filepath), C.CString("novm-deleted"), unsafe.Pointer(&val), C.size_t(1)) if err != C.ssize_t(1) { var stat syscall.Stat_t err := syscall.Stat( path.Join(filepath, ".deleted"), &stat) if err != nil { return false, err } return true, nil } return val == C.char(1), nil }
// Creates new ModbusRTU connection func NewRtuConnection(device string, baud int, parity byte, data_bit uint8, stop_bit uint8) (*RtuConnection, error) { cs := C.CString(device) defer C.free(unsafe.Pointer(cs)) context, errno := C.modbus_new_rtu(cs, C.int(baud), C.char(parity), C.int(data_bit), C.int(stop_bit)) if context == nil { return nil, errors.New(fmt.Sprintf("Failed to create libmodbus context: %s", modbus_strerror(errno))) } return &RtuConnection{context, INVALID_SLAVE, false}, nil }
func Bind_param_float(req_handle int, index int, value interface{}, flag int) int { var handle C.int = C.int(req_handle) var res C.int c_param := C.float(value.(float64)) res = C.cci_bind_param(handle, C.int(index), C.CCI_A_TYPE_FLOAT, unsafe.Pointer(&c_param), C.CCI_U_TYPE_FLOAT, C.char(flag)) return int(res) }
func Bind_param_string(req_handle int, index int, value interface{}, flag int) int { var handle C.int = C.int(req_handle) var res C.int ss := fmt.Sprint(value) res = C.cci_bind_param(handle, C.int(index), C.CCI_A_TYPE_STR, unsafe.Pointer(C.CString(ss)), C.CCI_U_TYPE_STRING, C.char(flag)) return int(res) }
func main() { input := bufio.NewReader(os.Stdin) fmt.Println("Enter text to be wrapped") text, _ := input.ReadString('\n') text = strings.TrimSpace(text) fmt.Print("Enter the character for the border: ") b, _ := input.ReadString('\n') b = strings.TrimSpace(b) size := len(text) fmt.Println("Text:", string(text)) C.printBorder(C.size_t(size), C.char(b[0])) C.printSpacer(C.size_t(size), C.char(b[0])) myPrintText(string(text), string(b[0])) C.printSpacer(C.size_t(size), C.char(b[0])) C.printBorder(C.size_t(size), C.char(b[0])) }
func Execute(req_handle int, flag int, max_col_size int) (int, GCI_ERROR) { var res C.int var cci_error C.T_CCI_ERROR var handle C.int = C.int(req_handle) var err GCI_ERROR res = C.cci_execute(handle, C.char(flag), C.int(max_col_size), &cci_error) err.Code = int(cci_error.err_code) err.Msg = C.GoString(&cci_error.err_msg[0]) return int(res), err }
func End_tran(conn_handle int, tran_type int) (int, GCI_ERROR) { var res C.int var handle C.int = C.int(conn_handle) var cci_error C.T_CCI_ERROR var err GCI_ERROR res = C.cci_end_tran(handle, C.char(tran_type), &cci_error) err.Code = int(cci_error.err_code) err.Msg = C.GoString(&cci_error.err_msg[0]) return int(res), err }
// Return true if the file header contains instrument information for the file. false otherwise. func (f *File) SetInstrument(i *Instrument) bool { c := new(C.SF_INSTRUMENT) c.gain = C.int(i.Gain) c.basenote = C.char(i.Basenote) c.detune = C.char(i.Detune) c.velocity_lo = C.char(i.Velocity[0]) c.velocity_hi = C.char(i.Velocity[1]) c.key_lo = C.char(i.Key[0]) c.key_hi = C.char(i.Key[1]) c.loop_count = C.int(i.LoopCount) var index int for ; index < i.LoopCount; index++ { c.loops[index].mode = C.int(i.Loops[index].Mode) c.loops[index].start = C.uint32_t(i.Loops[index].Start) c.loops[index].end = C.uint32_t(i.Loops[index].End) c.loops[index].count = C.uint32_t(i.Loops[index].Count) } for ; index < 16; index++ { c.loops[index].mode = C.int(None) // why is this necessary? libsndfile doesn't check loopcount for AIFF } r := C.sf_command(f.s, C.SFC_SET_INSTRUMENT, unsafe.Pointer(c), C.int(unsafe.Sizeof(*c))) return (r == C.SF_TRUE) }
func (b *BTRFS) SubvolumeCreate(name string) error { var args C.struct_btrfs_ioctl_vol_args for i, c := range []byte(name) { args.name[i] = C.char(c) } _, _, errno := syscall.Syscall(syscall.SYS_IOCTL, b.fd.Fd(), C.BTRFS_IOC_SUBVOL_CREATE, uintptr(unsafe.Pointer(&args))) if errno != 0 { return fmt.Errorf("Failed to create btrfs subvolume: %v", errno.Error()) } return nil }