///////////////////////////////////////////////////////////////////// // RecScan.cpp - Recursively opens included files and invokes // // a processing action on them // // // // Lanaguage: Visual C++ 2005 // // Platform: Dell Dimension 9150, Windows XP SP2 // // Application: Prototype for CSE687 Pr1, Sp06 // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////// #include #include "RecScan.h" #include "WinTools.h" #include "SemiExpression.h" #include "Tokenizer.h" //----< constructor >------------------------------------------------ Scanner::Scanner() {} //----< scan file, recursively opening include files >--------------- void Scanner::doRecursiveScan(const std::string& file) { doFileProc(file); std::string path = Path::getPath(file); std::string lastDir = Directory::GetCurrentDirectory(); Directory::SetCurrentDirectory(path); std::string name = Path::getName(file); Toker tokr; if(tokr.attach(name)) { if(files.find(name) == files.end()) files.insert(name); } SemiExp semi(&tokr); while(semi.getSemiExp()) { doNonDestructiveProcess(); if(semi.length() > 3) { if(semi[0] == "#" && semi[1] == "include" && semi[2] != "<") { std::string newName = stripQuotes(semi[2]); doRecursiveScan(newName); } } } Directory::SetCurrentDirectory(lastDir); } // //----< strip containing quote characters >-------------------------- std::string Scanner::stripQuotes(const std::string& tok) { std::string temp; for(size_t i=1; i-------------------------------- void Scanner::doFileProc(const std::string& file) { std::string name = Path::getName(file); if(files.find(name) != files.end()) return; std::cout << "\n current path = " << Directory::GetCurrentDirectory(); std::cout << "\n Processing path: " << Path::getPath(file); std::cout << ", Processing file: " << name; std::cout << std::endl; } //----< process SemiExp without changing it >------------------------ void Scanner::doNonDestructiveProcess() { // do something useful with the SemiExp here } // //----< test stub >-------------------------------------------------- #ifdef TEST_RECSCAN void main(int argc, char* argv[]) { std::cout << "\n Testing RecScan Module"; std::cout << "\n ------------------------\n"; Directory dir; Scanner scanr; std::cout << "\n starting at path: " << Directory::GetCurrentDirectory(); std::cout << std::endl; for(int i=1; i files = scanr.filesProcessed(); std::set::iterator iter; for(iter = files.begin(); iter != files.end(); ++iter) std::cout << "\n " << *iter; std::cout << std::endl; std::cout << "\n\n"; } #endif