mike (Michael Stefanik) (01/23/91)
In an article, ncs.dnd.ca!marwood (Gordon Marwood) writes: >I shall shortly be transferring from a MicroVAX Ultrix system to one >using Interactive Unix 2.2. In preparation for this I am transfering a >number of programs over to the new system. One of these uses CBREAK in >a function which changes mode to allow "hot-key" interaction by the user. >The Interactive C compiler cannot seem to find CBREAK, and generates an >error. Any assistance to solve this problem would be appreciated. The only cbreak function that I'm aware of is in curses(3); if you need the equivalent without using curses, here ya' go: #include <termio.h> int cbreak(mode) int mode; { static struct termio old, new; int oncethru = 0, israw = 0; if ( ! oncethru ) { ioctl(0,TCGETA,&old); ioctl(0,TCGETA,&new); oncethru = 1; } if ( mode && (! israw) ) { new.c_lflag &= ~ECHO; new.c_lflag &= ~ICANON; new.c_lflag &= ~ISIG; new.c_cc[VMIN] = 1; new.c_cc[VTIME] = 0; ioctl(0,TCSETA,&new); } else { ioctl(0,TCSETA,&old); israw = 0; } } Thus, using cbreak(1) would put the terminal into cbreak mode, which will return one character at a time; using cbreak(0) would put the terminal back into canonical mode. -- Michael Stefanik, Systems Engineer (JOAT), Briareus Corporation UUCP: ...!uunet!bria!mike -- technoignorami (tek'no-ig'no-ram`i) a group of individuals that are constantly found to be saying things like "Well, it works on my DOS machine ..."
guy@auspex.auspex.com (Guy Harris) (01/25/91)
> new.c_lflag &= ~ECHO; > new.c_lflag &= ~ICANON; > new.c_lflag &= ~ISIG; ... >Thus, using cbreak(1) would put the terminal into cbreak mode, And also turn off echoing and processing of signal characters such as the interrupt and quit characters, which turning CBREAK mode on, in systems with that mode, won't do. CBREAK, in systems that have it (well, in systems that have a V7-style CBREAK, and not some Mutant CBREAK From Hell), is the inverse of ICANON on systems that have it; turning CBREAK on is equivalent to turning ICANON off, setting c_cc[VMIN] to 1, and setting c_cc[VTIME] to 0, but leaving ECHO and ISIG alone. In practice, lots of programs that turn CBREAK mode on also want to turn echoing and the signal characters off, but not all do (most probably turn echoing off, but many may not turn the signal characters off), so the function in question may be what he wants - but it's not *necessarily* what he wants, as the program may really want the interrupt character to cause a SIGINT.