Compare commits

..

No commits in common. "a84415a953b17ff349bdd38a93cac19f0a3a4b01" and "09e0d32c15bd33c56d212e249edc0f6f23e626f2" have entirely different histories.

View File

@ -1,35 +1,18 @@
geadline2(prompt, text) geadline(prompt) {
{
local capacity = 64, local capacity = 64,
size = 0, size = 0,
i = 0, i = 0,
c, c,
a, a,
buf; buf = galloc(capacity);
if (text) {
size = strlen(text);
i = size;
loop {
if (capacity > size)
break;
capacity = capacity * 2;
}
buf = galloc(capacity);
if (buf == NULL)
return NULL;
strcpy(buf, text);
} else {
buf = galloc(capacity);
if (buf == NULL)
return NULL;
[buf] = 0;
}
if (prompt) if (prompt)
putstr(prompt); putstr(prompt);
putstr(buf); if (buf == NULL)
return NULL;
[buf] = 0;
loop { loop {
c = getchar(); red &c;
if ((c == 0xffff) | (c == 0x04)) { if ((c == 0xffff) | (c == 0x04)) {
if ((size == 0) | (c == 0xffff)) { if ((size == 0) | (c == 0xffff)) {
free(buf); free(buf);
@ -37,8 +20,8 @@ geadline2(prompt, text)
} }
} else if (c == 0x1b) { } else if (c == 0x1b) {
// ESC code // ESC code
getchar(); // skip [ red &c; // skip [
c = getchar(); // value red &c; // value
if ((c == 'A') & (size > 0)) { if ((c == 'A') & (size > 0)) {
loop { loop {
@ -121,13 +104,7 @@ geadline2(prompt, text)
} }
} }
geadline(prompt) esccode(c) {
{
geadline2(prompt, NULL);
}
esccode(c)
{
wrt 0x1b; wrt 0x1b;
wrt '['; wrt '[';
wrt c; wrt c;