Fix the build and introduce some APIs

The tcgetwinsize() and tcsetwinsize() APIs are now available. The
printargs.com example also now displays the baud rate.
This commit is contained in:
Justine Tunney 2023-01-20 09:25:45 -08:00
parent cac86197cb
commit 1473eafd1a
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
6 changed files with 120 additions and 2 deletions

28
libc/calls/tcgetwinsize.c Normal file
View file

@ -0,0 +1,28 @@
/*-*- 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/calls.h"
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/winsize.h"
/**
* Gets terminal window size.
*/
int tcgetwinsize(int fd, struct winsize *ws) {
return ioctl_tiocgwinsz(fd, ws);
}

28
libc/calls/tcsetwinsize.c Normal file
View file

@ -0,0 +1,28 @@
/*-*- 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/calls.h"
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/winsize.h"
/**
* Sets terminal window size attributes.
*/
int tcsetwinsize(int fd, const struct winsize *ws) {
return ioctl_tiocswinsz(fd, ws);
}

View file

@ -35,6 +35,8 @@ int cfsetospeed(struct termios *, unsigned);
int cfsetispeed(struct termios *, unsigned);
uint32_t cfgetospeed(const struct termios *);
uint32_t cfgetispeed(const struct termios *);
int tcsetwinsize(int, const struct winsize *);
int tcgetwinsize(int, struct winsize *);
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § teletypewriter » undiamonding

View file

@ -511,6 +511,65 @@ textstartup void __printargs(const char *prologue) {
} else if ((termios.c_cflag & CSIZE) == CS8) {
kprintf(" CS8");
}
if ((termios.c_cflag & CBAUD) == B0) {
kprintf(" B0");
} else if ((termios.c_cflag & CBAUD) == B50) {
kprintf(" B50");
} else if ((termios.c_cflag & CBAUD) == B75) {
kprintf(" B75");
} else if ((termios.c_cflag & CBAUD) == B110) {
kprintf(" B110");
} else if ((termios.c_cflag & CBAUD) == B134) {
kprintf(" B134");
} else if ((termios.c_cflag & CBAUD) == B150) {
kprintf(" B150");
} else if ((termios.c_cflag & CBAUD) == B200) {
kprintf(" B200");
} else if ((termios.c_cflag & CBAUD) == B300) {
kprintf(" B300");
} else if ((termios.c_cflag & CBAUD) == B600) {
kprintf(" B600");
} else if ((termios.c_cflag & CBAUD) == B1200) {
kprintf(" B1200");
} else if ((termios.c_cflag & CBAUD) == B1800) {
kprintf(" B1800");
} else if ((termios.c_cflag & CBAUD) == B2400) {
kprintf(" B2400");
} else if ((termios.c_cflag & CBAUD) == B4800) {
kprintf(" B4800");
} else if ((termios.c_cflag & CBAUD) == B9600) {
kprintf(" B9600");
} else if ((termios.c_cflag & CBAUD) == B19200) {
kprintf(" B19200");
} else if ((termios.c_cflag & CBAUD) == B38400) {
kprintf(" B38400");
} else if ((termios.c_cflag & CBAUD) == B57600) {
kprintf(" B57600");
} else if ((termios.c_cflag & CBAUD) == B115200) {
kprintf(" B115200");
} else if ((termios.c_cflag & CBAUD) == B230400) {
kprintf(" B230400");
} else if ((termios.c_cflag & CBAUD) == B500000) {
kprintf(" B500000");
} else if ((termios.c_cflag & CBAUD) == B576000) {
kprintf(" B576000");
} else if ((termios.c_cflag & CBAUD) == B1000000) {
kprintf(" B1000000");
} else if ((termios.c_cflag & CBAUD) == B1152000) {
kprintf(" B1152000");
} else if ((termios.c_cflag & CBAUD) == B1500000) {
kprintf(" B1500000");
} else if ((termios.c_cflag & CBAUD) == B2000000) {
kprintf(" B2000000");
} else if ((termios.c_cflag & CBAUD) == B2500000) {
kprintf(" B2500000");
} else if ((termios.c_cflag & CBAUD) == B3000000) {
kprintf(" B3000000");
} else if ((termios.c_cflag & CBAUD) == B3500000) {
kprintf(" B3500000");
} else if ((termios.c_cflag & CBAUD) == B4000000) {
kprintf(" B4000000");
}
kprintf("\n");
kprintf(prologue);
kprintf(" c_lflag =");
@ -530,8 +589,8 @@ textstartup void __printargs(const char *prologue) {
if (termios.c_lflag & PENDIN) kprintf(" PENDIN");
if (termios.c_lflag & XCASE) kprintf(" XCASE");
kprintf("\n");
PRINT(" c_ispeed = %u", termios.c_ispeed);
PRINT(" c_ospeed = %u", termios.c_ospeed);
PRINT(" c_ispeed = %u", cfgetispeed(&termios));
PRINT(" c_ospeed = %u", cfgetospeed(&termios));
PRINT(" c_cc[VMIN] = %d", termios.c_cc[VMIN]);
PRINT(" c_cc[VTIME] = %d", termios.c_cc[VTIME]);
PRINT(" c_cc[VINTR] = CTRL-%c", CTRL(termios.c_cc[VINTR]));

View file

@ -16,6 +16,7 @@
"__GNUC_PATCHLEVEL__"
"__GNUC__"
"__APPLE__"
"__HAIKU__"
"__CYGWIN__"
"__EMSCRIPTEN__"
"__ANDROID__"