diff --git a/src/preprocessor.cpp b/src/preprocessor.cpp index feaad8128..a1bd1fcf2 100644 --- a/src/preprocessor.cpp +++ b/src/preprocessor.cpp @@ -24,6 +24,7 @@ #include #include +#include #ifdef __BORLANDC__ #include @@ -255,11 +256,10 @@ void Preprocessor::preprocess(std::istream &istr, std::string &processedFile, st // Remove space characters that are after or before new line character processedFile = removeSpaceNearNL(processedFile); - processedFile = replaceIfDefined(processedFile); - -// TODO, uncomment below when handling of includes is implemented well enough // processedFile = handleIncludes(processedFile); + processedFile = replaceIfDefined(processedFile); + // Get all possible configurations.. resultConfigurations = getcfgs(processedFile); } @@ -487,9 +487,22 @@ std::string Preprocessor::handleIncludes(std::string code) continue; // filename contains now a file name e.g. "menu.h" + std::ifstream fin(filename.c_str()); + std::string processedFile = Preprocessor::read(fin); + if (processedFile.length() > 0) + { + // Replace all tabs with spaces.. + std::replace(processedFile.begin(), processedFile.end(), '\t', ' '); - // TODO, add the file here, except do not mess up with the line numbers. - // So me must tokenize, before we can append. + // Remove all indentation.. + if (!processedFile.empty() && processedFile[0] == ' ') + processedFile.erase(0, processedFile.find_first_not_of(" ")); + + // Remove space characters that are after or before new line character + processedFile = removeSpaceNearNL(processedFile); + processedFile = "#file " + filename + "\n" + processedFile + "#endfile"; + code.insert(pos, processedFile); + } } return code; diff --git a/src/preprocessor.h b/src/preprocessor.h index 47491ace6..0125fa423 100644 --- a/src/preprocessor.h +++ b/src/preprocessor.h @@ -53,7 +53,7 @@ public: void preprocess(std::istream &istr, std::string &processedFile, std::list &resultConfigurations); /** Just read the code into a string. Perform simple cleanup of the code */ - std::string read(std::istream &istr); + static std::string read(std::istream &istr); /** * Get preprocessed code for a given configuration