mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 17:28:30 +00:00
Get Fat Emacs working in Windows Console
This commit is contained in:
parent
bf835de612
commit
7100b1cf91
34 changed files with 479 additions and 168 deletions
130
libc/intrin/describetermios.c
Normal file
130
libc/intrin/describetermios.c
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue