diff --git a/uppdev/cpp/cpp.cpp b/uppdev/cpp/cpp.cpp index c6907bab4..81c473b70 100644 --- a/uppdev/cpp/cpp.cpp +++ b/uppdev/cpp/cpp.cpp @@ -256,6 +256,22 @@ String Cpp::Preprocess(Stream& in, bool needresult) if(p.IsId()) macro.UnlinkKey(p.ReadId()); } + else + if(strncmp(s + 1, "include", 7) == 0 && level < 100) { + String path = GetIncludePath(s + 8); + DDUMP(path); + if(path.GetCount()) { + Cpp inc; + inc.level = level + 1; + inc.filedir = filedir; + inc.include_path = include_path; + FileIn in(path); + inc.Preprocess(in, false); + inc.macro.Sweep(); + for(int i = 0; i < inc.macro.GetCount(); i++) + macro.GetAdd(inc.macro.GetKey(i)) = inc.macro[i]; + } + } } else if(needresult) @@ -272,7 +288,11 @@ String Cpp::Preprocess(Stream& in, bool needresult) incomment = false; s += 2; } - s++; + else + if(s[0] == '/' && s[1] == '/' && !incomment) + break; + else + s++; } } if(needresult) @@ -281,3 +301,27 @@ String Cpp::Preprocess(Stream& in, bool needresult) } return result; } + +String Cpp::GetIncludePath(const char *s) +{ + while(IsSpace(*s)) + s++; + int type = *s; + if(type == '<' || type == '\"' || type == '?') { + s++; + String name; + if(type == '<') type = '>'; + while(*s != '\r' && *s != '\n') { + if(*s == type) { + if(type == '\"') { + String fn = NormalizePath(name, filedir); + if(FileExists(fn)) + return fn; + } + return GetFileOnPath(name, include_path, false); + } + name.Cat(*s++); + } + } + return Null; +} diff --git a/uppdev/cpp/cpp.h b/uppdev/cpp/cpp.h index 7e2bdab27..135e9e3fe 100644 --- a/uppdev/cpp/cpp.h +++ b/uppdev/cpp/cpp.h @@ -21,6 +21,10 @@ struct CppMacro : Moveable { struct Cpp { bool incomment; VectorMap macro; + + String filedir; + String include_path; + int level; void Define(const char *s); @@ -28,9 +32,10 @@ struct Cpp { void ParamAdd(Vector& param, const char *b, const char *e); String Expand(const char *s); + void Include(const char *s); + String GetIncludePath(const char *s); String Preprocess(Stream& in, bool needresult = true); }; - #endif diff --git a/uppdev/cpp/main.cpp b/uppdev/cpp/main.cpp index 7c6d4fa11..1e437598d 100644 --- a/uppdev/cpp/main.cpp +++ b/uppdev/cpp/main.cpp @@ -55,8 +55,11 @@ CONSOLE_APP_MAIN DUMP(x.Expand("This is: TEST( \"1\" \"2\" \",\", ',')!")); */ Cpp x; - FileIn in0("C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include\\crtdefs.h"); - x.Preprocess(in0); + x.filedir = GetFileFolder(GetDataFile("x")); + x.include_path = "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include;C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Include;C:\\OpenSSL-Win32\\include;C:\\u\\pgsql\\include;C:\\u\\OpenSSL-Win32\\include"; + x.level = 0; +// FileIn in0("C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include\\crtdefs.h"); +// x.Preprocess(in0); // FileIn in("C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include\\string.h"); FileIn in(GetDataFile("test.h")); LOG(x.Preprocess(in)); diff --git a/uppdev/cpp/test.h b/uppdev/cpp/test.h index 4005becc4..0940682bc 100644 --- a/uppdev/cpp/test.h +++ b/uppdev/cpp/test.h @@ -1,4 +1,7 @@ #include +#include +#include +#include #define eprintf(x, ...) if(x) printf(__VA_ARGS__)