/
checker.cpp
127 lines (105 loc) · 3.02 KB
/
checker.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
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
#include <string.h>
#include <stdlib.h>
#include "parse.h"
#include "URL.h"
#include "phone.h"
void help() {
std::cout << "Product Availability Checker v0.0\n\n"
<< "Commands:\n"
<< "-wu -- Displays the tracked URL's\n"
<< "-wn -- Displays the phone numbers to notify\n"
<< "-au [URL] -- Add a URL to watch\n"
<< "-an [NUMBER] -- Add a number to notify\n"
<< "-du [ENTRY #] -- Stop watching a URL\n"
<< "-dn [ENTRY #] -- Stop notifying a number\n"
<< "-eu [ENTRY #] -- Modify a watched URL\n"
<< "-en [ENTRY #] -- Modify a phone number\n"
<< std::endl;
}
int main ( int argc, char *argv[] ) {
Parser parse; URL url; Phone phone;
if ( argc == 1 ) {
//This is where the checker will run
}
else if ( argc == 2 ) {
if ( strcmp(argv[1], "-wu") == 0 ) {
url.writeLines();
}
else if ( strcmp(argv[1], "-wn" ) == 0 ) {
phone.writeLines();
}
else if ( strcmp(argv[1], "--help") == 0 ||
strcmp(argv[1], "-h") == 0 ) {
help();
}
else { std::cout << "Invalid argument." << std::endl; }
}
else if ( argc == 3 ) {
if ( strcmp(argv[1], "-au") == 0 ) {
std::string str(argv[2]);
parse.url = argv[2];
if ( parse.validURL() ) {
url.addLine( argv[2] );
}
else {
std::cout << "Must enter a valid URL." << std::endl;
}
}
else if ( strcmp(argv[1], "-an") == 0 ) {
std::string str(argv[2]);
if ( phone.validNumber(argv[2]) ) {
phone.addLine( argv[2] );
}
else {
std::cout << "Must enter a valid number." << std::endl;
}
}
else if ( strcmp(argv[1], "-du") == 0 ) {
unsigned int lineSelection = strtoul( argv[2], NULL, 0);
if ( url.validateSelection( lineSelection ) ) {
url.deleteLine( lineSelection );
}
else {
std::cout << "Entry doesn't exist." << std::endl;
}
}
else if ( strcmp(argv[1], "-dn") == 0 ) {
unsigned int lineSelection = strtoul( argv[2], NULL, 0);
if ( phone.validateSelection( lineSelection ) ) {
phone.deleteLine( lineSelection );
}
else {
std::cout << "Entry doesn't exist." << std::endl;
}
}
else { std::cout << "Invalid argument." << std::endl; }
}
else if ( argc == 4 ) {
if ( strcmp(argv[1], "-eu") == 0 ) {
std::string str(argv[3]);
parse.url = argv[3];
unsigned int lineSelection = strtoul( argv[2], NULL, 0);
if ( url.validateSelection( lineSelection ) && parse.validURL() ) {
url.editLine( lineSelection, argv[3] );
}
else {
std::cout << "Entry doesn't exist or URL is invalid." << std::endl;
}
}
else if ( strcmp(argv[1], "-en") == 0 ) {
std::string str(argv[3]);
unsigned int lineSelection = strtoul( argv[2], NULL, 0);
if ( phone.validateSelection( lineSelection ) && phone.validNumber( argv[3] ) ) {
phone.editLine( lineSelection, argv[3] );
}
else {
std::cout << "Entry doesn't exist or number is invalid." << std::endl;
}
}
else { std::cout << "Invalid argument." << std::endl; }
}
else {
std::cout << "Invalid arguments. Type --help for full command list." << std::endl;
}
return 0;
}