Unbufferred file I/O
Ben Smith
ben at idsnh.UUCP
Sun May 15 13:24:38 AEST 1988
In article <2961 at crash.cts.com> cline at 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 <stdio.h>
#include <termio.h>
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);
}
More information about the Comp.unix.xenix
mailing list