From: Iain Patterson Date: Tue, 5 Aug 2008 13:36:07 +0000 (+0000) Subject: Unused. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=eae36419db72d287dc1af274027ab1c2d3d18dec;p=profile.git Unused. git-svn-id: https://svn.cambridge.iain.cx/profile/trunk@119 6be0d1a5-5cfe-0310-89b6-964be062b18b --- diff --git a/.profile.d/TERM.bashrc b/.profile.d/TERM.bashrc index f9132c0..054e284 100644 --- a/.profile.d/TERM.bashrc +++ b/.profile.d/TERM.bashrc @@ -3,11 +3,27 @@ # 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 -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 index 0000000..2bb205f --- /dev/null +++ b/answerback.c @@ -0,0 +1,51 @@ +/* answerback.c version 0.1 + * Written by John Newbigin + * GPL Version 2 + * Compile with 'gcc -Wall -o answerback answerback.c' + * */ +#include +#include +#include +#include +#include +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; +}