From df4c240e8eb30e520469fdaee2042e04adc854e3 Mon Sep 17 00:00:00 2001 From: "John Ankarstr\\xf6m" Date: Mon, 31 May 2021 20:54:54 +0200 Subject: Add 'da' utility --- da.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 da.c (limited to 'da.c') diff --git a/da.c b/da.c new file mode 100644 index 0000000..6f1b511 --- /dev/null +++ b/da.c @@ -0,0 +1,43 @@ +/* + * da prints the device attributes of the current terminal + * to standard output as a string of comma-separated integers. + * + * If run inside GNU screen, it will print the device attributes + * of GNU screen itself and not those of the real terminal. + */ + +#include +#include +#include +#include +#include + +int +main() +{ + char c; + int r, ttyfd; + struct termios term, restore; + + if((ttyfd = open("/dev/tty", O_RDWR))==-1) + err(1, "open"); + + tcgetattr(ttyfd, &restore); + tcgetattr(ttyfd, &term); + term.c_lflag &= ~(ICANON|ECHO); + tcsetattr(ttyfd, TCSANOW, &term); + + write(ttyfd, "\033[>c", 4); + while(r = read(ttyfd, &c, 1)){ + if(r==-1){ + warn("read"); + goto end; + } + if(c=='c') break; + printf("%d,", c); + } + printf("99\n"); + +end: + tcsetattr(ttyfd, TCSANOW, &restore); +} -- cgit v1.2.3