-
Notifications
You must be signed in to change notification settings - Fork 0
/
console.sj
41 lines (37 loc) · 1.02 KB
/
console.sj
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
package console {
write(data : 'string)'void {
data.nullTerminate()
--c--
printf("%s", (char*)data->data.data);
--c--
}
writeLine(data : 'string)'void {
data.nullTerminate()
--c--
printf("%s\n", (char*)data->data.data);
--c--
}
readLine()'string {
data := nullptr
dataSize := 1024
--c--
char* str = (char*)malloc(console_datasize);
int index = 0;
char ch = ' ';
do {
ch = getchar();
if (ch != '\n') {
str[index] = ch;
index++;
if (index >= console_datasize) {
console_datasize *= 2;
str = (char*)realloc(str, console_datasize);
}
}
} while (ch != '\n');
console_data = (void*)str;
console_datasize = index;
--c--
string(count := dataSize, data := array!char(dataSize := dataSize, data := data, count := dataSize))
}
}