Path: utzoo!attcan!uunet!idsnh!ben From: ben@idsnh.UUCP (Ben Smith) Newsgroups: comp.unix.xenix Subject: Re: Unbufferred file I/O Message-ID: <23@idsnh.UUCP> Date: 15 May 88 03:24:38 GMT References: <2961@crash.cts.com> Reply-To: ben@.UUCP (Ben Smith) Organization: Integrated Decision Systems, Inc. - NH Lines: 85 In article <2961@crash.cts.com> cline@pnet01.cts.com (Ben Humphreys) writes: | As I have not been able to get any versions of talk to run on my SCO system, I | was forced to use write. But write is a bummer because it is bufferred. The I/O has to be set to "cbreak" mode. See the termio & ioctl sections of your UNIX manual. The following program demonstrates the use of "cbreak": /* 1ch - sets terminal echo off and does decimal code echo of each keypress until newline is received - ben smith (uunet!idsnh!ben) - this program is being placed in the public domain by the author (bss) */ #include #include char *descr[33] /* control character descriptions */ = { " NULL", "^A SOH ", "^B STX ", "^C ETX ", "^D EOT ", "^E ENQ ", "^F ACK ", "^G BEL ", "^H BS ", "^I HT ", "^J LF ", "^K VT ", "^L FF ", "^M CR ", "^N SO ", "^O SI ", "^P DLE ", "^Q DC1 ", "^R DC2 ", "^S DC3 ", "^T DC4 ", "^U NAK ", "^V SYN ", "^W ETB ", "^X CAN ", "^Y EM ", "^Z SUB ", "^[ ESC ", "^\\ FS ", "^] GS ", "^^ RS ", " SP " }; main() { int inchar, c; struct termio old, new; /* save old terminal config */ ioctl(0,TCGETA,&old); /* set up new terminal config */ /* first make a copy to modify */ ioctl(0,TCGETA,&new); /* then AND the controls */ new.c_lflag &= !(ICANON); new.c_cc[4] = new.c_cc[5] = '\01'; /* delay and buffer size */ /* and send out new config */ ioctl(0,TCSETAW,&new); /* now for the real part of the program - processing the keypresses */ do { c = getchar(); if ((c > 32 && c < 127) || (c > 160 && c < 255)) printf("decimal %3d octal %3o hex %2X = %c\n",c,c,c,c); else if (c >= 0 && c <= 32) printf("decimal %3d octal %3o hex %2X = %s\n",c,c,c,descr[c]); else if (c >= 128 && c <= 160) printf("decimal %3d octal %3o hex %2X = %s\n", c,c,c,descr[c-128]); else if (c == 127 || c == 255) printf("decimal %3d octal %3o hex %2X = DEL\n",c,c,c); }while (c != '\n'); /* reinstate old parameters before leaving */ ioctl(0,TCSETAW,&old); }