-
Notifications
You must be signed in to change notification settings - Fork 53
/
main.cpp
75 lines (60 loc) · 1.81 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
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include "Url.hpp"
#include "flags.hpp"
#include "utils.hpp"
const std::string VERSION {"1.0.4"};
int main(int argc, char **argv)
{
CliOptions cli_options {};
// Parse flags if provided
std::vector<Option> options;
if (argc > 1)
{
options = parse_flags(argc, argv);
}
std::vector<Url> urls {};
std::string filename {};
for (const Option &option: options)
{
if (option.flag.short_name == "-h")
{
print_usage();
return 0;
}
if (option.flag.short_name == "-V")
{
print_version(VERSION);
return 0;
}
parse_cli_options(option, cli_options);
}
if (cli_options.filename.length() > 0)
load_urls_from_file(urls, cli_options.filename, cli_options.regex_mode);
else
read_urls_from_stream(urls, std::cin, cli_options.regex_mode);
std::unordered_map<std::string, bool> deduped_url_keys;
for (auto &parsed_url: urls)
{
// Move on to the next if -qs is enabled and URL has no query strings
if (cli_options.query_strings_only)
{
if (parsed_url.get_query_strings().empty())
continue;
}
if (cli_options.no_extensions_only)
{
if (parsed_url.has_extension())
continue;
}
std::string url_key {parsed_url.get_url_key(cli_options.similar_mode)};
if (deduped_url_keys.find(url_key) != deduped_url_keys.end())
continue;
deduped_url_keys.insert(std::make_pair(url_key, true));
// If it has made it to this point, it's a non-duplicate URL. Print it
std::cout << parsed_url.get_url_string() << std::endl;
}
return 0;
}