From 7683ae4b538e312e1d8412392a25c7da94e48ad6 Mon Sep 17 00:00:00 2001 From: alexpeshkoff Date: Sun, 18 Dec 2005 17:47:43 +0000 Subject: [PATCH] simple utility to build public ibase.h --- src/misc/makeHeader.cpp | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/misc/makeHeader.cpp diff --git a/src/misc/makeHeader.cpp b/src/misc/makeHeader.cpp new file mode 100644 index 0000000000..9a11a60d78 --- /dev/null +++ b/src/misc/makeHeader.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include + + +void ProcessFile(FILE *in, bool stripFirstComment) +{ + char s[256]; + bool striping = false; + while(fgets(s, sizeof(s), in)) { + if (stripFirstComment) { + char *x = strstr(s, "/*"); + if (x) { + striping = true; + stripFirstComment = false; + continue; + } + } + if (striping) { + char *x = strstr(s, "*/"); + if (x) { + striping = false; + } + continue; + } + const char* include = "#include"; + if (memcmp(s, include, strlen(include))) { + fputs(s, stdout); + continue; + } + char *p = strchr(s, '"'); + if (! p) { + throw "#include misses \" - start of filename"; + } + ++p; + char *p2 = strchr(p, '"'); + if (! p2) { + throw "#include misses \" - end of filename"; + } + *p2 = 0; + p2 = strrchr(p, '/'); // always open files in current directory + if (p2) { + p = p2 + 1; + } + FILE *newIn = fopen(p, "rt"); + if (! newIn) { + continue; + } + ProcessFile(newIn, true); + fclose(newIn); + // clean after Makefile's cp + unlink(p); + } +} + + +int main() +{ + try { + ProcessFile(stdin, false); + } + catch(char* x) + { + fprintf(stderr, "%s\n", x); + return 1; + } + return 0; +}