-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesync.cpp
73 lines (59 loc) · 1.26 KB
/
filesync.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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include "components.h"
using namespace std;
int main(int argc, char* argv[]){
//arguments number check
if(argc != 5){
cout << "You gave wrong arguments." << endl;
cout << "Try again with 5 (4 + 'filesync')." << endl;
return -1;
}
//arguments reading
FILE* f1, * f2;
int page_size, fan_out;
f1 = fopen(argv[1],"rb");
f2 = fopen(argv[2],"rb");
sscanf(argv[3], "%d", &page_size);
//arguments checking
if(page_size < 1){
cout << "Wrong page size." << endl;
exit(EXIT_FAILURE);
}
sscanf(argv[4], "%d", &fan_out);
if(fan_out < 2){
cout << "Wrong fan out." << endl;
exit(EXIT_FAILURE);
}
//file opening
if(f1 == NULL){
cout << "f1" << endl;
perror("fopen");
exit(EXIT_FAILURE);
}
if(f2 == NULL){
cout << "f2" << endl;
perror("fopen");
fclose(f1);
exit(EXIT_FAILURE);
}
//creating trees
Tree* t1 = new Tree(fan_out, page_size, f1);
Tree* t2 = new Tree(fan_out, page_size, f2);
//print trees if we want to
//t1->printTree();
//t2->printTree();
//comparing trees
compare(t1, t2, fan_out);
//deleting trees
delete t2;
delete t1;
//closing files
fclose(f1);
fclose(f2);
//print statistics if we want to
printStatistics();
return 0;
}