Skip to content

Commit

Permalink
Add Offset and GLXRopCode parsing
Browse files Browse the repository at this point in the history
- Offset and glxopcode parsing added to funcreader.go
- Unit test for offset and glxropcode added
  • Loading branch information
chsc committed Nov 29, 2011
1 parent 668bb6d commit dbd5ddc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 0 additions & 3 deletions Makefile
Expand Up @@ -14,9 +14,6 @@ GOFILES=\

include $(GOROOT)/src/Make.cmd

test:
gotest

format:
gofmt -w *.go

Expand Down
15 changes: 15 additions & 0 deletions funcreader.go
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"regexp"
"strings"
"strconv"
)

var (
Expand All @@ -19,6 +20,8 @@ var (
funcCategoryRE = regexp.MustCompile("^[ \\t]*category[ \\t]+([^ \\t#\\n]+)")
funcVersionRE = regexp.MustCompile("^[ \\t]*version[ \\t]+([0-9]+)\\.([0-9]+)")
funcDeprecatedRE = regexp.MustCompile("^[ \\t]*deprecated[ \\t]+([0-9]+)\\.([0-9]+)")
funcOffsetRE = regexp.MustCompile("^[ \\t]*offset[ \\t]+([0-9]+)")
funcGlxRopCodeRE = regexp.MustCompile("^[ \\t]*glxropcode[ \\t]+([0-9]+)")
funcAllVersionsRE = regexp.MustCompile("^version:[ \\t]*([0-9\\. ]+)")
)

Expand Down Expand Up @@ -77,6 +80,18 @@ func ReadFunctions(r io.Reader) (FunctionCategories, []Version, error) {
return functions, versions, errors.New("Unable to parse version: " + line)
}
currentFunction.DeprecatedVersion = v
} else if offset := funcOffsetRE.FindStringSubmatch(line); offset != nil {
v, err := strconv.Atoi(offset[1])
if err != nil {
return functions, versions, errors.New("Unable to parse offset: " + line)
}
currentFunction.Offset = v
} else if glxropcode := funcGlxRopCodeRE.FindStringSubmatch(line); glxropcode != nil {
v, err := strconv.Atoi(glxropcode[1])
if err != nil {
return functions, versions, errors.New("Unable to parse glxropcode: " + line)
}
currentFunction.GlxRopCode = v
} else if allVersions := funcAllVersionsRE.FindStringSubmatch(line); allVersions != nil {
split := strings.Split(allVersions[1], " ")
for _, verString := range split {
Expand Down
4 changes: 2 additions & 2 deletions funcreader_test.go
Expand Up @@ -59,7 +59,7 @@ func TestReadFunctions(t *testing.T) {
t.Errorf("Wrong number of categories.")
}

checkFunc(&Function{"Foo1", []Parameter{{"p1", "type1", false}, {"p2", "type2", false}}, "void", Version{1, 0}, Version{0, 0}, "cat_1"}, f, t)
checkFunc(&Function{"Foo2", []Parameter{{"p1", "type3", false}}, "void", Version{2, 1}, Version{0, 0}, "cat_2"}, f, t)
checkFunc(&Function{"Foo1", []Parameter{{"p1", "type1", false}, {"p2", "type2", false}}, "void", Version{1, 0}, Version{0, 0}, "cat_1", 158, 85}, f, t)
checkFunc(&Function{"Foo2", []Parameter{{"p1", "type3", false}}, "void", Version{2, 1}, Version{0, 0}, "cat_2", 168, 95}, f, t)
// TODO: add more tests: in array, out array, glxflags, offset, ...
}
2 changes: 2 additions & 0 deletions structs.go
Expand Up @@ -71,6 +71,8 @@ type Function struct {
Version Version
DeprecatedVersion Version
Category string
Offset int
GlxRopCode int
}

type Functions []*Function
Expand Down

0 comments on commit dbd5ddc

Please sign in to comment.