Compare commits
No commits in common. "3443ed76e852231d2eb16b924f8808ace5b750f0" and "fa5a7755e47b3c31493c4fd24368f8d2c14cb484" have entirely different histories.
3443ed76e8
...
fa5a7755e4
@ -1,49 +0,0 @@
|
||||
geadline(prompt) {
|
||||
local capacity = 64,
|
||||
size = 0,
|
||||
i = 0,
|
||||
c,
|
||||
buf = galloc(capacity);
|
||||
if (prompt)
|
||||
putstr(prompt);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
|
||||
loop {
|
||||
red &c;
|
||||
if ((c == 0xffff) | (c == 0x04)) {
|
||||
if ((size == 0) | (c == 0xffff)) {
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
} else if (c == 0x007f) {
|
||||
if (size) {
|
||||
size = size - 1;
|
||||
i = i - 1;
|
||||
[buf + size] = 0;
|
||||
|
||||
wrt 0x1b;
|
||||
wrt 0x5b;
|
||||
wrt 0x44;
|
||||
wrt ' ';
|
||||
wrt 0x1b;
|
||||
wrt 0x5b;
|
||||
wrt 0x44;
|
||||
}
|
||||
} else {
|
||||
size = size + 1;
|
||||
if (size > capacity) {
|
||||
buf = reallocarray(buf, capacity, capacity * 2);
|
||||
if (buf == NULL)
|
||||
return NULL;
|
||||
capacity = capacity * 2;
|
||||
}
|
||||
[buf + i] = c;
|
||||
i = i + 1;
|
||||
[buf + i] = 0;
|
||||
wrt c;
|
||||
if (c == '\n')
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user