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

@ -0,0 +1,130 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2023 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/struct/termios.h"
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/kprintf.h"
#include "libc/macros.internal.h"
#include "libc/sysv/consts/termios.h"
#define N 1024
#define append(...) o += ksnprintf(buf + o, N - o, __VA_ARGS__)
const char *(DescribeTermios)(char buf[N], ssize_t rc, struct termios *tio) {
int o = 0;
char b128[128];
if (!tio) return "NULL";
if ((!IsAsan() && kisdangerous(tio)) ||
(IsAsan() && !__asan_is_valid(tio, sizeof(*tio)))) {
ksnprintf(buf, N, "%p", tio);
return buf;
}
append("{");
struct DescribeFlags kInput[] = {
{IGNBRK, "IGNBRK"}, //
{BRKINT, "BRKINT"}, //
{IGNPAR, "IGNPAR"}, //
{PARMRK, "PARMRK"}, //
{INPCK, "INPCK"}, //
{ISTRIP, "ISTRIP"}, //
{INLCR, "INLCR"}, //
{IGNCR, "IGNCR"}, //
{ICRNL, "ICRNL"}, //
{IUCLC, "IUCLC"}, //
{IXON, "IXON"}, //
{IXANY, "IXANY"}, //
{IXOFF, "IXOFF"}, //
{IMAXBEL, "IMAXBEL"}, //
{IUTF8, "IUTF8"}, //
};
append(".c_iflag=%s",
DescribeFlags(b128, 128, kInput, ARRAYLEN(kInput), "", tio->c_iflag));
struct DescribeFlags kOutput[] = {
{OPOST, "OPOST"}, //
{OLCUC, "OLCUC"}, //
{ONLCR, "ONLCR"}, //
{OCRNL, "OCRNL"}, //
{ONOCR, "ONOCR"}, //
{ONLRET, "ONLRET"}, //
{OFILL, "OFILL"}, //
{OFDEL, "OFDEL"}, //
{NL1, "NL1"}, //
{CR3, "CR3"}, //
{CR2, "CR2"}, //
{CR1, "CR1"}, //
{TAB3, "TAB3"}, //
{TAB2, "TAB2"}, //
{TAB1, "TAB1"}, //
{BS1, "BS1"}, //
{VT1, "VT1"}, //
{FF1, "FF1"}, //
};
append(", .c_oflag=%s", DescribeFlags(b128, 128, kOutput, ARRAYLEN(kOutput),
"", tio->c_oflag));
struct DescribeFlags kControl[] = {
{CS8, "CS8"}, //
{CS7, "CS7"}, //
{CS6, "CS6"}, //
{CSTOPB, "CSTOPB"}, //
{CREAD, "CREAD"}, //
{PARENB, "PARENB"}, //
{PARODD, "PARODD"}, //
{HUPCL, "HUPCL"}, //
{CLOCAL, "CLOCAL"}, //
{CRTSCTS, "CRTSCTS"}, //
};
append(", .c_cflag=%s", DescribeFlags(b128, 128, kControl, ARRAYLEN(kControl),
"", tio->c_cflag));
struct DescribeFlags kLocal[] = {
{ISIG, "ISIG"}, //
{ICANON, "ICANON"}, //
{XCASE, "XCASE"}, //
{ECHO, "ECHO"}, //
{ECHOE, "ECHOE"}, //
{ECHOK, "ECHOK"}, //
{ECHONL, "ECHONL"}, //
{NOFLSH, "NOFLSH"}, //
{TOSTOP, "TOSTOP"}, //
{ECHOCTL, "ECHOCTL"}, //
{ECHOPRT, "ECHOPRT"}, //
{ECHOKE, "ECHOKE"}, //
{FLUSHO, "FLUSHO"}, //
{PENDIN, "PENDIN"}, //
{IEXTEN, "IEXTEN"}, //
{EXTPROC, "EXTPROC"}, //
};
append(", .c_lflag=%s",
DescribeFlags(b128, 128, kLocal, ARRAYLEN(kLocal), "", tio->c_lflag));
append(", c_cc[VINTR]=%#o", tio->c_cc[VINTR]);
append(", c_cc[VERASE]=%#o", tio->c_cc[VERASE]);
append(", c_cc[VWERASE]=%#o", tio->c_cc[VWERASE]);
append("}");
return buf;
}

View file

@ -18,10 +18,12 @@
*/
#include "libc/calls/internal.h"
#include "libc/calls/state.internal.h"
#include "libc/calls/ttydefaults.h"
#include "libc/intrin/_getenv.internal.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/extend.internal.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/nomultics.internal.h"
#include "libc/intrin/pushpop.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/macros.internal.h"
@ -117,4 +119,6 @@ textstartup void __init_fds(int argc, char **argv, char **envp) {
}
fds->p[1].flags = O_WRONLY | O_APPEND;
fds->p[2].flags = O_WRONLY | O_APPEND;
__vintr = CTRL('C');
__vquit = CTRL('\\');
}

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/nomultics.internal.h"
/**
* Controls ANSI prefix for log emissions.
@ -26,3 +27,6 @@
*/
char __replmode;
char __replstderr;
char __ttymagic;
char __vintr;
char __vquit;

View file

@ -5,6 +5,9 @@ COSMOPOLITAN_C_START_
extern char __replmode;
extern char __replstderr;
extern char __ttymagic;
extern char __vintr;
extern char __vquit;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

View file

@ -94,11 +94,11 @@ static dontasan inline const char *strchr_x64(const char *p, uint64_t c) {
* @asyncsignalsafe
* @vforksafe
*/
char *strchr(const char *s, int c) {
dontasan char *strchr(const char *s, int c) {
if (IsAsan()) __asan_verify_str(s);
#if defined(__x86_64__) && !defined(__chibicc__)
const char *r;
if (X86_HAVE(SSE)) {
if (IsAsan()) __asan_verify(s, 1);
r = strchr_sse(s, c);
} else {
r = strchr_pure(s, c);

View file

@ -94,10 +94,10 @@ dontasan static const char *strchrnul_x64(const char *p, uint64_t c) {
* NUL terminator if c is not found
*/
char *strchrnul(const char *s, int c) {
if (IsAsan()) __asan_verify_str(s);
#if defined(__x86_64__) && !defined(__chibicc__)
const char *r;
if (X86_HAVE(SSE)) {
if (IsAsan()) __asan_verify(s, 1);
r = strchrnul_sse(s, c);
} else {
r = strchrnul_pure(s, c);

View file

@ -36,6 +36,7 @@ typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
dontasan char *strcpy(char *d, const char *s) {
size_t i = 0;
if (IsAsan()) {
__asan_verify_str(s);
__asan_verify(d, strlen(s) + 1);
}
#if defined(__x86_64__) && !defined(__chibicc__)