/
main.cpp
executable file
·125 lines (121 loc) · 3.51 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
/* Filename: main.cpp */
/* Function: Excution of program */
/* Author Wubaolin */
/* vision 2.1.0 */
#include <stdio.h>
#include <malloc.h>
#include <ctype.h>
#include <stdlib.h>
#include "datatype.h"
#include "createtable.h"
#include "importtable.h"
#include "search.h"
#include "update.h"
#include "quit.h"
#include "help.h"
#include "delete.h"
//#include <crtdbg.h>
//#include "mystring.h"
int main(void)
{
//#ifdef _DEBUG
//_CrtSetDbgFlag(_crtDbgFlag|_CRTDBG_LEAK_CHECK_DF);
//char* pDumMemoryLeak = new char[20];
//::mystrcpy(pDumMemoryLeak,"Dum Leak");
//#endif
int i=1;
char buffer[LINE_MAX];
char* command=buffer; // check command
char tableindex[TABLE_MAX][TABLE_NAME_MAX]={0}; //Index of Table
Data*** database = (Data***)malloc(sizeof(Data**) * TABLE_MAX); //Data
if(database == NULL) {printf("error in creating Table\n"); exit(1);}
int j1=0;
for(j1=0;j1<TABLE_MAX;j1++) database[j1] = NULL; //Initialize every table to NULL
Column** columnindex= (Column**) malloc( sizeof(Column*) * TABLE_MAX) ; //Index of Column
if(database == NULL) {printf("error in creating Column\n"); exit(1);}
int j2=0;
for(j2=0;j2<TABLE_MAX;j2++) columnindex[j2] = NULL; //Initialize every column to NULL
printscreen(); //print screen
while(i)
{
printf("DB1=>");
gets(buffer);
command=buffer;
while(isspace(*command)){command++;}//ignore ' '
if(*(command)++!='-')
{
printf("command should be started by - \n");
continue;
}
if(*command == 'c') //create database
{
command++;
while(isspace((*command))){command++;}//ignore ' '
if(createtable(command,tableindex,columnindex,database) == 0)
printf("Error in Initializing the table and create it!\n");
else printf("Succeed in Initializing the table!\n");
continue;
}
if(*command=='i') // Import DB
{
command++;
while(isspace((*command))){command++;}//ignore ' '
int i=0;
char tablename[TABLE_NAME_MAX];
char filename[20];
while(*command!=' ')
{
tablename[i++]=*(command++);
}
tablename[i]='\0';
while(isspace((*command))){command++;}//ignore ' '
i=0;
while(*command!='\0')
{
filename[i++]=*(command++);
}
filename[i]='\0';
printf("%d items has been imported\n", ImportTable(tablename,filename,tableindex,columnindex,database));
continue;
}
if(*command=='s')
{
command++;
while(isspace((*command))){command++;}///ignore ' '
printf("------%d Items has been searched !--------------\n",tablesearch(command,tableindex,columnindex,database) );
continue;
}
if(*command == 'u') //ignore ' '
{
command++;
while(isspace((*command))){command++;}///ignore ' '
printf("-------%d Items has been updated!---------------\n",Updatetable(tableindex,columnindex,database,command));
printf("The result is printed to the File 074090_update.txt \n");
continue;
}
if(*command == 'd') //delete DB
{
command++;
while(isspace((*command))){command++;}///ignore ' '
printf("-------%d Items has been Deleted!---------------\n",Deletetable(command,tableindex,columnindex,database) );
printf("The result is printed to the File 074090_delete \n");
continue;
}
if(*command == 'h') //help
{
help();
continue;
}
if(*command == 'q') //Quit free Memrory
{
quit(database,columnindex,tableindex);
break;
}
else
{
puts("Commands can't ben supported!\n");
}
}
printf("\nThank you for using!");
return 0;
}