-
Notifications
You must be signed in to change notification settings - Fork 22
/
Main.cpp
95 lines (83 loc) · 4.02 KB
/
Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "ArgumentParser.h"
#include "Duplo.h"
#include "Options.h"
#include <algorithm>
#include <iostream>
#include <iterator>
namespace {
int Clamp(int upper, int lower, int value) {
return std::max(lower, std::min(upper, value));
}
int run(long argc, const char* argv[]) {
ArgumentParser ap(argc, argv);
const int MIN_BLOCK_SIZE = 4;
const int MIN_CHARS = 3;
if (!ap.is("--help") && argc > 2) {
auto minBlockSize = ap.getInt("-ml", MIN_BLOCK_SIZE);
auto blockPercentThresholdValue = Clamp(100, 0, ap.getInt("-pt", 100));
if (blockPercentThresholdValue < 0 || 100 < blockPercentThresholdValue) {
throw std::runtime_error("-pt out of range");
}
unsigned char blockPercentThreshold = static_cast<unsigned char>(blockPercentThresholdValue);
auto numberOfFiles = ap.getInt("-n", 0);
auto minChars = ap.getInt("-mc", MIN_CHARS);
bool ignorePrepStuff = ap.is("-ip");
bool outputXml = ap.is("-xml");
bool ignoreSameFilename = ap.is("-d");
std::string listFilename(argv[argc - 2]);
std::string outputFilename(argv[argc - 1]);
Options options(
minChars,
ignorePrepStuff,
minBlockSize,
blockPercentThreshold,
numberOfFiles,
outputXml,
ignoreSameFilename,
listFilename,
outputFilename);
Duplo::Run(options);
return EXIT_SUCCESS;
} else {
std::cout << "\nNAME\n";
std::cout << " Duplo " << VERSION << " - duplicate source code block finder\n\n";
std::cout << "\nSYNOPSIS\n";
std::cout << " duplo [OPTIONS] [INTPUT_FILELIST] [OUTPUT_FILE]\n";
std::cout << "\nDESCRIPTION\n";
std::cout << " Duplo is a tool to find duplicated code blocks in large\n";
std::cout << " C/C++/Java/C#/VB.Net/Ada software systems.\n\n";
std::cout << " -ml minimal block size in lines (default is " << MIN_BLOCK_SIZE << ")\n";
std::cout << " -pt percentage of lines of duplication threshold to override -ml\n";
std::cout << " (default is 100%)\n";
std::cout << " useful for identifying whole file duplication\n";
std::cout << " -mc minimal characters in line (default is " << MIN_CHARS << ")\n";
std::cout << " lines with less characters are ignored\n";
std::cout << " -n only report for first N files\n";
std::cout << " -ip ignore preprocessor directives\n";
std::cout << " -d ignore file pairs with same name\n";
std::cout << " -xml output file in XML\n";
std::cout << " INPUT_FILELIST input filelist (specify '-' to read from stdin)\n";
std::cout << " OUTPUT_FILE output file\n";
std::cout << "\nVERSION\n";
std::cout << " " << VERSION << "\n";
std::cout << "\nAUTHORS\n";
auto authors = {
" Daniel Lidstrom ([email protected])",
" Christian M. Ammann ([email protected])",
" Trevor D'Arcy-Evans ([email protected])",
};
std::copy(std::begin(authors), std::end(authors), std::ostream_iterator<const char*>(std::cout, "\n"));
std::cout << "\n";
return EXIT_FAILURE;
}
}
}
int main(int argc, const char* argv[]) {
try {
return run(argc, argv);
}
catch (const std::exception& ex) {
std::cerr << ex.what() << std::endl;
return EXIT_FAILURE;
}
}