-
Notifications
You must be signed in to change notification settings - Fork 0
/
INPUT.H
124 lines (110 loc) · 1.91 KB
/
INPUT.H
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
#include <GRAPHICS.H>
#define PREOD "preorder"
#define INOD "inorder"
#define POSTOD "postorder"
#define INSERT "insert "
#define DEL "del "
#define LEAF "leaf"
#define FIND "find "
#define EXIT "exit"
#define HELP "help"
int FileOp(char filename[],char retbuf[]);
void showCommand(char cmd[]);
void Flash_Input();
int KEY_STATE=0;
int FileOp(char filename[],char retbuf[])
{
int i=0;
FILE *fp;
fp=fopen(filename,"r");
if(fp==NULL){puts("file error");return 0;}
while((retbuf[i++]=fgetc(fp))!=EOF);
retbuf[--i]='\0';
fclose(fp);
return 1;
}
void GetCommand(char cmd[])
{
int i=0,j=1;
char ch='\0';
char list[9][12]={
"preorder",
"inorder",
"postorder",
"insert ",
"del ",
"leaf",
"find ",
"exit",
"help"
};
cmd[i]='_';
cmd[i+1]='\0';
setcolor(WHITE);
outtextxy(10,getmaxy()-120,"command :");
showCommand(cmd);
while(ch!=0x0D)
{
if(!kbhit())
{
ch=getch();
Flash_Input();
if((ch>='a'&&ch<='z')||ch==' ')
{
cmd[i++]=ch;
cmd[i]='_';
cmd[i+1]='\0';
}else if(ch==8&&i>0)
{
Flash_Input();
cmd[--i]='_';
cmd[i+1]='\0';
}else if(ch==0x00)
{
ch=getch();
switch(ch)
{
case 0x48:j--;if(j<0)j=7;break;
case 0x50:j++;if(j>7)j=0;break;
}
if(ch==0x48||ch==0x50)
{
strcpy(cmd,list[j]);i=strlen(list[j]);
cmd[i]='_';
cmd[i+1]='\0';
}else
{
strcpy(cmd,list[8]);i=strlen(list[j]);
cmd[i]='_';
cmd[i+1]='\0';
}
}else if(ch!=0x0D)
{
strcpy(cmd,list[8]);i=strlen(list[j]);
cmd[i]='_';
cmd[i+1]='\0';
showCommand(cmd);
if((ch=getch())==0x00)
{
ch=getch();
}
}
showCommand(cmd);
}
}
cmd[i]='\0';
}
void showCommand(char cmd[])
{
setcolor(WHITE);
outtextxy(50,getmaxy()-100,cmd);
}
void Flash_Input()
{
int i;
setcolor(BLACK);
for(i=0;i<=20;i++)
{
line(20,getmaxy()-100+i,getmaxx(),getmaxy()-100+i);
}
}