8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-26 08:03:03 +01:00
firebird-mirror/src/misc/makeHeader.cpp

84 lines
1.3 KiB
C++
Raw Normal View History

2005-12-18 18:47:43 +01:00
#include <stdio.h>
#include <string.h>
#include <errno.h>
//#ifdef HAVE_UNISTD_H
2005-12-18 18:47:43 +01:00
#include <unistd.h>
//#endif
2005-12-18 18:47:43 +01:00
2008-12-05 02:20:14 +01:00
void ProcessFile(FILE *in, bool stripFirstComment)
2005-12-18 18:47:43 +01:00
{
char s[256];
bool striping = false;
2014-02-25 07:13:30 +01:00
while (fgets(s, sizeof(s), in))
{
if (stripFirstComment)
{
2005-12-18 18:47:43 +01:00
char *x = strstr(s, "/*");
2014-02-25 07:13:30 +01:00
if (x)
{
2005-12-18 18:47:43 +01:00
striping = true;
stripFirstComment = false;
continue;
}
}
2014-02-25 07:13:30 +01:00
if (striping)
{
2005-12-18 18:47:43 +01:00
char *x = strstr(s, "*/");
if (x) {
striping = false;
}
continue;
}
const char* include = "#include";
2014-02-25 07:13:30 +01:00
if (memcmp(s, include, strlen(include)))
{
2005-12-18 18:47:43 +01:00
fputs(s, stdout);
continue;
}
char *p = strchr(s, '<');
2014-02-25 07:13:30 +01:00
if (p)
{
fputs(s, stdout);
continue;
}
2006-07-25 15:06:02 +02:00
p = strchr(s, '"');
2005-12-18 18:47:43 +01:00
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 (const char* x)
2005-12-18 18:47:43 +01:00
{
fprintf(stderr, "%s\n", x);
return 1;
}
return 0;
}