From d26d15300db01c4eb131efdb267d04fe8b724c7f Mon Sep 17 00:00:00 2001 From: adrien-matta <a.matta@surrey.ac.uk> Date: Thu, 24 Dec 2015 15:06:45 +0100 Subject: [PATCH] * Progress on nptool-wizard - now behave correctly i ntaking data year and authorship - Updated command for creation of the folder in the right place --- NPLib/Utility/nptool-wizard.cxx | 88 ++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 17 deletions(-) diff --git a/NPLib/Utility/nptool-wizard.cxx b/NPLib/Utility/nptool-wizard.cxx index 64e785dae..a6cf05c10 100644 --- a/NPLib/Utility/nptool-wizard.cxx +++ b/NPLib/Utility/nptool-wizard.cxx @@ -1,20 +1,54 @@ #include<iostream> -#include<stdlib.h> +#include<sstream> +#include<stdlib.h> +#include<ctime> +#include"NPVDetector.h" int main(int argc , char** argv){ - // Go to npl + // Find the different path std::string path = getenv("NPTOOL"); - std::string pathNPL = path+ "/NPLib/"; + std::string pathNPL = path+ "/NPLib/Detectors/"; std::string pathNPS = path+"/NPSimulation/"; std::string pwd = getenv("PWD"); - + int return_value = -1 ; std::string command; std::string answer; - std::string author,firstname,surname; + std::string author,buffer; std::string email; - // TODO // - std::string year = "2015"; + + // Get the current year and month + time_t t = time(0); + struct tm* now = localtime( & t ); + std::string month; + switch(now->tm_mon + 1){ + case 1: + month = "January"; + case 2: + month = "February"; + case 3: + month = "March"; + case 4: + month = "April"; + case 5: + month = "May"; + case 6: + month = "June"; + case 7: + month = "July"; + case 8: + month = "August"; + case 9: + month = "September"; + case 10: + month = "October"; + case 11: + month = "November"; + case 12: + month = "December"; + } + + std::string year = NPL::itoa(now->tm_year+1900); ////////// bool check = true; std::cout << "\r\033[1;32m" << std::endl << std::endl; @@ -25,12 +59,15 @@ int main(int argc , char** argv){ std::cout << " This utility will create a new detector skeleton"<< std::endl; std::cout << "\033[1;36m-> What is the detector name ? \033[0m" ; std::cin >> answer ; - std::cout << "\033[1;36m-> What is your name (FirstName Surname)? \033[0m" ; - std::cin >> firstname >> surname ; - author = firstname + " " + surname ; + std::cout << "\033[1;36m-> What is your name (firstname and surname)? \033[0m" ; + std::cin >> author; + getline(cin, buffer); + istringstream oss(buffer); + while(oss>> buffer) + author +=" " + buffer ; std::cout << "\033[1;36m-> What is your email? \033[0m" ; std::cin >> email ; - + std::cout << std::endl << std::endl; // Cheking if the name does not already exist or is close to something else: @@ -61,7 +98,24 @@ int main(int argc , char** argv){ command = "sed -i '' -e \"s/DETECTORNAME/"+ answer +"/g\" " + pathNPL + answer +"/* > /dev/null 2> /dev/null"; return_value = system(command.c_str()); - + + command = "sed -i '' -e \"s/XAUTHORX/"+ author+"/g\" " + + pathNPL + answer +"/* > /dev/null 2> /dev/null"; + return_value = system(command.c_str()); + + command = "sed -i '' -e \"s/XMAILX/"+ email+"/g\" " + + pathNPL + answer +"/* > /dev/null 2> /dev/null"; + return_value = system(command.c_str()); + + command = "sed -i '' -e \"s/XYEARX/"+ year +" /g\" " + + pathNPL + answer +"/* > /dev/null 2> /dev/null"; + return_value = system(command.c_str()); + + command = "sed -i '' -e \"s/XMONTHX/"+ month +"/g\" " + + pathNPL + answer +"/* > /dev/null 2> /dev/null"; + return_value = system(command.c_str()); + + command = "mv " + pathNPL + answer +"/TDETECTORNAMEData.h " + pathNPL + answer + "/" + DataFile_h ; return_value = system(command.c_str()); @@ -84,15 +138,15 @@ int main(int argc , char** argv){ return_value = system(command.c_str()); // Create nps folder - + // Add nps file // Add input file - + // Provide a list of created file std::cout << "\t List of created files to\033[1;35m edit \033[0m:" << std::endl; std::cout << "\t NPLib :" << std::endl; - std::cout << "\t\t -> Folder: " << answer << std::endl; + std::cout << "\t\t -> Folder: Detectors/" << answer << std::endl; std::cout << "\t\t -> Data Class: \033[1;35m" << DataFile_h << "\033[0m and \033[1;35m" << DataFile_cxx << "\033[0m" << std::endl; std::cout << "\t\t -> Physics Class: \033[1;35m" << PhysicsFile_h @@ -101,7 +155,7 @@ int main(int argc , char** argv){ << "\033[0m and \033[1;35m" << SpectraFile_cxx << "\033[0m" << std::endl; std::cout << std::endl; std::cout << "\tNPSimulation :" << std::endl; - std::cout << "\t\t -> Folder: " << answer << std::endl; + std::cout << "\t\t -> Folder: Detectors/" << answer << std::endl; std::cout << "\t\t -> Detector Class: \033[1;35m" << SimFile_h << "\033[0m and \033[1;35m" << SimFile_cxx << "\033[0m" << std::endl; std::cout << std::endl; @@ -116,6 +170,6 @@ int main(int argc , char** argv){ // Adding file to git // TODO // ////////// - + return 0; } -- GitLab