forked from youngsamwei/DongmenDB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
74 lines (56 loc) · 1.57 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
/*****************************************************************************
*
* dongmendb
*
* 简单的sql命令行界面
*
\*****************************************************************************/
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <dongmendb/DongmenDB.h>
#include <stdio.h>
#include "shell/shell.h"
int main(int argc, char *argv[]) {
int opt;
int rc;
int verbosity = 0;
const char *command = "select sno from student;";
dongmendb_shell_handle_sql_t shell_ctx;
dongmendb_shell_init_ctx(&shell_ctx);
/* Process command-line arguments */
while ((opt = getopt(argc, argv, "c:vh")) != -1)
switch (opt) {
case 'c':
command = strdup(optarg);
break;
case 'v':
verbosity++;
break;
case 'h':
printf("Usage: dongmendb [-c COMMAND] [DATABASE]\n");
exit(0);
default:
printf("ERROR: Unknown option -%c\n", opt);
exit(-1);
}
char cmdstring[MAX_CMD];
int n;
setbuf(stdout,0);
setbuf(stderr,0);
while (1) {
printf("\ndongmendb>");
if ((n = read(0, cmdstring, MAX_CMD)) < 0) {
printf("read error");
}
int wordcount = 0;
while(cmdstring[wordcount] != '\n'){
wordcount++;
}
cmdstring[wordcount] = '\0';
if (cmdstring) {
dongmendb_shell_handle_cmd(&shell_ctx, cmdstring);
}
}
return 0;
}