This repository has been archived by the owner on May 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
143 lines (124 loc) · 3.05 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
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
#include <iostream>
#include <unistd.h>
#include <cstring>
void help();
void version();
void test(char* arg);
bool check(char* arg);
void parser(char* arg);
void read();
void sread();
void write();
void swrite();
int main(int argc, char** argv)
{
for(;;)
{
switch(getopt(argc, argv, "p:vh"))
{
case 'h':
help();
break;
case 'v':
version();
break;
case 'p':
test(optarg);
break;
default:
help();
break;
}
break;
}
return 0;
}
void help()
{
std::cout << "Instructions:" << std::endl;
std::cout << "diskspeak -h|v" << std::endl;
std::cout << "diskspeak -p \'[rw]...\' <disk>" << std::endl;
}
void version()
{
std::cout << "Program version: Diskspeak 1.0";
}
void test(char* arg)
{
if (check(arg))
{
parser(arg);
} else {
help();
}
}
bool check(char* arg)
{
bool error = false;
if (strlen(arg)>0)
{
for (int counter = 0; counter<strlen(arg) && !error; counter++)
{
switch (arg[counter])
{
case 'R':
break;
case 'r':
break;
case 'W':
break;
case 'w':
break;
default:
error = true;
}
}
} else
{
error = true;
}
if (error)
{
return false;
} else
{
return true;
}
}
void parser(char* arg)
{
for (int counter = 0; counter<strlen(arg); counter++)
{
switch (arg[counter])
{
case 'R':
read();
break;
case 'r':
sread();
break;
case 'W':
write();
break;
case 'w':
swrite();
break;
}
}
}
void read()
{
std::cout << "Lectura" << std::endl;
}
void sread()
{
std::cout << "Lectura inteligente" << std::endl;
}
void write()
{
std::cout << "Escritura" << std::endl;
}
void swrite()
{
std::cout << "Escritura inteligente" << std::endl;
}