Arkanjo 0.1
A tool for find code duplicated functions in codebases
Loading...
Searching...
No Matches
preprocessor.cpp
Go to the documentation of this file.
1#include "preprocessor.hpp"
2
3void Preprocessor::save_current_run_params(string path){
4 vector<string> config_content;
5
6 string path_message = PATH_MESSAGE + path;
7
8 auto end = std::chrono::system_clock::now();
9 std::time_t end_time = std::chrono::system_clock::to_time_t(end);
10 string time_message = TIME_MESSAGE + std::ctime(&end_time);
11
12 config_content.push_back(path_message);
13 config_content.push_back(time_message);
14
15 Utils::write_file_generic(Config::config()->getBasePath() + "/" + CONFIG_PATH,config_content);
16}
17
18tuple<string,double,bool> Preprocessor::read_parameters(){
19 cout << INITIAL_MESSAGE << '\n';
20 string path,similarity_message;
21
22 cout << PROJECT_PATH_MESSAGE << '\n';
23 cin >> path;
24
25 cout << MINIMUM_SIMILARITY_MESSAGE << '\n';
26 cin >> similarity_message;
27 double similarity = stod(similarity_message);
28
29 bool use_duplication_finder_by_tool=false;
30
31 while(true){
32 cout << MESSAGE_DUPLICATION_FINDER_TYPE_1 << '\n';
33 cout << MESSAGE_DUPLICATION_FINDER_TYPE_2 << '\n';
34 cout << MESSAGE_DUPLICATION_FINDER_TYPE_3 << '\n';
35 int x;
36 cin >> x;
37 if(x == 1){
38 use_duplication_finder_by_tool = true;
39 }else if(x == 2){
40 use_duplication_finder_by_tool = false;
41 }else{
42 cout << INVALID_CODE_DUPLICATION_FINDER << '\n';
43 exit(0);
44 continue;
45 }
46 break;
47 }
48
49 return {path,similarity,use_duplication_finder_by_tool};
50}
51
52void Preprocessor::preprocess(string path, double similarity, bool use_duplication_finder_by_tool){
53 cout << BREAKER_MESSAGE << '\n';
54
55 Config *config = Config::config();
56 string base_path = config->getBasePath();
57
58 string command_rm_tmp = "rm -r -f " + base_path + "/";
59 system(command_rm_tmp.c_str());
60 FunctionBreaker function_breaker(path);
61
62 cout << DUPLICATION_MESSAGE << '\n';
63
64 if(use_duplication_finder_by_tool){
65 DuplicationFinderTool duplicationFinder(base_path,similarity);
66 duplicationFinder.execute();
67 }else{
68 DuplicationFinderDiff duplicationFinder(base_path,similarity);
69 duplicationFinder.execute();
70 }
71
72 save_current_run_params(path);
73
74 cout << END_MESSAGE << '\n';
75}
76
77Preprocessor::Preprocessor(bool force_preprocess){
78 Config *config = Config::config();
79 string base_path = config->getBasePath();
80 if(force_preprocess || !Utils::does_file_exist(base_path+"/"+CONFIG_PATH)){
81 auto [path,similarity,use_duplication_finder_by_tool] = read_parameters();
82 preprocess(path,similarity,use_duplication_finder_by_tool);
83 }
84}
85
86Preprocessor::Preprocessor(bool force_preprocess, string path, double similarity){
87 Config *config = Config::config();
88 string base_path = config->getBasePath();
89 if(force_preprocess || !Utils::does_file_exist(base_path+"/"+CONFIG_PATH)){
90 preprocess(path,similarity,true);
91 }
92}
Singleton configuration manager class.
Definition config.hpp:26
static Config * config()
Gets the singleton configuration instance.
Definition config.cpp:18
string getBasePath()
Gets the current base path.
Definition config.cpp:4
Preprocessor(bool force_preprocess)
Constructs preprocessor with optional forcing.
bool does_file_exist(string file_path)
Checks if a file exists at the given path.
Definition utils.cpp:69
void write_file_generic(string file_path, vector< string > content)
Writes content to a file at specified path.
Definition utils.cpp:32
Codebase preprocessing interface.