///////////////////////////////////////////////////////////////////// // ConsoleExec.cpp - Demonstrates parsing // // // // Language: 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 // ///////////////////////////////////////////////////////////////////// /* Module Operations: ================== This module defines a console executive. Its purpose is to accept command line arguments that specify a path (argv[1]) and file patterns (argv[2], ... ), and perform a structural analysis on each of the matching files. Public Interface: ================= This Executive module provides services through a set of command-line arguments, provided to allow a user to control the files analyzed and see the results of that analysis. - if argv[1] is supplied, it specifies a path, on which to find files Otherwise, the current directory is used to search for matches. - each argument after argv[1] is interpreted as a file pattern, and the program attempts to find matching files and analyze them. Build Process: ============== Required files - ConsoleExec.cpp, ConfigureParser.h, ConfigureParser.cpp, ActionsAndRules.h, ActionsAndRules.cpp, Parser.h, Parser.cpp, SemiExpression.h, SemiExpression.cpp, tokenizer.h, tokenizer.cpp Build commands (either one) - devenv Project1HelpS06.sln - cl /EHsc ConsoleExec.cpp, ConfigureParser.cpp, ActionsAndRules.cpp \ Parser.cpp SemiExpression.cpp Tokenizer.cpp Maintenance History: ==================== ver 1.0 : 01 Feb 06 - first release */ #include #include #include #include #include "Tokenizer.h" #include "SemiExpression.h" #include "Parser.h" #include "ActionsAndRules.h" #include "ConfigureParser.h" #include "WinTools.h" // //----< retrieve files >--------------------------------------------- std::vector getFiles(const std::string& path, int argc, char* argv[]) { std::vector files; for(int i=2; i filesFromPattern; filesFromPattern = Directory::GetFiles(argv[i]); while(filesFromPattern.size() > 0) { files.push_back(filesFromPattern.back()); filesFromPattern.pop_back(); } } if(files.size() == 0) // no patterns specified, so use *.h and *.cpp { std::vector filesFromPattern = Directory::GetFiles("*.h"); while(filesFromPattern.size() > 0) { files.push_back(filesFromPattern.back()); filesFromPattern.pop_back(); } filesFromPattern = Directory::GetFiles("*.cpp"); while(filesFromPattern.size() > 0) { files.push_back(filesFromPattern.back()); filesFromPattern.pop_back(); } } std::sort(files.begin(),files.end()); return files; } //----< display missing code structures >---------------------------- void showMissing(std::map* pMap, std::string file) { std::string temp = "Structure of "; temp += file; std::cout << "\n " << temp; std::cout << "\n " << std::string(temp.size()+2,'-'); std::vector missing; file = Path::toLower(file); size_t pos = file.find(".h"); if(pos < file.size()) { if(pMap->find("ifndef") == pMap->end()) missing.push_back("ifndef"); else std::cout << "\n ifndef " << Path::toUpper((*pMap)["ifndef"]); if(pMap->find("define") == pMap->end()) missing.push_back("define"); else std::cout << "\n define " << Path::toUpper((*pMap)["define"]); if(pMap->find("language") == pMap->end()) if(pMap->find("platform") == pMap->end()) if(pMap->find("application") == pMap->end()) if(pMap->find("author") == pMap->end()) missing.push_back("prologue"); if(pMap->find("required") == pMap->end()) missing.push_back("required files"); if(pMap->find("compiler") == pMap->end()) if(pMap->find("command") == pMap->end()) missing.push_back("compiler command"); if(pMap->find("maintenance") == pMap->end()) if(pMap->find("history") == pMap->end()) missing.push_back("maintenance page"); if(pMap->find("endif") == pMap->end()) missing.push_back("endif"); } if(!(pos < file.size())) { if(pMap->find("language") == pMap->end()) if(pMap->find("platform") == pMap->end()) if(pMap->find("application") == pMap->end()) if(pMap->find("author") == pMap->end()) missing.push_back("prologue"); if(pMap->find("ifdef") == pMap->end()) missing.push_back("ifdef"); else std::cout << "\n ifdef " << Path::toUpper((*pMap)["ifdef"]); if(pMap->find("main") == pMap->end()) missing.push_back("main"); if(pMap->find("endif") == pMap->end()) missing.push_back("endif"); } if(missing.size() > 0) { std::cout << "\n missing:\n --------"; for(size_t i=0; i------------------------------------------------ int main(int argc, char* argv[]) { std::string path; if(argc > 1) path = argv[1]; // use specified directory else path = "."; // use current directory // set directory to specified path Directory dir; if(Directory::DirectoryExists(path)) { Directory::SetCurrentDirectory(path); std::cout << "\n Analyzing files on path:\n \"" << Directory::GetCurrentDirectory() << "\"\n"; } else { std::cout << "\n path \"" << path << " does not exist\n\n"; return 1; } // select files on current path, that match supplied patterns std::vector files = getFiles(path, argc, argv); for(size_t i=0; inext()) pParser->parse(); } catch(std::exception& ex) { std::cout << "\n\n " << ex.what() << "\n\n"; } std::map* pMap = Qconfigure.GetMap(); showMissing(pMap,files[i]); } std::cout << std::endl; }