mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-30 17:22:27 +00:00
Do code cleanup use duff device linenoise i/o
This commit is contained in:
parent
6ff46ca373
commit
2f56ebfe78
79 changed files with 1393 additions and 1484 deletions
|
@ -30,9 +30,9 @@ size_t FormatCga(uint8_t bgfg, char buf[hasatleast 11]) {
|
|||
char *p = buf;
|
||||
*p++ = '\e';
|
||||
*p++ = '[';
|
||||
p += uint64toarray_radix10(kCgaToAnsi[(bgfg & 0xF0) >> 4] + 10, p);
|
||||
p = FormatUint32(p, kCgaToAnsi[(bgfg & 0xF0) >> 4] + 10);
|
||||
*p++ = ';';
|
||||
p += uint64toarray_radix10(kCgaToAnsi[bgfg & 0x0F], p);
|
||||
p = FormatUint32(p, kCgaToAnsi[bgfg & 0x0F]);
|
||||
*p++ = 'm';
|
||||
*p = '\0';
|
||||
return p - buf;
|
||||
|
|
|
@ -128,7 +128,7 @@ static char *DisRegisterWord(struct Dis *d, uint32_t rde, char *p, bool g,
|
|||
|
||||
static char *DisInt(char *p, int64_t x) {
|
||||
if (-15 <= x && x <= 15) {
|
||||
p += int64toarray_radix10(x, p);
|
||||
p = FormatInt64(p, x);
|
||||
} else if (x == INT64_MIN) {
|
||||
p = stpcpy(p, "-0x");
|
||||
p += uint64toarray_radix16(INT64_MIN, p);
|
||||
|
@ -319,7 +319,8 @@ static char *DisRegMem(struct Dis *d, uint32_t rde, char *p,
|
|||
}
|
||||
|
||||
static dontinline char *DisE(struct Dis *d, uint32_t rde, char *p,
|
||||
char *f(struct Dis *, uint32_t, char *, bool, int)) {
|
||||
char *f(struct Dis *, uint32_t, char *, bool,
|
||||
int)) {
|
||||
if (IsModrmRegister(rde)) {
|
||||
return f(d, rde, p, Rexb(rde), ModrmRm(rde));
|
||||
} else {
|
||||
|
@ -471,13 +472,13 @@ static char *DisOne(struct Dis *d, uint32_t rde, char *p) {
|
|||
|
||||
static char *DisJbs(struct Dis *d, uint32_t rde, char *p) {
|
||||
if (d->xedd->op.disp > 0) *p++ = '+';
|
||||
p += int64toarray_radix10(d->xedd->op.disp, p);
|
||||
p = FormatInt64(p, d->xedd->op.disp);
|
||||
return p;
|
||||
}
|
||||
|
||||
static char *DisJb(struct Dis *d, uint32_t rde, char *p) {
|
||||
if (d->xedd->op.disp > 0) *p++ = '+';
|
||||
p += uint64toarray_radix10(d->xedd->op.disp & 0xff, p);
|
||||
p = FormatUint32(p, d->xedd->op.disp & 0xff);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
@ -522,7 +523,7 @@ static char *DisXmm(struct Dis *d, uint32_t rde, char *p, const char *s,
|
|||
p = HighStart(p, g_high.reg);
|
||||
*p++ = '%';
|
||||
p = stpcpy(p, s);
|
||||
p += uint64toarray_radix10(reg, p);
|
||||
p = FormatUint32(p, reg);
|
||||
p = HighEnd(p);
|
||||
return p;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ struct High g_high;
|
|||
char *HighStart(char *p, int h) {
|
||||
if (h) {
|
||||
p = stpcpy(p, "\e[38;5;");
|
||||
p += uint64toarray_radix10(h, p);
|
||||
p = FormatUint32(p, h);
|
||||
p = stpcpy(p, "m");
|
||||
g_high.active = true;
|
||||
}
|
||||
|
|
|
@ -693,9 +693,9 @@ static void PtyReportCursorPosition(struct Pty *pty) {
|
|||
p = buf;
|
||||
*p++ = '\e';
|
||||
*p++ = '[';
|
||||
p += uint64toarray_radix10((pty->y + 1) & 0x7fff, p);
|
||||
p = FormatInt32(p, (pty->y + 1) & 0x7fff);
|
||||
*p++ = ';';
|
||||
p += uint64toarray_radix10((pty->x + 1) & 0x7fff, p);
|
||||
p = FormatInt32(p, (pty->x + 1) & 0x7fff);
|
||||
*p++ = 'R';
|
||||
PtyWriteInput(pty, buf, p - buf);
|
||||
}
|
||||
|
@ -1178,7 +1178,8 @@ ssize_t PtyWriteInput(struct Pty *pty, const void *data, size_t n) {
|
|||
m = pty->input.n;
|
||||
if (i + n * 2 + 1 > m) {
|
||||
m = MAX(m, 8);
|
||||
do m += m >> 1;
|
||||
do
|
||||
m += m >> 1;
|
||||
while (i + n * 2 + 1 > m);
|
||||
if (!(p = realloc(p, m))) {
|
||||
return -1;
|
||||
|
@ -1229,18 +1230,18 @@ ssize_t PtyRead(struct Pty *pty, void *buf, size_t size) {
|
|||
static char *PtyEncodeRgb(char *p, int rgb) {
|
||||
*p++ = '2';
|
||||
*p++ = ';';
|
||||
p += uint64toarray_radix10((rgb & 0x0000ff) >> 000, p);
|
||||
p = FormatUint32(p, (rgb & 0x0000ff) >> 000);
|
||||
*p++ = ';';
|
||||
p += uint64toarray_radix10((rgb & 0x00ff00) >> 010, p);
|
||||
p = FormatUint32(p, (rgb & 0x00ff00) >> 010);
|
||||
*p++ = ';';
|
||||
p += uint64toarray_radix10((rgb & 0xff0000) >> 020, p);
|
||||
p = FormatUint32(p, (rgb & 0xff0000) >> 020);
|
||||
return p;
|
||||
}
|
||||
|
||||
static char *PtyEncodeXterm256(char *p, int xt) {
|
||||
*p++ = '5';
|
||||
*p++ = ';';
|
||||
p += uint64toarray_radix10(xt, p);
|
||||
p = FormatUint32(p, xt);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue