-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHydresInput.c
More file actions
189 lines (160 loc) · 4.02 KB
/
Copy pathHydresInput.c
File metadata and controls
189 lines (160 loc) · 4.02 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include "HydresInput.h"
int ArrowGet()
{
int loop = 1;
while ((loop != -32) && (loop != 224))
{
loop = getch();
}
switch(getch())
{
case 72:
return UPKEY;
case 75:
return LEFTKEY;
case 80:
return DOWNKEY;
case 77:
return RIGHTKEY;
default:
printf("getch() error during ArrowGet() operation\nreturning right key by default");
return RIGHTKEY;
}
}
int KeyGet()
{
int loop = 0;
while (loop == 0)
{
loop = getch();
switch (loop)
{
case 1 ... 7:
case 10 ... 12:
case 14 ... 26:
loop = 0;
break;
case -32:
case 224:
switch(getch())
{
case 72:
return UPKEY;
case 75:
return LEFTKEY;
case 80:
return DOWNKEY;
case 77:
return RIGHTKEY;
}
default:
return loop;
}
}
return loop;
}
int CharGet()
{
int loop = 0;
while (loop == 0)
{
loop = getch();
switch(loop)
{
case 13:
loop = ENTERKEY;
break;
case 8:
loop = ERASEKEY;
break;
case -32:
case 224:
getch();
case 1 ... 7:
case 9 ... 12:
case 14 ... 26:
loop = 0;
break;
}
}
return loop;
}
char* fieldInputString(field* source, int posx, int posy, int length, int crop)
{
field* tempDisplay = NULL;
if (!source)
{
char *errc = malloc(sizeof(char));
if (errc)
*errc = '\0';
else
herr.x = 1;
HydresErr(err_inputstring_nosource);
return errc;
}
char input = 0, *string = malloc(sizeof(char) * length), *dstring = malloc(sizeof(char) * (length + 1));
int loop = 1, counter = 0, i, lastErased = 0;
for (i = 0 ; i < length ; i++)
string[i] = ' ';
while (loop)
{
for(i = 0 ; i < length ; i++)
{
dstring[i] = string[i];
}
dstring[length] = '\0';
tempDisplay = fsFuse(source,dstring,posx, posy, source->fbody[posx][posy].color);
if (counter < length)
tempDisplay->fbody[posx + counter][posy].color = BACKGROUND_WHITE;
else
tempDisplay->fbody[posx + length - 1][posy].color = BACKGROUND_WHITE;
if ((!((input == ERASEKEY) && (counter == 0)) && (counter <= length)) || lastErased)
{
system("cls");
fieldADisplay(tempDisplay);
lastErased = 0;
}
fieldDestroy(tempDisplay);
input = CharGet();
if (counter >= MAX_INPUT_LENGTH)
{
input = ERASEKEY;
}
if (input == ENTERKEY)
{
string[counter] = '\0';
loop = 0;
for (i = 0 ; i < length ; i++)
{
dstring[i] = string[i];
}
dstring[length] = '\0';
fsPaste(source, dstring, posx, posy, source->fbody[posx][posy].color);
}
else if (input == ERASEKEY)
{
if (counter == 1)
lastErased = 1;
if (counter > 0)
counter--;
string[counter] = ' ';
}
else
{
if (counter >= length)
{
string = realloc(string, sizeof(char) * (counter + 3));
if (!string)
HydresErr(err_misc_oom);
}
string[counter] = input;
counter++;
}
}
free(dstring);
return string;
}
void fieldInStr(field* t, int x, int y, int l, int c)
{
free(fieldInputString(t, x, y, l, c));
}