bool CGptBind::run( ) { ifstream in((_options->sourcefile+".sld").c_str()); GptBindLexer lexer(in); GptBindParser parser(lexer); // string asmProgram = parser.program(_options->sourcefile); parser.sld_grammar(_options->sourcefile); string cppOutput = parser.getCpp(); string hppOutput = parser.getHpp(); string makefileOutput = parser.getMakefile(); ofstream cppFile((_options->destfile + ".cpp").c_str(), ios_base::out); if (!cppFile) { cout << "ERRO: não foi possível abrir o arquivo: \"" << _options->destfile << "\"" << endl; return false; } cppFile << cppOutput; ofstream hppFile((_options->destfile + ".hpp").c_str(), ios_base::out); if (!hppFile) { cout << "ERRO: não foi possível abrir o arquivo: \"" << _options->destfile << "\"" << endl; return false; } hppFile << hppOutput; ofstream makefileFile(("Makefile." + _options->destfile).c_str(), ios_base::out); if (!makefileFile) { cout << "ERRO: não foi possível abrir o arquivo: \"" << _options->destfile << "\"" << endl; return false; } makefileFile << makefileOutput; return true; }
void D3D11InterfaceWriter::writeCpp(const string &outputCpp) { auto templateLinesA = util::getFileLines(dataDir + "d3d11InterfaceTemplate.txt"); auto templateLinesB = util::getFileLines(dataDir + "d3d11InterfaceVoidTemplate.txt"); ofstream cppFile(outputCpp); cppFile << endl << "#include \"main.h\"" << endl; cppFile << endl; for (const D3D11InterfaceFunction &func : functions) { for (const string &templateLine : func.returnType == "void" ? templateLinesB : templateLinesA) { string line = util::replace(templateLine, "#FunctionName#", func.name); line = util::replace(line, "#FunctionParameters#", func.getParameterList()); line = util::replace(line, "#FunctionParameterCall#", func.getParameterCallList()); line = util::replace(line, "#FunctionReturn#", func.returnType); line = util::replace(line, "#InterfaceName#", name); cppFile << line << endl; } cppFile << endl; } }
int main(int argc, char *argv[]){ if(argc>1){ TFile inFile(argv[1],"read"); if(inFile.IsOpen() && !inFile.IsZombie()){ std::ofstream cppFile("src/cfa.cpp"), hppFile("inc/cfa.hpp"); {TTree t("a","b");}//Magically make ROOT link things correctly... TChain *chainA(static_cast<TChain*>(inFile.Get("configurableAnalysis/eventA"))), *chainB(static_cast<TChain*>(inFile.Get("configurableAnalysis/eventB"))); if(chainA!=NULL && chainB!=NULL){ hppFile << "#ifndef H_CFA\n"; hppFile << "#define H_CFA\n\n"; hppFile << "#include <vector>\n"; hppFile << "#include <string>\n"; hppFile << "#include \"TChain.h\"\n"; hppFile << "#include \"TBranch.h\"\n\n"; hppFile << "class cfA{\n"; hppFile << "public:\n"; hppFile << " int GetTotalEntries() const;\n"; hppFile << "protected:\n"; hppFile << " cfA(const std::string&, const bool);\n"; hppFile << " TChain chainA, chainB;\n"; hppFile << " TChain* GetChainA();\n"; hppFile << " TChain* GetChainB();\n"; hppFile << " std::string GetSampleName() const;\n"; hppFile << " int GetEntry(const unsigned int);\n"; hppFile << " void SetFile(const std::string&, const bool);\n\n"; hppFile << " std::string sampleName;\n"; hppFile << " int totalEntries;\n"; hppFile << " short cfAVersion;\n\n"; hppFile << " void GetVersion();\n"; hppFile << " void AddFiles(const std::string&, const bool);\n"; hppFile << " void CalcTotalEntries();\n"; hppFile << " void PrepareNewChains();\n"; hppFile << " void InitializeA();\n"; hppFile << " void InitializeB();\n\n"; PrintLeaves(chainA, hppFile); PrintBranches(chainA, hppFile); PrintLeaves(chainB, hppFile); PrintBranches(chainB, hppFile); hppFile << "};\n\n"; hppFile << "#endif" << std::endl; cppFile << "#include \"cfa.hpp\"\n"; cppFile << "#include <vector>\n"; cppFile << "#include <string>\n"; cppFile << "#include <fstream>\n"; cppFile << "#include <sstream>\n"; cppFile << "#include \"TChain.h\"\n"; cppFile << "#include \"TBranch.h\"\n\n"; cppFile << "cfA::cfA(const std::string& fileIn, const bool isList):\n"; cppFile << " chainA(\"eventA\"),\n"; cppFile << " chainB(\"eventB\"),\n"; cppFile << " sampleName(fileIn),\n"; cppFile << " totalEntries(0),\n"; cppFile << " cfAVersion(-1),\n"; PrintNullInit(chainA, cppFile); PrintBranchInit(chainA, cppFile); cppFile << ",\n"; PrintNullInit(chainB, cppFile); PrintBranchInit(chainB, cppFile); cppFile << "{\n"; cppFile << " GetVersion();\n"; cppFile << " AddFiles(fileIn, isList);\n"; cppFile << " PrepareNewChains();\n"; cppFile << "}\n\n"; cppFile << "void cfA::GetVersion(){\n"; cppFile << " size_t pos(sampleName.rfind(\"_v\"));\n"; cppFile << " if(pos!=std::string::npos && pos<sampleName.size()-2){\n"; cppFile << " std::istringstream iss(sampleName.substr(pos+2));\n"; cppFile << " iss >> cfAVersion;\n"; cppFile << " if(iss.fail() || iss.bad()){\n"; cppFile << " cfAVersion=-1;\n"; cppFile << " }\n"; cppFile << " }\n"; cppFile << "}\n\n"; cppFile << "void cfA::PrepareNewChains(){\n"; cppFile << " InitializeA();\n"; cppFile << " InitializeB();\n"; cppFile << " CalcTotalEntries();\n"; cppFile << "}\n\n"; cppFile << "void cfA::AddFiles(const std::string& fileIn, const bool isList){\n"; cppFile << " if(isList){\n"; cppFile << " std::ifstream infile(fileIn.c_str());\n"; cppFile << " std::string file(\"\");\n"; cppFile << " while(infile >> file){\n"; cppFile << " chainA.Add((file+\"/configurableAnalysis/eventA\").c_str());\n"; cppFile << " chainB.Add((file+\"/configurableAnalysis/eventB\").c_str());\n"; cppFile << " }\n"; cppFile << " infile.close();\n"; cppFile << " }else{\n"; cppFile << " chainA.Add((fileIn+\"/configurableAnalysis/eventA\").c_str());\n"; cppFile << " chainB.Add((fileIn+\"/configurableAnalysis/eventB\").c_str());\n"; cppFile << " }\n"; cppFile << "}\n\n"; cppFile << "void cfA::SetFile(const std::string& fileIn, const bool isList){\n"; cppFile << " chainA.Reset(); chainB.Reset();\n"; cppFile << " AddFiles(fileIn, isList);\n"; cppFile << "}\n\n"; cppFile << "int cfA::GetEntry(const unsigned int entryIn){\n"; cppFile << " return chainA.GetEntry(entryIn)+chainB.GetEntry(entryIn);\n"; cppFile << "}\n\n"; cppFile << "void cfA::CalcTotalEntries(){\n"; cppFile << " const int nEntriesA(chainA.GetEntries()), nEntriesB(chainB.GetEntries());\n"; cppFile << " if (nEntriesA!=nEntriesB){\n"; cppFile << " totalEntries=-1;\n"; cppFile << " }else{\n"; cppFile << " totalEntries=nEntriesA;\n"; cppFile << " }\n"; cppFile << "}\n\n"; cppFile << "TChain* cfA::GetChainA(){\n"; cppFile << " return &chainA;\n"; cppFile << "}\n\n"; cppFile << "TChain* cfA::GetChainB(){\n"; cppFile << " return &chainB;\n"; cppFile << "}\n\n"; cppFile << "std::string cfA::GetSampleName() const{\n"; cppFile << " return sampleName;\n"; cppFile << "}\n\n"; cppFile << "int cfA::GetTotalEntries() const{\n"; cppFile << " return totalEntries;\n"; cppFile << "}\n\n"; cppFile << "void cfA::InitializeA(){\n"; PrintSetNull(chainA, cppFile); PrintSetBranchAddressA(chainA, cppFile); cppFile << "}\n\n"; cppFile << "void cfA::InitializeB(){\n"; PrintSetNull(chainB, cppFile); PrintSetBranchAddressB(chainB, cppFile); cppFile << "}\n\n"; }else{ std::cout << "Warning in " << argv[0] << ": one or both of chainA and chainB are NULL (" << chainA << " and " << chainB << ").\n"; } inFile.Close(); cppFile.close(); hppFile.close(); }else{ std::cout << "Warning in " << argv[0] << ": Could not open " << argv[1] << ".\n"; } } }
void TestRunner::compile() { // Check when is the last time that the test source has been modified const QString filePath = inDir_.filePath(fileName_); const QFileInfo fileInfo(filePath); const QDateTime lastModified = fileInfo.lastModified(); // Compile if necessary Status s = status(); bool notCompiledYet = (s == Status::NotCompiledYet) || (s == Status::CompileError); bool modified = (lastCompiled_ < lastModified); bool processing = (s == Status::Compiling) || (s == Status::Running); if (notCompiledYet || (modified && !processing)) { setStatus_(Status::Compiling); compileOutput_.clear(); lastCompiled_ = lastModified; // -------- Go to folder where to compile test -------- QString compileDirPath = outDir_.absoluteFilePath(testName_); compileDir_ = outDir_; if (!compileDir_.cd(testName_)) { // Create folder since it doesn't exist if (!outDir_.mkdir(testName_)) { failCompilation_("Can't create build folder " + compileDirPath); return; } // Go to folder where to compile test // This is hard to reach (if we manage to create the folder, surely // we can cd to it), but doesn't hurt to check. if (!compileDir_.cd(testName_)) { failCompilation_("Can't create build folder " + compileDirPath); return; } } // -------- Open all files for reading or writing -------- const QString hFileName = testName_ + ".gen.h"; const QString cppFileName = testName_ + ".gen.cpp"; const QString proFileName = testName_ + ".gen.pro"; const QString hFilePath = compileDir_.filePath(hFileName); const QString cppFilePath = compileDir_.filePath(cppFileName); const QString proFilePath = compileDir_.filePath(proFileName); QFile sourceFile(filePath); QFile hFile(hFilePath); QFile cppFile(cppFilePath); QFile proFile(proFilePath); if (!sourceFile.open(QFile::ReadOnly | QFile::Text)) { failCompilation_("Can't open " + filePath); return; } if (!hFile.open(QFile::WriteOnly | QFile::Text)) { failCompilation_("Can't write " + hFilePath); return; } if (!cppFile.open(QFile::WriteOnly | QFile::Text)) { failCompilation_("Can't write " + cppFilePath); return; } if (!proFile.open(QFile::WriteOnly | QFile::Text)) { failCompilation_("Can't write " + proFilePath); return; } // -------- Read source file -------- QTextStream sourceStream(&sourceFile); const QString testSource = sourceStream.readAll(); // -------- Generate and write test gen files -------- QTextStream hStream(&hFile); QTextStream cppStream(&cppFile); QTextStream proStream(&proFile); hStream << generateH(testName_, testSource); cppStream << generateCpp(testName_, testSource); proStream << generatePro(testName_, testSource); // -------- Run qmake -------- QString program = QMAKE_QMAKE_QMAKE; QStringList arguments; arguments << "-spec" << QMAKE_QMAKESPEC << proFilePath; compileOutput_ += getCurrentTime() + ": Starting: \"" + program + "\" " + arguments.join(' ') + "\n"; process_->setWorkingDirectory(compileDirPath); connect(process_, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &TestRunner::compile_onQmakeFinished_); emit outputChanged(); process_->start(program, arguments); // -> go read qMakeFinished_(int exitCode) now. } else { emit compileFinished(true); } }
void wxFormBuilder::DoCreateWxFormBuilderProject(const wxFBItemInfo& data) { // add new virtual folder to the selected virtual directory wxString formbuilderVD; formbuilderVD = data.virtualFolder.BeforeFirst(wxT(':')); m_mgr->CreateGroupFolder(formbuilderVD, wxT("formbuilder")); wxString templateFile(m_mgr->GetInstallDirectory() + wxT("/templates/formbuilder/")); //todo,todo switch (data.kind) { default: case wxFBItemKind_Dialog: templateFile << wxT("DialogTemplate.fbp"); break; case wxFBItemKind_Frame: templateFile << wxT("FrameTemplate.fbp"); break; case wxFBItemKind_Panel: templateFile << wxT("PanelTemplate.fbp"); break; case wxFBItemKind_Dialog_With_Buttons: templateFile << wxT("DialogTemplateWithButtons.fbp"); break; } wxFileName tmplFile(templateFile); if (!tmplFile.FileExists()) { wxMessageBox(wxString::Format(wxT("Cant find wxFormBuilder template file '%s'"), tmplFile.GetFullPath().c_str()), wxT("EmbeddedLite"), wxOK|wxCENTER|wxICON_WARNING); return; } // place the files under the VD's project owner wxString err_msg; wxString project = data.virtualFolder.BeforeFirst(wxT(':')); ProjectPtr proj = m_mgr->GetSolution()->FindProjectByName(project, err_msg); if (proj) { wxString files_path = proj->GetFileName().GetPath(wxPATH_GET_SEPARATOR|wxPATH_GET_VOLUME); // copy the file to here wxFileName fbpFile(files_path, data.file + wxT(".fbp")); if (!wxCopyFile(tmplFile.GetFullPath(), fbpFile.GetFullPath())) { wxMessageBox(wxString::Format(wxT("Failed to copy tempalte file to '%s'"), fbpFile.GetFullPath().c_str()), wxT("EmbeddedLite"), wxOK|wxCENTER|wxICON_WARNING); return; } // open the file, and replace expand its macros wxString content; if (!ReadFileWithConversion(fbpFile.GetFullPath().c_str(), content)) { wxMessageBox(wxString::Format(wxT("Failed to read file '%s'"), fbpFile.GetFullPath().c_str()), wxT("EmbeddedLite"), wxOK|wxCENTER|wxICON_WARNING); return; } content.Replace(wxT("$(BaseFileName)"), data.file); content.Replace(wxT("$(ProjectName)"), data.className); content.Replace(wxT("$(Title)"), data.title); content.Replace(wxT("$(ClassName)"), data.className); if (!WriteFileWithBackup(fbpFile.GetFullPath().c_str(), content, false)) { wxMessageBox(wxString::Format(wxT("Failed to write file '%s'"), fbpFile.GetFullPath().c_str()), wxT("EmbeddedLite"), wxOK|wxCENTER|wxICON_WARNING); return; } // add the file to the project wxArrayString paths; paths.Add(fbpFile.GetFullPath()); m_mgr->AddFilesToGroupFolder(project + wxT(":formbuilder"), paths); // // first we launch wxFB with the -g flag set wxString genFileCmd; genFileCmd << GetWxFBPath() << wxT(" -g ") << fbpFile.GetFullPath(); wxArrayString dummy, filesToAdd; ProcUtils::SafeExecuteCommand(genFileCmd, dummy); wxFileName cppFile(fbpFile.GetPath(), data.file + wxT(".cpp")); wxFileName headerFile(fbpFile.GetPath(), data.file + wxT(".h")); if (cppFile.FileExists()) { filesToAdd.Add(cppFile.GetFullPath()); } if (headerFile.FileExists()) { filesToAdd.Add(headerFile.GetFullPath()); } if (filesToAdd.GetCount()) { m_mgr->AddFilesToGroupFolder(data.virtualFolder, filesToAdd); } DoLaunchWxFB(fbpFile.GetFullPath()); } }