Unused.
authorIain Patterson <me@iain.cx>
Tue, 5 Aug 2008 13:36:07 +0000 (13:36 +0000)
committerIain Patterson <me@iain.cx>
Tue, 5 Aug 2008 13:36:07 +0000 (13:36 +0000)
git-svn-id: https://svn.cambridge.iain.cx/profile/trunk@119 6be0d1a5-5cfe-0310-89b6-964be062b18b

.profile.d/TERM.bashrc
answerback.c [new file with mode: 0644]

index f9132c0..054e284 100644 (file)
@@ -3,11 +3,27 @@
 # Try to find a valid TERM entry.
 #
 
 # Try to find a valid TERM entry.
 #
 
-for term in linux dtterm xterm vt100; do
-  if has_term $term; then
-    export TERM=$term
-    break
+# Note that running answerback will prevent keyboard input, which is annoying 
+# if you try to start typing while the shell is starting up.
+term=
+eval $(answerback 2>/dev/null)
+case "$ANSWERBACK" in
+  PuTTY) term=xterm-256color;;
+  urxvt) term=rxvt-unicode;;
+esac
+
+if [ ! -z "$term" ]; then
+  if ! has_term $term; then
+    export TERMINFO=~/.terminfo
   fi
   fi
-done
+  export TERM=$term
+elif ! has_term $TERM; then
+  for term in rxvt-unicode xterm-256color xterm-88color linux dtterm xterm-color xterm vt100; do
+    if has_term $term; then
+      export TERM=$term
+      break
+    fi
+  done
+fi
 
 
-unset term
+unset ANSWERBACK term
diff --git a/answerback.c b/answerback.c
new file mode 100644 (file)
index 0000000..2bb205f
--- /dev/null
@@ -0,0 +1,51 @@
+/* answerback.c version 0.1
+ * Written by John Newbigin <jn@it.swin.edu.au>
+ * GPL Version 2
+ * Compile with 'gcc -Wall -o answerback answerback.c'
+ * */
+#include <stdio.h>
+#include <unistd.h>
+#include <termios.h>
+#include <signal.h>
+#include <string.h>
+int main(int argc, char **argv)
+{
+  char *name = "ANSWERBACK";
+  char code = 5;
+  char buffer[16];
+  int r;
+  sigset_t sig, sigsave;
+  struct termios term, termsave;
+  FILE *fp;
+  if(argc == 2)
+  {
+    name = argv[1];
+  }
+  if((fp = fopen(ctermid(NULL), "r+")) == NULL)
+  {
+    perror("open");
+    return 0;
+  }
+  setbuf(fp, NULL);
+  sigemptyset(&sig);
+  sigaddset(&sig, SIGINT);
+  sigaddset(&sig, SIGTSTP);
+  sigprocmask(SIG_BLOCK, &sig, &sigsave);
+  tcgetattr(fileno(fp), &termsave);
+  term = termsave;
+  term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL | ICANON);
+  term.c_cc[VMIN] = 0;
+  term.c_cc[VTIME] = 10;
+  tcsetattr(fileno(fp), TCSAFLUSH, &term);
+  write(fileno(fp), &code, 1);
+  memset(buffer, 0, sizeof(buffer));
+  r = read(fileno(fp), buffer, sizeof(buffer) - 1);
+  tcsetattr(fileno(fp), TCSAFLUSH, &termsave);
+  sigprocmask(SIG_SETMASK, &sigsave, NULL);
+  fclose(fp);
+  if(r > 0)
+  {
+    printf("%s='%s'\n", name, buffer);
+  }
+  return 0;
+}