Do code cleanup use duff device linenoise i/o

This commit is contained in:
Justine Tunney 2022-04-22 18:55:28 -07:00
parent 6ff46ca373
commit 2f56ebfe78
79 changed files with 1393 additions and 1484 deletions

View file

@ -103,22 +103,21 @@ static void AppendArg(struct Args *l, char *s) {
static void MakeHeader(struct Header *h, const char *name, int ref, int mode,
int size) {
size_t n;
char buf[24];
memset(h, ' ', sizeof(*h));
n = strlen(name);
memcpy(h->name, name, n);
if (ref != -1) {
memcpy(h->name + n, buf, uint64toarray_radix10(ref, buf));
FormatUint32(h->name + n, ref);
}
if (strcmp(name, "//") != 0) {
h->date[0] = '0';
h->uid[0] = '0';
h->gid[0] = '0';
memcpy(h->mode, buf, uint64toarray_radix8(mode & 0777, buf));
FormatOctal32(h->mode, mode & 0777, false);
}
h->fmag[0] = '`';
h->fmag[1] = '\n';
memcpy(h->size, buf, uint64toarray_radix10(size, buf));
FormatUint32(h->size, size);
}
int main(int argc, char *argv[]) {

View file

@ -1271,7 +1271,7 @@ static void DrawXmm(struct Panel *p, long i, long r) {
uint64toarray_fixed16(ival, buf, xmmtype.size[r] * 8);
}
} else {
int64toarray_radix10(SignExtend(ival, xmmtype.size[r] * 8), buf);
FormatInt64(buf, SignExtend(ival, xmmtype.size[r] * 8));
}
break;
default:
@ -2270,7 +2270,8 @@ static void OnVidyaServiceTeletypeOutput(void) {
char buf[12];
n = 0 /* FormatCga(m->bx[0], buf) */;
w = tpenc(VidyaServiceXlatTeletype(m->ax[0]));
do buf[n++] = w;
do
buf[n++] = w;
while ((w >>= 8));
PtyWrite(pty, buf, n);
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -661,7 +661,7 @@ static const char *GetErrnoName(int x) {
const char *s;
static char buf[16];
if ((s = strerror_short(x))) return s;
int64toarray_radix10(x, buf);
FormatInt64(buf, x);
return buf;
}