aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarstr\xf6m <john@ankarstrom.se>2021-05-31 20:54:54 +0200
committerJohn Ankarstr\xf6m <john@ankarstrom.se>2021-05-31 20:55:20 +0200
commitdf4c240e8eb30e520469fdaee2042e04adc854e3 (patch)
treeb1fd611751a5449d7421c0df8a4de1c2c5112972
parent8cc2b45caabc4d15d15193acdeda90246e5f3aba (diff)
downloadsafetitle-df4c240e8eb30e520469fdaee2042e04adc854e3.tar.gz
Add 'da' utility
-rw-r--r--Makefile1
-rw-r--r--da.c43
-rw-r--r--safetitle.c1
3 files changed, 44 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 3f6f76b..9aae517 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,7 @@
CFLAGS += -O2 -pedantic -Wall -Wextra
safetitle: safetitle.c
+da: da.c
install:
install safetitle /usr/local/bin
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 <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <termios.h>
+#include <unistd.h>
+
+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);
+}
diff --git a/safetitle.c b/safetitle.c
index a926264..bf302d3 100644
--- a/safetitle.c
+++ b/safetitle.c
@@ -6,7 +6,6 @@
* the title is not set. It is theoretically possible to check every
* terminal too see if it is recognized and, if so, set the title --
* but that would make the code more complex.
- *
*/
#include <err.h>