-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
116 lines (100 loc) · 2.45 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
#include <iostream>
#include "Interpreter.h"
#include "CatalogManager.h"
#include "RecordManager.h"
#include "IndexManager.h"
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "API.h"
void init()//如果没有Indexs文件,则创建一个
{
FILE *fp;
fp = fopen("Indexs", "r");
if (fp == NULL)
{
fp = fopen("Indexs", "w+");
return;
}
fclose(fp);
}
void print()
{
clock_t finish = clock();
double duration = (double)(finish - start) / CLOCKS_PER_SEC;
duration *= 1000;
printf( "now time is %2.1f milliseconds\n", duration * 1000);
}
clock_t start;
int main(int argc,char * argv[])
{
init();
API api;
CatalogManager cm;
RecordManager rm;
api.rm = &rm;
api.cm = &cm;
IndexManager im(&api);
api.im = &im;
rm.api = &api;
start = 0;
clock_t finish;
cout<<"*******************Welcome to use our MiniSQL**********************"<<endl;
cout<<"********* Author: Chen hy &Peng zy & Chen yl & Zhong fy **********"<<endl;
int fileRead = 1;
string fileN = "";
string fileName ="";
cin >> fileName;
ifstream file;
Interpreter in(fileName);
in.ap = &api;
string s;
string flag;
int status = 0;
while(1)
{
if(fileRead)
{
file.open(in.fileName.c_str());
if(!file.is_open())
{
cout<<"Fail to open "<<in.fileName<<endl;
fileRead = 0;
continue;
}
while(getline(file,s,';'))
{
in.interpreter(s);
}
file.close();
fileRead = 0;
finish = clock();
double duration = (double)(finish - start) / CLOCKS_PER_SEC;
duration *= 1000;
printf( "%2.1f milliseconds\n", duration );
}
else
{
cout<<"minisql>>";
getline(cin,s,';');
start = clock();
status = in.interpreter(s);
if(status==2)
{
fileRead = 1;
}
else if(status==587)//出错?
{
break;
}
else{
finish = clock();
double duration = (double)(finish - start) / CLOCKS_PER_SEC;
duration *= 1000;
printf( "The duration is %2.1f milliseconds\n", duration);
}
}
}
return 0;
}