$NetBSD: patch-ac,v 1.6 2006/01/17 21:23:01 kristerw Exp $

--- fep_com.c.orig	1991-05-29 01:31:09.000000000 -0400
+++ fep_com.c	2005-12-10 16:59:27.000000000 -0500
@@ -6 +6 @@
-#endif lint
+#endif /* lint */
@@ -7,6 +7,18 @@
 
 #include <stdio.h>
+#include <sys/ioctl.h>
+#ifdef TERMIOS
+#include <termios.h>
+#ifdef __linux__
+#ifndef _POSIX_VDISABLE
+#define _POSIX_VDISABLE '\0'
+#endif
+#endif
+#else
 #include <sgtty.h>
+#endif
 #include <ctype.h>
+#include <inttypes.h>
+#include <stdlib.h>
 #include <sys/param.h>
 #include <sys/file.h>
@@ -31,7 +43,7 @@
     char *comline, **more;
 {
     register FunctionTableEnt *ftp;
-    char linebuf[MAXCOMLEN], *line;
+    char linebuf[MAXCMDLEN], *line;
     char *search_string();
     int argc;
 
@@ -93,7 +105,7 @@
 
     while (*a && *b && *a == *b)
 	++a, ++b;
-    if ((*a == NULL || isspace (*a)) && (*b == NULL || isspace (*b)))
+    if ((*a == '\0' || isspace ((unsigned char)*a)) && (*b == '\0' || isspace ((unsigned char)*b)))
 	return 1;
     else
 	return 0;
@@ -295,7 +307,7 @@
 set (comline)
     char *comline;
 {
-    char line[MAXCOMLEN];
+    char line[MAXCMDLEN];
     char *cp, *index();
     char *argv[MAXARGS];
     int argc;
@@ -352,8 +364,13 @@
 
 extern	int Transparency;
 extern	int Through;
-extern	struct sgttyb slave_ttymode;
-extern	struct sgttyb master_ttymode;
+#ifdef TERMIOS
+#define ttystruct termios
+#elif defined(TIOCSETN)
+#define ttystruct sgttyb
+#endif
+struct	ttystruct master_ttymode;		/* master tty mode */
+struct	ttystruct slave_ttymode;		/* slave tty mode */
 extern	int master, slave;
 extern	char slave_tty[];
 
@@ -368,7 +385,11 @@
 {
     int r;
     int slave_fd;
+#ifdef TERMIOS
+    struct termios s;
+#else
     struct sgttyb s;
+#endif
 
     if (Through == OFF) {
 
@@ -378,15 +399,26 @@
 	    return;
 	}
 
+#ifdef TERMIOS
+	r = tcgetattr(slave_fd, &s);
+#else
 	r = ioctl (slave_fd, TIOCGETP, (char *) &s);
+#endif
 	if (r < 0) {
 	    perror (slave_tty);
 	    (void) close (slave_fd);
 	    return;
 	}
 
+#ifdef TERMIOS
+	s.c_lflag &= ~(ICANON);
+	s.c_cc[VMIN] = 1;
+	s.c_cc[VTIME] = 0;
+	r = tcsetattr(0, TCSANOW, &s);
+#else
 	s.sg_flags |= CBREAK;
 	r = ioctl (0, TIOCSETN, (char *) & s);
+#endif
 	if (r < 0) {
 	    perror (slave_tty);
 	    (void) close (slave_fd);
@@ -394,7 +426,11 @@
 	(void) close (slave_fd);
     }
     else
+#ifdef TERMIOS
+	r = tcsetattr(0, TCSANOW, & master_ttymode);
+#else
 	r = ioctl (0, TIOCSETN, (char *) & master_ttymode);
+#endif
 
     if (r < 0) {
 	printf ("Can't change pty mode.\n");
@@ -410,7 +446,11 @@
 fix_transparency()
 {
     int r;
+#ifdef TERMIOS
+    struct termios s;
+#else
     struct sgttyb s;
+#endif
 
     if (Through)
 	return;
@@ -418,11 +458,17 @@
     if (slave < 0)
 	return;
 
+#ifdef TERMIOS
+    r = tcgetattr(slave, &s);
+    s.c_iflag |= ICRNL;
+    s.c_oflag |= ONLCR;
+#else
     r = ioctl (slave, TIOCGETP, (char *) &s);
     /*
      * slave CRMOD is off, but master should be.
      */
     s.sg_flags |= CRMOD;
+#endif
     if (r < 0) {
 	perror (slave_tty);
 	return;
@@ -432,9 +478,19 @@
      * If find slave tty mode is cbreak or raw, fix tty mode of stdout to
      * same mode as slave and set Transparency ON.
      */
-    if (s.sg_flags & (CBREAK|RAW)) {
+
+#ifdef TERMIOS
+    if ((s.c_lflag & ICANON) == 0)
+#else
+    if (s.sg_flags & (CBREAK|RAW))
+#endif
+    {
 	if (Transparency == OFF) {
+#ifdef TERMIOS
+	    r = tcsetattr(0, TCSANOW, & s);
+#else
 	    r = ioctl (0, TIOCSETN, (char *) & s);
+#endif
 	    if (r < 0) {
 		perror ("stdout");
 		return;
@@ -445,7 +501,11 @@
     }
     else {
 	if (Transparency == ON) {
-	    r = ioctl (0, TIOCSETN, (char *) &master_ttymode);
+#ifdef TERMIOS
+	    r = tcsetattr(0, TCSANOW, & master_ttymode);
+#else
+	    r = ioctl (0, TIOCSETN, (char *) & master_ttymode);
+#endif
 	    if (r < 0) {
 		perror ("stdout");
 		return;
@@ -623,10 +683,10 @@
 {
     MORE *mp;
 
-    mp = (MORE *) malloc (sizeof (MORE));
+    mp = malloc (sizeof (MORE));
 
     if (mp == 0)
-	return ((MORE*)0);
+	return (NULL);
     else {
 	mp->cur_line = 0;
 	mp->max_line = maxline;
@@ -738,9 +798,9 @@
 fep_pwd (line)
     char *line;
 {
-    char cwd[MAXPATHLEN], *getwd();
+    char cwd[MAXPATHLEN];
 
-    (void) getwd (cwd);
+    (void) getcwd (cwd, sizeof(cwd));
     printf ("%s\n", cwd);
 }
 
@@ -755,7 +815,7 @@
     argc = mkargv (comline, argv, MAXARGS);
     
     argp = &argv[1];
-    if (*argp && strcmp (*argp, "-n") == NULL) {
+    if (*argp && strcmp (*argp, "-n") == 0) {
 	putnewline = 0;
 	++argp;
     }
@@ -791,7 +851,7 @@
     int argc;
     int i;
     char **argp;
-    char *buf[256];
+    char buf[256];
 
     argc = mkargv (comline, argv, MAXARGS);
 
