|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T u
Length: 2423 (0x977)
Types: TextFile
Names: »unixio.c«
└─⟦060c9c824⟧ Bits:30007080 DKUUG TeX 2/12/89
└─⟦this⟧ »./DVIware/crt-viewers/others/dvitovdu/src/unixio.c«
└─⟦52210d11f⟧ Bits:30007239 EUUGD2: TeX 3 1992-12
└─⟦af5ba6c8e⟧ »unix3.0/DVIWARE.tar.Z«
└─⟦ca79c7339⟧
└─⟦this⟧ »DVIware/crt-viewers/others/dvitovdu/src/unixio.c«
/* Alex Dickinson
Procedures for setting and resetting UNIX tty characteristics.
Interesting functions are:
savetty();
restoretty();
echoon();
echooff();
singlecharon();
singlecharoff();
buffercount();
suspend();
A side effect of calling savetty() is to set up signal handling to reset
the terminal characteristics appropriately for the various interrupt
signals.
*/
#include <stdio.h>
#include <sgtty.h>
#include <signal.h>
struct sgttyb initchars; /* store initial terminal characteristics */
/* Save the original tty characteristics and set up the signalling. */
savetty()
{
ioctl(1, TIOCGETP, &initchars);
setsignals();
}
/* Restore the original tty characteristics. */
restoretty()
{
ioctl(1, TIOCSETN, &initchars);
}
/* Set driver to read characters as they are typed without waiting for a
terminator. Echo remains unchanged. */
singlecharon()
{
struct sgttyb s;
ioctl(1, TIOCGETP, &s);
s.sg_flags |= CBREAK;
ioctl(1, TIOCSETN, &s);
fflush(stdin);
}
/* Turn off single character read mode. */
singlecharoff()
{
struct sgttyb s;
ioctl(1, TIOCGETP, &s);
s.sg_flags &= ~CBREAK;
ioctl(1, TIOCSETN, &s);
}
/* Turn character echoing on. */
echoon()
{
struct sgttyb s;
ioctl(1, TIOCGETP, &s);
s.sg_flags |= ECHO;
ioctl(1, TIOCSETN, &s);
}
/* Turn character echoing off. */
echooff()
{
struct sgttyb s;
ioctl(1, TIOCGETP, &s);
s.sg_flags &= ~ECHO;
ioctl(1, TIOCSETN, &s);
}
/* Return the number of characters currently in the input buffer. */
int buffercount()
{
long count;
ioctl(1, FIONREAD, &count);
return(count);
}
/* Yukko */
realungetc(ch, filed)
char ch;
int filed;
{
ioctl(filed, TIOCSTI, &ch);
}
/* Catch signals from tty.
If sig is an interrupt, put 0 and terminator into the buffer.
Otherwise it was a suspend, so we put 1 and terminator into buffer. */
handleint(sig)
int sig;
{
fflush(stdin);
if (sig == SIGINT)
{
realungetc(0, 0);
realungetc(13, 0);
}
else
{
realungetc(1, 0);
realungetc(13, 0);
}
}
/* Signal initialization. */
setsignals()
{
signal(SIGINT, handleint);
signal(SIGTSTP, handleint);
}
/* Suspend the process */
suspend()
{
signal(SIGTSTP, SIG_DFL);
kill(0, SIGTSTP);
/* resumed again, goody! */
setsignals();
}
/* Dummy "implementation block" required by linker. */
unixio__init()
{}