-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
77 lines (66 loc) · 2.42 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 <fstream>
#include <bits/stdc++.h>
#include<time.h>
using namespace std;
int main(int argc, char* argv[]){
//defining USAGE for the user
if (argc < 7) {
cout << "Usage: " << argv[0] << " -f \"From Time\" -t \"To Time\" -i \"Log file directory location\" " << endl;
return 1;
}
//taking arguments from command line
int from, to, file;
for (int i = 1; i < argc; i++){
if (string(argv[i]) == "-f"){
if (i + 1 < argc) // Make sure we aren't at the end of argv!
from = ++i; // Increment 'i' to capture the From Time.
else{ //There was no argument to the From option.
cout << "-f option requires one argument." << endl;
return 1;
}
}
else if(string(argv[i]) == "-t"){
if (i + 1 < argc) // Make sure we aren't at the end of argv!
to = ++i; // Increment 'i' to capture the To Time.
else{ //There was no argument to the To option.
cout << "-t option requires one argument." << endl;
return 1;
}
}
else if(string(argv[i]) == "-i"){
if (i + 1 < argc) // Make sure we aren't at the end of argv!
file = ++i; // Increment 'i' to capture the Log file directory location.
else{ //There was no argument to the Log file directory option.
cout << "-i option requires one argument." << endl;
return 1;
}
}
else{ //Give error and define the usage
cout << "Usage: " << argv[0] << " -f \"From Time\" -t \"To Time\" -i \"Log file directory location\" " << endl;
return 1;
}
}
//read from the file
// cout<<file<<"****";
double time_spent = 0.0;
// clock_t begin = clock();
//cout<<"5461615645151";
for(int k = 0;k<4;k++)
{
char c = '0';
argv[file][7] = char(c+k+1);
ifstream source(argv[file]);
string line;
//If the time substring lies between FROM TIME and TO TIME, print it
while (getline(source, line)){
if(line.substr(0, 25) >= argv[from] && line.substr(0, 25) <= argv[to])
cout << line << endl;
}
}
// clock_t end = clock();
// time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
// cout<<endl<<endl;
// cout << "time taken to fetch lines" << time_spent << endl;
return 0;
}