Make improvements

- Expand redbean UNIX module
- Expand redbean documentation
- Ensure Lua copyright is embedded in binary
- Increase the PATH_MAX limit especially on NT
- Use column major sorting for linenoise completions
- Fix some suboptimalities in redbean's new UNIX API
- Figured out right flags for Multics newline in raw mode
This commit is contained in:
Justine Tunney 2022-04-24 09:59:22 -07:00
parent cf3174dc74
commit 2046c0d2ae
305 changed files with 6602 additions and 4221 deletions

View file

@ -28,7 +28,7 @@ int main(int argc, char *argv[]) {
while ((c = getchar()) != -1) {
if (col == 0) {
printf("\t.byte\t");
memset(glyphs, 0, sizeof(glyphs));
bzero(glyphs, sizeof(glyphs));
}
ch = c & 0xff;
glyphs[col] = kCp437[ch];

View file

@ -248,7 +248,7 @@ static unsigned combinecolors(unsigned char bf[1u << MC][2],
const unsigned char bl[CN][YS * XS]) {
uint64_t hv, ht[(1u << MC) * 2];
unsigned i, j, n, b, f, h, hi, bu, fu;
memset(ht, 0, sizeof(ht));
bzero(ht, sizeof(ht));
for (n = b = 0; b < BN && n < (1u << MC); ++b) {
bu = bl[2][b] << 020 | bl[1][b] << 010 | bl[0][b];
hi = 0;
@ -295,7 +295,7 @@ static unsigned combinecolors(unsigned char bf[1u << MC][2],
const float lb[CN][YS * XS]) { \
unsigned i, k, gu; \
float p[BN], q[BN], fu, bu, r; \
memset(q, 0, sizeof(q)); \
bzero(q, sizeof(q)); \
for (k = 0; k < CN; ++k) { \
gu = kGlyphs[g]; \
bu = lb[k][b]; \
@ -336,7 +336,7 @@ static float adjudicate(unsigned b, unsigned f, unsigned g,
const float lb[CN][YS * XS]) {
unsigned i, k, gu;
float p[BN], q[BN], fu, bu, r;
memset(q, 0, sizeof(q));
bzero(q, sizeof(q));
for (k = 0; k < CN; ++k) {
gu = kGlyphs[g];
bu = lb[k][b];
@ -487,8 +487,8 @@ static void LoadFileViaImageMagick(const char *path, unsigned yn, unsigned xn,
unsigned char rgb[yn][YS][xn][XS][CN]) {
const char *convert;
int pid, ws, pipefds[2];
char pathbuf[PATH_MAX], dim[32];
if (!(convert = commandv("convert", pathbuf))) {
char pathbuf[PATH_MAX + 1], dim[32];
if (!(convert = commandv("convert", pathbuf, sizeof(pathbuf)))) {
fputs("error: `convert` command not found\n"
"try: apt-get install imagemagick\n",
stderr);

View file

@ -93,7 +93,7 @@ void *BilinearScale(long dcw, long dyw, long dxw,
gc(xmemalign(64, ROUNDUP(dxn, 64))),
gc(xmemalign(64, ROUNDUP(sxn, 64) * 2)));
} else {
memset(dst[c0], 0, &dst[cn][0][0] - &dst[c0][0][0]);
bzero(dst[c0], &dst[cn][0][0] - &dst[c0][0][0]);
}
}
return dst;

View file

@ -19,12 +19,12 @@ forceinline void convolve(unsigned yn, unsigned xn, __m128 img[yn][xn], int KW,
kflip[KW - i - 1][KW - j - 1] = (__v4sf){f, f, f, f};
}
}
memset(&g, 0, sizeof(g));
bzero(&g, sizeof(g));
resizegraphic(&g, yn, xn);
tmp = g.b.p;
for (y = 0; y < yn - KW; ++y) {
for (x = 0; x < xn - KW; ++x) {
memset(&p, 0, sizeof(p));
bzero(&p, sizeof(p));
for (i = 0; i < KW; ++i) {
for (j = 0; j < KW; ++j) {
p += img[y + i][x + j] * kflip[i][j] + C2;

View file

@ -45,7 +45,7 @@ long unsharp(long cn, long yw, long xw, unsigned char img[cn][yw][xw], long yn,
for (x = 0; x < xn; ++x) {
img[c][y - 3][x] = MIN(255, MAX(0, (*t)[y % 3][x]));
}
memset((*t)[y % 3], 0, sizeof(short) * xn);
bzero((*t)[y % 3], sizeof(short) * xn);
}
if (y < yn) {
for (x = 0; x < xn; ++x) {

View file

@ -155,8 +155,8 @@ void YCbCrInit(struct YCbCr **ycbcr, bool yonly, int swing, double gamma,
const double gamut[3], const double illuminant[3]) {
if (!*ycbcr) *ycbcr = xcalloc(1, sizeof(struct YCbCr));
(*ycbcr)->yonly = yonly;
memset((*ycbcr)->magnums, 0, sizeof((*ycbcr)->magnums));
memset((*ycbcr)->lighting, 0, sizeof((*ycbcr)->lighting));
bzero((*ycbcr)->magnums, sizeof((*ycbcr)->magnums));
bzero((*ycbcr)->lighting, sizeof((*ycbcr)->lighting));
YCbCrComputeCoefficients(swing, gamma, gamut, illuminant, (*ycbcr)->magnums,
(*ycbcr)->lighting, (*ycbcr)->transfer[0]);
imapxlatab((*ycbcr)->transfer[1]);

View file

@ -612,7 +612,7 @@ static int LoadFile(const char *path) {
}
if (yn > byn || xn > bxn) goto ReadError;
xchg(&board, &board2);
memset(board, 0, (byn * bxn) >> 3);
bzero(board, (byn * bxn) >> 3);
yo = byn / 2 - yn / 2;
xo = bxn / 2 - xn / 2;
y = 0;
@ -857,7 +857,7 @@ static void Rando2(void) {
static void ReadKeyboard(void) {
char buf[32], *p = buf;
memset(buf, 0, sizeof(buf));
bzero(buf, sizeof(buf));
if (readansi(0, buf, sizeof(buf)) == -1) {
if (errno == EINTR) return;
exit(errno);
@ -895,7 +895,7 @@ static void ReadKeyboard(void) {
}
break;
case 'R':
memset(board, 0, (byn * bxn) >> 3);
bzero(board, (byn * bxn) >> 3);
break;
case CTRL('T'):
OnTurbo();
@ -1166,7 +1166,7 @@ static void OnMenuOpen(int64_t hwnd) {
char buf8[PATH_MAX];
char16_t buf16[PATH_MAX];
struct NtOpenFilename ofn;
memset(&ofn, 0, sizeof(ofn));
bzero(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = buf16;
@ -1370,7 +1370,7 @@ static void Gui(void) {
int64_t hwnd, mh;
struct NtMsg msg;
struct NtWndClass wc;
memset(&wc, 0, sizeof(wc));
bzero(&wc, sizeof(wc));
wc.lpfnWndProc = NT2SYSV(WindowProc);
wc.hInstance = GetModuleHandle(NULL);
wc.hCursor = LoadCursor(0, kNtIdcCross);

View file

@ -192,7 +192,7 @@ static void *MagikarpY(CHAR w, unsigned char p[1u << w][1u << w], char yw,
long y, x, yn, xn, ym;
unsigned char(*t)[(1u << w) + 2][1u << w];
t = memalign(64, ((1u << w) + 2) * (1u << w));
memset(t, 0, ((1u << w) + 2) * (1u << w));
bzero(t, ((1u << w) + 2) * (1u << w));
yn = 1u << yw;
xn = 1u << xw;
ym = yn >> 1;

View file

@ -496,7 +496,7 @@ static void OnMouse(char *p) {
static void ReadKeyboard(void) {
char buf[32], *p = buf;
memset(buf, 0, sizeof(buf));
bzero(buf, sizeof(buf));
if (readansi(0, buf, sizeof(buf)) == -1) {
if (errno == EINTR) return;
exit(errno);
@ -797,7 +797,7 @@ static void Zoom(long have) {
n >>= 1;
}
if (n < tyn * txn) {
memset(canvas + n, 0, canvassize - n);
bzero(canvas + n, canvassize - n);
}
if (have != -1) {
n = have >> zoom;
@ -817,7 +817,7 @@ static void FileZoom(void) {
have = MIN(displaysize, size - offset);
have = pread(fd, canvas, have, offset);
have = MAX(0, have);
memset(canvas + have, 0, canvassize - have);
bzero(canvas + have, canvassize - have);
Zoom(have);
Render();
}

View file

@ -26,11 +26,11 @@
int main(int argc, char *argv[]) {
int i;
for (i = 0; kDos2Errno[i].doscode; ++i) {
kprintf("dos error %10hu maps to rva %10d errno %10d which is %s%n",
kDos2Errno[i].doscode, kDos2Errno[i].systemv,
*(const int *)((intptr_t)kDos2Errno + kDos2Errno[i].systemv),
strerror_short(
*(const int *)((intptr_t)kDos2Errno + kDos2Errno[i].systemv)));
kprintf(
"dos error %10hu maps to rva %10d errno %10d which is %s%n",
kDos2Errno[i].doscode, kDos2Errno[i].systemv,
*(const int *)((intptr_t)kDos2Errno + kDos2Errno[i].systemv),
strerrno(*(const int *)((intptr_t)kDos2Errno + kDos2Errno[i].systemv)));
}
return 0;
}