示例#1
0
func Initialize() {
	/*
		This method is used to initialize cpress. Call it before
		doing anything.
	*/
	C.initialize()
}
示例#2
0
文件: init.go 项目: postfix/goquic
func init() {
	ret := C.goquic_init_thread_callbacks()
	if ret != 0 {
		panic(fmt.Errorf("goquic_init_thread_callbacks failed with error node %d", ret))
	}

	// This initializes Chromium's base library codes
	C.initialize()
}
示例#3
0
// NewSNMPManager creates a new SNMP manager.
func NewSNMPManager(community string, maxConnections uint) (*SNMPManager, error) {
	C.initialize()
	s := SNMPManager{
		inUse:          lib.NewSemaphore(1),
		community:      C.CString(community),
		maxConnections: maxConnections,
	}
	return &s, nil
}
示例#4
0
// NewSNMPManager creates a new SNMP manager.
func NewSNMPManager(community string, maxConnections uint) (*SNMPManager, error) {
	if community == "" || maxConnections == 0 {
		return nil, errors.New(
			"SNMP values not set in config file; run connector-util -update-config-file")
	}

	C.initialize()
	s := SNMPManager{
		inUse:          lib.NewSemaphore(1),
		community:      C.CString(community),
		maxConnections: maxConnections,
	}
	return &s, nil
}
示例#5
0
文件: goquic.go 项目: horiga/goquic
func init() {
	// This initializes Chromium's base library codes
	C.initialize()
}
示例#6
0
文件: imp.go 项目: CaptainSoOmA/Uni
func Init(w, h uint, cF, cB col.Colour) (uint, uint, uint) {
	//
	initialized = false
	//
	maxX, maxY, bitdepth = Screen()
	bdp := uint(bitdepth)
	switch bdp {
	case 15, 16, 24, 32:
		col.SetColourDepth(bdp)
	default:
		panic("strange colourdepth") /* Terminate (); */ os.Exit(1)
	}
	colourdepth := (bdp + 1) / 8
	col.ScreenF, col.ScreenB = cF, cB
	xx, yy = C.uint(w), C.uint(h)
	window = C.XCreateSimpleWindow(display, C.Window(window0), 0, 0, xx, yy, C.uint(0), C.ulong(0), cc(col.ScreenB))
	//  var E C.XEvent
	//  C.XNextEvent (display, &E) // XCreate... did not produce an XEvent
	C.initialize(display, screen, window)
	t := C.CString(env.Par(0))
	defer C.free(unsafe.Pointer(t))
	C.XStoreName(display, window, t)
	C.XMapRaised(display, window)
	const inputmask = (C.KeyPressMask + // C.KeyReleaseMask +
		C.ButtonPressMask + C.ButtonReleaseMask + C.PointerMotionMask +
		C.ExposureMask + C.StructureNotifyMask)
	C.XSelectInput(display, window, inputmask)
	cursor := C.XCreateFontCursor(display, C.XC_gumby)
	C.XDefineCursor(display, window, cursor)
	graphicsContext = C.XDefaultGC(display, screen)
	//  C.XFlushGC (display graphicsContext)
	C.XSetGraphicsExposures(display, graphicsContext, C.False)
	SetFontsize(16)
	initialized = true
	Colours(cF, cB)
	C.XSetForeground(display, graphicsContext, cc(col.ScreenB))

	C.XFillRectangle(display, C.Drawable(window), graphicsContext, 0, 0, xx, yy)
	pixmap = C.XCreatePixmap(display, C.Drawable(window), xx, yy, bitdepth)
	pixmap1 = C.XCreatePixmap(display, C.Drawable(window), maxX, maxY, bitdepth)
	C.XFillRectangle(display, C.Drawable(pixmap), graphicsContext, 0, 0, xx, yy)
	C.XFillRectangle(display, C.Drawable(pixmap1), graphicsContext, 0, 0, xx, yy)
	C.XSetForeground(display, graphicsContext, cc(col.ScreenF))

	MouseDef(0, 0, int(xx-1), int(yy-1))
	var E C.XEvent
	C.XNextEvent(display, &E)
	var et C.int = C.typ(&E) // et == *E.type
	switch et {
	case C.Expose, C.ConfigureNotify: // zur Erstausgabe
		for C.XCheckTypedEvent(display, et, &E) == C.True {
		}
		//    pp2ff ()
	case KeyPress, KeyRelease, ButtonPress, ButtonRelease, MotionNotify:
		C.XPutBackEvent(display, &E)
	case C.ReparentNotify: // at Switch (?)
		// ignore
	default: // for test purposes
		//    println ("at initializing x:" + txt [et])
	}
	p := C.CString("WM_PROTOCOLS")
	defer C.free(unsafe.Pointer(p))
	wm_protocols := C.XInternAtom(display, p, C.False)
	C.XSetWMProtocols(display, window, &wm_protocols, 1)
	s := C.CString("_NET_WM_STATE")
	defer C.free(unsafe.Pointer(s))
	netwm_state = C.XInternAtom(display, s, C.False)
	f := C.CString("_NET_WM_STATE_FULLSCREEN")
	defer C.free(unsafe.Pointer(f))
	fullscreen = C.XInternAtom(display, f, C.False)
	m := C.CString("navi")
	defer C.free(unsafe.Pointer(m))
	naviAtom = C.XInternAtom(display, m, C.False)
	Eventpipe = make(chan Event)
	go sendEvents()
	//  C.XFlush (display)
	//  println ("init ok")
	return uint(maxX), uint(maxY), colourdepth
}
func main() {
	fmt.Printf("Initializing Rosie... ")

	var messages C.struct_stringArray

	home := gostring_to_structStringptr("/Users/jjennings/Work/Dev/public/rosie-pattern-language")
	engine, err := C.initialize(home, &messages)
	fmt.Printf("done.\n")
	if engine == nil {
		fmt.Printf("Return value from initialize was NULL!")
		fmt.Printf("Err field returned by initialize was: %s\n", err)
		fmt.Printf("Messages returned from initialize:\n")
		print_structStringArray(messages)
		os.Exit(-1)
	}

	var a C.struct_stringArray
	cfg := gostring_to_structStringptr("{\"expression\":\"[:digit:]+\", \"encode\":\"json\"}")
	a, err = C.configure_engine(engine, cfg)
	retval := structString_to_GoString(*C.string_array_ref(a, 0))
	fmt.Printf("Return code from configure_engine: %s\n", retval)

	a, err = C.inspect_engine(engine)
	retval = structString_to_GoString(*C.string_array_ref(a, 0))
	fmt.Printf("Return code from inspect_engine: %s\n", retval)
	fmt.Printf("Config from inspect_engine: %s\n", structString_to_GoString(*C.string_array_ref(a, 1)))
	C.free_stringArray(a)

	var foo string = "1111111111222222222211111111112222222222111111111122222222221111111111222222222211111111112222222222"
	foo_string := C.new_string_ptr(C.int(len(foo)), C.CString(foo))

	a, err = C.match(engine, foo_string, nil)
	retval = structString_to_GoString(*C.string_array_ref(a, 0))
	fmt.Printf("Return code from match: %s\n", retval)
	fmt.Printf("Data|false from match: %s\n", structString_to_GoString(*C.string_array_ref(a, 1)))
	fmt.Printf("Leftover chars from match: %s\n", structString_to_GoString(*C.string_array_ref(a, 2)))

	var r C.struct_stringArray
	var code, js_str string
	var leftover int

	foo = "1239999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
	foo_string = C.new_string_ptr(C.int(len(foo)), C.CString(foo))

	r = C.match(engine, foo_string, nil)
	code = structString_to_GoString(*C.string_array_ref(r, 0))
	js_str = structString_to_GoString(*C.string_array_ref(r, 1))
	leftover, err = strconv.Atoi(structString_to_GoString(*C.string_array_ref(r, 2)))
	if code != "true" {
		fmt.Printf("Error in match: %s\n", js_str)
	} else {
		fmt.Printf("Return code from match: %s\n", code)
		fmt.Printf("Data|false from match: %s\n", js_str)
		fmt.Printf("Leftover chars from match: %d\n", leftover)

		var retvals map[string]map[string]interface{}
		err = json.Unmarshal([]byte(js_str), &retvals)
		if err != nil {
			fmt.Println("JSON parse error:", err)
		}
		fmt.Printf("Match table: %s\n", retvals)
		fmt.Printf("Text from match table: %s\n", retvals["*"]["text"])
		fmt.Printf("Pos from match table: %d\n", int(retvals["*"]["pos"].(float64)))
		if retvals["*"]["subs"] != nil {
			fmt.Printf("Subs from match table: %s\n", retvals["*"]["subs"].(string))
		} else {
			fmt.Printf("No subs from match table.\n")
		}
	}
	C.free_stringArray(r)

	fmt.Printf(" done.\n")

	C.finalize(engine)

}
func init() {
	log.Debug("initialize python.")
	C.initialize()
}