From 6d6bb88a0215b87a4a47ed86a84ae3c75d399962 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Sun, 24 Apr 2016 18:05:02 -0400 Subject: Initial import of 5.0 source code with minor changes to use termios on Linux. --- unix.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 unix.c (limited to 'unix.c') diff --git a/unix.c b/unix.c new file mode 100644 index 0000000..3ac06c7 --- /dev/null +++ b/unix.c @@ -0,0 +1,171 @@ +/* + Terminal I/O routines for SEDT (a la UNIX) +*/ +#include +#include +#if defined(ULTRIX) +#include +#include +#else +#include +#if defined(CONVEX) +#include +#else +#if defined(LINUX) +#include +#else +#include +#endif +#endif +#if defined(SGI) +#include +#endif +#endif + +int tty; +#if defined(ULTRIX) +struct sgttyb restore, special; +#else +#if defined(CONVEX) | defined(LINUX) +struct termios restore, special; +#else +struct termio restore, special; +#endif +#endif + +UInit() +{ + /*char *ttyname();*/ + +/* + Open up the terminal device user is on. Get the characteristics + of this terminal, make a copy, and set for no post-processing, + no echo, no canonical input processing, and process each character + when typed rather than await a new-line. +*/ + if((tty = open(ttyname(fileno(stdin)), 2)) <= 0) + { + perror("Can't attach the terminal"); + exit(0); + } +#if defined(ULTRIX) + ioctl(tty, TIOCGETP, &restore); +#else +#if defined(LINUX) + tcgetattr(tty, &restore); +#else + ioctl(tty, TCGETA, &restore); +#endif +#endif + + special = restore; + +#if defined(ULTRIX) + special.sg_flags &= ~(ECHO | CRMOD); + special.sg_flags |= CBREAK; + ioctl(tty, TIOCSETP, &special); +#else + special.c_iflag &= ~ICRNL; + special.c_oflag &= ~OPOST; + special.c_lflag &= ~(ECHO | ICANON | ISIG); + special.c_cc[VEOF] = 1; +#if defined(LINUX) + tcsetattr(tty, TCSANOW, &special); +#else + ioctl(tty, TCSETA, &special); +#endif +#endif + +} + +UEnd() +{ + +/* + Restore terminal attributes and close. +*/ +#if defined(ULTRIX) + ioctl(tty, TIOCSETP, &restore); +#else +#if defined(LINUX) + tcsetattr(tty, TCSANOW, &restore); +#else + ioctl(tty, TCSETA, &restore); +#endif +#endif + close(tty); +} + +USysenv() +{ + +/* + Restore terminal attributes prior to Spawning a command. +*/ +#if defined(ULTRIX) + ioctl(tty, TIOCSETP, &restore); +#else +#if defined(LINUX) + tcsetattr(tty, TCSANOW, &restore); +#else + ioctl(tty, TCSETA, &restore); +#endif +#endif + close(tty); +} + +USedtenv() +{ + +/* + Set terminal attributes back to Sedt specifications. +*/ + if((tty = open(ttyname(fileno(stdin)), 2)) <= 0) + { + perror("Can't attach the terminal"); + exit(0); + } +#if defined(ULTRIX) + ioctl(tty, TIOCSETP, &special); +#else + +#if defined(LINUX) + tcsetattr(tty, TCSANOW, &special); +#else + ioctl(tty, TCSETA, &special); +#endif + +#endif +} + +UGetrm() +{ +unsigned + char key; + + if((read(tty, &key, 1)) < 1) + { + perror("Can't read from terminal"); + exit(0); + } + return((int)key); +} + +UPutrm(string, length) +char *string; +int length; +{ + write(tty, string, length); +} + +#if defined(SUN) +char _toupper(C) +char C; +{return toupper(C); +} + +char _tolower(C) +char C; +{return tolower(C); +} +#endif -- cgit v1.2.3