-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
176 lines (118 loc) · 3.37 KB
/
main.cpp
File metadata and controls
176 lines (118 loc) · 3.37 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <thread>
#include <regex>
#include <map>
#include "ripper.h"
#include "./libargmage/argmage.h"
using namespace std;
string fnumstr4(int num);
void helpscrn();
int main(int argc, char* argv[]){
// help
if( ((string)argv[1] == "-h") || ((string)argv[1] == "--help") ){
helpscrn();
return 0;
}
// parse argv into a map
auto args = argmage::argvtomap(argc, argv, 1);
// check if files args given and give necessary feedback
if( (args["-f"] == "") && (args["-r"] == "") ){
cout << "No files given\n";
// display help screen
helpscrn();
return 0;
}
if( (args["-f"] == "") || (args["-f"] == "\0") ){
cout << "No html file given\n";
// display help screen
helpscrn();
return 0;
} else if( (args["-r"] == "") || (args["-r"] == "\0") ){
cout << "No regex file given\n";
// display help screen
helpscrn();
return 0;
}
// add directory validation for all files... later.
// file stream declarations
ifstream infile(args["-f"]);
ifstream regfile(args["-r"]);
// string declarations
string temp;
string instr;
string regstr;
// regfile to string
while(getline(regfile, temp)) regstr = regstr + temp;
regfile.close(); // don't need the regfile anymore
temp = "";
// regex declarations
regex r(regstr + "(.*)"); // make global... pseudo global
smatch sm;
// vectors
vector<string> vin;
vector<string> vurl;
vector<string> vfname;
// infile to vector
while(getline(infile, temp)) vin.push_back(temp);
infile.close();
// invec regex matches to string
for(string in : vin){
regex_search(in, sm, r);
instr = instr + sm[1].str();
}
// urls to vec
do{
regex_search(instr, sm, r);
vurl.push_back(sm[1].str());
instr = sm[2].str();
}while( (instr != "") && (instr != "\0") ); //changed from || to &&
// infile.close();
// if -x don't display urls in stdout or save to file
// check if url save file given
// if not display to std out
if( (args["-x"] != "") && (args["-x"] != "\0") ){
} else if( (args["-s"] == "") || (args["-s"] == "\0") ){
for(string url : vurl){
cout << url << endl;
}
} else {
ofstream outfile(args["-s"]);
for(string url : vurl){
outfile << url << endl;
}
outfile.close();
}
// set file names
regex fnr("\\/([^/]+\\.\\w+$)");
for(int i = 0; i < vurl.size(); i++){
regex_search(vurl.at(i), sm, fnr);
vfname.push_back(fnumstr4(i + 1) + "_" + sm[1].str());
}
// sequential download
if( ((args["-o"] != "") && (args["-o"] != "\0")) && ((args["-m"] == "") || (args["-m"] == "\0")) ) seqdl(vurl, vfname, args["-o"]);
// parallel downloading
if( ((args["-o"] != "") && (args["-o"] != "\0")) && ((args["-m"] != "") && (args["-m"] != "\0")) ){
}else if( (args["-m"] != "") && (args["-m"] != "\0") ){
}
return 0;
}
void helpscrn(){
cout << "\n\t+===================================================================+\n";
cout << "\n";
cout << "\t\t--help (-h)\n";
cout << "\n";
cout << "\t\t -f file.html (or url savefile. depends on your regex)\n";
cout << "\n";
cout << "\t\t -r regex_file.txt\n";
cout << "\n";
cout << "\t\t -s url_save_file.txt\n";
cout << "\n";
cout << "\t\t -x (no url save file or output)\n";
cout << "\n";
cout << "\t\t -o /download/path/\n";
cout << "\n";
cout << "\t+===================================================================+\n\n";
}