Get Fat Emacs working in Windows Console

This commit is contained in:
Justine Tunney 2023-08-18 04:55:57 -07:00
parent bf835de612
commit 7100b1cf91
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
34 changed files with 479 additions and 168 deletions

View file

@ -18,11 +18,15 @@
*/
#include "libc/intrin/bits.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/files.h"
#include "libc/nt/thunk/msabi.h"
#include "libc/runtime/internal.h"
#include "libc/str/str.h"
#include "libc/str/utf16.h"
__msabi extern typeof(GetFileAttributes) *const __imp_GetFileAttributesW;
struct DosArgv {
const char16_t *s;
char *p;
@ -102,6 +106,31 @@ textwindows dontasan int GetDosArgv(const char16_t *cmdline, char *buf,
if (!st->wc) break;
if (++argc < max) {
argv[argc - 1] = st->p < st->pe ? st->p : NULL;
if (argc == 1) {
// windows lets you run "foo.com" without saying "./foo.com"
// which caused emacs to crash after searching for itself :(
char16_t cmd[256];
uint32_t i, j, attr;
i = j = 0;
cmd[j++] = st->wc;
for (; st->s[i]; ++i) {
if (i == 255 || st->s[i] == '/' || st->s[i] == '\\') {
goto GiveUpAddingDotSlash;
}
if (st->s[i] == ' ' || st->s[i] == '\t') {
break;
}
cmd[j++] = st->s[i];
}
cmd[j] = 0;
if ((attr = __imp_GetFileAttributesW(cmd)) != -1u &&
!(attr & kNtFileAttributeDirectory)) {
AppendDosArgv('.', st);
AppendDosArgv('\\', st);
}
GiveUpAddingDotSlash:
donothing;
}
}
inquote = false;
while (st->wc) {

View file

@ -284,9 +284,11 @@ dontasan textstartup void __printargs(const char *prologue) {
}
if ((n = poll(u.pfds, ARRAYLEN(u.pfds), 0)) != -1) {
for (i = 0; i < ARRAYLEN(u.pfds); ++i) {
char oflagbuf[128];
if (i && (u.pfds[i].revents & POLLNVAL)) continue;
PRINT(" ☼ %d (revents=%#hx fcntl(F_GETFL)=%#x isatty()=%hhhd)", i,
u.pfds[i].revents, fcntl(i, F_GETFL), isatty(i));
PRINT(" ☼ %d (revents=%#hx fcntl(F_GETFL)=%s isatty()=%hhhd)", i,
u.pfds[i].revents, (DescribeOpenFlags)(oflagbuf, fcntl(i, F_GETFL)),
isatty(i));
}
} else {
PRINT(" poll() returned %d %m", n);
@ -449,15 +451,18 @@ dontasan textstartup void __printargs(const char *prologue) {
PRINT(" ☼ %s = %#s", "kNtSystemDirectory", kNtSystemDirectory);
PRINT(" ☼ %s = %#s", "kNtWindowsDirectory", kNtWindowsDirectory);
#endif
PRINT(" ☼ %s = %#s", "__argv[0]", __argv[0]);
PRINT(" ☼ %s = %#s", "getenv(\"_\")", getenv("_"));
PRINT(" ☼ %s = %#s", "getauxval(AT_EXECFN)", getauxval(AT_EXECFN));
PRINT(" ☼ %s = %#s", "GetProgramExecutableName", GetProgramExecutableName());
PRINT(" ☼ %s = %#s", "GetInterpreterExecutableName",
GetInterpreterExecutableName(u.path, sizeof(u.path)));
PRINT(" ☼ %s = %p", "RSP", __builtin_frame_address(0));
PRINT(" ☼ %s = %p", "GetStackSize()", GetStackSize());
PRINT(" ☼ %s = %p", "GetGuardSize()", GetGuardSize());
PRINT(" ☼ %s = %p", "GetStackAddr()", GetStackAddr());
PRINT(" ☼ %s = %p", "GetStaticStackSize()", GetStaticStackSize());
PRINT(" ☼ %s = %p", "GetStaticStackAddr(0)", GetStaticStackAddr(0));
PRINT(" ☼ %s = %p", "__builtin_frame_address(0)", __builtin_frame_address(0));
PRINT("");
PRINT("MEMTRACK");
@ -509,46 +514,34 @@ dontasan textstartup void __printargs(const char *prologue) {
if (termios.c_oflag & OFILL) kprintf(" OFILL");
if (termios.c_oflag & OFDEL) kprintf(" OFDEL");
if (termios.c_oflag & OLCUC) kprintf(" OLCUC");
if ((termios.c_oflag & NLDLY) == NL0) {
kprintf(" NL0");
} else if ((termios.c_oflag & NLDLY) == NL1) {
if ((termios.c_oflag & NLDLY) == NL1) {
kprintf(" NL1");
} else if ((termios.c_oflag & NLDLY) == NL2) {
kprintf(" NL2");
} else if ((termios.c_oflag & NLDLY) == NL3) {
kprintf(" NL3");
}
if ((termios.c_oflag & CRDLY) == CR0) {
kprintf(" CR0");
} else if ((termios.c_oflag & CRDLY) == CR1) {
if ((termios.c_oflag & CRDLY) == CR1) {
kprintf(" CR1");
} else if ((termios.c_oflag & CRDLY) == CR2) {
kprintf(" CR2");
} else if ((termios.c_oflag & CRDLY) == CR3) {
kprintf(" CR3");
}
if ((termios.c_oflag & TABDLY) == TAB0) {
kprintf(" TAB0");
} else if ((termios.c_oflag & TABDLY) == TAB1) {
if ((termios.c_oflag & TABDLY) == TAB1) {
kprintf(" TAB1");
} else if ((termios.c_oflag & TABDLY) == TAB2) {
kprintf(" TAB2");
} else if ((termios.c_oflag & TABDLY) == TAB3) {
kprintf(" TAB3");
}
if ((termios.c_oflag & BSDLY) == BS0) {
kprintf(" BS0");
} else if ((termios.c_oflag & BSDLY) == BS1) {
if ((termios.c_oflag & BSDLY) == BS1) {
kprintf(" BS1");
}
if ((termios.c_oflag & VTDLY) == VT0) {
kprintf(" VT0");
} else if ((termios.c_oflag & VTDLY) == VT1) {
if ((termios.c_oflag & VTDLY) == VT1) {
kprintf(" VT1");
}
if ((termios.c_oflag & FFDLY) == FF0) {
kprintf(" FF0");
} else if ((termios.c_oflag & FFDLY) == FF1) {
if ((termios.c_oflag & FFDLY) == FF1) {
kprintf(" FF1");
}
kprintf("\n");