From f77feff864545c590ad4f717ecf47278703e1792 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sat, 12 May 2012 21:27:47 -0400 Subject: some docs in the Makefile and removing a prefix that isn't needed. --- nexgb/help.go | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 nexgb/help.go (limited to 'nexgb/help.go') diff --git a/nexgb/help.go b/nexgb/help.go new file mode 100644 index 0000000..36fe98b --- /dev/null +++ b/nexgb/help.go @@ -0,0 +1,95 @@ +package xgb + +import ( + "fmt" + "strings" +) + +// StringsJoin is an alias to strings.Join. It allows us to avoid having to +// import 'strings' in each of the generated Go files. +func StringsJoin(ss []string, sep string) string { + return strings.Join(ss, sep) +} + +// Sprintf is so we don't need to import 'fmt' in the generated Go files. +func Sprintf(format string, v ...interface{}) string { + return fmt.Sprintf(format, v...) +} + +// Errorf is just a wrapper for fmt.Errorf. Exists for the same reason +// that 'stringsJoin' and 'sprintf' exists. +func Errorf(format string, v ...interface{}) error { + return fmt.Errorf(format, v...) +} + +// Pad a length to align on 4 bytes. +func Pad(n int) int { + return (n + 3) & ^3 +} + +// popCount counts the number of bits set in a value list mask. +func PopCount(mask0 int) int { + mask := uint32(mask0) + n := 0 + for i := uint32(0); i < 32; i++ { + if mask&(1<> 8) +} + +// Put32 takes a 32 bit integer and copies it into a byte slice. +func Put32(buf []byte, v uint32) { + buf[0] = byte(v) + buf[1] = byte(v >> 8) + buf[2] = byte(v >> 16) + buf[3] = byte(v >> 24) +} + +// Put64 takes a 64 bit integer and copies it into a byte slice. +func Put64(buf []byte, v uint64) { + buf[0] = byte(v) + buf[1] = byte(v >> 8) + buf[2] = byte(v >> 16) + buf[3] = byte(v >> 24) + buf[4] = byte(v >> 32) + buf[5] = byte(v >> 40) + buf[6] = byte(v >> 48) + buf[7] = byte(v >> 56) +} + +// Get16 constructs a 16 bit integer from the beginning of a byte slice. +func Get16(buf []byte) uint16 { + v := uint16(buf[0]) + v |= uint16(buf[1]) << 8 + return v +} + +// Get32 constructs a 32 bit integer from the beginning of a byte slice. +func Get32(buf []byte) uint32 { + v := uint32(buf[0]) + v |= uint32(buf[1]) << 8 + v |= uint32(buf[2]) << 16 + v |= uint32(buf[3]) << 24 + return v +} + +// Get64 constructs a 64 bit integer from the beginning of a byte slice. +func Get64(buf []byte) uint64 { + v := uint64(buf[0]) + v |= uint64(buf[1]) << 8 + v |= uint64(buf[2]) << 16 + v |= uint64(buf[3]) << 24 + v |= uint64(buf[4]) << 32 + v |= uint64(buf[5]) << 40 + v |= uint64(buf[6]) << 48 + v |= uint64(buf[7]) << 56 + return v +} -- cgit v1.2.3-70-g09d2 From 24fef4062ad441c935f5a87e908c5f293d8a2f42 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sat, 12 May 2012 21:36:31 -0400 Subject: docs --- nexgb/auth.go | 10 ++++++---- nexgb/conn.go | 7 +++++++ nexgb/help.go | 10 ++++++++++ nexgb/sync.go | 2 +- nexgb/xgb.go | 7 +++++-- 5 files changed, 29 insertions(+), 7 deletions(-) (limited to 'nexgb/help.go') diff --git a/nexgb/auth.go b/nexgb/auth.go index 85e2d56..396e832 100644 --- a/nexgb/auth.go +++ b/nexgb/auth.go @@ -1,9 +1,11 @@ -// Copyright 2009 The XGB Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - package xgb +/* +auth.go contains functions to facilitate the parsing of .Xauthority files. + +It is largely unmodified from the original XGB package that I forked. +*/ + import ( "bufio" "errors" diff --git a/nexgb/conn.go b/nexgb/conn.go index 662a059..9baf86c 100644 --- a/nexgb/conn.go +++ b/nexgb/conn.go @@ -1,5 +1,12 @@ package xgb +/* +conn.go contains a couple of functions that do some real dirty work related +to the initial connection handshake with X. + +This code is largely unmodified from the original XGB package that I forked. +*/ + import ( "errors" "fmt" diff --git a/nexgb/help.go b/nexgb/help.go index 36fe98b..5729917 100644 --- a/nexgb/help.go +++ b/nexgb/help.go @@ -1,5 +1,15 @@ package xgb +/* +help.go is meant to contain a rough hodge podge of functions that are mainly +used in the auto generated code. Indeed, several functions here are simple +wrappers so that the sub-packages don't need to be smart about which stdlib +packages to import. + +Also, the 'Get..' and 'Put..' functions are used through the core xgb package +too. (xgbutil uses them too.) +*/ + import ( "fmt" "strings" diff --git a/nexgb/sync.go b/nexgb/sync.go index d671e62..59d0de1 100644 --- a/nexgb/sync.go +++ b/nexgb/sync.go @@ -1,6 +1,6 @@ package xgb -// Sync sends a round trip request and wait for the response. +// Sync sends a round trip request and waits for the response. // This forces all pending cookies to be dealt with. // You actually shouldn't need to use this like you might with Xlib. Namely, // buffers are automatically flushed using Go's channels and round trip requests diff --git a/nexgb/xgb.go b/nexgb/xgb.go index 50cfdba..b2cf56c 100644 --- a/nexgb/xgb.go +++ b/nexgb/xgb.go @@ -166,8 +166,11 @@ type eventOrError interface{} // NewID generates a new unused ID for use with requests like CreateWindow. // If no new ids can be generated, the id returned is 0 and error is non-nil. -// Note that the value returned will need to be converted to the proper -// type. i.e., xproto.Window(id). +// This shouldn't be used directly, and is exported for use in the extension +// sub-packages. +// If you need identifiers, use the appropriate constructor. +// e.g., For a window id, use xproto.NewWindowId. For +// a new pixmap id, use xproto.NewPixmapId. And so on. func (c *Conn) NewId() (uint32, error) { xid := <-c.xidChan if xid.err != nil { -- cgit v1.2.3-70-g09d2 From e9dc18b4f9a6a3f02dceaef93bafee3c826b8dd3 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Mon, 4 Jun 2012 23:55:20 -0400 Subject: Doc fix. --- nexgb/help.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nexgb/help.go') diff --git a/nexgb/help.go b/nexgb/help.go index 5729917..f692442 100644 --- a/nexgb/help.go +++ b/nexgb/help.go @@ -37,7 +37,7 @@ func Pad(n int) int { return (n + 3) & ^3 } -// popCount counts the number of bits set in a value list mask. +// PopCount counts the number of bits set in a value list mask. func PopCount(mask0 int) int { mask := uint32(mask0) n := 0 -- cgit v1.2.3-70-g09d2