Пример #1
0
// InitColor is used to set 'color' to the specified RGB values. Values may
// be between 0 and 1000.
func InitColor(col, r, g, b int16) error {
	if C.init_color(C.short(col), C.short(r), C.short(g),
		C.short(b)) == C.ERR {
		return errors.New("Failed to set new color definition")
	}
	return nil
}
Пример #2
0
// Compute the topocentric place of a solar system body.
func (p *Body) Topo(t Time, geo *Place, refr RefractType) BodyTopoData {

	t.update()

	data := BodyTopoData{}

	var ra, dec, dis C.double

	switch p.class {
	case clPLANET:
		if err := C.topo_planet(C.double(t.jd_tt), &p.object, C.double(t.delta_t), &geo.place, C.short(Accuracy), &ra, &dec, &dis); err != 0 {
			log.Fatalf("Error %d from app_planet (%s)\n", int(err), p.name)
		}
		data.Dis = float64(dis)
	case clSTAR:
		if err := C.topo_star(C.double(t.jd_tt), C.double(t.delta_t), &p.cat_entry, &geo.place, C.short(Accuracy), &ra, &dec); err != 0 {
			log.Fatalf("Error %d from app_planet (%s)\n", int(err), p.name)
		}
		data.Dis = math.NaN()
	}

	var elon, elat C.double
	C.equ2ecl(C.double(t.jd_tt), 0, C.short(Accuracy), ra, dec, &elon, &elat)

	var zd, az, rar, decr C.double
	C.equ2hor(C.double(t.jd_ut1), C.double(t.delta_t), C.short(Accuracy), 0, 0, &geo.place, ra, dec, C.short(refr), &zd, &az, &rar, &decr)
	data.Alt = 90 - float64(zd)
	data.Az = float64(az)

	return data
}
Пример #3
0
// Compute the apparent place of an object.
func (p *Body) App(t Time) BodyData {

	t.update()

	data := BodyData{}

	var ra, dec, dis C.double
	switch p.class {
	case clPLANET:
		if err := C.app_planet(C.double(t.jd_tt), &p.object, C.short(Accuracy), &ra, &dec, &dis); err != 0 {
			log.Fatalf("Error %d from app_planet (%s)\n", int(err), p.name)
		}
		data.Dis = float64(dis)
	case clSTAR:
		if err := C.app_star(C.double(t.jd_tt), &p.cat_entry, C.short(Accuracy), &ra, &dec); err != 0 {
			log.Fatalf("Error %d from app_star (%s)\n", int(err), p.name)
		}
		data.Dis = math.NaN()
	}
	data.RA = float64(ra)
	data.Dec = float64(dec)

	var elon, elat C.double
	C.equ2ecl(C.double(t.jd_tt), 0, C.short(Accuracy), ra, dec, &elon, &elat)
	data.ELon = float64(elon)
	data.ELat = float64(elat)

	return data
}
Пример #4
0
// WaitZero adds and operation that will block until a semaphore's number is 0.
func (so *SemOps) WaitZero(num uint16, flags *SemOpFlags) error {
	*so = append(*so, C.struct_sembuf{
		sem_num: C.ushort(num),
		sem_op:  C.short(0),
		sem_flg: C.short(flags.flags()),
	})
	return nil
}
Пример #5
0
func Init_pair(pair int, fg int, bg int) os.Error {
	in()
	defer out()
	if C.init_pair(C.short(pair), C.short(fg), C.short(bg)) == 0 {
		return CursesError{"Init_pair failed"}
	}
	return nil
}
Пример #6
0
// InitPair sets a colour pair designated by 'pair' to fg and bg colors
func InitPair(pair, fg, bg int16) error {
	if pair <= 0 || C.int(pair) > C.int(C.COLOR_PAIRS-1) {
		return errors.New("Color pair out of range")
	}
	if C.init_pair(C.short(pair), C.short(fg), C.short(bg)) == C.ERR {
		return errors.New("Failed to init color pair")
	}
	return nil
}
Пример #7
0
func PairFor(fg int, bg int) int {
	key := (fg << 8) + bg
	if found, prs := _colorMap[key]; prs {
		return found
	}

	id := len(_colorMap) + ColUser
	C.init_pair(C.short(id), C.short(fg), C.short(bg))
	_colorMap[key] = id
	return id
}
Пример #8
0
// Decrement adds an operation that will decrease a semaphore's number.
func (so *SemOps) Decrement(num uint16, by int16, flags *SemOpFlags) error {
	if by <= 0 {
		return errors.New("sysvipc: by must be >0. use WaitZero or Increment")
	}

	*so = append(*so, C.struct_sembuf{
		sem_num: C.ushort(num),
		sem_op:  C.short(-by),
		sem_flg: C.short(flags.flags()),
	})
	return nil
}
Пример #9
0
func PairFor(fg Color, bg Color) ColorPair {
	// ncurses does not support 24-bit colors
	if fg.is24() || bg.is24() {
		return ColDefault
	}
	key := (int(fg) << 8) + int(bg)
	if found, prs := _colorMap[key]; prs {
		return found
	}

	id := ColorPair(len(_colorMap) + int(ColUser))
	C.init_pair(C.short(id), C.short(fg), C.short(bg))
	_colorMap[key] = id
	return id
}
Пример #10
0
func (t *Time) update() {
	if t.Time.Equal(t.current) {
		return
	}
	t.current = t.Time
	t1 := t.current.UTC()
	t.jd_utc = float64(C.julian_date(
		C.short(t1.Year()),
		C.short(t1.Month()),
		C.short(t1.Day()),
		C.double(float64(t1.Hour())+float64(t1.Minute())/60+float64(t1.Second())/3600+float64(t1.Nanosecond())/3600/1e9)))
	t.jd_tt = t.jd_utc + (float64(Leap_secs)+32.184)/86400
	t.jd_ut1 = t.jd_utc + UT1_UTC/86400
	t.delta_t = 32.184 + float64(Leap_secs) - UT1_UTC
	t.jd_tdb = t.jd_tt /* Approximation good to 0.0017 seconds. */
}
Пример #11
0
/* Opens jabber connection for client */
func (client *Client) Connect(pass string,
	host string, port uint16) error {

	jid_i := C.CString(client.Jid)
	pass_i := C.CString(pass)
	var host_i *C.char = nil

	log.Println("xmpp.Connect: ", client.Jid)

	if len(host) > 0 {
		host_i = C.CString(host)
	}

	mutex.Lock()
	counter += 1
	mutex.Unlock()

	client.ConnInfo = C.open_xmpp_conn(jid_i, pass_i, host_i,
		C.short(port), C.int(counter))

	if client.ConnInfo != nil {
		client.Id = counter
		clients[counter] = client
		return nil
	}
	return errors.New("Connection error")
}
Пример #12
0
// PairContent returns the current foreground and background colours
// associated with the given pair
func PairContent(pair int16) (fg int16, bg int16, err error) {
	var f, b C.short
	if C.pair_content(C.short(pair), &f, &b) == C.ERR {
		return -1, -1, errors.New("Invalid color pair")
	}
	return int16(f), int16(b), nil
}
Пример #13
0
// Update the events mask of a socket in the poller
//
// Replaces the Poller's bitmask for the specified id with the events parameter passed
//
// Returns the previous value, or ErrorNoSocket if the id was out of range
func (p *Poller) Update(id int, events State) (previous State, err error) {
	if id >= 0 && id < len(p.items) {
		previous = State(p.items[id].events)
		p.items[id].events = C.short(events)
		return previous, nil
	}
	return 0, ErrorNoSocket
}
Пример #14
0
func initPairs(theme *ColorTheme) {
	C.assume_default_colors(C.int(theme.Fg), C.int(theme.Bg))
	initPair := func(group ColorPair, fg Color, bg Color) {
		C.init_pair(C.short(group), C.short(fg), C.short(bg))
	}
	initPair(ColNormal, theme.Fg, theme.Bg)
	initPair(ColPrompt, theme.Prompt, theme.Bg)
	initPair(ColMatch, theme.Match, theme.Bg)
	initPair(ColCurrent, theme.Current, theme.DarkBg)
	initPair(ColCurrentMatch, theme.CurrentMatch, theme.DarkBg)
	initPair(ColSpinner, theme.Spinner, theme.Bg)
	initPair(ColInfo, theme.Info, theme.Bg)
	initPair(ColCursor, theme.Cursor, theme.DarkBg)
	initPair(ColSelected, theme.Selected, theme.DarkBg)
	initPair(ColHeader, theme.Header, theme.Bg)
	initPair(ColBorder, theme.Border, theme.Bg)
}
Пример #15
0
func (d *DSPMeteringInfo) toC() C.FMOD_DSP_METERING_INFO {
	var cd C.FMOD_DSP_METERING_INFO
	cd.numsamples = C.int(d.Numsamples)
	//cd.peaklevel = C.float(d.Peaklevel)
	//cd.rmslevel = C.float(d.Rmslevel)
	cd.numchannels = C.short(d.Numchannels)
	return cd
}
Пример #16
0
func initPairs(theme *ColorTheme) {
	C.assume_default_colors(C.int(theme.Fg), C.int(theme.Bg))
	for _, pair := range []ColorPair{
		ColNormal,
		ColPrompt,
		ColMatch,
		ColCurrent,
		ColCurrentMatch,
		ColSpinner,
		ColInfo,
		ColCursor,
		ColSelected,
		ColHeader,
		ColBorder} {
		C.init_pair(C.short(pair.index()), C.short(pair.Fg()), C.short(pair.Bg()))
	}
}
Пример #17
0
func (w *CursesWindow) CFill(fg Color, bg Color, attr Attr, str string) FillReturn {
	index := ColorPair{fg, bg, -1}.index()
	C.wcolor_set(w.impl, C.short(index), nil)
	C.wattron(w.impl, C.int(attr))
	ret := w.Fill(str)
	C.wattroff(w.impl, C.int(attr))
	C.wcolor_set(w.impl, 0, nil)
	return ret
}
Пример #18
0
//Chmod.
//path: the path to the file or directory.
//mode: the bitmask to set it to.
//Returns nil on success else error.
func (fs *Fs) Chmod(path string, mode int16) error {
	p := C.CString(path)
	defer C.free(unsafe.Pointer(p))
	ret, err := C.hdfsChmod(fs.cptr, p, C.short(mode))
	if err != nil && ret == C.int(-1) {
		return err
	}
	return nil
}
Пример #19
0
func (p lzmqSocket) SetPollItem(pi *PollItem, revents int8) os.Error {
	if pi == nil {
		return os.EINVAL
	}
	pi.socket = unsafe.Pointer(uintptr(p))
	pi.revents = C.short(revents)
	pi.fd = 0
	return nil
}
Пример #20
0
func (w *Window) CFill(str string, fg Color, bg Color, attr Attr) bool {
	pair := PairFor(fg, bg)
	C.wcolor_set(w.win(), C.short(pair), nil)
	C.wattron(w.win(), C.int(attr))
	ret := w.Fill(str)
	C.wattroff(w.win(), C.int(attr))
	C.wcolor_set(w.win(), 0, nil)
	return ret
}
Пример #21
0
// Adds a Socket to the PollSet along with a set of events to monitor. Returns the index in the PollSet of the added socket.
func (p *PollSet) Socket(sock *Socket, events EventSet) (index int) {
	item := C.zmq_pollitem_t{
		socket: sock.sock,
		events: C.short(events),
	}
	index = len(p.items)
	p.items = append(p.items, item)
	return
}
Пример #22
0
// Adds a file descriptor to the PollSet along with a set of events to monitor. Returns the index in the PollSet of the
// added file.
func (p *PollSet) Fd(fd uintptr, events EventSet) (index int) {
	item := C.zmq_pollitem_t{
		fd:     C.int(fd),
		events: C.short(events),
	}
	index = len(p.items)
	p.items = append(p.items, item)
	return
}
Пример #23
0
// Add items to the poller
//
// Events is a bitwise OR of zmq.POLLIN and zmq.POLLOUT
func (p *Poller) Add(soc *Socket, events State) {
	var item C.zmq_pollitem_t
	item.socket = soc.soc
	item.fd = 0
	item.events = C.short(events)
	p.items = append(p.items, item)
	p.socks = append(p.socks, soc)
	p.size += 1
}
Пример #24
0
// Add items to the poller
//
// Events is a bitwise OR of zmq.POLLIN and zmq.POLLOUT
//
// Returns the id of the item, which can be used as a handle to
// (*Poller)Update and as an index into the result of (*Poller)PollAll
func (p *Poller) Add(soc *Socket, events State) int {
	var item C.zmq_pollitem_t
	item.socket = soc.soc
	item.fd = 0
	item.events = C.short(events)
	p.items = append(p.items, item)
	p.socks = append(p.socks, soc)
	return len(p.items) - 1
}
Пример #25
0
//Open a hdfs file in given mode.
//path: The full path to the file.
//flags: - an | of bits/fcntl.h file flags - supported flags are O_RDONLY, O_WRONLY (meaning create or overwrite i.e., implies O_TRUNCAT), O_WRONLY|O_APPEND. Other flags are generally ignored other than (O_RDWR || (O_EXCL & O_CREAT)) which return nil and set error equal ENOTSUP.
//bufferSize: Size of buffer for read/write - pass 0 if you want to use the default configured values.
//replication: Block replication - pass 0 if you want to use the default configured values.
//blocksize: Size of block - pass 0 if you want to use the default configured values.
//Returns the handle to the open file or nil on error.
func (fs *Fs) OpenFile(path string, flags int, buffersize int, replication int, blocksize uint32) (*File, error) {
	p := C.CString(path)
	defer C.free(unsafe.Pointer(p))
	file, err := C.hdfsOpenFile(fs.cptr, p, C.int(flags), C.int(buffersize), C.short(replication), C.tSize(blocksize))
	if err != nil && file == (C.hdfsFile)(unsafe.Pointer(uintptr(0))) {
		return nil, err
	}
	return &File{file, new(sync.RWMutex)}, nil
}
Пример #26
0
// Update the events mask of a socket in the poller
//
// Replaces the Poller's bitmask for the specified socket with the events parameter passed
//
// Returns the previous value, or ErrorNoSocket if the socket didn't match
func (p *Poller) UpdateBySocket(soc *Socket, events State) (previous State, err error) {
	for id, s := range p.socks {
		if s == soc {
			previous = State(p.items[id].events)
			p.items[id].events = C.short(events)
			return previous, nil
		}
	}
	return 0, ErrorNoSocket
}
Пример #27
0
func setRoute(ctl *os.File, dst ip.IP4Net, nextHopIP ip.IP4, nextHopPort int) {
	cmd := C.command{
		cmd:           C.CMD_SET_ROUTE,
		dest_net:      C.in_addr_t(dst.IP.NetworkOrder()),
		dest_net_len:  C.int(dst.PrefixLen),
		next_hop_ip:   C.in_addr_t(nextHopIP.NetworkOrder()),
		next_hop_port: C.short(nextHopPort),
	}

	writeCommand(ctl, &cmd)
}
Пример #28
0
func (p ColorPair) index() int16 {
	if p.id >= 0 {
		return p.id
	}

	// ncurses does not support 24-bit colors
	if p.is24() {
		return ColDefault.index()
	}

	key := p.key()
	if found, prs := _colorMap[key]; prs {
		return found
	}

	id := int16(len(_colorMap)) + ColUser.id
	C.init_pair(C.short(id), C.short(p.Fg()), C.short(p.Bg()))
	_colorMap[key] = id
	return id
}
Пример #29
0
func PolygonFull(X, Y []int, n bool) {
	//
	l := len(X)
	if len(Y) != l {
		return
	}
	p := make([]C.XPoint, l)
	for i := 0; i < l; i++ {
		p[i].x, p[i].y = C.short(X[i]), C.short(Y[i])
	}
	if !n {
		C.XSetFunction(display, graphicsContext, C.GXcopyInverted)
	}
	if !xxb {
		C.XFillPolygon(display, C.Drawable(window), graphicsContext, &p[0], C.int(l), C.Convex, C.CoordModeOrigin)
	}
	C.XFillPolygon(display, C.Drawable(pixmap), graphicsContext, &p[0], C.int(l), C.Convex, C.CoordModeOrigin)
	if !n {
		C.XSetFunction(display, graphicsContext, C.GXcopy)
	}
	C.XFlush(display)
}
Пример #30
0
func fbErrorCheckWarn(isc_status *[20]C.ISC_STATUS) error {
	var code C.short = C.short(C.isc_sqlcode(&isc_status[0]))
	if code != 0 {
		var buf [1024]C.ISC_SCHAR
		C.isc_sql_interprete(code, &buf[0], 1024)
		var msg bytes.Buffer
		for i := 0; buf[i] != 0; i++ {
			msg.WriteByte(uint8(buf[i]))
		}
		return &Error{int(code), msg.String()}
	}
	return nil
}