// FindGenericPassword finds the first generic password item which matches the
// attributes you provide. Most attributes are optional; you should pass only as
// many as you need to narrow the search sufficiently for your application's
// intended use.
func FindGenericPassword(service, account string) (string, error) {
	if service == "" || account == "" {
		return "", errors.New("service and account are required")
	}

	cService := C.CString(service)
	defer C.free(unsafe.Pointer(cService))

	cAccount := C.CString(account)
	defer C.free(unsafe.Pointer(cAccount))

	cPasswordLen := C.UInt32(0)
	cPassword := unsafe.Pointer(nil)

	errCode := C.SecKeychainFindGenericPassword(
		nil, // default keychain
		C.UInt32(C.strlen(cService)),
		cService,
		C.UInt32(C.strlen(cAccount)),
		cAccount,
		&cPasswordLen,
		&cPassword,
		nil,
	)

	if err := newKeychainError(errCode); err != nil {
		return "", err
	}

	defer C.SecKeychainItemFreeContent(nil, cPassword)

	return C.GoStringN((*C.char)(cPassword), C.int(cPasswordLen)), nil
}
示例#2
0
文件: conn.go 项目: jeffycf/goci-1
func (conn *connection) performLogon(dsn string) error {

	user, pwd, host := parseDsn(dsn)
	puser := C.CString(user)
	defer C.free(unsafe.Pointer(puser))
	ppwd := C.CString(pwd)
	defer C.free(unsafe.Pointer(ppwd))
	phost := C.CString(host)
	defer C.free(unsafe.Pointer(phost))

	result := C.OCILogon2((*C.OCIEnv)(unsafe.Pointer(conn.env)),
		(*C.OCIError)(conn.err),
		(**C.OCIServer)(unsafe.Pointer(&conn.svr)),
		(*C.OraText)(unsafe.Pointer(puser)),
		C.ub4(C.strlen(puser)),
		(*C.OraText)(unsafe.Pointer(ppwd)),
		C.ub4(C.strlen(ppwd)),
		(*C.OraText)(unsafe.Pointer(phost)),
		C.ub4(C.strlen(phost)),
		C.OCI_LOGON2_STMTCACHE)
	if result != C.OCI_SUCCESS {
		return ociGetError(conn.err)
	}
	return nil
}
示例#3
0
func (d *OCI8Driver) Open(dsn string) (driver.Conn, error) {
	var conn OCI8Conn
	token := strings.SplitN(dsn, "@", 2)
	userpass := strings.SplitN(token[0], "/", 2)

	rv := C.OCIInitialize(
		C.OCI_DEFAULT,
		nil,
		nil,
		nil,
		nil)
	if rv == C.OCI_ERROR {
		return nil, ociGetError(conn.err)
	}

	rv = C.OCIEnvInit(
		(**C.OCIEnv)(unsafe.Pointer(&conn.env)),
		C.OCI_DEFAULT,
		0,
		nil)

	rv = C.OCIHandleAlloc(
		conn.env,
		&conn.err,
		C.OCI_HTYPE_ERROR,
		0,
		nil)
	if rv == C.OCI_ERROR {
		return nil, ociGetError(conn.err)
	}

	var phost *C.char
	phostlen := C.size_t(0)
	if len(token) > 1 {
		phost = C.CString(token[1])
		defer C.free(unsafe.Pointer(phost))
		phostlen = C.strlen(phost)
	}
	puser := C.CString(userpass[0])
	defer C.free(unsafe.Pointer(puser))
	ppass := C.CString(userpass[1])
	defer C.free(unsafe.Pointer(ppass))

	rv = C.OCILogon(
		(*C.OCIEnv)(conn.env),
		(*C.OCIError)(conn.err),
		(**C.OCIServer)(unsafe.Pointer(&conn.svc)),
		(*C.OraText)(unsafe.Pointer(puser)),
		C.ub4(C.strlen(puser)),
		(*C.OraText)(unsafe.Pointer(ppass)),
		C.ub4(C.strlen(ppass)),
		(*C.OraText)(unsafe.Pointer(phost)),
		C.ub4(phostlen))
	if rv == C.OCI_ERROR {
		return nil, ociGetError(conn.err)
	}

	return &conn, nil
}
示例#4
0
func (grok *Grok) AddPattern(name, pattern string) {
	cname := C.CString(name)
	cpattern := C.CString(pattern)
	defer C.free(unsafe.Pointer(cname))
	defer C.free(unsafe.Pointer(cpattern))

	C.grok_pattern_add(grok.g, cname, C.strlen(cname), cpattern, C.strlen(cpattern))
}
示例#5
0
文件: pcap.go 项目: alvinlee/gopcap
func Findalldevs() (ifs []Interface, err os.Error) {
	var alldevsp *C.pcap_if_t
	var buf [ERRBUF_SIZE]byte
	cbuf := (*C.char)(unsafe.Pointer(&buf[0]))

	if C.pcap_findalldevs(&alldevsp, cbuf) == -1 {
		clen := C.strlen(cbuf)
		err = os.NewError(string(buf[:clen]))
		return
	}
	defer C.pcap_freealldevs(alldevsp)

	dev := (*C.struct_pcap_if)(alldevsp)
	i := 0
	for ; dev != nil; dev = dev.next {
		i++
	}

	ifs = make([]Interface, i)
	for ; dev != nil; dev = dev.next {
		ifs[i].Name = C.GoString(dev.name)
		ifs[i].Desc = C.GoString(dev.description)
		i++
	}

	return
}
示例#6
0
文件: stmt.go 项目: pkf/gosqlite
func (c *Conn) prepare(cmd string, args ...interface{}) (*Stmt, error) {
	if c == nil {
		return nil, errors.New("nil sqlite database")
	}
	cmdstr := C.CString(cmd)
	defer C.free(unsafe.Pointer(cmdstr))
	var stmt *C.sqlite3_stmt
	var tail *C.char
	// If the caller knows that the supplied string is nul-terminated, then there is a small performance advantage to be gained by passing an nByte parameter that is equal to the number of bytes in the input string including the nul-terminator bytes as this saves SQLite from having to make a copy of the input string.
	rv := C.my_prepare_v2(c.db, cmdstr, C.int(len(cmd)+1), &stmt, &tail)
	if rv != C.SQLITE_OK {
		return nil, c.error(rv, cmd)
	}
	var t string
	if tail != nil && C.strlen(tail) > 0 {
		t = C.GoString(tail)
	}
	s := &Stmt{c: c, stmt: stmt, tail: t, columnCount: -1, bindParameterCount: -1, CheckTypeMismatch: true}
	if len(args) > 0 {
		err := s.Bind(args...)
		if err != nil {
			s.finalize()
			return nil, err
		}
	}
	return s, nil
}
示例#7
0
文件: sqlite.go 项目: kazyk/go-sqlite
func (stmt Stmt) bind(args []driver.Value) error {
	if C.sqlite3_clear_bindings(stmt.stmt) != C.SQLITE_OK {
		return stmtError(stmt.stmt)
	}
	for i, arg := range args {
		r := C.int(-1)
		switch val := arg.(type) {
		case int64:
			r = C.sqlite3_bind_int64(stmt.stmt, C.int(i+1), C.sqlite3_int64(val))
		case float64:
			r = C.sqlite3_bind_double(stmt.stmt, C.int(i+1), C.double(val))
		case bool:
			if val {
				r = C.sqlite3_bind_int64(stmt.stmt, C.int(i+1), C.sqlite3_int64(1))
			} else {
				r = C.sqlite3_bind_int64(stmt.stmt, C.int(i+1), C.sqlite3_int64(0))
			}
		case nil:
			r = C.sqlite3_bind_null(stmt.stmt, C.int(i+1))
		case string:
			str := C.CString(val)
			defer C.free(unsafe.Pointer(str))
			l := C.int(C.strlen(str))
			r = C.bind_text(stmt.stmt, C.int(i+1), str, l)
		default:
			panic("unsupported type")
		}

		if r != C.SQLITE_OK {
			return stmtError(stmt.stmt)
		}
	}
	return nil
}
示例#8
0
文件: gdal.go 项目: kikht/gdal
func metadata(object unsafe.Pointer, domain string) map[string]string {
	c_domain := C.CString(domain)
	defer C.free(unsafe.Pointer(c_domain))

	stringList := C.GDALGetMetadata((C.GDALMajorObjectH)(object), c_domain)
	if stringList == nil {
		return nil
	}

	stringCount := C.CSLCount(stringList)
	metadata := make(map[string]string, stringCount)

	var nameBuffer []byte
	for i := (C.int)(0); i < stringCount; i++ {
		cPair := C.CSLGetField(stringList, i)
		totalLength := C.strlen(cPair) + 1 // add one for null terminator
		if int(totalLength) > len(nameBuffer) {
			nameBuffer = make([]byte, totalLength)
		}

		namePointer := (*C.char)(unsafe.Pointer(&nameBuffer[0]))
		cValue := C.CPLParseNameValue(cPair, &namePointer)

		name := C.GoString(namePointer)
		value := C.GoString(cValue)
		metadata[name] = value
	}

	return metadata
}
示例#9
0
文件: oci8.go 项目: AsamQi/go-oci8
func (c *OCI8Conn) Prepare(query string) (driver.Stmt, error) {
	pquery := C.CString(query)
	defer C.free(unsafe.Pointer(pquery))
	var s, bp, defp unsafe.Pointer

	if rv := C.WrapOCIHandleAlloc(
		c.env,
		C.OCI_HTYPE_STMT,
		(C.size_t)(unsafe.Sizeof(bp)*2)); rv.rv != C.OCI_SUCCESS {
		return nil, ociGetError(c.err)
	} else {
		s = rv.ptr
		bp = rv.extra
		defp = unsafe.Pointer(uintptr(rv.extra) + unsafe.Sizeof(unsafe.Pointer(nil)))
	}

	if rv := C.OCIStmtPrepare(
		(*C.OCIStmt)(s),
		(*C.OCIError)(c.err),
		(*C.OraText)(unsafe.Pointer(pquery)),
		C.ub4(C.strlen(pquery)),
		C.ub4(C.OCI_NTV_SYNTAX),
		C.ub4(C.OCI_DEFAULT)); rv != C.OCI_SUCCESS {
		return nil, ociGetError(c.err)
	}

	ss := &OCI8Stmt{c: c, s: s, bp: (**C.OCIBind)(bp), defp: (**C.OCIDefine)(defp)}
	runtime.SetFinalizer(ss, (*OCI8Stmt).Close)
	return ss, nil
}
func (snoty Notification) Show() {

	var message *C.char = C.CString(snoty.Message)
	var title *C.char = C.CString(snoty.Title)
	var appname *C.char = C.CString(snoty.Appname)
	var n *C.NotifyNotification

	if C.strlen(appname) > 0 {
		if C.notify_is_initted() == C.FALSE {
			C.notify_init(appname)
		}
	} else {
		if C.notify_is_initted() == C.FALSE {
			C.notify_init(C.CString("Simple.Notification"))

		}
	}

	if snoty.Icon_path != "" {
		var tmpPath *C.char = C.CString(snoty.Icon_path)
		var buf *C.GdkPixbuf = C.gdk_pixbuf_new_from_file(tmpPath, nil)
		C.notify_notification_set_image_from_pixbuf(n, buf)
		//C.free(unsafe.Pointer(tmpPath))
	}

	n = C.notify_notification_new(title, message, nil)
	C.notify_notification_show(n, nil)
	C.my_own_unref(n)

	C.notify_uninit()
	C.free(unsafe.Pointer(appname))
	C.free(unsafe.Pointer(message))
	C.free(unsafe.Pointer(title))

}
示例#11
0
func (c *ConnectionOracle) NewStatement(sql string) (s *StatementOracle, err int) {

	s = new(StatementOracle)
	pStatement := unsafe.Pointer(&s.hStatement)
	res := C.OCIHandleAlloc(unsafe.Pointer(c.driver.hEnv), (*unsafe.Pointer)(pStatement), C.OCI_HTYPE_STMT, 0, nil)
	if C.OCI_SUCCESS != res /*&& C.OCI_STILL_EXECUTING != res*/ {
		fmt.Printf("Result hSession=%v\n", res)
		C.AuxOCIErrorGet(c.driver.hError)
		return nil, -1
	}

	cSql := C.CString(sql)
	defer C.free(unsafe.Pointer(cSql))
	var osql *C.OraText = C.Get_OraText(cSql)
	//fmt.Printf( "%v:%v\n", C.strlen(sql), C.GoString(sql))
	res = C.OCIStmtPrepare(s.hStatement, c.driver.hError, osql, C.ub4(C.strlen(cSql)), C.OCI_NTV_SYNTAX, C.OCI_DEFAULT)
	if C.OCI_SUCCESS != res /*&& C.OCI_STILL_EXECUTING != res*/ {
		fmt.Printf("Resultado OCIStmtPrepare=%v\n", res)
		C.AuxOCIErrorGet(c.driver.hError)
		return nil, -2
	}
	s.fetchDone = false
	s.con = c
	return s, 0
}
示例#12
0
func CBulkUnjar(db *C.ol_database, keys []string) [][]byte {
	var ckeys []*C.char

	// Set array structure
	for _, v := range keys {
		ckey := C.CString(v)
		defer C.free(unsafe.Pointer(ckey))
		ckeys = append(ckeys, ckey)
	}

	var keysPtr C.ol_key_array
	keysPtr = &ckeys[0]

	values := (*C.vector)(C.ol_bulk_unjar(db, keysPtr, (C.size_t)(len(ckeys))))

	var toReturn [][]byte
	// TODO: Will not work for unsigned char data with nulls sprinkled
	// throughout. :^)
	for i := (uint)(0); i < (uint)(values.count); i++ {
		raw_value := *(**C.char)(C.vector_get(values, (C.uint)(i)))
		if raw_value != nil {
			raw_len := C.strlen(raw_value)
			coerced := C.GoBytes(unsafe.Pointer(raw_value), (C.int)(raw_len))
			toReturn = append(toReturn, coerced)
			C.free(unsafe.Pointer(raw_value))
		} else {
			toReturn = append(toReturn, []byte{})
		}
	}
	C.vector_free(values)

	return toReturn
}
示例#13
0
文件: oci8.go 项目: kwargs/go-oci8
func (conn *OCI8Conn) Prepare(query string) (driver.Stmt, error) {
	pquery := C.CString(query)
	defer C.free(unsafe.Pointer(pquery))
	var s unsafe.Pointer

	rv := C.OCIHandleAlloc(
		conn.env,
		&s,
		C.OCI_HTYPE_STMT,
		0,
		nil)

	if err := conn.check(rv, "OCI8Conn.Prepare() allocate statement handle"); err != nil {
		return nil, err
	}

	rv = C.OCIStmtPrepare(
		(*C.OCIStmt)(s),
		(*C.OCIError)(conn.err),
		(*C.OraText)(unsafe.Pointer(pquery)),
		C.ub4(C.strlen(pquery)),
		C.ub4(C.OCI_NTV_SYNTAX),
		C.ub4(C.OCI_DEFAULT))

	if err := conn.check(rv, "OCI8Conn.Prepare() prepare statement"); err != nil {
		return nil, err
	}

	return &OCI8Stmt{c: conn, s: s}, nil
}
示例#14
0
// Return input with pattern replaced by sub.
func reSub(pattern []byte, sub []byte, input []byte) []byte {
	var err *C.GError = nil
	re := C.g_regex_new(
		(*C.gchar)(data(append(pattern, 0))),
		C.G_REGEX_CASELESS|
			C.G_REGEX_RAW|
			C.G_REGEX_NO_AUTO_CAPTURE|
			C.G_REGEX_OPTIMIZE,
		0,
		&err)
	if err != nil {
		panic("g_regex_new")
	}
	defer C.g_regex_unref(re)
	subd := C.g_regex_replace_literal(re, (*C.gchar)(data(input)),
		C.gssize(len(input)), 0, (*C.gchar)(data(sub)), 0, &err)
	if err != nil {
		panic("g_regex_replace_literal")
	}
	defer C.g_free(C.gpointer(subd))
	l := C.strlen((*C.char)(subd))
	rv := make([]byte, l)
	C.memcpy(data(rv), unsafe.Pointer(subd), l)
	return rv
}
示例#15
0
文件: r3.go 项目: Bendalexis/go-r3
// creates a new MatchEntry
func NewMatchEntry(path string) *MatchEntry {
	p := C.CString(path)
	e := C.match_entry_createl(p, C.int(C.strlen(p)))
	return &MatchEntry{
		entry: e,
	}
}
示例#16
0
文件: oci8.go 项目: supiyun/go-oci8
func (c *OCI8Conn) Prepare(query string) (driver.Stmt, error) {
	pquery := C.CString(query)
	defer C.free(unsafe.Pointer(pquery))
	var s unsafe.Pointer

	rv := C.OCIHandleAlloc(
		c.env,
		&s,
		C.OCI_HTYPE_STMT,
		0,
		nil)
	if rv == C.OCI_ERROR {
		return nil, ociGetError(c.err)
	}

	rv = C.OCIStmtPrepare(
		(*C.OCIStmt)(s),
		(*C.OCIError)(c.err),
		(*C.OraText)(unsafe.Pointer(pquery)),
		C.ub4(C.strlen(pquery)),
		C.ub4(C.OCI_NTV_SYNTAX),
		C.ub4(OCI_MODE))
	if rv == C.OCI_ERROR {
		return nil, ociGetError(c.err)
	}

	return &OCI8Stmt{c: c, s: s}, nil
}
示例#17
0
文件: pcre.go 项目: utsl42/go-pcre
// Compile pattern with jit compilation. flagC is Compile flags,
// flagS is study flag.
func CompileJIT(pattern string, flagsC, flagsS int) (Regexp, error) {
	patternC := C.CString(pattern)
	defer C.free(unsafe.Pointer(patternC))
	if clen := int(C.strlen(patternC)); clen != len(pattern) {
		return Regexp{}, fmt.Errorf("%s (%d): %s",
			pattern,
			clen,
			"NUL byte in pattern",
		)
	}
	var errptr *C.char
	var erroffset C.int
	ptr := C.pcre_compile(patternC, C.int(flagsC), &errptr, &erroffset, nil)
	if ptr == nil {
		return Regexp{}, fmt.Errorf("%s (%d): %s",
			pattern,
			int(erroffset),
			C.GoString(errptr),
		)
	}
	psize := pcresize(ptr)
	var re Regexp
	re.ptr = make([]byte, psize)
	C.memcpy(unsafe.Pointer(&re.ptr[0]), unsafe.Pointer(ptr), psize)
	errS := re.study(flagsS)
	if errS != nil {
		return re, fmt.Errorf("study error: %s", errS)
	}
	return re, nil
}
示例#18
0
文件: cef.go 项目: mmatey/cef2go
func CEFString(original string) (final *C.cef_string_t) {
	final = (*C.cef_string_t)(C.calloc(1, C.sizeof_cef_string_t))
	charString := C.CString(original)
	defer C.free(unsafe.Pointer(charString))
	C.cef_string_from_utf8(charString, C.strlen(charString), final)
	return final
}
示例#19
0
func (_self_ *Pixbuf) GetPixelsWithLength() (_go__return__ []byte, _go_length_ uint) {
	var length C.guint
	var _return_ *C.guchar
	_return_ = C._gdk_pixbuf_get_pixels_with_length((*C.GdkPixbuf)(_self_._value_), &length)
	_go_length_ = (uint)(length)
	_go__return__ = C.GoBytes(unsafe.Pointer(_return_), C.int(C.strlen((*C.char)(unsafe.Pointer(_return_)))))
	return
}
示例#20
0
文件: ovr.go 项目: postfix/ovr
// The ovrHmd_GetLatencyTestResult function has a bug, where it sends back an
// empty string when there is no error, instead of a NULL. Work around that.
func (hmd *Hmd) GetLatencyTestResult() *string {
	if str := C.ovrHmd_GetLatencyTestResult(hmd.hmdRef); str != nil && C.strlen(str) != 0 {
		goStr := C.GoString(str)
		return &goStr
	}

	return nil
}
示例#21
0
文件: ovr.go 项目: postfix/ovr
// The ovrHmd_GetLastError function has a bug, where it sends back an empty
// string when there is no error, instead of NULL. Work around that.
func (hmd *Hmd) GetLastError() *string {
	if str := C.ovrHmd_GetLastError(hmd.hmdRef); str != nil && C.strlen(str) != 0 {
		goStr := C.GoString(str)
		return &goStr
	}

	return nil
}
// FindInternetPassword function finds the first Internet password item which
// matches the attributes you provide. Most attributes are optional; you should
// pass only as many as you need to narrow the search sufficiently for your
// application's intended use. SecKeychainFindInternetPassword optionally
// returns a reference to the found item.
func FindInternetPassword(server, domain, account, path string, port uint16, protocol ProtocolType, authType AuthenticationType) (string, error) {
	if server == "" || account == "" {
		return "", errors.New("server and account are required")
	}

	cServer := C.CString(server)
	defer C.free(unsafe.Pointer(cServer))

	cDomain := C.CString(domain)
	defer C.free(unsafe.Pointer(cDomain))

	cAccount := C.CString(account)
	defer C.free(unsafe.Pointer(cAccount))

	cPath := C.CString(path)
	defer C.free(unsafe.Pointer(cPath))

	cPasswordLen := C.UInt32(0)
	cPassword := unsafe.Pointer(nil)

	errCode := C.SecKeychainFindInternetPassword(
		nil, // default keychain,
		C.UInt32(C.strlen(cServer)),
		cServer,
		C.UInt32(C.strlen(cDomain)),
		cDomain,
		C.UInt32(C.strlen(cAccount)),
		cAccount,
		C.UInt32(C.strlen(cPath)),
		cPath,
		C.UInt16(port),
		C.SecProtocolType(protocol),
		C.SecAuthenticationType(authType),
		&cPasswordLen,
		&cPassword,
		nil,
	)

	if err := newKeychainError(errCode); err != nil {
		return "", err
	}

	defer C.SecKeychainItemFreeContent(nil, cPassword)

	return C.GoStringN((*C.char)(cPassword), C.int(cPasswordLen)), nil
}
示例#23
0
文件: r3.go 项目: Bendalexis/go-r3
// Insert path
func (n *Tree) InsertPath(path string, data interface{}) {
	d := &Data{
		Value: data,
	}
	/* hold reference to d so that it's not GCed */
	n.datas = append(n.datas, d)
	p := C.CString(path)
	C.r3_tree_insert_pathl(n.node, p, C.int(C.strlen(p)), unsafe.Pointer(d))
}
示例#24
0
文件: cef.go 项目: regiontog/cef
func toCefStringCopy(s string, out *C.cef_string_t) {
	var asC *C.char = C.CString(s)
	defer C.free(unsafe.Pointer(asC))
	C.cef_string_from_utf8(
		asC,
		C.strlen(asC),
		C.cefStringCastToCefString16(out),
	)
}
示例#25
0
文件: err.go 项目: eftychis/crypto-1
// Get the last OpenSSL error and convert it to a human-readable string
func getErrString() string {
	e := C.ERR_get_error()

	buf := [120]byte{} // max length specified in OpenSSL doc
	bufp := (*_Ctype_char)(unsafe.Pointer(&buf[0]))
	C.ERR_error_string_n(e, bufp, C.size_t(len(buf)))

	return string(buf[:C.strlen(bufp)])
}
示例#26
0
文件: c.go 项目: h12w/go-shapefile
func DBFReadStringAttribute(h DBFHandle, shapeIndex, fieldIndex int) []byte {
	cstr := C.DBFReadStringAttribute(h, C.int(shapeIndex), C.int(fieldIndex))
	slen := int(C.strlen(cstr))
	bytes := make([]byte, slen)
	if slen > 0 {
		C.memcpy(unsafe.Pointer(&bytes[0]), unsafe.Pointer(cstr), C.size_t(slen))
	}
	return bytes
}
示例#27
0
文件: r3.go 项目: Bendalexis/go-r3
// Insert route with method and arbitary data
func (n *Tree) InsertRoute(m Method, path string, data interface{}) {
	d := &Data{
		Value: data,
	}
	p := C.CString(path)
	/* hold reference to d so that it's not GCed */
	n.datas = append(n.datas, d)
	C.r3_tree_insert_routel(n.node, C.int(m), p, C.int(C.strlen(p)), unsafe.Pointer(d))
}
示例#28
0
func update_candidates(serial int, input string, providersp unsafe.Pointer, info map[string]interface{}) {
	texts := make(map[string]bool)
	providers := make(map[string][]string)
	descriptions := make(map[string][]string)
	distances := make(map[string]int)
	var lock sync.Mutex

	// from GlobalVocabulary
	l := GlobalVocabulary.Len()
	var word *Word
	for i := 0; i < l; i++ {
		word = GlobalVocabulary.GetByIndex(i)
		if match, distance := fuzzyMatch(word.Text, input); match {
			texts[word.Text] = true
			distances[word.Text] = distance
			providers[word.Text] = []string{}
		}
	}

	// get buffer content
	buffer := (*C.GtkTextBuffer)(info["buffer"].(unsafe.Pointer))
	var start_iter, end_iter C.GtkTextIter
	C.gtk_text_buffer_get_start_iter(buffer, &start_iter)
	C.gtk_text_buffer_get_end_iter(buffer, &end_iter)
	cContent := C.gtk_text_buffer_get_text(buffer, &start_iter, &end_iter, C.gtk_false())
	content := C.GoBytes(unsafe.Pointer(cContent), C.int(C.strlen((*C.char)(cContent))))

	result := sort(input, texts, distances, providers, descriptions)

	// extra providers
	for source, provider := range (*Providers)(providersp).Providers {
		go func() {
			lock.Lock()
			for _, pair := range provider(input, content, info) {
				text := pair[0]
				if input != "" {
					if match, _ := fuzzyMatch(text, input); !match {
						continue
					}
				}
				GlobalVocabulary.Add(text)
				texts[text] = true
				providers[text] = append(providers[text], source)
				descriptions[text] = append(descriptions[text], "<"+source+"> "+pair[1])
				distances[text] = 0
			}
			result := sort(input, texts, distances, providers, descriptions)
			lock.Unlock()
			C.emit()
			results <- Result{serial, result}
		}()
	}

	updateStore(result)

}
示例#29
0
func HtmlReadMemory(buffer string, url string, encoding string, options HtmlParseOptions) unsafe.Pointer {
	cbuffer := C.CString(buffer)
	curl := C.CString(url)
	cencoding := C.CString(encoding)
	cdoc := C.htmlReadMemory(cbuffer, C.int(C.strlen(cbuffer)), curl, cencoding, C.int(options))
	C.free(unsafe.Pointer(cbuffer))
	C.free(unsafe.Pointer(curl))
	C.free(unsafe.Pointer(cencoding))
	return unsafe.Pointer(cdoc)
}
示例#30
0
// String converts a Number to a character string, using scientific notation if an exponent is
// needed (that is, there will be just one digit before any decimal point). It implements the
// to-scientific-string conversion.
func (n *Number) String() string {
	nDigits := int(n.dn.digits)
	if nDigits == 0 {
		nDigits++
	}
	str := make([]byte, nDigits+14) // TODO: escapes to heap, need to check how fmt uses sync.Pool
	pStr := (*C.char)(unsafe.Pointer(&str[0]))
	C.decNumberToString(n.dn, pStr)
	return string(str[:C.strlen(pStr)])
}