Mass patch to enable uum on FreeWnn-1.10-pl020
かべ。
しまった、 input-method.wnn はもう存在しないんだった。
input-method 直下に出し直します。
※とりあえず現状放出です。
※細かいチェックはしてません。
NetBSD-1.6.1 (x86) で、FreeWnnのuumを動かそうとしてみましたが
そのままでは pty の取得まわりがうまくいかないので、
以前fj.comp.input-method.wnnに投稿した(はず)の
Solaris/HPUX用パッチをベースに
ごりごりと Wnn/uum/jhlp.c を書き換えてみました。
サーバーへの接続は試してませんが、uumは立ち上がってひらがなは入力できるし
ジョブコントロールも効きます。
pty回りは昔からの建て増しをすると究極に汚くなるので、
思いきって
・sgi
・/dev/ptmx (ptm(7D))
・openpty(3)
・伝統的 /dev/ttyXXスキャン
の4通りに整理してあります。
TODO: configureでちゃんとどれを使うか検出する。
(NetBSD-1.6では伝統式とopenpty()両方動くようだ)
もしかしたら Solaris でもこのパッチで動いちゃうかもしれません。(未チェック)
==
懸案というか疑問:
ptyで何かを動かすにあたっては、普通は
・ptyのmaster と slaveを取得
・fork()
・子供側で slave をつなぎ替える
・親は masterに入出力
なんですが、main() ではなぜか linuxだけは
fork()した「後」にslaveを開いて(open_ttyp())います。
fork後に開かないと動かなかった理由でもあるんですかね?
かなり昔からこのまんまになっているようですが、
可能ならfork前slave取得に統一した方がいいような…
(openpty(3) なんかはfork前slave取得しかできないので、
fork前に統一すると open_pty() と open_ttyp() が合体できてすっきりする)
--
kabe
^L
* Patch against FreeWnn-1.10-pl020 to
enable uum on NetBSD.
jhlp.c is heavily modified & cleaned to
accomodate different methods of aquiring pty;
TODO will be switching methods in configure
Tested on NetBSD-1.6.1
-DUSE_OPENPTY seems to work on NetBSD (not automatically enabled)
Fri Jul 4 14:36:20 JST 2003
--
kabe
^L
diff -ur FreeWnn-1.10-pl020.dist/Wnn/conv/cvt_head.h FreeWnn-1.10-pl020/Wnn/conv/cvt_head.h
--- FreeWnn-1.10-pl020.dist/Wnn/conv/cvt_head.h Thu Mar 21 12:32:45 2002
+++ FreeWnn-1.10-pl020/Wnn/conv/cvt_head.h Fri Jul 4 10:02:51 2003
@@ -40,7 +40,7 @@
#include "commonhd.h"
-#if defined(luna) || defined(DGUX)
+#if defined(luna) || defined(DGUX) || defined(hpux) || defined(sun)
#ifndef SUPPORT_TWODIGIT_FUNCTIONS
#define SUPPORT_TWODIGIT_FUNCTIONS
#endif /* SUPPORT_TWODIGIT_FUNCTIONS */
diff -ur FreeWnn-1.10-pl020.dist/Wnn/conv/cvt_read.c FreeWnn-1.10-pl020/Wnn/conv/cvt_read.c
--- FreeWnn-1.10-pl020.dist/Wnn/conv/cvt_read.c Wed Apr 3 13:16:19 2002
+++ FreeWnn-1.10-pl020/Wnn/conv/cvt_read.c Fri Jul 4 10:05:55 2003
@@ -455,6 +455,40 @@
keydef_key[i++] = stradd (&tdataptr, key_f29);
keydef_key[i++] = stradd (&tdataptr, key_f30);
keydef_key[i++] = stradd (&tdataptr, key_f31);
+#ifndef uniosu
+ keydef_key[i++] = stradd (&tdataptr, key_f32);
+ keydef_key[i++] = stradd (&tdataptr, key_f33);
+ keydef_key[i++] = stradd (&tdataptr, key_f34);
+ keydef_key[i++] = stradd (&tdataptr, key_f35);
+ keydef_key[i++] = stradd (&tdataptr, key_f36);
+ keydef_key[i++] = stradd (&tdataptr, key_f37);
+ keydef_key[i++] = stradd (&tdataptr, key_f38);
+ keydef_key[i++] = stradd (&tdataptr, key_f39);
+ keydef_key[i++] = stradd (&tdataptr, key_f40);
+ keydef_key[i++] = stradd (&tdataptr, key_f41);
+ keydef_key[i++] = stradd (&tdataptr, key_f42);
+ keydef_key[i++] = stradd (&tdataptr, key_f43);
+ keydef_key[i++] = stradd (&tdataptr, key_f44);
+ keydef_key[i++] = stradd (&tdataptr, key_f45);
+ keydef_key[i++] = stradd (&tdataptr, key_f46);
+ keydef_key[i++] = stradd (&tdataptr, key_f47);
+ keydef_key[i++] = stradd (&tdataptr, key_f48);
+ keydef_key[i++] = stradd (&tdataptr, key_f49);
+ keydef_key[i++] = stradd (&tdataptr, key_f50);
+ keydef_key[i++] = stradd (&tdataptr, key_f51);
+ keydef_key[i++] = stradd (&tdataptr, key_f52);
+ keydef_key[i++] = stradd (&tdataptr, key_f53);
+ keydef_key[i++] = stradd (&tdataptr, key_f54);
+ keydef_key[i++] = stradd (&tdataptr, key_f55);
+ keydef_key[i++] = stradd (&tdataptr, key_f56);
+ keydef_key[i++] = stradd (&tdataptr, key_f57);
+ keydef_key[i++] = stradd (&tdataptr, key_f58);
+ keydef_key[i++] = stradd (&tdataptr, key_f59);
+ keydef_key[i++] = stradd (&tdataptr, key_f60);
+ keydef_key[i++] = stradd (&tdataptr, key_f61);
+ keydef_key[i++] = stradd (&tdataptr, key_f62);
+ keydef_key[i++] = stradd (&tdataptr, key_f63);
+#endif /*uniosu*/
#endif /* SUPPORT_TWODIGIT_FUNCTIONS */
/* 以下順に
"kcuu1", "kcuf1", "kcub1", "kcud1", "khome",
diff -ur FreeWnn-1.10-pl020.dist/Wnn/include/commonhd.h FreeWnn-1.10-pl020/Wnn/include/commonhd.h
--- FreeWnn-1.10-pl020.dist/Wnn/include/commonhd.h Sun May 5 14:13:08 2002
+++ FreeWnn-1.10-pl020/Wnn/include/commonhd.h Fri Jul 4 11:41:35 2003
@@ -119,6 +119,7 @@
# endif
# ifdef sun
# define SOLARIS
+# define USE_PTMX 1 /*VVV should use configure*/
# endif
#else
# ifndef BSD43
diff -ur FreeWnn-1.10-pl020.dist/Wnn/uum/jhlp.c FreeWnn-1.10-pl020/Wnn/uum/jhlp.c
--- FreeWnn-1.10-pl020.dist/Wnn/uum/jhlp.c Sun Apr 6 14:55:17 2003
+++ FreeWnn-1.10-pl020/Wnn/uum/jhlp.c Fri Jul 4 14:25:19 2003
@@ -364,7 +364,7 @@
open_pty ();
#ifndef linux
- open_ttyp ();
+ open_ttyp (); /* (only?) linux opens slave after fork */
#endif
exec_cmd (argv);
@@ -1289,10 +1289,6 @@
struct winsize win;
extern Term_RowWidth, crow;
#endif
-#if defined(SYSVR2) && !defined(linux)
- setpgrp ();
- close (open (ttyname (ttypfd), O_WRONLY, 0));
-#endif /* SYSVR2 */
if (!(child_id = fork ()))
{
@@ -1319,6 +1315,10 @@
close (open (ttyname (ttypfd), O_WRONLY, 0));
setpgrp (0, pid);
#endif /* BSD42 */
+#if defined(SYSVR2) && !defined(linux)
+ setpgrp (); /* should setpgrp() AFTER fork() */
+ close (open (ttyname (ttypfd), O_WRONLY, 0));
+#endif /* SYSVR2 */
#if !(defined(BSD) && (BSD >= 199306))
if (setutmp (ttypfd) == ERROR)
@@ -1327,7 +1327,7 @@
}
#endif
-#ifdef linux
+#if linux /* (only?) linux open slave tty after fork */
setsid ();
open_ttyp ();
close (ptyfd);
@@ -1496,27 +1496,28 @@
/** ttyp のオープン */
-int ptyno;
-char *ptynm = "/dev/pty";
-#ifdef sgi
-extern char *_getpty (int *, int, mode_t, int);
-char *ttypnm = "/dev/ttyqxxx";
-#else
-char *ttypnm = "/dev/tty";
-#endif /* sgi */
+/* Ways to get a pty:
+== Traditional
+ Try opening each /dev/ptyXX and use the succeeded one
+== SGI IRIX
+ use _getpty()
+== BSD? (USE_OPENPTY)
+ use openpty()
+== STREAMS (Solaris) (USE_PTMX)
+ use /dev/ptmx and ptsname() (see pts(7D) for EXAMPLE)
+ */
+
+char tty_master[32]; /*VVVV overflow?*/
+char tty_slave [32]; /*VVVV overflow?*/
#if defined(BSD43) || defined(DGUX) /* FOR PASS8 */
static int local_mode_sv;
#endif
-#ifndef sgi
-static void ptyname ();
-#endif
-
+/* open slave side of pty to ttypfd */
static void
open_ttyp ()
{
- char nmbuf[20];
#ifdef BSD42
int word;
#endif
@@ -1528,18 +1529,27 @@
#endif
#ifdef sgi
- if ((ttypfd = open (ttypnm, O_RDWR)) == ERROR)
- {
+ if ((ttypfd = open (tty_slave, O_RDWR)) == ERROR)
#else
- ptyname (nmbuf, ttypnm, ptyno);
- if ((ttypfd = open (nmbuf, O_RDWR, 0)) == ERROR)
+#ifdef USE_PTMX /*VVV ptmx*/
+ if ((ttypfd = open(tty_slave, O_RDWR)) == ERROR || /* open slave */
+ ioctl(ttypfd, I_PUSH, "ptem") == ERROR || /* push ptem */
+ ioctl(ttypfd, I_PUSH, "ldterm") == ERROR) /* push ldterm */
+#else /* USE_PTMX */
+#if USE_OPENPTY
+ if (ttypfd < 0)
+#else /*USE_OPENPTY*/
+ if ((ttypfd = open (tty_slave, O_RDWR, 0)) == ERROR)
+#endif /*USE_OPENPTY*/
+#endif /* USE_PTMX */
+#endif /*sgi*/
{
-#endif
+perror(tty_slave); /*VVV debug*/
uum_err ("Can't open ttyp.");
}
#ifndef linux
- chown (nmbuf, getuid (), getgid ());
- chmod (nmbuf, 0622);
+ chown (tty_slave, getuid (), getgid ());
+ chmod (tty_slave, 0622);
#endif /* !linux */
#ifdef BSD42
ioctl (ttyfd, TIOCGETC, &tcharsv);
@@ -1664,33 +1674,98 @@
}
/** pty のオープン */
+/* allocate a new pty master into int ptyfd */
#ifdef sgi
static void
open_pty ()
{
- char nmbuf[20];
char *tty_name_buff;
+ extern char *_getpty (int *, int, mode_t, int);
tty_name_buff = _getpty (&ptyfd, O_RDWR | O_NDELAY, 0600, 0);
if (tty_name_buff == 0)
uum_err ("Can't get pty.");
- strcpy (ttypnm, tty_name_buff);
+ strcpy (tty_slave, tty_name_buff);
+ strcpy (tty_master, "/dev/(_getpty master)"); /* XXX what should this be? */
return;
-
}
#else
+#ifdef USE_PTMX
+static void
+open_pty ()
+{
+ char *p;
+ extern char *ptsname();
+ ptyfd = open("/dev/ptmx", O_RDWR); /* open master */
+ if (ptyfd < 0) {
+ uum_err("Can't get pty.");
+ }
+ grantpt(ptyfd); /* change permission of slave */
+ unlockpt(ptyfd); /* unlock slave */
+
+ p = ptsname(ptyfd); /* get name of slave */
+ strcpy(tty_slave, p);
+ p = ttyname(ptyfd); /* get name of master */
+ strcpy(tty_master, p);
+ return;
+}
+#else /* USE_PTMX */
+#if USE_OPENPTY
static void
open_pty ()
{
- char nmbuf[20];
+ if (openpty(&ptyfd, &ttypfd, tty_slave, NULL, NULL) == ERROR)
+ uum_err("Can't get pty.");
+ /* Note: slave tty is ALREADY OPEN as ttypfd */
+ strcpy(tty_master, ttyname(ptyfd));
+}
+#else /* USE_OPENPTY */
+/* Traditional searching in /dev/ttyXX */
+static void
+open_pty ()
+{
+ int ptyno;
#ifdef linux
struct termio buf1;
#endif
- for (ptyno = 0; ptyno < 32; ptyno++)
+#ifdef hpux
+#define MAXPTYS (11*16)
+#define PTYDEV "/dev/ptym/pty"
+#define TTYDEV "/dev/pty/tty"
+#else
+#define MAXPTYS 32
+#define PTYDEV "/dev/pty"
+#define TTYDEV "/dev/tty"
+#endif
+
+ for (ptyno = 0; ptyno < MAXPTYS; ptyno++) /*VVV sysconf?*/
{
- ptyname (nmbuf, ptynm, ptyno);
- if ((ptyfd = open (nmbuf, O_RDWR, 0)) != ERROR)
+/*
+ * Change pseudo-devices.
+ * Because FreeBSD's master pseudo-devices are pty[p-sP-S][0-9a-v].
+ * Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp) 1996/8/20
+ */
+#if (defined(BSD) && (BSD >= 199306)) /* 4.4BSD-Lite by Taoka */
+#define PTXNAME(b, PFX, no) \
+ sprintf ((b), PFX "%1c%1c", "pqrsPQRS"[((no) >> 5)], "0123456789abcdefghijklmnopqrstuv"[(no) & 0x1f])
+#else /* ! 4.4BSD-Lite */
+#ifdef hpux
+#define PTXNAME(b, PFX, no) \
+ sprintf ((b), PFX "%1c%1c", "zyxwvutsrqp"[(no)>>4], "fedcba9876543210"[(no)&0x0f])
+#else
+#define PTXNAME(b, PFX, no) \
+ sprintf ((b), PFX "%1c%1c", 'p' + ((no) >> 4), "0123456789abcdef"[(no) & 0x0f]);
+#endif /*hpux*/
+#endif /* ! 4.4BSD-Lite */
+#define PTMNAME(b, no) PTXNAME(b, PTYDEV, no)
+#define PTSNAME(b, no) PTXNAME(b, TTYDEV, no)
+
+ PTMNAME(tty_master, ptyno);
+fprintf(stderr, "trying master <%s>\n", tty_master); /*VVV debug*/
+ if ((ptyfd = open (tty_master, O_RDWR, 0)) != ERROR)
{
+ PTSNAME(tty_slave, ptyno);
+fprintf(stderr, "got master=%s slave=%s\n", tty_master, tty_slave); /*VVV debug*/
#if defined(uniosu)
if (ioctl (ptyfd, PIOCPKT, 1) < 0)
{ /* packet mode on */
@@ -1710,7 +1785,9 @@
}
uum_err ("Can't get pty.");
}
-#endif
+#endif /* USE_OPENPTY */
+#endif /* USE_PTMX */
+#endif /*sgi*/
/** エラーだよ。さようなら。 */
void
@@ -1728,8 +1805,6 @@
static void
do_end ()
{
- char nmbuf[20];
-
static int do_end_flg = 0;
if (do_end_flg == 1)
return;
@@ -1762,25 +1837,25 @@
#endif /* defined(uniosu) */
#ifndef sgi
- ptyname (nmbuf, ptynm, ptyno);
- if (chown (nmbuf, 0, 0) == ERROR)
+#ifndef USE_PTMX /*VVV ptmx*/
+ if (chown (tty_master, 0, 0) == ERROR)
{
perror (prog);
}
- if (chmod (nmbuf, 0666) == ERROR)
+ if (chmod (tty_master, 0666) == ERROR)
{
perror (prog);
}
- ptyname (nmbuf, ttypnm, ptyno);
- if (chown (nmbuf, 0, 0) == ERROR)
+ if (chown (tty_slave, 0, 0) == ERROR)
{
perror (prog);
}
- if (chmod (nmbuf, 0666) == ERROR)
+ if (chmod (tty_slave, 0666) == ERROR)
{
perror (prog);
}
+#endif /* USE_PTMX */
#if !(defined(BSD) && (BSD >= 199306))
if (resetutmp (ttypfd) == ERROR)
@@ -1862,26 +1937,6 @@
}
}
#endif /* defined(uniosu) */
-
-
-#ifndef sgi
-static void
-ptyname (b, pty, no)
- char *b, *pty;
- int no;
-{
-/*
- * Change pseudo-devices.
- * Because FreeBSD's master pseudo-devices are pty[p-sP-S][0-9a-v].
- * Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp) 1996/8/20
- */
-#if (defined(BSD) && (BSD >= 199306)) /* 4.4BSD-Lite by Taoka */
- sprintf (b, "%s%1c%1c", pty, "pqrsPQRS"[(no >> 5)], ((no & 0x1f > 9) ? 'a' : '0') + (no & 0x1f));
-#else /* ! 4.4BSD-Lite */
- sprintf (b, "%s%1c%1x", pty, 'p' + (no >> 4), no & 0x0f);
-#endif /* ! 4.4BSD-Lite */
-}
-#endif /* !sgi */
/* Move to etc/xutoj.c
int
diff -ur FreeWnn-1.10-pl020.dist/Wnn/uum/setutmp.c FreeWnn-1.10-pl020/Wnn/uum/setutmp.c
--- FreeWnn-1.10-pl020.dist/Wnn/uum/setutmp.c Sat Jun 22 22:26:21 2002
+++ FreeWnn-1.10-pl020/Wnn/uum/setutmp.c Fri Jul 4 10:15:26 2003
@@ -153,8 +153,10 @@
memset (&ut, 0, sizeof ut);
if ((p = ttyname (ttyFd)) == NULL)
return -1;
- strncpy (ut.ut_line, strrchr (p, '/') + 1, 12);
- strncpy (ut.ut_user, getpwuid (getuid ())->pw_name, 8);
+
+ if (!strcmp(p, "/dev/")) p+=5;
+ strncpy(ut.ut_line, p, sizeof(ut.ut_line));
+ strncpy (ut.ut_user, getpwuid (getuid ())->pw_name, 8); /*VVV should be sizeof(ut_user) */
ut.ut_time = time (0);
#ifdef DGUX
strncpy (ut.ut_id, &ut.ut_line[3], 4);
@@ -212,8 +214,9 @@
memset (&ut, 0, sizeof ut);
if ((p = ttyname (ttyFd)) == NULL)
return -1;
- strncpy (ut.ut_line, strrchr (p, '/') + 1, 12);
- strncpy (ut.ut_user, getpwuid (getuid ())->pw_name, 8);
+ if (!strcmp(p, "/dev/")) p+=5;
+ strncpy (ut.ut_line, p, sizeof(ut.ut_line));
+ strncpy (ut.ut_user, getpwuid (getuid ())->pw_name, 8); /*VVV sizeof*/
ut.ut_time = time (0);
#ifdef DGUX
strncpy (ut.ut_id, &ut.ut_line[3], 4);
diff -ur FreeWnn-1.10-pl020.dist/Wnn/uum/termio.c FreeWnn-1.10-pl020/Wnn/uum/termio.c
--- FreeWnn-1.10-pl020.dist/Wnn/uum/termio.c Fri Jun 14 06:27:47 2002
+++ FreeWnn-1.10-pl020/Wnn/uum/termio.c Fri Jul 4 10:18:16 2003
@@ -112,9 +112,10 @@
fprintf (stderr, "Your terminal is not strong enough. Goodbye !\n");
return (-1);
}
+ /* setenv TERM "${TERM}-j" */
termchar[0] = 0;
strcat (termchar, cp);
- strcat (termchar, "-j");
+ /* strcat (termchar, "-j"); /*VVV what for?? */
if (setenv ("TERM", termchar, 1) != 0)
{
#if HAVE_SNPRINTF
Fnews-brouse 1.9(20180406) -- by Mizuno, MWE <mwe@ccsf.jp>
GnuPG Key ID = ECC8A735
GnuPG Key fingerprint = 9BE6 B9E9 55A5 A499 CD51 946E 9BDC 7870 ECC8 A735