From owner-FreeBSD-users-jp@jp.freebsd.org  Tue Aug 12 10:22:51 1997
Received: by jaz.jp.freebsd.org (8.8.7+2.7Wbeta5/8.7.3) id KAA02679
	Tue, 12 Aug 1997 10:22:51 +0900 (JST)
Received: by jaz.jp.freebsd.org (8.8.7+2.7Wbeta5/8.7.3) with ESMTP id KAA02674
	for <FreeBSD-users-jp@jp.freebsd.org>; Tue, 12 Aug 1997 10:22:50 +0900 (JST)
Received: from uucp3.iij.ad.jp (uucp3.iij.ad.jp [202.232.2.203]) by mail0.iij.ad.jp (8.8.5+2.7Wbeta5/3.5Wpl4-MAIL) with SMTP id KAA13435 for <FreeBSD-users-jp@jp.freebsd.org>; Tue, 12 Aug 1997 10:22:49 +0900 (JST)
Received: (from uucp@localhost) by uucp3.iij.ad.jp (8.6.12+2.4W/3.3W9-UUCP) with UUCP id KAA23700 for FreeBSD-users-jp@jp.freebsd.org; Tue, 12 Aug 1997 10:22:48 +0900
Received: (qmail 7430 invoked by uid 1000); 12 Aug 1997 01:22:26 -0000
Message-ID: <19970812012226.7429.qmail@reseau.toyonaka.osaka.jp>
Date: Tue, 12 Aug 1997 10:22:26 +0900 (JST)
From: Kenji Rikitake <kenji@reseau.toyonaka.osaka.jp>
X-Sender: kenji@reseau.reseau.rcac.tdi.co.jp
To: FreeBSD-users-jp@jp.freebsd.org
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Reply-To: FreeBSD-users-jp@jp.freebsd.org
Precedence: bulk
X-Distribute: distribute [version 2.1 (Alpha) patchlevel=20]
X-Sequence: FreeBSD-users-jp 16896
Subject: [FreeBSD-users-jp 16896] 8-bit thru patch for 2.2.2-RELEASE tip
Errors-To: owner-FreeBSD-users-jp@jp.freebsd.org
Sender: owner-FreeBSD-users-jp@jp.freebsd.org

Following patch modifies tip.c and tipout.c of /usr/src/usr.bin/tip/tip to
get Japanese and 8-bit multilingual code through for FreeBSD 2.2.2-RELEASE.
This patch was originally created by Shin Yoshimura for BSD/386 tipx,
I have reviewed and tested this code for BSD/OS 2.0.1 tip for more than a year.
Compiling tip with -DJP option will enable the patched code.

Just a thought:

* Is the whole fuss of mungling termios really necessary?
  (BSD/OS tip doesn't have this so you can manipulate on your own)
  I have to remove the ISTRIP anyway.

// Kenji Rikitake <kenji@reseau.toyonaka.osaka.jp>
// 12-AUG-1997

--- tip.c.FCS	Mon Nov 27 06:08:36 1995
+++ tip.c	Tue Aug 12 10:09:03 1997
@@ -53,6 +53,16 @@
  *  cu phone-number [-s speed] [-l line] [-a acu]
  */
 
+/*
+ * JP patch for 8-bit-through functionality
+ * originally created by Shin Yoshimura for tipx
+ * modified and applied to FreeBSD tip by 
+ * Kenji Rikitake <kenji@reseau.toyonaka.osaka.jp>
+ * -a is for non-JP mode, -e is for emacs mode
+ * 12-AUG-1997
+ * Compiling the code with -DJP option enables the patched code
+ */
+
 #include "tipconf.h"
 #include "tip.h"
 #include "pathnames.h"
@@ -71,12 +81,28 @@
 int	disc = OTTYDISC;		/* tip normally runs this way */
 #endif
 
+#ifdef JP
+int jpmode = 1;		/* Japanese mode */
+int gchmask = 0377;	/* getchar mask */
+int emacsmode = 0;	/* emacs mode */
+int gotchr = -1;	/* gotchr */
+#endif /* JP */
+
 void	intprompt();
 void	timeout();
 void	cleanup();
 void	tipdone();
 char	*sname();
 char	PNbuf[256];			/* This limits the size of a number */
+#ifdef JP
+/* fake interrupt handler for sending ^C */
+void
+fakeintr()
+{
+	gotchr = 037 & 'C';	/* ^C */
+}
+#endif /* JP */
+
 
 void
 main(argc, argv)
@@ -101,7 +127,11 @@
 #endif /* INCLUDE_CU_INTERFACE */
 
 	if (argc > 4) {
+#ifdef JP
+		fprintf(stderr, "usage: tip [-aev] [-speed] [system-name]\n");
+#else /* JP */
 		fprintf(stderr, "usage: tip [-v] [-speed] [system-name]\n");
+#endif /* JP */
 		exit(1);
 	}
 	if (!isatty(0)) {
@@ -114,6 +144,15 @@
 			system = argv[1];
 		else switch (argv[1][1]) {
 
+#ifdef JP
+		case 'a':
+			jpmode = 0;
+			gchmask = 0177;
+			break;
+		case 'e':
+			emacsmode++;
+			break;
+#endif /* JP */
 		case 'v':
 			vflag++;
 			break;
@@ -151,7 +190,16 @@
 	system = sbuf;
 
 notnumber:
+#ifdef JP
+	if (emacsmode) {
+		(void)signal(SIGINT, fakeintr);
+		}
+	else {
+		(void)signal(SIGINT, cleanup);
+		}
+#else /* JP */
 	(void)signal(SIGINT, cleanup);
+#endif /* JP */
 	(void)signal(SIGQUIT, cleanup);
 	(void)signal(SIGHUP, cleanup);
 	(void)signal(SIGTERM, cleanup);
@@ -217,10 +265,20 @@
 	tcgetattr (0, &otermios);
 	ctermios = otermios;
 #ifndef _POSIX_SOURCE
+#ifdef JP
+	/* no ISTRIP since it strips the 8th bit */
+	ctermios.c_iflag = (IMAXBEL|IXANY|IXON|BRKINT);
+#else /* JP */
 	ctermios.c_iflag = (IMAXBEL|IXANY|ISTRIP|IXON|BRKINT);
+#endif /* JP */
 	ctermios.c_lflag = (PENDIN|IEXTEN|ISIG|ECHOCTL|ECHOE|ECHOKE);
 #else
+#ifdef JP
+	/* no ISTRIP since it strips the 8th bit */
+	ctermios.c_iflag = (IXON|BRKINT);
+#else /* JP */
 	ctermios.c_iflag = (ISTRIP|IXON|BRKINT);
+#endif /* JP */
 	ctermios.c_lflag = (PENDIN|IEXTEN|ISIG|ECHOE);
 #endif
 	ctermios.c_cflag = (CLOCAL|HUPCL|CREAD|CS8);
@@ -414,17 +472,35 @@
 	}
 
 	while (1) {
+#ifdef JP
+		if (gotchr != -1) {
+			gch = gotchr;
+			gotchr = -1;
+		}
+		else {
+#endif /* JP */
 		i = getchar();
 		if (i == EOF)
 			break;
+#ifdef JP
+		gch = i & gchmask;
+		} /* for else above */
+#else /* JP */
 		gch = i&0177;
+#endif /* JP */
 		if ((gch == character(value(ESCAPE))) && bol) {
 			if (!(gch = escape()))
 				continue;
 		} else if (!cumode && gch == character(value(RAISECHAR))) {
 			boolean(value(RAISE)) = !boolean(value(RAISE));
 			continue;
-		} else if (gch == '\r') {
+		} 
+#ifdef JP
+		else if (gch == '\r' || emacsmode && gch == '\n') {
+			gch = '\r';
+#else /* JP */
+		else if (gch == '\r') {
+#endif /* JP */
 			bol = 1;
 			pwrite(FD, &gch, 1);
 			if (boolean(value(HALFDUPLEX)))
@@ -434,7 +510,11 @@
 			i = getchar();
 			if (i == EOF)
 				break;
+#ifdef JP
+			gch = i & gchmask;
+#else /* JP */
 			gch = i & 0177;
+#endif /* JP */
 		}
 		bol = any(gch, value(EOL));
 		if (boolean(value(RAISE)) && islower(gch))
@@ -461,7 +541,11 @@
 	i = getchar();
 	if (i == EOF)
 		return 0;
+#ifdef JP
+	gch = (i & gchmask);
+#else /* JP */
 	gch = (i&0177);
+#endif /* JP */
 	for (p = etable; p->e_char; p++)
 		if (p->e_char == gch) {
 			if ((p->e_flags&PRIV) && uid)
@@ -638,7 +722,11 @@
 	extern int errno;
 
 	bp = buf;
+#ifdef JP
+	if (bits8 == 0 && !jpmode)
+#else /* JP */
 	if (bits8 == 0)
+#endif /* JP */
 		for (i = 0; i < n; i++) {
 			*bp = partab[(*bp) & 0177];
 			bp++;
--- tipout.c.FCS	Mon Oct  9 18:51:17 1995
+++ tipout.c	Tue Aug 12 09:24:40 1997
@@ -43,6 +43,16 @@
  *  reading from the remote host
  */
 
+/*
+ * JP patch for 8-bit-through functionality
+ * originally created by Shin Yoshimura for tipx
+ * modified and applied to FreeBSD tip by
+ * Kenji Rikitake <kenji@reseau.toyonaka.osaka.jp>
+ * -a is for non-JP mode, -e is for emacs mode
+ * 12-AUG-1997
+ * Compiling the code with -DJP option enables the patched code
+ */
+
 static	jmp_buf sigbuf;
 
 /*
@@ -109,6 +119,10 @@
 	longjmp(sigbuf, 1);
 }
 
+#ifdef JP
+extern int jpmode, emacsmode;
+#endif /* JP */
+
 /*
  * ****TIPOUT   TIPOUT****
  */
@@ -153,9 +167,31 @@
 		}
 #define	ALLSIGS	sigmask(SIGEMT)|sigmask(SIGTERM)|sigmask(SIGIOT)|sigmask(SIGSYS)
 		omask = sigblock(ALLSIGS);
-		for (cp = buf; cp < buf + cnt; cp++)
-			*cp &= 0177;
-		write(1, buf, cnt);
+#ifdef JP
+		if (!jpmode)
+#endif /* JP */
+		{
+			for (cp = buf; cp < buf + cnt; cp++)
+				*cp &= 0177;
+		}
+#ifdef JP
+		if (emacsmode) {
+			register char *bcp;
+			for (bcp = cp = buf; cp < buf + cnt; cp++)
+				if (*cp == '\r') {
+					if (cp > bcp)
+						write(1, bcp, cp - bcp);
+					bcp = cp + 1;
+				}
+			if (cp > bcp) {
+				write(1, bcp, cp - bcp);
+				}
+			}
+		else
+#endif /* JP */
+		{
+			write(1, buf, cnt);
+		}
 		if (boolean(value(SCRIPT)) && fscript != NULL) {
 			if (!boolean(value(BEAUTIFY))) {
 				fwrite(buf, 1, cnt, fscript);
@@ -163,6 +199,9 @@
 			}
 			for (cp = buf; cp < buf + cnt; cp++)
 				if ((*cp >= ' ' && *cp <= '~') ||
+#ifdef JP
+                                    (jpmode && (0377&*cp) >= 0200) ||
+#endif /* JP */
 				    any(*cp, value(EXCEPTIONS)))
 					putc(*cp, fscript);
 		}

