Last active
August 29, 2015 14:14
-
-
Save yorung/6a68558d4b5304688f97 to your computer and use it in GitHub Desktop.
parsing OpenGL extension header files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct GLFunc | |
{ | |
GLFunc(){} | |
GLFunc(const GLFunc& r) { | |
*this = r; | |
} | |
const GLFunc& operator=(const GLFunc& r) { | |
name = r.name; | |
decl = r.decl; | |
caster = r.caster; | |
return *this; | |
} | |
std::string name; | |
std::string decl; | |
std::string caster; | |
}; | |
std::vector<GLFunc> glFuncs; | |
void ParseHeader(const char* healderFileName, const char* regExp, const char* conventions) | |
{ | |
char* h = (char*)LoadFile(healderFileName); | |
std::string str = h; | |
std::regex pattern(regExp); | |
auto funcBegin = std::sregex_iterator(str.begin(), str.end(), pattern); | |
auto End = std::sregex_iterator(); | |
int dist = std::distance(funcBegin, End); | |
printf("%d functions found in %s\n", dist, healderFileName); | |
int i = 0; | |
for (auto it = funcBegin; it != End; it++) { | |
std::smatch m = *it; | |
if (m.size() < 4) { | |
continue; | |
} | |
GLFunc func; | |
func.name = m[2].str(); | |
func.decl = m[1].str() + "(" + conventions + "*" + m[2].str() + ")" + m[3].str(); | |
func.caster = m[1].str() + "(" + conventions + "*)" + m[3].str(); | |
glFuncs.push_back(func); | |
printf("\r%d/%d", ++i, dist); | |
} | |
printf("\n"); | |
free(h); | |
} | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
ParseHeader("glheaders/glcorearb.h", "^GLAPI\\s+([\\w\\s\\*]+)APIENTRY\\s+(gl\\w+)\\s*(\\(.*\\))", "APIENTRY"); | |
ParseHeader("glheaders/wglext.h", "^(\\w+(?:\\s+\\w+)*\\s+)WINAPI\\s+(wgl\\w+)\\s*(\\(.*\\))", "WINAPI"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment