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/Makefile | 25 +++++++++++++-- nexgb/help.go | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ nexgb/xgb_help.go | 95 ------------------------------------------------------- 3 files changed, 117 insertions(+), 98 deletions(-) create mode 100644 nexgb/help.go delete mode 100644 nexgb/xgb_help.go diff --git a/nexgb/Makefile b/nexgb/Makefile index 7fa8b9b..6809661 100644 --- a/nexgb/Makefile +++ b/nexgb/Makefile @@ -1,10 +1,20 @@ # This Makefile is used by the developer. It is not needed in any way to build # a checkout of the XGB repository. # It will be useful, however, if you are hacking at the code generator. +# i.e., after making a change to the code generator, run 'make' in the +# xgb directory. This will build xgbgen and regenerate each sub-package. +# 'make test' will then run any appropriate tests (just tests xproto right now). +# 'make bench' will test a couple of benchmarks. +# 'make build-all' will then try to build each extension. This isn't strictly +# necessary, but it's a good idea to make sure each sub-package is a valid +# Go package. +# My path to the X protocol XML descriptions. XPROTO=/usr/share/xcb # All of the XML files in my /usr/share/xcb directory EXCEPT XKB. -_- +# This is intended to build xgbgen and generate Go code for each supported +# extension. all: build-xgbgen \ bigreq.xml composite.xml damage.xml dpms.xml dri2.xml \ ge.xml glx.xml randr.xml record.xml render.xml res.xml \ @@ -16,6 +26,7 @@ all: build-xgbgen \ build-xgbgen: (cd xgbgen && go build) +# Builds each individual sub-package to make sure its valid Go code. build-all: bigreq.b composite.b damage.b dpms.b dri2.b ge.b glx.b randr.b \ record.b render.b res.b screensaver.b shape.b shm.b sync.b xcmisc.b \ xevie.b xf86dri.b xf86vidmode.b xfixes.b xinerama.b xinput.b \ @@ -24,6 +35,8 @@ build-all: bigreq.b composite.b damage.b dpms.b dri2.b ge.b glx.b randr.b \ %.b: (cd $* ; go build) +# xc_misc is special because it has an underscore. +# There's probably a way to do this better, but Makefiles aren't my strong suit. xc_misc.xml: build-xgbgen mkdir -p xcmisc xgbgen/xgbgen --proto-path $(XPROTO) $(XPROTO)/xc_misc.xml > xcmisc/xcmisc.go @@ -32,14 +45,20 @@ xc_misc.xml: build-xgbgen mkdir -p $* xgbgen/xgbgen --proto-path $(XPROTO) $(XPROTO)/$*.xml > $*/$*.go +# Just test the xproto core protocol for now. test: (cd xproto ; go test) +# Force all xproto benchmarks to run and no tests. bench: (cd xproto ; go test -run 'nomatch' -bench '.*' -cpu 1,2,6) +# gofmt all non-auto-generated code. +# (auto-generated code is already gofmt'd.) +# Also do a column check (80 cols) after a gofmt. +# But don't check columns on auto-generated code, since I don't care if they +# break 80 cols. gofmt: - gofmt -w *.go xgbgen/*.go examples/*.go examples/*/*.go - colcheck xgbgen/*.go examples/*.go examples/*/*.go xproto/xproto_test.go \ - auth.go conn.go cookie.go doc.go xgb.go xgb_help.go + gofmt -w *.go xgbgen/*.go examples/*.go examples/*/*.go xproto/xproto_test.go + colcheck *.go xgbgen/*.go examples/*.go examples/*/*.go xproto/xproto_test.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 +} diff --git a/nexgb/xgb_help.go b/nexgb/xgb_help.go deleted file mode 100644 index 36fe98b..0000000 --- a/nexgb/xgb_help.go +++ /dev/null @@ -1,95 +0,0 @@ -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