// This scripts analyze the text of:
// http://www.opengl.org/sdk/docs/man/xhtml/glGet.html
// and extracts parameter name and length that can be retrieved
// by glGetBooleanv(), glGetDoublev(), glGetFloatv() and glGetIntegerv().

import(re)

constOKNames = (re.match(r"^#define\s+(GL_\w+)", open("gl.h").readlines()):xiter):*group(1)
lines = open("b").readlines()
stat = `start
constNames = []
counts = []
for (line in lines) {
	if (stat == `start) {
		m = re.match(r"^(GL_\w+)", line)
		if (m) {
			constNames.add(m.group(1))
			stat = `follower
		}
	} elsif (stat == `follower) {
		m = re.match(r"returns +(.+)$", line)
		if (m) {
			text = m.group(1)
			if (re.match(r"^one", text)) {
				num = "1"
			} elsif (re.match(r"^two", text)) {
				num = "2"
			} elsif (re.match(r"^three", text)) {
				num = "3"
			} elsif (re.match(r"^four", text)) {
				num = "4"
			} elsif (re.match(r"^sixteen", text)) {
				num = "16"
			} elsif (re.match(r"^a single", text)) {
				num = "1"
			} elsif (m = re.match(r"^(\d+)", text)) {
				num = m.group(1)
			} else {
				num = "0 /* " + text + " */"
			}
			counts.add(num)
			stat = `start
		}
	}
}
padlen = constNames:*len().max() + 2
for (constName in constNames, count in counts) {
	if (constName in constOKNames) {
		text = "{ " + constName + ","
		printf("{ %-*s %2s },\n", padlen, constName + ",", count)
	}
}
